Contents of /trunk/src/cache.c

Parent Directory Parent Directory | Revision Log Revision Log


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