Contents of /trunk/src/cache.c

Parent Directory Parent Directory | Revision Log Revision Log


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