Line 0
Link Here
|
|
|
1 |
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ |
2 |
/* gnome-about.c - An about box widget for gnome. |
3 |
|
4 |
Copyright (C) 2001 CodeFactory AB |
5 |
Copyright (C) 2001, 2002 Anders Carlsson |
6 |
|
7 |
The Gnome Library is free software; you can redistribute it and/or |
8 |
modify it under the terms of the GNU Library General Public License as |
9 |
published by the Free Software Foundation; either version 2 of the |
10 |
License, or (at your option) any later version. |
11 |
|
12 |
The Gnome Library is distributed in the hope that it will be useful, |
13 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
15 |
Library General Public License for more details. |
16 |
|
17 |
You should have received a copy of the GNU Library General Public |
18 |
License along with the Gnome Library; see the file COPYING.LIB. If not, |
19 |
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
20 |
Boston, MA 02111-1307, USA. |
21 |
|
22 |
Author: Anders Carlsson <andersca@gnu.org> |
23 |
*/ |
24 |
|
25 |
//Changed by Hu Zheng <huzheng_001@163.com> to make it compile along. 2003.09.23 |
26 |
|
27 |
#include <glib/gi18n.h> |
28 |
|
29 |
#include <gtk/gtkalignment.h> |
30 |
#include <gtk/gtkbbox.h> |
31 |
#include <gtk/gtkbutton.h> |
32 |
#include <gtk/gtkdialog.h> |
33 |
#include <gtk/gtkhbox.h> |
34 |
#include <gtk/gtkimage.h> |
35 |
#include <gtk/gtklabel.h> |
36 |
#include <gtk/gtknotebook.h> |
37 |
#include <gtk/gtkscrolledwindow.h> |
38 |
#include <gtk/gtkstock.h> |
39 |
#include <gtk/gtktextview.h> |
40 |
#include <gtk/gtkvbox.h> |
41 |
#include <gtk/gtkviewport.h> |
42 |
|
43 |
|
44 |
#include <glib/gmacros.h> |
45 |
|
46 |
#include "gnome-about.h" |
47 |
|
48 |
G_BEGIN_DECLS |
49 |
|
50 |
#define BONOBO_BOILERPLATE(type, type_as_function, corba_type, \ |
51 |
parent_type, parent_type_macro, \ |
52 |
register_type_macro) \ |
53 |
static void type_as_function ## _class_init (type ## Class *klass); \ |
54 |
static void type_as_function ## _instance_init (type *object); \ |
55 |
static parent_type ## Class *parent_class = NULL; \ |
56 |
static void \ |
57 |
type_as_function ## _class_init_trampoline (gpointer klass, \ |
58 |
gpointer data) \ |
59 |
{ \ |
60 |
parent_class = (parent_type ## Class *)g_type_class_ref ( \ |
61 |
parent_type_macro); \ |
62 |
type_as_function ## _class_init ((type ## Class *)klass); \ |
63 |
} \ |
64 |
GType \ |
65 |
type_as_function ## _get_type (void) \ |
66 |
{ \ |
67 |
static GType object_type = 0; \ |
68 |
if (object_type == 0) { \ |
69 |
static const GTypeInfo object_info = { \ |
70 |
sizeof (type ## Class), \ |
71 |
NULL, /* base_init */ \ |
72 |
NULL, /* base_finalize */ \ |
73 |
type_as_function ## _class_init_trampoline, \ |
74 |
NULL, /* class_finalize */ \ |
75 |
NULL, /* class_data */ \ |
76 |
sizeof (type), \ |
77 |
0, /* n_preallocs */ \ |
78 |
(GInstanceInitFunc) type_as_function ## _instance_init \ |
79 |
}; \ |
80 |
object_type = register_type_macro \ |
81 |
(type, type_as_function, corba_type, \ |
82 |
parent_type, parent_type_macro); \ |
83 |
} \ |
84 |
return object_type; \ |
85 |
} |
86 |
|
87 |
#define BONOBO_CALL_PARENT(parent_class_cast, name, args) \ |
88 |
((parent_class_cast(parent_class)->name != NULL) ? \ |
89 |
parent_class_cast(parent_class)->name args : (void)0) |
90 |
|
91 |
G_END_DECLS |
92 |
|
93 |
#define GNOME_CLASS_BOILERPLATE(type, type_as_function, \ |
94 |
parent_type, parent_type_macro) \ |
95 |
BONOBO_BOILERPLATE(type, type_as_function, type, \ |
96 |
parent_type, parent_type_macro, \ |
97 |
GNOME_REGISTER_TYPE) |
98 |
|
99 |
#define GNOME_REGISTER_TYPE(type, type_as_function, corba_type, \ |
100 |
parent_type, parent_type_macro) \ |
101 |
g_type_register_static (parent_type_macro, #type, &object_info, 0) |
102 |
|
103 |
#define GNOME_CALL_PARENT(parent_class_cast, name, args) \ |
104 |
BONOBO_CALL_PARENT (parent_class_cast, name, args) |
105 |
|
106 |
/* FIXME: More includes! */ |
107 |
|
108 |
struct _GnomeAboutPrivate { |
109 |
gchar *name; |
110 |
gchar *version; |
111 |
gchar *copyright; |
112 |
gchar *comments; |
113 |
gchar *translator_credits; |
114 |
|
115 |
GSList *authors; |
116 |
GSList *documenters; |
117 |
|
118 |
GtkWidget *logo_image; |
119 |
GtkWidget *name_label; |
120 |
GtkWidget *comments_label; |
121 |
GtkWidget *copyright_label; |
122 |
|
123 |
GtkWidget *credits_dialog; |
124 |
}; |
125 |
|
126 |
enum { |
127 |
PROP_0, |
128 |
PROP_NAME, |
129 |
PROP_VERSION, |
130 |
PROP_COPYRIGHT, |
131 |
PROP_COMMENTS, |
132 |
PROP_AUTHORS, |
133 |
PROP_DOCUMENTERS, |
134 |
PROP_TRANSLATOR_CREDITS, |
135 |
PROP_LOGO, |
136 |
}; |
137 |
|
138 |
#define GNOME_RESPONSE_CREDITS 1 |
139 |
|
140 |
static void gnome_about_finalize (GObject *object); |
141 |
static void gnome_about_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec); |
142 |
static void gnome_about_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec); |
143 |
|
144 |
GNOME_CLASS_BOILERPLATE (GnomeAbout, gnome_about, |
145 |
GtkDialog, GTK_TYPE_DIALOG) |
146 |
|
147 |
static void |
148 |
gnome_about_update_authors_label (GnomeAbout *about, GtkWidget *label) |
149 |
{ |
150 |
GString *string; |
151 |
GSList *list; |
152 |
gchar *tmp; |
153 |
|
154 |
if (about->_priv->authors == NULL) { |
155 |
gtk_widget_hide (label); |
156 |
return; |
157 |
} |
158 |
else { |
159 |
gtk_widget_show (label); |
160 |
} |
161 |
|
162 |
string = g_string_new (NULL); |
163 |
|
164 |
for (list = about->_priv->authors; list; list = list->next) { |
165 |
tmp = g_markup_escape_text (list->data, -1); |
166 |
g_string_append (string, tmp); |
167 |
|
168 |
if (list->next) |
169 |
g_string_append_c (string, '\n'); |
170 |
g_free (tmp); |
171 |
} |
172 |
|
173 |
gtk_label_set_markup (GTK_LABEL (label), string->str); |
174 |
g_string_free (string, TRUE); |
175 |
} |
176 |
|
177 |
static void |
178 |
gnome_about_update_documenters_label (GnomeAbout *about, GtkWidget *label) |
179 |
{ |
180 |
GString *string; |
181 |
GSList *list; |
182 |
gchar *tmp; |
183 |
|
184 |
if (about->_priv->documenters == NULL) { |
185 |
gtk_widget_hide (label); |
186 |
return; |
187 |
} |
188 |
else { |
189 |
gtk_widget_show (label); |
190 |
} |
191 |
|
192 |
string = g_string_new (NULL); |
193 |
|
194 |
for (list = about->_priv->documenters; list; list = list->next) { |
195 |
tmp = g_markup_escape_text (list->data, -1); |
196 |
g_string_append (string, tmp); |
197 |
|
198 |
if (list->next) |
199 |
g_string_append (string, "\n"); |
200 |
g_free (tmp); |
201 |
} |
202 |
|
203 |
gtk_label_set_markup (GTK_LABEL (label), string->str); |
204 |
g_string_free (string, TRUE); |
205 |
} |
206 |
|
207 |
static void |
208 |
gnome_about_update_translation_information_label (GnomeAbout *about, GtkWidget *label) |
209 |
{ |
210 |
GString *string; |
211 |
gchar *tmp; |
212 |
|
213 |
if (about->_priv->translator_credits == NULL) { |
214 |
gtk_widget_hide (label); |
215 |
return; |
216 |
} |
217 |
else { |
218 |
gtk_widget_show (label); |
219 |
} |
220 |
|
221 |
string = g_string_new (NULL); |
222 |
|
223 |
tmp = g_markup_escape_text (about->_priv->translator_credits, -1); |
224 |
g_string_append (string, tmp); |
225 |
g_free (tmp); |
226 |
|
227 |
gtk_label_set_markup (GTK_LABEL (label), string->str); |
228 |
g_string_free (string, TRUE); |
229 |
} |
230 |
|
231 |
static GtkWidget * |
232 |
create_label (void) |
233 |
{ |
234 |
GtkWidget *label; |
235 |
|
236 |
label = gtk_label_new (""); |
237 |
gtk_label_set_selectable (GTK_LABEL (label), TRUE); |
238 |
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.0); |
239 |
gtk_misc_set_padding (GTK_MISC (label), 8, 8); |
240 |
|
241 |
gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_LEFT); |
242 |
|
243 |
return label; |
244 |
} |
245 |
|
246 |
static void |
247 |
gnome_about_display_credits_dialog (GnomeAbout *about) |
248 |
{ |
249 |
GtkWidget *dialog, *label, *notebook, *sw; |
250 |
|
251 |
if (about->_priv->credits_dialog != NULL) { |
252 |
gtk_window_present (GTK_WINDOW (about->_priv->credits_dialog)); |
253 |
return; |
254 |
} |
255 |
|
256 |
dialog = gtk_dialog_new_with_buttons (_("Credits"), |
257 |
GTK_WINDOW (about), |
258 |
GTK_DIALOG_DESTROY_WITH_PARENT, |
259 |
GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE, |
260 |
NULL); |
261 |
about->_priv->credits_dialog = dialog; |
262 |
gtk_window_set_default_size (GTK_WINDOW (dialog), 360, 260); |
263 |
gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_CLOSE); |
264 |
gtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE); |
265 |
gtk_container_set_border_width (GTK_CONTAINER (dialog), 5); |
266 |
gtk_box_set_spacing (GTK_BOX (GTK_DIALOG (dialog)->vbox), 2); |
267 |
g_signal_connect (dialog, "response", |
268 |
G_CALLBACK (gtk_widget_destroy), dialog); |
269 |
g_signal_connect (dialog, "destroy", |
270 |
G_CALLBACK (gtk_widget_destroyed), |
271 |
&(about->_priv->credits_dialog)); |
272 |
|
273 |
notebook = gtk_notebook_new (); |
274 |
gtk_container_set_border_width (GTK_CONTAINER (notebook), 5); |
275 |
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), notebook, TRUE, TRUE, 0); |
276 |
|
277 |
if (about->_priv->authors != NULL) { |
278 |
label = create_label (); |
279 |
|
280 |
sw = gtk_scrolled_window_new (NULL, NULL); |
281 |
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw), |
282 |
GTK_POLICY_AUTOMATIC, |
283 |
GTK_POLICY_AUTOMATIC); |
284 |
gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (sw), label); |
285 |
gtk_viewport_set_shadow_type (GTK_VIEWPORT (GTK_BIN (sw)->child), GTK_SHADOW_NONE); |
286 |
|
287 |
gtk_notebook_append_page (GTK_NOTEBOOK (notebook), sw, |
288 |
gtk_label_new (_("Written by"))); |
289 |
gnome_about_update_authors_label (about, label); |
290 |
} |
291 |
|
292 |
if (about->_priv->documenters != NULL) { |
293 |
label = create_label (); |
294 |
|
295 |
sw = gtk_scrolled_window_new (NULL, NULL); |
296 |
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw), |
297 |
GTK_POLICY_AUTOMATIC, |
298 |
GTK_POLICY_AUTOMATIC); |
299 |
gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (sw), label); |
300 |
gtk_viewport_set_shadow_type (GTK_VIEWPORT (GTK_BIN (sw)->child), GTK_SHADOW_NONE); |
301 |
|
302 |
gtk_notebook_append_page (GTK_NOTEBOOK (notebook), sw, |
303 |
gtk_label_new (_("Documented by"))); |
304 |
gnome_about_update_documenters_label (about, label); |
305 |
} |
306 |
|
307 |
if (about->_priv->translator_credits != NULL) { |
308 |
label = create_label (); |
309 |
|
310 |
sw = gtk_scrolled_window_new (NULL, NULL); |
311 |
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw), |
312 |
GTK_POLICY_AUTOMATIC, |
313 |
GTK_POLICY_AUTOMATIC); |
314 |
gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (sw), label); |
315 |
gtk_viewport_set_shadow_type (GTK_VIEWPORT (GTK_BIN (sw)->child), GTK_SHADOW_NONE); |
316 |
|
317 |
gtk_notebook_append_page (GTK_NOTEBOOK (notebook), sw, |
318 |
gtk_label_new (_("Translated by"))); |
319 |
gnome_about_update_translation_information_label (about, label); |
320 |
} |
321 |
|
322 |
gtk_widget_show_all (dialog); |
323 |
} |
324 |
|
325 |
static void |
326 |
gnome_about_instance_init (GnomeAbout *about) |
327 |
{ |
328 |
GnomeAboutPrivate *priv; |
329 |
GtkWidget *vbox, *hbox, *image, *label, *alignment, *button; |
330 |
|
331 |
/* Data */ |
332 |
|
333 |
priv = g_new0 (GnomeAboutPrivate, 1); |
334 |
about->_priv = priv; |
335 |
|
336 |
priv->name = NULL; |
337 |
priv->version = NULL; |
338 |
priv->copyright = NULL; |
339 |
priv->comments = NULL; |
340 |
priv->translator_credits = NULL; |
341 |
priv->authors = NULL; |
342 |
priv->documenters = NULL; |
343 |
|
344 |
gtk_dialog_set_has_separator (GTK_DIALOG (about), FALSE); |
345 |
gtk_container_set_border_width (GTK_CONTAINER (about), 5); |
346 |
gtk_box_set_spacing (GTK_BOX (GTK_DIALOG (about)->vbox), 5); |
347 |
|
348 |
/* Widgets */ |
349 |
vbox = gtk_vbox_new (FALSE, 8); |
350 |
gtk_container_set_border_width (GTK_CONTAINER (vbox), 5); |
351 |
|
352 |
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (about)->vbox), vbox, TRUE, TRUE, 0); |
353 |
|
354 |
priv->logo_image = gtk_image_new (); |
355 |
gtk_box_pack_start (GTK_BOX (vbox), priv->logo_image, FALSE, FALSE, 0); |
356 |
priv->name_label = gtk_label_new (NULL); |
357 |
gtk_label_set_selectable (GTK_LABEL (priv->name_label), TRUE); |
358 |
gtk_label_set_justify (GTK_LABEL (priv->name_label), GTK_JUSTIFY_CENTER); |
359 |
gtk_box_pack_start (GTK_BOX (vbox), priv->name_label, FALSE, FALSE, 0); |
360 |
|
361 |
priv->comments_label = gtk_label_new (NULL); |
362 |
gtk_label_set_selectable (GTK_LABEL (priv->comments_label), TRUE); |
363 |
gtk_label_set_justify (GTK_LABEL (priv->comments_label), GTK_JUSTIFY_CENTER); |
364 |
gtk_label_set_line_wrap (GTK_LABEL (priv->comments_label), TRUE); |
365 |
gtk_box_pack_start (GTK_BOX (vbox), priv->comments_label, FALSE, FALSE, 0); |
366 |
|
367 |
priv->copyright_label = gtk_label_new (NULL); |
368 |
gtk_label_set_selectable (GTK_LABEL (priv->copyright_label), TRUE); |
369 |
gtk_label_set_justify (GTK_LABEL (priv->copyright_label), GTK_JUSTIFY_CENTER); |
370 |
gtk_box_pack_start (GTK_BOX (vbox), priv->copyright_label, FALSE, FALSE, 0); |
371 |
|
372 |
gtk_widget_show_all (vbox); |
373 |
|
374 |
/* Add the close button */ |
375 |
gtk_dialog_add_button (GTK_DIALOG (about), GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE); |
376 |
gtk_dialog_set_default_response (GTK_DIALOG (about), GTK_RESPONSE_CLOSE); |
377 |
|
378 |
/* Add the credits button */ |
379 |
image = gtk_image_new_from_stock (GTK_STOCK_JUMP_TO, GTK_ICON_SIZE_BUTTON); |
380 |
|
381 |
label = gtk_label_new_with_mnemonic (_("C_redits")); |
382 |
|
383 |
hbox = gtk_hbox_new (FALSE, 2); |
384 |
gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0); |
385 |
gtk_box_pack_end (GTK_BOX (hbox), label, FALSE, FALSE, 0); |
386 |
|
387 |
alignment = gtk_alignment_new (0.5, 0.5, 0.0, 0.0); |
388 |
gtk_container_add (GTK_CONTAINER (alignment), hbox); |
389 |
|
390 |
button = gtk_button_new (); |
391 |
gtk_container_add (GTK_CONTAINER (button), alignment); |
392 |
gtk_widget_show_all (button); |
393 |
|
394 |
gtk_dialog_add_action_widget (GTK_DIALOG (about), button, GNOME_RESPONSE_CREDITS); |
395 |
gtk_button_box_set_child_secondary (GTK_BUTTON_BOX (GTK_DIALOG (about)->action_area), button, TRUE); |
396 |
|
397 |
gtk_window_set_resizable (GTK_WINDOW (about), FALSE); |
398 |
|
399 |
priv->credits_dialog = NULL; |
400 |
} |
401 |
|
402 |
static void |
403 |
gnome_about_response (GtkDialog *dialog, gint response) |
404 |
{ |
405 |
switch (response) { |
406 |
case GNOME_RESPONSE_CREDITS: |
407 |
gnome_about_display_credits_dialog (GNOME_ABOUT (dialog)); |
408 |
break; |
409 |
default: |
410 |
gtk_widget_destroy (GTK_WIDGET (dialog)); |
411 |
break; |
412 |
} |
413 |
} |
414 |
|
415 |
static void |
416 |
gnome_about_class_init (GnomeAboutClass *klass) |
417 |
{ |
418 |
GObjectClass *object_class; |
419 |
GtkWidgetClass *widget_class; |
420 |
GtkDialogClass *dialog_class; |
421 |
|
422 |
object_class = (GObjectClass *)klass; |
423 |
widget_class = (GtkWidgetClass *)klass; |
424 |
dialog_class = (GtkDialogClass *)klass; |
425 |
|
426 |
object_class->set_property = gnome_about_set_property; |
427 |
object_class->get_property = gnome_about_get_property; |
428 |
|
429 |
object_class->finalize = gnome_about_finalize; |
430 |
|
431 |
dialog_class->response = gnome_about_response; |
432 |
|
433 |
g_object_class_install_property (object_class, |
434 |
PROP_NAME, |
435 |
g_param_spec_string ("name", |
436 |
_("Program name"), |
437 |
_("The name of the program"), |
438 |
NULL, |
439 |
G_PARAM_READWRITE)); |
440 |
|
441 |
g_object_class_install_property (object_class, |
442 |
PROP_VERSION, |
443 |
g_param_spec_string ("version", |
444 |
_("Program version"), |
445 |
_("The version of the program"), |
446 |
NULL, |
447 |
G_PARAM_READWRITE)); |
448 |
g_object_class_install_property (object_class, |
449 |
PROP_COPYRIGHT, |
450 |
g_param_spec_string ("copyright", |
451 |
_("Copyright string"), |
452 |
_("Copyright information for the program"), |
453 |
NULL, |
454 |
G_PARAM_READWRITE)); |
455 |
|
456 |
g_object_class_install_property (object_class, |
457 |
PROP_COMMENTS, |
458 |
g_param_spec_string ("comments", |
459 |
_("Comments string"), |
460 |
_("Comments about the program"), |
461 |
NULL, |
462 |
G_PARAM_READWRITE)); |
463 |
g_object_class_install_property (object_class, |
464 |
PROP_AUTHORS, |
465 |
g_param_spec_value_array ("authors", |
466 |
_("Authors"), |
467 |
_("List of authors of the programs"), |
468 |
g_param_spec_string ("author-entry", |
469 |
_("Author entry"), |
470 |
_("A single author entry"), |
471 |
NULL, |
472 |
G_PARAM_READWRITE), |
473 |
G_PARAM_WRITABLE)); |
474 |
g_object_class_install_property (object_class, |
475 |
PROP_DOCUMENTERS, |
476 |
g_param_spec_value_array ("documenters", |
477 |
_("Documenters"), |
478 |
_("List of people documenting the program"), |
479 |
g_param_spec_string ("documenter-entry", |
480 |
_("Documenter entry"), |
481 |
_("A single documenter entry"), |
482 |
NULL, |
483 |
G_PARAM_READWRITE), |
484 |
G_PARAM_WRITABLE)); |
485 |
|
486 |
g_object_class_install_property (object_class, |
487 |
PROP_TRANSLATOR_CREDITS, |
488 |
g_param_spec_string ("translator_credits", |
489 |
_("Translator credits"), |
490 |
_("Credits to the translators. This string should be marked as translatable"), |
491 |
NULL, |
492 |
G_PARAM_READWRITE)); |
493 |
|
494 |
g_object_class_install_property (object_class, |
495 |
PROP_LOGO, |
496 |
g_param_spec_object ("logo", |
497 |
_("Logo"), |
498 |
_("A logo for the about box"), |
499 |
GDK_TYPE_PIXBUF, |
500 |
G_PARAM_WRITABLE)); |
501 |
|
502 |
} |
503 |
|
504 |
static void |
505 |
gnome_about_set_comments (GnomeAbout *about, const gchar *comments) |
506 |
{ |
507 |
g_free (about->_priv->comments); |
508 |
about->_priv->comments = comments ? g_strdup (comments) : NULL; |
509 |
|
510 |
gtk_label_set_text (GTK_LABEL (about->_priv->comments_label), about->_priv->comments); |
511 |
} |
512 |
|
513 |
static void |
514 |
gnome_about_set_translator_credits (GnomeAbout *about, const gchar *translator_credits) |
515 |
{ |
516 |
g_free (about->_priv->translator_credits); |
517 |
|
518 |
about->_priv->translator_credits = g_strdup (translator_credits); |
519 |
} |
520 |
|
521 |
static void |
522 |
gnome_about_set_copyright (GnomeAbout *about, const gchar *copyright) |
523 |
{ |
524 |
char *copyright_string, *tmp; |
525 |
|
526 |
g_free (about->_priv->copyright); |
527 |
about->_priv->copyright = copyright ? g_strdup (copyright) : NULL; |
528 |
|
529 |
if (about->_priv->copyright != NULL) { |
530 |
tmp = g_markup_escape_text (about->_priv->copyright, -1); |
531 |
copyright_string = g_strdup_printf ("<span size=\"small\">%s</span>", tmp); |
532 |
g_free (tmp); |
533 |
} |
534 |
else { |
535 |
copyright_string = NULL; |
536 |
} |
537 |
|
538 |
gtk_label_set_markup (GTK_LABEL (about->_priv->copyright_label), copyright_string); |
539 |
|
540 |
g_free (copyright_string); |
541 |
} |
542 |
|
543 |
static void |
544 |
gnome_about_set_version (GnomeAbout *about, const gchar *version) |
545 |
{ |
546 |
gchar *name_string, *tmp_name, *tmp_version; |
547 |
|
548 |
g_free (about->_priv->version); |
549 |
about->_priv->version = version ? g_strdup (version) : NULL; |
550 |
|
551 |
tmp_name = g_markup_escape_text (about->_priv->name, -1); |
552 |
|
553 |
if (about->_priv->version != NULL) { |
554 |
tmp_version = g_markup_escape_text (about->_priv->version, -1); |
555 |
name_string = g_strdup_printf ("<span size=\"xx-large\" weight=\"bold\">%s %s</span>", tmp_name, tmp_version); |
556 |
g_free (tmp_version); |
557 |
} |
558 |
else { |
559 |
name_string = g_strdup_printf ("<span size=\"xx-large\" weight=\"bold\">%s</span>", tmp_name); |
560 |
} |
561 |
|
562 |
gtk_label_set_markup (GTK_LABEL (about->_priv->name_label), name_string); |
563 |
g_free (name_string); |
564 |
g_free (tmp_name); |
565 |
} |
566 |
|
567 |
static void |
568 |
gnome_about_set_name (GnomeAbout *about, const gchar *name) |
569 |
{ |
570 |
gchar *title_string; |
571 |
gchar *name_string; |
572 |
gchar *tmp_name, *tmp_version; |
573 |
|
574 |
g_free (about->_priv->name); |
575 |
about->_priv->name = g_strdup (name ? name : ""); |
576 |
|
577 |
title_string = g_strdup_printf (_("About %s"), name); |
578 |
gtk_window_set_title (GTK_WINDOW (about), title_string); |
579 |
g_free (title_string); |
580 |
|
581 |
tmp_name = g_markup_escape_text (about->_priv->name, -1); |
582 |
|
583 |
if (about->_priv->version != NULL) { |
584 |
tmp_version = g_markup_escape_text (about->_priv->version, -1); |
585 |
name_string = g_strdup_printf ("<span size=\"xx-large\" weight=\"bold\">%s %s</span>", tmp_name, tmp_version); |
586 |
g_free (tmp_version); |
587 |
} |
588 |
else { |
589 |
name_string = g_strdup_printf ("<span size=\"xx-large\" weight=\"bold\">%s</span>", tmp_name); |
590 |
} |
591 |
|
592 |
gtk_label_set_markup (GTK_LABEL (about->_priv->name_label), name_string); |
593 |
g_free (name_string); |
594 |
g_free (tmp_name); |
595 |
} |
596 |
|
597 |
static void |
598 |
gnome_about_free_person_list (GSList *list) |
599 |
{ |
600 |
if (list == NULL) |
601 |
return; |
602 |
|
603 |
g_slist_foreach (list, (GFunc) g_free, NULL); |
604 |
g_slist_free (list); |
605 |
} |
606 |
|
607 |
static void |
608 |
gnome_about_finalize (GObject *object) |
609 |
{ |
610 |
GnomeAbout *about = GNOME_ABOUT (object); |
611 |
|
612 |
g_free (about->_priv->name); |
613 |
g_free (about->_priv->version); |
614 |
g_free (about->_priv->copyright); |
615 |
g_free (about->_priv->comments); |
616 |
|
617 |
gnome_about_free_person_list (about->_priv->authors); |
618 |
gnome_about_free_person_list (about->_priv->documenters); |
619 |
|
620 |
g_free (about->_priv->translator_credits); |
621 |
|
622 |
g_free (about->_priv); |
623 |
about->_priv = NULL; |
624 |
|
625 |
GNOME_CALL_PARENT (G_OBJECT_CLASS, finalize, (object)); |
626 |
} |
627 |
|
628 |
static void |
629 |
gnome_about_set_persons (GnomeAbout *about, guint prop_id, const GValue *persons) |
630 |
{ |
631 |
GValueArray *value_array; |
632 |
gint i; |
633 |
GSList *list; |
634 |
|
635 |
/* Free the old list */ |
636 |
switch (prop_id) { |
637 |
case PROP_AUTHORS: |
638 |
list = about->_priv->authors; |
639 |
break; |
640 |
case PROP_DOCUMENTERS: |
641 |
list = about->_priv->documenters; |
642 |
break; |
643 |
default: |
644 |
g_assert_not_reached (); |
645 |
list = NULL; /* silence warning */ |
646 |
} |
647 |
|
648 |
gnome_about_free_person_list (list); |
649 |
list = NULL; |
650 |
|
651 |
value_array = g_value_get_boxed (persons); |
652 |
|
653 |
if (value_array == NULL) { |
654 |
return; |
655 |
} |
656 |
|
657 |
for (i = 0; i < value_array->n_values; i++) { |
658 |
list = g_slist_prepend (list, g_value_dup_string (&value_array->values[i])); |
659 |
} |
660 |
|
661 |
list = g_slist_reverse (list); |
662 |
|
663 |
switch (prop_id) { |
664 |
case PROP_AUTHORS: |
665 |
about->_priv->authors = list; |
666 |
break; |
667 |
case PROP_DOCUMENTERS: |
668 |
about->_priv->documenters = list; |
669 |
break; |
670 |
default: |
671 |
g_assert_not_reached (); |
672 |
} |
673 |
} |
674 |
|
675 |
static void |
676 |
set_value_array_from_list (GValue *value, GSList *list) |
677 |
{ |
678 |
GValueArray *array; |
679 |
GValue tmp_value = { 0 }; |
680 |
GSList *tmp; |
681 |
gint length; |
682 |
|
683 |
length = g_slist_length (list); |
684 |
array = g_value_array_new (length); |
685 |
|
686 |
for (tmp = list; tmp; tmp = tmp->next) { |
687 |
char *str = tmp->data; |
688 |
|
689 |
g_value_init (&tmp_value, G_TYPE_STRING); |
690 |
g_value_set_string (&tmp_value, str); |
691 |
g_value_array_append (array, &tmp_value); |
692 |
} |
693 |
|
694 |
g_value_set_boxed (value, array); |
695 |
g_value_array_free (array); |
696 |
} |
697 |
|
698 |
static void |
699 |
gnome_about_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) |
700 |
{ |
701 |
switch (prop_id) { |
702 |
case PROP_NAME: |
703 |
gnome_about_set_name (GNOME_ABOUT (object), g_value_get_string (value)); |
704 |
break; |
705 |
case PROP_VERSION: |
706 |
gnome_about_set_version (GNOME_ABOUT (object), g_value_get_string (value)); |
707 |
break; |
708 |
case PROP_COMMENTS: |
709 |
gnome_about_set_comments (GNOME_ABOUT (object), g_value_get_string (value)); |
710 |
break; |
711 |
case PROP_COPYRIGHT: |
712 |
gnome_about_set_copyright (GNOME_ABOUT (object), g_value_get_string (value)); |
713 |
break; |
714 |
case PROP_LOGO: |
715 |
if (g_value_get_object (value) != NULL) { |
716 |
gtk_image_set_from_pixbuf (GTK_IMAGE (GNOME_ABOUT (object)->_priv->logo_image), |
717 |
g_value_get_object (value)); |
718 |
} |
719 |
else { |
720 |
} |
721 |
break; |
722 |
case PROP_AUTHORS: |
723 |
case PROP_DOCUMENTERS: |
724 |
gnome_about_set_persons (GNOME_ABOUT (object), prop_id, value); |
725 |
break; |
726 |
case PROP_TRANSLATOR_CREDITS: |
727 |
gnome_about_set_translator_credits (GNOME_ABOUT (object), g_value_get_string (value)); |
728 |
break; |
729 |
default: |
730 |
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); |
731 |
break; |
732 |
} |
733 |
} |
734 |
|
735 |
static void |
736 |
gnome_about_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) |
737 |
{ |
738 |
GnomeAbout *about; |
739 |
|
740 |
about = GNOME_ABOUT (object); |
741 |
|
742 |
switch (prop_id) { |
743 |
case PROP_NAME: |
744 |
g_value_set_string (value, about->_priv->name); |
745 |
break; |
746 |
case PROP_VERSION: |
747 |
g_value_set_string (value, about->_priv->version); |
748 |
break; |
749 |
case PROP_COPYRIGHT: |
750 |
g_value_set_string (value, about->_priv->copyright); |
751 |
break; |
752 |
case PROP_COMMENTS: |
753 |
g_value_set_string (value, about->_priv->comments); |
754 |
break; |
755 |
case PROP_TRANSLATOR_CREDITS: |
756 |
g_value_set_string (value, about->_priv->translator_credits); |
757 |
break; |
758 |
case PROP_AUTHORS: |
759 |
set_value_array_from_list (value, about->_priv->authors); |
760 |
break; |
761 |
case PROP_DOCUMENTERS: |
762 |
set_value_array_from_list (value, about->_priv->documenters); |
763 |
break; |
764 |
case PROP_LOGO: |
765 |
g_value_set_object (value, gtk_image_get_pixbuf (GTK_IMAGE (about->_priv->logo_image))); |
766 |
break; |
767 |
default: |
768 |
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); |
769 |
break; |
770 |
} |
771 |
} |
772 |
|
773 |
/** |
774 |
* gnome_about_new: |
775 |
* @name: The name of the application. |
776 |
* @version: The version string of the application. |
777 |
* @copyright: The application's copyright statement. |
778 |
* @comments: A short miscellaneous string. |
779 |
* @authors: An %NULL terminated array of the application authors. |
780 |
* @documenters: An array of the application documenters. |
781 |
* @translator_credits: The translator for the current locale. |
782 |
* @logo_pixbuf: The application's logo. |
783 |
* |
784 |
* Construct an application's credits box. The @authors array cannot be empty |
785 |
* and the @translator_credits should be marked as a translatable string (so |
786 |
* that only the translator for the currently active locale is displayed). |
787 |
* |
788 |
* Returns: A new "About" dialog. |
789 |
*/ |
790 |
GtkWidget * |
791 |
gnome_about_new (const gchar *name, |
792 |
const gchar *version, |
793 |
const gchar *copyright, |
794 |
const gchar *comments, |
795 |
const gchar **authors, |
796 |
const gchar **documenters, |
797 |
const gchar *translator_credits, |
798 |
GdkPixbuf *logo_pixbuf) |
799 |
{ |
800 |
GnomeAbout *about; |
801 |
|
802 |
g_return_val_if_fail (authors != NULL, NULL); |
803 |
|
804 |
about = g_object_new (GNOME_TYPE_ABOUT, NULL); |
805 |
gnome_about_construct(about, |
806 |
name, version, copyright, |
807 |
comments, authors, documenters, |
808 |
translator_credits, logo_pixbuf); |
809 |
|
810 |
return GTK_WIDGET(about); |
811 |
} |
812 |
|
813 |
/** |
814 |
* gnome_about_construct: |
815 |
* @about: An existing #GnomeAbout instance. |
816 |
* @name: The name of the application. |
817 |
* @version: The version string of the application. |
818 |
* @copyright: The application's copyright statement. |
819 |
* @comments: A short miscellaneous string. |
820 |
* @authors: An %NULL terminated array of the application authors. |
821 |
* @documenters: An array of the application documenters. |
822 |
* @translator_credits: The translator for the current locale. |
823 |
* @logo_pixbuf: The application's logo. |
824 |
* |
825 |
* Similar to gnome_about_new() except that the pre-existing @about widget is |
826 |
* used. Note that in this version of the function, @authors is not checked to |
827 |
* be non-%NULL, so callers must be careful, since bad things will happen if |
828 |
* this condition is not met. |
829 |
*/ |
830 |
void |
831 |
gnome_about_construct (GnomeAbout *about, |
832 |
const gchar *name, |
833 |
const gchar *version, |
834 |
const gchar *copyright, |
835 |
const gchar *comments, |
836 |
const gchar **authors, |
837 |
const gchar **documenters, |
838 |
const gchar *translator_credits, |
839 |
GdkPixbuf *logo_pixbuf) |
840 |
{ |
841 |
GValueArray *authors_array; |
842 |
GValueArray *documenters_array; |
843 |
gint i; |
844 |
|
845 |
authors_array = g_value_array_new (0); |
846 |
|
847 |
for (i = 0; authors[i] != NULL; i++) { |
848 |
GValue value = {0, }; |
849 |
|
850 |
g_value_init (&value, G_TYPE_STRING); |
851 |
g_value_set_static_string (&value, authors[i]); |
852 |
authors_array = g_value_array_append (authors_array, &value); |
853 |
} |
854 |
|
855 |
if (documenters != NULL) { |
856 |
documenters_array = g_value_array_new (0); |
857 |
|
858 |
for (i = 0; documenters[i] != NULL; i++) { |
859 |
GValue value = {0, }; |
860 |
|
861 |
g_value_init (&value, G_TYPE_STRING); |
862 |
g_value_set_static_string (&value, documenters[i]); |
863 |
documenters_array = g_value_array_append (documenters_array, &value); |
864 |
} |
865 |
|
866 |
} |
867 |
else { |
868 |
documenters_array = NULL; |
869 |
} |
870 |
|
871 |
g_object_set (G_OBJECT (about), |
872 |
"name", name, |
873 |
"version", version, |
874 |
"copyright", copyright, |
875 |
"comments", comments, |
876 |
"authors", authors_array, |
877 |
"documenters", documenters_array, |
878 |
"translator_credits", translator_credits, |
879 |
"logo", logo_pixbuf, |
880 |
NULL); |
881 |
|
882 |
if (authors_array != NULL) { |
883 |
g_value_array_free (authors_array); |
884 |
} |
885 |
if (documenters_array != NULL) { |
886 |
g_value_array_free (documenters_array); |
887 |
} |
888 |
} |