Diff of /trunk/src/cache.c

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

revision 190 by harbaum, Tue Nov 17 10:22:41 2009 UTC revision 228 by harbaum, Thu Dec 3 20:07:13 2009 UTC
# Line 68  void bearing_fill_hbox(GtkWidget *hbox, Line 68  void bearing_fill_hbox(GtkWidget *hbox,
68      } else      } else
69        gtk_box_pack_start(GTK_BOX(hbox),        gtk_box_pack_start(GTK_BOX(hbox),
70                           gtk_label_attrib(_("(no position)"),                           gtk_label_attrib(_("(no position)"),
71                           SIZE_SMALL, STRIKETHROUGH_NONE),TRUE,FALSE,0);                                            SIZE_SMALL, STRIKETHROUGH_NONE),TRUE,FALSE,0);
72    } else    } else
73      gtk_box_pack_start(GTK_BOX(hbox),      gtk_box_pack_start(GTK_BOX(hbox),
74             gtk_label_attrib(_("(invalid position in notes)"),                         gtk_label_attrib(_("(invalid position in notes)"),
75                              SIZE_SMALL, STRIKETHROUGH_NONE),TRUE,FALSE,0);                                          SIZE_SMALL, STRIKETHROUGH_NONE),TRUE,FALSE,0);
76  }  }
77    
78  /* this function sets everything related to the coordinate. used to */  /* this function sets everything related to the coordinate. used to */
# Line 80  void bearing_fill_hbox(GtkWidget *hbox, Line 80  void bearing_fill_hbox(GtkWidget *hbox,
80  void overview_coordinate_update(cache_context_t *context) {  void overview_coordinate_update(cache_context_t *context) {
81    if(!context->notes.modified)    if(!context->notes.modified)
82      return;      return;
83    
84    /* update position labels */    /* update position labels */
85    int strike = notes_get_override(context)?STRIKETHROUGH:STRIKETHROUGH_NONE;    int strike = notes_get_override(context)?STRIKETHROUGH:STRIKETHROUGH_NONE;
86    char str[32];    lat_label_attrib_set(context->pos_lat_label,
87    pos_lat_str(str, sizeof(str), context->cache->pos.lat);                         context->cache->pos.lat, SIZE_BIG, strike);
88    gtk_label_attrib_set(context->pos_lat_label, str, SIZE_BIG, strike);    lon_label_attrib_set(context->pos_lon_label,
89    pos_lon_str(str, sizeof(str), context->cache->pos.lon);                         context->cache->pos.lon, SIZE_BIG, strike);
90    gtk_label_attrib_set(context->pos_lon_label, str, SIZE_BIG, strike);  
   
91    /* remove enire hbox and build a new one */    /* remove enire hbox and build a new one */
92    gtk_container_foreach(GTK_CONTAINER(context->bearing_hbox),    gtk_container_foreach(GTK_CONTAINER(context->bearing_hbox),
93                          (GtkCallback)gtk_widget_destroy, NULL);                          (GtkCallback)gtk_widget_destroy, NULL);
94    
95    /* update distance/etc */    /* update distance/etc */
96    if(!isnan(context->cache->pos.lat) &&    if(!isnan(context->cache->pos.lat) &&
97       !isnan(context->cache->pos.lon))       !isnan(context->cache->pos.lon))
98      bearing_fill_hbox(context->bearing_hbox, context->appdata,      bearing_fill_hbox(context->bearing_hbox, context->appdata,
99                        *get_pos(context->appdata), notes_get_pos(context));                        *get_pos(context->appdata), notes_get_pos(context));
100    
101    gtk_widget_show_all(context->bearing_hbox);    gtk_widget_show_all(context->bearing_hbox);
102  }  }
103    
104  static void gcvote_set(cache_context_t *context, vote_t *vote) {  static void gcvote_set(cache_context_t *context, vote_t *vote) {
105    if(!vote) return;    if(!vote) return;
106    
107    if(context->quality) {    if(context->quality) {
108      gtk_widget_destroy(context->quality);      gtk_widget_destroy(context->quality);
109      context->quality = NULL;      context->quality = NULL;
110    }    }
111    
112    if(context->votes) {    if(context->votes) {
113      gtk_widget_destroy(context->votes);      gtk_widget_destroy(context->votes);
114      context->votes = NULL;      context->votes = NULL;
115    }    }
116    
117    /* update/draw the voting */    /* update/draw the voting */
118  #ifndef USE_MAEMO  #ifndef USE_MAEMO
119    GtkTooltips *tips = gtk_tooltips_new();    GtkTooltips *tips = gtk_tooltips_new();
120  #endif  #endif
121    
122    char *votes_str = g_strdup_printf(_("Quality (%d %s):"), vote->votes,    char *votes_str = g_strdup_printf(_("Quality (%d %s):"), vote->votes,
123                                        (vote->votes == 1)?_("vote"):_("votes"));                                      (vote->votes == 1)?_("vote"):_("votes"));
124    context->votes = GTK_LABEL_SMALL(votes_str);    context->votes = GTK_LABEL_SMALL(votes_str);
125    gtk_box_pack_start(GTK_BOX(context->votebox),    gtk_box_pack_start(GTK_BOX(context->votebox),
126                       context->votes, FALSE, FALSE, 0);                       context->votes, FALSE, FALSE, 0);
# Line 129  static void gcvote_set(cache_context_t * Line 128  static void gcvote_set(cache_context_t *
128    context->quality = icon_get_widget(ICON_STARS, (int)(vote->quality*2-2));    context->quality = icon_get_widget(ICON_STARS, (int)(vote->quality*2-2));
129    gtk_box_pack_start(GTK_BOX(context->votebox), context->quality,    gtk_box_pack_start(GTK_BOX(context->votebox), context->quality,
130                       FALSE, FALSE, 0);                       FALSE, FALSE, 0);
131    
132  #ifndef USE_MAEMO  #ifndef USE_MAEMO
133    char *str = g_strdup_printf(_("Quality: %d"), vote->quality);    char *str = g_strdup_printf(_("Quality: %d"), vote->quality);
134    gtk_tooltips_set_tip(tips, context->votebox, str, NULL);    gtk_tooltips_set_tip(tips, context->votebox, str, NULL);
# Line 143  static void gcvote_set(cache_context_t * Line 142  static void gcvote_set(cache_context_t *
142    
143  static void gcvote_callback(vote_t *vote, gpointer data) {  static void gcvote_callback(vote_t *vote, gpointer data) {
144    cache_context_t *context = (cache_context_t*)data;    cache_context_t *context = (cache_context_t*)data;
145    
146    /* no vote returned: request failed, just cleanup */    /* no vote returned: request failed, just cleanup */
147    if(!vote) {    if(!vote) {
148      printf("gcvote: callback for failed request\n");      printf("gcvote: callback for failed request\n");
149    
150      gcvote_request_free(context->gcvote_request);      gcvote_request_free(context->gcvote_request);
151      context->gcvote_request = NULL;      context->gcvote_request = NULL;
152      return;      return;
# Line 157  static void gcvote_callback(vote_t *vote Line 156  static void gcvote_callback(vote_t *vote
156           vote->quality, vote->votes);           vote->quality, vote->votes);
157    
158    gcvote_set(context, vote);    gcvote_set(context, vote);
159    
160    gcvote_save(context->appdata, context->cache, &context->gcvote_request->mem);    gcvote_save(context->appdata, context->cache, &context->gcvote_request->mem);
161    
162    gcvote_request_free(context->gcvote_request);    gcvote_request_free(context->gcvote_request);
163    context->gcvote_request = NULL;    context->gcvote_request = NULL;
164  }  }
# Line 170  static void pack_vcentered(GtkWidget *vb Line 169  static void pack_vcentered(GtkWidget *vb
169    gtk_box_pack_start_defaults(GTK_BOX(vbox), align);    gtk_box_pack_start_defaults(GTK_BOX(vbox), align);
170  }  }
171    
172    #ifdef FREMANTLE
173    #define ICON_SIZE  ICON_CACHE_TYPE_2X
174    #else
175    #define ICON_SIZE  ICON_CACHE_TYPE_1_5X
176    #endif
177    
178  static GtkWidget *cache_overview(cache_context_t *context) {  static GtkWidget *cache_overview(cache_context_t *context) {
179    GtkWidget *vbox, *ivbox;    GtkWidget *vbox, *ivbox;
180    GtkWidget *colbox, *tip;    GtkWidget *colbox, *tip;
# Line 179  static GtkWidget *cache_overview(cache_c Line 184  static GtkWidget *cache_overview(cache_c
184  #endif  #endif
185    appdata_t *appdata = context->appdata;    appdata_t *appdata = context->appdata;
186    cache_t *cache = context->cache;    cache_t *cache = context->cache;
187    
188    vbox = gtk_vbox_new(FALSE, 4);    vbox = gtk_vbox_new(FALSE, 4);
189    
190    /* hbox containing the four columns of cache details */    /* hbox containing the four columns of cache details */
191    GtkWidget *ihbox = gtk_hbox_new(FALSE, 0);    GtkWidget *ihbox = gtk_hbox_new(FALSE, 0);
192    
193    /* vbox containing leftmost column (icon and container) */    /* vbox containing leftmost column (icon and container) */
194    colbox = gtk_vbox_new(FALSE, 0);    colbox = gtk_vbox_new(FALSE, 0);
195    
196    if(cache->type != CACHE_TYPE_UNKNOWN) {    if(cache->type != CACHE_TYPE_UNKNOWN) {
197      gtk_box_pack_start_defaults(GTK_BOX(colbox),      gtk_box_pack_start_defaults(GTK_BOX(colbox),
198            tip = icon_get_widget(ICON_SIZE, cache->type));
199  #if defined(USE_MAEMO) && (MAEMO_VERSION_MAJOR >= 5)  
     tip = icon_get_widget(ICON_CACHE_TYPE_2X, cache->type));  
 #else  
     tip = icon_get_widget(ICON_CACHE_TYPE_1_5X, cache->type));  
 #endif  
   
200  #ifndef USE_MAEMO  #ifndef USE_MAEMO
201      gtk_tooltips_set_tip(tips, tip, _(cache_type_tip[cache->type]), NULL);      gtk_tooltips_set_tip(tips, tip, _(cache_type_tip[cache->type]), NULL);
202  #endif  #endif
203    }    }
204    
205    /* ------------ box containing container info ------------ */    /* ------------ box containing container info ------------ */
206    if(cache->container != CACHE_CONT_UNKNOWN) {    if(cache->container != CACHE_CONT_UNKNOWN) {
207      ivbox = gtk_vbox_new(FALSE, 0);      ivbox = gtk_vbox_new(FALSE, 0);
# Line 211  static GtkWidget *cache_overview(cache_c Line 211  static GtkWidget *cache_overview(cache_c
211      gtk_box_pack_start(GTK_BOX(ivbox),      gtk_box_pack_start(GTK_BOX(ivbox),
212                         icon_get_widget(ICON_CACHE_SIZE, cache->container),                         icon_get_widget(ICON_CACHE_SIZE, cache->container),
213                         FALSE, FALSE, 0);                         FALSE, FALSE, 0);
214    
215      pack_vcentered(colbox, ivbox);      pack_vcentered(colbox, ivbox);
216  #ifndef USE_MAEMO  #ifndef USE_MAEMO
217      gtk_tooltips_set_tip(tips, ivbox, _(cache_size_tip[cache->container]), NULL);      gtk_tooltips_set_tip(tips, ivbox, _(cache_size_tip[cache->container]), NULL);
218  #endif  #endif
219    }    }
220    
221    gtk_box_pack_start_defaults(GTK_BOX(ihbox), colbox);    gtk_box_pack_start_defaults(GTK_BOX(ihbox), colbox);
222    colbox = gtk_vbox_new(FALSE, 0);    colbox = gtk_vbox_new(FALSE, 0);
223    
224    /* ----------------------- id ---------------------------- */    /* ----------------------- id ---------------------------- */
225    if(cache->id) {    if(cache->id) {
226      int strike = cache->archived?STRIKETHROUGH_RED:      int strike = cache->archived?STRIKETHROUGH_RED:
# Line 599  static GtkWidget *cache_logs(appdata_t * Line 599  static GtkWidget *cache_logs(appdata_t *
599    
600  #ifdef ENABLE_BROWSER_INTERFACE  #ifdef ENABLE_BROWSER_INTERFACE
601    if(gc_link) {    if(gc_link) {
602      GtkWidget *but =      GtkWidget *but =
603        gtk_button_new_with_label(_("Post a new log entry for this geocache"));        gtk_button_new_with_label(_("Post a new log entry for this geocache"));
604    #if 0
605        gtk_button_set_image(GTK_BUTTON(but),
606            gtk_image_new_from_stock(GTK_STOCK_ADD, GTK_ICON_SIZE_BUTTON));
607        gtk_button_set_image_position(GTK_BUTTON(but), GTK_POS_LEFT);
608    #endif
609  #if defined(USE_MAEMO) && (MAEMO_VERSION_MAJOR == 5)  #if defined(USE_MAEMO) && (MAEMO_VERSION_MAJOR == 5)
610    hildon_gtk_widget_set_theme_size(but,    hildon_gtk_widget_set_theme_size(but,
611             (HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH));             (HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH));
# Line 635  static GtkWidget *cache_logs(appdata_t * Line 640  static GtkWidget *cache_logs(appdata_t *
640                     (HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH));                     (HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH));
641  #endif  #endif
642    
643        gtk_label_set_ellipsize(GTK_LABEL(gtk_bin_get_child(GTK_BIN(finder))),      gtk_label_set_ellipsize(GTK_LABEL(gtk_bin_get_child(GTK_BIN(finder))),
644                                PANGO_ELLIPSIZE_END);                                PANGO_ELLIPSIZE_END);
645      } else      } else
646        gtk_label_set_ellipsize(GTK_LABEL(finder), PANGO_ELLIPSIZE_END);        gtk_label_set_ellipsize(GTK_LABEL(finder), PANGO_ELLIPSIZE_END);
# Line 726  static void on_notebook_page_change(GtkN Line 731  static void on_notebook_page_change(GtkN
731    /* seems to work ... */    /* seems to work ... */
732    if(strcasecmp(name, _("Logs")) == 0) {    if(strcasecmp(name, _("Logs")) == 0) {
733      gtk_widget_queue_resize(w);      gtk_widget_queue_resize(w);
   } else if(strcasecmp(name, _("TBs")) == 0) {  
     gtk_widget_queue_resize(w);  
734    } else if(strcasecmp(name, _("Goto")) == 0) {    } else if(strcasecmp(name, _("Goto")) == 0) {
735  #ifdef USE_MAEMO  #ifdef USE_MAEMO
736      context->handler_id = gtk_timeout_add(1000, screensaver_update,      context->handler_id = gtk_timeout_add(1000, screensaver_update,
737                                            context->appdata);                                            context->appdata);
738  #endif  #endif
739    
740      goto_coordinate_update(context);      goto_coordinate_update(context);
741    }    }
742    
# Line 762  static void on_notebook_destroy(GtkWidge Line 766  static void on_notebook_destroy(GtkWidge
766      gtk_timeout_remove(context->handler_id);      gtk_timeout_remove(context->handler_id);
767  #endif  #endif
768    
769    free(user_data);  #ifdef USE_STACKABLE_WINDOW
770      if(context->notes_have_been_changed) {
771        printf("notes changed -> cachelist redraw\n");
772    
773        /* now the cachelist is visible again. so redraw it since it may */
774        /* have changed */
775        cachelist_redraw(context->appdata);
776      }
777    #endif
778    
779      printf("freeing cache context\n");
780      context->appdata->cache_context = NULL;
781      g_free(context);
782  }  }
783    
784  #if defined(USE_MAEMO) && (MAEMO_VERSION_MAJOR >= 5)  #if defined(USE_MAEMO) && (MAEMO_VERSION_MAJOR >= 5)
# Line 862  static GObject *notebook_object(GtkWidge Line 878  static GObject *notebook_object(GtkWidge
878  GtkWidget *cache_view(appdata_t *appdata, cache_t *cache) {  GtkWidget *cache_view(appdata_t *appdata, cache_t *cache) {
879    GtkWidget *notebook;    GtkWidget *notebook;
880    
881    cache_context_t *cache_context = malloc(sizeof(cache_context_t));    cache_context_t *cache_context = g_new0(cache_context_t, 1);
882    memset(cache_context, 0, sizeof(cache_context_t));    appdata->cache_context = cache_context;
883    cache_context->appdata = appdata;    cache_context->appdata = appdata;
884    cache_context->cache = cache;    cache_context->cache = cache;
885    
# Line 941  void cache_dialog(appdata_t *appdata, ca Line 957  void cache_dialog(appdata_t *appdata, ca
957  static void on_cache_destroy (GtkWidget *widget, appdata_t *appdata) {  static void on_cache_destroy (GtkWidget *widget, appdata_t *appdata) {
958    appdata->cur_cache = NULL;    appdata->cur_cache = NULL;
959    
960      HildonWindowStack *stack = hildon_window_stack_get_default();
961      appdata->window = HILDON_WINDOW(hildon_window_stack_peek(stack));
962    
963    /* restore cur_view */    /* restore cur_view */
964    appdata->cur_view = g_object_get_data(G_OBJECT(widget), "cur_view");    appdata->cur_view = g_object_get_data(G_OBJECT(widget), "cur_view");
965  }  }
966    
967  void cache_dialog(appdata_t *appdata, cache_t *cache) {  void cache_dialog(appdata_t *appdata, cache_t *cache) {
968    GtkWidget *window = hildon_stackable_window_new();    GtkWidget *window = hildon_stackable_window_new();
969      appdata->window = HILDON_WINDOW(window);
970    
971    /* store last "cur_view" in window */    /* store last "cur_view" in window */
972    g_object_set_data(G_OBJECT(window), "cur_view", appdata->cur_view);    g_object_set_data(G_OBJECT(window), "cur_view", appdata->cur_view);

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