Mercurial > mplayer.hg
annotate gui/dialog/dialog.c @ 36034:e1d1d404ee9e
Move function declaration where it belongs.
Additionally, rename function.
author | ib |
---|---|
date | Mon, 01 Apr 2013 08:14:25 +0000 |
parents | 8ae2e20462a7 |
children | 2421356e2a03 |
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 |
35623
46b3d0bb76e0
Make variables static that are only used inside the file.
ib
parents:
35529
diff
changeset
|
54 static int gtkInitialized; |
23077 | 55 |
35529 | 56 #include "skinbrowser.h" |
57 #include "playlist.h" | |
58 #include "msgbox.h" | |
59 #include "about.h" | |
60 #include "preferences.h" | |
61 #include "menu.h" | |
62 #include "url.h" | |
63 #include "equalizer.h" | |
36024 | 64 #include "tools.h" |
23077 | 65 |
34596
04feb00f91be
Prefer static const char arrays for string constants to #defines.
ib
parents:
34481
diff
changeset
|
66 static const char gui_icon_name[] = "mplayer"; |
23077 | 67 |
33542 | 68 #define THRESHOLD 128 // transparency values equal to or above this will become |
69 // opaque, all values below this will become transparent | |
70 | |
33529 | 71 guiIcon_t guiIcon; |
23077 | 72 |
35643 | 73 /** |
74 * @brief Add an icon to the #guiIcon icon structure. | |
75 * | |
76 * @param theme theme to load the icon from | |
77 * @param size size of the icon to load | |
78 * @param gdkIcon location to store a pointer to the created pixmap | |
79 * @param gdkIconMask location to store a pointer to the created mask | |
80 * | |
81 * @return #True (ok) or #False (error) | |
82 */ | |
34780 | 83 static int gtkLoadIcon(GtkIconTheme *theme, gint size, GdkPixmap **gdkIcon, GdkBitmap **gdkIconMask) |
34480 | 84 { |
85 GdkPixbuf *pixbuf; | |
86 guchar *data; | |
87 int csize, i; | |
88 | |
34596
04feb00f91be
Prefer static const char arrays for string constants to #defines.
ib
parents:
34481
diff
changeset
|
89 pixbuf = gtk_icon_theme_load_icon(theme, gui_icon_name, size, 0, NULL); |
34480 | 90 |
91 if (pixbuf) | |
92 gdk_pixbuf_render_pixmap_and_mask_for_colormap(pixbuf, gdk_colormap_get_system(), gdkIcon, gdkIconMask, THRESHOLD); | |
93 | |
94 if (pixbuf && | |
95 gdk_pixbuf_get_colorspace(pixbuf) == GDK_COLORSPACE_RGB && | |
96 gdk_pixbuf_get_n_channels(pixbuf) == 4 && | |
97 gdk_pixbuf_get_bits_per_sample(pixbuf) == 8) { | |
98 csize = guiIcon.collection_size; | |
99 guiIcon.collection_size += 2 + gdk_pixbuf_get_width(pixbuf) * gdk_pixbuf_get_height(pixbuf); | |
100 | |
101 guiIcon.collection = realloc(guiIcon.collection, guiIcon.collection_size * sizeof(*guiIcon.collection)); | |
102 | |
103 if (guiIcon.collection) { | |
104 guiIcon.collection[csize++] = gdk_pixbuf_get_width(pixbuf); | |
105 guiIcon.collection[csize++] = gdk_pixbuf_get_height(pixbuf); | |
106 | |
107 data = gdk_pixbuf_get_pixels(pixbuf); | |
108 | |
109 for (i = csize; i < guiIcon.collection_size; data += 4, i++) | |
35703 | 110 guiIcon.collection[i] = (uint32_t)(data[3] << 24) | AV_RB24(data); // RGBA -> ARGB |
34480 | 111 } |
112 | |
113 g_object_unref(pixbuf); | |
114 } else | |
34596
04feb00f91be
Prefer static const char arrays for string constants to #defines.
ib
parents:
34481
diff
changeset
|
115 mp_msg(MSGT_GPLAYER, MSGL_WARN, MSGTR_ICONERROR, gui_icon_name, size); |
34480 | 116 |
34684 | 117 /* start up GTK which realizes the pixmaps */ |
34480 | 118 gtk_main_iteration_do(FALSE); |
34780 | 119 |
120 return (pixbuf != NULL); | |
34480 | 121 } |
122 | |
35643 | 123 /** |
124 * @brief Initialize the GTK user interface. | |
125 * | |
126 * @param display_name name of the X display to use or NULL (using the DISPLAY environment variable) | |
127 */ | |
35629 | 128 void gtkInit(char *display_name) |
23077 | 129 { |
34480 | 130 int argc = 0; |
33538 | 131 char *arg[3], **argv = arg; |
35873
65f7b2fdda46
Add a warning message about @locale in G_FILENAME_ENCODING.
ib
parents:
35703
diff
changeset
|
132 #ifdef CONFIG_GTK2 |
65f7b2fdda46
Add a warning message about @locale in G_FILENAME_ENCODING.
ib
parents:
35703
diff
changeset
|
133 char *env; |
65f7b2fdda46
Add a warning message about @locale in G_FILENAME_ENCODING.
ib
parents:
35703
diff
changeset
|
134 #endif |
34480 | 135 GtkIconTheme *theme; |
33538 | 136 GdkPixmap *gdkIcon; |
137 GdkBitmap *gdkIconMask; | |
33465 | 138 |
33538 | 139 mp_msg(MSGT_GPLAYER, MSGL_V, "GTK init.\n"); |
33528 | 140 |
33538 | 141 arg[argc++] = GMPlayer; |
33465 | 142 |
35703 | 143 if (display_name) { // MPlayer option '-display' was given |
144 arg[argc++] = "--display"; // Pass corresponding command line arguments to GTK, | |
35629 | 145 arg[argc++] = display_name; // to open the requested display for the GUI, too. |
33538 | 146 } |
33465 | 147 |
27343 | 148 #ifdef CONFIG_GTK2 |
33538 | 149 gtk_disable_setlocale(); |
35873
65f7b2fdda46
Add a warning message about @locale in G_FILENAME_ENCODING.
ib
parents:
35703
diff
changeset
|
150 |
65f7b2fdda46
Add a warning message about @locale in G_FILENAME_ENCODING.
ib
parents:
35703
diff
changeset
|
151 env = getenv("G_FILENAME_ENCODING"); |
65f7b2fdda46
Add a warning message about @locale in G_FILENAME_ENCODING.
ib
parents:
35703
diff
changeset
|
152 |
65f7b2fdda46
Add a warning message about @locale in G_FILENAME_ENCODING.
ib
parents:
35703
diff
changeset
|
153 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
|
154 mp_msg(MSGT_GPLAYER, MSGL_WARN, MSGTR_LOCALE_ENCODING); |
23077 | 155 #endif |
33528 | 156 |
33538 | 157 gtk_init(&argc, &argv); |
35703 | 158 wsSetErrorHandler(); // GDK has just set its own handler |
33538 | 159 |
34480 | 160 theme = gtk_icon_theme_get_default(); |
33542 | 161 |
34780 | 162 if (gtkLoadIcon(theme, 16, &gdkIcon, &gdkIconMask)) { |
34781 | 163 guiIcon.small = GDK_PIXMAP_XID(gdkIcon); |
164 guiIcon.small_mask = GDK_PIXMAP_XID(gdkIconMask); | |
34780 | 165 } |
33542 | 166 |
34780 | 167 if (gtkLoadIcon(theme, 32, &gdkIcon, &gdkIconMask)) { |
34781 | 168 guiIcon.normal = GDK_PIXMAP_XID(gdkIcon); |
169 guiIcon.normal_mask = GDK_PIXMAP_XID(gdkIconMask); | |
34780 | 170 } |
23077 | 171 |
34480 | 172 gtkLoadIcon(theme, 48, &gdkIcon, &gdkIconMask); |
173 | |
35493 | 174 gtkInitialized = True; |
33538 | 175 } |
23077 | 176 |
35643 | 177 /** |
178 * @brief Add the #guiIcon icons to a GTK window. | |
179 * | |
180 * @param window pointer to a GtkWindow widget | |
181 */ | |
33538 | 182 void gtkAddIcon(GtkWidget *window) |
183 { | |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35643
diff
changeset
|
184 wsWindowIcon(gdk_display, GDK_WINDOW_XWINDOW(window->window), &guiIcon); |
33538 | 185 } |
23077 | 186 |
33538 | 187 void gtkEventHandling(void) |
23077 | 188 { |
33538 | 189 int i; |
190 | |
191 for (i = 0; i < 25; i++) | |
192 gtk_main_iteration_do(0); | |
23077 | 193 } |
194 | |
34684 | 195 /* funcs */ |
23077 | 196 |
33538 | 197 void gtkMessageBox(int type, const gchar *str) |
23077 | 198 { |
33538 | 199 if (!gtkInitialized) |
200 return; | |
201 | |
202 ShowMessageBox(str); | |
203 gtk_label_set_text(GTK_LABEL(gtkMessageBoxText), str); | |
204 | |
205 /* enable linewrapping by alex */ | |
23077 | 206 // GTK_LABEL(gtkMessageBoxText)->max_width = 80; |
33538 | 207 if (strlen(str) > 80) |
208 gtk_label_set_line_wrap(GTK_LABEL(gtkMessageBoxText), TRUE); | |
209 else | |
210 gtk_label_set_line_wrap(GTK_LABEL(gtkMessageBoxText), FALSE); | |
211 | |
212 switch (type) { | |
23077 | 213 case GTK_MB_FATAL: |
33538 | 214 gtk_window_set_title(GTK_WINDOW(MessageBox), MSGTR_MSGBOX_LABEL_FatalError); |
215 gtk_widget_hide(WarningPixmap); | |
216 gtk_widget_show(ErrorPixmap); | |
217 break; | |
218 | |
23077 | 219 case GTK_MB_ERROR: |
33538 | 220 gtk_window_set_title(GTK_WINDOW(MessageBox), MSGTR_MSGBOX_LABEL_Error); |
221 gtk_widget_hide(WarningPixmap); | |
222 gtk_widget_show(ErrorPixmap); | |
223 break; | |
224 | |
23077 | 225 case GTK_MB_WARNING: |
33538 | 226 gtk_window_set_title(GTK_WINDOW(MessageBox), MSGTR_MSGBOX_LABEL_Warning); |
227 gtk_widget_show(WarningPixmap); | |
228 gtk_widget_hide(ErrorPixmap); | |
229 break; | |
230 } | |
231 | |
232 gtk_widget_show(MessageBox); | |
233 gtkSetLayer(MessageBox); | |
234 | |
235 if (type == GTK_MB_FATAL) | |
236 while (MessageBox) | |
237 gtk_main_iteration_do(0); | |
23077 | 238 } |
239 | |
35643 | 240 /** |
241 * @brief Set the layer for a GTK window. | |
242 * | |
243 * @param window pointer to a GtkWindow widget | |
244 */ | |
35638
78d9cfd68b34
Cosmetic: Use parameter name 'window' for a GtkWindow.
ib
parents:
35636
diff
changeset
|
245 void gtkSetLayer(GtkWidget *window) |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
27343
diff
changeset
|
246 { |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35643
diff
changeset
|
247 wsWindowLayer(gdk_display, GDK_WINDOW_XWINDOW(window->window), guiApp.videoWindow.isFullScreen); |
36019 | 248 gtkRaise(window); |
33538 | 249 } |
250 | |
35643 | 251 /** |
252 * @brief Activate a GTK window, i.e. raise it to the top. | |
253 * | |
254 * @param window pointer to a GtkWindow widget | |
255 */ | |
36019 | 256 void gtkRaise(GtkWidget *window) |
33538 | 257 { |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35643
diff
changeset
|
258 wsWindowRaiseTop(gdk_display, GDK_WINDOW_XWINDOW(window->window)); |
23077 | 259 } |
260 | |
36022 | 261 static void gtkSelectInCList(GtkWidget *list, char *item) |
262 { | |
263 gint i; | |
264 | |
36024 | 265 if ((i = gtkFindInCList(list, item)) > -1) |
36022 | 266 gtk_clist_select_row(GTK_CLIST(list), i, 0); |
267 } | |
268 | |
33538 | 269 void gtkShow(int type, char *param) |
23077 | 270 { |
33538 | 271 switch (type) { |
272 case evEqualizer: | |
273 ShowEqualizer(); | |
274 gtkSetLayer(Equalizer); | |
275 break; | |
276 | |
277 case evSkinBrowser: | |
278 ShowSkinBrowser(); | |
279 | |
36020 | 280 // gtk_clist_clear(GTK_CLIST(SkinList)); |
36034 | 281 if (FillSkinList(sbMPlayerPrefixDir) && |
282 FillSkinList(sbMPlayerDirInHome)) { | |
36021 | 283 gtkSelectInCList(SkinList, param); |
33538 | 284 gtk_clist_sort(GTK_CLIST(SkinList)); |
285 gtk_widget_show(SkinBrowser); | |
286 gtkSetLayer(SkinBrowser); | |
287 } else { | |
288 gtk_widget_destroy(SkinBrowser); | |
289 gtkMessageBox(GTK_MB_ERROR, "Skin dirs not found ... Please install skins."); | |
290 } | |
291 | |
23077 | 292 break; |
33538 | 293 |
294 case evPreferences: | |
23077 | 295 ShowPreferences(); |
296 break; | |
33538 | 297 |
34321
daebf766dea6
Cosmetic: Synchronize evPlaylist event and message names.
ib
parents:
33990
diff
changeset
|
298 case evPlaylist: |
35981 | 299 ShowPlaylist(); |
300 gtkSetLayer(Playlist); | |
23077 | 301 break; |
33538 | 302 |
303 case evLoad: | |
35976 | 304 ShowFileSelector(FILESELECT_VIDEO_AUDIO); |
35975 | 305 gtkSetLayer(FileSelector); |
23077 | 306 break; |
33538 | 307 |
308 case evLoadSubtitle: | |
35976 | 309 ShowFileSelector(FILESELECT_SUBTITLE); |
35975 | 310 gtkSetLayer(FileSelector); |
23077 | 311 break; |
33538 | 312 |
313 case evLoadAudioFile: | |
35976 | 314 ShowFileSelector(FILESELECT_AUDIO); |
35975 | 315 gtkSetLayer(FileSelector); |
33538 | 316 break; |
317 | |
318 case evAbout: | |
35977 | 319 ShowAbout(); |
33538 | 320 gtkSetLayer(About); |
23077 | 321 break; |
33538 | 322 |
34333 | 323 case ivShowPopUpMenu: |
33538 | 324 gtkPopupMenu = evNone; |
325 gtkPopupMenuParam = 0; | |
326 | |
327 if (PopUpMenu) { | |
328 gtk_widget_hide(PopUpMenu); | |
329 gtk_widget_destroy(PopUpMenu); | |
330 } | |
331 | |
35996 | 332 PopUpMenu = CreatePopUpMenu(); |
33538 | 333 gtk_menu_popup(GTK_MENU(PopUpMenu), NULL, NULL, NULL, NULL, 0, 0); |
23077 | 334 break; |
33538 | 335 |
34333 | 336 case ivHidePopUpMenu: |
33538 | 337 |
338 if (PopUpMenu) { | |
339 gtk_widget_hide(PopUpMenu); | |
340 gtk_widget_destroy(PopUpMenu); | |
341 PopUpMenu = NULL; | |
342 } | |
343 | |
23077 | 344 break; |
33538 | 345 |
34329 | 346 case evLoadURL: |
35978 | 347 ShowURLDialog(); |
348 gtkSetLayer(URLDialog); | |
33538 | 349 break; |
350 } | |
23077 | 351 } |