Parent Directory | Revision Log
Description zooming
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 | #include <string.h> |
23 | |
24 | #if MAEMO_VERSION_MAJOR == 5 |
25 | #include <gdk/gdkx.h> |
26 | #include <X11/Xatom.h> |
27 | #endif |
28 | |
29 | static GtkWidget *cache_description(appdata_t *appdata, cache_t *cache) { |
30 | return html_view(appdata, cache->long_description, |
31 | cache->long_is_html?HTML_HTML:HTML_PLAIN_TEXT, TRUE, cache, NULL); |
32 | } |
33 | |
34 | #ifndef USE_MAEMO // maemos touchscreen doesn't support tooltips |
35 | static const char *cache_type_tip[] = { |
36 | "Traditional Cache", "Multicache", "Mystery/Unknown Cache", |
37 | "Virtual Cache", "Webcam Cache", "Event Cache", |
38 | "Letterbox Hybrid", "Earthcache", "Wherigo Cache", |
39 | "Mega-Event Cache", "Cache-In-Trash-Out Cache" |
40 | }; |
41 | |
42 | static const char *cache_size_tip[] = { |
43 | "Regular Container", "Small Container", "Micro", |
44 | "Other Container", "Container not chosen", "Large Container", |
45 | "Virtual Container" |
46 | }; |
47 | #endif |
48 | |
49 | static const char *cache_size_name[] = { |
50 | "Regular", "Small", "Micro", "Other", "Not chosen", "Large", "Virtual" |
51 | }; |
52 | |
53 | void bearing_fill_hbox(GtkWidget *hbox, |
54 | appdata_t *appdata, pos_t refpos, pos_t pos) { |
55 | char str[32]; |
56 | |
57 | if(!isnan(pos.lat) && !isnan(pos.lon)) { |
58 | gtk_box_pack_start(GTK_BOX(hbox), gtk_image_new_from_pixbuf( |
59 | icon_bearing(refpos, pos)),TRUE,FALSE,0); |
60 | |
61 | if(!isnan(refpos.lat) && !isnan(refpos.lon)) { |
62 | snprintf(str, sizeof(str), _("%.1f°"), |
63 | gpx_pos_get_bearing(refpos, pos)); |
64 | gtk_box_pack_start_defaults(GTK_BOX(hbox), GTK_LABEL_SMALL(str)); |
65 | gpx_pos_get_distance_str(str, sizeof(str), |
66 | refpos, pos, appdata->imperial); |
67 | gtk_box_pack_start_defaults(GTK_BOX(hbox), GTK_LABEL_SMALL(" ")); |
68 | gtk_box_pack_start(GTK_BOX(hbox), |
69 | gtk_label_attrib(str, SIZE_SMALL, STRIKETHROUGH_NONE),TRUE,FALSE,0); |
70 | } else |
71 | gtk_box_pack_start(GTK_BOX(hbox), |
72 | gtk_label_attrib(_("(no position)"), |
73 | SIZE_SMALL, STRIKETHROUGH_NONE),TRUE,FALSE,0); |
74 | } else |
75 | gtk_box_pack_start(GTK_BOX(hbox), |
76 | gtk_label_attrib(_("(invalid position in notes)"), |
77 | SIZE_SMALL, STRIKETHROUGH_NONE),TRUE,FALSE,0); |
78 | } |
79 | |
80 | /* this function sets everything related to the coordinate. used to */ |
81 | /* cope with the user setting a new "note coordinate" */ |
82 | void overview_coordinate_update(cache_context_t *context) { |
83 | if(!context->notes.modified) |
84 | return; |
85 | |
86 | /* update position labels */ |
87 | int strike = notes_get_override(context)?STRIKETHROUGH:STRIKETHROUGH_NONE; |
88 | lat_label_attrib_set(context->pos_lat_label, |
89 | context->cache->pos.lat, SIZE_BIG, strike); |
90 | lon_label_attrib_set(context->pos_lon_label, |
91 | context->cache->pos.lon, SIZE_BIG, strike); |
92 | |
93 | /* remove enire hbox and build a new one */ |
94 | gtk_container_foreach(GTK_CONTAINER(context->bearing_hbox), |
95 | (GtkCallback)gtk_widget_destroy, NULL); |
96 | |
97 | /* update distance/etc */ |
98 | if(!isnan(context->cache->pos.lat) && |
99 | !isnan(context->cache->pos.lon)) |
100 | bearing_fill_hbox(context->bearing_hbox, context->appdata, |
101 | *get_pos(context->appdata), notes_get_pos(context)); |
102 | |
103 | gtk_widget_show_all(context->bearing_hbox); |
104 | } |
105 | |
106 | static void gcvote_set(cache_context_t *context, vote_t *vote) { |
107 | if(!vote) return; |
108 | |
109 | if(context->quality) { |
110 | gtk_widget_destroy(context->quality); |
111 | context->quality = NULL; |
112 | } |
113 | |
114 | if(context->votes) { |
115 | gtk_widget_destroy(context->votes); |
116 | context->votes = NULL; |
117 | } |
118 | |
119 | /* update/draw the voting */ |
120 | #ifndef USE_MAEMO |
121 | GtkTooltips *tips = gtk_tooltips_new(); |
122 | #endif |
123 | |
124 | char *votes_str = g_strdup_printf(_("Quality (%d %s):"), vote->votes, |
125 | (vote->votes == 1)?_("vote"):_("votes")); |
126 | context->votes = GTK_LABEL_SMALL(votes_str); |
127 | gtk_box_pack_start(GTK_BOX(context->votebox), |
128 | context->votes, FALSE, FALSE, 0); |
129 | g_free(votes_str); |
130 | context->quality = icon_get_widget(ICON_STARS, (int)(vote->quality*2-2)); |
131 | gtk_box_pack_start(GTK_BOX(context->votebox), context->quality, |
132 | FALSE, FALSE, 0); |
133 | |
134 | #ifndef USE_MAEMO |
135 | char *str = g_strdup_printf(_("Quality: %d"), vote->quality); |
136 | gtk_tooltips_set_tip(tips, context->votebox, str, NULL); |
137 | g_free(str); |
138 | #endif |
139 | |
140 | gtk_widget_show_all(context->votebox); |
141 | |
142 | g_free(vote); |
143 | } |
144 | |
145 | static void gcvote_callback(vote_t *vote, gpointer data) { |
146 | cache_context_t *context = (cache_context_t*)data; |
147 | |
148 | /* no vote returned: request failed, just cleanup */ |
149 | if(!vote) { |
150 | printf("gcvote: callback for failed request\n"); |
151 | |
152 | gcvote_request_free(context->gcvote_request); |
153 | context->gcvote_request = NULL; |
154 | return; |
155 | } |
156 | |
157 | printf("gcvote: callback is being called with a %d/%d\n", |
158 | vote->quality, vote->votes); |
159 | |
160 | gcvote_set(context, vote); |
161 | |
162 | gcvote_save(context->appdata, context->cache, &context->gcvote_request->mem); |
163 | |
164 | gcvote_request_free(context->gcvote_request); |
165 | context->gcvote_request = NULL; |
166 | } |
167 | |
168 | static void pack_vcentered(GtkWidget *vbox, GtkWidget *child) { |
169 | GtkWidget *align = gtk_alignment_new(0.5, 0.5, 0.0, 0.0); |
170 | gtk_container_add(GTK_CONTAINER(align), child); |
171 | gtk_box_pack_start_defaults(GTK_BOX(vbox), align); |
172 | } |
173 | |
174 | #ifdef FREMANTLE |
175 | #define ICON_SIZE ICON_CACHE_TYPE_2X |
176 | #else |
177 | #define ICON_SIZE ICON_CACHE_TYPE_1_5X |
178 | #endif |
179 | |
180 | static GtkWidget *cache_overview(cache_context_t *context) { |
181 | GtkWidget *vbox, *ivbox; |
182 | GtkWidget *colbox, *tip; |
183 | char str[64]; |
184 | #ifndef USE_MAEMO |
185 | GtkTooltips *tips = gtk_tooltips_new(); |
186 | #endif |
187 | appdata_t *appdata = context->appdata; |
188 | cache_t *cache = context->cache; |
189 | |
190 | vbox = gtk_vbox_new(FALSE, 4); |
191 | |
192 | /* hbox containing the four columns of cache details */ |
193 | GtkWidget *pbox = portrait_box_new(FALSE, 0); |
194 | |
195 | GtkWidget *ihbox = gtk_hbox_new(FALSE, 0); |
196 | |
197 | /* vbox containing leftmost column (icon and container) */ |
198 | colbox = gtk_vbox_new(FALSE, 0); |
199 | |
200 | if(cache->type != CACHE_TYPE_UNKNOWN) { |
201 | gtk_box_pack_start_defaults(GTK_BOX(colbox), |
202 | tip = icon_get_widget(ICON_SIZE, cache->type)); |
203 | |
204 | #ifndef USE_MAEMO |
205 | gtk_tooltips_set_tip(tips, tip, _(cache_type_tip[cache->type]), NULL); |
206 | #endif |
207 | } |
208 | |
209 | /* ------------ box containing container info ------------ */ |
210 | if(cache->container != CACHE_CONT_UNKNOWN) { |
211 | ivbox = gtk_vbox_new(FALSE, 0); |
212 | sprintf(str, _("Size: %s"), _(cache_size_name[cache->container])); |
213 | gtk_box_pack_start(GTK_BOX(ivbox), GTK_LABEL_SMALL(str), |
214 | FALSE, FALSE, 0); |
215 | gtk_box_pack_start(GTK_BOX(ivbox), |
216 | icon_get_widget(ICON_CACHE_SIZE, cache->container), |
217 | FALSE, FALSE, 0); |
218 | |
219 | pack_vcentered(colbox, ivbox); |
220 | #ifndef USE_MAEMO |
221 | gtk_tooltips_set_tip(tips, ivbox, _(cache_size_tip[cache->container]), NULL); |
222 | #endif |
223 | } |
224 | |
225 | gtk_box_pack_start_defaults(GTK_BOX(ihbox), colbox); |
226 | colbox = gtk_vbox_new(FALSE, 0); |
227 | |
228 | /* ----------------------- id ---------------------------- */ |
229 | if(cache->id) { |
230 | int strike = cache->archived?STRIKETHROUGH_RED: |
231 | (!cache->available?STRIKETHROUGH:STRIKETHROUGH_NONE); |
232 | GtkWidget *lbl = link_button_attrib(context->appdata, |
233 | cache->id, context->cache->url, |
234 | SIZE_BIG, strike); |
235 | pack_vcentered(colbox, lbl); |
236 | } |
237 | |
238 | /* --------------- box containing owner info ------------- */ |
239 | if(cache->owner) { |
240 | gtk_box_pack_start_defaults(GTK_BOX(colbox), GTK_LABEL_SMALL(_("by"))); |
241 | |
242 | static const char *owner_type = "profile/"; |
243 | pack_vcentered(colbox, |
244 | link_button_by_id(appdata, cache->owner->name, |
245 | owner_type, cache->owner->id)); |
246 | } |
247 | |
248 | gtk_box_pack_start_defaults(GTK_BOX(ihbox), colbox); |
249 | |
250 | /* pack left two columns into portrait box */ |
251 | gtk_box_pack_start_defaults(GTK_BOX(pbox), ihbox); |
252 | ihbox = gtk_hbox_new(FALSE, 0); |
253 | |
254 | /* ----------- vbox containing all ratings ---------- */ |
255 | colbox = gtk_vbox_new(FALSE, 0); |
256 | |
257 | /* ----------- box containing difficulty rating ---------- */ |
258 | if(cache->difficulty != 0) { |
259 | ivbox = gtk_vbox_new(FALSE, 0); |
260 | gtk_box_pack_start(GTK_BOX(ivbox), |
261 | GTK_LABEL_SMALL(_("Difficulty:")), |
262 | FALSE, FALSE, 0); |
263 | gtk_box_pack_start(GTK_BOX(ivbox), |
264 | icon_get_widget(ICON_STARS, (int)(cache->difficulty*2-2)), |
265 | FALSE, FALSE, 0); |
266 | |
267 | pack_vcentered(colbox, ivbox); |
268 | #ifndef USE_MAEMO |
269 | sprintf(str, _("Difficulty: %.1f"), cache->difficulty); |
270 | gtk_tooltips_set_tip(tips, ivbox, str, NULL); |
271 | #endif |
272 | } |
273 | |
274 | /* ------------ box containing terrain rating ------------ */ |
275 | if(cache->terrain != 0) { |
276 | ivbox = gtk_vbox_new(FALSE, 0); |
277 | gtk_box_pack_start(GTK_BOX(ivbox), GTK_LABEL_SMALL(_("Terrain:")), |
278 | FALSE, FALSE, 0); |
279 | gtk_box_pack_start(GTK_BOX(ivbox), |
280 | icon_get_widget(ICON_STARS, (int)(cache->terrain*2-2)), |
281 | FALSE, FALSE, 0); |
282 | pack_vcentered(colbox, ivbox); |
283 | #ifndef USE_MAEMO |
284 | sprintf(str, _("Terrain: %.1f"), cache->terrain); |
285 | gtk_tooltips_set_tip(tips, ivbox, str, NULL); |
286 | #endif |
287 | } |
288 | |
289 | /* --------------------- GCVote ------------------------ */ |
290 | if(!appdata->disable_gcvote) { |
291 | vote_t *vote = gcvote_restore(appdata, cache); |
292 | |
293 | context->gcvote_request = |
294 | gcvote_request(appdata, gcvote_callback, cache->url, context); |
295 | |
296 | context->votebox = gtk_vbox_new(FALSE, 0); |
297 | pack_vcentered(colbox, context->votebox); |
298 | |
299 | /* fill with vote if present on disk (will also free vote) */ |
300 | if(vote) |
301 | gcvote_set(context, vote); |
302 | } |
303 | |
304 | gtk_box_pack_start_defaults(GTK_BOX(ihbox), colbox); |
305 | |
306 | /* ----------------------------------------------------- */ |
307 | |
308 | |
309 | /* ----------------- the two coordinates ----------------- */ |
310 | /* ----------------- and the heading/distance ------------ */ |
311 | colbox = gtk_vbox_new(FALSE, 0); |
312 | |
313 | pos_t *refpos = get_pos(appdata); |
314 | |
315 | ivbox = gtk_vbox_new(FALSE, 0); |
316 | int strike = (cache->notes && cache->notes->override)? |
317 | STRIKETHROUGH:STRIKETHROUGH_NONE; |
318 | |
319 | /* the original coordinate is being displayed */ |
320 | gtk_box_pack_start(GTK_BOX(ivbox), |
321 | context->pos_lat_label = pos_lat(cache->pos.lat, SIZE_BIG, strike), FALSE, FALSE, 0); |
322 | gtk_box_pack_start(GTK_BOX(ivbox), |
323 | context->pos_lon_label = pos_lon(cache->pos.lon, SIZE_BIG, strike), FALSE, FALSE, 0); |
324 | |
325 | pack_vcentered(colbox, ivbox); |
326 | |
327 | /* but calculations may be done with respect to the overriden one */ |
328 | if(!isnan(cache->pos.lat) && !isnan(cache->pos.lon)) { |
329 | context->bearing_hbox = gtk_hbox_new(FALSE, 0); |
330 | bearing_fill_hbox(context->bearing_hbox, appdata, *refpos, |
331 | gpx_cache_pos(cache)); |
332 | pack_vcentered(colbox, context->bearing_hbox); |
333 | } |
334 | |
335 | gtk_box_pack_start_defaults(GTK_BOX(ihbox), colbox); |
336 | gtk_box_pack_start_defaults(GTK_BOX(pbox), ihbox); |
337 | |
338 | /* ----------------------------------------------------- */ |
339 | |
340 | gtk_box_pack_start(GTK_BOX(vbox), pbox, FALSE, FALSE, 0); |
341 | gtk_box_pack_start(GTK_BOX(vbox), gtk_hseparator_new(), FALSE, FALSE, 0); |
342 | |
343 | /* ----------------------------------------------------- */ |
344 | |
345 | if(cache->attribute) { |
346 | GtkWidget *thbox = gtk_hbox_new(FALSE, 0); |
347 | ihbox = gtk_hbox_new(FALSE, 0); |
348 | |
349 | attribute_t *att = cache->attribute; |
350 | while(att) { |
351 | if(att->inc) |
352 | tip = icon_get_widget(ICON_ATT, att->id+1); |
353 | else |
354 | tip = icon_get_widget_ovl(ICON_ATT, att->id+1, 0); |
355 | |
356 | gtk_box_pack_start(GTK_BOX(ihbox), tip, FALSE, FALSE, 4); |
357 | |
358 | #ifndef USE_MAEMO |
359 | gtk_tooltips_set_tip(tips, tip, _(att->name), NULL); |
360 | #endif |
361 | |
362 | att = att->next; |
363 | } |
364 | |
365 | gtk_box_pack_start(GTK_BOX(thbox), ihbox, TRUE, FALSE, 0); |
366 | gtk_box_pack_start(GTK_BOX(vbox), thbox, FALSE, FALSE, 0); |
367 | gtk_box_pack_start(GTK_BOX(vbox), gtk_hseparator_new(), FALSE, FALSE, 0); |
368 | } |
369 | |
370 | /* ----------------------------------------------------- */ |
371 | |
372 | if(cache->short_description) |
373 | gtk_box_pack_start_defaults(GTK_BOX(vbox), |
374 | html_view(appdata, cache->short_description, |
375 | cache->short_is_html?HTML_HTML:HTML_PLAIN_TEXT, TRUE, cache, NULL)); |
376 | |
377 | return vbox; |
378 | } |
379 | |
380 | /* slow but short, we don't need performance here ... */ |
381 | static void rot13(char *t) { |
382 | int braces = 0; |
383 | |
384 | while(*t) { |
385 | if(!braces) { |
386 | if(*t == '[') |
387 | braces++; |
388 | else if(((*t >= 'a') && (*t < 'n')) || |
389 | ((*t >= 'A') && (*t < 'N'))) *t += 13; |
390 | else if(((*t >= 'n') && (*t <= 'z')) || |
391 | ((*t >= 'N') && (*t <= 'Z'))) *t -= 13; |
392 | } else { |
393 | if(braces > 0 && *t == ']') |
394 | braces--; |
395 | } |
396 | |
397 | t++; |
398 | } |
399 | } |
400 | |
401 | static void on_decrypt(GtkWidget *widget, gpointer data) { |
402 | /* data is a link to the textview */ |
403 | g_assert(GTK_IS_TEXT_VIEW(data)); |
404 | |
405 | GtkTextIter start, end; |
406 | GtkTextBuffer *buffer = gtk_text_view_get_buffer((GtkTextView*)data); |
407 | |
408 | gtk_text_buffer_get_start_iter(buffer, &start); |
409 | gtk_text_buffer_get_end_iter(buffer, &end); |
410 | char *text = gtk_text_buffer_get_text(buffer, &start, &end, FALSE); |
411 | |
412 | rot13(text); |
413 | gtk_text_buffer_set_text(buffer, text, -1); |
414 | |
415 | free(text); |
416 | } |
417 | |
418 | static GtkWidget *cache_hint(appdata_t *appdata, cache_t *cache) { |
419 | /* encrypting/decrypting html is nothing we want to do */ |
420 | if(cache->hint_is_html) |
421 | return html_view(appdata, cache->hint, HTML_HTML, TRUE, NULL, NULL); |
422 | |
423 | /* we can now be sure that we are talking about pain text */ |
424 | GtkWidget *vbox = gtk_vbox_new(FALSE, 0); |
425 | |
426 | char *hint = strdup(cache->hint); |
427 | rot13(hint); |
428 | GtkWidget *view = |
429 | html_view(appdata, hint, HTML_PLAIN_TEXT, TRUE, NULL, NULL); |
430 | gtk_box_pack_start_defaults(GTK_BOX(vbox), view); |
431 | free(hint); |
432 | |
433 | GtkWidget *button = gtk_button_new_with_label(_("Encrypt/Decrypt")); |
434 | #if defined(USE_MAEMO) && (MAEMO_VERSION_MAJOR == 5) |
435 | hildon_gtk_widget_set_theme_size(button, |
436 | (HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH)); |
437 | #endif |
438 | gtk_box_pack_start(GTK_BOX(vbox), button, FALSE, FALSE, 0); |
439 | gtk_signal_connect(GTK_OBJECT(button), "clicked", |
440 | GTK_SIGNAL_FUNC(on_decrypt), gtk_bin_get_child(GTK_BIN(view))); |
441 | |
442 | return vbox; |
443 | } |
444 | |
445 | static GtkWidget *cache_wpts(appdata_t *appdata, wpt_t *wpt) { |
446 | pos_t *refpos = NULL; |
447 | |
448 | #ifndef USE_PANNABLE_AREA |
449 | GtkWidget *scrolled_window = gtk_scrolled_window_new(NULL, NULL); |
450 | gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_window), |
451 | GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); |
452 | #else |
453 | GtkWidget *pannable_area = hildon_pannable_area_new(); |
454 | #endif |
455 | |
456 | GtkWidget *vbox = gtk_vbox_new(FALSE, 0); |
457 | |
458 | /* four rows per waypoint */ |
459 | GtkWidget *table = gtk_table_new(4*gpx_number_of_waypoints(wpt)-1,4, FALSE); |
460 | |
461 | refpos = get_pos(appdata); |
462 | |
463 | int wpt_row=0; |
464 | while(wpt) { |
465 | GtkWidget *ihbox, *tip; |
466 | char str[32]; |
467 | |
468 | /* ----------------------- icon/id ---------------------------- */ |
469 | ihbox = gtk_hbox_new(FALSE, 0); |
470 | |
471 | if(wpt->sym != WPT_SYM_UNKNOWN) { |
472 | gtk_box_pack_start(GTK_BOX(ihbox), |
473 | tip = icon_get_widget(ICON_WPT, wpt->sym), 1,0,0); |
474 | } |
475 | |
476 | if(wpt->id) |
477 | gtk_box_pack_start(GTK_BOX(ihbox), GTK_LABEL_BIG(wpt->id), 1,0,0); |
478 | |
479 | gtk_table_attach_defaults(GTK_TABLE(table), ihbox, 0,1,wpt_row, wpt_row+1); |
480 | |
481 | /* ----------------- the two coordinates ----------------- */ |
482 | /* ----------------- and the heading/distance ------------ */ |
483 | gtk_table_attach_defaults(GTK_TABLE(table), |
484 | pos_lat(wpt->pos.lat, SIZE_BIG, STRIKETHROUGH_NONE), |
485 | 1,2, wpt_row, wpt_row+1); |
486 | gtk_table_attach_defaults(GTK_TABLE(table), |
487 | pos_lon(wpt->pos.lon, SIZE_BIG, STRIKETHROUGH_NONE), |
488 | 2,3, wpt_row, wpt_row+1); |
489 | |
490 | if(refpos && !isnan(refpos->lat) && !isnan(refpos->lon)) { |
491 | ihbox = gtk_hbox_new(FALSE, 0); |
492 | gtk_box_pack_start(GTK_BOX(ihbox), gtk_image_new_from_pixbuf( |
493 | icon_bearing(*refpos, wpt->pos)),1,0,0); |
494 | snprintf(str, sizeof(str), _("%.1f°"), |
495 | gpx_pos_get_bearing(*refpos, wpt->pos)); |
496 | gtk_box_pack_start_defaults(GTK_BOX(ihbox), GTK_LABEL_SMALL(str)); |
497 | |
498 | gpx_pos_get_distance_str(str, sizeof(str), |
499 | *refpos, wpt->pos, appdata->imperial); |
500 | gtk_box_pack_start(GTK_BOX(ihbox), GTK_LABEL_SMALL(str),1,0,0); |
501 | |
502 | gtk_table_attach_defaults(GTK_TABLE(table), ihbox, 3,4, |
503 | wpt_row+0, wpt_row+1); |
504 | } |
505 | |
506 | /* ------------------ description ------------------------- */ |
507 | if(wpt->desc) |
508 | gtk_table_attach_defaults(GTK_TABLE(table), |
509 | simple_text_widget(wpt->desc), 0,4, |
510 | wpt_row+1, wpt_row+2); |
511 | |
512 | /* ------------------ comment ------------------------- */ |
513 | if(wpt->cmt) |
514 | gtk_table_attach_defaults(GTK_TABLE(table), |
515 | simple_text_widget(wpt->cmt), 0,4, |
516 | wpt_row+2, wpt_row+3); |
517 | |
518 | /* --------------------- seperator -------------------------*/ |
519 | if(wpt->next) { |
520 | gtk_table_set_row_spacing(GTK_TABLE(table), wpt_row+2, 8); |
521 | gtk_table_attach_defaults(GTK_TABLE(table), gtk_hseparator_new(), 0,4, |
522 | wpt_row+3, wpt_row+4); |
523 | gtk_table_set_row_spacing(GTK_TABLE(table), wpt_row+3, 8); |
524 | } |
525 | |
526 | wpt_row+=4; |
527 | wpt = wpt->next; |
528 | } |
529 | |
530 | gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0); |
531 | |
532 | #ifndef USE_PANNABLE_AREA |
533 | gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scrolled_window), |
534 | vbox); |
535 | return scrolled_window; |
536 | #else |
537 | hildon_pannable_area_add_with_viewport(HILDON_PANNABLE_AREA(pannable_area), |
538 | vbox); |
539 | return pannable_area; |
540 | #endif |
541 | } |
542 | |
543 | static GtkWidget *cache_tbs(appdata_t *appdata, tb_t *tb) { |
544 | pos_t *refpos = NULL; |
545 | |
546 | #ifndef USE_PANNABLE_AREA |
547 | GtkWidget *scrolled_window = gtk_scrolled_window_new(NULL, NULL); |
548 | gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_window), |
549 | GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); |
550 | #else |
551 | GtkWidget *pannable_area = hildon_pannable_area_new(); |
552 | #endif |
553 | |
554 | GtkWidget *vbox = gtk_vbox_new(FALSE, 0); |
555 | |
556 | /* four rows per waypoint */ |
557 | GtkWidget *table = gtk_table_new(2*gpx_number_of_tbs(tb)-1,3, FALSE); |
558 | |
559 | refpos = get_pos(appdata); |
560 | |
561 | int tb_row=0; |
562 | while(tb) { |
563 | static const char *tb_type = "track/details.aspx"; |
564 | |
565 | /* --------------------- icon/ref/name -------------------------*/ |
566 | GtkWidget *icon = NULL; |
567 | if((strcasestr(tb->name, "coin") != 0) || |
568 | (strcasestr(tb->name, "muenze") != 0) || |
569 | (strcasestr(tb->name, "münze") != 0)) |
570 | icon = icon_get_widget(ICON_TB, 1); /* coin icon */ |
571 | else |
572 | icon = icon_get_widget(ICON_TB, 0); /* tb icon */ |
573 | |
574 | gtk_table_attach_defaults(GTK_TABLE(table), icon, |
575 | 0, 1, tb_row+0, tb_row+1); |
576 | |
577 | if(tb->ref) { |
578 | GtkWidget *ref = link_button_by_id(appdata, tb->ref, tb_type, tb->id); |
579 | gtk_table_attach_defaults(GTK_TABLE(table), ref, |
580 | 1, 2, tb_row+0, tb_row+1); |
581 | } |
582 | |
583 | if(tb->name) |
584 | gtk_table_attach_defaults(GTK_TABLE(table), GTK_LABEL_BIG(tb->name), |
585 | 2, 3, tb_row+0, tb_row+1); |
586 | |
587 | /* --------------------- seperator -------------------------*/ |
588 | if(tb->next) |
589 | gtk_table_attach_defaults(GTK_TABLE(table), gtk_hseparator_new(), 0, 3, |
590 | tb_row+1, tb_row+2); |
591 | tb_row+=2; |
592 | tb = tb->next; |
593 | } |
594 | |
595 | gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0); |
596 | |
597 | #ifndef USE_PANNABLE_AREA |
598 | gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scrolled_window), |
599 | vbox); |
600 | return scrolled_window; |
601 | #else |
602 | hildon_pannable_area_add_with_viewport(HILDON_PANNABLE_AREA(pannable_area), |
603 | vbox); |
604 | return pannable_area; |
605 | #endif |
606 | } |
607 | |
608 | #ifdef ENABLE_BROWSER_INTERFACE |
609 | static void on_gclink_clicked(GtkButton *button, gpointer data) { |
610 | cache_context_t *context = (cache_context_t*)data; |
611 | char *url = g_strdup_printf("http://www.geocaching.com/seek/log.aspx?wp=%s", context->cache->id); |
612 | browser_url(context->appdata, url); |
613 | g_free(url); |
614 | } |
615 | #endif |
616 | |
617 | static GtkWidget *cache_logs(appdata_t *appdata, cache_context_t *context, |
618 | log_t *log, int is_html) { |
619 | #ifndef USE_PANNABLE_AREA |
620 | /* put this inside a scrolled view */ |
621 | GtkWidget *scrolled_window = gtk_scrolled_window_new(NULL, NULL); |
622 | gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_window), |
623 | GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); |
624 | #else |
625 | GtkWidget *pannable_area = hildon_pannable_area_new(); |
626 | #endif |
627 | |
628 | #ifdef ENABLE_BROWSER_INTERFACE |
629 | gboolean gc_link = strncmp(context->cache->id, "GC", 2) == 0; |
630 | #else |
631 | #define gc_link (FALSE) |
632 | #endif |
633 | |
634 | GtkWidget *vbox = gtk_vbox_new(FALSE, 6); |
635 | |
636 | #ifdef ENABLE_BROWSER_INTERFACE |
637 | if(gc_link) { |
638 | GtkWidget *but = |
639 | gtk_button_new_with_label(_("Post a new log entry for this geocache")); |
640 | #if defined(USE_MAEMO) && (MAEMO_VERSION_MAJOR == 5) |
641 | hildon_gtk_widget_set_theme_size(but, |
642 | (HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH)); |
643 | #endif |
644 | gtk_signal_connect(GTK_OBJECT(but), "clicked", |
645 | GTK_SIGNAL_FUNC(on_gclink_clicked), context); |
646 | |
647 | gtk_box_pack_start(GTK_BOX(vbox), but, FALSE, FALSE, 0); |
648 | } |
649 | #endif |
650 | |
651 | int logs = gpx_number_of_logs(log); |
652 | GtkWidget *table = gtk_table_new(2*logs-1, 2,FALSE); |
653 | int log_cnt = 0; |
654 | |
655 | gtk_table_set_col_spacing(GTK_TABLE(table), 0, 8); |
656 | |
657 | /* add all logs to the vbox */ |
658 | while(log) { |
659 | GtkWidget *ivbox = gtk_vbox_new(FALSE, 2); |
660 | GtkWidget *ihbox = gtk_hbox_new(FALSE, 2); |
661 | |
662 | static const char *finder_type = "profile/"; |
663 | GtkWidget *finder = link_button_by_id(appdata, log->finder->name, |
664 | finder_type, log->finder->id); |
665 | |
666 | /* if the finder is a button make sure it's the right size and */ |
667 | /* does not exceed the size limits */ |
668 | if(GTK_WIDGET_TYPE(finder) == GTK_TYPE_BUTTON) { |
669 | #if defined(USE_MAEMO) && (MAEMO_VERSION_MAJOR == 5) |
670 | hildon_gtk_widget_set_theme_size(finder, |
671 | (HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH)); |
672 | #endif |
673 | |
674 | gtk_label_set_ellipsize(GTK_LABEL(gtk_bin_get_child(GTK_BIN(finder))), |
675 | PANGO_ELLIPSIZE_END); |
676 | } else |
677 | gtk_label_set_ellipsize(GTK_LABEL(finder), PANGO_ELLIPSIZE_END); |
678 | |
679 | gtk_box_pack_start(GTK_BOX(ivbox), finder, FALSE, FALSE, 0); |
680 | |
681 | gtk_box_pack_start_defaults(GTK_BOX(ihbox), |
682 | icon_get_widget(ICON_LOG, log->type)); |
683 | |
684 | char date_str[32]; |
685 | if(log->day && log->month && log->year) { |
686 | GDate *date = g_date_new_dmy(log->day, log->month, log->year); |
687 | g_date_strftime(date_str, sizeof(date_str), "%x", date); |
688 | g_date_free(date); |
689 | } else |
690 | strcpy(date_str, "---"); |
691 | |
692 | gtk_box_pack_start_defaults(GTK_BOX(ihbox), gtk_label_new(date_str)); |
693 | |
694 | gtk_box_pack_start(GTK_BOX(ivbox), ihbox, FALSE, FALSE, 0); |
695 | |
696 | gtk_table_attach(GTK_TABLE(table), ivbox, 0, 1, |
697 | 2*log_cnt, 2*log_cnt+1, 0, GTK_EXPAND | GTK_FILL, 0, 0); |
698 | |
699 | if(log->text) { |
700 | gtk_table_attach_defaults(GTK_TABLE(table), |
701 | html_view(appdata, log->text, |
702 | is_html?HTML_HTML:HTML_CUSTOM_MARKUP, FALSE, NULL, NULL), |
703 | 1, 2, 2*log_cnt, 2*log_cnt+1); |
704 | } |
705 | |
706 | if(log_cnt < logs-1) { |
707 | gtk_table_set_row_spacing(GTK_TABLE(table), 2*log_cnt, 8); |
708 | |
709 | gtk_table_attach_defaults(GTK_TABLE(table), gtk_hseparator_new(), |
710 | 0, 2, 2*log_cnt+1, 2*log_cnt+2); |
711 | |
712 | gtk_table_set_row_spacing(GTK_TABLE(table), 2*log_cnt+1, 8); |
713 | } |
714 | |
715 | log = log->next; |
716 | log_cnt++; |
717 | } |
718 | |
719 | gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0); |
720 | |
721 | #ifndef USE_PANNABLE_AREA |
722 | gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scrolled_window), |
723 | vbox); |
724 | return scrolled_window; |
725 | #else |
726 | hildon_pannable_area_add_with_viewport(HILDON_PANNABLE_AREA(pannable_area), |
727 | vbox); |
728 | return pannable_area; |
729 | #endif |
730 | } |
731 | |
732 | #ifdef USE_MAEMO |
733 | /* this routine is called once a second as long as the "goto" tab is visible */ |
734 | static gboolean screensaver_update(gpointer data) { |
735 | appdata_t *appdata = (appdata_t*)data; |
736 | |
737 | if(appdata->goto_disable_screensaver) |
738 | if (osso_display_blanking_pause(appdata->osso_context) != OSSO_OK) |
739 | fprintf(stderr, "error with display blank\n"); |
740 | |
741 | return TRUE; // fire again |
742 | } |
743 | #endif |
744 | |
745 | static void on_notebook_page_change(GtkNotebook *notebook, |
746 | GtkNotebookPage *page, |
747 | guint page_num, |
748 | gpointer user_data) { |
749 | |
750 | cache_context_t *context = (cache_context_t*)user_data; |
751 | GtkWidget *w = gtk_notebook_get_nth_page(notebook, page_num); |
752 | const char *name = gtk_notebook_get_tab_label_text(notebook, w); |
753 | |
754 | #ifdef USE_MAEMO |
755 | if(context->handler_id) |
756 | gtk_timeout_remove(context->handler_id); |
757 | #endif |
758 | |
759 | /* this is a workaround, around some bug in the gtktextwidget or so ... */ |
760 | /* i tried to get info on this and everybody agreed that this is a bug */ |
761 | /* in gtk but noone had a fix ready. so i came up with this. */ |
762 | /* seems to work ... */ |
763 | if(strcasecmp(name, _("Logs")) == 0) { |
764 | gtk_widget_queue_resize(w); |
765 | } else if(strcasecmp(name, _("Goto")) == 0) { |
766 | #ifdef USE_MAEMO |
767 | context->handler_id = gtk_timeout_add(1000, screensaver_update, |
768 | context->appdata); |
769 | #endif |
770 | |
771 | goto_coordinate_update(context); |
772 | } |
773 | |
774 | if(strcasecmp(name, _("Main")) == 0) { |
775 | /* the notes page may have changed its "override" setting, thus the */ |
776 | /* striked out coordinate may need update */ |
777 | overview_coordinate_update(context); |
778 | } |
779 | } |
780 | |
781 | static void on_notebook_destroy(GtkWidget *widget, gpointer user_data ) { |
782 | cache_context_t *context = (cache_context_t*)user_data; |
783 | |
784 | printf("destroying notebook\n"); |
785 | |
786 | /* cancel a pending gcvote request */ |
787 | if(context->gcvote_request) { |
788 | gcvote_request_free(context->gcvote_request); |
789 | context->gcvote_request = NULL; |
790 | } |
791 | |
792 | notes_destroy_event(NULL, context); |
793 | goto_destroy_event(NULL, context); |
794 | |
795 | #ifdef USE_MAEMO |
796 | if(context->handler_id) |
797 | gtk_timeout_remove(context->handler_id); |
798 | #endif |
799 | |
800 | #ifdef USE_STACKABLE_WINDOW |
801 | if(context->notes_have_been_changed) { |
802 | printf("notes changed -> cachelist redraw\n"); |
803 | |
804 | /* now the cachelist is visible again. so redraw it since it may */ |
805 | /* have changed */ |
806 | cachelist_redraw(context->appdata); |
807 | } |
808 | #endif |
809 | |
810 | printf("freeing cache context\n"); |
811 | context->appdata->cache_context = NULL; |
812 | g_free(context); |
813 | } |
814 | |
815 | static GObject *notebook_object(GtkWidget *notebook) { |
816 | return G_OBJECT(notebook_get_gtk_notebook(notebook)); |
817 | } |
818 | |
819 | GtkWidget *cache_view(appdata_t *appdata, cache_t *cache) { |
820 | GtkWidget *notebook; |
821 | |
822 | cache_context_t *cache_context = g_new0(cache_context_t, 1); |
823 | appdata->cache_context = cache_context; |
824 | cache_context->appdata = appdata; |
825 | cache_context->cache = cache; |
826 | |
827 | #ifdef USE_MAEMO |
828 | #define TAB_DESC _("Desc.") |
829 | #define TAB_WPTS _("Wpts") |
830 | #else |
831 | #define TAB_DESC _("Description") |
832 | #define TAB_WPTS _("Waypoints") |
833 | #endif |
834 | |
835 | notebook = notebook_new(); |
836 | |
837 | notebook_append_page(notebook, |
838 | cache_overview(cache_context), _("Main")); |
839 | |
840 | if(cache->long_description) |
841 | notebook_append_page(notebook, |
842 | cache_description(appdata, cache), TAB_DESC); |
843 | |
844 | if(cache->hint) |
845 | notebook_append_page(notebook, |
846 | cache_hint(appdata, cache), _("Hint")); |
847 | |
848 | // always display log page to allow user to post a new log |
849 | if(cache->log |
850 | #ifdef ENABLE_BROWSER_INTERFACE |
851 | || (strncmp(cache->id, "GC", 2) == 0) |
852 | #endif |
853 | ) |
854 | notebook_append_page(notebook, |
855 | cache_logs(appdata, cache_context, cache->log, cache->logs_are_html), |
856 | _("Logs")); |
857 | |
858 | if(cache->wpt) |
859 | notebook_append_page(notebook, |
860 | cache_wpts(appdata, cache->wpt), TAB_WPTS); |
861 | |
862 | if(cache->tb) |
863 | notebook_append_page(notebook, |
864 | cache_tbs(appdata, cache->tb), _("TBs")); |
865 | |
866 | /* the demo caches don't have coordinates, so avoid */ |
867 | /* having to deal with them */ |
868 | if(!isnan(cache->pos.lat) && !isnan(cache->pos.lon)) { |
869 | notebook_append_page(notebook, |
870 | cache_notes(cache_context), _("Notes")); |
871 | |
872 | notebook_append_page(notebook, |
873 | goto_cache(cache_context), _("Goto")); |
874 | } |
875 | |
876 | g_signal_connect(notebook_object(notebook), "switch-page", |
877 | G_CALLBACK(on_notebook_page_change), cache_context); |
878 | |
879 | g_signal_connect(notebook_object(notebook), "destroy", |
880 | G_CALLBACK(on_notebook_destroy), cache_context); |
881 | |
882 | return notebook; |
883 | } |
884 | |
885 | #ifndef USE_MAEMO |
886 | void cache_dialog(appdata_t *appdata, cache_t *cache) { |
887 | GtkWidget *dialog = gtk_dialog_new_with_buttons(cache->name, |
888 | GTK_WINDOW(appdata->window), |
889 | GTK_DIALOG_NO_SEPARATOR | GTK_DIALOG_MODAL | |
890 | GTK_DIALOG_DESTROY_WITH_PARENT, |
891 | GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE, |
892 | NULL); |
893 | |
894 | gtk_window_set_default_size(GTK_WINDOW(dialog), DIALOG_WIDTH, DIALOG_HEIGHT); |
895 | |
896 | /* create cache visualization widget */ |
897 | gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), |
898 | cache_view(appdata, cache)); |
899 | |
900 | gtk_widget_show_all(dialog); |
901 | gtk_dialog_run(GTK_DIALOG(dialog)); |
902 | gtk_widget_destroy(dialog); |
903 | } |
904 | |
905 | #else |
906 | #ifdef USE_STACKABLE_WINDOW |
907 | |
908 | #if !defined(__i386__) |
909 | /* get access to zoom buttons */ |
910 | static void |
911 | on_window_realize(GtkWidget *widget, gpointer data) { |
912 | if (widget->window) { |
913 | unsigned char value = 1; |
914 | Atom hildon_zoom_key_atom = |
915 | gdk_x11_get_xatom_by_name("_HILDON_ZOOM_KEY_ATOM"), |
916 | integer_atom = gdk_x11_get_xatom_by_name("INTEGER"); |
917 | Display *dpy = |
918 | GDK_DISPLAY_XDISPLAY(gdk_drawable_get_display(widget->window)); |
919 | Window w = GDK_WINDOW_XID(widget->window); |
920 | |
921 | XChangeProperty(dpy, w, hildon_zoom_key_atom, |
922 | integer_atom, 8, PropModeReplace, &value, 1); |
923 | } |
924 | } |
925 | #endif |
926 | |
927 | static void on_cache_destroy (GtkWidget *widget, appdata_t *appdata) { |
928 | appdata->cur_cache = NULL; |
929 | |
930 | HildonWindowStack *stack = hildon_window_stack_get_default(); |
931 | appdata->window = HILDON_WINDOW(hildon_window_stack_peek(stack)); |
932 | |
933 | /* restore cur_view */ |
934 | appdata->cur_view = g_object_get_data(G_OBJECT(widget), "cur_view"); |
935 | } |
936 | |
937 | void cache_dialog(appdata_t *appdata, cache_t *cache) { |
938 | GtkWidget *window = hildon_stackable_window_new(); |
939 | appdata->window = HILDON_WINDOW(window); |
940 | |
941 | #if !defined(__i386__) |
942 | g_signal_connect(G_OBJECT(appdata->window), "realize", |
943 | G_CALLBACK(on_window_realize), NULL); |
944 | #endif |
945 | |
946 | g_signal_connect(G_OBJECT(appdata->window), "key_press_event", |
947 | G_CALLBACK(on_window_key_press), appdata); |
948 | |
949 | /* store last "cur_view" in window */ |
950 | g_object_set_data(G_OBJECT(window), "cur_view", appdata->cur_view); |
951 | |
952 | appdata->cur_cache = cache; |
953 | gtk_window_set_title(GTK_WINDOW(window), cache->name); |
954 | |
955 | /* make sure window can control gps */ |
956 | g_signal_connect(G_OBJECT(window), "focus-in-event", |
957 | G_CALLBACK(on_main_focus_change), appdata); |
958 | |
959 | g_signal_connect(G_OBJECT(window), "focus-out-event", |
960 | G_CALLBACK(on_main_focus_change), appdata); |
961 | |
962 | /* create cache visualization widget */ |
963 | appdata->cur_view = cache_view(appdata, cache); |
964 | gtk_container_add(GTK_CONTAINER(window), appdata->cur_view); |
965 | |
966 | hildon_window_set_app_menu(HILDON_WINDOW(window), |
967 | menu_create(appdata, MENU_CACHE)); |
968 | |
969 | g_signal_connect(G_OBJECT(window), "destroy", |
970 | G_CALLBACK(on_cache_destroy), appdata); |
971 | |
972 | gtk_widget_show_all(window); |
973 | } |
974 | #endif // USE_STACKABLE_WINDOW |
975 | |
976 | #endif // USE_MAEMO |