Parent Directory | Revision Log
New about dialog
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 | GtkWidget *ihbox = gtk_hbox_new(FALSE, 0); | ||
189 | harbaum | 214 | |
190 | harbaum | 187 | /* vbox containing leftmost column (icon and container) */ |
191 | colbox = gtk_vbox_new(FALSE, 0); | ||
192 | harbaum | 214 | |
193 | harbaum | 1 | if(cache->type != CACHE_TYPE_UNKNOWN) { |
194 | harbaum | 187 | gtk_box_pack_start_defaults(GTK_BOX(colbox), |
195 | harbaum | 214 | tip = icon_get_widget(ICON_SIZE, cache->type)); |
196 | |||
197 | harbaum | 1 | #ifndef USE_MAEMO |
198 | gtk_tooltips_set_tip(tips, tip, _(cache_type_tip[cache->type]), NULL); | ||
199 | #endif | ||
200 | } | ||
201 | harbaum | 214 | |
202 | harbaum | 1 | /* ------------ box containing container info ------------ */ |
203 | if(cache->container != CACHE_CONT_UNKNOWN) { | ||
204 | ivbox = gtk_vbox_new(FALSE, 0); | ||
205 | sprintf(str, _("Size: %s"), _(cache_size_name[cache->container])); | ||
206 | harbaum | 137 | gtk_box_pack_start(GTK_BOX(ivbox), GTK_LABEL_SMALL(str), |
207 | FALSE, FALSE, 0); | ||
208 | gtk_box_pack_start(GTK_BOX(ivbox), | ||
209 | icon_get_widget(ICON_CACHE_SIZE, cache->container), | ||
210 | FALSE, FALSE, 0); | ||
211 | harbaum | 214 | |
212 | harbaum | 187 | pack_vcentered(colbox, ivbox); |
213 | harbaum | 1 | #ifndef USE_MAEMO |
214 | gtk_tooltips_set_tip(tips, ivbox, _(cache_size_tip[cache->container]), NULL); | ||
215 | #endif | ||
216 | } | ||
217 | harbaum | 214 | |
218 | harbaum | 187 | gtk_box_pack_start_defaults(GTK_BOX(ihbox), colbox); |
219 | colbox = gtk_vbox_new(FALSE, 0); | ||
220 | harbaum | 214 | |
221 | harbaum | 1 | /* ----------------------- id ---------------------------- */ |
222 | if(cache->id) { | ||
223 | int strike = cache->archived?STRIKETHROUGH_RED: | ||
224 | (!cache->available?STRIKETHROUGH:STRIKETHROUGH_NONE); | ||
225 | harbaum | 137 | GtkWidget *lbl = link_button_attrib(context->appdata, |
226 | cache->id, context->cache->url, | ||
227 | SIZE_BIG, strike); | ||
228 | harbaum | 187 | pack_vcentered(colbox, lbl); |
229 | harbaum | 1 | } |
230 | |||
231 | /* --------------- box containing owner info ------------- */ | ||
232 | if(cache->owner) { | ||
233 | harbaum | 187 | gtk_box_pack_start_defaults(GTK_BOX(colbox), GTK_LABEL_SMALL(_("by"))); |
234 | harbaum | 137 | |
235 | static const char *owner_type = "profile/"; | ||
236 | harbaum | 187 | pack_vcentered(colbox, |
237 | harbaum | 137 | link_button_by_id(appdata, cache->owner->name, |
238 | owner_type, cache->owner->id)); | ||
239 | harbaum | 1 | } |
240 | |||
241 | harbaum | 187 | gtk_box_pack_start_defaults(GTK_BOX(ihbox), colbox); |
242 | |||
243 | harbaum | 156 | /* ----------- vbox containing all ratings ---------- */ |
244 | harbaum | 187 | colbox = gtk_vbox_new(FALSE, 0); |
245 | harbaum | 156 | |
246 | harbaum | 1 | /* ----------- box containing difficulty rating ---------- */ |
247 | if(cache->difficulty != 0) { | ||
248 | ivbox = gtk_vbox_new(FALSE, 0); | ||
249 | harbaum | 137 | gtk_box_pack_start(GTK_BOX(ivbox), |
250 | GTK_LABEL_SMALL(_("Difficulty:")), | ||
251 | FALSE, FALSE, 0); | ||
252 | gtk_box_pack_start(GTK_BOX(ivbox), | ||
253 | icon_get_widget(ICON_STARS, (int)(cache->difficulty*2-2)), | ||
254 | FALSE, FALSE, 0); | ||
255 | harbaum | 156 | |
256 | harbaum | 187 | pack_vcentered(colbox, ivbox); |
257 | harbaum | 1 | #ifndef USE_MAEMO |
258 | sprintf(str, _("Difficulty: %.1f"), cache->difficulty); | ||
259 | gtk_tooltips_set_tip(tips, ivbox, str, NULL); | ||
260 | #endif | ||
261 | } | ||
262 | |||
263 | /* ------------ box containing terrain rating ------------ */ | ||
264 | if(cache->terrain != 0) { | ||
265 | ivbox = gtk_vbox_new(FALSE, 0); | ||
266 | harbaum | 137 | gtk_box_pack_start(GTK_BOX(ivbox), GTK_LABEL_SMALL(_("Terrain:")), |
267 | FALSE, FALSE, 0); | ||
268 | gtk_box_pack_start(GTK_BOX(ivbox), | ||
269 | icon_get_widget(ICON_STARS, (int)(cache->terrain*2-2)), | ||
270 | FALSE, FALSE, 0); | ||
271 | harbaum | 187 | pack_vcentered(colbox, ivbox); |
272 | harbaum | 1 | #ifndef USE_MAEMO |
273 | sprintf(str, _("Terrain: %.1f"), cache->terrain); | ||
274 | gtk_tooltips_set_tip(tips, ivbox, str, NULL); | ||
275 | #endif | ||
276 | } | ||
277 | |||
278 | harbaum | 156 | /* --------------------- GCVote ------------------------ */ |
279 | harbaum | 167 | if(!appdata->disable_gcvote) { |
280 | vote_t *vote = gcvote_restore(appdata, cache); | ||
281 | harbaum | 160 | |
282 | harbaum | 167 | context->gcvote_request = |
283 | gcvote_request(appdata, gcvote_callback, cache->url, context); | ||
284 | harbaum | 156 | |
285 | harbaum | 167 | context->votebox = gtk_vbox_new(FALSE, 0); |
286 | harbaum | 187 | pack_vcentered(colbox, context->votebox); |
287 | harbaum | 156 | |
288 | harbaum | 167 | /* fill with vote if present on disk (will also free vote) */ |
289 | if(vote) | ||
290 | gcvote_set(context, vote); | ||
291 | } | ||
292 | harbaum | 156 | |
293 | harbaum | 187 | gtk_box_pack_start_defaults(GTK_BOX(ihbox), colbox); |
294 | harbaum | 180 | |
295 | harbaum | 156 | /* ----------------------------------------------------- */ |
296 | |||
297 | |||
298 | harbaum | 1 | /* ----------------- the two coordinates ----------------- */ |
299 | /* ----------------- and the heading/distance ------------ */ | ||
300 | harbaum | 187 | colbox = gtk_vbox_new(FALSE, 0); |
301 | |||
302 | harbaum | 1 | pos_t *refpos = get_pos(appdata); |
303 | |||
304 | ivbox = gtk_vbox_new(FALSE, 0); | ||
305 | int strike = (cache->notes && cache->notes->override)? | ||
306 | STRIKETHROUGH:STRIKETHROUGH_NONE; | ||
307 | |||
308 | /* the original coordinate is being displayed */ | ||
309 | harbaum | 187 | gtk_box_pack_start(GTK_BOX(ivbox), |
310 | context->pos_lat_label = pos_lat(cache->pos.lat, SIZE_BIG, strike), FALSE, FALSE, 0); | ||
311 | gtk_box_pack_start(GTK_BOX(ivbox), | ||
312 | context->pos_lon_label = pos_lon(cache->pos.lon, SIZE_BIG, strike), FALSE, FALSE, 0); | ||
313 | harbaum | 1 | |
314 | harbaum | 187 | pack_vcentered(colbox, ivbox); |
315 | |||
316 | harbaum | 1 | /* but calculations may be done with respect to the overriden one */ |
317 | harbaum | 13 | if(!isnan(cache->pos.lat) && !isnan(cache->pos.lon)) { |
318 | context->bearing_hbox = gtk_hbox_new(FALSE, 0); | ||
319 | bearing_fill_hbox(context->bearing_hbox, appdata, *refpos, | ||
320 | gpx_cache_pos(cache)); | ||
321 | harbaum | 187 | pack_vcentered(colbox, context->bearing_hbox); |
322 | harbaum | 13 | } |
323 | harbaum | 1 | |
324 | harbaum | 187 | gtk_box_pack_start_defaults(GTK_BOX(ihbox), colbox); |
325 | harbaum | 1 | |
326 | harbaum | 157 | /* ----------------------------------------------------- */ |
327 | |||
328 | harbaum | 187 | gtk_box_pack_start(GTK_BOX(vbox), ihbox, FALSE, FALSE, 0); |
329 | gtk_box_pack_start(GTK_BOX(vbox), gtk_hseparator_new(), FALSE, FALSE, 0); | ||
330 | harbaum | 1 | |
331 | harbaum | 156 | /* ----------------------------------------------------- */ |
332 | |||
333 | harbaum | 1 | if(cache->short_description) |
334 | gtk_box_pack_start_defaults(GTK_BOX(vbox), | ||
335 | html_view(appdata, cache->short_description, | ||
336 | harbaum | 140 | cache->short_is_html?HTML_HTML:HTML_PLAIN_TEXT, TRUE, cache, NULL)); |
337 | harbaum | 1 | |
338 | return vbox; | ||
339 | } | ||
340 | |||
341 | /* slow but short, we don't need performance here ... */ | ||
342 | static void rot13(char *t) { | ||
343 | harbaum | 55 | int braces = 0; |
344 | |||
345 | harbaum | 1 | while(*t) { |
346 | harbaum | 55 | if(!braces) { |
347 | if(*t == '[') | ||
348 | braces++; | ||
349 | else if(((*t >= 'a') && (*t < 'n')) || | ||
350 | ((*t >= 'A') && (*t < 'N'))) *t += 13; | ||
351 | else if(((*t >= 'n') && (*t <= 'z')) || | ||
352 | ((*t >= 'N') && (*t <= 'Z'))) *t -= 13; | ||
353 | } else { | ||
354 | if(braces > 0 && *t == ']') | ||
355 | braces--; | ||
356 | } | ||
357 | harbaum | 1 | |
358 | t++; | ||
359 | } | ||
360 | } | ||
361 | |||
362 | static void on_decrypt(GtkWidget *widget, gpointer data) { | ||
363 | /* data is a link to the textview */ | ||
364 | g_assert(GTK_IS_TEXT_VIEW(data)); | ||
365 | |||
366 | GtkTextIter start, end; | ||
367 | GtkTextBuffer *buffer = gtk_text_view_get_buffer((GtkTextView*)data); | ||
368 | |||
369 | gtk_text_buffer_get_start_iter(buffer, &start); | ||
370 | gtk_text_buffer_get_end_iter(buffer, &end); | ||
371 | char *text = gtk_text_buffer_get_text(buffer, &start, &end, FALSE); | ||
372 | |||
373 | rot13(text); | ||
374 | gtk_text_buffer_set_text(buffer, text, -1); | ||
375 | |||
376 | free(text); | ||
377 | } | ||
378 | |||
379 | static GtkWidget *cache_hint(appdata_t *appdata, cache_t *cache) { | ||
380 | /* encrypting/decrypting html is nothing we want to do */ | ||
381 | if(cache->hint_is_html) | ||
382 | harbaum | 140 | return html_view(appdata, cache->hint, HTML_HTML, TRUE, NULL, NULL); |
383 | harbaum | 1 | |
384 | /* we can now be sure that we are talking about pain text */ | ||
385 | GtkWidget *vbox = gtk_vbox_new(FALSE, 0); | ||
386 | |||
387 | char *hint = strdup(cache->hint); | ||
388 | rot13(hint); | ||
389 | harbaum | 140 | GtkWidget *view = |
390 | html_view(appdata, hint, HTML_PLAIN_TEXT, TRUE, NULL, NULL); | ||
391 | harbaum | 1 | gtk_box_pack_start_defaults(GTK_BOX(vbox), view); |
392 | free(hint); | ||
393 | |||
394 | GtkWidget *button = gtk_button_new_with_label(_("Encrypt/Decrypt")); | ||
395 | harbaum | 66 | #if defined(USE_MAEMO) && (MAEMO_VERSION_MAJOR == 5) |
396 | hildon_gtk_widget_set_theme_size(button, | ||
397 | (HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH)); | ||
398 | #endif | ||
399 | harbaum | 1 | gtk_box_pack_start(GTK_BOX(vbox), button, FALSE, FALSE, 0); |
400 | gtk_signal_connect(GTK_OBJECT(button), "clicked", | ||
401 | GTK_SIGNAL_FUNC(on_decrypt), gtk_bin_get_child(GTK_BIN(view))); | ||
402 | |||
403 | return vbox; | ||
404 | } | ||
405 | |||
406 | static GtkWidget *cache_wpts(appdata_t *appdata, wpt_t *wpt) { | ||
407 | pos_t *refpos = NULL; | ||
408 | |||
409 | #ifndef USE_PANNABLE_AREA | ||
410 | GtkWidget *scrolled_window = gtk_scrolled_window_new(NULL, NULL); | ||
411 | gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_window), | ||
412 | GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); | ||
413 | #else | ||
414 | GtkWidget *pannable_area = hildon_pannable_area_new(); | ||
415 | #endif | ||
416 | |||
417 | GtkWidget *vbox = gtk_vbox_new(FALSE, 0); | ||
418 | |||
419 | /* four rows per waypoint */ | ||
420 | GtkWidget *table = gtk_table_new(4*gpx_number_of_waypoints(wpt)-1,4, FALSE); | ||
421 | |||
422 | refpos = get_pos(appdata); | ||
423 | |||
424 | int wpt_row=0; | ||
425 | while(wpt) { | ||
426 | GtkWidget *ihbox, *tip; | ||
427 | char str[32]; | ||
428 | |||
429 | /* ----------------------- icon/id ---------------------------- */ | ||
430 | ihbox = gtk_hbox_new(FALSE, 0); | ||
431 | |||
432 | if(wpt->sym != WPT_SYM_UNKNOWN) { | ||
433 | gtk_box_pack_start(GTK_BOX(ihbox), | ||
434 | tip = icon_get_widget(ICON_WPT, wpt->sym), 1,0,0); | ||
435 | } | ||
436 | |||
437 | if(wpt->id) | ||
438 | gtk_box_pack_start(GTK_BOX(ihbox), GTK_LABEL_BIG(wpt->id), 1,0,0); | ||
439 | |||
440 | gtk_table_attach_defaults(GTK_TABLE(table), ihbox, 0,1,wpt_row, wpt_row+1); | ||
441 | |||
442 | /* ----------------- the two coordinates ----------------- */ | ||
443 | /* ----------------- and the heading/distance ------------ */ | ||
444 | gtk_table_attach_defaults(GTK_TABLE(table), | ||
445 | pos_lat(wpt->pos.lat, SIZE_BIG, STRIKETHROUGH_NONE), | ||
446 | 1,2, wpt_row, wpt_row+1); | ||
447 | gtk_table_attach_defaults(GTK_TABLE(table), | ||
448 | pos_lon(wpt->pos.lon, SIZE_BIG, STRIKETHROUGH_NONE), | ||
449 | 2,3, wpt_row, wpt_row+1); | ||
450 | |||
451 | harbaum | 185 | if(refpos && !isnan(refpos->lat) && !isnan(refpos->lon)) { |
452 | ihbox = gtk_hbox_new(FALSE, 0); | ||
453 | gtk_box_pack_start(GTK_BOX(ihbox), gtk_image_new_from_pixbuf( | ||
454 | harbaum | 1 | icon_bearing(*refpos, wpt->pos)),1,0,0); |
455 | harbaum | 185 | snprintf(str, sizeof(str), _("%.1f°"), |
456 | gpx_pos_get_bearing(*refpos, wpt->pos)); | ||
457 | gtk_box_pack_start_defaults(GTK_BOX(ihbox), GTK_LABEL_SMALL(str)); | ||
458 | harbaum | 1 | |
459 | harbaum | 185 | gpx_pos_get_distance_str(str, sizeof(str), |
460 | *refpos, wpt->pos, appdata->imperial); | ||
461 | gtk_box_pack_start(GTK_BOX(ihbox), GTK_LABEL_SMALL(str),1,0,0); | ||
462 | |||
463 | gtk_table_attach_defaults(GTK_TABLE(table), ihbox, 3,4, | ||
464 | wpt_row+0, wpt_row+1); | ||
465 | } | ||
466 | |||
467 | harbaum | 1 | /* ------------------ description ------------------------- */ |
468 | harbaum | 165 | if(wpt->desc) |
469 | gtk_table_attach_defaults(GTK_TABLE(table), | ||
470 | simple_text_widget(wpt->desc), 0,4, | ||
471 | harbaum | 1 | wpt_row+1, wpt_row+2); |
472 | |||
473 | /* ------------------ comment ------------------------- */ | ||
474 | harbaum | 165 | if(wpt->cmt) |
475 | gtk_table_attach_defaults(GTK_TABLE(table), | ||
476 | simple_text_widget(wpt->cmt), 0,4, | ||
477 | harbaum | 1 | wpt_row+2, wpt_row+3); |
478 | |||
479 | /* --------------------- seperator -------------------------*/ | ||
480 | harbaum | 165 | if(wpt->next) { |
481 | gtk_table_set_row_spacing(GTK_TABLE(table), wpt_row+2, 8); | ||
482 | harbaum | 1 | gtk_table_attach_defaults(GTK_TABLE(table), gtk_hseparator_new(), 0,4, |
483 | wpt_row+3, wpt_row+4); | ||
484 | harbaum | 165 | gtk_table_set_row_spacing(GTK_TABLE(table), wpt_row+3, 8); |
485 | } | ||
486 | harbaum | 1 | |
487 | wpt_row+=4; | ||
488 | wpt = wpt->next; | ||
489 | } | ||
490 | |||
491 | gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0); | ||
492 | |||
493 | #ifndef USE_PANNABLE_AREA | ||
494 | gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scrolled_window), | ||
495 | vbox); | ||
496 | return scrolled_window; | ||
497 | #else | ||
498 | hildon_pannable_area_add_with_viewport(HILDON_PANNABLE_AREA(pannable_area), | ||
499 | vbox); | ||
500 | return pannable_area; | ||
501 | #endif | ||
502 | } | ||
503 | |||
504 | static GtkWidget *cache_tbs(appdata_t *appdata, tb_t *tb) { | ||
505 | pos_t *refpos = NULL; | ||
506 | |||
507 | #ifndef USE_PANNABLE_AREA | ||
508 | GtkWidget *scrolled_window = gtk_scrolled_window_new(NULL, NULL); | ||
509 | gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_window), | ||
510 | GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); | ||
511 | #else | ||
512 | GtkWidget *pannable_area = hildon_pannable_area_new(); | ||
513 | #endif | ||
514 | |||
515 | GtkWidget *vbox = gtk_vbox_new(FALSE, 0); | ||
516 | |||
517 | /* four rows per waypoint */ | ||
518 | GtkWidget *table = gtk_table_new(2*gpx_number_of_tbs(tb)-1,3, FALSE); | ||
519 | |||
520 | refpos = get_pos(appdata); | ||
521 | |||
522 | int tb_row=0; | ||
523 | while(tb) { | ||
524 | harbaum | 137 | static const char *tb_type = "track/details.aspx"; |
525 | |||
526 | harbaum | 1 | /* --------------------- icon/ref/name -------------------------*/ |
527 | harbaum | 178 | GtkWidget *icon = NULL; |
528 | harbaum | 179 | if((strcasestr(tb->name, "coin") != 0) || |
529 | (strcasestr(tb->name, "muenze") != 0) || | ||
530 | (strcasestr(tb->name, "münze") != 0)) | ||
531 | harbaum | 178 | icon = icon_get_widget(ICON_TB, 1); /* coin icon */ |
532 | else | ||
533 | icon = icon_get_widget(ICON_TB, 0); /* tb icon */ | ||
534 | |||
535 | gtk_table_attach_defaults(GTK_TABLE(table), icon, | ||
536 | harbaum | 1 | 0, 1, tb_row+0, tb_row+1); |
537 | harbaum | 133 | |
538 | if(tb->ref) { | ||
539 | harbaum | 137 | GtkWidget *ref = link_button_by_id(appdata, tb->ref, tb_type, tb->id); |
540 | harbaum | 133 | gtk_table_attach_defaults(GTK_TABLE(table), ref, |
541 | harbaum | 1 | 1, 2, tb_row+0, tb_row+1); |
542 | harbaum | 133 | } |
543 | |||
544 | harbaum | 1 | if(tb->name) |
545 | gtk_table_attach_defaults(GTK_TABLE(table), GTK_LABEL_BIG(tb->name), | ||
546 | 2, 3, tb_row+0, tb_row+1); | ||
547 | |||
548 | /* --------------------- seperator -------------------------*/ | ||
549 | if(tb->next) | ||
550 | gtk_table_attach_defaults(GTK_TABLE(table), gtk_hseparator_new(), 0, 3, | ||
551 | tb_row+1, tb_row+2); | ||
552 | tb_row+=2; | ||
553 | tb = tb->next; | ||
554 | } | ||
555 | |||
556 | gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0); | ||
557 | |||
558 | #ifndef USE_PANNABLE_AREA | ||
559 | gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scrolled_window), | ||
560 | vbox); | ||
561 | return scrolled_window; | ||
562 | #else | ||
563 | hildon_pannable_area_add_with_viewport(HILDON_PANNABLE_AREA(pannable_area), | ||
564 | vbox); | ||
565 | return pannable_area; | ||
566 | #endif | ||
567 | } | ||
568 | |||
569 | harbaum | 66 | #ifdef ENABLE_BROWSER_INTERFACE |
570 | static void on_gclink_clicked(GtkButton *button, gpointer data) { | ||
571 | cache_context_t *context = (cache_context_t*)data; | ||
572 | char *url = g_strdup_printf("http://www.geocaching.com/seek/log.aspx?wp=%s", context->cache->id); | ||
573 | browser_url(context->appdata, url); | ||
574 | g_free(url); | ||
575 | } | ||
576 | #endif | ||
577 | |||
578 | harbaum | 165 | static GtkWidget *cache_logs(appdata_t *appdata, cache_context_t *context, |
579 | log_t *log, int is_html) { | ||
580 | harbaum | 1 | #ifndef USE_PANNABLE_AREA |
581 | /* put this inside a scrolled view */ | ||
582 | GtkWidget *scrolled_window = gtk_scrolled_window_new(NULL, NULL); | ||
583 | gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_window), | ||
584 | GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); | ||
585 | #else | ||
586 | GtkWidget *pannable_area = hildon_pannable_area_new(); | ||
587 | #endif | ||
588 | |||
589 | harbaum | 66 | #ifdef ENABLE_BROWSER_INTERFACE |
590 | gboolean gc_link = strncmp(context->cache->id, "GC", 2) == 0; | ||
591 | #else | ||
592 | #define gc_link (FALSE) | ||
593 | #endif | ||
594 | |||
595 | harbaum | 163 | GtkWidget *vbox = gtk_vbox_new(FALSE, 6); |
596 | harbaum | 66 | |
597 | #ifdef ENABLE_BROWSER_INTERFACE | ||
598 | if(gc_link) { | ||
599 | harbaum | 199 | GtkWidget *but = |
600 | harbaum | 165 | gtk_button_new_with_label(_("Post a new log entry for this geocache")); |
601 | harbaum | 199 | #if 0 |
602 | gtk_button_set_image(GTK_BUTTON(but), | ||
603 | gtk_image_new_from_stock(GTK_STOCK_ADD, GTK_ICON_SIZE_BUTTON)); | ||
604 | gtk_button_set_image_position(GTK_BUTTON(but), GTK_POS_LEFT); | ||
605 | #endif | ||
606 | harbaum | 66 | #if defined(USE_MAEMO) && (MAEMO_VERSION_MAJOR == 5) |
607 | hildon_gtk_widget_set_theme_size(but, | ||
608 | (HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH)); | ||
609 | #endif | ||
610 | gtk_signal_connect(GTK_OBJECT(but), "clicked", | ||
611 | GTK_SIGNAL_FUNC(on_gclink_clicked), context); | ||
612 | |||
613 | harbaum | 184 | gtk_box_pack_start(GTK_BOX(vbox), but, FALSE, FALSE, 0); |
614 | harbaum | 66 | } |
615 | #endif | ||
616 | harbaum | 165 | |
617 | int logs = gpx_number_of_logs(log); | ||
618 | GtkWidget *table = gtk_table_new(2*logs-1, 2,FALSE); | ||
619 | int log_cnt = 0; | ||
620 | |||
621 | gtk_table_set_col_spacing(GTK_TABLE(table), 0, 8); | ||
622 | harbaum | 1 | |
623 | /* add all logs to the vbox */ | ||
624 | while(log) { | ||
625 | harbaum | 165 | GtkWidget *ivbox = gtk_vbox_new(FALSE, 2); |
626 | GtkWidget *ihbox = gtk_hbox_new(FALSE, 2); | ||
627 | harbaum | 1 | |
628 | harbaum | 165 | static const char *finder_type = "profile/"; |
629 | GtkWidget *finder = link_button_by_id(appdata, log->finder->name, | ||
630 | finder_type, log->finder->id); | ||
631 | harbaum | 163 | |
632 | harbaum | 165 | /* if the finder is a button make sure it's the right size and */ |
633 | /* does not exceed the size limits */ | ||
634 | if(GTK_WIDGET_TYPE(finder) == GTK_TYPE_BUTTON) { | ||
635 | #if defined(USE_MAEMO) && (MAEMO_VERSION_MAJOR == 5) | ||
636 | hildon_gtk_widget_set_theme_size(finder, | ||
637 | (HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH)); | ||
638 | #endif | ||
639 | harbaum | 163 | |
640 | harbaum | 214 | gtk_label_set_ellipsize(GTK_LABEL(gtk_bin_get_child(GTK_BIN(finder))), |
641 | harbaum | 165 | PANGO_ELLIPSIZE_END); |
642 | } else | ||
643 | gtk_label_set_ellipsize(GTK_LABEL(finder), PANGO_ELLIPSIZE_END); | ||
644 | harbaum | 163 | |
645 | harbaum | 165 | gtk_box_pack_start(GTK_BOX(ivbox), finder, FALSE, FALSE, 0); |
646 | |||
647 | harbaum | 163 | gtk_box_pack_start_defaults(GTK_BOX(ihbox), |
648 | icon_get_widget(ICON_LOG, log->type)); | ||
649 | |||
650 | harbaum | 1 | char date_str[32]; |
651 | if(log->day && log->month && log->year) { | ||
652 | GDate *date = g_date_new_dmy(log->day, log->month, log->year); | ||
653 | g_date_strftime(date_str, sizeof(date_str), "%x", date); | ||
654 | g_date_free(date); | ||
655 | } else | ||
656 | strcpy(date_str, "---"); | ||
657 | |||
658 | harbaum | 163 | gtk_box_pack_start_defaults(GTK_BOX(ihbox), gtk_label_new(date_str)); |
659 | harbaum | 1 | |
660 | harbaum | 165 | gtk_box_pack_start(GTK_BOX(ivbox), ihbox, FALSE, FALSE, 0); |
661 | harbaum | 137 | |
662 | harbaum | 184 | gtk_table_attach(GTK_TABLE(table), ivbox, 0, 1, |
663 | 2*log_cnt, 2*log_cnt+1, 0, GTK_EXPAND | GTK_FILL, 0, 0); | ||
664 | |||
665 | harbaum | 1 | if(log->text) { |
666 | harbaum | 165 | gtk_table_attach_defaults(GTK_TABLE(table), |
667 | harbaum | 140 | html_view(appdata, log->text, |
668 | harbaum | 165 | is_html?HTML_HTML:HTML_CUSTOM_MARKUP, FALSE, NULL, NULL), |
669 | 1, 2, 2*log_cnt, 2*log_cnt+1); | ||
670 | harbaum | 1 | } |
671 | harbaum | 163 | |
672 | harbaum | 165 | if(log_cnt < logs-1) { |
673 | gtk_table_set_row_spacing(GTK_TABLE(table), 2*log_cnt, 8); | ||
674 | |||
675 | gtk_table_attach_defaults(GTK_TABLE(table), gtk_hseparator_new(), | ||
676 | 0, 2, 2*log_cnt+1, 2*log_cnt+2); | ||
677 | |||
678 | gtk_table_set_row_spacing(GTK_TABLE(table), 2*log_cnt+1, 8); | ||
679 | } | ||
680 | |||
681 | harbaum | 1 | log = log->next; |
682 | harbaum | 165 | log_cnt++; |
683 | harbaum | 1 | } |
684 | |||
685 | harbaum | 184 | gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0); |
686 | harbaum | 165 | |
687 | harbaum | 1 | #ifndef USE_PANNABLE_AREA |
688 | gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scrolled_window), | ||
689 | harbaum | 163 | vbox); |
690 | harbaum | 1 | return scrolled_window; |
691 | #else | ||
692 | hildon_pannable_area_add_with_viewport(HILDON_PANNABLE_AREA(pannable_area), | ||
693 | harbaum | 163 | vbox); |
694 | harbaum | 1 | return pannable_area; |
695 | #endif | ||
696 | } | ||
697 | |||
698 | #ifdef USE_MAEMO | ||
699 | /* this routine is called once a second as long as the "goto" tab is visible */ | ||
700 | static gboolean screensaver_update(gpointer data) { | ||
701 | appdata_t *appdata = (appdata_t*)data; | ||
702 | |||
703 | if(appdata->goto_disable_screensaver) | ||
704 | if (osso_display_blanking_pause(appdata->osso_context) != OSSO_OK) | ||
705 | fprintf(stderr, "error with display blank\n"); | ||
706 | |||
707 | return TRUE; // fire again | ||
708 | } | ||
709 | #endif | ||
710 | |||
711 | static void on_notebook_page_change(GtkNotebook *notebook, | ||
712 | GtkNotebookPage *page, | ||
713 | guint page_num, | ||
714 | gpointer user_data) { | ||
715 | |||
716 | cache_context_t *context = (cache_context_t*)user_data; | ||
717 | GtkWidget *w = gtk_notebook_get_nth_page(notebook, page_num); | ||
718 | const char *name = gtk_notebook_get_tab_label_text(notebook, w); | ||
719 | |||
720 | #ifdef USE_MAEMO | ||
721 | if(context->handler_id) | ||
722 | gtk_timeout_remove(context->handler_id); | ||
723 | #endif | ||
724 | |||
725 | /* this is a workaround, around some bug in the gtktextwidget or so ... */ | ||
726 | /* i tried to get info on this and everybody agreed that this is a bug */ | ||
727 | harbaum | 136 | /* in gtk but noone had a fix ready. so i came up with this. */ |
728 | harbaum | 1 | /* seems to work ... */ |
729 | if(strcasecmp(name, _("Logs")) == 0) { | ||
730 | gtk_widget_queue_resize(w); | ||
731 | harbaum | 136 | } else if(strcasecmp(name, _("Goto")) == 0) { |
732 | harbaum | 1 | #ifdef USE_MAEMO |
733 | context->handler_id = gtk_timeout_add(1000, screensaver_update, | ||
734 | context->appdata); | ||
735 | #endif | ||
736 | harbaum | 214 | |
737 | harbaum | 1 | goto_coordinate_update(context); |
738 | } | ||
739 | |||
740 | if(strcasecmp(name, _("Main")) == 0) { | ||
741 | /* the notes page may have changed its "override" setting, thus the */ | ||
742 | /* striked out coordinate may need update */ | ||
743 | overview_coordinate_update(context); | ||
744 | } | ||
745 | } | ||
746 | |||
747 | static void on_notebook_destroy(GtkWidget *widget, gpointer user_data ) { | ||
748 | cache_context_t *context = (cache_context_t*)user_data; | ||
749 | |||
750 | printf("destroying notebook\n"); | ||
751 | |||
752 | harbaum | 159 | /* cancel a pending gcvote request */ |
753 | if(context->gcvote_request) { | ||
754 | gcvote_request_free(context->gcvote_request); | ||
755 | context->gcvote_request = NULL; | ||
756 | } | ||
757 | |||
758 | harbaum | 1 | notes_destroy_event(NULL, context); |
759 | goto_destroy_event(NULL, context); | ||
760 | |||
761 | #ifdef USE_MAEMO | ||
762 | if(context->handler_id) | ||
763 | gtk_timeout_remove(context->handler_id); | ||
764 | #endif | ||
765 | |||
766 | harbaum | 228 | #ifdef USE_STACKABLE_WINDOW |
767 | if(context->notes_have_been_changed) { | ||
768 | printf("notes changed -> cachelist redraw\n"); | ||
769 | |||
770 | /* now the cachelist is visible again. so redraw it since it may */ | ||
771 | /* have changed */ | ||
772 | cachelist_redraw(context->appdata); | ||
773 | } | ||
774 | #endif | ||
775 | |||
776 | harbaum | 221 | printf("freeing cache context\n"); |
777 | harbaum | 228 | context->appdata->cache_context = NULL; |
778 | harbaum | 221 | g_free(context); |
779 | harbaum | 1 | } |
780 | |||
781 | harbaum | 168 | #if defined(USE_MAEMO) && (MAEMO_VERSION_MAJOR >= 5) |
782 | harbaum | 165 | #define CUSTOM_NOTEBOOK |
783 | #endif | ||
784 | |||
785 | static GtkWidget *notebook_new(void) { | ||
786 | #ifdef CUSTOM_NOTEBOOK | ||
787 | GtkWidget *vbox = gtk_vbox_new(FALSE, 0); | ||
788 | |||
789 | GtkWidget *notebook = gtk_notebook_new(); | ||
790 | |||
791 | /* prevents user from accidentially touching the breadcrumb trail */ | ||
792 | /* (looks ugly on fremantle as it isn't themed) */ | ||
793 | // gtk_notebook_set_tab_pos(GTK_NOTEBOOK(notebook), GTK_POS_BOTTOM); | ||
794 | |||
795 | /* solution for fremantle: we use a row of ordinary buttons instead */ | ||
796 | /* of regular tabs */ | ||
797 | |||
798 | /* hide the regular tabs */ | ||
799 | gtk_notebook_set_show_tabs(GTK_NOTEBOOK(notebook), FALSE); | ||
800 | |||
801 | gtk_box_pack_start_defaults(GTK_BOX(vbox), notebook); | ||
802 | |||
803 | /* store a reference to the notebook in the vbox */ | ||
804 | g_object_set_data(G_OBJECT(vbox), "notebook", (gpointer)notebook); | ||
805 | |||
806 | /* create a hbox for the buttons */ | ||
807 | GtkWidget *hbox = gtk_hbox_new(TRUE, 0); | ||
808 | gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); | ||
809 | g_object_set_data(G_OBJECT(vbox), "hbox", (gpointer)hbox); | ||
810 | |||
811 | return vbox; | ||
812 | #else | ||
813 | return gtk_notebook_new(); | ||
814 | #endif | ||
815 | } | ||
816 | |||
817 | harbaum | 179 | #ifdef CUSTOM_NOTEBOOK |
818 | harbaum | 165 | static void on_notebook_button_clicked(GtkWidget *button, gpointer data) { |
819 | GtkNotebook *nb = | ||
820 | GTK_NOTEBOOK(g_object_get_data(G_OBJECT(data), "notebook")); | ||
821 | |||
822 | harbaum | 167 | gint page = (gint)g_object_get_data(G_OBJECT(button), "page"); |
823 | harbaum | 165 | gtk_notebook_set_current_page(nb, page); |
824 | } | ||
825 | harbaum | 179 | #endif |
826 | harbaum | 165 | |
827 | static void notebook_append_page(GtkWidget *notebook, | ||
828 | GtkWidget *page, char *label) { | ||
829 | #ifdef CUSTOM_NOTEBOOK | ||
830 | GtkNotebook *nb = | ||
831 | GTK_NOTEBOOK(g_object_get_data(G_OBJECT(notebook), "notebook")); | ||
832 | |||
833 | gint page_num = gtk_notebook_append_page(nb, page, gtk_label_new(label)); | ||
834 | harbaum | 167 | GtkWidget *button = NULL; |
835 | harbaum | 165 | |
836 | /* select button for page 0 by default */ | ||
837 | harbaum | 167 | if(!page_num) { |
838 | button = gtk_radio_button_new_with_label(NULL, label); | ||
839 | harbaum | 165 | gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), TRUE); |
840 | harbaum | 167 | g_object_set_data(G_OBJECT(notebook), "group_master", (gpointer)button); |
841 | } else { | ||
842 | GtkWidget *master = g_object_get_data(G_OBJECT(notebook), "group_master"); | ||
843 | button = gtk_radio_button_new_with_label_from_widget( | ||
844 | GTK_RADIO_BUTTON(master), label); | ||
845 | } | ||
846 | harbaum | 165 | |
847 | harbaum | 167 | gtk_toggle_button_set_mode(GTK_TOGGLE_BUTTON(button), FALSE); |
848 | g_object_set_data(G_OBJECT(button), "page", (gpointer)page_num); | ||
849 | |||
850 | harbaum | 165 | gtk_signal_connect(GTK_OBJECT(button), "clicked", |
851 | GTK_SIGNAL_FUNC(on_notebook_button_clicked), notebook); | ||
852 | |||
853 | #if defined(USE_MAEMO) && (MAEMO_VERSION_MAJOR == 5) | ||
854 | hildon_gtk_widget_set_theme_size(button, | ||
855 | (HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH)); | ||
856 | #endif | ||
857 | |||
858 | gtk_box_pack_start_defaults( | ||
859 | GTK_BOX(g_object_get_data(G_OBJECT(notebook), "hbox")), | ||
860 | button); | ||
861 | |||
862 | #else | ||
863 | gtk_notebook_append_page(GTK_NOTEBOOK(notebook), page, gtk_label_new(label)); | ||
864 | #endif | ||
865 | } | ||
866 | |||
867 | static GObject *notebook_object(GtkWidget *notebook) { | ||
868 | #ifdef CUSTOM_NOTEBOOK | ||
869 | return G_OBJECT(g_object_get_data(G_OBJECT(notebook), "notebook")); | ||
870 | #else | ||
871 | return G_OBJECT(notebook); | ||
872 | #endif | ||
873 | } | ||
874 | |||
875 | harbaum | 1 | GtkWidget *cache_view(appdata_t *appdata, cache_t *cache) { |
876 | GtkWidget *notebook; | ||
877 | |||
878 | harbaum | 221 | cache_context_t *cache_context = g_new0(cache_context_t, 1); |
879 | harbaum | 228 | appdata->cache_context = cache_context; |
880 | harbaum | 1 | cache_context->appdata = appdata; |
881 | cache_context->cache = cache; | ||
882 | |||
883 | #ifdef USE_MAEMO | ||
884 | #define TAB_DESC _("Desc.") | ||
885 | #define TAB_WPTS _("Wpts") | ||
886 | #else | ||
887 | #define TAB_DESC _("Description") | ||
888 | #define TAB_WPTS _("Waypoints") | ||
889 | #endif | ||
890 | |||
891 | harbaum | 165 | notebook = notebook_new(); |
892 | harbaum | 133 | |
893 | harbaum | 165 | notebook_append_page(notebook, |
894 | cache_overview(cache_context), _("Main")); | ||
895 | harbaum | 1 | |
896 | if(cache->long_description) | ||
897 | harbaum | 165 | notebook_append_page(notebook, |
898 | cache_description(appdata, cache), TAB_DESC); | ||
899 | harbaum | 1 | |
900 | if(cache->hint) | ||
901 | harbaum | 165 | notebook_append_page(notebook, |
902 | cache_hint(appdata, cache), _("Hint")); | ||
903 | harbaum | 1 | |
904 | if(cache->log) | ||
905 | harbaum | 165 | notebook_append_page(notebook, |
906 | harbaum | 66 | cache_logs(appdata, cache_context, cache->log, cache->logs_are_html), |
907 | harbaum | 165 | _("Logs")); |
908 | harbaum | 1 | |
909 | if(cache->wpt) | ||
910 | harbaum | 165 | notebook_append_page(notebook, |
911 | cache_wpts(appdata, cache->wpt), TAB_WPTS); | ||
912 | harbaum | 1 | |
913 | if(cache->tb) | ||
914 | harbaum | 165 | notebook_append_page(notebook, |
915 | cache_tbs(appdata, cache->tb), _("TBs")); | ||
916 | harbaum | 1 | |
917 | harbaum | 165 | notebook_append_page(notebook, |
918 | cache_notes(cache_context), _("Notes")); | ||
919 | harbaum | 1 | |
920 | harbaum | 165 | notebook_append_page(notebook, |
921 | goto_cache(cache_context), _("Goto")); | ||
922 | harbaum | 1 | |
923 | harbaum | 165 | g_signal_connect(notebook_object(notebook), "switch-page", |
924 | harbaum | 1 | G_CALLBACK(on_notebook_page_change), cache_context); |
925 | |||
926 | harbaum | 165 | g_signal_connect(notebook_object(notebook), "destroy", |
927 | harbaum | 1 | G_CALLBACK(on_notebook_destroy), cache_context); |
928 | |||
929 | return notebook; | ||
930 | } | ||
931 | |||
932 | #ifndef USE_MAEMO | ||
933 | void cache_dialog(appdata_t *appdata, cache_t *cache) { | ||
934 | GtkWidget *dialog = gtk_dialog_new_with_buttons(cache->name, | ||
935 | GTK_WINDOW(appdata->window), | ||
936 | GTK_DIALOG_NO_SEPARATOR | GTK_DIALOG_MODAL | | ||
937 | GTK_DIALOG_DESTROY_WITH_PARENT, | ||
938 | GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE, | ||
939 | NULL); | ||
940 | |||
941 | gtk_window_set_default_size(GTK_WINDOW(dialog), DIALOG_WIDTH, DIALOG_HEIGHT); | ||
942 | |||
943 | /* create cache visualization widget */ | ||
944 | gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), | ||
945 | cache_view(appdata, cache)); | ||
946 | |||
947 | gtk_widget_show_all(dialog); | ||
948 | gtk_dialog_run(GTK_DIALOG(dialog)); | ||
949 | gtk_widget_destroy(dialog); | ||
950 | } | ||
951 | |||
952 | #else | ||
953 | #ifdef USE_STACKABLE_WINDOW | ||
954 | harbaum | 11 | static void on_cache_destroy (GtkWidget *widget, appdata_t *appdata) { |
955 | appdata->cur_cache = NULL; | ||
956 | |||
957 | harbaum | 226 | HildonWindowStack *stack = hildon_window_stack_get_default(); |
958 | appdata->window = HILDON_WINDOW(hildon_window_stack_peek(stack)); | ||
959 | |||
960 | harbaum | 11 | /* restore cur_view */ |
961 | appdata->cur_view = g_object_get_data(G_OBJECT(widget), "cur_view"); | ||
962 | } | ||
963 | |||
964 | harbaum | 1 | void cache_dialog(appdata_t *appdata, cache_t *cache) { |
965 | GtkWidget *window = hildon_stackable_window_new(); | ||
966 | harbaum | 226 | appdata->window = HILDON_WINDOW(window); |
967 | harbaum | 1 | |
968 | harbaum | 11 | /* store last "cur_view" in window */ |
969 | g_object_set_data(G_OBJECT(window), "cur_view", appdata->cur_view); | ||
970 | |||
971 | appdata->cur_cache = cache; | ||
972 | harbaum | 229 | gtk_window_set_title(GTK_WINDOW(window), cache->name); |
973 | harbaum | 1 | |
974 | /* create cache visualization widget */ | ||
975 | harbaum | 11 | appdata->cur_view = cache_view(appdata, cache); |
976 | gtk_container_add(GTK_CONTAINER(window), appdata->cur_view); | ||
977 | harbaum | 1 | |
978 | harbaum | 3 | hildon_window_set_app_menu(HILDON_WINDOW(window), |
979 | menu_create(appdata, MENU_CACHE)); | ||
980 | |||
981 | harbaum | 11 | g_signal_connect(G_OBJECT(window), "destroy", |
982 | G_CALLBACK(on_cache_destroy), appdata); | ||
983 | |||
984 | harbaum | 1 | gtk_widget_show_all(window); |
985 | } | ||
986 | #endif // USE_STACKABLE_WINDOW | ||
987 | |||
988 | #endif // USE_MAEMO |