Mercurial > audlegacy
annotate src/audacious/ui_about.c @ 4026:17bf734f8187
avoid crash when audacious is launched with -p option.
author | Yoshiki Yazawa <yaz@cc.rim.or.jp> |
---|---|
date | Wed, 28 Nov 2007 06:01:28 +0900 |
parents | b5ee3a4a8e3b |
children | c9fb06a5688e |
rev | line source |
---|---|
2313 | 1 /* |
2890
fb9a8b312879
Backed out changeset fcf6f1b82f7ca0e1bef37c6c85df283eb71a1118
William Pitcock <nenolod@atheme.org>
parents:
2864
diff
changeset
|
2 * Audacious - Cross-platform multimedia player |
fb9a8b312879
Backed out changeset fcf6f1b82f7ca0e1bef37c6c85df283eb71a1118
William Pitcock <nenolod@atheme.org>
parents:
2864
diff
changeset
|
3 * Copyright (C) 2005-2007 Audacious development team |
2313 | 4 * |
2890
fb9a8b312879
Backed out changeset fcf6f1b82f7ca0e1bef37c6c85df283eb71a1118
William Pitcock <nenolod@atheme.org>
parents:
2864
diff
changeset
|
5 * Based on BMP: |
fb9a8b312879
Backed out changeset fcf6f1b82f7ca0e1bef37c6c85df283eb71a1118
William Pitcock <nenolod@atheme.org>
parents:
2864
diff
changeset
|
6 * Copyright (C) 2003-2004 BMP development team |
2313 | 7 * |
2890
fb9a8b312879
Backed out changeset fcf6f1b82f7ca0e1bef37c6c85df283eb71a1118
William Pitcock <nenolod@atheme.org>
parents:
2864
diff
changeset
|
8 * Based on XMMS: |
fb9a8b312879
Backed out changeset fcf6f1b82f7ca0e1bef37c6c85df283eb71a1118
William Pitcock <nenolod@atheme.org>
parents:
2864
diff
changeset
|
9 * Copyright (C) 1998-2003 XMMS development team |
2313 | 10 * |
2890
fb9a8b312879
Backed out changeset fcf6f1b82f7ca0e1bef37c6c85df283eb71a1118
William Pitcock <nenolod@atheme.org>
parents:
2864
diff
changeset
|
11 * This program is free software; you can redistribute it and/or modify |
fb9a8b312879
Backed out changeset fcf6f1b82f7ca0e1bef37c6c85df283eb71a1118
William Pitcock <nenolod@atheme.org>
parents:
2864
diff
changeset
|
12 * it under the terms of the GNU General Public License as published by |
3121
3b6d316f8b09
GPL3 relicensing.
William Pitcock <nenolod@atheme-project.org>
parents:
2890
diff
changeset
|
13 * the Free Software Foundation; under version 3 of the License. |
2313 | 14 * |
2890
fb9a8b312879
Backed out changeset fcf6f1b82f7ca0e1bef37c6c85df283eb71a1118
William Pitcock <nenolod@atheme.org>
parents:
2864
diff
changeset
|
15 * This program is distributed in the hope that it will be useful, |
fb9a8b312879
Backed out changeset fcf6f1b82f7ca0e1bef37c6c85df283eb71a1118
William Pitcock <nenolod@atheme.org>
parents:
2864
diff
changeset
|
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
fb9a8b312879
Backed out changeset fcf6f1b82f7ca0e1bef37c6c85df283eb71a1118
William Pitcock <nenolod@atheme.org>
parents:
2864
diff
changeset
|
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
fb9a8b312879
Backed out changeset fcf6f1b82f7ca0e1bef37c6c85df283eb71a1118
William Pitcock <nenolod@atheme.org>
parents:
2864
diff
changeset
|
18 * GNU General Public License for more details. |
fb9a8b312879
Backed out changeset fcf6f1b82f7ca0e1bef37c6c85df283eb71a1118
William Pitcock <nenolod@atheme.org>
parents:
2864
diff
changeset
|
19 * |
fb9a8b312879
Backed out changeset fcf6f1b82f7ca0e1bef37c6c85df283eb71a1118
William Pitcock <nenolod@atheme.org>
parents:
2864
diff
changeset
|
20 * You should have received a copy of the GNU General Public License |
3121
3b6d316f8b09
GPL3 relicensing.
William Pitcock <nenolod@atheme-project.org>
parents:
2890
diff
changeset
|
21 * along with this program. If not, see <http://www.gnu.org/licenses>. |
3123
f1c756f39e6c
Invoke "Plugins are not derived work" clause provided by GPL3.
William Pitcock <nenolod@atheme-project.org>
parents:
3121
diff
changeset
|
22 * |
f1c756f39e6c
Invoke "Plugins are not derived work" clause provided by GPL3.
William Pitcock <nenolod@atheme-project.org>
parents:
3121
diff
changeset
|
23 * The Audacious team does not consider modular code linking to |
f1c756f39e6c
Invoke "Plugins are not derived work" clause provided by GPL3.
William Pitcock <nenolod@atheme-project.org>
parents:
3121
diff
changeset
|
24 * Audacious or using our public API to be a derived work. |
2313 | 25 */ |
26 | |
27 #ifdef HAVE_CONFIG_H | |
28 # include "config.h" | |
29 #endif | |
30 | |
31 #include "ui_credits.h" | |
32 | |
33 #include <glib.h> | |
34 #include <glib/gi18n.h> | |
35 #include <gtk/gtk.h> | |
36 | |
37 #include "platform/smartinclude.h" | |
38 | |
39 static GtkWidget *about_window = NULL; | |
40 static GdkPixbuf *about_pixbuf = NULL; | |
41 static GdkPixmap *mask_pixmap_window1 = NULL, | |
42 *mask_pixmap_window2 = NULL; | |
43 static GdkBitmap *mask_bitmap_window1 = NULL, | |
44 *mask_bitmap_window2 = NULL; | |
45 | |
46 static const gchar *audacious_brief = N_("<big><b>Audacious %s</b></big>\n\n" | |
47 "Copyright (C) 2005-2007 Audacious Development Team"); | |
48 | |
49 static gboolean | |
50 on_about_window_expose(GtkWidget *widget, GdkEventExpose *expose, gpointer data) | |
51 { | |
52 g_return_val_if_fail(GTK_IS_WIDGET (widget), FALSE); | |
53 | |
54 gdk_window_set_back_pixmap(GDK_WINDOW(widget->window), mask_pixmap_window2, 0); | |
55 gdk_window_clear(GDK_WINDOW(widget->window)); | |
56 | |
57 return FALSE; | |
58 } | |
59 | |
60 static gboolean | |
61 on_about_window_key_press (GtkWidget *widget, GdkEventKey *event, gpointer data) | |
62 { | |
63 g_return_val_if_fail(GTK_IS_WIDGET (widget), FALSE); | |
64 | |
65 if (event->keyval == GDK_Escape) | |
66 { | |
67 gtk_widget_hide(widget); | |
68 } | |
69 | |
70 return FALSE; | |
71 } | |
72 | |
73 static gboolean | |
74 on_close_button_clicked (GtkWidget *widget, gpointer data) | |
75 { | |
76 g_return_val_if_fail(GTK_IS_WIDGET (widget), FALSE); | |
77 | |
78 gtk_widget_hide(about_window); | |
79 | |
80 return FALSE; | |
81 } | |
82 | |
83 static gboolean | |
84 on_credits_button_clicked (GtkWidget *widget, gpointer data) | |
85 { | |
86 g_return_val_if_fail(GTK_IS_WIDGET (widget), FALSE); | |
87 | |
88 show_credits_window(); | |
89 | |
90 return FALSE; | |
91 } | |
92 | |
93 void | |
94 show_about_window(void) | |
95 { | |
96 GtkWidget *about_fixedbox; | |
97 GtkWidget *close_button; | |
98 GtkWidget *credits_button , *credits_button_hbox, *credits_button_image, *credits_button_label; | |
99 GtkWidget *brief_label; | |
100 gchar *filename = DATA_DIR G_DIR_SEPARATOR_S "images" G_DIR_SEPARATOR_S "about-logo.png"; | |
101 gchar *text; | |
102 PangoAttrList *brief_label_attrs; | |
103 PangoAttribute *brief_label_foreground; | |
104 | |
105 if (about_window != NULL) | |
106 { | |
107 gtk_window_present(GTK_WINDOW(about_window)); | |
108 return; | |
109 } | |
110 | |
111 about_window = gtk_window_new(GTK_WINDOW_TOPLEVEL); | |
112 | |
113 g_signal_connect(about_window, "destroy", | |
114 G_CALLBACK(gtk_widget_destroyed), &about_window); | |
115 | |
116 gtk_widget_realize(about_window); | |
117 | |
118 about_pixbuf = gdk_pixbuf_new_from_file(filename, NULL); | |
119 | |
120 gtk_widget_set_size_request(GTK_WIDGET (about_window), | |
121 gdk_pixbuf_get_width (about_pixbuf), | |
122 gdk_pixbuf_get_height (about_pixbuf)); | |
123 | |
124 gtk_widget_set_app_paintable(about_window, TRUE); | |
125 gtk_window_set_title(GTK_WINDOW(about_window), _("About Audacious")); | |
126 gtk_window_set_position(GTK_WINDOW(about_window), GTK_WIN_POS_CENTER); | |
127 gtk_window_set_resizable(GTK_WINDOW(about_window), FALSE); | |
128 gtk_window_set_decorated(GTK_WINDOW(about_window), FALSE); | |
129 | |
130 gdk_pixbuf_render_pixmap_and_mask(about_pixbuf, | |
131 &mask_pixmap_window1, | |
132 &mask_bitmap_window1, | |
133 0); | |
134 | |
135 gdk_pixbuf_render_pixmap_and_mask(about_pixbuf, | |
136 &mask_pixmap_window2, | |
137 &mask_bitmap_window2, | |
138 128); | |
139 | |
140 gtk_widget_add_events(about_window, GDK_ALL_EVENTS_MASK); | |
141 | |
142 g_signal_connect(about_window, "expose-event", | |
143 G_CALLBACK(on_about_window_expose), &about_window); | |
144 | |
145 g_signal_connect(about_window, "key-press-event", | |
146 G_CALLBACK(on_about_window_key_press), &about_window); | |
147 | |
148 gtk_widget_shape_combine_mask(GTK_WIDGET(about_window), mask_bitmap_window2, 0, 0); | |
149 | |
150 /* GtkFixed hasn't got its GdkWindow, this means that it can be used to | |
151 display widgets while the logo below will be displayed anyway; | |
152 however fixed positions are not that great, cause the button sizes may (will) | |
153 vary depending on the gtk style used, so it's not possible to center | |
154 them unless a fixed width and heigth is forced (and this may bring to cutted | |
155 text if someone, i.e., uses a big font for gtk widgets); | |
156 other types of container most likely have their GdkWindow, this simply | |
157 means that the logo must be drawn on the container widget, instead of the | |
158 window; otherwise, it won't be displayed correctly */ | |
159 about_fixedbox = gtk_fixed_new(); | |
160 gtk_container_add( GTK_CONTAINER(about_window) , about_fixedbox ); | |
161 | |
162 close_button = gtk_button_new_from_stock(GTK_STOCK_CLOSE); | |
163 | |
164 g_signal_connect(close_button, "clicked", | |
165 G_CALLBACK(on_close_button_clicked), NULL); | |
166 | |
167 gtk_fixed_put( GTK_FIXED(about_fixedbox) , close_button , 375 , 220 ); | |
168 gtk_widget_set_size_request( close_button , 100 , -1 ); | |
169 | |
170 credits_button = gtk_button_new(); | |
171 credits_button_hbox = gtk_hbox_new( FALSE , 0 ); | |
172 credits_button_image = gtk_image_new_from_stock( GTK_STOCK_DIALOG_INFO , GTK_ICON_SIZE_BUTTON ); | |
173 gtk_misc_set_alignment( GTK_MISC(credits_button_image) , 1 , 0.5 ); | |
174 credits_button_label = gtk_label_new( _("Credits") ); | |
175 gtk_misc_set_alignment( GTK_MISC(credits_button_label) , 0 , 0.5 ); | |
176 gtk_box_pack_start( GTK_BOX(credits_button_hbox) , credits_button_image , | |
177 TRUE , TRUE , 2 ); | |
178 gtk_box_pack_start( GTK_BOX(credits_button_hbox) , credits_button_label , | |
179 TRUE , TRUE , 2 ); | |
180 gtk_container_add( GTK_CONTAINER(credits_button) , credits_button_hbox ); | |
181 | |
182 g_signal_connect(credits_button, "clicked", | |
183 G_CALLBACK(on_credits_button_clicked), NULL); | |
184 | |
185 gtk_fixed_put( GTK_FIXED(about_fixedbox) , credits_button , 25 , 220 ); | |
186 gtk_widget_set_size_request( credits_button , 100 , -1 ); | |
187 | |
188 brief_label = gtk_label_new(NULL); | |
189 text = g_strdup_printf(_(audacious_brief), VERSION); | |
190 | |
191 brief_label_foreground = pango_attr_foreground_new(0, 0, 0); | |
192 brief_label_attrs = pango_attr_list_new(); | |
193 pango_attr_list_insert(brief_label_attrs, brief_label_foreground); | |
194 | |
195 gtk_label_set_markup(GTK_LABEL(brief_label), text); | |
196 gtk_label_set_justify(GTK_LABEL(brief_label), GTK_JUSTIFY_CENTER); | |
197 gtk_label_set_attributes(GTK_LABEL(brief_label), brief_label_attrs); | |
198 g_free(text); | |
199 | |
200 gtk_fixed_put(GTK_FIXED(about_fixedbox), brief_label, 20, 145); | |
201 gtk_widget_set_size_request( brief_label , 460 , -1 ); | |
202 | |
203 gtk_widget_show_all(about_window); | |
204 gtk_window_present(GTK_WINDOW(about_window)); | |
205 } | |
3917 | 206 |
207 void | |
208 hide_about_window(void) | |
209 { | |
210 g_return_if_fail(about_window); | |
211 gtk_widget_hide(GTK_WIDGET(about_window)); | |
212 } |