Diff of /trunk/src/notes.c

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

revision 205 by harbaum, Mon Nov 23 20:12:22 2009 UTC revision 233 by harbaum, Wed Dec 9 19:45:36 2009 UTC
# Line 48  void gtk_text_buffer_set_rich_text_forma Line 48  void gtk_text_buffer_set_rich_text_forma
48    
49  #define TAG_STATE  GTK_STATE_PRELIGHT  #define TAG_STATE  GTK_STATE_PRELIGHT
50    
 static GtkWidget *check_button_new_with_label(char *label) {  
 #if !defined(USE_MAEMO) || (MAEMO_VERSION_MAJOR < 5)  
   return gtk_check_button_new_with_label(label);  
 #else  
   GtkWidget *cbut =  
     hildon_check_button_new(HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH);  
   gtk_button_set_label(GTK_BUTTON(cbut), label);  
   return cbut;  
 #endif  
 }  
   
 static void check_button_set_active(GtkWidget *button, gboolean active) {  
 #if !defined(USE_MAEMO) || (MAEMO_VERSION_MAJOR < 5)  
   gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), active);  
 #else  
   hildon_check_button_set_active(HILDON_CHECK_BUTTON(button), active);  
 #endif  
 }  
   
 static gboolean check_button_get_active(GtkWidget *button) {  
 #if !defined(USE_MAEMO) || (MAEMO_VERSION_MAJOR < 5)  
   return gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button));  
 #else  
   return hildon_check_button_get_active(HILDON_CHECK_BUTTON(button));  
 #endif  
 }  
   
51  static notes_t *notes_load(appdata_t *appdata, cache_t *cache) {  static notes_t *notes_load(appdata_t *appdata, cache_t *cache) {
52    notes_t *notes = NULL;    notes_t *notes = NULL;
53    xmlDoc *doc = NULL;    xmlDoc *doc = NULL;
# Line 198  static int notes_write_file(cache_contex Line 171  static int notes_write_file(cache_contex
171                        char *text, pos_t pos,                        char *text, pos_t pos,
172                        gboolean override, gboolean found,                        gboolean override, gboolean found,
173                        time_t ftime, gboolean logged) {                        time_t ftime, gboolean logged) {
174    
175      g_assert(context);
176      g_assert(context->cache);
177    
178    /* build local path */    /* build local path */
179    int path_len = strlen(context->appdata->image_path) +    int path_len = strlen(context->appdata->image_path) +
180      2 * strlen(context->cache->id) + 6;      2 * strlen(context->cache->id) + 6;
181    
182    char *path = malloc(path_len);    char *path = malloc(path_len);
183    snprintf(path, path_len, "%s%s/%s.gpx",    snprintf(path, path_len, "%s%s/%s.gpx",
184             context->appdata->image_path,             context->appdata->image_path,
# Line 273  static void notes_save(cache_context_t * Line 251  static void notes_save(cache_context_t *
251    /* or has been changed */    /* or has been changed */
252    
253    if(context->notes.modified) {    if(context->notes.modified) {
254    #ifdef USE_STACKABLE_WINDOW
255        context->notes_have_been_changed = TRUE;
256    #endif
257    
258      printf("something has been modified, saving notes\n");      printf("something has been modified, saving notes\n");
259    
260      GtkTextIter start;      GtkTextIter start;
# Line 283  static void notes_save(cache_context_t * Line 265  static void notes_save(cache_context_t *
265                                            &start, &end, FALSE);                                            &start, &end, FALSE);
266    
267      pos_t pos;      pos_t pos;
268      pos.lat = lat_get(context->notes.latw);      pos.lat = lat_entry_get(context->notes.latw);
269      pos.lon = lon_get(context->notes.lonw);      pos.lon = lon_entry_get(context->notes.lonw);
270    
271      gboolean override =      gboolean override =
272        check_button_get_active(context->notes.overridew);        check_button_get_active(context->notes.overridew);
# Line 293  static void notes_save(cache_context_t * Line 275  static void notes_save(cache_context_t *
275      gboolean logged =      gboolean logged =
276        check_button_get_active(context->notes.loggedw);        check_button_get_active(context->notes.loggedw);
277    
278      /* required accuracy is 1/60000 degree */      if(pos_differ(&pos, &context->cache->pos))
279      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);  
280      if(override || found)      if(override || found)
281        printf("flags are set\n");        printf("flags are set\n");
282      if(strlen(text))      if(strlen(text))
283        printf("text is present\n");        printf("text is present\n");
284    
285      /* check if the notes are empty */      /* check if the notes are empty */
286      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)) &&  
287         !override && !found && !logged && (strlen(text) == 0)) {         !override && !found && !logged && (strlen(text) == 0)) {
288        printf("notes are in default state, removing them if present\n");        printf("notes are in default state, removing them if present\n");
289    
# Line 363  static void notes_save(cache_context_t * Line 336  static void notes_save(cache_context_t *
336        /* we have to do two things here: */        /* we have to do two things here: */
337        /* - update the notes.xml file on disk */        /* - update the notes.xml file on disk */
338        /* - update the notes entry in the loaded gpx tree */        /* - update the notes entry in the loaded gpx tree */
339    
340        /* update file on disk */        /* update file on disk */
341        notes_write_file(context, text, pos, override, found,        notes_write_file(context, text, pos, override, found,
342                         context->notes.ftime, logged);                         context->notes.ftime, logged);
343    
344        /* search for matching caches and replace note there */        /* search for matching caches and replace note there */
345        notes_t *note = NULL;        notes_t *note = NULL;
346        gpx_t *gpx = context->appdata->gpx;        gpx_t *gpx = context->appdata->gpx;
# Line 618  GtkWidget *cache_notes(cache_context_t * Line 591  GtkWidget *cache_notes(cache_context_t *
591    GtkWidget *table = gtk_table_new(2, 4, FALSE);    GtkWidget *table = gtk_table_new(2, 4, FALSE);
592  #if !defined(USE_MAEMO) || (MAEMO_VERSION_MAJOR < 5)  #if !defined(USE_MAEMO) || (MAEMO_VERSION_MAJOR < 5)
593    gtk_table_set_col_spacing(GTK_TABLE(table), 0, 16);    gtk_table_set_col_spacing(GTK_TABLE(table), 0, 16);
   gtk_table_set_col_spacing(GTK_TABLE(table), 2, 16);  
594  #endif  #endif
595    
596      gtk_table_set_col_spacing(GTK_TABLE(table), 2, 16);
597    
598    gtk_table_attach_defaults(GTK_TABLE(table),    gtk_table_attach_defaults(GTK_TABLE(table),
599                      gtk_label_new(_("New coordinate:")), 0, 1, 0, 1);                      gtk_label_new(_("New coordinate:")), 0, 1, 0, 1);
600    context->notes.overridew = check_button_new_with_label(_("Override"));    context->notes.overridew = check_button_new_with_label(_("Override"));
601    check_button_set_active(context->notes.overridew,    check_button_set_active(context->notes.overridew,
602                            cache->notes && cache->notes->override);                            cache->notes && cache->notes->override);
603    gtk_table_attach_defaults(GTK_TABLE(table),    gtk_table_attach_defaults(GTK_TABLE(table),
604                              context->notes.overridew, 0, 1, 1, 2);                              context->notes.overridew, 2, 3, 0, 1);
605    
606    GtkWidget *hbox = gtk_hbox_new(FALSE, 2);    GtkWidget *hbox = gtk_hbox_new(FALSE, 2);
607    
# Line 659  GtkWidget *cache_notes(cache_context_t * Line 633  GtkWidget *cache_notes(cache_context_t *
633    if(cache->notes) pos = cache->notes->pos;    if(cache->notes) pos = cache->notes->pos;
634    
635    gtk_table_attach_defaults(GTK_TABLE(table),    gtk_table_attach_defaults(GTK_TABLE(table),
636              context->notes.latw = lat_entry_new(pos.lat), 2, 3, 0, 1);              context->notes.latw = lat_entry_new(pos.lat), 0, 1, 1, 2);
637    g_signal_connect(G_OBJECT(context->notes.latw), "focus-out-event",    g_signal_connect(G_OBJECT(context->notes.latw), "focus-out-event",
638                     G_CALLBACK(focus_out), context);                     G_CALLBACK(focus_out), context);
639    
# Line 762  void notes_free(notes_t *notes) { Line 736  void notes_free(notes_t *notes) {
736  pos_t notes_get_pos(cache_context_t *context) {  pos_t notes_get_pos(cache_context_t *context) {
737    pos_t pos = context->cache->pos;    pos_t pos = context->cache->pos;
738    if(check_button_get_active(context->notes.overridew)) {    if(check_button_get_active(context->notes.overridew)) {
739      pos.lat = lat_get(context->notes.latw);      pos.lat = lat_entry_get(context->notes.latw);
740      pos.lon = lon_get(context->notes.lonw);      pos.lon = lon_entry_get(context->notes.lonw);
741    }    }
742    return pos;    return pos;
743  }  }
# Line 777  typedef struct { Line 751  typedef struct {
751    GtkWidget *info_label;    GtkWidget *info_label;
752    GtkWidget *dialog;    GtkWidget *dialog;
753    appdata_t *appdata;    appdata_t *appdata;
   GtkWidget *path_label;  
754  } export_context_t;  } export_context_t;
755    
 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);  
 }  
   
756  typedef struct log_chain_s {  typedef struct log_chain_s {
757    cache_t *cache;    cache_t *cache;
758    struct log_chain_s *next;    struct log_chain_s *next;
# Line 918  void notes_log_export(appdata_t *appdata Line 842  void notes_log_export(appdata_t *appdata
842    /* ------------------ path/file ------------------ */    /* ------------------ path/file ------------------ */
843    gtk_box_pack_start_defaults(GTK_BOX(vbox), gtk_hseparator_new());    gtk_box_pack_start_defaults(GTK_BOX(vbox), gtk_hseparator_new());
844    
845    GtkWidget *hbox = gtk_hbox_new(FALSE, 0);    gtk_box_pack_start_defaults(GTK_BOX(vbox),
846    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"));  
 #if defined(USE_MAEMO) && (MAEMO_VERSION_MAJOR == 5)  
   hildon_gtk_widget_set_theme_size(button,  
            (HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH));  
 #endif  
   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);  
847    
848    label = gtk_label_new(_("(a %s in the filename will be replaced by the "    GtkWidget *label =
849                            "current date and time)"));      gtk_label_new(_("(a %s in the filename will be replaced by the "
850                        "current date and time)"));
851    gtk_label_set_line_wrap_mode(GTK_LABEL(label), PANGO_WRAP_WORD);    gtk_label_set_line_wrap_mode(GTK_LABEL(label), PANGO_WRAP_WORD);
852    gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);    gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
853    gtk_misc_set_alignment(GTK_MISC(label), 0.f, 0.5f);    gtk_misc_set_alignment(GTK_MISC(label), 0.f, 0.5f);

Legend:
Removed from v.205  
changed lines
  Added in v.233