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