Diff of /trunk/src/main.c

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

revision 19 by harbaum, Mon Jun 29 12:44:57 2009 UTC revision 31 by harbaum, Sat Jul 25 10:29:30 2009 UTC
# Line 1035  cb_menu_about(GtkWidget *window, gpointe Line 1035  cb_menu_about(GtkWidget *window, gpointe
1035    char *str = g_strdup_printf("%s\n\n(%s)",    char *str = g_strdup_printf("%s\n\n(%s)",
1036                        _("GPXView (c) 2008-2009 by\n"                        _("GPXView (c) 2008-2009 by\n"
1037                          "Till Harbaum <till@harbaum.org>\n"                          "Till Harbaum <till@harbaum.org>\n"
1038                          "Mailing list: gpxview-users@garage.maemo.org"                          "Mailing list: gpxview-users@garage.maemo.org"),
1039                        _(uses)                        _(uses)
1040                        );                        );
1041    
# 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 void on_export_destroy(GtkWidget *widget, appdata_t *appdata) {  typedef struct {
1529    appdata->cur_view = g_object_get_data(G_OBJECT(widget), "cur_view");    char *label, *desc;
1530  }    GtkSignalFunc activate_cb;
1531    } menu_entry_t;
 void on_export_clicked(GtkButton *button, appdata_t *appdata) {  
   HildonStackableWindow *view_window;  
   GtkWidget *but;  
   
   view_window = HILDON_STACKABLE_WINDOW (hildon_stackable_window_new ());  
   gtk_window_set_title (GTK_WINDOW (view_window), "GPXView - Export");  
   
    /* store last "cur_view" in window */  
   g_object_set_data(G_OBJECT(view_window), "cur_view", appdata->cur_view);  
   appdata->cur_view = NULL;  
   
   g_signal_connect(G_OBJECT(view_window), "destroy",  
                    G_CALLBACK(on_export_destroy), appdata);  
1532    
1533    GtkVBox *contents = GTK_VBOX(gtk_vbox_new (12, FALSE));  typedef struct {
1534      const char *title;
1535      const menu_entry_t *menu;
1536      int len;
1537    } submenu_t;
1538    
1539    #define COLUMNS  1
1540    
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    but = 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 to Maemo Mapper"),              _(menu_entries->label), _(menu_entries->desc));
             _("Save a Maemo Mapper POI file"));  
   g_signal_connect(but, "clicked",  
                    G_CALLBACK(cb_menu_export_mmpoi), appdata);  
   gtk_box_pack_start(GTK_BOX(contents), but, FALSE, FALSE, 0);  
1574    
1575        /* try to center both texts */
1576        hildon_button_set_title_alignment(HILDON_BUTTON(button), 0.5, 0.5);
1577        hildon_button_set_value_alignment(HILDON_BUTTON(button), 0.5, 0.5);
1578    
1579    but = hildon_button_new_with_text(      g_signal_connect(button, "clicked",
1580              HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH,                       G_CALLBACK(on_submenu_entry_clicked), dialog);
1581              HILDON_BUTTON_ARRANGEMENT_VERTICAL,  
1582              _("Export Field Notes"),      g_signal_connect(button, "clicked",
1583              _("Save a Garmin Field Notes file"));                       menu_entries->activate_cb, appdata);
1584    g_signal_connect(but, "clicked",  
1585                     G_CALLBACK(cb_menu_export_log), appdata);      gtk_table_attach_defaults(GTK_TABLE(table),  button, x, x+1, y, y+1);
1586    gtk_box_pack_start(GTK_BOX(contents), but, FALSE, FALSE, 0);  
1587        x++;
1588        if(x == COLUMNS) { x = 0; y++; }
1589    
1590    but = hildon_button_new_with_text(      menu_entries++;
1591              HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH,    }
             HILDON_BUTTON_ARRANGEMENT_VERTICAL,  
             _("Export Garmin GPX"),  
             _("Save a GPX file containing modified waypoints"));  
   g_signal_connect(but, "clicked",  
                    G_CALLBACK(cb_menu_export_garmin), appdata);  
   gtk_box_pack_start(GTK_BOX(contents), but, FALSE, FALSE, 0);  
1592    
1593    gtk_container_add (GTK_CONTAINER (view_window), GTK_WIDGET (contents));    gtk_box_pack_start_defaults(GTK_BOX(GTK_DIALOG(dialog)->vbox), table);
   gtk_widget_show_all (GTK_WIDGET (view_window));  
 }  
1594    
1595  static void on_tools_destroy(GtkWidget *widget, appdata_t *appdata) {    return dialog;
   appdata->cur_view = g_object_get_data(G_OBJECT(widget), "cur_view");  
1596  }  }
1597    
1598  void on_tools_clicked(GtkButton *button, appdata_t *appdata) {  /* popup the dialog shaped submenu */
1599    HildonStackableWindow *view_window;  static void submenu_popup(GtkWidget *menu) {
1600    GtkWidget *but;    gtk_widget_show_all(menu);
1601      gtk_dialog_run(GTK_DIALOG(menu));
1602      gtk_widget_hide(menu);
1603    }
1604    
1605    view_window = HILDON_STACKABLE_WINDOW (hildon_stackable_window_new ());  static void submenu_cleanup(GtkWidget *menu) {
1606    gtk_window_set_title (GTK_WINDOW (view_window), "GPXView - Tools");    gtk_widget_destroy(menu);
1607    }
1608    
1609     /* store last "cur_view" in window */  static const menu_entry_t submenu_export_entries[] = {
1610    g_object_set_data(G_OBJECT(view_window), "cur_view", appdata->cur_view);    { "Export to Maemo Mapper" , "Save a Maemo Mapper POI file",
1611    appdata->cur_view = NULL;      G_CALLBACK(cb_menu_export_mmpoi)  },
1612      { "Export Field Notes",      "Save a Garmin Field Notes file",
1613        G_CALLBACK(cb_menu_export_log)    },
1614      { "Export Garmin GPX",       "Save modified waypoints in GPX file",
1615        G_CALLBACK(cb_menu_export_garmin) },
1616      { NULL, NULL, NULL }
1617    };
1618    
1619    g_signal_connect(G_OBJECT(view_window), "destroy",  static const submenu_t submenu_export = {
1620                     G_CALLBACK(on_tools_destroy), appdata);    "Export", submenu_export_entries,
1621      sizeof(submenu_export_entries)/sizeof(menu_entry_t)-1
1622    };
1623    
1624    GtkVBox *contents = GTK_VBOX(gtk_vbox_new (12, FALSE));  /* the export submenu */
1625    void on_export_clicked(GtkButton *button, appdata_t *appdata) {
1626      if(!appdata->export_menu)
1627        appdata->export_menu = app_submenu_create(appdata, &submenu_export);
1628    
1629    but = hildon_button_new_with_text(    submenu_popup(appdata->export_menu);
1630              HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH,  }
             HILDON_BUTTON_ARRANGEMENT_VERTICAL,  
             _("Geomath"),  
             _("Geocoordinate calculation"));  
   g_signal_connect(but, "clicked",  
                    G_CALLBACK(cb_menu_geomath), appdata);  
   gtk_box_pack_start(GTK_BOX(contents), but, FALSE, FALSE, 0);  
1631    
1632    static const menu_entry_t submenu_tools_entries[] = {
1633      { "Geomath",          "Geocoordinate calculation",
1634        G_CALLBACK(cb_menu_geomath) },
1635      { "Geotext",          "Text analysis",
1636        G_CALLBACK(cb_menu_geotext) },
1637      { "Precise Position", "Calculate a precise GPS position",
1638        G_CALLBACK(cb_menu_precpos) },
1639      { NULL, NULL, NULL }
1640    };
1641    
1642    static const submenu_t submenu_tools = {
1643      "Tools", submenu_tools_entries,
1644      sizeof(submenu_tools_entries)/sizeof(menu_entry_t)-1
1645    };
1646    
1647    but = hildon_button_new_with_text(  /* the tools submenu */
1648              HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH,  void on_tools_clicked(GtkButton *button, appdata_t *appdata) {
1649              HILDON_BUTTON_ARRANGEMENT_VERTICAL,    if(!appdata->tools_menu)
1650              _("Geotext"),      appdata->tools_menu = app_submenu_create(appdata, &submenu_tools);
             _("Text analysis, letter counting etc"));  
   g_signal_connect(but, "clicked",  
                    G_CALLBACK(cb_menu_geotext), appdata);  
   gtk_box_pack_start(GTK_BOX(contents), but, FALSE, FALSE, 0);  
   
   
   but = hildon_button_new_with_text(  
             HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH,  
             HILDON_BUTTON_ARRANGEMENT_VERTICAL,  
             _("Precise Position"),  
             _("Calculate a very precise GPS position"));  
   g_signal_connect(but, "clicked",  
                    G_CALLBACK(cb_menu_precpos), appdata);  
   gtk_box_pack_start(GTK_BOX(contents), but, FALSE, FALSE, 0);  
1651    
1652    gtk_container_add (GTK_CONTAINER (view_window), GTK_WIDGET (contents));    submenu_popup(appdata->tools_menu);
   gtk_widget_show_all (GTK_WIDGET (view_window));  
1653  }  }
1654    
1655  HildonAppMenu *menu_create(appdata_t *appdata, int mode) {  HildonAppMenu *menu_create(appdata_t *appdata, int mode) {
# Line 1851  void cleanup(appdata_t *appdata) { Line 1872  void cleanup(appdata_t *appdata) {
1872    if(appdata->image_path) free(appdata->image_path);    if(appdata->image_path) free(appdata->image_path);
1873    if(appdata->search_str) free(appdata->search_str);    if(appdata->search_str) free(appdata->search_str);
1874    
1875    #ifdef USE_STACKABLE_WINDOW
1876      if(appdata->export_menu) submenu_cleanup(appdata->export_menu);
1877      if(appdata->tools_menu)  submenu_cleanup(appdata->tools_menu);
1878    #endif
1879    
1880    gnome_vfs_shutdown();    gnome_vfs_shutdown();
1881    icons_free();    icons_free();
1882    gps_release(appdata);    gps_release(appdata);
# Line 2222  int main(int argc, char *argv[]) { Line 2248  int main(int argc, char *argv[]) {
2248    
2249    appdata.vbox = gtk_vbox_new(FALSE, 2);    appdata.vbox = gtk_vbox_new(FALSE, 2);
2250    gtk_container_add(GTK_CONTAINER(appdata.window), appdata.vbox);    gtk_container_add(GTK_CONTAINER(appdata.window), appdata.vbox);
   
2251  #ifndef USE_STACKABLE_WINDOW  #ifndef USE_STACKABLE_WINDOW
2252    menu_create(&appdata);    menu_create(&appdata);
2253  #else  #else

Legend:
Removed from v.19  
changed lines
  Added in v.31