Diff of /trunk/src/main.c

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

revision 193 by harbaum, Tue Nov 17 20:13:09 2009 UTC revision 231 by harbaum, Mon Dec 7 16:14:50 2009 UTC
# Line 15  Line 15 
15   * along with GPXView.  If not, see <http://www.gnu.org/licenses/>.   * along with GPXView.  If not, see <http://www.gnu.org/licenses/>.
16   */   */
17    
18  #include <stdio.h>  #define __USE_GNU
19  #include <string.h>  #include <string.h>
20    
21    #include <stdio.h>
22  #include <math.h>  #include <math.h>
23    
24  #include <curl/curl.h>  #include <curl/curl.h>
# Line 155  gpx_t *choose_file(appdata_t *appdata, g Line 157  gpx_t *choose_file(appdata_t *appdata, g
157        gpx_dialog_t *dialog = gpx_busy_dialog_new(GTK_WIDGET(appdata->window));        gpx_dialog_t *dialog = gpx_busy_dialog_new(GTK_WIDGET(appdata->window));
158    
159        if(!whole_dir)        if(!whole_dir)
160          gpx = gpx_parse(dialog, filename);          gpx = gpx_parse(dialog, filename, appdata->username);
161        else {        else {
162          /* cur trailing '/' if present */          /* cur trailing '/' if present */
163          if(strlastchr(filename) == '/')          if(strlastchr(filename) == '/')
164            filename[strlen(filename)] = 0;            filename[strlen(filename)] = 0;
165    
166          gpx = gpx_parse_dir(dialog, filename);          gpx = gpx_parse_dir(dialog, filename, appdata->username);
167        }        }
168    
169        gpx_busy_dialog_destroy(dialog);        gpx_busy_dialog_destroy(dialog);
170    
171        /* save path if gpx was successfully loaded */        /* save path if gpx was successfully loaded */
# Line 221  void cachelist_goto_cache(appdata_t *app Line 223  void cachelist_goto_cache(appdata_t *app
223  #if !defined(USE_BREAD_CRUMB_TRAIL) && !defined(BCT)  #if !defined(USE_BREAD_CRUMB_TRAIL) && !defined(BCT)
224      cache_dialog(appdata, cache);      cache_dialog(appdata, cache);
225  #else  #else
226        crumb_add(appdata, cache->name, CRUMB_CACHE, cache);
227    
228      gtk_container_remove(GTK_CONTAINER(appdata->vbox), appdata->cur_view);      gtk_container_remove(GTK_CONTAINER(appdata->vbox), appdata->cur_view);
229      appdata->cur_view = cache_view(appdata, cache);      appdata->cur_view = cache_view(appdata, cache);
230      gtk_box_pack_start_defaults(GTK_BOX(appdata->vbox), appdata->cur_view);      gtk_box_pack_start_defaults(GTK_BOX(appdata->vbox), appdata->cur_view);
231      gtk_widget_show_all(appdata->vbox);      gtk_widget_show_all(appdata->vbox);
   
     crumb_add(appdata, cache->name, CRUMB_CACHE, cache);  
232  #endif  #endif
233  }  }
234    
# Line 474  static GtkWidget *cachelist_create(appda Line 476  static GtkWidget *cachelist_create(appda
476      if(tint > 8) tint = 8;      if(tint > 8) tint = 8;
477    
478      /* cache type includes "solved" flag in lowest bit */      /* cache type includes "solved" flag in lowest bit */
479      int type = (cache->type<<8) +      int type = cache->type<<8;
480        (cache->notes?4:0) +      if(cache->notes) type |= 4;
481        ((cache->notes && cache->notes->override)?1:0) +      if(cache->notes && cache->notes->override) type |= 1;
482        ((cache->notes && cache->notes->found)?2:0);      if(cache->notes && cache->notes->found) type |= 2;
483        if(cache->found) type |= 2;
484        if(cache->mine) type |= 8;
485    
486      if((!(type & 2)) || !appdata->cachelist_hide_found) {      if((!(type & 2)) || !appdata->cachelist_hide_found) {
487    
# Line 593  void cachelist_dialog(appdata_t *appdata Line 597  void cachelist_dialog(appdata_t *appdata
597  static void search_result_free(gpx_t *result);  static void search_result_free(gpx_t *result);
598    
599  void on_cachelist_destroy(GtkWidget *widget, appdata_t *appdata) {  void on_cachelist_destroy(GtkWidget *widget, appdata_t *appdata) {
600      printf("cachelist destroy\n");
601    
602      HildonWindowStack *stack = hildon_window_stack_get_default();
603      appdata->window = HILDON_WINDOW(hildon_window_stack_peek(stack));
604    
605    if(appdata->search_results) {    if(appdata->search_results) {
606      search_result_free(appdata->search_results);      search_result_free(appdata->search_results);
607      appdata->search_results = NULL;      appdata->search_results = NULL;
# Line 609  void on_cachelist_destroy(GtkWidget *wid Line 618  void on_cachelist_destroy(GtkWidget *wid
618    
619  void cachelist_dialog(appdata_t *appdata, gpx_t *gpx) {  void cachelist_dialog(appdata_t *appdata, gpx_t *gpx) {
620    GtkWidget *window = hildon_stackable_window_new();    GtkWidget *window = hildon_stackable_window_new();
621      appdata->window = HILDON_WINDOW(window);
622    
623    /* store last "cur_view" in window */    /* store last "cur_view" in window */
624    g_object_set_data(G_OBJECT(window), "cur_view", appdata->cur_view);    g_object_set_data(G_OBJECT(window), "cur_view", appdata->cur_view);
625    
626    appdata->cur_gpx = gpx;    appdata->cur_gpx = gpx;
627    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);  
628    
629    appdata->cur_view = cachelist_create(appdata, gpx, NULL);    appdata->cur_view = cachelist_create(appdata, gpx, NULL);
630    gtk_container_add(GTK_CONTAINER(window), appdata->cur_view);    gtk_container_add(GTK_CONTAINER(window), appdata->cur_view);
# Line 665  static GdkPixbuf *gpx_icon_get(gpx_t *gp Line 673  static GdkPixbuf *gpx_icon_get(gpx_t *gp
673    return icon_get(ICON_FILE, 0);    return icon_get(ICON_FILE, 0);
674  }  }
675    
676  static void gpxlist_set(GtkListStore *store, GtkTreeIter *iter, gpx_t *gpx) {  void gpxlist_set(GtkListStore *store, GtkTreeIter *iter, gpx_t *gpx) {
677    char date_str[32], cnum[32];    char date_str[32], cnum[32];
678    
679    if(gpx->year && gpx->month && gpx->day) {    if(gpx->year && gpx->month && gpx->day) {
# Line 690  static void gpxlist_set(GtkListStore *st Line 698  static void gpxlist_set(GtkListStore *st
698                       GPXLIST_COL_OPEN, !gpx->closed,                       GPXLIST_COL_OPEN, !gpx->closed,
699                       GPXLIST_COL_CACHES, gpx->closed?NULL:cnum,                       GPXLIST_COL_CACHES, gpx->closed?NULL:cnum,
700  #ifdef USE_PANNABLE_AREA  #ifdef USE_PANNABLE_AREA
701                       GPXLIST_COL_DELETE, icon_get(ICON_MISC, 4),                       GPXLIST_COL_DELETE, icon_get(ICON_MISC, 2),
702  #endif  #endif
703                       GPXLIST_COL_DATA, gpx,                       GPXLIST_COL_DATA, gpx,
704                       -1);                       -1);
# Line 864  static void gpxlist_view_onRowActivated( Line 872  static void gpxlist_view_onRowActivated(
872          gpx_t *new = NULL;          gpx_t *new = NULL;
873    
874          if(g_file_test(gpx->filename, G_FILE_TEST_IS_DIR))          if(g_file_test(gpx->filename, G_FILE_TEST_IS_DIR))
875            new = gpx_parse_dir(dialog, gpx->filename);            new = gpx_parse_dir(dialog, gpx->filename, appdata->username);
876          else          else
877            new = gpx_parse(dialog, gpx->filename);            new = gpx_parse(dialog, gpx->filename, appdata->username);
878    
879          if(new) {          if(new) {
880            gpx_t **prev = &(appdata->gpx);            gpx_t **prev = &(appdata->gpx);
# Line 908  static void gpxlist_view_onRowActivated( Line 916  static void gpxlist_view_onRowActivated(
916    }    }
917  }  }
918    
919    /* search gpx file in gpx list */
920    gboolean gpxlist_find(appdata_t *appdata, GtkTreeIter *iter, gpx_t *gpx) {
921      GtkTreeModel *model =
922        gtk_tree_view_get_model(GTK_TREE_VIEW(appdata->gpxview));
923    
924      gboolean found =
925        gtk_tree_model_get_iter_first(model, iter);
926    
927      while(found) {
928        gpx_t *this_gpx;
929        gtk_tree_model_get(model, iter, GPXLIST_COL_DATA, &this_gpx, -1);
930    
931        if(gpx == this_gpx)
932          return TRUE;
933    
934        found = gtk_tree_model_iter_next(model, iter);
935      }
936    
937      return FALSE;
938    }
939    
940    
941  #ifndef USE_PANNABLE_AREA  #ifndef USE_PANNABLE_AREA
942  static gboolean  static gboolean
943  view_selection_func(GtkTreeSelection *selection, GtkTreeModel *model,  view_selection_func(GtkTreeSelection *selection, GtkTreeModel *model,
# Line 1082  static GtkWidget *gpxlist_create_view_an Line 1112  static GtkWidget *gpxlist_create_view_an
1112  }  }
1113    
1114  /* add last entry in gpx list to visual representation */  /* add last entry in gpx list to visual representation */
1115  static void gpxlist_add(appdata_t *appdata, gpx_t *new) {  void gpxlist_add(appdata_t *appdata, gpx_t *new) {
1116    GtkTreeIter         iter;    GtkTreeIter         iter;
1117    
1118    gtk_list_store_append(appdata->gpxstore, &iter);    gtk_list_store_append(appdata->gpxstore, &iter);
# Line 1092  static void gpxlist_add(appdata_t *appda Line 1122  static void gpxlist_add(appdata_t *appda
1122    gpx_t **gpx = &appdata->gpx;    gpx_t **gpx = &appdata->gpx;
1123    while(*gpx) gpx = &((*gpx)->next);    while(*gpx) gpx = &((*gpx)->next);
1124    *gpx = new;    *gpx = new;
1125    
1126      /* select new iter */
1127      GtkTreeSelection *selection =
1128        gtk_tree_view_get_selection(GTK_TREE_VIEW(appdata->gpxview));
1129      gtk_tree_selection_select_iter(selection, &iter);
1130      GtkTreePath *path =
1131        gtk_tree_model_get_path(GTK_TREE_MODEL(appdata->gpxstore), &iter);
1132      gtk_tree_view_scroll_to_cell(GTK_TREE_VIEW(appdata->gpxview),
1133                                   path, NULL, TRUE, 0.0, 0.0);
1134      gtk_tree_path_free(path);
1135  }  }
1136    
1137  /******************** end of gpxlist ********************/  /******************** end of gpxlist ********************/
1138    
1139  /******************** begin of menu *********************/  /******************** begin of menu *********************/
1140    
 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  
   
1141  static void  static void
1142  cb_menu_about(GtkWidget *window, gpointer data) {  cb_menu_about(GtkWidget *window, gpointer data) {
1143    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);  
1144  }  }
1145    
1146  #if defined(USE_MAEMO) && defined(HILDON_HELP)  #if defined(USE_MAEMO) && defined(HILDON_HELP)
# Line 1451  cb_menu_search(GtkWidget *window, gpoint Line 1425  cb_menu_search(GtkWidget *window, gpoint
1425    
1426    gtk_box_pack_start_defaults(GTK_BOX(GTK_DIALOG(dialog)->vbox),    gtk_box_pack_start_defaults(GTK_BOX(GTK_DIALOG(dialog)->vbox),
1427                                gtk_label_new(_("Search for:")));                                gtk_label_new(_("Search for:")));
1428  #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  
   
1429    gtk_box_pack_start_defaults(GTK_BOX(GTK_DIALOG(dialog)->vbox),    gtk_box_pack_start_defaults(GTK_BOX(GTK_DIALOG(dialog)->vbox),
1430                                context.entry);                                context.entry);
1431    
# Line 2042  void menu_create(appdata_t *appdata) { Line 2011  void menu_create(appdata_t *appdata) {
2011  /********************* end of menu **********************/  /********************* end of menu **********************/
2012    
2013  void cleanup(appdata_t *appdata) {  void cleanup(appdata_t *appdata) {
2014      gconf_save_state(appdata);
2015    
2016    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);  
2017    
2018  #ifdef USE_STACKABLE_WINDOW  #ifdef USE_STACKABLE_WINDOW
2019    if(appdata->export_menu) submenu_cleanup(appdata->export_menu);    if(appdata->export_menu) submenu_cleanup(appdata->export_menu);
# Line 2083  void cleanup(appdata_t *appdata) { Line 2051  void cleanup(appdata_t *appdata) {
2051  static void on_window_destroy (GtkWidget *widget, gpointer data) {  static void on_window_destroy (GtkWidget *widget, gpointer data) {
2052    appdata_t *appdata = (appdata_t*)data;    appdata_t *appdata = (appdata_t*)data;
2053    
   gconf_save_state(appdata);  
2054    gtk_main_quit();    gtk_main_quit();
2055    appdata->window = NULL;    appdata->window = NULL;
2056  }  }
# Line 2374  int main(int argc, char *argv[]) { Line 2341  int main(int argc, char *argv[]) {
2341    
2342    gtk_init (&argc, &argv);    gtk_init (&argc, &argv);
2343    
2344      misc_init();
2345    
2346    curl_global_init(CURL_GLOBAL_ALL);    curl_global_init(CURL_GLOBAL_ALL);
2347    
2348  #ifdef USE_MAEMO  #ifdef USE_MAEMO

Legend:
Removed from v.193  
changed lines
  Added in v.231