Contents of /trunk/src/about.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 244 - (show annotations)
Tue Dec 15 19:54:04 2009 UTC (14 years, 4 months ago) by harbaum
File MIME type: text/plain
File size: 13697 byte(s)
Several search related bug fixes
1 /*
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 static void author_add(GtkWidget *box, char *str) {
290 gtk_box_pack_start(GTK_BOX(box), left_label(str), FALSE, FALSE, 0);
291 }
292
293 GtkWidget *authors_page_new(void) {
294 GtkWidget *ivbox, *vbox = gtk_vbox_new(FALSE, 16);
295
296 /* -------------------------------------------- */
297 ivbox = gtk_vbox_new(FALSE, 0);
298 author_add(ivbox, _("Main developer:"));
299 author_add(ivbox, "Till Harbaum <till@harbaum.org>");
300 gtk_box_pack_start(GTK_BOX(vbox), ivbox, TRUE, FALSE, 0);
301
302 /* -------------------------------------------- */
303 ivbox = gtk_vbox_new(FALSE, 0);
304 author_add(ivbox, _("Original map widget by:"));
305 author_add(ivbox, "John Stowers <john.stowers@gmail.com>");
306 gtk_box_pack_start(GTK_BOX(vbox), ivbox, TRUE, FALSE, 0);
307
308 /* -------------------------------------------- */
309 ivbox = gtk_vbox_new(FALSE, 0);
310 author_add(ivbox, _("GCVote service provided by:"));
311 author_add(ivbox, "Guido Wegener <guido.wegener@gmx.de>");
312 gtk_box_pack_start(GTK_BOX(vbox), ivbox, TRUE, FALSE, 0);
313
314 /* -------------------------------------------- */
315 ivbox = gtk_vbox_new(FALSE, 0);
316 author_add(ivbox, _("Additional translations by:"));
317 author_add(ivbox, "Marko Vertainen <marko.vertainen@iki.fi>");
318 gtk_box_pack_start(GTK_BOX(vbox), ivbox, TRUE, FALSE, 0);
319
320 /* -------------------------------------------- */
321 ivbox = gtk_vbox_new(FALSE, 0);
322 author_add(ivbox, _("Testers:"));
323 author_add(ivbox, "Uwe Koch <asys3@yahoo.com>");
324 author_add(ivbox, "Tanja Harbaum <tanja@harbaum.org>");
325 gtk_box_pack_start(GTK_BOX(vbox), ivbox, TRUE, FALSE, 0);
326
327 #ifndef USE_PANNABLE_AREA
328 GtkWidget *scrolled_window = gtk_scrolled_window_new(NULL, NULL);
329 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_window),
330 GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
331 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scrolled_window),
332 vbox);
333 gtk_scrolled_window_set_shadow_type( GTK_SCROLLED_WINDOW(scrolled_window),
334 GTK_SHADOW_IN);
335 return scrolled_window;
336 #else
337 GtkWidget *pannable_area = hildon_pannable_area_new();
338 hildon_pannable_area_add_with_viewport(HILDON_PANNABLE_AREA(pannable_area),
339 vbox);
340 return pannable_area;
341 #endif
342 }
343
344 GtkWidget *donate_page_new(appdata_t *appdata) {
345 GtkWidget *vbox = gtk_vbox_new(FALSE, 0);
346
347 gtk_box_pack_start_defaults(GTK_BOX(vbox),
348 label_wrap(_("If you like GPXView and want to support its future development "
349 "please consider donating to the developer. You can either "
350 "donate via paypal to")));
351
352 gtk_box_pack_start_defaults(GTK_BOX(vbox),
353 link_new(NULL, "till@harbaum.org"));
354
355 gtk_box_pack_start_defaults(GTK_BOX(vbox),
356 label_wrap(_("or you can just click the button below which will open "
357 "the appropriate web page in your browser.")));
358
359 GtkWidget *ihbox = gtk_hbox_new(FALSE, 0);
360 GtkWidget *button = gtk_button_new();
361 gtk_button_set_image(GTK_BUTTON(button),
362 icon_get_widget(ICON_MISC, 3));
363 gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE);
364 g_signal_connect(button, "clicked",
365 G_CALLBACK(on_paypal_button_clicked), appdata);
366 gtk_box_pack_start(GTK_BOX(ihbox), button, TRUE, FALSE, 0);
367 gtk_box_pack_start_defaults(GTK_BOX(vbox), ihbox);
368
369 return vbox;
370 }
371
372 GtkWidget *bugs_page_new(appdata_t *appdata) {
373 GtkWidget *vbox = gtk_vbox_new(FALSE, 0);
374
375 gtk_box_pack_start_defaults(GTK_BOX(vbox),
376 label_wrap(_("Please report bugs or feature requests via the GPXView "
377 "bug tracker. This bug tracker can directly be reached via "
378 "the following link:")));
379
380 gtk_box_pack_start_defaults(GTK_BOX(vbox),
381 link_new(appdata, "https://garage.maemo.org/tracker/?group_id=973"));
382
383 gtk_box_pack_start_defaults(GTK_BOX(vbox),
384 label_wrap(_("You might also be interested in joining the mailing lists "
385 "or the forum:")));
386
387 gtk_box_pack_start_defaults(GTK_BOX(vbox),
388 link_new(appdata, "http://garage.maemo.org/projects/gpxview/"));
389
390 gtk_box_pack_start_defaults(GTK_BOX(vbox),
391 label_wrap(_("Thank you for contributing!")));
392
393 return vbox;
394 }
395
396 void about_box(appdata_t *appdata) {
397 GtkWidget *dialog = gtk_dialog_new_with_buttons(_("About GPXView"),
398 GTK_WINDOW(appdata->window), GTK_DIALOG_MODAL,
399 GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE, NULL);
400
401 #ifdef USE_MAEMO
402 gtk_window_set_default_size(GTK_WINDOW(dialog), 640, 480);
403 #else
404 gtk_window_set_default_size(GTK_WINDOW(dialog), 400, 200);
405 #endif
406
407 GtkWidget *notebook = notebook_new();
408
409 notebook_append_page(notebook, copyright_page_new(appdata), _("Copyright"));
410 notebook_append_page(notebook, license_page_new(), _("License"));
411 notebook_append_page(notebook, authors_page_new(), _("Authors"));
412 notebook_append_page(notebook, donate_page_new(appdata), _("Donate"));
413 notebook_append_page(notebook, bugs_page_new(appdata), _("Bugs"));
414
415 gtk_box_pack_start_defaults(GTK_BOX((GTK_DIALOG(dialog))->vbox),
416 notebook);
417
418 gtk_widget_show_all(dialog);
419
420 gtk_dialog_run(GTK_DIALOG(dialog));
421 gtk_widget_destroy(dialog);
422 }