Contents of /trunk/src/cache.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 226 - (hide annotations)
Wed Dec 2 20:05:52 2009 UTC (14 years, 5 months ago) by harbaum
File MIME type: text/plain
File size: 31228 byte(s)
Map nav source selection
1 harbaum 1 /*
2     * Copyright (C) 2008 Till Harbaum <till@harbaum.org>.
3     *
4     * This file is part of GPXView.
5     *
6     * GPXView is free software: you can redistribute it and/or modify
7     * it under the terms of the GNU General Public License as published by
8     * the Free Software Foundation, either version 3 of the License, or
9     * (at your option) any later version.
10     *
11     * GPXView is distributed in the hope that it will be useful,
12     * but WITHOUT ANY WARRANTY; without even the implied warranty of
13     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14     * GNU General Public License for more details.
15     *
16     * You should have received a copy of the GNU General Public License
17     * along with GPXView. If not, see <http://www.gnu.org/licenses/>.
18     */
19    
20     #include "gpxview.h"
21     #include <math.h>
22 harbaum 178 #include <string.h>
23 harbaum 1
24     static GtkWidget *cache_description(appdata_t *appdata, cache_t *cache) {
25     return html_view(appdata, cache->long_description,
26 harbaum 140 cache->long_is_html?HTML_HTML:HTML_PLAIN_TEXT, TRUE, cache, NULL);
27 harbaum 1 }
28    
29     #ifndef USE_MAEMO // maemos touchscreen doesn't support tooltips
30     static const char *cache_type_tip[] = {
31     "Traditional Cache", "Multicache", "Mystery/Unknown Cache",
32     "Virtual Cache", "Webcam Cache", "Event Cache",
33     "Letterbox Hybrid", "Earthcache", "Wherigo Cache",
34     "Mega-Event Cache", "Cache-In-Trash-Out Cache"
35     };
36    
37     static const char *cache_size_tip[] = {
38     "Regular Container", "Small Container", "Micro",
39     "Other Container", "Container not chosen", "Large Container",
40     "Virtual Container"
41     };
42     #endif
43    
44     static const char *cache_size_name[] = {
45 harbaum 187 "Regular", "Small", "Micro", "Other", "Not chosen", "Large", "Virtual"
46 harbaum 1 };
47    
48     void bearing_fill_hbox(GtkWidget *hbox,
49     appdata_t *appdata, pos_t refpos, pos_t pos) {
50     char str[32];
51    
52     if(!isnan(pos.lat) && !isnan(pos.lon)) {
53     gtk_box_pack_start(GTK_BOX(hbox), gtk_image_new_from_pixbuf(
54 harbaum 187 icon_bearing(refpos, pos)),TRUE,FALSE,0);
55 harbaum 1
56 harbaum 34 if(!isnan(refpos.lat) && !isnan(refpos.lon)) {
57 harbaum 1 gtk_box_pack_start_defaults(GTK_BOX(hbox),
58     GTK_LABEL_SMALL((char*)pos_get_bearing_str(refpos, pos)));
59 harbaum 187 gtk_box_pack_start_defaults(GTK_BOX(hbox), GTK_LABEL_SMALL(" "));
60 harbaum 1 snprintf(str, sizeof(str), _("%.1f°"),
61     gpx_pos_get_bearing(refpos, pos));
62     gtk_box_pack_start_defaults(GTK_BOX(hbox), GTK_LABEL_SMALL(str));
63     gpx_pos_get_distance_str(str, sizeof(str),
64     refpos, pos, appdata->imperial);
65 harbaum 187 gtk_box_pack_start_defaults(GTK_BOX(hbox), GTK_LABEL_SMALL(" "));
66 harbaum 1 gtk_box_pack_start(GTK_BOX(hbox),
67 harbaum 187 gtk_label_attrib(str, SIZE_SMALL, STRIKETHROUGH_NONE),TRUE,FALSE,0);
68 harbaum 1 } else
69     gtk_box_pack_start(GTK_BOX(hbox),
70     gtk_label_attrib(_("(no position)"),
71 harbaum 214 SIZE_SMALL, STRIKETHROUGH_NONE),TRUE,FALSE,0);
72 harbaum 1 } else
73     gtk_box_pack_start(GTK_BOX(hbox),
74 harbaum 214 gtk_label_attrib(_("(invalid position in notes)"),
75     SIZE_SMALL, STRIKETHROUGH_NONE),TRUE,FALSE,0);
76 harbaum 1 }
77    
78 harbaum 187 /* this function sets everything related to the coordinate. used to */
79 harbaum 1 /* cope with the user setting a new "note coordinate" */
80     void overview_coordinate_update(cache_context_t *context) {
81     if(!context->notes.modified)
82     return;
83 harbaum 214
84 harbaum 1 /* update position labels */
85     int strike = notes_get_override(context)?STRIKETHROUGH:STRIKETHROUGH_NONE;
86 harbaum 221 lat_label_attrib_set(context->pos_lat_label,
87     context->cache->pos.lat, SIZE_BIG, strike);
88     lon_label_attrib_set(context->pos_lon_label,
89     context->cache->pos.lon, SIZE_BIG, strike);
90 harbaum 214
91 harbaum 1 /* remove enire hbox and build a new one */
92     gtk_container_foreach(GTK_CONTAINER(context->bearing_hbox),
93     (GtkCallback)gtk_widget_destroy, NULL);
94 harbaum 214
95 harbaum 1 /* update distance/etc */
96 harbaum 13 if(!isnan(context->cache->pos.lat) &&
97     !isnan(context->cache->pos.lon))
98     bearing_fill_hbox(context->bearing_hbox, context->appdata,
99     *get_pos(context->appdata), notes_get_pos(context));
100 harbaum 214
101 harbaum 1 gtk_widget_show_all(context->bearing_hbox);
102     }
103    
104 harbaum 159 static void gcvote_set(cache_context_t *context, vote_t *vote) {
105     if(!vote) return;
106 harbaum 214
107 harbaum 159 if(context->quality) {
108     gtk_widget_destroy(context->quality);
109     context->quality = NULL;
110     }
111 harbaum 214
112 harbaum 159 if(context->votes) {
113     gtk_widget_destroy(context->votes);
114     context->votes = NULL;
115     }
116 harbaum 214
117 harbaum 158 /* update/draw the voting */
118     #ifndef USE_MAEMO
119 harbaum 159 GtkTooltips *tips = gtk_tooltips_new();
120 harbaum 158 #endif
121 harbaum 214
122 harbaum 159 char *votes_str = g_strdup_printf(_("Quality (%d %s):"), vote->votes,
123 harbaum 214 (vote->votes == 1)?_("vote"):_("votes"));
124 harbaum 159 context->votes = GTK_LABEL_SMALL(votes_str);
125     gtk_box_pack_start(GTK_BOX(context->votebox),
126     context->votes, FALSE, FALSE, 0);
127     g_free(votes_str);
128     context->quality = icon_get_widget(ICON_STARS, (int)(vote->quality*2-2));
129     gtk_box_pack_start(GTK_BOX(context->votebox), context->quality,
130     FALSE, FALSE, 0);
131 harbaum 214
132 harbaum 158 #ifndef USE_MAEMO
133 harbaum 159 char *str = g_strdup_printf(_("Quality: %d"), vote->quality);
134     gtk_tooltips_set_tip(tips, context->votebox, str, NULL);
135     g_free(str);
136 harbaum 158 #endif
137 harbaum 159
138     gtk_widget_show_all(context->votebox);
139 harbaum 158
140 harbaum 159 g_free(vote);
141     }
142 harbaum 158
143 harbaum 159 static void gcvote_callback(vote_t *vote, gpointer data) {
144     cache_context_t *context = (cache_context_t*)data;
145 harbaum 214
146 harbaum 159 /* no vote returned: request failed, just cleanup */
147     if(!vote) {
148 harbaum 160 printf("gcvote: callback for failed request\n");
149 harbaum 214
150 harbaum 158 gcvote_request_free(context->gcvote_request);
151     context->gcvote_request = NULL;
152 harbaum 159 return;
153 harbaum 158 }
154 harbaum 159
155 harbaum 160 printf("gcvote: callback is being called with a %d/%d\n",
156 harbaum 159 vote->quality, vote->votes);
157    
158     gcvote_set(context, vote);
159 harbaum 214
160 harbaum 159 gcvote_save(context->appdata, context->cache, &context->gcvote_request->mem);
161 harbaum 214
162 harbaum 159 gcvote_request_free(context->gcvote_request);
163     context->gcvote_request = NULL;
164 harbaum 158 }
165    
166 harbaum 187 static void pack_vcentered(GtkWidget *vbox, GtkWidget *child) {
167     GtkWidget *align = gtk_alignment_new(0.5, 0.5, 0.0, 0.0);
168     gtk_container_add(GTK_CONTAINER(align), child);
169     gtk_box_pack_start_defaults(GTK_BOX(vbox), align);
170     }
171    
172 harbaum 214 #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 harbaum 1 static GtkWidget *cache_overview(cache_context_t *context) {
179     GtkWidget *vbox, *ivbox;
180 harbaum 187 GtkWidget *colbox, *tip;
181 harbaum 1 char str[64];
182     #ifndef USE_MAEMO
183     GtkTooltips *tips = gtk_tooltips_new();
184     #endif
185     appdata_t *appdata = context->appdata;
186     cache_t *cache = context->cache;
187 harbaum 214
188 harbaum 187 vbox = gtk_vbox_new(FALSE, 4);
189 harbaum 214
190 harbaum 187 /* hbox containing the four columns of cache details */
191     GtkWidget *ihbox = gtk_hbox_new(FALSE, 0);
192 harbaum 214
193 harbaum 187 /* vbox containing leftmost column (icon and container) */
194     colbox = gtk_vbox_new(FALSE, 0);
195 harbaum 214
196 harbaum 1 if(cache->type != CACHE_TYPE_UNKNOWN) {
197 harbaum 187 gtk_box_pack_start_defaults(GTK_BOX(colbox),
198 harbaum 214 tip = icon_get_widget(ICON_SIZE, cache->type));
199    
200 harbaum 1 #ifndef USE_MAEMO
201     gtk_tooltips_set_tip(tips, tip, _(cache_type_tip[cache->type]), NULL);
202     #endif
203     }
204 harbaum 214
205 harbaum 1 /* ------------ box containing container info ------------ */
206     if(cache->container != CACHE_CONT_UNKNOWN) {
207     ivbox = gtk_vbox_new(FALSE, 0);
208     sprintf(str, _("Size: %s"), _(cache_size_name[cache->container]));
209 harbaum 137 gtk_box_pack_start(GTK_BOX(ivbox), GTK_LABEL_SMALL(str),
210     FALSE, FALSE, 0);
211     gtk_box_pack_start(GTK_BOX(ivbox),
212     icon_get_widget(ICON_CACHE_SIZE, cache->container),
213     FALSE, FALSE, 0);
214 harbaum 214
215 harbaum 187 pack_vcentered(colbox, ivbox);
216 harbaum 1 #ifndef USE_MAEMO
217     gtk_tooltips_set_tip(tips, ivbox, _(cache_size_tip[cache->container]), NULL);
218     #endif
219     }
220 harbaum 214
221 harbaum 187 gtk_box_pack_start_defaults(GTK_BOX(ihbox), colbox);
222     colbox = gtk_vbox_new(FALSE, 0);
223 harbaum 214
224 harbaum 1 /* ----------------------- id ---------------------------- */
225     if(cache->id) {
226     int strike = cache->archived?STRIKETHROUGH_RED:
227     (!cache->available?STRIKETHROUGH:STRIKETHROUGH_NONE);
228 harbaum 137 GtkWidget *lbl = link_button_attrib(context->appdata,
229     cache->id, context->cache->url,
230     SIZE_BIG, strike);
231 harbaum 187 pack_vcentered(colbox, lbl);
232 harbaum 1 }
233    
234     /* --------------- box containing owner info ------------- */
235     if(cache->owner) {
236 harbaum 187 gtk_box_pack_start_defaults(GTK_BOX(colbox), GTK_LABEL_SMALL(_("by")));
237 harbaum 137
238     static const char *owner_type = "profile/";
239 harbaum 187 pack_vcentered(colbox,
240 harbaum 137 link_button_by_id(appdata, cache->owner->name,
241     owner_type, cache->owner->id));
242 harbaum 1 }
243    
244 harbaum 187 gtk_box_pack_start_defaults(GTK_BOX(ihbox), colbox);
245    
246 harbaum 156 /* ----------- vbox containing all ratings ---------- */
247 harbaum 187 colbox = gtk_vbox_new(FALSE, 0);
248 harbaum 156
249 harbaum 1 /* ----------- box containing difficulty rating ---------- */
250     if(cache->difficulty != 0) {
251     ivbox = gtk_vbox_new(FALSE, 0);
252 harbaum 137 gtk_box_pack_start(GTK_BOX(ivbox),
253     GTK_LABEL_SMALL(_("Difficulty:")),
254     FALSE, FALSE, 0);
255     gtk_box_pack_start(GTK_BOX(ivbox),
256     icon_get_widget(ICON_STARS, (int)(cache->difficulty*2-2)),
257     FALSE, FALSE, 0);
258 harbaum 156
259 harbaum 187 pack_vcentered(colbox, ivbox);
260 harbaum 1 #ifndef USE_MAEMO
261     sprintf(str, _("Difficulty: %.1f"), cache->difficulty);
262     gtk_tooltips_set_tip(tips, ivbox, str, NULL);
263     #endif
264     }
265    
266     /* ------------ box containing terrain rating ------------ */
267     if(cache->terrain != 0) {
268     ivbox = gtk_vbox_new(FALSE, 0);
269 harbaum 137 gtk_box_pack_start(GTK_BOX(ivbox), GTK_LABEL_SMALL(_("Terrain:")),
270     FALSE, FALSE, 0);
271     gtk_box_pack_start(GTK_BOX(ivbox),
272     icon_get_widget(ICON_STARS, (int)(cache->terrain*2-2)),
273     FALSE, FALSE, 0);
274 harbaum 187 pack_vcentered(colbox, ivbox);
275 harbaum 1 #ifndef USE_MAEMO
276     sprintf(str, _("Terrain: %.1f"), cache->terrain);
277     gtk_tooltips_set_tip(tips, ivbox, str, NULL);
278     #endif
279     }
280    
281 harbaum 156 /* --------------------- GCVote ------------------------ */
282 harbaum 167 if(!appdata->disable_gcvote) {
283     vote_t *vote = gcvote_restore(appdata, cache);
284 harbaum 160
285 harbaum 167 context->gcvote_request =
286     gcvote_request(appdata, gcvote_callback, cache->url, context);
287 harbaum 156
288 harbaum 167 context->votebox = gtk_vbox_new(FALSE, 0);
289 harbaum 187 pack_vcentered(colbox, context->votebox);
290 harbaum 156
291 harbaum 167 /* fill with vote if present on disk (will also free vote) */
292     if(vote)
293     gcvote_set(context, vote);
294     }
295 harbaum 156
296 harbaum 187 gtk_box_pack_start_defaults(GTK_BOX(ihbox), colbox);
297 harbaum 180
298 harbaum 156 /* ----------------------------------------------------- */
299    
300    
301 harbaum 1 /* ----------------- the two coordinates ----------------- */
302     /* ----------------- and the heading/distance ------------ */
303 harbaum 187 colbox = gtk_vbox_new(FALSE, 0);
304    
305 harbaum 1 pos_t *refpos = get_pos(appdata);
306    
307     ivbox = gtk_vbox_new(FALSE, 0);
308     int strike = (cache->notes && cache->notes->override)?
309     STRIKETHROUGH:STRIKETHROUGH_NONE;
310    
311     /* the original coordinate is being displayed */
312 harbaum 187 gtk_box_pack_start(GTK_BOX(ivbox),
313     context->pos_lat_label = pos_lat(cache->pos.lat, SIZE_BIG, strike), FALSE, FALSE, 0);
314     gtk_box_pack_start(GTK_BOX(ivbox),
315     context->pos_lon_label = pos_lon(cache->pos.lon, SIZE_BIG, strike), FALSE, FALSE, 0);
316 harbaum 1
317 harbaum 187 pack_vcentered(colbox, ivbox);
318    
319 harbaum 1 /* but calculations may be done with respect to the overriden one */
320 harbaum 13 if(!isnan(cache->pos.lat) && !isnan(cache->pos.lon)) {
321     context->bearing_hbox = gtk_hbox_new(FALSE, 0);
322     bearing_fill_hbox(context->bearing_hbox, appdata, *refpos,
323     gpx_cache_pos(cache));
324 harbaum 187 pack_vcentered(colbox, context->bearing_hbox);
325 harbaum 13 }
326 harbaum 1
327 harbaum 187 gtk_box_pack_start_defaults(GTK_BOX(ihbox), colbox);
328 harbaum 1
329 harbaum 157 /* ----------------------------------------------------- */
330    
331 harbaum 187 gtk_box_pack_start(GTK_BOX(vbox), ihbox, FALSE, FALSE, 0);
332     gtk_box_pack_start(GTK_BOX(vbox), gtk_hseparator_new(), FALSE, FALSE, 0);
333 harbaum 1
334 harbaum 156 /* ----------------------------------------------------- */
335    
336 harbaum 1 if(cache->short_description)
337     gtk_box_pack_start_defaults(GTK_BOX(vbox),
338     html_view(appdata, cache->short_description,
339 harbaum 140 cache->short_is_html?HTML_HTML:HTML_PLAIN_TEXT, TRUE, cache, NULL));
340 harbaum 1
341     return vbox;
342     }
343    
344     /* slow but short, we don't need performance here ... */
345     static void rot13(char *t) {
346 harbaum 55 int braces = 0;
347    
348 harbaum 1 while(*t) {
349 harbaum 55 if(!braces) {
350     if(*t == '[')
351     braces++;
352     else if(((*t >= 'a') && (*t < 'n')) ||
353     ((*t >= 'A') && (*t < 'N'))) *t += 13;
354     else if(((*t >= 'n') && (*t <= 'z')) ||
355     ((*t >= 'N') && (*t <= 'Z'))) *t -= 13;
356     } else {
357     if(braces > 0 && *t == ']')
358     braces--;
359     }
360 harbaum 1
361     t++;
362     }
363     }
364    
365     static void on_decrypt(GtkWidget *widget, gpointer data) {
366     /* data is a link to the textview */
367     g_assert(GTK_IS_TEXT_VIEW(data));
368    
369     GtkTextIter start, end;
370     GtkTextBuffer *buffer = gtk_text_view_get_buffer((GtkTextView*)data);
371    
372     gtk_text_buffer_get_start_iter(buffer, &start);
373     gtk_text_buffer_get_end_iter(buffer, &end);
374     char *text = gtk_text_buffer_get_text(buffer, &start, &end, FALSE);
375    
376     rot13(text);
377     gtk_text_buffer_set_text(buffer, text, -1);
378    
379     free(text);
380     }
381    
382     static GtkWidget *cache_hint(appdata_t *appdata, cache_t *cache) {
383     /* encrypting/decrypting html is nothing we want to do */
384     if(cache->hint_is_html)
385 harbaum 140 return html_view(appdata, cache->hint, HTML_HTML, TRUE, NULL, NULL);
386 harbaum 1
387     /* we can now be sure that we are talking about pain text */
388     GtkWidget *vbox = gtk_vbox_new(FALSE, 0);
389    
390     char *hint = strdup(cache->hint);
391     rot13(hint);
392 harbaum 140 GtkWidget *view =
393     html_view(appdata, hint, HTML_PLAIN_TEXT, TRUE, NULL, NULL);
394 harbaum 1 gtk_box_pack_start_defaults(GTK_BOX(vbox), view);
395     free(hint);
396    
397     GtkWidget *button = gtk_button_new_with_label(_("Encrypt/Decrypt"));
398 harbaum 66 #if defined(USE_MAEMO) && (MAEMO_VERSION_MAJOR == 5)
399     hildon_gtk_widget_set_theme_size(button,
400     (HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH));
401     #endif
402 harbaum 1 gtk_box_pack_start(GTK_BOX(vbox), button, FALSE, FALSE, 0);
403     gtk_signal_connect(GTK_OBJECT(button), "clicked",
404     GTK_SIGNAL_FUNC(on_decrypt), gtk_bin_get_child(GTK_BIN(view)));
405    
406     return vbox;
407     }
408    
409     static GtkWidget *cache_wpts(appdata_t *appdata, wpt_t *wpt) {
410     pos_t *refpos = NULL;
411    
412     #ifndef USE_PANNABLE_AREA
413     GtkWidget *scrolled_window = gtk_scrolled_window_new(NULL, NULL);
414     gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_window),
415     GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
416     #else
417     GtkWidget *pannable_area = hildon_pannable_area_new();
418     #endif
419    
420     GtkWidget *vbox = gtk_vbox_new(FALSE, 0);
421    
422     /* four rows per waypoint */
423     GtkWidget *table = gtk_table_new(4*gpx_number_of_waypoints(wpt)-1,4, FALSE);
424    
425     refpos = get_pos(appdata);
426    
427     int wpt_row=0;
428     while(wpt) {
429     GtkWidget *ihbox, *tip;
430     char str[32];
431    
432     /* ----------------------- icon/id ---------------------------- */
433     ihbox = gtk_hbox_new(FALSE, 0);
434    
435     if(wpt->sym != WPT_SYM_UNKNOWN) {
436     gtk_box_pack_start(GTK_BOX(ihbox),
437     tip = icon_get_widget(ICON_WPT, wpt->sym), 1,0,0);
438     }
439    
440     if(wpt->id)
441     gtk_box_pack_start(GTK_BOX(ihbox), GTK_LABEL_BIG(wpt->id), 1,0,0);
442    
443     gtk_table_attach_defaults(GTK_TABLE(table), ihbox, 0,1,wpt_row, wpt_row+1);
444    
445     /* ----------------- the two coordinates ----------------- */
446     /* ----------------- and the heading/distance ------------ */
447     gtk_table_attach_defaults(GTK_TABLE(table),
448     pos_lat(wpt->pos.lat, SIZE_BIG, STRIKETHROUGH_NONE),
449     1,2, wpt_row, wpt_row+1);
450     gtk_table_attach_defaults(GTK_TABLE(table),
451     pos_lon(wpt->pos.lon, SIZE_BIG, STRIKETHROUGH_NONE),
452     2,3, wpt_row, wpt_row+1);
453    
454 harbaum 185 if(refpos && !isnan(refpos->lat) && !isnan(refpos->lon)) {
455     ihbox = gtk_hbox_new(FALSE, 0);
456     gtk_box_pack_start(GTK_BOX(ihbox), gtk_image_new_from_pixbuf(
457 harbaum 1 icon_bearing(*refpos, wpt->pos)),1,0,0);
458 harbaum 185 snprintf(str, sizeof(str), _("%.1f°"),
459     gpx_pos_get_bearing(*refpos, wpt->pos));
460     gtk_box_pack_start_defaults(GTK_BOX(ihbox), GTK_LABEL_SMALL(str));
461 harbaum 1
462 harbaum 185 gpx_pos_get_distance_str(str, sizeof(str),
463     *refpos, wpt->pos, appdata->imperial);
464     gtk_box_pack_start(GTK_BOX(ihbox), GTK_LABEL_SMALL(str),1,0,0);
465    
466     gtk_table_attach_defaults(GTK_TABLE(table), ihbox, 3,4,
467     wpt_row+0, wpt_row+1);
468     }
469    
470 harbaum 1 /* ------------------ description ------------------------- */
471 harbaum 165 if(wpt->desc)
472     gtk_table_attach_defaults(GTK_TABLE(table),
473     simple_text_widget(wpt->desc), 0,4,
474 harbaum 1 wpt_row+1, wpt_row+2);
475    
476     /* ------------------ comment ------------------------- */
477 harbaum 165 if(wpt->cmt)
478     gtk_table_attach_defaults(GTK_TABLE(table),
479     simple_text_widget(wpt->cmt), 0,4,
480 harbaum 1 wpt_row+2, wpt_row+3);
481    
482     /* --------------------- seperator -------------------------*/
483 harbaum 165 if(wpt->next) {
484     gtk_table_set_row_spacing(GTK_TABLE(table), wpt_row+2, 8);
485 harbaum 1 gtk_table_attach_defaults(GTK_TABLE(table), gtk_hseparator_new(), 0,4,
486     wpt_row+3, wpt_row+4);
487 harbaum 165 gtk_table_set_row_spacing(GTK_TABLE(table), wpt_row+3, 8);
488     }
489 harbaum 1
490     wpt_row+=4;
491     wpt = wpt->next;
492     }
493    
494     gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
495    
496     #ifndef USE_PANNABLE_AREA
497     gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scrolled_window),
498     vbox);
499     return scrolled_window;
500     #else
501     hildon_pannable_area_add_with_viewport(HILDON_PANNABLE_AREA(pannable_area),
502     vbox);
503     return pannable_area;
504     #endif
505     }
506    
507     static GtkWidget *cache_tbs(appdata_t *appdata, tb_t *tb) {
508     pos_t *refpos = NULL;
509    
510     #ifndef USE_PANNABLE_AREA
511     GtkWidget *scrolled_window = gtk_scrolled_window_new(NULL, NULL);
512     gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_window),
513     GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
514     #else
515     GtkWidget *pannable_area = hildon_pannable_area_new();
516     #endif
517    
518     GtkWidget *vbox = gtk_vbox_new(FALSE, 0);
519    
520     /* four rows per waypoint */
521     GtkWidget *table = gtk_table_new(2*gpx_number_of_tbs(tb)-1,3, FALSE);
522    
523     refpos = get_pos(appdata);
524    
525     int tb_row=0;
526     while(tb) {
527 harbaum 137 static const char *tb_type = "track/details.aspx";
528    
529 harbaum 1 /* --------------------- icon/ref/name -------------------------*/
530 harbaum 178 GtkWidget *icon = NULL;
531 harbaum 179 if((strcasestr(tb->name, "coin") != 0) ||
532     (strcasestr(tb->name, "muenze") != 0) ||
533     (strcasestr(tb->name, "münze") != 0))
534 harbaum 178 icon = icon_get_widget(ICON_TB, 1); /* coin icon */
535     else
536     icon = icon_get_widget(ICON_TB, 0); /* tb icon */
537    
538     gtk_table_attach_defaults(GTK_TABLE(table), icon,
539 harbaum 1 0, 1, tb_row+0, tb_row+1);
540 harbaum 133
541     if(tb->ref) {
542 harbaum 137 GtkWidget *ref = link_button_by_id(appdata, tb->ref, tb_type, tb->id);
543 harbaum 133 gtk_table_attach_defaults(GTK_TABLE(table), ref,
544 harbaum 1 1, 2, tb_row+0, tb_row+1);
545 harbaum 133 }
546    
547 harbaum 1 if(tb->name)
548     gtk_table_attach_defaults(GTK_TABLE(table), GTK_LABEL_BIG(tb->name),
549     2, 3, tb_row+0, tb_row+1);
550    
551     /* --------------------- seperator -------------------------*/
552     if(tb->next)
553     gtk_table_attach_defaults(GTK_TABLE(table), gtk_hseparator_new(), 0, 3,
554     tb_row+1, tb_row+2);
555     tb_row+=2;
556     tb = tb->next;
557     }
558    
559     gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
560    
561     #ifndef USE_PANNABLE_AREA
562     gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scrolled_window),
563     vbox);
564     return scrolled_window;
565     #else
566     hildon_pannable_area_add_with_viewport(HILDON_PANNABLE_AREA(pannable_area),
567     vbox);
568     return pannable_area;
569     #endif
570     }
571    
572 harbaum 66 #ifdef ENABLE_BROWSER_INTERFACE
573     static void on_gclink_clicked(GtkButton *button, gpointer data) {
574     cache_context_t *context = (cache_context_t*)data;
575     char *url = g_strdup_printf("http://www.geocaching.com/seek/log.aspx?wp=%s", context->cache->id);
576     browser_url(context->appdata, url);
577     g_free(url);
578     }
579     #endif
580    
581 harbaum 165 static GtkWidget *cache_logs(appdata_t *appdata, cache_context_t *context,
582     log_t *log, int is_html) {
583 harbaum 1 #ifndef USE_PANNABLE_AREA
584     /* put this inside a scrolled view */
585     GtkWidget *scrolled_window = gtk_scrolled_window_new(NULL, NULL);
586     gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_window),
587     GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
588     #else
589     GtkWidget *pannable_area = hildon_pannable_area_new();
590     #endif
591    
592 harbaum 66 #ifdef ENABLE_BROWSER_INTERFACE
593     gboolean gc_link = strncmp(context->cache->id, "GC", 2) == 0;
594     #else
595     #define gc_link (FALSE)
596     #endif
597    
598 harbaum 163 GtkWidget *vbox = gtk_vbox_new(FALSE, 6);
599 harbaum 66
600     #ifdef ENABLE_BROWSER_INTERFACE
601     if(gc_link) {
602 harbaum 199 GtkWidget *but =
603 harbaum 165 gtk_button_new_with_label(_("Post a new log entry for this geocache"));
604 harbaum 199 #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 harbaum 66 #if defined(USE_MAEMO) && (MAEMO_VERSION_MAJOR == 5)
610     hildon_gtk_widget_set_theme_size(but,
611     (HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH));
612     #endif
613     gtk_signal_connect(GTK_OBJECT(but), "clicked",
614     GTK_SIGNAL_FUNC(on_gclink_clicked), context);
615    
616 harbaum 184 gtk_box_pack_start(GTK_BOX(vbox), but, FALSE, FALSE, 0);
617 harbaum 66 }
618     #endif
619 harbaum 165
620     int logs = gpx_number_of_logs(log);
621     GtkWidget *table = gtk_table_new(2*logs-1, 2,FALSE);
622     int log_cnt = 0;
623    
624     gtk_table_set_col_spacing(GTK_TABLE(table), 0, 8);
625 harbaum 1
626     /* add all logs to the vbox */
627     while(log) {
628 harbaum 165 GtkWidget *ivbox = gtk_vbox_new(FALSE, 2);
629     GtkWidget *ihbox = gtk_hbox_new(FALSE, 2);
630 harbaum 1
631 harbaum 165 static const char *finder_type = "profile/";
632     GtkWidget *finder = link_button_by_id(appdata, log->finder->name,
633     finder_type, log->finder->id);
634 harbaum 163
635 harbaum 165 /* if the finder is a button make sure it's the right size and */
636     /* does not exceed the size limits */
637     if(GTK_WIDGET_TYPE(finder) == GTK_TYPE_BUTTON) {
638     #if defined(USE_MAEMO) && (MAEMO_VERSION_MAJOR == 5)
639     hildon_gtk_widget_set_theme_size(finder,
640     (HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH));
641     #endif
642 harbaum 163
643 harbaum 214 gtk_label_set_ellipsize(GTK_LABEL(gtk_bin_get_child(GTK_BIN(finder))),
644 harbaum 165 PANGO_ELLIPSIZE_END);
645     } else
646     gtk_label_set_ellipsize(GTK_LABEL(finder), PANGO_ELLIPSIZE_END);
647 harbaum 163
648 harbaum 165 gtk_box_pack_start(GTK_BOX(ivbox), finder, FALSE, FALSE, 0);
649    
650 harbaum 163 gtk_box_pack_start_defaults(GTK_BOX(ihbox),
651     icon_get_widget(ICON_LOG, log->type));
652    
653 harbaum 1 char date_str[32];
654     if(log->day && log->month && log->year) {
655     GDate *date = g_date_new_dmy(log->day, log->month, log->year);
656     g_date_strftime(date_str, sizeof(date_str), "%x", date);
657     g_date_free(date);
658     } else
659     strcpy(date_str, "---");
660    
661 harbaum 163 gtk_box_pack_start_defaults(GTK_BOX(ihbox), gtk_label_new(date_str));
662 harbaum 1
663 harbaum 165 gtk_box_pack_start(GTK_BOX(ivbox), ihbox, FALSE, FALSE, 0);
664 harbaum 137
665 harbaum 184 gtk_table_attach(GTK_TABLE(table), ivbox, 0, 1,
666     2*log_cnt, 2*log_cnt+1, 0, GTK_EXPAND | GTK_FILL, 0, 0);
667    
668 harbaum 1 if(log->text) {
669 harbaum 165 gtk_table_attach_defaults(GTK_TABLE(table),
670 harbaum 140 html_view(appdata, log->text,
671 harbaum 165 is_html?HTML_HTML:HTML_CUSTOM_MARKUP, FALSE, NULL, NULL),
672     1, 2, 2*log_cnt, 2*log_cnt+1);
673 harbaum 1 }
674 harbaum 163
675 harbaum 165 if(log_cnt < logs-1) {
676     gtk_table_set_row_spacing(GTK_TABLE(table), 2*log_cnt, 8);
677    
678     gtk_table_attach_defaults(GTK_TABLE(table), gtk_hseparator_new(),
679     0, 2, 2*log_cnt+1, 2*log_cnt+2);
680    
681     gtk_table_set_row_spacing(GTK_TABLE(table), 2*log_cnt+1, 8);
682     }
683    
684 harbaum 1 log = log->next;
685 harbaum 165 log_cnt++;
686 harbaum 1 }
687    
688 harbaum 184 gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
689 harbaum 165
690 harbaum 1 #ifndef USE_PANNABLE_AREA
691     gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scrolled_window),
692 harbaum 163 vbox);
693 harbaum 1 return scrolled_window;
694     #else
695     hildon_pannable_area_add_with_viewport(HILDON_PANNABLE_AREA(pannable_area),
696 harbaum 163 vbox);
697 harbaum 1 return pannable_area;
698     #endif
699     }
700    
701     #ifdef USE_MAEMO
702     /* this routine is called once a second as long as the "goto" tab is visible */
703     static gboolean screensaver_update(gpointer data) {
704     appdata_t *appdata = (appdata_t*)data;
705    
706     if(appdata->goto_disable_screensaver)
707     if (osso_display_blanking_pause(appdata->osso_context) != OSSO_OK)
708     fprintf(stderr, "error with display blank\n");
709    
710     return TRUE; // fire again
711     }
712     #endif
713    
714     static void on_notebook_page_change(GtkNotebook *notebook,
715     GtkNotebookPage *page,
716     guint page_num,
717     gpointer user_data) {
718    
719     cache_context_t *context = (cache_context_t*)user_data;
720     GtkWidget *w = gtk_notebook_get_nth_page(notebook, page_num);
721     const char *name = gtk_notebook_get_tab_label_text(notebook, w);
722    
723     #ifdef USE_MAEMO
724     if(context->handler_id)
725     gtk_timeout_remove(context->handler_id);
726     #endif
727    
728     /* this is a workaround, around some bug in the gtktextwidget or so ... */
729     /* i tried to get info on this and everybody agreed that this is a bug */
730 harbaum 136 /* in gtk but noone had a fix ready. so i came up with this. */
731 harbaum 1 /* seems to work ... */
732     if(strcasecmp(name, _("Logs")) == 0) {
733     gtk_widget_queue_resize(w);
734 harbaum 136 } else if(strcasecmp(name, _("Goto")) == 0) {
735 harbaum 1 #ifdef USE_MAEMO
736     context->handler_id = gtk_timeout_add(1000, screensaver_update,
737     context->appdata);
738     #endif
739 harbaum 214
740 harbaum 1 goto_coordinate_update(context);
741     }
742    
743     if(strcasecmp(name, _("Main")) == 0) {
744     /* the notes page may have changed its "override" setting, thus the */
745     /* striked out coordinate may need update */
746     overview_coordinate_update(context);
747     }
748     }
749    
750     static void on_notebook_destroy(GtkWidget *widget, gpointer user_data ) {
751     cache_context_t *context = (cache_context_t*)user_data;
752    
753     printf("destroying notebook\n");
754    
755 harbaum 159 /* cancel a pending gcvote request */
756     if(context->gcvote_request) {
757     gcvote_request_free(context->gcvote_request);
758     context->gcvote_request = NULL;
759     }
760    
761 harbaum 1 notes_destroy_event(NULL, context);
762     goto_destroy_event(NULL, context);
763    
764     #ifdef USE_MAEMO
765     if(context->handler_id)
766     gtk_timeout_remove(context->handler_id);
767     #endif
768    
769 harbaum 221 printf("freeing cache context\n");
770     g_free(context);
771 harbaum 1 }
772    
773 harbaum 168 #if defined(USE_MAEMO) && (MAEMO_VERSION_MAJOR >= 5)
774 harbaum 165 #define CUSTOM_NOTEBOOK
775     #endif
776    
777     static GtkWidget *notebook_new(void) {
778     #ifdef CUSTOM_NOTEBOOK
779     GtkWidget *vbox = gtk_vbox_new(FALSE, 0);
780    
781     GtkWidget *notebook = gtk_notebook_new();
782    
783     /* prevents user from accidentially touching the breadcrumb trail */
784     /* (looks ugly on fremantle as it isn't themed) */
785     // gtk_notebook_set_tab_pos(GTK_NOTEBOOK(notebook), GTK_POS_BOTTOM);
786    
787     /* solution for fremantle: we use a row of ordinary buttons instead */
788     /* of regular tabs */
789    
790     /* hide the regular tabs */
791     gtk_notebook_set_show_tabs(GTK_NOTEBOOK(notebook), FALSE);
792    
793     gtk_box_pack_start_defaults(GTK_BOX(vbox), notebook);
794    
795     /* store a reference to the notebook in the vbox */
796     g_object_set_data(G_OBJECT(vbox), "notebook", (gpointer)notebook);
797    
798     /* create a hbox for the buttons */
799     GtkWidget *hbox = gtk_hbox_new(TRUE, 0);
800     gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
801     g_object_set_data(G_OBJECT(vbox), "hbox", (gpointer)hbox);
802    
803     return vbox;
804     #else
805     return gtk_notebook_new();
806     #endif
807     }
808    
809 harbaum 179 #ifdef CUSTOM_NOTEBOOK
810 harbaum 165 static void on_notebook_button_clicked(GtkWidget *button, gpointer data) {
811     GtkNotebook *nb =
812     GTK_NOTEBOOK(g_object_get_data(G_OBJECT(data), "notebook"));
813    
814 harbaum 167 gint page = (gint)g_object_get_data(G_OBJECT(button), "page");
815 harbaum 165 gtk_notebook_set_current_page(nb, page);
816     }
817 harbaum 179 #endif
818 harbaum 165
819     static void notebook_append_page(GtkWidget *notebook,
820     GtkWidget *page, char *label) {
821     #ifdef CUSTOM_NOTEBOOK
822     GtkNotebook *nb =
823     GTK_NOTEBOOK(g_object_get_data(G_OBJECT(notebook), "notebook"));
824    
825     gint page_num = gtk_notebook_append_page(nb, page, gtk_label_new(label));
826 harbaum 167 GtkWidget *button = NULL;
827 harbaum 165
828     /* select button for page 0 by default */
829 harbaum 167 if(!page_num) {
830     button = gtk_radio_button_new_with_label(NULL, label);
831 harbaum 165 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), TRUE);
832 harbaum 167 g_object_set_data(G_OBJECT(notebook), "group_master", (gpointer)button);
833     } else {
834     GtkWidget *master = g_object_get_data(G_OBJECT(notebook), "group_master");
835     button = gtk_radio_button_new_with_label_from_widget(
836     GTK_RADIO_BUTTON(master), label);
837     }
838 harbaum 165
839 harbaum 167 gtk_toggle_button_set_mode(GTK_TOGGLE_BUTTON(button), FALSE);
840     g_object_set_data(G_OBJECT(button), "page", (gpointer)page_num);
841    
842 harbaum 165 gtk_signal_connect(GTK_OBJECT(button), "clicked",
843     GTK_SIGNAL_FUNC(on_notebook_button_clicked), notebook);
844    
845     #if defined(USE_MAEMO) && (MAEMO_VERSION_MAJOR == 5)
846     hildon_gtk_widget_set_theme_size(button,
847     (HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH));
848     #endif
849    
850     gtk_box_pack_start_defaults(
851     GTK_BOX(g_object_get_data(G_OBJECT(notebook), "hbox")),
852     button);
853    
854     #else
855     gtk_notebook_append_page(GTK_NOTEBOOK(notebook), page, gtk_label_new(label));
856     #endif
857     }
858    
859     static GObject *notebook_object(GtkWidget *notebook) {
860     #ifdef CUSTOM_NOTEBOOK
861     return G_OBJECT(g_object_get_data(G_OBJECT(notebook), "notebook"));
862     #else
863     return G_OBJECT(notebook);
864     #endif
865     }
866    
867 harbaum 1 GtkWidget *cache_view(appdata_t *appdata, cache_t *cache) {
868     GtkWidget *notebook;
869    
870 harbaum 221 cache_context_t *cache_context = g_new0(cache_context_t, 1);
871 harbaum 1 cache_context->appdata = appdata;
872     cache_context->cache = cache;
873    
874     #ifdef USE_MAEMO
875     #define TAB_DESC _("Desc.")
876     #define TAB_WPTS _("Wpts")
877     #else
878     #define TAB_DESC _("Description")
879     #define TAB_WPTS _("Waypoints")
880     #endif
881    
882 harbaum 165 notebook = notebook_new();
883 harbaum 133
884 harbaum 165 notebook_append_page(notebook,
885     cache_overview(cache_context), _("Main"));
886 harbaum 1
887     if(cache->long_description)
888 harbaum 165 notebook_append_page(notebook,
889     cache_description(appdata, cache), TAB_DESC);
890 harbaum 1
891     if(cache->hint)
892 harbaum 165 notebook_append_page(notebook,
893     cache_hint(appdata, cache), _("Hint"));
894 harbaum 1
895     if(cache->log)
896 harbaum 165 notebook_append_page(notebook,
897 harbaum 66 cache_logs(appdata, cache_context, cache->log, cache->logs_are_html),
898 harbaum 165 _("Logs"));
899 harbaum 1
900     if(cache->wpt)
901 harbaum 165 notebook_append_page(notebook,
902     cache_wpts(appdata, cache->wpt), TAB_WPTS);
903 harbaum 1
904     if(cache->tb)
905 harbaum 165 notebook_append_page(notebook,
906     cache_tbs(appdata, cache->tb), _("TBs"));
907 harbaum 1
908 harbaum 165 notebook_append_page(notebook,
909     cache_notes(cache_context), _("Notes"));
910 harbaum 1
911 harbaum 165 notebook_append_page(notebook,
912     goto_cache(cache_context), _("Goto"));
913 harbaum 1
914 harbaum 165 g_signal_connect(notebook_object(notebook), "switch-page",
915 harbaum 1 G_CALLBACK(on_notebook_page_change), cache_context);
916    
917 harbaum 165 g_signal_connect(notebook_object(notebook), "destroy",
918 harbaum 1 G_CALLBACK(on_notebook_destroy), cache_context);
919    
920     return notebook;
921     }
922    
923     #ifndef USE_MAEMO
924     void cache_dialog(appdata_t *appdata, cache_t *cache) {
925     GtkWidget *dialog = gtk_dialog_new_with_buttons(cache->name,
926     GTK_WINDOW(appdata->window),
927     GTK_DIALOG_NO_SEPARATOR | GTK_DIALOG_MODAL |
928     GTK_DIALOG_DESTROY_WITH_PARENT,
929     GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
930     NULL);
931    
932     gtk_window_set_default_size(GTK_WINDOW(dialog), DIALOG_WIDTH, DIALOG_HEIGHT);
933    
934     /* create cache visualization widget */
935     gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox),
936     cache_view(appdata, cache));
937    
938     gtk_widget_show_all(dialog);
939     gtk_dialog_run(GTK_DIALOG(dialog));
940     gtk_widget_destroy(dialog);
941     }
942    
943     #else
944     #ifdef USE_STACKABLE_WINDOW
945 harbaum 11 static void on_cache_destroy (GtkWidget *widget, appdata_t *appdata) {
946     appdata->cur_cache = NULL;
947    
948 harbaum 226 HildonWindowStack *stack = hildon_window_stack_get_default();
949     appdata->window = HILDON_WINDOW(hildon_window_stack_peek(stack));
950    
951 harbaum 11 /* restore cur_view */
952     appdata->cur_view = g_object_get_data(G_OBJECT(widget), "cur_view");
953     }
954    
955 harbaum 1 void cache_dialog(appdata_t *appdata, cache_t *cache) {
956     GtkWidget *window = hildon_stackable_window_new();
957 harbaum 226 appdata->window = HILDON_WINDOW(window);
958 harbaum 1
959 harbaum 11 /* store last "cur_view" in window */
960     g_object_set_data(G_OBJECT(window), "cur_view", appdata->cur_view);
961    
962     appdata->cur_cache = cache;
963 harbaum 34 char *title = g_strdup_printf("%s - GPXView", cache->name);
964 harbaum 6 gtk_window_set_title(GTK_WINDOW(window), title);
965     g_free(title);
966 harbaum 1
967     /* create cache visualization widget */
968 harbaum 11 appdata->cur_view = cache_view(appdata, cache);
969     gtk_container_add(GTK_CONTAINER(window), appdata->cur_view);
970 harbaum 1
971 harbaum 3 hildon_window_set_app_menu(HILDON_WINDOW(window),
972     menu_create(appdata, MENU_CACHE));
973    
974 harbaum 11 g_signal_connect(G_OBJECT(window), "destroy",
975     G_CALLBACK(on_cache_destroy), appdata);
976    
977 harbaum 1 gtk_widget_show_all(window);
978     }
979     #endif // USE_STACKABLE_WINDOW
980    
981     #endif // USE_MAEMO