Mercurial > mplayer.hg
annotate gui/dialog/dialog.c @ 36542:1163104c8adb
Improve the dialog for subtitle encodings selection.
Prettify the dialog by moving the option for unicode subtitles up,
and place it below the subtitle encodings combo box.
In this way, everything related to subtitle encodings is grouped
together.
As a result, we'll need the label unconditionally.
author | ib |
---|---|
date | Sun, 19 Jan 2014 14:46:33 +0000 |
parents | 989b5d955703 |
children | cc70b0fb8d36 |
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 | |
36049 | 99 mp_msg(MSGT_GPLAYER, MSGL_WARN, MSGTR_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)) |
65f7b2fdda46
Add a warning message about @locale in G_FILENAME_ENCODING.
ib
parents:
35703
diff
changeset
|
138 mp_msg(MSGT_GPLAYER, MSGL_WARN, MSGTR_LOCALE_ENCODING); |
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: |
33538 | 199 gtk_window_set_title(GTK_WINDOW(MessageBox), MSGTR_MSGBOX_LABEL_FatalError); |
200 gtk_widget_hide(WarningPixmap); | |
201 gtk_widget_show(ErrorPixmap); | |
202 break; | |
203 | |
36036 | 204 case MSGBOX_ERROR: |
33538 | 205 gtk_window_set_title(GTK_WINDOW(MessageBox), MSGTR_MSGBOX_LABEL_Error); |
206 gtk_widget_hide(WarningPixmap); | |
207 gtk_widget_show(ErrorPixmap); | |
208 break; | |
209 | |
36036 | 210 case MSGBOX_WARNING: |
33538 | 211 gtk_window_set_title(GTK_WINDOW(MessageBox), MSGTR_MSGBOX_LABEL_Warning); |
212 gtk_widget_show(WarningPixmap); | |
213 gtk_widget_hide(ErrorPixmap); | |
214 break; | |
215 } | |
216 | |
217 gtk_widget_show(MessageBox); | |
218 gtkSetLayer(MessageBox); | |
219 | |
36036 | 220 if (type == MSGBOX_FATAL) |
33538 | 221 while (MessageBox) |
222 gtk_main_iteration_do(0); | |
23077 | 223 } |
224 | |
35643 | 225 /** |
226 * @brief Set the layer for a GTK window. | |
227 * | |
228 * @param window pointer to a GtkWindow widget | |
229 */ | |
35638
78d9cfd68b34
Cosmetic: Use parameter name 'window' for a GtkWindow.
ib
parents:
35636
diff
changeset
|
230 void gtkSetLayer(GtkWidget *window) |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
27343
diff
changeset
|
231 { |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35643
diff
changeset
|
232 wsWindowLayer(gdk_display, GDK_WINDOW_XWINDOW(window->window), guiApp.videoWindow.isFullScreen); |
36019 | 233 gtkRaise(window); |
33538 | 234 } |
235 | |
35643 | 236 /** |
237 * @brief Activate a GTK window, i.e. raise it to the top. | |
238 * | |
239 * @param window pointer to a GtkWindow widget | |
240 */ | |
36019 | 241 void gtkRaise(GtkWidget *window) |
33538 | 242 { |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35643
diff
changeset
|
243 wsWindowRaiseTop(gdk_display, GDK_WINDOW_XWINDOW(window->window)); |
23077 | 244 } |
245 | |
36022 | 246 static void gtkSelectInCList(GtkWidget *list, char *item) |
247 { | |
248 gint i; | |
249 | |
36024 | 250 if ((i = gtkFindInCList(list, item)) > -1) |
36022 | 251 gtk_clist_select_row(GTK_CLIST(list), i, 0); |
252 } | |
253 | |
33538 | 254 void gtkShow(int type, char *param) |
23077 | 255 { |
33538 | 256 switch (type) { |
257 case evEqualizer: | |
258 ShowEqualizer(); | |
259 gtkSetLayer(Equalizer); | |
260 break; | |
261 | |
262 case evSkinBrowser: | |
263 ShowSkinBrowser(); | |
264 | |
36020 | 265 // gtk_clist_clear(GTK_CLIST(SkinList)); |
36044 | 266 if (FillSkinList(sbSkinDirInHome) && |
267 FillSkinList(sbSkinDirInData)) { | |
36021 | 268 gtkSelectInCList(SkinList, param); |
33538 | 269 gtk_clist_sort(GTK_CLIST(SkinList)); |
270 gtk_widget_show(SkinBrowser); | |
271 gtkSetLayer(SkinBrowser); | |
272 } else { | |
273 gtk_widget_destroy(SkinBrowser); | |
36036 | 274 gtkMessageBox(MSGBOX_ERROR, "Skin dirs not found ... Please install skins."); |
33538 | 275 } |
276 | |
23077 | 277 break; |
33538 | 278 |
279 case evPreferences: | |
23077 | 280 ShowPreferences(); |
281 break; | |
33538 | 282 |
34321
daebf766dea6
Cosmetic: Synchronize evPlaylist event and message names.
ib
parents:
33990
diff
changeset
|
283 case evPlaylist: |
35981 | 284 ShowPlaylist(); |
285 gtkSetLayer(Playlist); | |
23077 | 286 break; |
33538 | 287 |
288 case evLoad: | |
35976 | 289 ShowFileSelector(FILESELECT_VIDEO_AUDIO); |
35975 | 290 gtkSetLayer(FileSelector); |
23077 | 291 break; |
33538 | 292 |
293 case evLoadSubtitle: | |
35976 | 294 ShowFileSelector(FILESELECT_SUBTITLE); |
35975 | 295 gtkSetLayer(FileSelector); |
23077 | 296 break; |
33538 | 297 |
298 case evLoadAudioFile: | |
35976 | 299 ShowFileSelector(FILESELECT_AUDIO); |
35975 | 300 gtkSetLayer(FileSelector); |
33538 | 301 break; |
302 | |
303 case evAbout: | |
35977 | 304 ShowAbout(); |
33538 | 305 gtkSetLayer(About); |
23077 | 306 break; |
33538 | 307 |
34333 | 308 case ivShowPopUpMenu: |
33538 | 309 gtkPopupMenu = evNone; |
310 gtkPopupMenuParam = 0; | |
311 | |
312 if (PopUpMenu) { | |
313 gtk_widget_hide(PopUpMenu); | |
314 gtk_widget_destroy(PopUpMenu); | |
315 } | |
316 | |
35996 | 317 PopUpMenu = CreatePopUpMenu(); |
33538 | 318 gtk_menu_popup(GTK_MENU(PopUpMenu), NULL, NULL, NULL, NULL, 0, 0); |
23077 | 319 break; |
33538 | 320 |
34333 | 321 case ivHidePopUpMenu: |
33538 | 322 |
323 if (PopUpMenu) { | |
324 gtk_widget_hide(PopUpMenu); | |
325 gtk_widget_destroy(PopUpMenu); | |
326 PopUpMenu = NULL; | |
327 } | |
328 | |
23077 | 329 break; |
33538 | 330 |
34329 | 331 case evLoadURL: |
35978 | 332 ShowURLDialog(); |
333 gtkSetLayer(URLDialog); | |
33538 | 334 break; |
335 } | |
23077 | 336 } |