Contents of /trunk/src/cache.c

Parent Directory Parent Directory | Revision Log Revision Log


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