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 133 by harbaum, Mon Oct 12 20:27:55 2009 UTC
# Line 35  Line 35 
35    
36  extern char *strcasestr (__const char *__haystack, __const char *__needle);  extern char *strcasestr (__const char *__haystack, __const char *__needle);
37    
38  #ifdef USE_BREAD_CRUMB_TRAIL  #if defined(USE_BREAD_CRUMB_TRAIL) || defined(BCT)
39  static void crumb_add(appdata_t *appdata, char *name, int level,  static void crumb_add(appdata_t *appdata, char *name, int level,
40                        gpointer user_data);                        gpointer user_data);
41    
# Line 95  void errorf(const char *fmt, ...) { Line 95  void errorf(const char *fmt, ...) {
95    GtkWidget *dialog = gtk_message_dialog_new(    GtkWidget *dialog = gtk_message_dialog_new(
96                             GTK_WINDOW(NULL),                             GTK_WINDOW(NULL),
97                             GTK_DIALOG_DESTROY_WITH_PARENT,                             GTK_DIALOG_DESTROY_WITH_PARENT,
98                             GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE,  #if !defined(USE_MAEMO) || (MAEMO_VERSION_MAJOR < 5)
99                             buf);                             GTK_MESSAGE_ERROR,
100    #else
101                               GTK_MESSAGE_OTHER,
102    #endif
103                               GTK_BUTTONS_CLOSE, buf);
104    
105    gtk_window_set_title(GTK_WINDOW(dialog), _("ERROR"));    gtk_window_set_title(GTK_WINDOW(dialog), _("ERROR"));
106    
# Line 138  gpx_t *choose_file(appdata_t *appdata, g Line 142  gpx_t *choose_file(appdata_t *appdata, g
142    gtk_widget_show_all (GTK_WIDGET(dialog));    gtk_widget_show_all (GTK_WIDGET(dialog));
143    if (gtk_dialog_run (GTK_DIALOG(dialog)) == GTK_FM_OK) {    if (gtk_dialog_run (GTK_DIALOG(dialog)) == GTK_FM_OK) {
144      char *filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));      char *filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
145    
146        if(filename) {
147          gpx_dialog_t *dialog = gpx_busy_dialog_new(GTK_WIDGET(appdata->window));
148    
149      gpx_dialog_t *dialog = gpx_busy_dialog_new(GTK_WIDGET(appdata->window));        if(!whole_dir)
150            gpx = gpx_parse(dialog, filename);
151      if(!whole_dir)        else {
152        gpx = gpx_parse(dialog, filename);          /* cur trailing '/' if present */
153      else {          if(strlastchr(filename) == '/')
154        /* cur trailing '/' if present */            filename[strlen(filename)] = 0;
155        if(strlastchr(filename) == '/')  
156          filename[strlen(filename)] = 0;          gpx = gpx_parse_dir(dialog, filename);
   
       gpx = gpx_parse_dir(dialog, filename);  
     }  
   
     gpx_busy_dialog_destroy(dialog);  
   
     /* save path if gpx was successfully loaded */  
     if(gpx) {  
       char *r = strrchr(filename, '/');  
   
       /* there is a delimiter, use everything left of it as path */  
       if(r && !whole_dir) {  
         *r = 0;  
         if(appdata->path) free(appdata->path);  
         appdata->path = strdup(filename);  
         /* restore path ... just in case ... */  
         *r = '/';  
157        }        }
158    
159          gpx_busy_dialog_destroy(dialog);
160    
161          /* save path if gpx was successfully loaded */
162          if(gpx) {
163            char *r = strrchr(filename, '/');
164    
165            /* there is a delimiter, use everything left of it as path */
166            if(r && !whole_dir) {
167              *r = 0;
168              if(appdata->path) free(appdata->path);
169              appdata->path = strdup(filename);
170              /* restore path ... just in case ... */
171              *r = '/';
172            }
173    
174            if(whole_dir)
175              appdata->path = strdup(filename);
176          } else
177            errorf(_("Load error"));
178    
179        if(whole_dir)        g_free (filename);
180          appdata->path = strdup(filename);      } else {
181    #ifndef USE_MAEMO
182          errorf(_("Error accessing the file."));
183    #else
184          errorf(_("Error accessing the file. This may happen if the file "
185                   "resides on a remote file system. Please copy the file onto "
186                   "the device (e.g. onto the memory card) and try again."));
187    #endif
188      }      }
   
     g_free (filename);  
189    }    }
190    
191    gtk_widget_destroy (dialog);    gtk_widget_destroy (dialog);
# Line 202  void cachelist_view_onRowActivated(GtkTr Line 217  void cachelist_view_onRowActivated(GtkTr
217    GtkTreeIter   iter;    GtkTreeIter   iter;
218    GtkTreeModel *model = gtk_tree_view_get_model(treeview);    GtkTreeModel *model = gtk_tree_view_get_model(treeview);
219    
220    #ifdef USE_MAEMO
221      /* check if a cache is already selected and ignore click if yes */
222      /* (was probably a double click) */
223      if(appdata->cur_cache) return;
224    #endif
225    
226    if(gtk_tree_model_get_iter(model, &iter, path)) {    if(gtk_tree_model_get_iter(model, &iter, path)) {
227      cache_t *cache;      cache_t *cache;
228      gtk_tree_model_get(model, &iter, CACHELIST_COL_DATA, &cache, -1);      gtk_tree_model_get(model, &iter, CACHELIST_COL_DATA, &cache, -1);
229  #ifndef USE_BREAD_CRUMB_TRAIL  #if !defined(USE_BREAD_CRUMB_TRAIL) && !defined(BCT)
230      cache_dialog(appdata, cache);      cache_dialog(appdata, cache);
231  #else  #else
232      gtk_container_remove(GTK_CONTAINER(appdata->vbox), appdata->cur_view);      gtk_container_remove(GTK_CONTAINER(appdata->vbox), appdata->cur_view);
# Line 257  static GtkWidget *cachelist_create(appda Line 278  static GtkWidget *cachelist_create(appda
278                                     cache_t *sel_cache);                                     cache_t *sel_cache);
279    
280  void cachelist_redraw(appdata_t *appdata) {  void cachelist_redraw(appdata_t *appdata) {
 #ifndef USE_MAEMO  
   //  gtk_container_remove(GTK_CONTAINER(appdata->vbox), appdata->cur_view);  
   //  appdata->cur_view = gpxlist_create_view_and_model(appdata, NULL);  
   //  gtk_box_pack_start_defaults(GTK_BOX(appdata->vbox), appdata->cur_view);  
   // gtk_widget_show_all(appdata->vbox);  
 #else  
   
281    if(!appdata->cur_view) {    if(!appdata->cur_view) {
282      printf("cachelist redraw: no active view\n");      printf("cachelist redraw: no active view\n");
283      return;      return;
# Line 281  void cachelist_redraw(appdata_t *appdata Line 295  void cachelist_redraw(appdata_t *appdata
295    if(redraw) {    if(redraw) {
296      GtkWidget *container = appdata->vbox;      GtkWidget *container = appdata->vbox;
297    
     printf("redraw %d\n", redraw);  
   
298  #ifdef USE_STACKABLE_WINDOW  #ifdef USE_STACKABLE_WINDOW
299      HildonWindowStack *stack = hildon_window_stack_get_default();      HildonWindowStack *stack = hildon_window_stack_get_default();
300      container = hildon_window_stack_peek(stack);      container = hildon_window_stack_peek(stack);
# Line 309  void cachelist_redraw(appdata_t *appdata Line 321  void cachelist_redraw(appdata_t *appdata
321    
322      gtk_widget_show_all(container);      gtk_widget_show_all(container);
323    }    }
 #endif  
324  }  }
325    
326    
# Line 317  static gboolean cachelist_update(gpointe Line 328  static gboolean cachelist_update(gpointe
328    
329    printf("cachelist timer fired!\n");    printf("cachelist timer fired!\n");
330    
 #ifdef USE_MAEMO  
331    appdata_t *appdata = (appdata_t*)data;    appdata_t *appdata = (appdata_t*)data;
332    
333    if(appdata->cur_cache)    if(appdata->cur_cache)
334      return TRUE;      return TRUE;
335    
336    #ifdef USE_MAEMO
337    if(appdata->cachelist_disable_screensaver)    if(appdata->cachelist_disable_screensaver)
338      if (osso_display_blanking_pause(appdata->osso_context) != OSSO_OK)      if (osso_display_blanking_pause(appdata->osso_context) != OSSO_OK)
339        fprintf(stderr, "error with display blank\n");        fprintf(stderr, "error with display blank\n");
340    #endif
341    
342    if(appdata->cachelist_update)    if(appdata->cachelist_update)
343      cachelist_redraw(appdata);      cachelist_redraw(appdata);
 #endif  
344    
345    return TRUE;    return TRUE;
346  }  }
# Line 576  void on_cachelist_destroy(GtkWidget *wid Line 587  void on_cachelist_destroy(GtkWidget *wid
587    }    }
588    appdata->cur_gpx = NULL;    appdata->cur_gpx = NULL;
589    
590    #ifdef ENABLE_OSM_GPS_MAP
591      map_update(appdata);
592    #endif
593    
594    /* restore cur_view */    /* restore cur_view */
595    appdata->cur_view = g_object_get_data(G_OBJECT(widget), "cur_view");    appdata->cur_view = g_object_get_data(G_OBJECT(widget), "cur_view");
596  }  }
# Line 587  void cachelist_dialog(appdata_t *appdata Line 602  void cachelist_dialog(appdata_t *appdata
602    g_object_set_data(G_OBJECT(window), "cur_view", appdata->cur_view);    g_object_set_data(G_OBJECT(window), "cur_view", appdata->cur_view);
603    
604    appdata->cur_gpx = gpx;    appdata->cur_gpx = gpx;
605    char *title = g_strdup_printf("GPXView - %s", gpx->name);    char *title = g_strdup_printf("%s - GPXView", gpx->name);
606    gtk_window_set_title(GTK_WINDOW(window), title);    gtk_window_set_title(GTK_WINDOW(window), title);
607    g_free(title);    g_free(title);
608    
# Line 602  void cachelist_dialog(appdata_t *appdata Line 617  void cachelist_dialog(appdata_t *appdata
617                     G_CALLBACK(on_cachelist_destroy), appdata);                     G_CALLBACK(on_cachelist_destroy), appdata);
618    
619    gtk_widget_show_all(window);    gtk_widget_show_all(window);
620    
621    #ifdef ENABLE_OSM_GPS_MAP
622      map_update(appdata);
623    #endif
624  }  }
625  #endif  #endif
626  #endif  #endif
# Line 713  static void gpxlist_view_onRowActivated( Line 732  static void gpxlist_view_onRowActivated(
732    GtkTreeIter   iter;    GtkTreeIter   iter;
733    GtkTreeModel *model = gtk_tree_view_get_model(treeview);    GtkTreeModel *model = gtk_tree_view_get_model(treeview);
734    
735    #ifdef USE_MAEMO
736      /* check if a cache is already selected and ignore click if yes */
737      /* (was probably a double click) */
738      if(appdata->cur_gpx) return;
739    #endif
740    
741    if (gtk_tree_model_get_iter(model, &iter, path)) {    if (gtk_tree_model_get_iter(model, &iter, path)) {
742      gpx_t *gpx;      gpx_t *gpx;
743      gtk_tree_model_get(model, &iter, GPXLIST_COL_DATA, &gpx, -1);      gtk_tree_model_get(model, &iter, GPXLIST_COL_DATA, &gpx, -1);
# Line 729  static void gpxlist_view_onRowActivated( Line 754  static void gpxlist_view_onRowActivated(
754        GtkWidget *dialog = gtk_message_dialog_new(        GtkWidget *dialog = gtk_message_dialog_new(
755                   GTK_WINDOW(appdata->window),                   GTK_WINDOW(appdata->window),
756                   GTK_DIALOG_DESTROY_WITH_PARENT,                   GTK_DIALOG_DESTROY_WITH_PARENT,
757                   GTK_MESSAGE_QUESTION, GTK_BUTTONS_CANCEL,                   /* this doesn't fix the text selection issues ... */
758    #if defined(USE_MAEMO) && (MAEMO_VERSION_MAJOR >=5)
759                     GTK_MESSAGE_OTHER,
760    #else
761                     GTK_MESSAGE_QUESTION,
762    #endif
763                     GTK_BUTTONS_CANCEL,
764                   _("Do you want to close this entry only or do "                   _("Do you want to close this entry only or do "
765                     "you want to remove it completely from the list?"));                     "you want to remove it completely from the list?"));
766    
# Line 741  static void gpxlist_view_onRowActivated( Line 772  static void gpxlist_view_onRowActivated(
772        if(gpx->closed)        if(gpx->closed)
773          gtk_dialog_set_response_sensitive(GTK_DIALOG(dialog), 2, FALSE);          gtk_dialog_set_response_sensitive(GTK_DIALOG(dialog), 2, FALSE);
774    
775        gtk_window_set_title(GTK_WINDOW(dialog), _("Remove entry?"));        gtk_window_set_title(GTK_WINDOW(dialog), _("Close or remove entry?"));
776    
777        /* set the active flag again if the user answered "no" */        /* set the active flag again if the user answered "no" */
778        switch(gtk_dialog_run(GTK_DIALOG(dialog))) {        switch(gtk_dialog_run(GTK_DIALOG(dialog))) {
# Line 810  static void gpxlist_view_onRowActivated( Line 841  static void gpxlist_view_onRowActivated(
841    
842          gpx_busy_dialog_destroy(dialog);          gpx_busy_dialog_destroy(dialog);
843        }        }
844  #ifndef USE_BREAD_CRUMB_TRAIL  #if !defined(USE_BREAD_CRUMB_TRAIL) && !defined(BCT)
845  #ifdef USE_STACKABLE_WINDOW  #ifdef USE_STACKABLE_WINDOW
846        if(!appdata->cur_gpx)        if(!appdata->cur_gpx)
847  #endif  #endif
# Line 957  static GtkWidget *gpxlist_create_view_an Line 988  static GtkWidget *gpxlist_create_view_an
988      GtkTreeIter         iter;      GtkTreeIter         iter;
989      gtk_list_store_append(appdata->gpxstore, &iter);      gtk_list_store_append(appdata->gpxstore, &iter);
990      gpxlist_set(appdata->gpxstore, &iter, gpx);      gpxlist_set(appdata->gpxstore, &iter, gpx);
991    
992      if(gpx == sel_gpx) {      if(gpx == sel_gpx) {
993        sel_iter = iter;        sel_iter = iter;
994        sel_iter_valid = TRUE;        sel_iter_valid = TRUE;
# Line 1017  static void gpxlist_add(appdata_t *appda Line 1048  static void gpxlist_add(appdata_t *appda
1048    
1049  /******************** begin of menu *********************/  /******************** begin of menu *********************/
1050    
1051    typedef struct {
1052      appdata_t *appdata;
1053      GtkWidget *dialog;
1054    } about_context_t;
1055    
1056    #ifdef ENABLE_BROWSER_INTERFACE
1057    void on_paypal_button_clicked(GtkButton *button, about_context_t *context) {
1058      gtk_dialog_response(GTK_DIALOG(context->dialog), GTK_RESPONSE_ACCEPT);
1059      browser_url(context->appdata,
1060                  "https://www.paypal.com/cgi-bin/webscr"
1061                  "?cmd=_s-xclick&hosted_button_id=7400558");
1062    }
1063    #endif
1064    
1065  static void  static void
1066  cb_menu_about(GtkWidget *window, gpointer data) {  cb_menu_about(GtkWidget *window, gpointer data) {
1067    GtkAboutDialog *about = GTK_ABOUT_DIALOG(gtk_about_dialog_new());    about_context_t context;
1068    
1069    gtk_about_dialog_set_name(about, "GPXView");    context.appdata = (appdata_t *)data;
   gtk_about_dialog_set_version(about, VERSION);  
1070    
1071  #ifdef ENABLE_LIBLOCATION  #ifdef ENABLE_LIBLOCATION
1072    char *uses = "uses liblocation";    char *uses = "uses liblocation";
# Line 1032  cb_menu_about(GtkWidget *window, gpointe Line 1076  cb_menu_about(GtkWidget *window, gpointe
1076    char *uses = "uses gpsd";    char *uses = "uses gpsd";
1077  #endif  #endif
1078    
1079    char *str = g_strdup_printf("%s\n\n(%s)",    const gchar *authors[] = {
1080                        _("GPXView (c) 2008-2009 by\n"      "Till Harbaum <till@harbaum.org>",
1081                          "Till Harbaum <till@harbaum.org>\n"      "John Stowers <john.stowers@gmail.com>",
1082                          "Mailing list: gpxview-users@garage.maemo.org"),      NULL };
1083                        _(uses)  
1084                        );    context.dialog = g_object_new(GTK_TYPE_ABOUT_DIALOG,
1085                            "name", "GPXView",
1086    gtk_about_dialog_set_copyright(about, str);                          "version", VERSION,
1087    g_free(str);                          "copyright", _("Copyright 2008-2009"),
1088                            "authors", authors,
1089    gtk_about_dialog_set_website(about,                          "website", _("http://www.harbaum.org/till/maemo"),
1090         _("http://www.harbaum.org/till/maemo"));                          "comments", _(uses),
1091                            NULL);
1092    gtk_about_dialog_set_comments(about,  
1093         _("Geocaching.com GPX file viewer"));  #ifdef ENABLE_BROWSER_INTERFACE
1094      /* add a way to donate to the project */
1095    gtk_widget_show_all(GTK_WIDGET(about));    GtkWidget *alignment = gtk_alignment_new(0.5, 0, 0, 0);
1096    gtk_dialog_run(GTK_DIALOG(about));  
1097    gtk_widget_destroy(GTK_WIDGET(about));    GtkWidget *hbox = gtk_hbox_new(FALSE, 8);
1098      gtk_box_pack_start(GTK_BOX(hbox),
1099                         gtk_label_new(_("Do you like GPXView?")),
1100                         FALSE, FALSE, 0);
1101    
1102      GtkWidget *button = gtk_button_new();
1103      gtk_button_set_image(GTK_BUTTON(button),
1104                           icon_get_widget(ICON_MISC, 8));
1105      gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE);
1106      g_signal_connect(button, "clicked",
1107                       G_CALLBACK(on_paypal_button_clicked), &context);
1108      gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0);
1109    
1110      gtk_container_add(GTK_CONTAINER(alignment), hbox);
1111      gtk_box_pack_start_defaults(GTK_BOX((GTK_DIALOG(context.dialog))->vbox),
1112                                  alignment);
1113    
1114      gtk_widget_show_all(alignment);
1115    #endif
1116    
1117      gtk_dialog_run(GTK_DIALOG(context.dialog));
1118      gtk_widget_destroy(context.dialog);
1119  }  }
1120    
1121  #if defined(USE_MAEMO) && defined(HILDON_HELP)  #if defined(USE_MAEMO) && defined(HILDON_HELP)
# Line 1399  cb_menu_search(GtkWidget *window, gpoint Line 1464  cb_menu_search(GtkWidget *window, gpoint
1464    
1465        printf("Search for %s (flags = %x)...\n", p, appdata->search);        printf("Search for %s (flags = %x)...\n", p, appdata->search);
1466    
1467  #ifndef USE_BREAD_CRUMB_TRAIL  #if !defined(USE_BREAD_CRUMB_TRAIL) && !defined(BCT)
1468        gpx_t *found =        gpx_t *found =
1469          search_do(appdata, appdata->gpx, p, appdata->search, FALSE);          search_do(appdata, appdata->gpx, p, appdata->search, FALSE);
1470    
# Line 1433  cb_menu_search(GtkWidget *window, gpoint Line 1498  cb_menu_search(GtkWidget *window, gpoint
1498      gtk_widget_destroy(dialog);      gtk_widget_destroy(dialog);
1499  }  }
1500    
1501  void on_window_destroy (GtkWidget *widget, gpointer data);  static void on_window_destroy (GtkWidget *widget, gpointer data);
1502    
1503  #ifndef USE_MAEMO  #ifndef USE_MAEMO
1504  static void  static void
# Line 1495  cb_menu_export_log(GtkWidget *widget, gp Line 1560  cb_menu_export_log(GtkWidget *widget, gp
1560    notes_log_export(appdata);    notes_log_export(appdata);
1561  }  }
1562    
1563  #ifdef USE_MAEMO  #ifdef ENABLE_MAEMO_MAPPER
1564  static void  static void
1565  cb_menu_export_mmpoi(GtkWidget *widget, gpointer data) {  cb_menu_export_mmpoi(GtkWidget *widget, gpointer data) {
1566    appdata_t *appdata = (appdata_t*)data;    appdata_t *appdata = (appdata_t*)data;
# Line 1509  cb_menu_export_garmin(GtkWidget *widget, Line 1574  cb_menu_export_garmin(GtkWidget *widget,
1574    garmin_export(appdata);    garmin_export(appdata);
1575  }  }
1576    
1577    #ifdef ENABLE_OSM_GPS_MAP
1578    static void
1579    cb_menu_map(GtkWidget *window, gpointer data) {
1580      map((appdata_t *)data);
1581    }
1582    #endif
1583    
1584  static void  static void
1585  cb_menu_geomath(GtkWidget *window, gpointer data) {  cb_menu_geomath(GtkWidget *window, gpointer data) {
1586    geomath_dialog((appdata_t *)data);    geomath_dialog((appdata_t *)data);
# Line 1525  cb_menu_precpos(GtkWidget *window, gpoin Line 1597  cb_menu_precpos(GtkWidget *window, gpoin
1597  }  }
1598    
1599  #ifdef USE_STACKABLE_WINDOW  #ifdef USE_STACKABLE_WINDOW
1600  static GtkWidget *export_menu_create(appdata_t *appdata) {  typedef struct {
1601    GtkWidget *button;    char *label, *desc;
1602    HildonAppMenu *menu = HILDON_APP_MENU(hildon_app_menu_new());    GtkSignalFunc activate_cb;
1603    } 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));  
1604    
1605    button = hildon_button_new_with_text(  typedef struct {
1606              HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH,    const char *title;
1607              HILDON_BUTTON_ARRANGEMENT_VERTICAL,    const menu_entry_t *menu;
1608              _("Export Field Notes"),    int len;
1609              _("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));  
1610    
1611    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));  
1612    
1613    gtk_widget_show_all(GTK_WIDGET(menu));  void on_submenu_entry_clicked(GtkButton *button, GtkWidget *menu) {
1614    
1615    return GTK_WIDGET(menu);    /* force closing of submenu dialog */
1616      gtk_dialog_response(GTK_DIALOG(menu), GTK_RESPONSE_NONE);
1617      gtk_widget_hide(menu);
1618    
1619      /* let gtk clean up */
1620      while(gtk_events_pending())
1621        gtk_main_iteration();
1622  }  }
1623    
1624  /* the export submenu */  static GtkWidget *app_submenu_create(appdata_t *appdata,
1625  void on_export_clicked(GtkButton *button, appdata_t *appdata) {                                       const submenu_t *submenu) {
   if(!appdata->export_menu)  
     appdata->export_menu = export_menu_create(appdata);  
1626    
1627    /* draw a popup menu */    /* create a oridinary dialog box */
1628    hildon_app_menu_popup(HILDON_APP_MENU(appdata->export_menu),    GtkWidget *dialog = gtk_dialog_new();
1629                          GTK_WINDOW(hildon_window_stack_peek(    gtk_window_set_title(GTK_WINDOW(dialog), _(submenu->title));
1630                      hildon_window_stack_get_default())));    gtk_window_set_modal(GTK_WINDOW(dialog), TRUE);
1631  }    gtk_window_set_transient_for(GTK_WINDOW(dialog),
1632                                   GTK_WINDOW(appdata->window));
1633      gtk_dialog_set_has_separator(GTK_DIALOG(dialog), FALSE);
1634    
1635  static GtkWidget *tools_menu_create(appdata_t *appdata) {    GtkWidget *table = gtk_table_new(submenu->len/COLUMNS, COLUMNS, TRUE);
1636    GtkWidget *button;    int x = 0, y = 0;
   HildonAppMenu *menu = HILDON_APP_MENU(hildon_app_menu_new());  
1637    
1638    /* the following doesn't have an effect */    const menu_entry_t *menu_entries = submenu->menu;
1639    //  gtk_window_set_title(GTK_WINDOW(menu), "Tools");    while(menu_entries->label) {
1640        GtkWidget *button = NULL;
1641    
1642    button = hildon_button_new_with_text(      button = hildon_button_new_with_text(
1643              HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH,              HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH,
1644              HILDON_BUTTON_ARRANGEMENT_VERTICAL,              HILDON_BUTTON_ARRANGEMENT_VERTICAL,
1645              _("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));  
1646    
1647        /* try to center both texts */
1648        hildon_button_set_title_alignment(HILDON_BUTTON(button), 0.5, 0.5);
1649        hildon_button_set_value_alignment(HILDON_BUTTON(button), 0.5, 0.5);
1650    
1651    button = hildon_button_new_with_text(      g_signal_connect(button, "clicked",
1652              HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH,                       G_CALLBACK(on_submenu_entry_clicked), dialog);
1653              HILDON_BUTTON_ARRANGEMENT_VERTICAL,  
1654              _("Geotext"),      g_signal_connect(button, "clicked",
1655              _("Text analysis"));                       menu_entries->activate_cb, appdata);
1656    g_signal_connect_after(button, "clicked",  
1657                     G_CALLBACK(cb_menu_geotext), appdata);      gtk_table_attach_defaults(GTK_TABLE(table),  button, x, x+1, y, y+1);
1658    hildon_app_menu_append(menu, GTK_BUTTON(button));  
1659        x++;
1660        if(x == COLUMNS) { x = 0; y++; }
1661    
1662    button = hildon_button_new_with_text(      menu_entries++;
1663              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));  
1664    
1665    gtk_widget_show_all(GTK_WIDGET(menu));    gtk_box_pack_start_defaults(GTK_BOX(GTK_DIALOG(dialog)->vbox), table);
1666    
1667    return GTK_WIDGET(menu);    return dialog;
1668  }  }
1669    
1670    /* popup the dialog shaped submenu */
1671    static void submenu_popup(GtkWidget *menu) {
1672      gtk_widget_show_all(menu);
1673      gtk_dialog_run(GTK_DIALOG(menu));
1674      gtk_widget_hide(menu);
1675    }
1676    
1677    static void submenu_cleanup(GtkWidget *menu) {
1678      gtk_widget_destroy(menu);
1679    }
1680    
1681    static const menu_entry_t submenu_export_entries[] = {
1682    #ifdef ENABLE_MAEMO_MAPPER
1683      { "Export to Maemo Mapper" , "Save a Maemo Mapper POI file",
1684        G_CALLBACK(cb_menu_export_mmpoi)  },
1685    #endif
1686      { "Export Field Notes",      "Save a Garmin Field Notes file",
1687        G_CALLBACK(cb_menu_export_log)    },
1688      { "Export Garmin GPX",       "Save modified waypoints in GPX file",
1689        G_CALLBACK(cb_menu_export_garmin) },
1690      { NULL, NULL, NULL }
1691    };
1692    
1693    static const submenu_t submenu_export = {
1694      "Export", submenu_export_entries,
1695      sizeof(submenu_export_entries)/sizeof(menu_entry_t)-1
1696    };
1697    
1698    /* the export submenu */
1699    void on_export_clicked(GtkButton *button, appdata_t *appdata) {
1700      if(!appdata->export_menu)
1701        appdata->export_menu = app_submenu_create(appdata, &submenu_export);
1702    
1703      submenu_popup(appdata->export_menu);
1704    }
1705    
1706    static const menu_entry_t submenu_tools_entries[] = {
1707      { "Geomath",          "Geocoordinate calculation",
1708        G_CALLBACK(cb_menu_geomath) },
1709      { "Geotext",          "Text analysis",
1710        G_CALLBACK(cb_menu_geotext) },
1711      { "Precise Position", "Calculate a precise GPS position",
1712        G_CALLBACK(cb_menu_precpos) },
1713      { NULL, NULL, NULL }
1714    };
1715    
1716    static const submenu_t submenu_tools = {
1717      "Tools", submenu_tools_entries,
1718      sizeof(submenu_tools_entries)/sizeof(menu_entry_t)-1
1719    };
1720    
1721  /* the tools submenu */  /* the tools submenu */
1722  void on_tools_clicked(GtkButton *button, appdata_t *appdata) {  void on_tools_clicked(GtkButton *button, appdata_t *appdata) {
1723    if(!appdata->tools_menu)    if(!appdata->tools_menu)
1724      appdata->tools_menu = tools_menu_create(appdata);      appdata->tools_menu = app_submenu_create(appdata, &submenu_tools);
1725    
1726    /* 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())));  
1727  }  }
1728    
   
1729  HildonAppMenu *menu_create(appdata_t *appdata, int mode) {  HildonAppMenu *menu_create(appdata_t *appdata, int mode) {
1730    GtkWidget *button;    GtkWidget *button;
1731    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 1751  HildonAppMenu *menu_create(appdata_t *ap
1751      g_signal_connect_after(button, "clicked",      g_signal_connect_after(button, "clicked",
1752                             G_CALLBACK(cb_menu_adddir), appdata);                             G_CALLBACK(cb_menu_adddir), appdata);
1753      hildon_app_menu_append(menu, GTK_BUTTON(button));      hildon_app_menu_append(menu, GTK_BUTTON(button));
   }  
1754    
   if(mode == MENU_GPXLIST) {  
1755      button = gtk_button_new_with_label(_("Export"));      button = gtk_button_new_with_label(_("Export"));
1756      g_signal_connect_after(button, "clicked",      g_signal_connect_after(button, "clicked",
1757                             G_CALLBACK(on_export_clicked), appdata);                             G_CALLBACK(on_export_clicked), appdata);
# Line 1669  HildonAppMenu *menu_create(appdata_t *ap Line 1768  HildonAppMenu *menu_create(appdata_t *ap
1768                           G_CALLBACK(on_tools_clicked), appdata);                           G_CALLBACK(on_tools_clicked), appdata);
1769    hildon_app_menu_append(menu, GTK_BUTTON(button));    hildon_app_menu_append(menu, GTK_BUTTON(button));
1770    
1771    #ifdef ENABLE_OSM_GPS_MAP
1772        button = gtk_button_new_with_label(_("Map"));
1773        g_signal_connect_after(button, "clicked",
1774                               G_CALLBACK(cb_menu_map), appdata);
1775        hildon_app_menu_append(menu, GTK_BUTTON(button));
1776    #endif
1777    
1778  #ifdef HILDON_HELP  #ifdef HILDON_HELP
1779    button = gtk_button_new_with_label(_("Help"));    button = gtk_button_new_with_label(_("Help"));
1780    g_signal_connect_after(button, "clicked",    g_signal_connect_after(button, "clicked",
# Line 1686  void menu_create(appdata_t *appdata) { Line 1792  void menu_create(appdata_t *appdata) {
1792    GtkWidget *menu, *item;    GtkWidget *menu, *item;
1793    menu = gtk_menu_new();    menu = gtk_menu_new();
1794    
1795  #ifdef USE_BREAD_CRUMB_TRAIL  #if defined(USE_BREAD_CRUMB_TRAIL) || defined(BCT)
1796    appdata->menu_import =    appdata->menu_import =
1797  #endif  #endif
1798    item = gtk_menu_item_new_with_label(_("Import"));    item = gtk_menu_item_new_with_label(_("Import"));
# Line 1716  void menu_create(appdata_t *appdata) { Line 1822  void menu_create(appdata_t *appdata) {
1822    g_signal_connect(item, "activate", GTK_SIGNAL_FUNC(cb_menu_remove), appdata);    g_signal_connect(item, "activate", GTK_SIGNAL_FUNC(cb_menu_remove), appdata);
1823  #endif  #endif
1824    
1825  #ifdef USE_BREAD_CRUMB_TRAIL  #if defined(USE_BREAD_CRUMB_TRAIL) || defined(BCT)
1826    appdata->menu_export =    appdata->menu_export =
1827  #endif  #endif
1828      item = gtk_menu_item_new_with_label(_("Export"));      item = gtk_menu_item_new_with_label(_("Export"));
# Line 1724  void menu_create(appdata_t *appdata) { Line 1830  void menu_create(appdata_t *appdata) {
1830    submenu = gtk_menu_new();    submenu = gtk_menu_new();
1831    gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), submenu);    gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), submenu);
1832    
1833  #ifdef USE_MAEMO  #ifdef ENABLE_MAEMO_MAPPER
1834    item = gtk_menu_item_new_with_label( _("Maemo Mapper POI") );    item = gtk_menu_item_new_with_label( _("Maemo Mapper POI") );
1835    gtk_menu_append(GTK_MENU_SHELL(submenu), item);    gtk_menu_append(GTK_MENU_SHELL(submenu), item);
1836    g_signal_connect(item, "activate",    g_signal_connect(item, "activate",
# Line 1741  void menu_create(appdata_t *appdata) { Line 1847  void menu_create(appdata_t *appdata) {
1847    g_signal_connect(item, "activate",    g_signal_connect(item, "activate",
1848                     GTK_SIGNAL_FUNC(cb_menu_export_garmin), appdata);                     GTK_SIGNAL_FUNC(cb_menu_export_garmin), appdata);
1849    
1850  #ifdef USE_BREAD_CRUMB_TRAIL  #if defined(USE_BREAD_CRUMB_TRAIL) || defined(BCT)
1851    appdata->menu_search =    appdata->menu_search =
1852  #endif  #endif
1853    item = gtk_menu_item_new_with_label( _("Search") );    item = gtk_menu_item_new_with_label( _("Search") );
# Line 1750  void menu_create(appdata_t *appdata) { Line 1856  void menu_create(appdata_t *appdata) {
1856    
1857    gtk_menu_append(GTK_MENU_SHELL(menu), gtk_separator_menu_item_new());    gtk_menu_append(GTK_MENU_SHELL(menu), gtk_separator_menu_item_new());
1858    
 #ifndef NO_COPY_N_PASTE  
1859    /* ----------- copy'n paste submenu ----------------- */    /* ----------- copy'n paste submenu ----------------- */
1860    appdata->clipboard = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD);  #ifndef NO_COPY_N_PASTE
   gtk_clipboard_set_can_store(appdata->clipboard, NULL, 0);  
   
1861    item = gtk_menu_item_new_with_label(_("Edit"));    item = gtk_menu_item_new_with_label(_("Edit"));
1862    gtk_menu_append(GTK_MENU_SHELL(menu), item);    gtk_menu_append(GTK_MENU_SHELL(menu), item);
1863    submenu = gtk_menu_new();    submenu = gtk_menu_new();
# Line 1781  void menu_create(appdata_t *appdata) { Line 1884  void menu_create(appdata_t *appdata) {
1884    
1885    gtk_menu_append(GTK_MENU_SHELL(menu), gtk_separator_menu_item_new());    gtk_menu_append(GTK_MENU_SHELL(menu), gtk_separator_menu_item_new());
1886    
1887    #ifdef ENABLE_OSM_GPS_MAP
1888      item = gtk_menu_item_new_with_label( _("Map") );
1889      gtk_menu_append(GTK_MENU_SHELL(menu), item);
1890      g_signal_connect(item, "activate",
1891                       GTK_SIGNAL_FUNC(cb_menu_map), appdata);
1892    #endif
1893    
1894    item = gtk_menu_item_new_with_label(_("Tools"));    item = gtk_menu_item_new_with_label(_("Tools"));
1895    gtk_menu_append(GTK_MENU_SHELL(menu), item);    gtk_menu_append(GTK_MENU_SHELL(menu), item);
1896    submenu = gtk_menu_new();    submenu = gtk_menu_new();
# Line 1845  void cleanup(appdata_t *appdata) { Line 1955  void cleanup(appdata_t *appdata) {
1955    if(appdata->image_path) free(appdata->image_path);    if(appdata->image_path) free(appdata->image_path);
1956    if(appdata->search_str) free(appdata->search_str);    if(appdata->search_str) free(appdata->search_str);
1957    
1958    #ifdef USE_STACKABLE_WINDOW
1959      if(appdata->export_menu) submenu_cleanup(appdata->export_menu);
1960      if(appdata->tools_menu)  submenu_cleanup(appdata->tools_menu);
1961    #endif
1962    
1963    gnome_vfs_shutdown();    gnome_vfs_shutdown();
1964    icons_free();    icons_free();
1965    gps_release(appdata);    gps_release(appdata);
# Line 1873  void cleanup(appdata_t *appdata) { Line 1988  void cleanup(appdata_t *appdata) {
1988    puts("everything is gone");    puts("everything is gone");
1989  }  }
1990    
1991  void on_window_destroy (GtkWidget *widget, gpointer data) {  static void on_window_destroy (GtkWidget *widget, gpointer data) {
1992    appdata_t *appdata = (appdata_t*)data;    appdata_t *appdata = (appdata_t*)data;
1993    
1994    gconf_save_state(appdata);    gconf_save_state(appdata);
# Line 1936  gboolean on_window_key_press(GtkWidget * Line 2051  gboolean on_window_key_press(GtkWidget *
2051    return handled;    return handled;
2052  }  }
2053    
2054  #ifdef USE_BREAD_CRUMB_TRAIL  #if defined(USE_BREAD_CRUMB_TRAIL) || defined(BCT)
2055  typedef struct {  typedef struct {
2056    int level;    int level;
2057    appdata_t *appdata;    appdata_t *appdata;
# Line 2028  crumb_back(gpointer data) { Line 2143  crumb_back(gpointer data) {
2143    
2144    gtk_widget_show_all(crumb->appdata->vbox);    gtk_widget_show_all(crumb->appdata->vbox);
2145    g_free(data);    g_free(data);
2146    
2147    #ifdef ENABLE_OSM_GPS_MAP
2148      map_update(crumb->appdata);
2149    #endif
2150  }  }
2151    
2152  static void crumb_add(appdata_t *appdata, char *name, int level,  static void crumb_add(appdata_t *appdata, char *name, int level,
# Line 2068  static void crumb_add(appdata_t *appdata Line 2187  static void crumb_add(appdata_t *appdata
2187  #endif  #endif
2188    }    }
2189    
2190    #ifdef USE_BREAD_CRUMB_TRAIL
2191    hildon_bread_crumb_trail_push_text(HILDON_BREAD_CRUMB_TRAIL(appdata->bct),    hildon_bread_crumb_trail_push_text(HILDON_BREAD_CRUMB_TRAIL(appdata->bct),
2192                                       name, crumb, (GDestroyNotify)crumb_back);                                       name, crumb, (GDestroyNotify)crumb_back);
2193    #else
2194      bct_push_text(appdata->bct, name, crumb, (GDestroyNotify)crumb_back);
2195    #endif
2196    
2197    #ifdef ENABLE_OSM_GPS_MAP
2198      map_update(appdata);
2199    #endif
2200  }  }
2201  #endif // USE_BREAD_CRUMB_TRAIL  #endif // USE_BREAD_CRUMB_TRAIL
2202    
# Line 2081  void main_after_settings_redraw(appdata_ Line 2208  void main_after_settings_redraw(appdata_
2208      return;      return;
2209    }    }
2210    
 #ifndef USE_MAEMO  
   // in non-maemo setup this can only affect the main screen as  
   // the menu is blocked while a dialog is open. also the main  
   // screen is always present  
   if(appdata->gpxlist_items != appdata->cur_items) {  
     /* re-do the main screen */  
     gtk_container_remove(GTK_CONTAINER(appdata->vbox), appdata->cur_view);  
     appdata->cur_view = gpxlist_create_view_and_model(appdata, NULL);  
     gtk_box_pack_start_defaults(GTK_BOX(appdata->vbox), appdata->cur_view);  
     gtk_widget_show_all(appdata->vbox);  
   }  
 #else  
2211    /* a cache screen cannot be changed from the settings and thus doesn't */    /* a cache screen cannot be changed from the settings and thus doesn't */
2212    /* need to be redrawn */    /* need to be redrawn */
2213    if(appdata->cur_cache) {    if(appdata->cur_cache) {
# Line 2147  void main_after_settings_redraw(appdata_ Line 2262  void main_after_settings_redraw(appdata_
2262    
2263      gtk_widget_show_all(container);      gtk_widget_show_all(container);
2264    }    }
 #endif // USE_MAEMO  
2265  }  }
2266    
2267  int main(int argc, char *argv[]) {  int main(int argc, char *argv[]) {
# Line 2176  int main(int argc, char *argv[]) { Line 2290  int main(int argc, char *argv[]) {
2290      fprintf(stderr, "error initiating osso context\n");      fprintf(stderr, "error initiating osso context\n");
2291    }    }
2292    
2293    #ifdef ENABLE_MAEMO_MAPPER
2294    dbus_register(&appdata);    dbus_register(&appdata);
2295  #endif  #endif
2296    #endif
2297    
2298    icons_init();    icons_init();
2299    
# Line 2201  int main(int argc, char *argv[]) { Line 2317  int main(int argc, char *argv[]) {
2317    /* Create a Window. */    /* Create a Window. */
2318    appdata.window = gtk_window_new(GTK_WINDOW_TOPLEVEL);    appdata.window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
2319    /* Set a decent default size for the window. */    /* Set a decent default size for the window. */
2320    gtk_window_set_default_size(GTK_WINDOW(appdata.window), 500, 300);    gtk_window_set_default_size(GTK_WINDOW(appdata.window), 640, 480);
2321  #endif  #endif
2322    
2323  #if MAEMO_VERSION_MAJOR == 5  #if MAEMO_VERSION_MAJOR == 5
# Line 2214  int main(int argc, char *argv[]) { Line 2330  int main(int argc, char *argv[]) {
2330    g_signal_connect(G_OBJECT(appdata.window), "key_press_event",    g_signal_connect(G_OBJECT(appdata.window), "key_press_event",
2331                     G_CALLBACK(on_window_key_press), &appdata);                     G_CALLBACK(on_window_key_press), &appdata);
2332    
2333      /* prepare clipboard */
2334      appdata.clipboard = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD);
2335      gtk_clipboard_set_can_store(appdata.clipboard, NULL, 0);
2336    
2337    appdata.vbox = gtk_vbox_new(FALSE, 2);    appdata.vbox = gtk_vbox_new(FALSE, 2);
2338    gtk_container_add(GTK_CONTAINER(appdata.window), appdata.vbox);    gtk_container_add(GTK_CONTAINER(appdata.window), appdata.vbox);
   
2339  #ifndef USE_STACKABLE_WINDOW  #ifndef USE_STACKABLE_WINDOW
2340    menu_create(&appdata);    menu_create(&appdata);
2341  #else  #else
# Line 2230  int main(int argc, char *argv[]) { Line 2349  int main(int argc, char *argv[]) {
2349    gtk_box_pack_start(GTK_BOX(appdata.vbox), appdata.bct, FALSE,FALSE,0);    gtk_box_pack_start(GTK_BOX(appdata.vbox), appdata.bct, FALSE,FALSE,0);
2350    
2351    hildon_bread_crumb_trail_clear(HILDON_BREAD_CRUMB_TRAIL(appdata.bct));    hildon_bread_crumb_trail_clear(HILDON_BREAD_CRUMB_TRAIL(appdata.bct));
2352    #else
2353    #ifdef BCT
2354      /* on non-hildon machines we use some custom made breadcrumbtrail */
2355      /* replacement */
2356      appdata.bct = bct_new();
2357      gtk_box_pack_start(GTK_BOX(appdata.vbox), appdata.bct, FALSE,FALSE,0);
2358    #endif
2359    #endif
2360    
2361    #if defined(USE_BREAD_CRUMB_TRAIL) || defined(BCT)
2362    crumb_add(&appdata, "GPX", CRUMB_GPXLIST, NULL);    crumb_add(&appdata, "GPX", CRUMB_GPXLIST, NULL);
2363  #endif  #endif
2364    

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