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 259 by harbaum, Sat May 15 12:27:40 2010 UTC
# Line 19  Line 19 
19    
20  #include <stdio.h>  #include <stdio.h>
21  #include <string.h>  #include <string.h>
22    #include <errno.h>
23    
24  #include <glib/gunicode.h>  #include <glib/gunicode.h>
25    
# Line 27  Line 28 
28    
29  #include <math.h>  #include <math.h>
30    
31    #if defined(USE_MAEMO) && (MAEMO_VERSION_MAJOR >= 5)
32    #include <hildon/hildon-note.h>
33    #include <hildon/hildon-entry.h>
34    #include <hildon/hildon-check-button.h>
35    #endif
36    
37  #if !defined(LIBXML_TREE_ENABLED) || !defined(LIBXML_OUTPUT_ENABLED)  #if !defined(LIBXML_TREE_ENABLED) || !defined(LIBXML_OUTPUT_ENABLED)
38  #error "libxml doesn't support required tree or output"  #error "libxml doesn't support required tree or output"
39  #endif  #endif
40    
41  #include "gpxview.h"  #include "gpxview.h"
42    
43    #if defined(USE_MAEMO) && (MAEMO_VERSION_MAJOR >= 5)
44    #include <hildon/hildon-note.h>
45    #endif
46    
47  void gtk_text_buffer_set_can_paste_rich_text(GtkTextBuffer *buffer, gboolean);  void gtk_text_buffer_set_can_paste_rich_text(GtkTextBuffer *buffer, gboolean);
48  void gtk_text_buffer_set_rich_text_format(GtkTextBuffer *buffer, const gchar *);  void gtk_text_buffer_set_rich_text_format(GtkTextBuffer *buffer, const gchar *);
49    
# Line 157  void notes_load_all(appdata_t *appdata, Line 168  void notes_load_all(appdata_t *appdata,
168    }    }
169  }  }
170    
171  static int notes_save(cache_context_t *context,  static int notes_write_file(cache_context_t *context,
172                        char *text, pos_t pos,                        char *text, pos_t pos,
173                        gboolean override, gboolean found,                        gboolean override, gboolean found,
174                        time_t ftime, gboolean logged) {                        time_t ftime, gboolean logged) {
175    
176      g_assert(context);
177      g_assert(context->cache);
178    
179    /* build local path */    /* build local path */
180    int path_len = strlen(context->appdata->image_path) +    int path_len = strlen(context->appdata->image_path) +
181      2 * strlen(context->cache->id) + 6;      2 * strlen(context->cache->id) + 6;
182    
183    char *path = malloc(path_len);    char *path = malloc(path_len);
184    snprintf(path, path_len, "%s%s/%s.gpx",    snprintf(path, path_len, "%s%s/%s.gpx",
185             context->appdata->image_path,             context->appdata->image_path,
# Line 230  static int notes_save(cache_context_t *c Line 246  static int notes_save(cache_context_t *c
246    return 0;    return 0;
247  }  }
248    
249  /* 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");  
   
250    /* only save if: there is a text which has been changed or */    /* only save if: there is a text which has been changed or */
251    /* there is a position which differs from the original one */    /* there is a position which differs from the original one */
252    /* or has been changed */    /* or has been changed */
253    
254    if(context->notes.modified) {    if(context->notes.modified) {
255    #ifdef USE_STACKABLE_WINDOW
256        context->notes_have_been_changed = TRUE;
257    #endif
258    
259      printf("something has been modified, saving notes\n");      printf("something has been modified, saving notes\n");
260    
261      GtkTextIter start;      GtkTextIter start;
# Line 251  gint notes_destroy_event(GtkWidget *widg Line 266  gint notes_destroy_event(GtkWidget *widg
266                                            &start, &end, FALSE);                                            &start, &end, FALSE);
267    
268      pos_t pos;      pos_t pos;
269      pos.lat = lat_get(context->notes.latw);      pos.lat = lat_entry_get(context->notes.latw);
270      pos.lon = lon_get(context->notes.lonw);      pos.lon = lon_entry_get(context->notes.lonw);
271    
272      gboolean override =      gboolean override =
273        gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(context->notes.overridew));        check_button_get_active(context->notes.overridew);
274      gboolean found =      gboolean found =
275        gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(context->notes.foundw));        check_button_get_active(context->notes.foundw);
276      gboolean logged =      gboolean logged =
277        gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(context->notes.loggedw));        check_button_get_active(context->notes.loggedw);
278    
279      /* required accuracy is 1/60000 degree */      if(pos_differ(&pos, &context->cache->pos))
280      if(((int)(pos.lat * 60000 + .5) !=        printf("position is modified\n");
         (int)(context->cache->pos.lat * 60000 + .5)) ||  
        ((int)(pos.lon * 60000 + .5) !=  
         (int)(context->cache->pos.lon * 60000 + .5)))  
       printf("position is modified %f != %f / %f != %f\n",  
              pos.lat * 60000 + .5, context->cache->pos.lat * 60000 + .5,  
              pos.lon * 60000 + .5, context->cache->pos.lon * 60000 + .5);  
281      if(override || found)      if(override || found)
282        printf("flags are set\n");        printf("flags are set\n");
283      if(strlen(text))      if(strlen(text))
284        printf("text is present\n");        printf("text is present\n");
285    
286      /* check if the notes are empty */      /* check if the notes are empty */
287      if(((int)(pos.lat * 60000 + .5) ==      if(!pos_differ(&pos, &context->cache->pos) &&
         (int)(context->cache->pos.lat * 60000 + .5)) &&  
        ((int)(pos.lon * 60000 + .5) ==  
         (int)(context->cache->pos.lon * 60000 + .5)) &&  
288         !override && !found && !logged && (strlen(text) == 0)) {         !override && !found && !logged && (strlen(text) == 0)) {
289        printf("notes are in default state, removing them if present\n");        printf("notes are in default state, removing them if present\n");
290    
# Line 331  gint notes_destroy_event(GtkWidget *widg Line 337  gint notes_destroy_event(GtkWidget *widg
337        /* we have to do two things here: */        /* we have to do two things here: */
338        /* - update the notes.xml file on disk */        /* - update the notes.xml file on disk */
339        /* - update the notes entry in the loaded gpx tree */        /* - update the notes entry in the loaded gpx tree */
   
       /* update file on disk */  
       notes_save(context, text, pos, override, found,  
                  context->notes.ftime, logged);  
340    
341          /* update file on disk */
342          notes_write_file(context, text, pos, override, found,
343                           context->notes.ftime, logged);
344    
345        /* search for matching caches and replace note there */        /* search for matching caches and replace note there */
346        notes_t *note = NULL;        notes_t *note = NULL;
347        gpx_t *gpx = context->appdata->gpx;        gpx_t *gpx = context->appdata->gpx;
# Line 382  gint notes_destroy_event(GtkWidget *widg Line 388  gint notes_destroy_event(GtkWidget *widg
388    
389      if(text) free(text);      if(text) free(text);
390    }    }
391    }
392    
393    /* this is called from the destroy event of the entire notebook */
394    gint notes_destroy_event(GtkWidget *widget, gpointer data ) {
395      cache_context_t *context = (cache_context_t*)data;
396    
397      printf("about to destroy notes view\n");
398      notes_save(context);
399    
400    return FALSE;    return FALSE;
401  }  }
# Line 418  static void on_destroy_textview(GtkWidge Line 432  static void on_destroy_textview(GtkWidge
432  static void ftime_update(GtkWidget *widget, cache_context_t *context,  static void ftime_update(GtkWidget *widget, cache_context_t *context,
433                           gboolean update) {                           gboolean update) {
434    /* check if it has been selected */    /* check if it has been selected */
435    if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))) {    if(check_button_get_active(widget)) {
436      printf("set active\n");      printf("set active\n");
437    
438      if(update)      if(update)
# Line 450  static void callback_modified(GtkWidget Line 464  static void callback_modified(GtkWidget
464      printf("was foundw\n");      printf("was foundw\n");
465    
466      /* about to remove "found" flag -> ask for confirmation */      /* about to remove "found" flag -> ask for confirmation */
467      if(!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))) {      if(!check_button_get_active(widget)) {
468    #if !defined(USE_MAEMO) || (MAEMO_VERSION_MAJOR < 5)
469        GtkWidget *dialog = gtk_message_dialog_new(        GtkWidget *dialog = gtk_message_dialog_new(
470                   GTK_WINDOW(context->appdata->window),                   GTK_WINDOW(context->appdata->window),
471                   GTK_DIALOG_DESTROY_WITH_PARENT,                   GTK_DIALOG_DESTROY_WITH_PARENT,
# Line 464  static void callback_modified(GtkWidget Line 479  static void callback_modified(GtkWidget
479        if(GTK_RESPONSE_NO == gtk_dialog_run(GTK_DIALOG(dialog)))        if(GTK_RESPONSE_NO == gtk_dialog_run(GTK_DIALOG(dialog)))
480          gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), TRUE);          gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), TRUE);
481    
482    #else
483          GtkWidget *dialog =
484            hildon_note_new_confirmation(GTK_WINDOW(context->appdata->window),
485                     _("Do you really want to remove the \"found\" flag? "
486                       "This will void the recorded date of your find!"));
487    
488          /* set the active flag again if the user answered "no" */
489          if(GTK_RESPONSE_OK != gtk_dialog_run(GTK_DIALOG(dialog)))
490            gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), TRUE);
491    #endif
492    
493        gtk_widget_destroy(dialog);        gtk_widget_destroy(dialog);
494      }      }
495    
# Line 474  static void callback_modified(GtkWidget Line 500  static void callback_modified(GtkWidget
500      printf("was loggedw\n");      printf("was loggedw\n");
501    
502      /* about to remove "found" flag -> ask for confirmation */      /* about to remove "found" flag -> ask for confirmation */
503      if(!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))) {      if(!check_button_get_active(widget)) {
504    #if !defined(USE_MAEMO) || (MAEMO_VERSION_MAJOR < 5)
505        GtkWidget *dialog = gtk_message_dialog_new(        GtkWidget *dialog = gtk_message_dialog_new(
506                   GTK_WINDOW(context->appdata->window),                   GTK_WINDOW(context->appdata->window),
507                   GTK_DIALOG_DESTROY_WITH_PARENT,                   GTK_DIALOG_DESTROY_WITH_PARENT,
# Line 493  static void callback_modified(GtkWidget Line 520  static void callback_modified(GtkWidget
520          gtk_widget_set_sensitive(context->notes.foundw, TRUE);          gtk_widget_set_sensitive(context->notes.foundw, TRUE);
521        }        }
522    
523    #else
524          GtkWidget *dialog =
525            hildon_note_new_confirmation(GTK_WINDOW(context->appdata->window),
526                       _("Do you really want to remove the \"logged\" flag? "
527                       "This may cause problems on your next Garmin Field "
528                       "Notes upload!"));
529    
530          /* set the active flag again if the user answered "no" */
531          if(GTK_RESPONSE_OK != gtk_dialog_run(GTK_DIALOG(dialog)))
532            gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), TRUE);
533          else {
534            gtk_widget_set_sensitive(widget, FALSE);
535            gtk_widget_set_sensitive(context->notes.foundw, TRUE);
536          }
537    
538    #endif
539    
540        gtk_widget_destroy(dialog);        gtk_widget_destroy(dialog);
541      }      }
542    }    }
# Line 519  static gboolean focus_in(GtkWidget *widg Line 563  static gboolean focus_in(GtkWidget *widg
563  }  }
564  #endif  #endif
565    
566    static gboolean focus_out(GtkWidget *widget, GdkEventFocus *event,
567                             gpointer data) {
568      cache_context_t *context = (cache_context_t*)data;
569    
570      notes_save(context);
571    #if !defined(USE_MAEMO) && defined(ENABLE_OSM_GPS_MAP)
572      map_update(context->appdata);
573    #endif
574    
575      return FALSE;
576    }
577    
578  GtkWidget *cache_notes(cache_context_t *context) {  GtkWidget *cache_notes(cache_context_t *context) {
   appdata_t *appdata = context->appdata;  
579    cache_t *cache = context->cache;    cache_t *cache = context->cache;
580    
581    context->notes.modified = FALSE;    context->notes.modified = FALSE;
# Line 535  GtkWidget *cache_notes(cache_context_t * Line 590  GtkWidget *cache_notes(cache_context_t *
590    /* -------------- custom coordinate ---------------- */    /* -------------- custom coordinate ---------------- */
591    
592    GtkWidget *table = gtk_table_new(2, 4, FALSE);    GtkWidget *table = gtk_table_new(2, 4, FALSE);
593    #if !defined(USE_MAEMO) || (MAEMO_VERSION_MAJOR < 5)
594    gtk_table_set_col_spacing(GTK_TABLE(table), 0, 16);    gtk_table_set_col_spacing(GTK_TABLE(table), 0, 16);
595    #endif
596    
597    gtk_table_set_col_spacing(GTK_TABLE(table), 2, 16);    gtk_table_set_col_spacing(GTK_TABLE(table), 2, 16);
598    
599    gtk_table_attach_defaults(GTK_TABLE(table),    gtk_table_attach_defaults(GTK_TABLE(table),
600                      gtk_label_new(_("New coordinate:")), 0, 1, 0, 1);                      gtk_label_new(_("New coordinate:")), 0, 1, 0, 1);
601    context->notes.overridew = gtk_check_button_new_with_label(_("Override"));    context->notes.overridew = check_button_new_with_label(_("Override"));
602    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(context->notes.overridew),    check_button_set_active(context->notes.overridew,
603                                 cache->notes && cache->notes->override);                            cache->notes && cache->notes->override);
604    gtk_table_attach_defaults(GTK_TABLE(table),    gtk_table_attach_defaults(GTK_TABLE(table),
605                              context->notes.overridew, 0, 1, 1, 2);                              context->notes.overridew, 2, 3, 0, 1);
606    
607    GtkWidget *hbox = gtk_hbox_new(FALSE, 2);    GtkWidget *hbox = gtk_hbox_new(FALSE, 2);
608    
609    context->notes.foundw = gtk_check_button_new_with_label(_("Found"));    context->notes.foundw = check_button_new_with_label(_("Found"));
610    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(context->notes.foundw),    check_button_set_active(context->notes.foundw,
611                                 cache->notes && cache->notes->found);                            cache->notes && cache->notes->found);
612    gtk_box_pack_start_defaults(GTK_BOX(hbox), context->notes.foundw);    gtk_box_pack_start_defaults(GTK_BOX(hbox), context->notes.foundw);
613    
614    context->notes.loggedw = gtk_check_button_new_with_label(_("Logged"));    context->notes.loggedw = check_button_new_with_label(_("Logged"));
615    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(context->notes.loggedw),    check_button_set_active(context->notes.loggedw,
616                                 cache->notes && cache->notes->logged);                            cache->notes && cache->notes->logged);
617    gtk_box_pack_start_defaults(GTK_BOX(hbox), context->notes.loggedw);    gtk_box_pack_start_defaults(GTK_BOX(hbox), context->notes.loggedw);
618    
619    gtk_table_attach_defaults(GTK_TABLE(table), hbox, 3, 4, 0, 1);    gtk_table_attach_defaults(GTK_TABLE(table), hbox, 3, 4, 0, 1);
# Line 567  GtkWidget *cache_notes(cache_context_t * Line 625  GtkWidget *cache_notes(cache_context_t *
625      gtk_widget_set_sensitive(context->notes.foundw, FALSE);      gtk_widget_set_sensitive(context->notes.foundw, FALSE);
626    
627    context->notes.datew = gtk_label_new("");    context->notes.datew = gtk_label_new("");
628    gtk_misc_set_alignment(GTK_MISC(context->notes.datew), 0.0f, 0.5f);    gtk_misc_set_alignment(GTK_MISC(context->notes.datew), 0.5f, 0.5f);
629    gtk_table_attach_defaults(GTK_TABLE(table),    gtk_table_attach_defaults(GTK_TABLE(table),
630                              context->notes.datew, 3, 4, 1, 2);                              context->notes.datew, 3, 4, 1, 2);
631    ftime_update(context->notes.foundw, context, FALSE);    ftime_update(context->notes.foundw, context, FALSE);
# Line 575  GtkWidget *cache_notes(cache_context_t * Line 633  GtkWidget *cache_notes(cache_context_t *
633    pos_t pos = gpx_cache_pos(cache);    pos_t pos = gpx_cache_pos(cache);
634    if(cache->notes) pos = cache->notes->pos;    if(cache->notes) pos = cache->notes->pos;
635    
636    gtk_table_attach_defaults(GTK_TABLE(table),    context->notes.latw = lat_entry_new(pos.lat);
637              context->notes.latw = lat_entry_new(pos.lat), 2, 3, 0, 1);    context->notes.lonw = lon_entry_new(pos.lon);
638      GtkWidget *picker =
639        preset_coordinate_picker(context->appdata,
640                                 context->notes.latw, context->notes.lonw);
641    
642      g_signal_connect(G_OBJECT(context->notes.latw), "focus-out-event",
643                       G_CALLBACK(focus_out), context);
644      g_signal_connect(G_OBJECT(context->notes.lonw), "focus-out-event",
645                       G_CALLBACK(focus_out), context);
646    
647    
648      GtkWidget *ihbox = gtk_hbox_new(FALSE, 0);
649    
650      gtk_box_pack_start_defaults(GTK_BOX(ihbox), context->notes.latw);
651      gtk_box_pack_start_defaults(GTK_BOX(ihbox), context->notes.lonw);
652      gtk_box_pack_start_defaults(GTK_BOX(ihbox), picker);
653    
654    gtk_table_attach_defaults(GTK_TABLE(table),    gtk_table_attach_defaults(GTK_TABLE(table),
655              context->notes.lonw = lon_entry_new(pos.lon), 2, 3, 1, 2);                              ihbox, 0, 3, 1, 2);
656    
657    #if !defined(USE_MAEMO) || (MAEMO_VERSION_MAJOR < 5)
658    hbox = gtk_hbox_new(FALSE, 0);    hbox = gtk_hbox_new(FALSE, 0);
659    gtk_box_pack_start(GTK_BOX(hbox), table, FALSE, FALSE, 0);    gtk_box_pack_start(GTK_BOX(hbox), table, FALSE, FALSE, 0);
660    gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);    gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
661    #else
662      gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
663    #endif
664    
665  #ifndef USE_PANNABLE_AREA  #ifndef USE_PANNABLE_AREA
666    GtkWidget *scrolled_window = gtk_scrolled_window_new(NULL, NULL);    GtkWidget *scrolled_window = gtk_scrolled_window_new(NULL, NULL);
# Line 598  GtkWidget *cache_notes(cache_context_t * Line 675  GtkWidget *cache_notes(cache_context_t *
675    if(cache->notes && cache->notes->text)    if(cache->notes && cache->notes->text)
676      gtk_text_buffer_set_text(context->notes.buffer, cache->notes->text, -1);      gtk_text_buffer_set_text(context->notes.buffer, cache->notes->text, -1);
677    
678  #ifndef USE_MAEMO  #ifndef USE_HILDON_TEXT_VIEW
679    GtkWidget *view = gtk_text_view_new_with_buffer(context->notes.buffer);    GtkWidget *view = gtk_text_view_new_with_buffer(context->notes.buffer);
680  #else  #else
681    GtkWidget *view = hildon_text_view_new();    GtkWidget *view = hildon_text_view_new();
682    hildon_text_view_set_buffer(HILDON_TEXT_VIEW(view), context->notes.buffer);    hildon_text_view_set_buffer(HILDON_TEXT_VIEW(view), context->notes.buffer);
683  #endif  #endif
684    
685      /* if the cache has been marked found in the logs already, there's */
686      /* no need/use to be able to change all this */
687      if(cache->found) {
688        gtk_widget_set_sensitive(table, FALSE);
689        gtk_widget_set_sensitive(view, FALSE);
690      }
691    
692    gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(view), GTK_WRAP_WORD);    gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(view), GTK_WRAP_WORD);
693    gtk_text_view_set_editable(GTK_TEXT_VIEW(view), TRUE);    gtk_text_view_set_editable(GTK_TEXT_VIEW(view), TRUE);
694    gtk_text_view_set_left_margin(GTK_TEXT_VIEW(view), 2 );    gtk_text_view_set_left_margin(GTK_TEXT_VIEW(view), 2 );
# Line 618  GtkWidget *cache_notes(cache_context_t * Line 702  GtkWidget *cache_notes(cache_context_t *
702    
703  #ifndef NO_COPY_N_PASTE  #ifndef NO_COPY_N_PASTE
704    g_signal_connect(G_OBJECT(view), "focus-in-event",    g_signal_connect(G_OBJECT(view), "focus-in-event",
705                     G_CALLBACK(focus_in), appdata);                     G_CALLBACK(focus_in), context->appdata);
706    g_signal_connect(G_OBJECT(view), "destroy",    g_signal_connect(G_OBJECT(view), "destroy",
707                     G_CALLBACK(on_destroy_textview), appdata);                     G_CALLBACK(on_destroy_textview), context->appdata);
708  #endif  #endif
709    
710  #ifndef USE_PANNABLE_AREA  #ifndef USE_PANNABLE_AREA
# Line 663  void notes_free(notes_t *notes) { Line 747  void notes_free(notes_t *notes) {
747    
748  pos_t notes_get_pos(cache_context_t *context) {  pos_t notes_get_pos(cache_context_t *context) {
749    pos_t pos = context->cache->pos;    pos_t pos = context->cache->pos;
750    if(gtk_toggle_button_get_active(    if(check_button_get_active(context->notes.overridew)) {
751                   GTK_TOGGLE_BUTTON(context->notes.overridew))) {      pos.lat = lat_entry_get(context->notes.latw);
752      pos.lat = lat_get(context->notes.latw);      pos.lon = lon_entry_get(context->notes.lonw);
     pos.lon = lon_get(context->notes.lonw);  
753    }    }
754    return pos;    return pos;
755  }  }
756    
757  gboolean notes_get_override(cache_context_t *context) {  gboolean notes_get_override(cache_context_t *context) {
758    /* get override value */    /* get override value */
759    return gtk_toggle_button_get_active(    return check_button_get_active(context->notes.overridew);
                       GTK_TOGGLE_BUTTON(context->notes.overridew));  
   
760  }  }
761    
762  typedef struct {  typedef struct {
763    GtkWidget *info_label;    GtkWidget *info_label;
764    GtkWidget *dialog;    GtkWidget *dialog;
765    appdata_t *appdata;    appdata_t *appdata;
   GtkWidget *path_label;  
766  } export_context_t;  } export_context_t;
767    
 static void on_browse(GtkWidget *widget, gpointer data) {  
   GtkWidget *dialog;  
   
   export_context_t *context = (export_context_t*)data;  
   
 #ifdef USE_MAEMO  
   dialog = hildon_file_chooser_dialog_new(GTK_WINDOW(context->dialog),  
                                           GTK_FILE_CHOOSER_ACTION_SAVE);  
 #else  
   dialog = gtk_file_chooser_dialog_new(_("Save POI database"),  
                                        GTK_WINDOW(context->dialog),  
                                        GTK_FILE_CHOOSER_ACTION_SAVE,  
                                        GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,  
                                        GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,  
                                        NULL);  
 #endif  
   
   printf("set filename <%s>\n", context->appdata->fieldnotes_path);  
   
   if(!g_file_test(context->appdata->fieldnotes_path, G_FILE_TEST_EXISTS)) {  
     char *last_sep = strrchr(context->appdata->fieldnotes_path, '/');  
     if(last_sep) {  
       *last_sep = 0;  // seperate path from file  
   
       /* the user just created a new document */  
       gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog),  
                                           context->appdata->fieldnotes_path);  
       gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(dialog), last_sep+1);  
   
       /* restore full filename */  
       *last_sep = '/';  
     }  
   } else  
     gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(dialog),  
                                   context->appdata->fieldnotes_path);  
   
   if (gtk_dialog_run (GTK_DIALOG(dialog)) == GTK_FM_OK) {  
     gchar *name = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));  
     if(name) {  
       free(context->appdata->fieldnotes_path);  
       context->appdata->fieldnotes_path = strdup(name);  
       gtk_label_set_text(GTK_LABEL(context->path_label),  
                          context->appdata->fieldnotes_path);  
     }  
   }  
   
   gtk_widget_destroy (dialog);  
 }  
   
768  typedef struct log_chain_s {  typedef struct log_chain_s {
769    cache_t *cache;    cache_t *cache;
770    struct log_chain_s *next;    struct log_chain_s *next;
# Line 823  void notes_log_export(appdata_t *appdata Line 854  void notes_log_export(appdata_t *appdata
854    /* ------------------ path/file ------------------ */    /* ------------------ path/file ------------------ */
855    gtk_box_pack_start_defaults(GTK_BOX(vbox), gtk_hseparator_new());    gtk_box_pack_start_defaults(GTK_BOX(vbox), gtk_hseparator_new());
856    
857    GtkWidget *hbox = gtk_hbox_new(FALSE, 0);    gtk_box_pack_start_defaults(GTK_BOX(vbox),
858    GtkWidget *label = gtk_label_new(_("Export to:"));       export_file(_("Save POI database"), &appdata->fieldnotes_path));
   gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, TRUE,0);  
   gtk_misc_set_alignment(GTK_MISC(label), 0.f, 0.5f);  
   GtkWidget *button = gtk_button_new_with_label(_("Browse"));  
   gtk_signal_connect(GTK_OBJECT(button), "clicked",  
                      GTK_SIGNAL_FUNC(on_browse), (gpointer)&context);  
   gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE,0);  
   gtk_box_pack_start_defaults(GTK_BOX(vbox), hbox);  
   
   context.path_label = gtk_label_new(appdata->fieldnotes_path);  
   gtk_misc_set_alignment(GTK_MISC(context.path_label), 0.f, 0.5f);  
   gtk_label_set_ellipsize(GTK_LABEL(context.path_label),  
                           PANGO_ELLIPSIZE_MIDDLE);  
   gtk_box_pack_start_defaults(GTK_BOX(vbox), context.path_label);  
859    
860    label = gtk_label_new(_("(a %s in the filename will be replaced by the "    GtkWidget *label =
861                            "current date and time)"));      gtk_label_new(_("(a %s in the filename will be replaced by the "
862                        "current date and time)"));
863    gtk_label_set_line_wrap_mode(GTK_LABEL(label), PANGO_WRAP_WORD);    gtk_label_set_line_wrap_mode(GTK_LABEL(label), PANGO_WRAP_WORD);
864    gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);    gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
865    gtk_misc_set_alignment(GTK_MISC(label), 0.f, 0.5f);    gtk_misc_set_alignment(GTK_MISC(label), 0.f, 0.5f);
# Line 859  void notes_log_export(appdata_t *appdata Line 878  void notes_log_export(appdata_t *appdata
878      time_t now = time(NULL);      time_t now = time(NULL);
879      struct tm *tm_now = localtime(&now);      struct tm *tm_now = localtime(&now);
880      char now_str[32];      char now_str[32];
881      strftime(now_str, sizeof(now_str)-1, "%F_%H:%M", tm_now);      strftime(now_str, sizeof(now_str)-1, "%F_%H-%M", tm_now);
882      char *fname = g_strdup_printf(appdata->fieldnotes_path, now_str);      char *fname = g_strdup_printf(appdata->fieldnotes_path, now_str);
883    
884      printf("--- about to export logs to %s ---\n", fname);      printf("--- about to export logs to %s ---\n", fname);
885      FILE *file = fopen(fname, "w");      FILE *file = fopen(fname, "w");
886      g_free(fname);      g_free(fname);
887    
888      if(file) {      if(file) {
   
889        llog = log;        llog = log;
890        while(llog) {        while(llog) {
891          printf("Exporting %s\n", llog->cache->id);          printf("Exporting %s\n", llog->cache->id);
# Line 947  void notes_log_export(appdata_t *appdata Line 966  void notes_log_export(appdata_t *appdata
966          ccontext.appdata = appdata;          ccontext.appdata = appdata;
967          ccontext.cache = llog->cache;          ccontext.cache = llog->cache;
968    
969          notes_save(&ccontext,          notes_write_file(&ccontext,
970                     llog->cache->notes->text, llog->cache->notes->pos,                     llog->cache->notes->text, llog->cache->notes->pos,
971                     llog->cache->notes->override, llog->cache->notes->found,                     llog->cache->notes->override, llog->cache->notes->found,
972                     llog->cache->notes->ftime, llog->cache->notes->logged);                     llog->cache->notes->ftime, llog->cache->notes->logged);
# Line 956  void notes_log_export(appdata_t *appdata Line 975  void notes_log_export(appdata_t *appdata
975        }        }
976    
977        fclose(file);        fclose(file);
978      }      } else
979          errorf(_("Can't open file:\n\n%s"), strerror(errno));
980    
981    } else {    } else {
982      /* restore old path, in case it has been altered but not been used */      /* restore old path, in case it has been altered but not been used */
983      free(appdata->fieldnotes_path);      free(appdata->fieldnotes_path);

Legend:
Removed from v.7  
changed lines
  Added in v.259