Contents of /trunk/src/cache.c

Parent Directory Parent Directory | Revision Log Revision Log


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