Contents of /trunk/src/cache.c

Parent Directory Parent Directory | Revision Log Revision Log


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