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