Contents of /trunk/src/about.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 246 - (hide annotations)
Tue Jan 19 20:26:37 2010 UTC (14 years, 3 months ago) by harbaum
File MIME type: text/plain
File size: 13787 byte(s)
Initial Espeak support
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 harbaum 246 static void
170     on_label_realize(GtkWidget *widget, gpointer user_data) {
171     /* get parent size (which is a container) */
172     gtk_widget_set_size_request(widget, widget->parent->allocation.width, -1);
173     }
174    
175 harbaum 236 GtkWidget *label_wrap(char *str) {
176     GtkWidget *label = gtk_label_new(str);
177     gtk_label_set_line_wrap_mode(GTK_LABEL(label), PANGO_WRAP_WORD);
178     gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
179 harbaum 246
180     g_signal_connect(G_OBJECT(label), "realize",
181     G_CALLBACK(on_label_realize), NULL);
182    
183 harbaum 236 return label;
184     }
185    
186     GtkWidget *license_page_new(void) {
187     char *name = g_strdup(ICONPATH "COPYING");
188    
189     GtkWidget *label = label_wrap("");
190    
191     /* load license into buffer */
192     FILE *file = fopen(name, "r");
193     g_free(name);
194    
195     if(!file) {
196     /* loading from installation path failed, try to load */
197     /* from local directory (for debugging) */
198     name = g_strdup("./data/COPYING");
199     file = fopen(name, "r");
200     g_free(name);
201     }
202    
203     if(file) {
204     fseek(file, 0l, SEEK_END);
205     int flen = ftell(file);
206     fseek(file, 0l, SEEK_SET);
207    
208     char *buffer = g_malloc(flen+1);
209     fread(buffer, 1, flen, file);
210     fclose(file);
211    
212     buffer[flen]=0;
213    
214     gtk_label_set_text(GTK_LABEL(label), buffer);
215    
216     g_free(buffer);
217     } else
218     gtk_label_set_text(GTK_LABEL(label), _("Load error"));
219    
220     #ifndef USE_PANNABLE_AREA
221     GtkWidget *scrolled_window = gtk_scrolled_window_new(NULL, NULL);
222     gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_window),
223     GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
224     gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scrolled_window),
225     label);
226     gtk_scrolled_window_set_shadow_type( GTK_SCROLLED_WINDOW(scrolled_window),
227     GTK_SHADOW_IN);
228     return scrolled_window;
229     #else
230     GtkWidget *pannable_area = hildon_pannable_area_new();
231     hildon_pannable_area_add_with_viewport(HILDON_PANNABLE_AREA(pannable_area),
232     label);
233     return pannable_area;
234     #endif
235     }
236    
237     GtkWidget *copyright_page_new(appdata_t *appdata) {
238     GtkWidget *vbox = gtk_vbox_new(FALSE, 0);
239    
240     /* ------------------------ */
241     GtkWidget *ivbox = gtk_vbox_new(FALSE, 0);
242    
243     GtkWidget *hbox = gtk_hbox_new(FALSE, 0);
244     GtkWidget *ihbox = gtk_hbox_new(FALSE, 20);
245     gtk_box_pack_start(GTK_BOX(ihbox), icon_get_widget(ICON_MISC, 5),
246     FALSE, FALSE, 0);
247     gtk_box_pack_start(GTK_BOX(ihbox), label_xbig("GPXView"),
248     FALSE, FALSE, 0);
249    
250     gtk_box_pack_start(GTK_BOX(hbox), ihbox, TRUE, FALSE, 0);
251     gtk_box_pack_start_defaults(GTK_BOX(ivbox), hbox);
252    
253     gtk_box_pack_start_defaults(GTK_BOX(ivbox),
254     label_big(_("Geocaching with Maemo")));
255    
256     gtk_box_pack_start(GTK_BOX(vbox), ivbox, TRUE, FALSE, 0);
257    
258     /* ------------------------ */
259     ivbox = gtk_vbox_new(FALSE, 0);
260    
261     gtk_box_pack_start(GTK_BOX(ivbox),
262     gtk_label_new("Version " VERSION), FALSE, FALSE, 0);
263     gtk_box_pack_start(GTK_BOX(ivbox),
264     gtk_label_new(__DATE__ " " __TIME__), FALSE, FALSE, 0);
265    
266     gtk_box_pack_start(GTK_BOX(vbox), ivbox, TRUE, FALSE, 0);
267    
268     /* ------------------------ */
269     ivbox = gtk_vbox_new(FALSE, 0);
270    
271     gtk_box_pack_start(GTK_BOX(ivbox),
272     gtk_label_new(_("Copyright 2008-2009")), FALSE, FALSE, 0);
273    
274     gtk_box_pack_start(GTK_BOX(ivbox),
275     link_new(appdata, "http://www.harbaum.org/till/maemo#gpxview"),
276     FALSE, FALSE, 0);
277    
278     gtk_box_pack_start(GTK_BOX(vbox), ivbox, TRUE, FALSE, 0);
279    
280     return vbox;
281     }
282    
283     /* a label that is left aligned */
284     GtkWidget *left_label(char *str) {
285     GtkWidget *widget = gtk_label_new(str);
286     gtk_misc_set_alignment(GTK_MISC(widget), 0.0f, 0.5f);
287     return widget;
288     }
289    
290 harbaum 244 static void author_add(GtkWidget *box, char *str) {
291     gtk_box_pack_start(GTK_BOX(box), left_label(str), FALSE, FALSE, 0);
292     }
293    
294 harbaum 236 GtkWidget *authors_page_new(void) {
295 harbaum 244 GtkWidget *ivbox, *vbox = gtk_vbox_new(FALSE, 16);
296 harbaum 236
297     /* -------------------------------------------- */
298     ivbox = gtk_vbox_new(FALSE, 0);
299 harbaum 244 author_add(ivbox, _("Main developer:"));
300     author_add(ivbox, "Till Harbaum <till@harbaum.org>");
301 harbaum 236 gtk_box_pack_start(GTK_BOX(vbox), ivbox, TRUE, FALSE, 0);
302    
303     /* -------------------------------------------- */
304     ivbox = gtk_vbox_new(FALSE, 0);
305 harbaum 244 author_add(ivbox, _("Original map widget by:"));
306     author_add(ivbox, "John Stowers <john.stowers@gmail.com>");
307 harbaum 236 gtk_box_pack_start(GTK_BOX(vbox), ivbox, TRUE, FALSE, 0);
308    
309     /* -------------------------------------------- */
310     ivbox = gtk_vbox_new(FALSE, 0);
311 harbaum 244 author_add(ivbox, _("GCVote service provided by:"));
312     author_add(ivbox, "Guido Wegener <guido.wegener@gmx.de>");
313 harbaum 236 gtk_box_pack_start(GTK_BOX(vbox), ivbox, TRUE, FALSE, 0);
314    
315     /* -------------------------------------------- */
316     ivbox = gtk_vbox_new(FALSE, 0);
317 harbaum 244 author_add(ivbox, _("Additional translations by:"));
318     author_add(ivbox, "Marko Vertainen <marko.vertainen@iki.fi>");
319 harbaum 236 gtk_box_pack_start(GTK_BOX(vbox), ivbox, TRUE, FALSE, 0);
320    
321 harbaum 244 /* -------------------------------------------- */
322     ivbox = gtk_vbox_new(FALSE, 0);
323     author_add(ivbox, _("Testers:"));
324     author_add(ivbox, "Uwe Koch <asys3@yahoo.com>");
325     author_add(ivbox, "Tanja Harbaum <tanja@harbaum.org>");
326     gtk_box_pack_start(GTK_BOX(vbox), ivbox, TRUE, FALSE, 0);
327    
328     #ifndef USE_PANNABLE_AREA
329     GtkWidget *scrolled_window = gtk_scrolled_window_new(NULL, NULL);
330     gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_window),
331     GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
332     gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scrolled_window),
333     vbox);
334     gtk_scrolled_window_set_shadow_type( GTK_SCROLLED_WINDOW(scrolled_window),
335     GTK_SHADOW_IN);
336     return scrolled_window;
337     #else
338     GtkWidget *pannable_area = hildon_pannable_area_new();
339     hildon_pannable_area_add_with_viewport(HILDON_PANNABLE_AREA(pannable_area),
340     vbox);
341     return pannable_area;
342     #endif
343 harbaum 236 }
344    
345     GtkWidget *donate_page_new(appdata_t *appdata) {
346     GtkWidget *vbox = gtk_vbox_new(FALSE, 0);
347    
348     gtk_box_pack_start_defaults(GTK_BOX(vbox),
349     label_wrap(_("If you like GPXView and want to support its future development "
350     "please consider donating to the developer. You can either "
351     "donate via paypal to")));
352    
353     gtk_box_pack_start_defaults(GTK_BOX(vbox),
354     link_new(NULL, "till@harbaum.org"));
355    
356     gtk_box_pack_start_defaults(GTK_BOX(vbox),
357     label_wrap(_("or you can just click the button below which will open "
358     "the appropriate web page in your browser.")));
359    
360     GtkWidget *ihbox = gtk_hbox_new(FALSE, 0);
361     GtkWidget *button = gtk_button_new();
362     gtk_button_set_image(GTK_BUTTON(button),
363     icon_get_widget(ICON_MISC, 3));
364     gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE);
365     g_signal_connect(button, "clicked",
366     G_CALLBACK(on_paypal_button_clicked), appdata);
367     gtk_box_pack_start(GTK_BOX(ihbox), button, TRUE, FALSE, 0);
368     gtk_box_pack_start_defaults(GTK_BOX(vbox), ihbox);
369    
370     return vbox;
371     }
372    
373     GtkWidget *bugs_page_new(appdata_t *appdata) {
374     GtkWidget *vbox = gtk_vbox_new(FALSE, 0);
375    
376     gtk_box_pack_start_defaults(GTK_BOX(vbox),
377     label_wrap(_("Please report bugs or feature requests via the GPXView "
378     "bug tracker. This bug tracker can directly be reached via "
379     "the following link:")));
380    
381     gtk_box_pack_start_defaults(GTK_BOX(vbox),
382     link_new(appdata, "https://garage.maemo.org/tracker/?group_id=973"));
383    
384     gtk_box_pack_start_defaults(GTK_BOX(vbox),
385     label_wrap(_("You might also be interested in joining the mailing lists "
386     "or the forum:")));
387    
388     gtk_box_pack_start_defaults(GTK_BOX(vbox),
389     link_new(appdata, "http://garage.maemo.org/projects/gpxview/"));
390    
391     gtk_box_pack_start_defaults(GTK_BOX(vbox),
392     label_wrap(_("Thank you for contributing!")));
393    
394     return vbox;
395     }
396    
397     void about_box(appdata_t *appdata) {
398     GtkWidget *dialog = gtk_dialog_new_with_buttons(_("About GPXView"),
399     GTK_WINDOW(appdata->window), GTK_DIALOG_MODAL,
400     GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE, NULL);
401    
402     #ifdef USE_MAEMO
403     gtk_window_set_default_size(GTK_WINDOW(dialog), 640, 480);
404     #else
405     gtk_window_set_default_size(GTK_WINDOW(dialog), 400, 200);
406     #endif
407    
408     GtkWidget *notebook = notebook_new();
409    
410     notebook_append_page(notebook, copyright_page_new(appdata), _("Copyright"));
411     notebook_append_page(notebook, license_page_new(), _("License"));
412     notebook_append_page(notebook, authors_page_new(), _("Authors"));
413     notebook_append_page(notebook, donate_page_new(appdata), _("Donate"));
414     notebook_append_page(notebook, bugs_page_new(appdata), _("Bugs"));
415    
416     gtk_box_pack_start_defaults(GTK_BOX((GTK_DIALOG(dialog))->vbox),
417     notebook);
418    
419     gtk_widget_show_all(dialog);
420    
421     gtk_dialog_run(GTK_DIALOG(dialog));
422     gtk_widget_destroy(dialog);
423     }