Contents of /trunk/src/cache.c

Parent Directory Parent Directory | Revision Log Revision Log


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