Diff of /trunk/src/notes.c

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

revision 1 by harbaum, Sat Jun 20 11:08:47 2009 UTC revision 164 by harbaum, Thu Nov 5 20:37:16 2009 UTC
# Line 33  Line 33 
33    
34  #include "gpxview.h"  #include "gpxview.h"
35    
36    #if defined(USE_MAEMO) && (MAEMO_VERSION_MAJOR >= 5)
37    #include <hildon/hildon-note.h>
38    #endif
39    
40  void gtk_text_buffer_set_can_paste_rich_text(GtkTextBuffer *buffer, gboolean);  void gtk_text_buffer_set_can_paste_rich_text(GtkTextBuffer *buffer, gboolean);
41  void gtk_text_buffer_set_rich_text_format(GtkTextBuffer *buffer, const gchar *);  void gtk_text_buffer_set_rich_text_format(GtkTextBuffer *buffer, const gchar *);
42    
# Line 157  void notes_load_all(appdata_t *appdata, Line 161  void notes_load_all(appdata_t *appdata,
161    }    }
162  }  }
163    
164  static int notes_save(cache_context_t *context,  static int notes_write_file(cache_context_t *context,
165                        char *text, pos_t pos,                        char *text, pos_t pos,
166                        gboolean override, gboolean found,                        gboolean override, gboolean found,
167                        time_t ftime, gboolean logged) {                        time_t ftime, gboolean logged) {
# Line 230  static int notes_save(cache_context_t *c Line 234  static int notes_save(cache_context_t *c
234    return 0;    return 0;
235  }  }
236    
237  /* this is called from the destroy event of the entire notebook */  static void notes_save(cache_context_t *context) {
 gint notes_destroy_event(GtkWidget *widget, gpointer data ) {  
   cache_context_t *context = (cache_context_t*)data;  
   
   printf("about to destroy notes view\n");  
   
238    /* only save if: there is a text which has been changed or */    /* only save if: there is a text which has been changed or */
239    /* there is a position which differs from the original one */    /* there is a position which differs from the original one */
240    /* or has been changed */    /* or has been changed */
# Line 333  gint notes_destroy_event(GtkWidget *widg Line 332  gint notes_destroy_event(GtkWidget *widg
332        /* - update the notes entry in the loaded gpx tree */        /* - update the notes entry in the loaded gpx tree */
333    
334        /* update file on disk */        /* update file on disk */
335        notes_save(context, text, pos, override, found,        notes_write_file(context, text, pos, override, found,
336                   context->notes.ftime, logged);                         context->notes.ftime, logged);
337    
338        /* search for matching caches and replace note there */        /* search for matching caches and replace note there */
339        notes_t *note = NULL;        notes_t *note = NULL;
# Line 382  gint notes_destroy_event(GtkWidget *widg Line 381  gint notes_destroy_event(GtkWidget *widg
381    
382      if(text) free(text);      if(text) free(text);
383    }    }
384    }
385    
386    /* this is called from the destroy event of the entire notebook */
387    gint notes_destroy_event(GtkWidget *widget, gpointer data ) {
388      cache_context_t *context = (cache_context_t*)data;
389    
390      printf("about to destroy notes view\n");
391      notes_save(context);
392    
393    return FALSE;    return FALSE;
394  }  }
395    
396    #ifndef NO_COPY_N_PASTE
397  static void on_destroy_textview(GtkWidget *widget, gpointer data) {  static void on_destroy_textview(GtkWidget *widget, gpointer data) {
398    appdata_t *appdata = (appdata_t*)data;    appdata_t *appdata = (appdata_t*)data;
399    
# Line 412  static void on_destroy_textview(GtkWidge Line 420  static void on_destroy_textview(GtkWidge
420      }      }
421    }    }
422  }  }
423    #endif
424    
425  static void ftime_update(GtkWidget *widget, cache_context_t *context,  static void ftime_update(GtkWidget *widget, cache_context_t *context,
426                           gboolean update) {                           gboolean update) {
# Line 449  static void callback_modified(GtkWidget Line 458  static void callback_modified(GtkWidget
458    
459      /* about to remove "found" flag -> ask for confirmation */      /* about to remove "found" flag -> ask for confirmation */
460      if(!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))) {      if(!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))) {
461    #if !defined(USE_MAEMO) || (MAEMO_VERSION_MAJOR < 5)
462        GtkWidget *dialog = gtk_message_dialog_new(        GtkWidget *dialog = gtk_message_dialog_new(
463                   GTK_WINDOW(context->appdata->window),                   GTK_WINDOW(context->appdata->window),
464                   GTK_DIALOG_DESTROY_WITH_PARENT,                   GTK_DIALOG_DESTROY_WITH_PARENT,
# Line 462  static void callback_modified(GtkWidget Line 472  static void callback_modified(GtkWidget
472        if(GTK_RESPONSE_NO == gtk_dialog_run(GTK_DIALOG(dialog)))        if(GTK_RESPONSE_NO == gtk_dialog_run(GTK_DIALOG(dialog)))
473          gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), TRUE);          gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), TRUE);
474    
475    #else
476          GtkWidget *dialog =
477            hildon_note_new_confirmation(GTK_WINDOW(context->appdata->window),
478                     _("Do you really want to remove the \"found\" flag? "
479                       "This will void the recorded date of your find!"));
480    
481          /* set the active flag again if the user answered "no" */
482          if(GTK_RESPONSE_OK != gtk_dialog_run(GTK_DIALOG(dialog)))
483            gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), TRUE);
484    #endif
485    
486        gtk_widget_destroy(dialog);        gtk_widget_destroy(dialog);
487      }      }
488    
# Line 473  static void callback_modified(GtkWidget Line 494  static void callback_modified(GtkWidget
494    
495      /* about to remove "found" flag -> ask for confirmation */      /* about to remove "found" flag -> ask for confirmation */
496      if(!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))) {      if(!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))) {
497    #if !defined(USE_MAEMO) || (MAEMO_VERSION_MAJOR < 5)
498        GtkWidget *dialog = gtk_message_dialog_new(        GtkWidget *dialog = gtk_message_dialog_new(
499                   GTK_WINDOW(context->appdata->window),                   GTK_WINDOW(context->appdata->window),
500                   GTK_DIALOG_DESTROY_WITH_PARENT,                   GTK_DIALOG_DESTROY_WITH_PARENT,
# Line 491  static void callback_modified(GtkWidget Line 513  static void callback_modified(GtkWidget
513          gtk_widget_set_sensitive(context->notes.foundw, TRUE);          gtk_widget_set_sensitive(context->notes.foundw, TRUE);
514        }        }
515    
516    #else
517          GtkWidget *dialog =
518            hildon_note_new_confirmation(GTK_WINDOW(context->appdata->window),
519                       _("Do you really want to remove the \"logged\" flag? "
520                       "This may cause problems on your next Garmin Field "
521                       "Notes upload!"));
522    
523          /* set the active flag again if the user answered "no" */
524          if(GTK_RESPONSE_OK != gtk_dialog_run(GTK_DIALOG(dialog)))
525            gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), TRUE);
526          else {
527            gtk_widget_set_sensitive(widget, FALSE);
528            gtk_widget_set_sensitive(context->notes.foundw, TRUE);
529          }
530    
531    #endif
532    
533        gtk_widget_destroy(dialog);        gtk_widget_destroy(dialog);
534      }      }
535    }    }
536  }  }
537    
538    #ifndef NO_COPY_N_PASTE
539  static gboolean focus_in(GtkWidget *widget, GdkEventFocus *event,  static gboolean focus_in(GtkWidget *widget, GdkEventFocus *event,
540                           gpointer data) {                           gpointer data) {
541    appdata_t *appdata = (appdata_t*)data;    appdata_t *appdata = (appdata_t*)data;
# Line 514  static gboolean focus_in(GtkWidget *widg Line 554  static gboolean focus_in(GtkWidget *widg
554    
555    return FALSE;    return FALSE;
556  }  }
557    #endif
558    
559    static gboolean focus_out(GtkWidget *widget, GdkEventFocus *event,
560                             gpointer data) {
561      cache_context_t *context = (cache_context_t*)data;
562    
563      notes_save(context);
564    #if !defined(USE_MAEMO) && defined(ENABLE_OSM_GPS_MAP)
565      map_update(context->appdata);
566    #endif
567    
568      return FALSE;
569    }
570    
571  GtkWidget *cache_notes(cache_context_t *context) {  GtkWidget *cache_notes(cache_context_t *context) {
   appdata_t *appdata = context->appdata;  
572    cache_t *cache = context->cache;    cache_t *cache = context->cache;
573    
574    context->notes.modified = FALSE;    context->notes.modified = FALSE;
# Line 572  GtkWidget *cache_notes(cache_context_t * Line 624  GtkWidget *cache_notes(cache_context_t *
624    if(cache->notes) pos = cache->notes->pos;    if(cache->notes) pos = cache->notes->pos;
625    
626    gtk_table_attach_defaults(GTK_TABLE(table),    gtk_table_attach_defaults(GTK_TABLE(table),
627              context->notes.latw = lat_entry_new(pos.lat), 2, 3, 0, 1);                              context->notes.latw = lat_entry_new(pos.lat), 2, 3, 0, 1);
628      g_signal_connect(G_OBJECT(context->notes.latw), "focus-out-event",
629                       G_CALLBACK(focus_out), context);
630    
631    gtk_table_attach_defaults(GTK_TABLE(table),    gtk_table_attach_defaults(GTK_TABLE(table),
632              context->notes.lonw = lon_entry_new(pos.lon), 2, 3, 1, 2);                              context->notes.lonw = lon_entry_new(pos.lon), 2, 3, 1, 2);
633      g_signal_connect(G_OBJECT(context->notes.lonw), "focus-out-event",
634                       G_CALLBACK(focus_out), context);
635    
636    hbox = gtk_hbox_new(FALSE, 0);    hbox = gtk_hbox_new(FALSE, 0);
637    gtk_box_pack_start(GTK_BOX(hbox), table, FALSE, FALSE, 0);    gtk_box_pack_start(GTK_BOX(hbox), table, FALSE, FALSE, 0);
# Line 594  GtkWidget *cache_notes(cache_context_t * Line 650  GtkWidget *cache_notes(cache_context_t *
650    if(cache->notes && cache->notes->text)    if(cache->notes && cache->notes->text)
651      gtk_text_buffer_set_text(context->notes.buffer, cache->notes->text, -1);      gtk_text_buffer_set_text(context->notes.buffer, cache->notes->text, -1);
652    
653  #ifndef USE_MAEMO  #ifndef USE_HILDON_TEXT_VIEW
654    GtkWidget *view = gtk_text_view_new_with_buffer(context->notes.buffer);    GtkWidget *view = gtk_text_view_new_with_buffer(context->notes.buffer);
655  #else  #else
656    GtkWidget *view = hildon_text_view_new();    GtkWidget *view = hildon_text_view_new();
# Line 612  GtkWidget *cache_notes(cache_context_t * Line 668  GtkWidget *cache_notes(cache_context_t *
668    gtk_text_buffer_set_rich_text_format(context->notes.buffer, "RTF" );    gtk_text_buffer_set_rich_text_format(context->notes.buffer, "RTF" );
669  #endif  #endif
670    
671    #ifndef NO_COPY_N_PASTE
672    g_signal_connect(G_OBJECT(view), "focus-in-event",    g_signal_connect(G_OBJECT(view), "focus-in-event",
673                     G_CALLBACK(focus_in), appdata);                     G_CALLBACK(focus_in), context->appdata);
674    g_signal_connect(G_OBJECT(view), "destroy",    g_signal_connect(G_OBJECT(view), "destroy",
675                     G_CALLBACK(on_destroy_textview), appdata);                     G_CALLBACK(on_destroy_textview), context->appdata);
676    #endif
677    
678  #ifndef USE_PANNABLE_AREA  #ifndef USE_PANNABLE_AREA
679    gtk_container_add(GTK_CONTAINER(scrolled_window), view);    gtk_container_add(GTK_CONTAINER(scrolled_window), view);
# Line 821  void notes_log_export(appdata_t *appdata Line 879  void notes_log_export(appdata_t *appdata
879    GtkWidget *label = gtk_label_new(_("Export to:"));    GtkWidget *label = gtk_label_new(_("Export to:"));
880    gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, TRUE,0);    gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, TRUE,0);
881    gtk_misc_set_alignment(GTK_MISC(label), 0.f, 0.5f);    gtk_misc_set_alignment(GTK_MISC(label), 0.f, 0.5f);
882    GtkWidget *button = gtk_button_new_with_label(_("Browse..."));    GtkWidget *button = gtk_button_new_with_label(_("Browse"));
883    gtk_signal_connect(GTK_OBJECT(button), "clicked",    gtk_signal_connect(GTK_OBJECT(button), "clicked",
884                       GTK_SIGNAL_FUNC(on_browse), (gpointer)&context);                       GTK_SIGNAL_FUNC(on_browse), (gpointer)&context);
885    gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE,0);    gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE,0);
# Line 941  void notes_log_export(appdata_t *appdata Line 999  void notes_log_export(appdata_t *appdata
999          ccontext.appdata = appdata;          ccontext.appdata = appdata;
1000          ccontext.cache = llog->cache;          ccontext.cache = llog->cache;
1001    
1002          notes_save(&ccontext,          notes_write_file(&ccontext,
1003                     llog->cache->notes->text, llog->cache->notes->pos,                     llog->cache->notes->text, llog->cache->notes->pos,
1004                     llog->cache->notes->override, llog->cache->notes->found,                     llog->cache->notes->override, llog->cache->notes->found,
1005                     llog->cache->notes->ftime, llog->cache->notes->logged);                     llog->cache->notes->ftime, llog->cache->notes->logged);

Legend:
Removed from v.1  
changed lines
  Added in v.164