Parent Directory | Revision Log
About box adjustments for diablo/chinnok
1 | harbaum | 236 | /* |
2 | * Copyright (C) 2009 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 | |||
22 | #ifndef FREMANTLE | ||
23 | #define LINK_COLOR "blue" | ||
24 | #else | ||
25 | #define LINK_COLOR "lightblue" | ||
26 | #define CUSTOM_NOTEBOOK | ||
27 | #endif | ||
28 | |||
29 | #ifdef ENABLE_BROWSER_INTERFACE | ||
30 | static gboolean on_link_clicked(GtkWidget *widget, GdkEventButton *event, | ||
31 | gpointer user_data) { | ||
32 | |||
33 | const char *str = | ||
34 | gtk_label_get_text(GTK_LABEL(gtk_bin_get_child(GTK_BIN(widget)))); | ||
35 | browser_url((appdata_t*)user_data, (char*)str); | ||
36 | return TRUE; | ||
37 | } | ||
38 | #endif | ||
39 | |||
40 | static GtkWidget *link_new(appdata_t *appdata, const char *url) { | ||
41 | #ifdef ENABLE_BROWSER_INTERFACE | ||
42 | if(appdata) { | ||
43 | GtkWidget *label = gtk_label_new(""); | ||
44 | char *str = g_strdup_printf("<span color=\"" LINK_COLOR | ||
45 | "\"><u>%s</u></span>", url); | ||
46 | gtk_label_set_markup(GTK_LABEL(label), str); | ||
47 | g_free(str); | ||
48 | |||
49 | GtkWidget *eventbox = gtk_event_box_new(); | ||
50 | gtk_container_add(GTK_CONTAINER(eventbox), label); | ||
51 | |||
52 | g_signal_connect(eventbox, "button-press-event", | ||
53 | G_CALLBACK(on_link_clicked), appdata); | ||
54 | return eventbox; | ||
55 | } | ||
56 | #endif | ||
57 | GtkWidget *label = gtk_label_new(""); | ||
58 | char *str = g_strdup_printf("<span color=\"" LINK_COLOR "\">%s</span>", url); | ||
59 | gtk_label_set_markup(GTK_LABEL(label), str); | ||
60 | g_free(str); | ||
61 | return label; | ||
62 | } | ||
63 | |||
64 | #ifdef ENABLE_BROWSER_INTERFACE | ||
65 | void on_paypal_button_clicked(GtkButton *button, appdata_t *appdata) { | ||
66 | // gtk_dialog_response(GTK_DIALOG(context->dialog), GTK_RESPONSE_ACCEPT); | ||
67 | browser_url(appdata, | ||
68 | "https://www.paypal.com/cgi-bin/webscr" | ||
69 | "?cmd=_s-xclick&hosted_button_id=7400558"); | ||
70 | } | ||
71 | #endif | ||
72 | |||
73 | static GtkWidget *notebook_new(void) { | ||
74 | #ifdef CUSTOM_NOTEBOOK | ||
75 | GtkWidget *vbox = gtk_vbox_new(FALSE, 0); | ||
76 | |||
77 | GtkWidget *notebook = gtk_notebook_new(); | ||
78 | |||
79 | /* solution for fremantle: we use a row of ordinary buttons instead */ | ||
80 | /* of regular tabs */ | ||
81 | |||
82 | /* hide the regular tabs */ | ||
83 | gtk_notebook_set_show_tabs(GTK_NOTEBOOK(notebook), FALSE); | ||
84 | |||
85 | gtk_box_pack_start_defaults(GTK_BOX(vbox), notebook); | ||
86 | |||
87 | /* store a reference to the notebook in the vbox */ | ||
88 | g_object_set_data(G_OBJECT(vbox), "notebook", (gpointer)notebook); | ||
89 | |||
90 | /* create a hbox for the buttons */ | ||
91 | GtkWidget *hbox = gtk_hbox_new(TRUE, 0); | ||
92 | gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); | ||
93 | g_object_set_data(G_OBJECT(vbox), "hbox", (gpointer)hbox); | ||
94 | |||
95 | return vbox; | ||
96 | #else | ||
97 | return gtk_notebook_new(); | ||
98 | #endif | ||
99 | } | ||
100 | |||
101 | #ifdef CUSTOM_NOTEBOOK | ||
102 | static void on_notebook_button_clicked(GtkWidget *button, gpointer data) { | ||
103 | GtkNotebook *nb = | ||
104 | GTK_NOTEBOOK(g_object_get_data(G_OBJECT(data), "notebook")); | ||
105 | |||
106 | gint page = (gint)g_object_get_data(G_OBJECT(button), "page"); | ||
107 | gtk_notebook_set_current_page(nb, page); | ||
108 | } | ||
109 | #endif | ||
110 | |||
111 | static void notebook_append_page(GtkWidget *notebook, | ||
112 | GtkWidget *page, char *label) { | ||
113 | #ifdef CUSTOM_NOTEBOOK | ||
114 | GtkNotebook *nb = | ||
115 | GTK_NOTEBOOK(g_object_get_data(G_OBJECT(notebook), "notebook")); | ||
116 | |||
117 | gint page_num = gtk_notebook_append_page(nb, page, gtk_label_new(label)); | ||
118 | GtkWidget *button = NULL; | ||
119 | |||
120 | /* select button for page 0 by default */ | ||
121 | if(!page_num) { | ||
122 | button = gtk_radio_button_new_with_label(NULL, label); | ||
123 | gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), TRUE); | ||
124 | g_object_set_data(G_OBJECT(notebook), "group_master", (gpointer)button); | ||
125 | } else { | ||
126 | GtkWidget *master = g_object_get_data(G_OBJECT(notebook), "group_master"); | ||
127 | button = gtk_radio_button_new_with_label_from_widget( | ||
128 | GTK_RADIO_BUTTON(master), label); | ||
129 | } | ||
130 | |||
131 | gtk_toggle_button_set_mode(GTK_TOGGLE_BUTTON(button), FALSE); | ||
132 | g_object_set_data(G_OBJECT(button), "page", (gpointer)page_num); | ||
133 | |||
134 | gtk_signal_connect(GTK_OBJECT(button), "clicked", | ||
135 | GTK_SIGNAL_FUNC(on_notebook_button_clicked), notebook); | ||
136 | |||
137 | #if defined(USE_MAEMO) && (MAEMO_VERSION_MAJOR == 5) | ||
138 | hildon_gtk_widget_set_theme_size(button, | ||
139 | (HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH)); | ||
140 | #endif | ||
141 | |||
142 | gtk_box_pack_start_defaults( | ||
143 | GTK_BOX(g_object_get_data(G_OBJECT(notebook), "hbox")), | ||
144 | button); | ||
145 | |||
146 | #else | ||
147 | gtk_notebook_append_page(GTK_NOTEBOOK(notebook), page, gtk_label_new(label)); | ||
148 | #endif | ||
149 | } | ||
150 | |||
151 | GtkWidget *label_big(char *str) { | ||
152 | GtkWidget *label = gtk_label_new(""); | ||
153 | char *markup = | ||
154 | g_markup_printf_escaped("<span size='x-large'>%s</span>", str); | ||
155 | gtk_label_set_markup(GTK_LABEL(label), markup); | ||
156 | g_free(markup); | ||
157 | return label; | ||
158 | } | ||
159 | |||
160 | GtkWidget *label_xbig(char *str) { | ||
161 | GtkWidget *label = gtk_label_new(""); | ||
162 | char *markup = | ||
163 | g_markup_printf_escaped("<span size='xx-large'>%s</span>", str); | ||
164 | gtk_label_set_markup(GTK_LABEL(label), markup); | ||
165 | g_free(markup); | ||
166 | return label; | ||
167 | } | ||
168 | |||
169 | GtkWidget *label_wrap(char *str) { | ||
170 | GtkWidget *label = gtk_label_new(str); | ||
171 | gtk_label_set_line_wrap_mode(GTK_LABEL(label), PANGO_WRAP_WORD); | ||
172 | gtk_label_set_line_wrap(GTK_LABEL(label), TRUE); | ||
173 | #ifdef USE_MAEMO | ||
174 | #if MAEMO_VERSION_MAJOR >= 5 | ||
175 | gtk_widget_set_size_request(label, 720, -1); | ||
176 | #else | ||
177 | gtk_widget_set_size_request(label, 640, -1); | ||
178 | #endif | ||
179 | #else | ||
180 | gtk_widget_set_size_request(label, 350, -1); | ||
181 | #endif | ||
182 | return label; | ||
183 | } | ||
184 | |||
185 | GtkWidget *license_page_new(void) { | ||
186 | char *name = g_strdup(ICONPATH "COPYING"); | ||
187 | |||
188 | GtkWidget *label = label_wrap(""); | ||
189 | |||
190 | /* load license into buffer */ | ||
191 | FILE *file = fopen(name, "r"); | ||
192 | g_free(name); | ||
193 | |||
194 | if(!file) { | ||
195 | /* loading from installation path failed, try to load */ | ||
196 | /* from local directory (for debugging) */ | ||
197 | name = g_strdup("./data/COPYING"); | ||
198 | file = fopen(name, "r"); | ||
199 | g_free(name); | ||
200 | } | ||
201 | |||
202 | if(file) { | ||
203 | fseek(file, 0l, SEEK_END); | ||
204 | int flen = ftell(file); | ||
205 | fseek(file, 0l, SEEK_SET); | ||
206 | |||
207 | char *buffer = g_malloc(flen+1); | ||
208 | fread(buffer, 1, flen, file); | ||
209 | fclose(file); | ||
210 | |||
211 | buffer[flen]=0; | ||
212 | |||
213 | gtk_label_set_text(GTK_LABEL(label), buffer); | ||
214 | |||
215 | g_free(buffer); | ||
216 | } else | ||
217 | gtk_label_set_text(GTK_LABEL(label), _("Load error")); | ||
218 | |||
219 | #ifndef USE_PANNABLE_AREA | ||
220 | GtkWidget *scrolled_window = gtk_scrolled_window_new(NULL, NULL); | ||
221 | gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_window), | ||
222 | GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC); | ||
223 | gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scrolled_window), | ||
224 | label); | ||
225 | gtk_scrolled_window_set_shadow_type( GTK_SCROLLED_WINDOW(scrolled_window), | ||
226 | GTK_SHADOW_IN); | ||
227 | return scrolled_window; | ||
228 | #else | ||
229 | GtkWidget *pannable_area = hildon_pannable_area_new(); | ||
230 | hildon_pannable_area_add_with_viewport(HILDON_PANNABLE_AREA(pannable_area), | ||
231 | label); | ||
232 | return pannable_area; | ||
233 | #endif | ||
234 | } | ||
235 | |||
236 | GtkWidget *copyright_page_new(appdata_t *appdata) { | ||
237 | GtkWidget *vbox = gtk_vbox_new(FALSE, 0); | ||
238 | |||
239 | /* ------------------------ */ | ||
240 | GtkWidget *ivbox = gtk_vbox_new(FALSE, 0); | ||
241 | |||
242 | GtkWidget *hbox = gtk_hbox_new(FALSE, 0); | ||
243 | GtkWidget *ihbox = gtk_hbox_new(FALSE, 20); | ||
244 | gtk_box_pack_start(GTK_BOX(ihbox), icon_get_widget(ICON_MISC, 5), | ||
245 | FALSE, FALSE, 0); | ||
246 | gtk_box_pack_start(GTK_BOX(ihbox), label_xbig("GPXView"), | ||
247 | FALSE, FALSE, 0); | ||
248 | |||
249 | gtk_box_pack_start(GTK_BOX(hbox), ihbox, TRUE, FALSE, 0); | ||
250 | gtk_box_pack_start_defaults(GTK_BOX(ivbox), hbox); | ||
251 | |||
252 | gtk_box_pack_start_defaults(GTK_BOX(ivbox), | ||
253 | label_big(_("Geocaching with Maemo"))); | ||
254 | |||
255 | gtk_box_pack_start(GTK_BOX(vbox), ivbox, TRUE, FALSE, 0); | ||
256 | |||
257 | /* ------------------------ */ | ||
258 | ivbox = gtk_vbox_new(FALSE, 0); | ||
259 | |||
260 | gtk_box_pack_start(GTK_BOX(ivbox), | ||
261 | gtk_label_new("Version " VERSION), FALSE, FALSE, 0); | ||
262 | gtk_box_pack_start(GTK_BOX(ivbox), | ||
263 | gtk_label_new(__DATE__ " " __TIME__), FALSE, FALSE, 0); | ||
264 | |||
265 | gtk_box_pack_start(GTK_BOX(vbox), ivbox, TRUE, FALSE, 0); | ||
266 | |||
267 | /* ------------------------ */ | ||
268 | ivbox = gtk_vbox_new(FALSE, 0); | ||
269 | |||
270 | gtk_box_pack_start(GTK_BOX(ivbox), | ||
271 | gtk_label_new(_("Copyright 2008-2009")), FALSE, FALSE, 0); | ||
272 | |||
273 | gtk_box_pack_start(GTK_BOX(ivbox), | ||
274 | link_new(appdata, "http://www.harbaum.org/till/maemo#gpxview"), | ||
275 | FALSE, FALSE, 0); | ||
276 | |||
277 | gtk_box_pack_start(GTK_BOX(vbox), ivbox, TRUE, FALSE, 0); | ||
278 | |||
279 | return vbox; | ||
280 | } | ||
281 | |||
282 | /* a label that is left aligned */ | ||
283 | GtkWidget *left_label(char *str) { | ||
284 | GtkWidget *widget = gtk_label_new(str); | ||
285 | gtk_misc_set_alignment(GTK_MISC(widget), 0.0f, 0.5f); | ||
286 | return widget; | ||
287 | } | ||
288 | |||
289 | GtkWidget *authors_page_new(void) { | ||
290 | GtkWidget *ivbox, *vbox = gtk_vbox_new(FALSE, 0); | ||
291 | |||
292 | /* -------------------------------------------- */ | ||
293 | ivbox = gtk_vbox_new(FALSE, 0); | ||
294 | gtk_box_pack_start(GTK_BOX(ivbox), left_label(_("Main developer:")), | ||
295 | FALSE, FALSE, 0); | ||
296 | gtk_box_pack_start(GTK_BOX(ivbox), | ||
297 | left_label("Till Harbaum <till@harbaum.org>"), | ||
298 | FALSE, FALSE, 0); | ||
299 | gtk_box_pack_start(GTK_BOX(vbox), ivbox, TRUE, FALSE, 0); | ||
300 | |||
301 | /* -------------------------------------------- */ | ||
302 | ivbox = gtk_vbox_new(FALSE, 0); | ||
303 | gtk_box_pack_start(GTK_BOX(ivbox), left_label(_("Original map widget by:")), | ||
304 | FALSE, FALSE, 0); | ||
305 | gtk_box_pack_start(GTK_BOX(ivbox), | ||
306 | left_label("John Stowers <john.stowers@gmail.com>"), | ||
307 | FALSE, FALSE, 0); | ||
308 | gtk_box_pack_start(GTK_BOX(vbox), ivbox, TRUE, FALSE, 0); | ||
309 | |||
310 | /* -------------------------------------------- */ | ||
311 | ivbox = gtk_vbox_new(FALSE, 0); | ||
312 | gtk_box_pack_start(GTK_BOX(ivbox), left_label(_("GCVote service provided by:")), | ||
313 | FALSE, FALSE, 0); | ||
314 | gtk_box_pack_start(GTK_BOX(ivbox), | ||
315 | left_label("Guido Wegener <guido.wegener@gmx.de>"), | ||
316 | FALSE, FALSE, 0); | ||
317 | gtk_box_pack_start(GTK_BOX(vbox), ivbox, TRUE, FALSE, 0); | ||
318 | |||
319 | /* -------------------------------------------- */ | ||
320 | ivbox = gtk_vbox_new(FALSE, 0); | ||
321 | gtk_box_pack_start(GTK_BOX(ivbox), left_label(_("Additional translations by:")), | ||
322 | FALSE, FALSE, 0); | ||
323 | gtk_box_pack_start(GTK_BOX(ivbox), | ||
324 | left_label("Marko Vertainen <marko.vertainen@iki.fi>"), | ||
325 | FALSE, FALSE, 0); | ||
326 | gtk_box_pack_start(GTK_BOX(vbox), ivbox, TRUE, FALSE, 0); | ||
327 | |||
328 | return vbox; | ||
329 | } | ||
330 | |||
331 | GtkWidget *donate_page_new(appdata_t *appdata) { | ||
332 | GtkWidget *vbox = gtk_vbox_new(FALSE, 0); | ||
333 | |||
334 | gtk_box_pack_start_defaults(GTK_BOX(vbox), | ||
335 | label_wrap(_("If you like GPXView and want to support its future development " | ||
336 | "please consider donating to the developer. You can either " | ||
337 | "donate via paypal to"))); | ||
338 | |||
339 | gtk_box_pack_start_defaults(GTK_BOX(vbox), | ||
340 | link_new(NULL, "till@harbaum.org")); | ||
341 | |||
342 | gtk_box_pack_start_defaults(GTK_BOX(vbox), | ||
343 | label_wrap(_("or you can just click the button below which will open " | ||
344 | "the appropriate web page in your browser."))); | ||
345 | |||
346 | GtkWidget *ihbox = gtk_hbox_new(FALSE, 0); | ||
347 | GtkWidget *button = gtk_button_new(); | ||
348 | gtk_button_set_image(GTK_BUTTON(button), | ||
349 | icon_get_widget(ICON_MISC, 3)); | ||
350 | gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE); | ||
351 | g_signal_connect(button, "clicked", | ||
352 | G_CALLBACK(on_paypal_button_clicked), appdata); | ||
353 | gtk_box_pack_start(GTK_BOX(ihbox), button, TRUE, FALSE, 0); | ||
354 | gtk_box_pack_start_defaults(GTK_BOX(vbox), ihbox); | ||
355 | |||
356 | return vbox; | ||
357 | } | ||
358 | |||
359 | GtkWidget *bugs_page_new(appdata_t *appdata) { | ||
360 | GtkWidget *vbox = gtk_vbox_new(FALSE, 0); | ||
361 | |||
362 | gtk_box_pack_start_defaults(GTK_BOX(vbox), | ||
363 | label_wrap(_("Please report bugs or feature requests via the GPXView " | ||
364 | "bug tracker. This bug tracker can directly be reached via " | ||
365 | "the following link:"))); | ||
366 | |||
367 | gtk_box_pack_start_defaults(GTK_BOX(vbox), | ||
368 | link_new(appdata, "https://garage.maemo.org/tracker/?group_id=973")); | ||
369 | |||
370 | gtk_box_pack_start_defaults(GTK_BOX(vbox), | ||
371 | label_wrap(_("You might also be interested in joining the mailing lists " | ||
372 | "or the forum:"))); | ||
373 | |||
374 | gtk_box_pack_start_defaults(GTK_BOX(vbox), | ||
375 | link_new(appdata, "http://garage.maemo.org/projects/gpxview/")); | ||
376 | |||
377 | gtk_box_pack_start_defaults(GTK_BOX(vbox), | ||
378 | label_wrap(_("Thank you for contributing!"))); | ||
379 | |||
380 | return vbox; | ||
381 | } | ||
382 | |||
383 | void about_box(appdata_t *appdata) { | ||
384 | GtkWidget *dialog = gtk_dialog_new_with_buttons(_("About GPXView"), | ||
385 | GTK_WINDOW(appdata->window), GTK_DIALOG_MODAL, | ||
386 | GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE, NULL); | ||
387 | |||
388 | #ifdef USE_MAEMO | ||
389 | gtk_window_set_default_size(GTK_WINDOW(dialog), 640, 480); | ||
390 | #else | ||
391 | gtk_window_set_default_size(GTK_WINDOW(dialog), 400, 200); | ||
392 | #endif | ||
393 | |||
394 | GtkWidget *notebook = notebook_new(); | ||
395 | |||
396 | notebook_append_page(notebook, copyright_page_new(appdata), _("Copyright")); | ||
397 | notebook_append_page(notebook, license_page_new(), _("License")); | ||
398 | notebook_append_page(notebook, authors_page_new(), _("Authors")); | ||
399 | notebook_append_page(notebook, donate_page_new(appdata), _("Donate")); | ||
400 | notebook_append_page(notebook, bugs_page_new(appdata), _("Bugs")); | ||
401 | |||
402 | gtk_box_pack_start_defaults(GTK_BOX((GTK_DIALOG(dialog))->vbox), | ||
403 | notebook); | ||
404 | |||
405 | gtk_widget_show_all(dialog); | ||
406 | |||
407 | gtk_dialog_run(GTK_DIALOG(dialog)); | ||
408 | gtk_widget_destroy(dialog); | ||
409 | } |