Mercurial > mplayer.hg
annotate gui/dialog/url.c @ 36082:bb41e924fea9
Cosmetic: Insert blank line and relocate statement.
author | ib |
---|---|
date | Mon, 29 Apr 2013 10:28:18 +0000 |
parents | 2c0e238bc070 |
children | 3705b6e4ba07 |
rev | line source |
---|---|
33572 | 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 */ | |
18 | |
36018 | 19 #include <stdio.h> |
33572 | 20 #include <stdlib.h> |
21 #include <string.h> | |
22 | |
23 #include "url.h" | |
36018 | 24 #include "dialog.h" |
33572 | 25 #include "tools.h" |
36032 | 26 #include "gui/interface.h" |
36018 | 27 #include "gui/app/app.h" |
36053 | 28 #include "gui/app/gui.h" |
35772 | 29 #include "gui/ui/actions.h" |
33742
e1539e14d60f
Move purely list related parts of gtkSet() from interface.c to list.c.
ib
parents:
33740
diff
changeset
|
30 #include "gui/util/list.h" |
33737 | 31 #include "gui/util/string.h" |
36018 | 32 |
33572 | 33 #include "help_mp.h" |
36018 | 34 #include "stream/stream.h" |
33572 | 35 |
36045 | 36 GtkWidget *URLDialog; |
33572 | 37 |
36049 | 38 static GtkWidget *urlCombo; |
39 static GtkWidget *urlEntry; | |
40 static GList *urlEntries; | |
33572 | 41 |
36050 | 42 static void button_clicked(GtkButton *button, gpointer user_data) |
33572 | 43 { |
36017 | 44 urlItem *item; |
36010 | 45 |
36017 | 46 (void)button; |
47 | |
36056 | 48 if (user_data) { |
36049 | 49 gchar *str = strdup(gtk_entry_get_text(GTK_ENTRY(urlEntry))); |
33572 | 50 |
36017 | 51 if (str) { |
52 if (!strstr(str, "://")) { | |
53 gchar *tmp; | |
36082 | 54 |
36017 | 55 tmp = malloc(strlen(str) + 8); |
56 sprintf(tmp, "http://%s", str); | |
57 free(str); | |
58 str = tmp; | |
59 } | |
60 | |
36049 | 61 urlEntries = g_list_prepend(urlEntries, (gchar *)str); |
33572 | 62 |
36017 | 63 item = calloc(1, sizeof(urlItem)); |
64 item->url = gstrdup(str); | |
65 listMgr(URLLIST_ITEM_ADD, item); | |
33572 | 66 |
36017 | 67 uiSetFile(NULL, str, STREAMTYPE_STREAM); |
68 listMgr(PLAYLIST_DELETE, 0); | |
69 add_to_gui_playlist(str, PLAYLIST_ITEM_APPEND); | |
36082 | 70 guiInfo.NewPlay = GUI_FILE_NEW; |
36017 | 71 uiEvent(evPlay, 0); |
72 } | |
33572 | 73 } |
36017 | 74 |
75 gtk_widget_destroy(URLDialog); | |
33572 | 76 } |
77 | |
36017 | 78 static GtkWidget *CreateURLDialog(void) |
33572 | 79 { |
36017 | 80 GtkWidget *vbox1; |
81 GtkWidget *hbox1; | |
82 GtkWidget *hbuttonbox1; | |
83 GtkWidget *Ok; | |
84 GtkWidget *Cancel; | |
85 GtkAccelGroup *accel_group; | |
36066
2c0e238bc070
Don't allow the URL dialog to be vertically user-resizable.
ib
parents:
36065
diff
changeset
|
86 GdkGeometry geometry; |
33572 | 87 |
36017 | 88 accel_group = gtk_accel_group_new(); |
33572 | 89 |
36017 | 90 URLDialog = gtk_window_new(GTK_WINDOW_TOPLEVEL); |
36057 | 91 gtk_widget_set_usize(URLDialog, 384, -1); |
36017 | 92 gtk_window_set_title(GTK_WINDOW(URLDialog), MSGTR_Network); |
93 gtk_window_set_position(GTK_WINDOW(URLDialog), GTK_WIN_POS_CENTER); | |
36053 | 94 gtk_window_set_wmclass(GTK_WINDOW(URLDialog), "Network", MPlayer); |
33572 | 95 |
36017 | 96 gtk_widget_realize(URLDialog); |
97 gtkAddIcon(URLDialog); | |
33572 | 98 |
36023
a04e8798227b
Cosmetic: Prefix all functions in dialog/tools.c with gtk.
ib
parents:
36019
diff
changeset
|
99 vbox1 = gtkAddVBox(gtkAddDialogFrame(URLDialog), 0); |
a04e8798227b
Cosmetic: Prefix all functions in dialog/tools.c with gtk.
ib
parents:
36019
diff
changeset
|
100 hbox1 = gtkAddHBox(vbox1, 1); |
a04e8798227b
Cosmetic: Prefix all functions in dialog/tools.c with gtk.
ib
parents:
36019
diff
changeset
|
101 gtkAddLabel("URL: ", hbox1); |
33572 | 102 |
36049 | 103 urlCombo = gtkAddCombo(hbox1); |
33572 | 104 /* |
36017 | 105 * gtk_combo_new(); |
36049 | 106 * gtk_widget_show( urlCombo ); |
107 * gtk_box_pack_start( GTK_BOX( hbox1 ),urlCombo,TRUE,TRUE,0 ); | |
36017 | 108 */ |
36049 | 109 urlEntry = GTK_COMBO(urlCombo)->entry; |
110 gtk_widget_show(urlEntry); | |
33572 | 111 |
36023
a04e8798227b
Cosmetic: Prefix all functions in dialog/tools.c with gtk.
ib
parents:
36019
diff
changeset
|
112 gtkAddHSeparator(vbox1); |
33572 | 113 |
36023
a04e8798227b
Cosmetic: Prefix all functions in dialog/tools.c with gtk.
ib
parents:
36019
diff
changeset
|
114 hbuttonbox1 = gtkAddHButtonBox(vbox1); |
36017 | 115 gtk_button_box_set_layout(GTK_BUTTON_BOX(hbuttonbox1), GTK_BUTTONBOX_END); |
116 gtk_button_box_set_spacing(GTK_BUTTON_BOX(hbuttonbox1), 10); | |
33572 | 117 |
36023
a04e8798227b
Cosmetic: Prefix all functions in dialog/tools.c with gtk.
ib
parents:
36019
diff
changeset
|
118 Ok = gtkAddButton(MSGTR_Ok, hbuttonbox1); |
a04e8798227b
Cosmetic: Prefix all functions in dialog/tools.c with gtk.
ib
parents:
36019
diff
changeset
|
119 Cancel = gtkAddButton(MSGTR_Cancel, hbuttonbox1); |
33572 | 120 |
36066
2c0e238bc070
Don't allow the URL dialog to be vertically user-resizable.
ib
parents:
36065
diff
changeset
|
121 geometry.max_width = gdk_screen_get_width(gtk_widget_get_screen(URLDialog)); |
2c0e238bc070
Don't allow the URL dialog to be vertically user-resizable.
ib
parents:
36065
diff
changeset
|
122 geometry.max_height = -1; |
2c0e238bc070
Don't allow the URL dialog to be vertically user-resizable.
ib
parents:
36065
diff
changeset
|
123 gtk_window_set_geometry_hints(GTK_WINDOW(URLDialog), NULL, &geometry, GDK_HINT_MAX_SIZE); |
2c0e238bc070
Don't allow the URL dialog to be vertically user-resizable.
ib
parents:
36065
diff
changeset
|
124 |
36017 | 125 gtk_widget_add_accelerator(Ok, "clicked", accel_group, GDK_Return, 0, GTK_ACCEL_VISIBLE); |
126 gtk_widget_add_accelerator(Cancel, "clicked", accel_group, GDK_Escape, 0, GTK_ACCEL_VISIBLE); | |
33572 | 127 |
36017 | 128 gtk_signal_connect(GTK_OBJECT(URLDialog), "destroy", GTK_SIGNAL_FUNC(gtk_widget_destroyed), &URLDialog); |
36056 | 129 gtk_signal_connect(GTK_OBJECT(Ok), "clicked", GTK_SIGNAL_FUNC(button_clicked), Ok); |
36050 | 130 gtk_signal_connect(GTK_OBJECT(Cancel), "clicked", GTK_SIGNAL_FUNC(button_clicked), NULL); |
33572 | 131 |
36049 | 132 gtk_widget_grab_focus(urlEntry); |
36017 | 133 gtk_window_add_accel_group(GTK_WINDOW(URLDialog), accel_group); |
33572 | 134 |
36017 | 135 return URLDialog; |
33572 | 136 } |
35988 | 137 |
36017 | 138 void ShowURLDialog(void) |
35988 | 139 { |
36017 | 140 urlItem *item; |
35988 | 141 |
36017 | 142 if (URLDialog) |
36019 | 143 gtkRaise(URLDialog); |
36017 | 144 else |
145 URLDialog = CreateURLDialog(); | |
35988 | 146 |
36017 | 147 item = listMgr(URLLIST_GET, 0); |
35988 | 148 |
36017 | 149 if (item) { |
36049 | 150 g_list_free(urlEntries); |
151 urlEntries = NULL; | |
36017 | 152 |
153 while (item) { | |
36049 | 154 urlEntries = g_list_append(urlEntries, (gchar *)item->url); |
36047 | 155 item = item->next; |
36017 | 156 } |
35988 | 157 } |
158 | |
36049 | 159 if (urlEntries) { |
160 gtk_entry_set_text(GTK_ENTRY(urlEntry), urlEntries->data); | |
161 gtk_combo_set_popdown_strings(GTK_COMBO(urlCombo), urlEntries); | |
36017 | 162 } |
35988 | 163 |
36017 | 164 gtk_widget_show(URLDialog); |
35988 | 165 } |