Diff of /trunk/src/notes.c

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

revision 7 by harbaum, Thu Jun 25 15:24:24 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  }  }
# Line 451  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 464  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 475  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 493  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    }    }
# Line 519  static gboolean focus_in(GtkWidget *widg Line 556  static gboolean focus_in(GtkWidget *widg
556  }  }
557  #endif  #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 576  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 598  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 618  GtkWidget *cache_notes(cache_context_t * Line 670  GtkWidget *cache_notes(cache_context_t *
670    
671  #ifndef NO_COPY_N_PASTE  #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  #endif
677    
678  #ifndef USE_PANNABLE_AREA  #ifndef USE_PANNABLE_AREA
# Line 947  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.7  
changed lines
  Added in v.164