Diff of /trunk/src/main.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 29 by harbaum, Mon Jul 6 14:07:36 2009 UTC revision 30 by harbaum, Fri Jul 24 19:24:42 2009 UTC
# Line 1525  cb_menu_precpos(GtkWidget *window, gpoin Line 1525  cb_menu_precpos(GtkWidget *window, gpoin
1525  }  }
1526    
1527  #ifdef USE_STACKABLE_WINDOW  #ifdef USE_STACKABLE_WINDOW
1528  static GtkWidget *export_menu_create(appdata_t *appdata) {  typedef struct {
1529    GtkWidget *button;    char *label, *desc;
1530    HildonAppMenu *menu = HILDON_APP_MENU(hildon_app_menu_new());    GtkSignalFunc activate_cb;
1531    } menu_entry_t;
   button = hildon_button_new_with_text(  
             HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH,  
             HILDON_BUTTON_ARRANGEMENT_VERTICAL,  
             _("Export to Maemo Mapper"),  
             _("Save a Maemo Mapper POI file"));  
   g_signal_connect_after(button, "clicked",  
                    G_CALLBACK(cb_menu_export_mmpoi), appdata);  
   hildon_app_menu_append(menu, GTK_BUTTON(button));  
1532    
1533    button = hildon_button_new_with_text(  typedef struct {
1534              HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH,    const char *title;
1535              HILDON_BUTTON_ARRANGEMENT_VERTICAL,    const menu_entry_t *menu;
1536              _("Export Field Notes"),    int len;
1537              _("Save a Garmin Field Notes file"));  } submenu_t;
1538    g_signal_connect_after(button, "clicked",  
1539                     G_CALLBACK(cb_menu_export_log), appdata);  #define COLUMNS  1
1540    hildon_app_menu_append(menu, GTK_BUTTON(button));  
1541    void on_submenu_entry_clicked(GtkButton *button, GtkWidget *menu) {
1542    
1543      /* force closing of submenu dialog */
1544      gtk_dialog_response(GTK_DIALOG(menu), GTK_RESPONSE_NONE);
1545      gtk_widget_hide(menu);
1546    
1547      /* let gtk clean up */
1548      while(gtk_events_pending())
1549        gtk_main_iteration();
1550    }
1551    
1552    static GtkWidget *app_submenu_create(appdata_t *appdata,
1553                                         const submenu_t *submenu) {
1554    
1555      /* create a oridinary dialog box */
1556      GtkWidget *dialog = gtk_dialog_new();
1557      gtk_window_set_title(GTK_WINDOW(dialog), _(submenu->title));
1558      gtk_window_set_modal(GTK_WINDOW(dialog), TRUE);
1559      gtk_window_set_transient_for(GTK_WINDOW(dialog),
1560                                   GTK_WINDOW(appdata->window));
1561      gtk_dialog_set_has_separator(GTK_DIALOG(dialog), FALSE);
1562    
1563      GtkWidget *table = gtk_table_new(submenu->len/COLUMNS, COLUMNS, TRUE);
1564      int x = 0, y = 0;
1565    
1566      const menu_entry_t *menu_entries = submenu->menu;
1567      while(menu_entries->label) {
1568        GtkWidget *button = NULL;
1569    
1570    button = hildon_button_new_with_text(      button = hildon_button_new_with_text(
1571              HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH,              HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH,
1572              HILDON_BUTTON_ARRANGEMENT_VERTICAL,              HILDON_BUTTON_ARRANGEMENT_VERTICAL,
1573              _("Export Garmin GPX"),              _(menu_entries->label), _(menu_entries->desc));
             _("Save modified waypoints in GPX file"));  
   g_signal_connect_after(button, "clicked",  
                    G_CALLBACK(cb_menu_export_garmin), appdata);  
   hildon_app_menu_append(menu, GTK_BUTTON(button));  
1574    
1575    gtk_widget_show_all(GTK_WIDGET(menu));        g_signal_connect(button, "clicked",
1576                           G_CALLBACK(on_submenu_entry_clicked), dialog);
1577    
1578    return GTK_WIDGET(menu);        g_signal_connect(button, "clicked",
1579  }                         menu_entries->activate_cb, appdata);
1580    
1581  /* the export submenu */      gtk_table_attach_defaults(GTK_TABLE(table),  button, x, x+1, y, y+1);
1582  void on_export_clicked(GtkButton *button, appdata_t *appdata) {  
1583    if(!appdata->export_menu)      x++;
1584      appdata->export_menu = export_menu_create(appdata);      if(x == COLUMNS) { x = 0; y++; }
1585    
1586    /* draw a popup menu */      menu_entries++;
1587    hildon_app_menu_popup(HILDON_APP_MENU(appdata->export_menu),    }
                         GTK_WINDOW(hildon_window_stack_peek(  
                     hildon_window_stack_get_default())));  
 }  
1588    
1589  static GtkWidget *tools_menu_create(appdata_t *appdata) {    gtk_box_pack_start_defaults(GTK_BOX(GTK_DIALOG(dialog)->vbox), table);
   GtkWidget *button;  
   HildonAppMenu *menu = HILDON_APP_MENU(hildon_app_menu_new());  
1590    
1591    /* the following doesn't have an effect */    return dialog;
1592    //  gtk_window_set_title(GTK_WINDOW(menu), "Tools");  }
1593    
1594    button = hildon_button_new_with_text(  /* popup the dialog shaped submenu */
1595              HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH,  static void submenu_popup(GtkWidget *menu) {
1596              HILDON_BUTTON_ARRANGEMENT_VERTICAL,    gtk_widget_show_all(menu);
1597              _("Geomath"),    gtk_dialog_run(GTK_DIALOG(menu));
1598              _("Geocoordinate calculation"));    gtk_widget_hide(menu);
1599    g_signal_connect_after(button, "clicked",  }
                    G_CALLBACK(cb_menu_geomath), appdata);  
   hildon_app_menu_append(menu, GTK_BUTTON(button));  
1600    
1601    static void submenu_cleanup(GtkWidget *menu) {
1602      gtk_widget_destroy(menu);
1603    }
1604    
1605    button = hildon_button_new_with_text(  static const menu_entry_t submenu_export_entries[] = {
1606              HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH,    { "Export to Maemo Mapper" , "Save a Maemo Mapper POI file",
1607              HILDON_BUTTON_ARRANGEMENT_VERTICAL,      G_CALLBACK(cb_menu_export_mmpoi)  },
1608              _("Geotext"),    { "Export Field Notes",      "Save a Garmin Field Notes file",
1609              _("Text analysis"));      G_CALLBACK(cb_menu_export_log)    },
1610    g_signal_connect_after(button, "clicked",    { "Export Garmin GPX",       "Save modified waypoints in GPX file",
1611                     G_CALLBACK(cb_menu_geotext), appdata);      G_CALLBACK(cb_menu_export_garmin) },
1612    hildon_app_menu_append(menu, GTK_BUTTON(button));    { NULL, NULL, NULL }
1613    };
1614    
1615    button = hildon_button_new_with_text(  static const submenu_t submenu_export = {
1616              HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH,    "Export", submenu_export_entries,
1617              HILDON_BUTTON_ARRANGEMENT_VERTICAL,    sizeof(submenu_export_entries)/sizeof(menu_entry_t)-1
1618              _("Precise Position"),  };
             _("Calculate a precise GPS position"));  
   g_signal_connect_after(button, "clicked",  
                    G_CALLBACK(cb_menu_precpos), appdata);  
   hildon_app_menu_append(menu, GTK_BUTTON(button));  
1619    
1620    gtk_widget_show_all(GTK_WIDGET(menu));  /* the export submenu */
1621    void on_export_clicked(GtkButton *button, appdata_t *appdata) {
1622      if(!appdata->export_menu)
1623        appdata->export_menu = app_submenu_create(appdata, &submenu_export);
1624    
1625    return GTK_WIDGET(menu);    submenu_popup(appdata->export_menu);
1626  }  }
1627    
1628    static const menu_entry_t submenu_tools_entries[] = {
1629      { "Geomath",          "Geocoordinate calculation",
1630        G_CALLBACK(cb_menu_geomath) },
1631      { "Geotext",          "Text analysis",
1632        G_CALLBACK(cb_menu_geotext) },
1633      { "Precise Position", "Calculate a precise GPS position",
1634        G_CALLBACK(cb_menu_precpos) },
1635      { NULL, NULL, NULL }
1636    };
1637    
1638    static const submenu_t submenu_tools = {
1639      "Tools", submenu_tools_entries,
1640      sizeof(submenu_tools_entries)/sizeof(menu_entry_t)-1
1641    };
1642    
1643  /* the tools submenu */  /* the tools submenu */
1644  void on_tools_clicked(GtkButton *button, appdata_t *appdata) {  void on_tools_clicked(GtkButton *button, appdata_t *appdata) {
1645    if(!appdata->tools_menu)    if(!appdata->tools_menu)
1646      appdata->tools_menu = tools_menu_create(appdata);      appdata->tools_menu = app_submenu_create(appdata, &submenu_tools);
1647    
1648    /* draw a popup menu */    submenu_popup(appdata->tools_menu);
   hildon_app_menu_popup(HILDON_APP_MENU(appdata->tools_menu),  
                         GTK_WINDOW(hildon_window_stack_peek(  
                     hildon_window_stack_get_default())));  
1649  }  }
1650    
   
1651  HildonAppMenu *menu_create(appdata_t *appdata, int mode) {  HildonAppMenu *menu_create(appdata_t *appdata, int mode) {
1652    GtkWidget *button;    GtkWidget *button;
1653    HildonAppMenu *menu = HILDON_APP_MENU(hildon_app_menu_new());    HildonAppMenu *menu = HILDON_APP_MENU(hildon_app_menu_new());
# Line 1845  void cleanup(appdata_t *appdata) { Line 1868  void cleanup(appdata_t *appdata) {
1868    if(appdata->image_path) free(appdata->image_path);    if(appdata->image_path) free(appdata->image_path);
1869    if(appdata->search_str) free(appdata->search_str);    if(appdata->search_str) free(appdata->search_str);
1870    
1871    #ifdef USE_STACKABLE_WINDOW
1872      if(appdata->export_menu) submenu_cleanup(appdata->export_menu);
1873      if(appdata->tools_menu)  submenu_cleanup(appdata->tools_menu);
1874    #endif
1875    
1876    gnome_vfs_shutdown();    gnome_vfs_shutdown();
1877    icons_free();    icons_free();
1878    gps_release(appdata);    gps_release(appdata);
# Line 2216  int main(int argc, char *argv[]) { Line 2244  int main(int argc, char *argv[]) {
2244    
2245    appdata.vbox = gtk_vbox_new(FALSE, 2);    appdata.vbox = gtk_vbox_new(FALSE, 2);
2246    gtk_container_add(GTK_CONTAINER(appdata.window), appdata.vbox);    gtk_container_add(GTK_CONTAINER(appdata.window), appdata.vbox);
   
2247  #ifndef USE_STACKABLE_WINDOW  #ifndef USE_STACKABLE_WINDOW
2248    menu_create(&appdata);    menu_create(&appdata);
2249  #else  #else

Legend:
Removed from v.29  
changed lines
  Added in v.30