Diff of /trunk/src/notes.c

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

revision 164 by harbaum, Thu Nov 5 20:37:16 2009 UTC revision 190 by harbaum, Tue Nov 17 10:22:41 2009 UTC
# Line 27  Line 27 
27    
28  #include <math.h>  #include <math.h>
29    
30    #if defined(USE_MAEMO) && (MAEMO_VERSION_MAJOR >= 5)
31    #include <hildon/hildon-note.h>
32    #include <hildon/hildon-entry.h>
33    #include <hildon/hildon-check-button.h>
34    #endif
35    
36  #if !defined(LIBXML_TREE_ENABLED) || !defined(LIBXML_OUTPUT_ENABLED)  #if !defined(LIBXML_TREE_ENABLED) || !defined(LIBXML_OUTPUT_ENABLED)
37  #error "libxml doesn't support required tree or output"  #error "libxml doesn't support required tree or output"
38  #endif  #endif
# Line 42  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    
51    static GtkWidget *check_button_new_with_label(char *label) {
52    #if !defined(USE_MAEMO) || (MAEMO_VERSION_MAJOR < 5)
53      return gtk_check_button_new_with_label(label);
54    #else
55      GtkWidget *cbut =
56        hildon_check_button_new(HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH);
57      gtk_button_set_label(GTK_BUTTON(cbut), label);
58      return cbut;
59    #endif
60    }
61    
62    static void check_button_set_active(GtkWidget *button, gboolean active) {
63    #if !defined(USE_MAEMO) || (MAEMO_VERSION_MAJOR < 5)
64      gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), active);
65    #else
66      hildon_check_button_set_active(HILDON_CHECK_BUTTON(button), active);
67    #endif
68    }
69    
70    static gboolean check_button_get_active(GtkWidget *button) {
71    #if !defined(USE_MAEMO) || (MAEMO_VERSION_MAJOR < 5)
72      return gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button));
73    #else
74      return hildon_check_button_get_active(HILDON_CHECK_BUTTON(button));
75    #endif
76    }
77    
78  static notes_t *notes_load(appdata_t *appdata, cache_t *cache) {  static notes_t *notes_load(appdata_t *appdata, cache_t *cache) {
79    notes_t *notes = NULL;    notes_t *notes = NULL;
80    xmlDoc *doc = NULL;    xmlDoc *doc = NULL;
# Line 254  static void notes_save(cache_context_t * Line 287  static void notes_save(cache_context_t *
287      pos.lon = lon_get(context->notes.lonw);      pos.lon = lon_get(context->notes.lonw);
288    
289      gboolean override =      gboolean override =
290        gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(context->notes.overridew));        check_button_get_active(context->notes.overridew);
291      gboolean found =      gboolean found =
292        gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(context->notes.foundw));        check_button_get_active(context->notes.foundw);
293      gboolean logged =      gboolean logged =
294        gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(context->notes.loggedw));        check_button_get_active(context->notes.loggedw);
295    
296      /* required accuracy is 1/60000 degree */      /* required accuracy is 1/60000 degree */
297      if(((int)(pos.lat * 60000 + .5) !=      if(((int)(pos.lat * 60000 + .5) !=
# Line 425  static void on_destroy_textview(GtkWidge Line 458  static void on_destroy_textview(GtkWidge
458  static void ftime_update(GtkWidget *widget, cache_context_t *context,  static void ftime_update(GtkWidget *widget, cache_context_t *context,
459                           gboolean update) {                           gboolean update) {
460    /* check if it has been selected */    /* check if it has been selected */
461    if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))) {    if(check_button_get_active(GTK_TOGGLE_BUTTON(widget))) {
462      printf("set active\n");      printf("set active\n");
463    
464      if(update)      if(update)
# Line 457  static void callback_modified(GtkWidget Line 490  static void callback_modified(GtkWidget
490      printf("was foundw\n");      printf("was foundw\n");
491    
492      /* about to remove "found" flag -> ask for confirmation */      /* about to remove "found" flag -> ask for confirmation */
493      if(!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))) {      if(!check_button_get_active(widget)) {
494  #if !defined(USE_MAEMO) || (MAEMO_VERSION_MAJOR < 5)  #if !defined(USE_MAEMO) || (MAEMO_VERSION_MAJOR < 5)
495        GtkWidget *dialog = gtk_message_dialog_new(        GtkWidget *dialog = gtk_message_dialog_new(
496                   GTK_WINDOW(context->appdata->window),                   GTK_WINDOW(context->appdata->window),
# Line 493  static void callback_modified(GtkWidget Line 526  static void callback_modified(GtkWidget
526      printf("was loggedw\n");      printf("was loggedw\n");
527    
528      /* about to remove "found" flag -> ask for confirmation */      /* about to remove "found" flag -> ask for confirmation */
529      if(!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))) {      if(!check_button_get_active(widget)) {
530  #if !defined(USE_MAEMO) || (MAEMO_VERSION_MAJOR < 5)  #if !defined(USE_MAEMO) || (MAEMO_VERSION_MAJOR < 5)
531        GtkWidget *dialog = gtk_message_dialog_new(        GtkWidget *dialog = gtk_message_dialog_new(
532                   GTK_WINDOW(context->appdata->window),                   GTK_WINDOW(context->appdata->window),
# Line 583  GtkWidget *cache_notes(cache_context_t * Line 616  GtkWidget *cache_notes(cache_context_t *
616    /* -------------- custom coordinate ---------------- */    /* -------------- custom coordinate ---------------- */
617    
618    GtkWidget *table = gtk_table_new(2, 4, FALSE);    GtkWidget *table = gtk_table_new(2, 4, FALSE);
619    #if !defined(USE_MAEMO) || (MAEMO_VERSION_MAJOR < 5)
620    gtk_table_set_col_spacing(GTK_TABLE(table), 0, 16);    gtk_table_set_col_spacing(GTK_TABLE(table), 0, 16);
621    gtk_table_set_col_spacing(GTK_TABLE(table), 2, 16);    gtk_table_set_col_spacing(GTK_TABLE(table), 2, 16);
622    #endif
623    
624    gtk_table_attach_defaults(GTK_TABLE(table),    gtk_table_attach_defaults(GTK_TABLE(table),
625                      gtk_label_new(_("New coordinate:")), 0, 1, 0, 1);                      gtk_label_new(_("New coordinate:")), 0, 1, 0, 1);
626    context->notes.overridew = gtk_check_button_new_with_label(_("Override"));    context->notes.overridew = check_button_new_with_label(_("Override"));
627    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(context->notes.overridew),    check_button_set_active(context->notes.overridew,
628                                 cache->notes && cache->notes->override);                            cache->notes && cache->notes->override);
629    gtk_table_attach_defaults(GTK_TABLE(table),    gtk_table_attach_defaults(GTK_TABLE(table),
630                              context->notes.overridew, 0, 1, 1, 2);                              context->notes.overridew, 0, 1, 1, 2);
631    
632    GtkWidget *hbox = gtk_hbox_new(FALSE, 2);    GtkWidget *hbox = gtk_hbox_new(FALSE, 2);
633    
634    context->notes.foundw = gtk_check_button_new_with_label(_("Found"));    context->notes.foundw = check_button_new_with_label(_("Found"));
635    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(context->notes.foundw),    check_button_set_active(context->notes.foundw,
636                                 cache->notes && cache->notes->found);                            cache->notes && cache->notes->found);
637    gtk_box_pack_start_defaults(GTK_BOX(hbox), context->notes.foundw);    gtk_box_pack_start_defaults(GTK_BOX(hbox), context->notes.foundw);
638    
639    context->notes.loggedw = gtk_check_button_new_with_label(_("Logged"));    context->notes.loggedw = check_button_new_with_label(_("Logged"));
640    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(context->notes.loggedw),    check_button_set_active(context->notes.loggedw,
641                                 cache->notes && cache->notes->logged);                            cache->notes && cache->notes->logged);
642    gtk_box_pack_start_defaults(GTK_BOX(hbox), context->notes.loggedw);    gtk_box_pack_start_defaults(GTK_BOX(hbox), context->notes.loggedw);
643    
644    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 615  GtkWidget *cache_notes(cache_context_t * Line 650  GtkWidget *cache_notes(cache_context_t *
650      gtk_widget_set_sensitive(context->notes.foundw, FALSE);      gtk_widget_set_sensitive(context->notes.foundw, FALSE);
651    
652    context->notes.datew = gtk_label_new("");    context->notes.datew = gtk_label_new("");
653    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);
654    gtk_table_attach_defaults(GTK_TABLE(table),    gtk_table_attach_defaults(GTK_TABLE(table),
655                              context->notes.datew, 3, 4, 1, 2);                              context->notes.datew, 3, 4, 1, 2);
656    ftime_update(context->notes.foundw, context, FALSE);    ftime_update(context->notes.foundw, context, FALSE);
# Line 624  GtkWidget *cache_notes(cache_context_t * Line 659  GtkWidget *cache_notes(cache_context_t *
659    if(cache->notes) pos = cache->notes->pos;    if(cache->notes) pos = cache->notes->pos;
660    
661    gtk_table_attach_defaults(GTK_TABLE(table),    gtk_table_attach_defaults(GTK_TABLE(table),
662                              context->notes.latw = lat_entry_new(pos.lat), 2, 3, 0, 1);              context->notes.latw = lat_entry_new(pos.lat), 2, 3, 0, 1);
663    g_signal_connect(G_OBJECT(context->notes.latw), "focus-out-event",    g_signal_connect(G_OBJECT(context->notes.latw), "focus-out-event",
664                     G_CALLBACK(focus_out), context);                     G_CALLBACK(focus_out), context);
665    
666    gtk_table_attach_defaults(GTK_TABLE(table),    gtk_table_attach_defaults(GTK_TABLE(table),
667                              context->notes.lonw = lon_entry_new(pos.lon), 2, 3, 1, 2);              context->notes.lonw = lon_entry_new(pos.lon), 2, 3, 1, 2);
668    g_signal_connect(G_OBJECT(context->notes.lonw), "focus-out-event",    g_signal_connect(G_OBJECT(context->notes.lonw), "focus-out-event",
669                     G_CALLBACK(focus_out), context);                     G_CALLBACK(focus_out), context);
670    
671    #if !defined(USE_MAEMO) || (MAEMO_VERSION_MAJOR < 5)
672    hbox = gtk_hbox_new(FALSE, 0);    hbox = gtk_hbox_new(FALSE, 0);
673    gtk_box_pack_start(GTK_BOX(hbox), table, FALSE, FALSE, 0);    gtk_box_pack_start(GTK_BOX(hbox), table, FALSE, FALSE, 0);
674    gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);    gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
675    #else
676      gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
677    #endif
678    
679  #ifndef USE_PANNABLE_AREA  #ifndef USE_PANNABLE_AREA
680    GtkWidget *scrolled_window = gtk_scrolled_window_new(NULL, NULL);    GtkWidget *scrolled_window = gtk_scrolled_window_new(NULL, NULL);
# Line 715  void notes_free(notes_t *notes) { Line 754  void notes_free(notes_t *notes) {
754    
755  pos_t notes_get_pos(cache_context_t *context) {  pos_t notes_get_pos(cache_context_t *context) {
756    pos_t pos = context->cache->pos;    pos_t pos = context->cache->pos;
757    if(gtk_toggle_button_get_active(    if(check_button_get_active(context->notes.overridew)) {
                  GTK_TOGGLE_BUTTON(context->notes.overridew))) {  
758      pos.lat = lat_get(context->notes.latw);      pos.lat = lat_get(context->notes.latw);
759      pos.lon = lon_get(context->notes.lonw);      pos.lon = lon_get(context->notes.lonw);
760    }    }
# Line 725  pos_t notes_get_pos(cache_context_t *con Line 763  pos_t notes_get_pos(cache_context_t *con
763    
764  gboolean notes_get_override(cache_context_t *context) {  gboolean notes_get_override(cache_context_t *context) {
765    /* get override value */    /* get override value */
766    return gtk_toggle_button_get_active(    return check_button_get_active(context->notes.overridew);
                       GTK_TOGGLE_BUTTON(context->notes.overridew));  
   
767  }  }
768    
769  typedef struct {  typedef struct {

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