Diff of /trunk/src/main.c

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

revision 206 by harbaum, Tue Nov 24 12:42:31 2009 UTC revision 233 by harbaum, Wed Dec 9 19:45:36 2009 UTC
# Line 36  Line 36 
36  #if MAEMO_VERSION_MAJOR >= 5  #if MAEMO_VERSION_MAJOR >= 5
37  #include <hildon/hildon-note.h>  #include <hildon/hildon-note.h>
38  #include <hildon/hildon-entry.h>  #include <hildon/hildon-entry.h>
 #include <hildon/hildon-check-button.h>  
39  #endif  #endif
40  #endif  #endif
41    
# Line 223  void cachelist_goto_cache(appdata_t *app Line 222  void cachelist_goto_cache(appdata_t *app
222  #if !defined(USE_BREAD_CRUMB_TRAIL) && !defined(BCT)  #if !defined(USE_BREAD_CRUMB_TRAIL) && !defined(BCT)
223      cache_dialog(appdata, cache);      cache_dialog(appdata, cache);
224  #else  #else
225        crumb_add(appdata, cache->name, CRUMB_CACHE, cache);
226    
227      gtk_container_remove(GTK_CONTAINER(appdata->vbox), appdata->cur_view);      gtk_container_remove(GTK_CONTAINER(appdata->vbox), appdata->cur_view);
228      appdata->cur_view = cache_view(appdata, cache);      appdata->cur_view = cache_view(appdata, cache);
229      gtk_box_pack_start_defaults(GTK_BOX(appdata->vbox), appdata->cur_view);      gtk_box_pack_start_defaults(GTK_BOX(appdata->vbox), appdata->cur_view);
230      gtk_widget_show_all(appdata->vbox);      gtk_widget_show_all(appdata->vbox);
   
     crumb_add(appdata, cache->name, CRUMB_CACHE, cache);  
231  #endif  #endif
232  }  }
233    
# Line 597  void cachelist_dialog(appdata_t *appdata Line 596  void cachelist_dialog(appdata_t *appdata
596  static void search_result_free(gpx_t *result);  static void search_result_free(gpx_t *result);
597    
598  void on_cachelist_destroy(GtkWidget *widget, appdata_t *appdata) {  void on_cachelist_destroy(GtkWidget *widget, appdata_t *appdata) {
599      printf("cachelist destroy\n");
600    
601      HildonWindowStack *stack = hildon_window_stack_get_default();
602      appdata->window = HILDON_WINDOW(hildon_window_stack_peek(stack));
603    
604    if(appdata->search_results) {    if(appdata->search_results) {
605      search_result_free(appdata->search_results);      search_result_free(appdata->search_results);
606      appdata->search_results = NULL;      appdata->search_results = NULL;
# Line 613  void on_cachelist_destroy(GtkWidget *wid Line 617  void on_cachelist_destroy(GtkWidget *wid
617    
618  void cachelist_dialog(appdata_t *appdata, gpx_t *gpx) {  void cachelist_dialog(appdata_t *appdata, gpx_t *gpx) {
619    GtkWidget *window = hildon_stackable_window_new();    GtkWidget *window = hildon_stackable_window_new();
620      appdata->window = HILDON_WINDOW(window);
621    
622    /* store last "cur_view" in window */    /* store last "cur_view" in window */
623    g_object_set_data(G_OBJECT(window), "cur_view", appdata->cur_view);    g_object_set_data(G_OBJECT(window), "cur_view", appdata->cur_view);
624    
625    appdata->cur_gpx = gpx;    appdata->cur_gpx = gpx;
626    char *title = g_strdup_printf("%s - GPXView", gpx->name);    gtk_window_set_title(GTK_WINDOW(window), gpx->name);
   gtk_window_set_title(GTK_WINDOW(window), title);  
   g_free(title);  
627    
628    appdata->cur_view = cachelist_create(appdata, gpx, NULL);    appdata->cur_view = cachelist_create(appdata, gpx, NULL);
629    gtk_container_add(GTK_CONTAINER(window), appdata->cur_view);    gtk_container_add(GTK_CONTAINER(window), appdata->cur_view);
# Line 669  static GdkPixbuf *gpx_icon_get(gpx_t *gp Line 672  static GdkPixbuf *gpx_icon_get(gpx_t *gp
672    return icon_get(ICON_FILE, 0);    return icon_get(ICON_FILE, 0);
673  }  }
674    
675  static void gpxlist_set(GtkListStore *store, GtkTreeIter *iter, gpx_t *gpx) {  void gpxlist_set(GtkListStore *store, GtkTreeIter *iter, gpx_t *gpx) {
676    char date_str[32], cnum[32];    char date_str[32], cnum[32];
677    
678    if(gpx->year && gpx->month && gpx->day) {    if(gpx->year && gpx->month && gpx->day) {
# Line 694  static void gpxlist_set(GtkListStore *st Line 697  static void gpxlist_set(GtkListStore *st
697                       GPXLIST_COL_OPEN, !gpx->closed,                       GPXLIST_COL_OPEN, !gpx->closed,
698                       GPXLIST_COL_CACHES, gpx->closed?NULL:cnum,                       GPXLIST_COL_CACHES, gpx->closed?NULL:cnum,
699  #ifdef USE_PANNABLE_AREA  #ifdef USE_PANNABLE_AREA
700                       GPXLIST_COL_DELETE, icon_get(ICON_MISC, 4),                       GPXLIST_COL_DELETE, icon_get(ICON_MISC, 2),
701  #endif  #endif
702                       GPXLIST_COL_DATA, gpx,                       GPXLIST_COL_DATA, gpx,
703                       -1);                       -1);
# Line 912  static void gpxlist_view_onRowActivated( Line 915  static void gpxlist_view_onRowActivated(
915    }    }
916  }  }
917    
918    /* search gpx file in gpx list */
919    gboolean gpxlist_find(appdata_t *appdata, GtkTreeIter *iter, gpx_t *gpx) {
920      GtkTreeModel *model =
921        gtk_tree_view_get_model(GTK_TREE_VIEW(appdata->gpxview));
922    
923      gboolean found =
924        gtk_tree_model_get_iter_first(model, iter);
925    
926      while(found) {
927        gpx_t *this_gpx;
928        gtk_tree_model_get(model, iter, GPXLIST_COL_DATA, &this_gpx, -1);
929    
930        if(gpx == this_gpx)
931          return TRUE;
932    
933        found = gtk_tree_model_iter_next(model, iter);
934      }
935    
936      return FALSE;
937    }
938    
939    
940  #ifndef USE_PANNABLE_AREA  #ifndef USE_PANNABLE_AREA
941  static gboolean  static gboolean
942  view_selection_func(GtkTreeSelection *selection, GtkTreeModel *model,  view_selection_func(GtkTreeSelection *selection, GtkTreeModel *model,
# Line 1086  static GtkWidget *gpxlist_create_view_an Line 1111  static GtkWidget *gpxlist_create_view_an
1111  }  }
1112    
1113  /* add last entry in gpx list to visual representation */  /* add last entry in gpx list to visual representation */
1114  static void gpxlist_add(appdata_t *appdata, gpx_t *new) {  void gpxlist_add(appdata_t *appdata, gpx_t *new) {
1115    GtkTreeIter         iter;    GtkTreeIter         iter;
1116    
1117    gtk_list_store_append(appdata->gpxstore, &iter);    gtk_list_store_append(appdata->gpxstore, &iter);
# Line 1096  static void gpxlist_add(appdata_t *appda Line 1121  static void gpxlist_add(appdata_t *appda
1121    gpx_t **gpx = &appdata->gpx;    gpx_t **gpx = &appdata->gpx;
1122    while(*gpx) gpx = &((*gpx)->next);    while(*gpx) gpx = &((*gpx)->next);
1123    *gpx = new;    *gpx = new;
1124    
1125      /* select new iter */
1126      GtkTreeSelection *selection =
1127        gtk_tree_view_get_selection(GTK_TREE_VIEW(appdata->gpxview));
1128      gtk_tree_selection_select_iter(selection, &iter);
1129      GtkTreePath *path =
1130        gtk_tree_model_get_path(GTK_TREE_MODEL(appdata->gpxstore), &iter);
1131      gtk_tree_view_scroll_to_cell(GTK_TREE_VIEW(appdata->gpxview),
1132                                   path, NULL, TRUE, 0.0, 0.0);
1133      gtk_tree_path_free(path);
1134  }  }
1135    
1136  /******************** end of gpxlist ********************/  /******************** end of gpxlist ********************/
1137    
1138  /******************** begin of menu *********************/  /******************** begin of menu *********************/
1139    
 typedef struct {  
   appdata_t *appdata;  
   GtkWidget *dialog;  
 } about_context_t;  
   
 #ifdef ENABLE_BROWSER_INTERFACE  
 void on_paypal_button_clicked(GtkButton *button, about_context_t *context) {  
   gtk_dialog_response(GTK_DIALOG(context->dialog), GTK_RESPONSE_ACCEPT);  
   browser_url(context->appdata,  
               "https://www.paypal.com/cgi-bin/webscr"  
               "?cmd=_s-xclick&hosted_button_id=7400558");  
 }  
 #endif  
   
1140  static void  static void
1141  cb_menu_about(GtkWidget *window, gpointer data) {  cb_menu_about(GtkWidget *window, gpointer data) {
1142    about_context_t context;    about_box((appdata_t*)data);
   
   context.appdata = (appdata_t *)data;  
   
 #ifdef ENABLE_LIBLOCATION  
   char *uses = "uses liblocation";  
 #elif defined(ENABLE_GPSBT)  
   char *uses = "uses gpsbt and gpsd";  
 #else  
   char *uses = "uses gpsd";  
 #endif  
   
   const gchar *authors[] = {  
     "Till Harbaum <till@harbaum.org>",  
     "John Stowers <john.stowers@gmail.com>",  
     "GCVote: Guido Wegener <guido.wegener@gmx.de>",  
     NULL };  
   
   context.dialog = g_object_new(GTK_TYPE_ABOUT_DIALOG,  
                         "name", "GPXView",  
                         "version", VERSION,  
                         "copyright", _("Copyright 2008-2009"),  
                         "authors", authors,  
                         "website", _("http://www.harbaum.org/till/maemo"),  
                         "comments", _(uses),  
                         NULL);  
   
 #ifdef ENABLE_BROWSER_INTERFACE  
   /* add a way to donate to the project */  
   GtkWidget *alignment = gtk_alignment_new(0.5, 0, 0, 0);  
   
   GtkWidget *hbox = gtk_hbox_new(FALSE, 8);  
   gtk_box_pack_start(GTK_BOX(hbox),  
                      gtk_label_new(_("Do you like GPXView?")),  
                      FALSE, FALSE, 0);  
   
   GtkWidget *button = gtk_button_new();  
   gtk_button_set_image(GTK_BUTTON(button),  
                        icon_get_widget(ICON_MISC, 5));  
   gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE);  
   g_signal_connect(button, "clicked",  
                    G_CALLBACK(on_paypal_button_clicked), &context);  
   gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0);  
   
   gtk_container_add(GTK_CONTAINER(alignment), hbox);  
   gtk_box_pack_start_defaults(GTK_BOX((GTK_DIALOG(context.dialog))->vbox),  
                               alignment);  
   
   gtk_widget_show_all(alignment);  
 #endif  
   
   gtk_dialog_run(GTK_DIALOG(context.dialog));  
   gtk_widget_destroy(context.dialog);  
1143  }  }
1144    
1145  #if defined(USE_MAEMO) && defined(HILDON_HELP)  #if defined(USE_MAEMO) && defined(HILDON_HELP)
# Line 1373  typedef struct { Line 1342  typedef struct {
1342  } search_context_t;  } search_context_t;
1343    
1344    
 static GtkWidget *check_button_new_with_label(char *label) {  
 #if !defined(USE_MAEMO) || (MAEMO_VERSION_MAJOR < 5)  
   return gtk_check_button_new_with_label(label);  
 #else  
   GtkWidget *cbut =  
     hildon_check_button_new(HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH);  
   gtk_button_set_label(GTK_BUTTON(cbut), label);  
   return cbut;  
 #endif  
 }  
   
 static void check_button_set_active(GtkWidget *button, gboolean active) {  
 #if !defined(USE_MAEMO) || (MAEMO_VERSION_MAJOR < 5)  
   gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), active);  
 #else  
   hildon_check_button_set_active(HILDON_CHECK_BUTTON(button), active);  
 #endif  
 }  
   
 static gboolean check_button_get_active(GtkWidget *button) {  
 #if !defined(USE_MAEMO) || (MAEMO_VERSION_MAJOR < 5)  
   return gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button));  
 #else  
   return hildon_check_button_get_active(HILDON_CHECK_BUTTON(button));  
 #endif  
 }  
   
1345  static void callback_finds_toggled(GtkWidget *widget, gpointer data ) {  static void callback_finds_toggled(GtkWidget *widget, gpointer data ) {
1346    search_context_t *context = (search_context_t*)data;    search_context_t *context = (search_context_t*)data;
1347    
# Line 1455  cb_menu_search(GtkWidget *window, gpoint Line 1397  cb_menu_search(GtkWidget *window, gpoint
1397    
1398    gtk_box_pack_start_defaults(GTK_BOX(GTK_DIALOG(dialog)->vbox),    gtk_box_pack_start_defaults(GTK_BOX(GTK_DIALOG(dialog)->vbox),
1399                                gtk_label_new(_("Search for:")));                                gtk_label_new(_("Search for:")));
1400  #if !defined(USE_MAEMO) || (MAEMO_VERSION_MAJOR < 5)    context.entry = entry_new();
   context.entry = gtk_entry_new();  
 #else  
   context.entry = hildon_entry_new(HILDON_SIZE_AUTO);  
 #endif  
   
1401    gtk_box_pack_start_defaults(GTK_BOX(GTK_DIALOG(dialog)->vbox),    gtk_box_pack_start_defaults(GTK_BOX(GTK_DIALOG(dialog)->vbox),
1402                                context.entry);                                context.entry);
1403    
# Line 2046  void menu_create(appdata_t *appdata) { Line 1983  void menu_create(appdata_t *appdata) {
1983  /********************* end of menu **********************/  /********************* end of menu **********************/
1984    
1985  void cleanup(appdata_t *appdata) {  void cleanup(appdata_t *appdata) {
1986      gconf_save_state(appdata);
1987    
1988    gpx_free_all(appdata->gpx);    gpx_free_all(appdata->gpx);
   if(appdata->path) free(appdata->path);  
   if(appdata->image_path) free(appdata->image_path);  
   if(appdata->search_str) free(appdata->search_str);  
1989    
1990  #ifdef USE_STACKABLE_WINDOW  #ifdef USE_STACKABLE_WINDOW
1991    if(appdata->export_menu) submenu_cleanup(appdata->export_menu);    if(appdata->export_menu) submenu_cleanup(appdata->export_menu);
# Line 2087  void cleanup(appdata_t *appdata) { Line 2023  void cleanup(appdata_t *appdata) {
2023  static void on_window_destroy (GtkWidget *widget, gpointer data) {  static void on_window_destroy (GtkWidget *widget, gpointer data) {
2024    appdata_t *appdata = (appdata_t*)data;    appdata_t *appdata = (appdata_t*)data;
2025    
   gconf_save_state(appdata);  
2026    gtk_main_quit();    gtk_main_quit();
2027    appdata->window = NULL;    appdata->window = NULL;
2028  }  }
# Line 2378  int main(int argc, char *argv[]) { Line 2313  int main(int argc, char *argv[]) {
2313    
2314    gtk_init (&argc, &argv);    gtk_init (&argc, &argv);
2315    
2316      misc_init();
2317    
2318    curl_global_init(CURL_GLOBAL_ALL);    curl_global_init(CURL_GLOBAL_ALL);
2319    
2320  #ifdef USE_MAEMO  #ifdef USE_MAEMO

Legend:
Removed from v.206  
changed lines
  Added in v.233