Diff of /trunk/src/main.c

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

revision 24 by harbaum, Mon Jul 6 14:07:36 2009 UTC revision 45 by harbaum, Tue Aug 4 19:27:39 2009 UTC
# Line 202  void cachelist_view_onRowActivated(GtkTr Line 202  void cachelist_view_onRowActivated(GtkTr
202    GtkTreeIter   iter;    GtkTreeIter   iter;
203    GtkTreeModel *model = gtk_tree_view_get_model(treeview);    GtkTreeModel *model = gtk_tree_view_get_model(treeview);
204    
205    #ifdef USE_MAEMO
206      /* check if a cache is already selected and ignore click if yes */
207      /* (was probably a double click) */
208      if(appdata->cur_cache) return;
209    #endif
210    
211    if(gtk_tree_model_get_iter(model, &iter, path)) {    if(gtk_tree_model_get_iter(model, &iter, path)) {
212      cache_t *cache;      cache_t *cache;
213      gtk_tree_model_get(model, &iter, CACHELIST_COL_DATA, &cache, -1);      gtk_tree_model_get(model, &iter, CACHELIST_COL_DATA, &cache, -1);
# Line 587  void cachelist_dialog(appdata_t *appdata Line 593  void cachelist_dialog(appdata_t *appdata
593    g_object_set_data(G_OBJECT(window), "cur_view", appdata->cur_view);    g_object_set_data(G_OBJECT(window), "cur_view", appdata->cur_view);
594    
595    appdata->cur_gpx = gpx;    appdata->cur_gpx = gpx;
596    char *title = g_strdup_printf("GPXView - %s", gpx->name);    char *title = g_strdup_printf("%s - GPXView", gpx->name);
597    gtk_window_set_title(GTK_WINDOW(window), title);    gtk_window_set_title(GTK_WINDOW(window), title);
598    g_free(title);    g_free(title);
599    
# Line 713  static void gpxlist_view_onRowActivated( Line 719  static void gpxlist_view_onRowActivated(
719    GtkTreeIter   iter;    GtkTreeIter   iter;
720    GtkTreeModel *model = gtk_tree_view_get_model(treeview);    GtkTreeModel *model = gtk_tree_view_get_model(treeview);
721    
722    #ifdef USE_MAEMO
723      /* check if a cache is already selected and ignore click if yes */
724      /* (was probably a double click) */
725      if(appdata->cur_gpx) return;
726    #endif
727    
728    if (gtk_tree_model_get_iter(model, &iter, path)) {    if (gtk_tree_model_get_iter(model, &iter, path)) {
729      gpx_t *gpx;      gpx_t *gpx;
730      gtk_tree_model_get(model, &iter, GPXLIST_COL_DATA, &gpx, -1);      gtk_tree_model_get(model, &iter, GPXLIST_COL_DATA, &gpx, -1);
# Line 1433  cb_menu_search(GtkWidget *window, gpoint Line 1445  cb_menu_search(GtkWidget *window, gpoint
1445      gtk_widget_destroy(dialog);      gtk_widget_destroy(dialog);
1446  }  }
1447    
1448  void on_window_destroy (GtkWidget *widget, gpointer data);  static void on_window_destroy (GtkWidget *widget, gpointer data);
1449    
1450  #ifndef USE_MAEMO  #ifndef USE_MAEMO
1451  static void  static void
# Line 1509  cb_menu_export_garmin(GtkWidget *widget, Line 1521  cb_menu_export_garmin(GtkWidget *widget,
1521    garmin_export(appdata);    garmin_export(appdata);
1522  }  }
1523    
1524    #ifdef ENABLE_OSM_GPS_MAP
1525    static void
1526    cb_menu_map(GtkWidget *window, gpointer data) {
1527      map((appdata_t *)data);
1528    }
1529    #endif
1530    
1531  static void  static void
1532  cb_menu_geomath(GtkWidget *window, gpointer data) {  cb_menu_geomath(GtkWidget *window, gpointer data) {
1533    geomath_dialog((appdata_t *)data);    geomath_dialog((appdata_t *)data);
# Line 1525  cb_menu_precpos(GtkWidget *window, gpoin Line 1544  cb_menu_precpos(GtkWidget *window, gpoin
1544  }  }
1545    
1546  #ifdef USE_STACKABLE_WINDOW  #ifdef USE_STACKABLE_WINDOW
1547  static GtkWidget *export_menu_create(appdata_t *appdata) {  typedef struct {
1548    GtkWidget *button;    char *label, *desc;
1549    HildonAppMenu *menu = HILDON_APP_MENU(hildon_app_menu_new());    GtkSignalFunc activate_cb;
1550    } 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));  
1551    
1552    button = hildon_button_new_with_text(  typedef struct {
1553              HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH,    const char *title;
1554              HILDON_BUTTON_ARRANGEMENT_VERTICAL,    const menu_entry_t *menu;
1555              _("Export Field Notes"),    int len;
1556              _("Save a Garmin Field Notes file"));  } submenu_t;
   g_signal_connect_after(button, "clicked",  
                    G_CALLBACK(cb_menu_export_log), appdata);  
   hildon_app_menu_append(menu, GTK_BUTTON(button));  
1557    
1558    button = hildon_button_new_with_text(  #define COLUMNS  1
             HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH,  
             HILDON_BUTTON_ARRANGEMENT_VERTICAL,  
             _("Export Garmin GPX"),  
             _("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));  
1559    
1560    gtk_widget_show_all(GTK_WIDGET(menu));  void on_submenu_entry_clicked(GtkButton *button, GtkWidget *menu) {
1561    
1562    return GTK_WIDGET(menu);    /* force closing of submenu dialog */
1563      gtk_dialog_response(GTK_DIALOG(menu), GTK_RESPONSE_NONE);
1564      gtk_widget_hide(menu);
1565    
1566      /* let gtk clean up */
1567      while(gtk_events_pending())
1568        gtk_main_iteration();
1569  }  }
1570    
1571  /* the export submenu */  static GtkWidget *app_submenu_create(appdata_t *appdata,
1572  void on_export_clicked(GtkButton *button, appdata_t *appdata) {                                       const submenu_t *submenu) {
   if(!appdata->export_menu)  
     appdata->export_menu = export_menu_create(appdata);  
1573    
1574    /* draw a popup menu */    /* create a oridinary dialog box */
1575    hildon_app_menu_popup(HILDON_APP_MENU(appdata->export_menu),    GtkWidget *dialog = gtk_dialog_new();
1576                          GTK_WINDOW(hildon_window_stack_peek(    gtk_window_set_title(GTK_WINDOW(dialog), _(submenu->title));
1577                      hildon_window_stack_get_default())));    gtk_window_set_modal(GTK_WINDOW(dialog), TRUE);
1578  }    gtk_window_set_transient_for(GTK_WINDOW(dialog),
1579                                   GTK_WINDOW(appdata->window));
1580      gtk_dialog_set_has_separator(GTK_DIALOG(dialog), FALSE);
1581    
1582  static GtkWidget *tools_menu_create(appdata_t *appdata) {    GtkWidget *table = gtk_table_new(submenu->len/COLUMNS, COLUMNS, TRUE);
1583    GtkWidget *button;    int x = 0, y = 0;
   HildonAppMenu *menu = HILDON_APP_MENU(hildon_app_menu_new());  
1584    
1585    /* the following doesn't have an effect */    const menu_entry_t *menu_entries = submenu->menu;
1586    //  gtk_window_set_title(GTK_WINDOW(menu), "Tools");    while(menu_entries->label) {
1587        GtkWidget *button = NULL;
1588    
1589    button = hildon_button_new_with_text(      button = hildon_button_new_with_text(
1590              HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH,              HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH,
1591              HILDON_BUTTON_ARRANGEMENT_VERTICAL,              HILDON_BUTTON_ARRANGEMENT_VERTICAL,
1592              _("Geomath"),              _(menu_entries->label), _(menu_entries->desc));
             _("Geocoordinate calculation"));  
   g_signal_connect_after(button, "clicked",  
                    G_CALLBACK(cb_menu_geomath), appdata);  
   hildon_app_menu_append(menu, GTK_BUTTON(button));  
1593    
1594        /* try to center both texts */
1595        hildon_button_set_title_alignment(HILDON_BUTTON(button), 0.5, 0.5);
1596        hildon_button_set_value_alignment(HILDON_BUTTON(button), 0.5, 0.5);
1597    
1598    button = hildon_button_new_with_text(      g_signal_connect(button, "clicked",
1599              HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH,                       G_CALLBACK(on_submenu_entry_clicked), dialog);
1600              HILDON_BUTTON_ARRANGEMENT_VERTICAL,  
1601              _("Geotext"),      g_signal_connect(button, "clicked",
1602              _("Text analysis"));                       menu_entries->activate_cb, appdata);
1603    g_signal_connect_after(button, "clicked",  
1604                     G_CALLBACK(cb_menu_geotext), appdata);      gtk_table_attach_defaults(GTK_TABLE(table),  button, x, x+1, y, y+1);
1605    hildon_app_menu_append(menu, GTK_BUTTON(button));  
1606        x++;
1607        if(x == COLUMNS) { x = 0; y++; }
1608    
1609    button = hildon_button_new_with_text(      menu_entries++;
1610              HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH,    }
             HILDON_BUTTON_ARRANGEMENT_VERTICAL,  
             _("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));  
1611    
1612    gtk_widget_show_all(GTK_WIDGET(menu));    gtk_box_pack_start_defaults(GTK_BOX(GTK_DIALOG(dialog)->vbox), table);
1613    
1614      return dialog;
1615    }
1616    
1617    /* popup the dialog shaped submenu */
1618    static void submenu_popup(GtkWidget *menu) {
1619      gtk_widget_show_all(menu);
1620      gtk_dialog_run(GTK_DIALOG(menu));
1621      gtk_widget_hide(menu);
1622    }
1623    
1624    static void submenu_cleanup(GtkWidget *menu) {
1625      gtk_widget_destroy(menu);
1626    }
1627    
1628    static const menu_entry_t submenu_export_entries[] = {
1629      { "Export to Maemo Mapper" , "Save a Maemo Mapper POI file",
1630        G_CALLBACK(cb_menu_export_mmpoi)  },
1631      { "Export Field Notes",      "Save a Garmin Field Notes file",
1632        G_CALLBACK(cb_menu_export_log)    },
1633      { "Export Garmin GPX",       "Save modified waypoints in GPX file",
1634        G_CALLBACK(cb_menu_export_garmin) },
1635      { NULL, NULL, NULL }
1636    };
1637    
1638    static const submenu_t submenu_export = {
1639      "Export", submenu_export_entries,
1640      sizeof(submenu_export_entries)/sizeof(menu_entry_t)-1
1641    };
1642    
1643    /* the export submenu */
1644    void on_export_clicked(GtkButton *button, appdata_t *appdata) {
1645      if(!appdata->export_menu)
1646        appdata->export_menu = app_submenu_create(appdata, &submenu_export);
1647    
1648    return GTK_WIDGET(menu);    submenu_popup(appdata->export_menu);
1649  }  }
1650    
1651    static const menu_entry_t submenu_tools_entries[] = {
1652      { "Geomath",          "Geocoordinate calculation",
1653        G_CALLBACK(cb_menu_geomath) },
1654      { "Geotext",          "Text analysis",
1655        G_CALLBACK(cb_menu_geotext) },
1656      { "Precise Position", "Calculate a precise GPS position",
1657        G_CALLBACK(cb_menu_precpos) },
1658      { NULL, NULL, NULL }
1659    };
1660    
1661    static const submenu_t submenu_tools = {
1662      "Tools", submenu_tools_entries,
1663      sizeof(submenu_tools_entries)/sizeof(menu_entry_t)-1
1664    };
1665    
1666  /* the tools submenu */  /* the tools submenu */
1667  void on_tools_clicked(GtkButton *button, appdata_t *appdata) {  void on_tools_clicked(GtkButton *button, appdata_t *appdata) {
1668    if(!appdata->tools_menu)    if(!appdata->tools_menu)
1669      appdata->tools_menu = tools_menu_create(appdata);      appdata->tools_menu = app_submenu_create(appdata, &submenu_tools);
1670    
1671    /* 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())));  
1672  }  }
1673    
   
1674  HildonAppMenu *menu_create(appdata_t *appdata, int mode) {  HildonAppMenu *menu_create(appdata_t *appdata, int mode) {
1675    GtkWidget *button;    GtkWidget *button;
1676    HildonAppMenu *menu = HILDON_APP_MENU(hildon_app_menu_new());    HildonAppMenu *menu = HILDON_APP_MENU(hildon_app_menu_new());
# Line 1650  HildonAppMenu *menu_create(appdata_t *ap Line 1696  HildonAppMenu *menu_create(appdata_t *ap
1696      g_signal_connect_after(button, "clicked",      g_signal_connect_after(button, "clicked",
1697                             G_CALLBACK(cb_menu_adddir), appdata);                             G_CALLBACK(cb_menu_adddir), appdata);
1698      hildon_app_menu_append(menu, GTK_BUTTON(button));      hildon_app_menu_append(menu, GTK_BUTTON(button));
   }  
1699    
   if(mode == MENU_GPXLIST) {  
1700      button = gtk_button_new_with_label(_("Export"));      button = gtk_button_new_with_label(_("Export"));
1701      g_signal_connect_after(button, "clicked",      g_signal_connect_after(button, "clicked",
1702                             G_CALLBACK(on_export_clicked), appdata);                             G_CALLBACK(on_export_clicked), appdata);
# Line 1669  HildonAppMenu *menu_create(appdata_t *ap Line 1713  HildonAppMenu *menu_create(appdata_t *ap
1713                           G_CALLBACK(on_tools_clicked), appdata);                           G_CALLBACK(on_tools_clicked), appdata);
1714    hildon_app_menu_append(menu, GTK_BUTTON(button));    hildon_app_menu_append(menu, GTK_BUTTON(button));
1715    
1716    #ifdef ENABLE_OSM_GPS_MAP
1717      if((mode == MENU_GPXLIST) || (mode == MENU_CACHELIST)) {
1718        button = gtk_button_new_with_label(_("Map"));
1719        g_signal_connect_after(button, "clicked",
1720                               G_CALLBACK(cb_menu_map), appdata);
1721        hildon_app_menu_append(menu, GTK_BUTTON(button));
1722      }
1723    #endif
1724    
1725  #ifdef HILDON_HELP  #ifdef HILDON_HELP
1726    button = gtk_button_new_with_label(_("Help"));    button = gtk_button_new_with_label(_("Help"));
1727    g_signal_connect_after(button, "clicked",    g_signal_connect_after(button, "clicked",
# Line 1786  void menu_create(appdata_t *appdata) { Line 1839  void menu_create(appdata_t *appdata) {
1839    submenu = gtk_menu_new();    submenu = gtk_menu_new();
1840    gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), submenu);    gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), submenu);
1841    
1842    #ifdef ENABLE_OSM_GPS_MAP
1843      item = gtk_menu_item_new_with_label( _("Map") );
1844      gtk_menu_append(GTK_MENU_SHELL(submenu), item);
1845      g_signal_connect(item, "activate",
1846                       GTK_SIGNAL_FUNC(cb_menu_map), appdata);
1847    #endif
1848    
1849    item = gtk_menu_item_new_with_label( _("Geomath") );    item = gtk_menu_item_new_with_label( _("Geomath") );
1850    gtk_menu_append(GTK_MENU_SHELL(submenu), item);    gtk_menu_append(GTK_MENU_SHELL(submenu), item);
1851    g_signal_connect(item, "activate",    g_signal_connect(item, "activate",
# Line 1845  void cleanup(appdata_t *appdata) { Line 1905  void cleanup(appdata_t *appdata) {
1905    if(appdata->image_path) free(appdata->image_path);    if(appdata->image_path) free(appdata->image_path);
1906    if(appdata->search_str) free(appdata->search_str);    if(appdata->search_str) free(appdata->search_str);
1907    
1908    #ifdef USE_STACKABLE_WINDOW
1909      if(appdata->export_menu) submenu_cleanup(appdata->export_menu);
1910      if(appdata->tools_menu)  submenu_cleanup(appdata->tools_menu);
1911    #endif
1912    
1913    gnome_vfs_shutdown();    gnome_vfs_shutdown();
1914    icons_free();    icons_free();
1915    gps_release(appdata);    gps_release(appdata);
# Line 1873  void cleanup(appdata_t *appdata) { Line 1938  void cleanup(appdata_t *appdata) {
1938    puts("everything is gone");    puts("everything is gone");
1939  }  }
1940    
1941  void on_window_destroy (GtkWidget *widget, gpointer data) {  static void on_window_destroy (GtkWidget *widget, gpointer data) {
1942    appdata_t *appdata = (appdata_t*)data;    appdata_t *appdata = (appdata_t*)data;
1943    
1944    gconf_save_state(appdata);    gconf_save_state(appdata);
# Line 2216  int main(int argc, char *argv[]) { Line 2281  int main(int argc, char *argv[]) {
2281    
2282    appdata.vbox = gtk_vbox_new(FALSE, 2);    appdata.vbox = gtk_vbox_new(FALSE, 2);
2283    gtk_container_add(GTK_CONTAINER(appdata.window), appdata.vbox);    gtk_container_add(GTK_CONTAINER(appdata.window), appdata.vbox);
   
2284  #ifndef USE_STACKABLE_WINDOW  #ifndef USE_STACKABLE_WINDOW
2285    menu_create(&appdata);    menu_create(&appdata);
2286  #else  #else

Legend:
Removed from v.24  
changed lines
  Added in v.45