Mercurial > mplayer.hg
annotate gui/dialog/dialog.c @ 35977:3734172b4af6
Cosmetic: Rename ShowAboutBox() ShowAbout().
author | ib |
---|---|
date | Thu, 28 Mar 2013 17:02:47 +0000 |
parents | 6eaf7941b762 |
children | 6dfdebfa72b7 |
rev | line source |
---|---|
26458 | 1 /* |
2 * This file is part of MPlayer. | |
3 * | |
4 * MPlayer is free software; you can redistribute it and/or modify | |
5 * it under the terms of the GNU General Public License as published by | |
6 * the Free Software Foundation; either version 2 of the License, or | |
7 * (at your option) any later version. | |
8 * | |
9 * MPlayer is distributed in the hope that it will be useful, | |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 * GNU General Public License for more details. | |
13 * | |
14 * You should have received a copy of the GNU General Public License along | |
15 * with MPlayer; if not, write to the Free Software Foundation, Inc., | |
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | |
17 */ | |
23077 | 18 |
19 #include <stdlib.h> | |
20 #include <stdio.h> | |
35361
3e8dcfa3ceef
Prevent unintended sign extension from int to long on 64-bit machines.
ib
parents:
34781
diff
changeset
|
21 #include <stdint.h> |
23077 | 22 |
23 #include <sys/types.h> | |
24 #include <sys/stat.h> | |
25 #include <sys/wait.h> | |
26 #include <unistd.h> | |
27 #include <string.h> | |
28 #include <signal.h> | |
29 | |
30 #include <gdk/gdkprivate.h> | |
31 #include <gdk/gdkkeysyms.h> | |
32 #include <gdk/gdkx.h> | |
33 #include <gdk/gdk.h> | |
34 #include <gtk/gtk.h> | |
35 | |
26382
b2f4abcf20ed
Make include paths consistent; do not use ../ in them.
diego
parents:
26365
diff
changeset
|
36 #include "config.h" |
b2f4abcf20ed
Make include paths consistent; do not use ../ in them.
diego
parents:
26365
diff
changeset
|
37 #include "help_mp.h" |
b2f4abcf20ed
Make include paths consistent; do not use ../ in them.
diego
parents:
26365
diff
changeset
|
38 #include "mp_msg.h" |
33542 | 39 #include "libavutil/intreadwrite.h" |
33465 | 40 #include "libvo/x11_common.h" |
26382
b2f4abcf20ed
Make include paths consistent; do not use ../ in them.
diego
parents:
26365
diff
changeset
|
41 |
35529 | 42 #include "dialog.h" |
35525 | 43 #include "gui/app/app.h" |
44 #include "gui/app/gui.h" | |
33466 | 45 #include "gui/interface.h" |
35873
65f7b2fdda46
Add a warning message about @locale in G_FILENAME_ENCODING.
ib
parents:
35703
diff
changeset
|
46 #include "gui/util/string.h" |
26365
10dfbc523184
Add gui/ prefix to some #include paths so that compilation from the
diego
parents:
26203
diff
changeset
|
47 #include "gui/wm/ws.h" |
23077 | 48 |
35529 | 49 #include "gui/ui/actions.h" |
50 #include "fileselect.h" | |
23077 | 51 |
35623
46b3d0bb76e0
Make variables static that are only used inside the file.
ib
parents:
35529
diff
changeset
|
52 static GtkWidget *PopUpMenu; |
23077 | 53 |
33538 | 54 GtkWidget *WarningPixmap; |
55 GtkWidget *ErrorPixmap; | |
23077 | 56 |
35624 | 57 int gtkPopupMenu; |
58 int gtkPopupMenuParam; | |
35623
46b3d0bb76e0
Make variables static that are only used inside the file.
ib
parents:
35529
diff
changeset
|
59 static int gtkInitialized; |
23077 | 60 |
35529 | 61 #include "skinbrowser.h" |
62 #include "playlist.h" | |
63 #include "msgbox.h" | |
64 #include "about.h" | |
65 #include "preferences.h" | |
66 #include "menu.h" | |
67 #include "url.h" | |
68 #include "equalizer.h" | |
23077 | 69 |
34596
04feb00f91be
Prefer static const char arrays for string constants to #defines.
ib
parents:
34481
diff
changeset
|
70 static const char gui_icon_name[] = "mplayer"; |
23077 | 71 |
33542 | 72 #define THRESHOLD 128 // transparency values equal to or above this will become |
73 // opaque, all values below this will become transparent | |
74 | |
33529 | 75 guiIcon_t guiIcon; |
23077 | 76 |
35643 | 77 /** |
78 * @brief Add an icon to the #guiIcon icon structure. | |
79 * | |
80 * @param theme theme to load the icon from | |
81 * @param size size of the icon to load | |
82 * @param gdkIcon location to store a pointer to the created pixmap | |
83 * @param gdkIconMask location to store a pointer to the created mask | |
84 * | |
85 * @return #True (ok) or #False (error) | |
86 */ | |
34780 | 87 static int gtkLoadIcon(GtkIconTheme *theme, gint size, GdkPixmap **gdkIcon, GdkBitmap **gdkIconMask) |
34480 | 88 { |
89 GdkPixbuf *pixbuf; | |
90 guchar *data; | |
91 int csize, i; | |
92 | |
34596
04feb00f91be
Prefer static const char arrays for string constants to #defines.
ib
parents:
34481
diff
changeset
|
93 pixbuf = gtk_icon_theme_load_icon(theme, gui_icon_name, size, 0, NULL); |
34480 | 94 |
95 if (pixbuf) | |
96 gdk_pixbuf_render_pixmap_and_mask_for_colormap(pixbuf, gdk_colormap_get_system(), gdkIcon, gdkIconMask, THRESHOLD); | |
97 | |
98 if (pixbuf && | |
99 gdk_pixbuf_get_colorspace(pixbuf) == GDK_COLORSPACE_RGB && | |
100 gdk_pixbuf_get_n_channels(pixbuf) == 4 && | |
101 gdk_pixbuf_get_bits_per_sample(pixbuf) == 8) { | |
102 csize = guiIcon.collection_size; | |
103 guiIcon.collection_size += 2 + gdk_pixbuf_get_width(pixbuf) * gdk_pixbuf_get_height(pixbuf); | |
104 | |
105 guiIcon.collection = realloc(guiIcon.collection, guiIcon.collection_size * sizeof(*guiIcon.collection)); | |
106 | |
107 if (guiIcon.collection) { | |
108 guiIcon.collection[csize++] = gdk_pixbuf_get_width(pixbuf); | |
109 guiIcon.collection[csize++] = gdk_pixbuf_get_height(pixbuf); | |
110 | |
111 data = gdk_pixbuf_get_pixels(pixbuf); | |
112 | |
113 for (i = csize; i < guiIcon.collection_size; data += 4, i++) | |
35703 | 114 guiIcon.collection[i] = (uint32_t)(data[3] << 24) | AV_RB24(data); // RGBA -> ARGB |
34480 | 115 } |
116 | |
117 g_object_unref(pixbuf); | |
118 } else | |
34596
04feb00f91be
Prefer static const char arrays for string constants to #defines.
ib
parents:
34481
diff
changeset
|
119 mp_msg(MSGT_GPLAYER, MSGL_WARN, MSGTR_ICONERROR, gui_icon_name, size); |
34480 | 120 |
34684 | 121 /* start up GTK which realizes the pixmaps */ |
34480 | 122 gtk_main_iteration_do(FALSE); |
34780 | 123 |
124 return (pixbuf != NULL); | |
34480 | 125 } |
126 | |
35643 | 127 /** |
128 * @brief Initialize the GTK user interface. | |
129 * | |
130 * @param display_name name of the X display to use or NULL (using the DISPLAY environment variable) | |
131 */ | |
35629 | 132 void gtkInit(char *display_name) |
23077 | 133 { |
34480 | 134 int argc = 0; |
33538 | 135 char *arg[3], **argv = arg; |
35873
65f7b2fdda46
Add a warning message about @locale in G_FILENAME_ENCODING.
ib
parents:
35703
diff
changeset
|
136 #ifdef CONFIG_GTK2 |
65f7b2fdda46
Add a warning message about @locale in G_FILENAME_ENCODING.
ib
parents:
35703
diff
changeset
|
137 char *env; |
65f7b2fdda46
Add a warning message about @locale in G_FILENAME_ENCODING.
ib
parents:
35703
diff
changeset
|
138 #endif |
34480 | 139 GtkIconTheme *theme; |
33538 | 140 GdkPixmap *gdkIcon; |
141 GdkBitmap *gdkIconMask; | |
33465 | 142 |
33538 | 143 mp_msg(MSGT_GPLAYER, MSGL_V, "GTK init.\n"); |
33528 | 144 |
33538 | 145 arg[argc++] = GMPlayer; |
33465 | 146 |
35703 | 147 if (display_name) { // MPlayer option '-display' was given |
148 arg[argc++] = "--display"; // Pass corresponding command line arguments to GTK, | |
35629 | 149 arg[argc++] = display_name; // to open the requested display for the GUI, too. |
33538 | 150 } |
33465 | 151 |
27343 | 152 #ifdef CONFIG_GTK2 |
33538 | 153 gtk_disable_setlocale(); |
35873
65f7b2fdda46
Add a warning message about @locale in G_FILENAME_ENCODING.
ib
parents:
35703
diff
changeset
|
154 |
65f7b2fdda46
Add a warning message about @locale in G_FILENAME_ENCODING.
ib
parents:
35703
diff
changeset
|
155 env = getenv("G_FILENAME_ENCODING"); |
65f7b2fdda46
Add a warning message about @locale in G_FILENAME_ENCODING.
ib
parents:
35703
diff
changeset
|
156 |
65f7b2fdda46
Add a warning message about @locale in G_FILENAME_ENCODING.
ib
parents:
35703
diff
changeset
|
157 if ((!env && getenv("G_BROKEN_FILENAMES")) || (gstrncmp(env, "@locale", 7) == 0)) |
65f7b2fdda46
Add a warning message about @locale in G_FILENAME_ENCODING.
ib
parents:
35703
diff
changeset
|
158 mp_msg(MSGT_GPLAYER, MSGL_WARN, MSGTR_LOCALE_ENCODING); |
23077 | 159 #endif |
33528 | 160 |
33538 | 161 gtk_init(&argc, &argv); |
35703 | 162 wsSetErrorHandler(); // GDK has just set its own handler |
33538 | 163 |
34480 | 164 theme = gtk_icon_theme_get_default(); |
33542 | 165 |
34780 | 166 if (gtkLoadIcon(theme, 16, &gdkIcon, &gdkIconMask)) { |
34781 | 167 guiIcon.small = GDK_PIXMAP_XID(gdkIcon); |
168 guiIcon.small_mask = GDK_PIXMAP_XID(gdkIconMask); | |
34780 | 169 } |
33542 | 170 |
34780 | 171 if (gtkLoadIcon(theme, 32, &gdkIcon, &gdkIconMask)) { |
34781 | 172 guiIcon.normal = GDK_PIXMAP_XID(gdkIcon); |
173 guiIcon.normal_mask = GDK_PIXMAP_XID(gdkIconMask); | |
34780 | 174 } |
23077 | 175 |
34480 | 176 gtkLoadIcon(theme, 48, &gdkIcon, &gdkIconMask); |
177 | |
35493 | 178 gtkInitialized = True; |
33538 | 179 } |
23077 | 180 |
35643 | 181 /** |
182 * @brief Add the #guiIcon icons to a GTK window. | |
183 * | |
184 * @param window pointer to a GtkWindow widget | |
185 */ | |
33538 | 186 void gtkAddIcon(GtkWidget *window) |
187 { | |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35643
diff
changeset
|
188 wsWindowIcon(gdk_display, GDK_WINDOW_XWINDOW(window->window), &guiIcon); |
33538 | 189 } |
23077 | 190 |
33538 | 191 void gtkClearList(GtkWidget *list) |
192 { | |
193 gtk_clist_clear(GTK_CLIST(list)); | |
23077 | 194 } |
195 | |
33538 | 196 int gtkFindCList(GtkWidget *list, char *item) |
23077 | 197 { |
33538 | 198 gint j; |
199 gchar *tmpstr; | |
200 | |
201 for (j = 0; j < GTK_CLIST(list)->rows; j++) { | |
202 gtk_clist_get_text(GTK_CLIST(list), j, 0, &tmpstr); | |
203 | |
204 if (!strcmp(tmpstr, item)) | |
205 return j; | |
206 } | |
207 | |
208 return -1; | |
23077 | 209 } |
210 | |
33538 | 211 void gtkSetDefaultToCList(GtkWidget *list, char *item) |
23077 | 212 { |
33538 | 213 gint i; |
214 | |
215 if ((i = gtkFindCList(list, item)) > -1) | |
216 gtk_clist_select_row(GTK_CLIST(list), i, 0); | |
23077 | 217 } |
218 | |
33538 | 219 void gtkEventHandling(void) |
23077 | 220 { |
33538 | 221 int i; |
222 | |
223 for (i = 0; i < 25; i++) | |
224 gtk_main_iteration_do(0); | |
23077 | 225 } |
226 | |
34684 | 227 /* funcs */ |
23077 | 228 |
33538 | 229 void gtkMessageBox(int type, const gchar *str) |
23077 | 230 { |
33538 | 231 if (!gtkInitialized) |
232 return; | |
233 | |
234 ShowMessageBox(str); | |
235 gtk_label_set_text(GTK_LABEL(gtkMessageBoxText), str); | |
236 | |
237 /* enable linewrapping by alex */ | |
23077 | 238 // GTK_LABEL(gtkMessageBoxText)->max_width = 80; |
33538 | 239 if (strlen(str) > 80) |
240 gtk_label_set_line_wrap(GTK_LABEL(gtkMessageBoxText), TRUE); | |
241 else | |
242 gtk_label_set_line_wrap(GTK_LABEL(gtkMessageBoxText), FALSE); | |
243 | |
244 switch (type) { | |
23077 | 245 case GTK_MB_FATAL: |
33538 | 246 gtk_window_set_title(GTK_WINDOW(MessageBox), MSGTR_MSGBOX_LABEL_FatalError); |
247 gtk_widget_hide(WarningPixmap); | |
248 gtk_widget_show(ErrorPixmap); | |
249 break; | |
250 | |
23077 | 251 case GTK_MB_ERROR: |
33538 | 252 gtk_window_set_title(GTK_WINDOW(MessageBox), MSGTR_MSGBOX_LABEL_Error); |
253 gtk_widget_hide(WarningPixmap); | |
254 gtk_widget_show(ErrorPixmap); | |
255 break; | |
256 | |
23077 | 257 case GTK_MB_WARNING: |
33538 | 258 gtk_window_set_title(GTK_WINDOW(MessageBox), MSGTR_MSGBOX_LABEL_Warning); |
259 gtk_widget_show(WarningPixmap); | |
260 gtk_widget_hide(ErrorPixmap); | |
261 break; | |
262 } | |
263 | |
264 gtk_widget_show(MessageBox); | |
265 gtkSetLayer(MessageBox); | |
266 | |
267 if (type == GTK_MB_FATAL) | |
268 while (MessageBox) | |
269 gtk_main_iteration_do(0); | |
23077 | 270 } |
271 | |
35643 | 272 /** |
273 * @brief Set the layer for a GTK window. | |
274 * | |
275 * @param window pointer to a GtkWindow widget | |
276 */ | |
35638
78d9cfd68b34
Cosmetic: Use parameter name 'window' for a GtkWindow.
ib
parents:
35636
diff
changeset
|
277 void gtkSetLayer(GtkWidget *window) |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
27343
diff
changeset
|
278 { |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35643
diff
changeset
|
279 wsWindowLayer(gdk_display, GDK_WINDOW_XWINDOW(window->window), guiApp.videoWindow.isFullScreen); |
35638
78d9cfd68b34
Cosmetic: Use parameter name 'window' for a GtkWindow.
ib
parents:
35636
diff
changeset
|
280 gtkActive(window); |
33538 | 281 } |
282 | |
35643 | 283 /** |
284 * @brief Activate a GTK window, i.e. raise it to the top. | |
285 * | |
286 * @param window pointer to a GtkWindow widget | |
287 */ | |
35638
78d9cfd68b34
Cosmetic: Use parameter name 'window' for a GtkWindow.
ib
parents:
35636
diff
changeset
|
288 void gtkActive(GtkWidget *window) |
33538 | 289 { |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35643
diff
changeset
|
290 wsWindowRaiseTop(gdk_display, GDK_WINDOW_XWINDOW(window->window)); |
23077 | 291 } |
292 | |
33538 | 293 void gtkShow(int type, char *param) |
23077 | 294 { |
33538 | 295 switch (type) { |
296 case evEqualizer: | |
297 ShowEqualizer(); | |
298 gtkSetLayer(Equalizer); | |
299 break; | |
300 | |
301 case evSkinBrowser: | |
302 ShowSkinBrowser(); | |
303 | |
23077 | 304 // gtkClearList( SkinList ); |
33538 | 305 if (gtkFillSkinList(sbMPlayerPrefixDir) && |
306 gtkFillSkinList(sbMPlayerDirInHome)) { | |
307 gtkSetDefaultToCList(SkinList, param); | |
308 gtk_clist_sort(GTK_CLIST(SkinList)); | |
309 gtk_widget_show(SkinBrowser); | |
310 gtkSetLayer(SkinBrowser); | |
311 } else { | |
312 gtk_widget_destroy(SkinBrowser); | |
313 gtkMessageBox(GTK_MB_ERROR, "Skin dirs not found ... Please install skins."); | |
314 } | |
315 | |
23077 | 316 break; |
33538 | 317 |
318 case evPreferences: | |
23077 | 319 ShowPreferences(); |
320 break; | |
33538 | 321 |
34321
daebf766dea6
Cosmetic: Synchronize evPlaylist event and message names.
ib
parents:
33990
diff
changeset
|
322 case evPlaylist: |
23077 | 323 ShowPlayList(); |
33538 | 324 gtkSetLayer(PlayList); |
23077 | 325 break; |
33538 | 326 |
327 case evLoad: | |
35976 | 328 ShowFileSelector(FILESELECT_VIDEO_AUDIO); |
35975 | 329 gtkSetLayer(FileSelector); |
23077 | 330 break; |
33538 | 331 |
332 case evLoadSubtitle: | |
35976 | 333 ShowFileSelector(FILESELECT_SUBTITLE); |
35975 | 334 gtkSetLayer(FileSelector); |
23077 | 335 break; |
33538 | 336 |
337 case evLoadAudioFile: | |
35976 | 338 ShowFileSelector(FILESELECT_AUDIO); |
35975 | 339 gtkSetLayer(FileSelector); |
33538 | 340 break; |
341 | |
342 case evAbout: | |
35977 | 343 ShowAbout(); |
33538 | 344 gtkSetLayer(About); |
23077 | 345 break; |
33538 | 346 |
34333 | 347 case ivShowPopUpMenu: |
33538 | 348 gtkPopupMenu = evNone; |
349 gtkPopupMenuParam = 0; | |
350 | |
351 if (PopUpMenu) { | |
352 gtk_widget_hide(PopUpMenu); | |
353 gtk_widget_destroy(PopUpMenu); | |
354 } | |
355 | |
356 PopUpMenu = create_PopUpMenu(); | |
357 gtk_menu_popup(GTK_MENU(PopUpMenu), NULL, NULL, NULL, NULL, 0, 0); | |
23077 | 358 break; |
33538 | 359 |
34333 | 360 case ivHidePopUpMenu: |
33538 | 361 |
362 if (PopUpMenu) { | |
363 gtk_widget_hide(PopUpMenu); | |
364 gtk_widget_destroy(PopUpMenu); | |
365 PopUpMenu = NULL; | |
366 } | |
367 | |
23077 | 368 break; |
33538 | 369 |
34329 | 370 case evLoadURL: |
33538 | 371 ShowURLDialogBox(); |
372 gtkSetLayer(URL); | |
373 break; | |
374 } | |
23077 | 375 } |