Mercurial > mplayer.hg
annotate gui/dialog/url.c @ 36084:64825e4a3fed
Remove pointless code.
The URL dialog widget will be destroyed after a selection has been made,
and urlEntries will be freed and rebuilt every time the URL dialog
widget is created (newly). So it makes no sense to prepend any data to
the GList that never will be used.
author | ib |
---|---|
date | Mon, 29 Apr 2013 11:21:23 +0000 |
parents | 3705b6e4ba07 |
children | d3e8f4f71514 |
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) { |
36083 | 49 char *str = strdup(gtk_entry_get_text(GTK_ENTRY(urlEntry))); |
33572 | 50 |
36017 | 51 if (str) { |
52 if (!strstr(str, "://")) { | |
36083 | 53 char *tmp; |
36082 | 54 |
36017 | 55 tmp = malloc(strlen(str) + 8); |
56 sprintf(tmp, "http://%s", str); | |
57 free(str); | |
58 str = tmp; | |
59 } | |
60 | |
61 item = calloc(1, sizeof(urlItem)); | |
62 item->url = gstrdup(str); | |
63 listMgr(URLLIST_ITEM_ADD, item); | |
33572 | 64 |
36017 | 65 uiSetFile(NULL, str, STREAMTYPE_STREAM); |
66 listMgr(PLAYLIST_DELETE, 0); | |
67 add_to_gui_playlist(str, PLAYLIST_ITEM_APPEND); | |
36082 | 68 guiInfo.NewPlay = GUI_FILE_NEW; |
36017 | 69 uiEvent(evPlay, 0); |
70 } | |
33572 | 71 } |
36017 | 72 |
73 gtk_widget_destroy(URLDialog); | |
33572 | 74 } |
75 | |
36017 | 76 static GtkWidget *CreateURLDialog(void) |
33572 | 77 { |
36017 | 78 GtkWidget *vbox1; |
79 GtkWidget *hbox1; | |
80 GtkWidget *hbuttonbox1; | |
81 GtkWidget *Ok; | |
82 GtkWidget *Cancel; | |
83 GtkAccelGroup *accel_group; | |
36066
2c0e238bc070
Don't allow the URL dialog to be vertically user-resizable.
ib
parents:
36065
diff
changeset
|
84 GdkGeometry geometry; |
33572 | 85 |
36017 | 86 accel_group = gtk_accel_group_new(); |
33572 | 87 |
36017 | 88 URLDialog = gtk_window_new(GTK_WINDOW_TOPLEVEL); |
36057 | 89 gtk_widget_set_usize(URLDialog, 384, -1); |
36017 | 90 gtk_window_set_title(GTK_WINDOW(URLDialog), MSGTR_Network); |
91 gtk_window_set_position(GTK_WINDOW(URLDialog), GTK_WIN_POS_CENTER); | |
36053 | 92 gtk_window_set_wmclass(GTK_WINDOW(URLDialog), "Network", MPlayer); |
33572 | 93 |
36017 | 94 gtk_widget_realize(URLDialog); |
95 gtkAddIcon(URLDialog); | |
33572 | 96 |
36023
a04e8798227b
Cosmetic: Prefix all functions in dialog/tools.c with gtk.
ib
parents:
36019
diff
changeset
|
97 vbox1 = gtkAddVBox(gtkAddDialogFrame(URLDialog), 0); |
a04e8798227b
Cosmetic: Prefix all functions in dialog/tools.c with gtk.
ib
parents:
36019
diff
changeset
|
98 hbox1 = gtkAddHBox(vbox1, 1); |
a04e8798227b
Cosmetic: Prefix all functions in dialog/tools.c with gtk.
ib
parents:
36019
diff
changeset
|
99 gtkAddLabel("URL: ", hbox1); |
33572 | 100 |
36049 | 101 urlCombo = gtkAddCombo(hbox1); |
33572 | 102 /* |
36017 | 103 * gtk_combo_new(); |
36049 | 104 * gtk_widget_show( urlCombo ); |
105 * gtk_box_pack_start( GTK_BOX( hbox1 ),urlCombo,TRUE,TRUE,0 ); | |
36017 | 106 */ |
36049 | 107 urlEntry = GTK_COMBO(urlCombo)->entry; |
108 gtk_widget_show(urlEntry); | |
33572 | 109 |
36023
a04e8798227b
Cosmetic: Prefix all functions in dialog/tools.c with gtk.
ib
parents:
36019
diff
changeset
|
110 gtkAddHSeparator(vbox1); |
33572 | 111 |
36023
a04e8798227b
Cosmetic: Prefix all functions in dialog/tools.c with gtk.
ib
parents:
36019
diff
changeset
|
112 hbuttonbox1 = gtkAddHButtonBox(vbox1); |
36017 | 113 gtk_button_box_set_layout(GTK_BUTTON_BOX(hbuttonbox1), GTK_BUTTONBOX_END); |
114 gtk_button_box_set_spacing(GTK_BUTTON_BOX(hbuttonbox1), 10); | |
33572 | 115 |
36023
a04e8798227b
Cosmetic: Prefix all functions in dialog/tools.c with gtk.
ib
parents:
36019
diff
changeset
|
116 Ok = gtkAddButton(MSGTR_Ok, hbuttonbox1); |
a04e8798227b
Cosmetic: Prefix all functions in dialog/tools.c with gtk.
ib
parents:
36019
diff
changeset
|
117 Cancel = gtkAddButton(MSGTR_Cancel, hbuttonbox1); |
33572 | 118 |
36066
2c0e238bc070
Don't allow the URL dialog to be vertically user-resizable.
ib
parents:
36065
diff
changeset
|
119 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
|
120 geometry.max_height = -1; |
2c0e238bc070
Don't allow the URL dialog to be vertically user-resizable.
ib
parents:
36065
diff
changeset
|
121 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
|
122 |
36017 | 123 gtk_widget_add_accelerator(Ok, "clicked", accel_group, GDK_Return, 0, GTK_ACCEL_VISIBLE); |
124 gtk_widget_add_accelerator(Cancel, "clicked", accel_group, GDK_Escape, 0, GTK_ACCEL_VISIBLE); | |
33572 | 125 |
36017 | 126 gtk_signal_connect(GTK_OBJECT(URLDialog), "destroy", GTK_SIGNAL_FUNC(gtk_widget_destroyed), &URLDialog); |
36056 | 127 gtk_signal_connect(GTK_OBJECT(Ok), "clicked", GTK_SIGNAL_FUNC(button_clicked), Ok); |
36050 | 128 gtk_signal_connect(GTK_OBJECT(Cancel), "clicked", GTK_SIGNAL_FUNC(button_clicked), NULL); |
33572 | 129 |
36049 | 130 gtk_widget_grab_focus(urlEntry); |
36017 | 131 gtk_window_add_accel_group(GTK_WINDOW(URLDialog), accel_group); |
33572 | 132 |
36017 | 133 return URLDialog; |
33572 | 134 } |
35988 | 135 |
36017 | 136 void ShowURLDialog(void) |
35988 | 137 { |
36017 | 138 urlItem *item; |
35988 | 139 |
36017 | 140 if (URLDialog) |
36019 | 141 gtkRaise(URLDialog); |
36017 | 142 else |
143 URLDialog = CreateURLDialog(); | |
35988 | 144 |
36017 | 145 item = listMgr(URLLIST_GET, 0); |
35988 | 146 |
36017 | 147 if (item) { |
36049 | 148 g_list_free(urlEntries); |
149 urlEntries = NULL; | |
36017 | 150 |
151 while (item) { | |
36049 | 152 urlEntries = g_list_append(urlEntries, (gchar *)item->url); |
36047 | 153 item = item->next; |
36017 | 154 } |
35988 | 155 } |
156 | |
36049 | 157 if (urlEntries) { |
158 gtk_entry_set_text(GTK_ENTRY(urlEntry), urlEntries->data); | |
159 gtk_combo_set_popdown_strings(GTK_COMBO(urlCombo), urlEntries); | |
36017 | 160 } |
35988 | 161 |
36017 | 162 gtk_widget_show(URLDialog); |
35988 | 163 } |