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 133 by harbaum, Mon Oct 12 20:27:55 2009 UTC
# Line 157  void notes_load_all(appdata_t *appdata, Line 157  void notes_load_all(appdata_t *appdata,
157    }    }
158  }  }
159    
160  static int notes_save(cache_context_t *context,  static int notes_write_file(cache_context_t *context,
161                        char *text, pos_t pos,                        char *text, pos_t pos,
162                        gboolean override, gboolean found,                        gboolean override, gboolean found,
163                        time_t ftime, gboolean logged) {                        time_t ftime, gboolean logged) {
# Line 230  static int notes_save(cache_context_t *c Line 230  static int notes_save(cache_context_t *c
230    return 0;    return 0;
231  }  }
232    
233  /* 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");  
   
234    /* only save if: there is a text which has been changed or */    /* only save if: there is a text which has been changed or */
235    /* there is a position which differs from the original one */    /* there is a position which differs from the original one */
236    /* or has been changed */    /* or has been changed */
# Line 333  gint notes_destroy_event(GtkWidget *widg Line 328  gint notes_destroy_event(GtkWidget *widg
328        /* - update the notes entry in the loaded gpx tree */        /* - update the notes entry in the loaded gpx tree */
329    
330        /* update file on disk */        /* update file on disk */
331        notes_save(context, text, pos, override, found,        notes_write_file(context, text, pos, override, found,
332                   context->notes.ftime, logged);                         context->notes.ftime, logged);
333    
334        /* search for matching caches and replace note there */        /* search for matching caches and replace note there */
335        notes_t *note = NULL;        notes_t *note = NULL;
# Line 382  gint notes_destroy_event(GtkWidget *widg Line 377  gint notes_destroy_event(GtkWidget *widg
377    
378      if(text) free(text);      if(text) free(text);
379    }    }
380    }
381    
382    /* this is called from the destroy event of the entire notebook */
383    gint notes_destroy_event(GtkWidget *widget, gpointer data ) {
384      cache_context_t *context = (cache_context_t*)data;
385    
386      printf("about to destroy notes view\n");
387      notes_save(context);
388    
389    return FALSE;    return FALSE;
390  }  }
391    
392    #ifndef NO_COPY_N_PASTE
393  static void on_destroy_textview(GtkWidget *widget, gpointer data) {  static void on_destroy_textview(GtkWidget *widget, gpointer data) {
394    appdata_t *appdata = (appdata_t*)data;    appdata_t *appdata = (appdata_t*)data;
395    
# Line 412  static void on_destroy_textview(GtkWidge Line 416  static void on_destroy_textview(GtkWidge
416      }      }
417    }    }
418  }  }
419    #endif
420    
421  static void ftime_update(GtkWidget *widget, cache_context_t *context,  static void ftime_update(GtkWidget *widget, cache_context_t *context,
422                           gboolean update) {                           gboolean update) {
# Line 496  static void callback_modified(GtkWidget Line 501  static void callback_modified(GtkWidget
501    }    }
502  }  }
503    
504    #ifndef NO_COPY_N_PASTE
505  static gboolean focus_in(GtkWidget *widget, GdkEventFocus *event,  static gboolean focus_in(GtkWidget *widget, GdkEventFocus *event,
506                           gpointer data) {                           gpointer data) {
507    appdata_t *appdata = (appdata_t*)data;    appdata_t *appdata = (appdata_t*)data;
# Line 514  static gboolean focus_in(GtkWidget *widg Line 520  static gboolean focus_in(GtkWidget *widg
520    
521    return FALSE;    return FALSE;
522  }  }
523    #endif
524    
525    static gboolean focus_out(GtkWidget *widget, GdkEventFocus *event,
526                             gpointer data) {
527      cache_context_t *context = (cache_context_t*)data;
528    
529      notes_save(context);
530    #if !defined(USE_MAEMO) && defined(ENABLE_OSM_GPS_MAP)
531      map_update(context->appdata);
532    #endif
533    
534      return FALSE;
535    }
536    
537  GtkWidget *cache_notes(cache_context_t *context) {  GtkWidget *cache_notes(cache_context_t *context) {
   appdata_t *appdata = context->appdata;  
538    cache_t *cache = context->cache;    cache_t *cache = context->cache;
539    
540    context->notes.modified = FALSE;    context->notes.modified = FALSE;
# Line 572  GtkWidget *cache_notes(cache_context_t * Line 590  GtkWidget *cache_notes(cache_context_t *
590    if(cache->notes) pos = cache->notes->pos;    if(cache->notes) pos = cache->notes->pos;
591    
592    gtk_table_attach_defaults(GTK_TABLE(table),    gtk_table_attach_defaults(GTK_TABLE(table),
593              context->notes.latw = lat_entry_new(pos.lat), 2, 3, 0, 1);                              context->notes.latw = lat_entry_new(pos.lat), 2, 3, 0, 1);
594      g_signal_connect(G_OBJECT(context->notes.latw), "focus-out-event",
595                       G_CALLBACK(focus_out), context);
596    
597    gtk_table_attach_defaults(GTK_TABLE(table),    gtk_table_attach_defaults(GTK_TABLE(table),
598              context->notes.lonw = lon_entry_new(pos.lon), 2, 3, 1, 2);                              context->notes.lonw = lon_entry_new(pos.lon), 2, 3, 1, 2);
599      g_signal_connect(G_OBJECT(context->notes.lonw), "focus-out-event",
600                       G_CALLBACK(focus_out), context);
601    
602    hbox = gtk_hbox_new(FALSE, 0);    hbox = gtk_hbox_new(FALSE, 0);
603    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 616  GtkWidget *cache_notes(cache_context_t *
616    if(cache->notes && cache->notes->text)    if(cache->notes && cache->notes->text)
617      gtk_text_buffer_set_text(context->notes.buffer, cache->notes->text, -1);      gtk_text_buffer_set_text(context->notes.buffer, cache->notes->text, -1);
618    
619  #ifndef USE_MAEMO  #ifndef USE_HILDON_TEXT_VIEW
620    GtkWidget *view = gtk_text_view_new_with_buffer(context->notes.buffer);    GtkWidget *view = gtk_text_view_new_with_buffer(context->notes.buffer);
621  #else  #else
622    GtkWidget *view = hildon_text_view_new();    GtkWidget *view = hildon_text_view_new();
# Line 612  GtkWidget *cache_notes(cache_context_t * Line 634  GtkWidget *cache_notes(cache_context_t *
634    gtk_text_buffer_set_rich_text_format(context->notes.buffer, "RTF" );    gtk_text_buffer_set_rich_text_format(context->notes.buffer, "RTF" );
635  #endif  #endif
636    
637    #ifndef NO_COPY_N_PASTE
638    g_signal_connect(G_OBJECT(view), "focus-in-event",    g_signal_connect(G_OBJECT(view), "focus-in-event",
639                     G_CALLBACK(focus_in), appdata);                     G_CALLBACK(focus_in), context->appdata);
640    g_signal_connect(G_OBJECT(view), "destroy",    g_signal_connect(G_OBJECT(view), "destroy",
641                     G_CALLBACK(on_destroy_textview), appdata);                     G_CALLBACK(on_destroy_textview), context->appdata);
642    #endif
643    
644  #ifndef USE_PANNABLE_AREA  #ifndef USE_PANNABLE_AREA
645    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 845  void notes_log_export(appdata_t *appdata
845    GtkWidget *label = gtk_label_new(_("Export to:"));    GtkWidget *label = gtk_label_new(_("Export to:"));
846    gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, TRUE,0);    gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, TRUE,0);
847    gtk_misc_set_alignment(GTK_MISC(label), 0.f, 0.5f);    gtk_misc_set_alignment(GTK_MISC(label), 0.f, 0.5f);
848    GtkWidget *button = gtk_button_new_with_label(_("Browse..."));    GtkWidget *button = gtk_button_new_with_label(_("Browse"));
849    gtk_signal_connect(GTK_OBJECT(button), "clicked",    gtk_signal_connect(GTK_OBJECT(button), "clicked",
850                       GTK_SIGNAL_FUNC(on_browse), (gpointer)&context);                       GTK_SIGNAL_FUNC(on_browse), (gpointer)&context);
851    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 965  void notes_log_export(appdata_t *appdata
965          ccontext.appdata = appdata;          ccontext.appdata = appdata;
966          ccontext.cache = llog->cache;          ccontext.cache = llog->cache;
967    
968          notes_save(&ccontext,          notes_write_file(&ccontext,
969                     llog->cache->notes->text, llog->cache->notes->pos,                     llog->cache->notes->text, llog->cache->notes->pos,
970                     llog->cache->notes->override, llog->cache->notes->found,                     llog->cache->notes->override, llog->cache->notes->found,
971                     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.133