annotate gui/dialog/url.c @ 36093:22ac72559523

Move declaration into scope where variable is used.
author ib
date Mon, 29 Apr 2013 12:26:37 +0000
parents e16833799bae
children 0fade14b5df1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
33572
d9b805602aa1 Rename some gtk files.
ib
parents:
diff changeset
1 /*
d9b805602aa1 Rename some gtk files.
ib
parents:
diff changeset
2 * This file is part of MPlayer.
d9b805602aa1 Rename some gtk files.
ib
parents:
diff changeset
3 *
d9b805602aa1 Rename some gtk files.
ib
parents:
diff changeset
4 * MPlayer is free software; you can redistribute it and/or modify
d9b805602aa1 Rename some gtk files.
ib
parents:
diff changeset
5 * it under the terms of the GNU General Public License as published by
d9b805602aa1 Rename some gtk files.
ib
parents:
diff changeset
6 * the Free Software Foundation; either version 2 of the License, or
d9b805602aa1 Rename some gtk files.
ib
parents:
diff changeset
7 * (at your option) any later version.
d9b805602aa1 Rename some gtk files.
ib
parents:
diff changeset
8 *
d9b805602aa1 Rename some gtk files.
ib
parents:
diff changeset
9 * MPlayer is distributed in the hope that it will be useful,
d9b805602aa1 Rename some gtk files.
ib
parents:
diff changeset
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
d9b805602aa1 Rename some gtk files.
ib
parents:
diff changeset
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
d9b805602aa1 Rename some gtk files.
ib
parents:
diff changeset
12 * GNU General Public License for more details.
d9b805602aa1 Rename some gtk files.
ib
parents:
diff changeset
13 *
d9b805602aa1 Rename some gtk files.
ib
parents:
diff changeset
14 * You should have received a copy of the GNU General Public License along
d9b805602aa1 Rename some gtk files.
ib
parents:
diff changeset
15 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
d9b805602aa1 Rename some gtk files.
ib
parents:
diff changeset
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
d9b805602aa1 Rename some gtk files.
ib
parents:
diff changeset
17 */
d9b805602aa1 Rename some gtk files.
ib
parents:
diff changeset
18
36018
26836919db4e Add, group and sort #includes, remove unneeded ones.
ib
parents: 36017
diff changeset
19 #include <stdio.h>
33572
d9b805602aa1 Rename some gtk files.
ib
parents:
diff changeset
20 #include <stdlib.h>
d9b805602aa1 Rename some gtk files.
ib
parents:
diff changeset
21 #include <string.h>
d9b805602aa1 Rename some gtk files.
ib
parents:
diff changeset
22
d9b805602aa1 Rename some gtk files.
ib
parents:
diff changeset
23 #include "url.h"
36018
26836919db4e Add, group and sort #includes, remove unneeded ones.
ib
parents: 36017
diff changeset
24 #include "dialog.h"
33572
d9b805602aa1 Rename some gtk files.
ib
parents:
diff changeset
25 #include "tools.h"
36032
c667e34fb941 Cosmetic: Rearrange #includes.
ib
parents: 36023
diff changeset
26 #include "gui/interface.h"
36018
26836919db4e Add, group and sort #includes, remove unneeded ones.
ib
parents: 36017
diff changeset
27 #include "gui/app/app.h"
36053
7affacef2f88 Define "MPlayer" string.
ib
parents: 36052
diff changeset
28 #include "gui/app/gui.h"
35772
3fec1d4b2736 Relocate uiMainEvent() prototype.
ib
parents: 35768
diff changeset
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"
36018
26836919db4e Add, group and sort #includes, remove unneeded ones.
ib
parents: 36017
diff changeset
31
33572
d9b805602aa1 Rename some gtk files.
ib
parents:
diff changeset
32 #include "help_mp.h"
36018
26836919db4e Add, group and sort #includes, remove unneeded ones.
ib
parents: 36017
diff changeset
33 #include "stream/stream.h"
33572
d9b805602aa1 Rename some gtk files.
ib
parents:
diff changeset
34
36045
a6f9525929a4 Remove unnecessary initialization.
ib
parents: 36032
diff changeset
35 GtkWidget *URLDialog;
33572
d9b805602aa1 Rename some gtk files.
ib
parents:
diff changeset
36
36049
31f6a88593b3 Cosmetic: Rename static variables.
ib
parents: 36047
diff changeset
37 static GtkWidget *urlCombo;
31f6a88593b3 Cosmetic: Rename static variables.
ib
parents: 36047
diff changeset
38 static GtkWidget *urlEntry;
31f6a88593b3 Cosmetic: Rename static variables.
ib
parents: 36047
diff changeset
39 static GList *urlEntries;
33572
d9b805602aa1 Rename some gtk files.
ib
parents:
diff changeset
40
36050
968e936dc898 Cosmetic: Rename signal handler function.
ib
parents: 36049
diff changeset
41 static void button_clicked(GtkButton *button, gpointer user_data)
33572
d9b805602aa1 Rename some gtk files.
ib
parents:
diff changeset
42 {
36017
b3764c930d0c Cosmetic: Format to MPlayer coding style.
ib
parents: 36010
diff changeset
43 (void)button;
b3764c930d0c Cosmetic: Format to MPlayer coding style.
ib
parents: 36010
diff changeset
44
36056
94188b63e047 Avoid casts by passing an existing pointer.
ib
parents: 36053
diff changeset
45 if (user_data) {
36083
3705b6e4ba07 Be more precise about type.
ib
parents: 36082
diff changeset
46 char *str = strdup(gtk_entry_get_text(GTK_ENTRY(urlEntry)));
33572
d9b805602aa1 Rename some gtk files.
ib
parents:
diff changeset
47
36017
b3764c930d0c Cosmetic: Format to MPlayer coding style.
ib
parents: 36010
diff changeset
48 if (str) {
b3764c930d0c Cosmetic: Format to MPlayer coding style.
ib
parents: 36010
diff changeset
49 if (!strstr(str, "://")) {
36092
e16833799bae Merge declaration and assignment.
ib
parents: 36091
diff changeset
50 char *tmp = malloc(strlen(str) + 8);
36085
d3e8f4f71514 Check return value to avoid segmentation fault.
ib
parents: 36084
diff changeset
51
d3e8f4f71514 Check return value to avoid segmentation fault.
ib
parents: 36084
diff changeset
52 if (tmp)
d3e8f4f71514 Check return value to avoid segmentation fault.
ib
parents: 36084
diff changeset
53 sprintf(tmp, "http://%s", str);
d3e8f4f71514 Check return value to avoid segmentation fault.
ib
parents: 36084
diff changeset
54
36017
b3764c930d0c Cosmetic: Format to MPlayer coding style.
ib
parents: 36010
diff changeset
55 free(str);
b3764c930d0c Cosmetic: Format to MPlayer coding style.
ib
parents: 36010
diff changeset
56 str = tmp;
b3764c930d0c Cosmetic: Format to MPlayer coding style.
ib
parents: 36010
diff changeset
57 }
b3764c930d0c Cosmetic: Format to MPlayer coding style.
ib
parents: 36010
diff changeset
58
36085
d3e8f4f71514 Check return value to avoid segmentation fault.
ib
parents: 36084
diff changeset
59 if (str) {
36093
22ac72559523 Move declaration into scope where variable is used.
ib
parents: 36092
diff changeset
60 urlItem *item;
22ac72559523 Move declaration into scope where variable is used.
ib
parents: 36092
diff changeset
61
36089
d4056035c260 Set file prior to adding to the URL list.
ib
parents: 36088
diff changeset
62 uiSetFile(NULL, str, STREAMTYPE_STREAM);
d4056035c260 Set file prior to adding to the URL list.
ib
parents: 36088
diff changeset
63 listMgr(PLAYLIST_DELETE, 0);
d4056035c260 Set file prior to adding to the URL list.
ib
parents: 36088
diff changeset
64 add_to_gui_playlist(str, PLAYLIST_ITEM_APPEND);
d4056035c260 Set file prior to adding to the URL list.
ib
parents: 36088
diff changeset
65
36091
101225a6ed42 Cosmetic: Adjust indent.
ib
parents: 36090
diff changeset
66 item = calloc(1, sizeof(urlItem));
36090
f658e29184e0 Check return value to avoid segmentation fault.
ib
parents: 36089
diff changeset
67
f658e29184e0 Check return value to avoid segmentation fault.
ib
parents: 36089
diff changeset
68 if (item) {
36091
101225a6ed42 Cosmetic: Adjust indent.
ib
parents: 36090
diff changeset
69 item->url = str;
101225a6ed42 Cosmetic: Adjust indent.
ib
parents: 36090
diff changeset
70 listMgr(URLLIST_ITEM_ADD, item);
36090
f658e29184e0 Check return value to avoid segmentation fault.
ib
parents: 36089
diff changeset
71 }
33572
d9b805602aa1 Rename some gtk files.
ib
parents:
diff changeset
72
36087
3240406fbd4f Cosmetic: Adjust indent.
ib
parents: 36086
diff changeset
73 guiInfo.NewPlay = GUI_FILE_NEW;
3240406fbd4f Cosmetic: Adjust indent.
ib
parents: 36086
diff changeset
74 uiEvent(evPlay, 0);
36085
d3e8f4f71514 Check return value to avoid segmentation fault.
ib
parents: 36084
diff changeset
75 }
36017
b3764c930d0c Cosmetic: Format to MPlayer coding style.
ib
parents: 36010
diff changeset
76 }
33572
d9b805602aa1 Rename some gtk files.
ib
parents:
diff changeset
77 }
36017
b3764c930d0c Cosmetic: Format to MPlayer coding style.
ib
parents: 36010
diff changeset
78
b3764c930d0c Cosmetic: Format to MPlayer coding style.
ib
parents: 36010
diff changeset
79 gtk_widget_destroy(URLDialog);
33572
d9b805602aa1 Rename some gtk files.
ib
parents:
diff changeset
80 }
d9b805602aa1 Rename some gtk files.
ib
parents:
diff changeset
81
36017
b3764c930d0c Cosmetic: Format to MPlayer coding style.
ib
parents: 36010
diff changeset
82 static GtkWidget *CreateURLDialog(void)
33572
d9b805602aa1 Rename some gtk files.
ib
parents:
diff changeset
83 {
36017
b3764c930d0c Cosmetic: Format to MPlayer coding style.
ib
parents: 36010
diff changeset
84 GtkWidget *vbox1;
b3764c930d0c Cosmetic: Format to MPlayer coding style.
ib
parents: 36010
diff changeset
85 GtkWidget *hbox1;
b3764c930d0c Cosmetic: Format to MPlayer coding style.
ib
parents: 36010
diff changeset
86 GtkWidget *hbuttonbox1;
b3764c930d0c Cosmetic: Format to MPlayer coding style.
ib
parents: 36010
diff changeset
87 GtkWidget *Ok;
b3764c930d0c Cosmetic: Format to MPlayer coding style.
ib
parents: 36010
diff changeset
88 GtkWidget *Cancel;
b3764c930d0c Cosmetic: Format to MPlayer coding style.
ib
parents: 36010
diff changeset
89 GtkAccelGroup *accel_group;
36066
2c0e238bc070 Don't allow the URL dialog to be vertically user-resizable.
ib
parents: 36065
diff changeset
90 GdkGeometry geometry;
33572
d9b805602aa1 Rename some gtk files.
ib
parents:
diff changeset
91
36017
b3764c930d0c Cosmetic: Format to MPlayer coding style.
ib
parents: 36010
diff changeset
92 accel_group = gtk_accel_group_new();
33572
d9b805602aa1 Rename some gtk files.
ib
parents:
diff changeset
93
36017
b3764c930d0c Cosmetic: Format to MPlayer coding style.
ib
parents: 36010
diff changeset
94 URLDialog = gtk_window_new(GTK_WINDOW_TOPLEVEL);
36057
12dcd03f4e79 Don't set (too small) height.
ib
parents: 36056
diff changeset
95 gtk_widget_set_usize(URLDialog, 384, -1);
36017
b3764c930d0c Cosmetic: Format to MPlayer coding style.
ib
parents: 36010
diff changeset
96 gtk_window_set_title(GTK_WINDOW(URLDialog), MSGTR_Network);
b3764c930d0c Cosmetic: Format to MPlayer coding style.
ib
parents: 36010
diff changeset
97 gtk_window_set_position(GTK_WINDOW(URLDialog), GTK_WIN_POS_CENTER);
36053
7affacef2f88 Define "MPlayer" string.
ib
parents: 36052
diff changeset
98 gtk_window_set_wmclass(GTK_WINDOW(URLDialog), "Network", MPlayer);
33572
d9b805602aa1 Rename some gtk files.
ib
parents:
diff changeset
99
36017
b3764c930d0c Cosmetic: Format to MPlayer coding style.
ib
parents: 36010
diff changeset
100 gtk_widget_realize(URLDialog);
b3764c930d0c Cosmetic: Format to MPlayer coding style.
ib
parents: 36010
diff changeset
101 gtkAddIcon(URLDialog);
33572
d9b805602aa1 Rename some gtk files.
ib
parents:
diff changeset
102
36023
a04e8798227b Cosmetic: Prefix all functions in dialog/tools.c with gtk.
ib
parents: 36019
diff changeset
103 vbox1 = gtkAddVBox(gtkAddDialogFrame(URLDialog), 0);
a04e8798227b Cosmetic: Prefix all functions in dialog/tools.c with gtk.
ib
parents: 36019
diff changeset
104 hbox1 = gtkAddHBox(vbox1, 1);
a04e8798227b Cosmetic: Prefix all functions in dialog/tools.c with gtk.
ib
parents: 36019
diff changeset
105 gtkAddLabel("URL: ", hbox1);
33572
d9b805602aa1 Rename some gtk files.
ib
parents:
diff changeset
106
36049
31f6a88593b3 Cosmetic: Rename static variables.
ib
parents: 36047
diff changeset
107 urlCombo = gtkAddCombo(hbox1);
33572
d9b805602aa1 Rename some gtk files.
ib
parents:
diff changeset
108 /*
36017
b3764c930d0c Cosmetic: Format to MPlayer coding style.
ib
parents: 36010
diff changeset
109 * gtk_combo_new();
36049
31f6a88593b3 Cosmetic: Rename static variables.
ib
parents: 36047
diff changeset
110 * gtk_widget_show( urlCombo );
31f6a88593b3 Cosmetic: Rename static variables.
ib
parents: 36047
diff changeset
111 * gtk_box_pack_start( GTK_BOX( hbox1 ),urlCombo,TRUE,TRUE,0 );
36017
b3764c930d0c Cosmetic: Format to MPlayer coding style.
ib
parents: 36010
diff changeset
112 */
36049
31f6a88593b3 Cosmetic: Rename static variables.
ib
parents: 36047
diff changeset
113 urlEntry = GTK_COMBO(urlCombo)->entry;
31f6a88593b3 Cosmetic: Rename static variables.
ib
parents: 36047
diff changeset
114 gtk_widget_show(urlEntry);
33572
d9b805602aa1 Rename some gtk files.
ib
parents:
diff changeset
115
36023
a04e8798227b Cosmetic: Prefix all functions in dialog/tools.c with gtk.
ib
parents: 36019
diff changeset
116 gtkAddHSeparator(vbox1);
33572
d9b805602aa1 Rename some gtk files.
ib
parents:
diff changeset
117
36023
a04e8798227b Cosmetic: Prefix all functions in dialog/tools.c with gtk.
ib
parents: 36019
diff changeset
118 hbuttonbox1 = gtkAddHButtonBox(vbox1);
36017
b3764c930d0c Cosmetic: Format to MPlayer coding style.
ib
parents: 36010
diff changeset
119 gtk_button_box_set_layout(GTK_BUTTON_BOX(hbuttonbox1), GTK_BUTTONBOX_END);
b3764c930d0c Cosmetic: Format to MPlayer coding style.
ib
parents: 36010
diff changeset
120 gtk_button_box_set_spacing(GTK_BUTTON_BOX(hbuttonbox1), 10);
33572
d9b805602aa1 Rename some gtk files.
ib
parents:
diff changeset
121
36023
a04e8798227b Cosmetic: Prefix all functions in dialog/tools.c with gtk.
ib
parents: 36019
diff changeset
122 Ok = gtkAddButton(MSGTR_Ok, hbuttonbox1);
a04e8798227b Cosmetic: Prefix all functions in dialog/tools.c with gtk.
ib
parents: 36019
diff changeset
123 Cancel = gtkAddButton(MSGTR_Cancel, hbuttonbox1);
33572
d9b805602aa1 Rename some gtk files.
ib
parents:
diff changeset
124
36066
2c0e238bc070 Don't allow the URL dialog to be vertically user-resizable.
ib
parents: 36065
diff changeset
125 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
126 geometry.max_height = -1;
2c0e238bc070 Don't allow the URL dialog to be vertically user-resizable.
ib
parents: 36065
diff changeset
127 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
128
36017
b3764c930d0c Cosmetic: Format to MPlayer coding style.
ib
parents: 36010
diff changeset
129 gtk_widget_add_accelerator(Ok, "clicked", accel_group, GDK_Return, 0, GTK_ACCEL_VISIBLE);
b3764c930d0c Cosmetic: Format to MPlayer coding style.
ib
parents: 36010
diff changeset
130 gtk_widget_add_accelerator(Cancel, "clicked", accel_group, GDK_Escape, 0, GTK_ACCEL_VISIBLE);
33572
d9b805602aa1 Rename some gtk files.
ib
parents:
diff changeset
131
36017
b3764c930d0c Cosmetic: Format to MPlayer coding style.
ib
parents: 36010
diff changeset
132 gtk_signal_connect(GTK_OBJECT(URLDialog), "destroy", GTK_SIGNAL_FUNC(gtk_widget_destroyed), &URLDialog);
36056
94188b63e047 Avoid casts by passing an existing pointer.
ib
parents: 36053
diff changeset
133 gtk_signal_connect(GTK_OBJECT(Ok), "clicked", GTK_SIGNAL_FUNC(button_clicked), Ok);
36050
968e936dc898 Cosmetic: Rename signal handler function.
ib
parents: 36049
diff changeset
134 gtk_signal_connect(GTK_OBJECT(Cancel), "clicked", GTK_SIGNAL_FUNC(button_clicked), NULL);
33572
d9b805602aa1 Rename some gtk files.
ib
parents:
diff changeset
135
36049
31f6a88593b3 Cosmetic: Rename static variables.
ib
parents: 36047
diff changeset
136 gtk_widget_grab_focus(urlEntry);
36017
b3764c930d0c Cosmetic: Format to MPlayer coding style.
ib
parents: 36010
diff changeset
137 gtk_window_add_accel_group(GTK_WINDOW(URLDialog), accel_group);
33572
d9b805602aa1 Rename some gtk files.
ib
parents:
diff changeset
138
36017
b3764c930d0c Cosmetic: Format to MPlayer coding style.
ib
parents: 36010
diff changeset
139 return URLDialog;
33572
d9b805602aa1 Rename some gtk files.
ib
parents:
diff changeset
140 }
35988
ad1a5580c91d Make create_URL() static.
ib
parents: 35987
diff changeset
141
36017
b3764c930d0c Cosmetic: Format to MPlayer coding style.
ib
parents: 36010
diff changeset
142 void ShowURLDialog(void)
35988
ad1a5580c91d Make create_URL() static.
ib
parents: 35987
diff changeset
143 {
36017
b3764c930d0c Cosmetic: Format to MPlayer coding style.
ib
parents: 36010
diff changeset
144 urlItem *item;
35988
ad1a5580c91d Make create_URL() static.
ib
parents: 35987
diff changeset
145
36017
b3764c930d0c Cosmetic: Format to MPlayer coding style.
ib
parents: 36010
diff changeset
146 if (URLDialog)
36019
d2d776c8e040 Cosmetic: Rename gtkActive() gtkRaise().
ib
parents: 36018
diff changeset
147 gtkRaise(URLDialog);
36017
b3764c930d0c Cosmetic: Format to MPlayer coding style.
ib
parents: 36010
diff changeset
148 else
b3764c930d0c Cosmetic: Format to MPlayer coding style.
ib
parents: 36010
diff changeset
149 URLDialog = CreateURLDialog();
35988
ad1a5580c91d Make create_URL() static.
ib
parents: 35987
diff changeset
150
36017
b3764c930d0c Cosmetic: Format to MPlayer coding style.
ib
parents: 36010
diff changeset
151 item = listMgr(URLLIST_GET, 0);
35988
ad1a5580c91d Make create_URL() static.
ib
parents: 35987
diff changeset
152
36017
b3764c930d0c Cosmetic: Format to MPlayer coding style.
ib
parents: 36010
diff changeset
153 if (item) {
36049
31f6a88593b3 Cosmetic: Rename static variables.
ib
parents: 36047
diff changeset
154 g_list_free(urlEntries);
31f6a88593b3 Cosmetic: Rename static variables.
ib
parents: 36047
diff changeset
155 urlEntries = NULL;
36017
b3764c930d0c Cosmetic: Format to MPlayer coding style.
ib
parents: 36010
diff changeset
156
b3764c930d0c Cosmetic: Format to MPlayer coding style.
ib
parents: 36010
diff changeset
157 while (item) {
36088
6500c354cd2c Remove pointless cast.
ib
parents: 36087
diff changeset
158 urlEntries = g_list_append(urlEntries, item->url);
36047
705ed2e9e7b1 Cosmetic: Rename variable and correct spelling.
ib
parents: 36045
diff changeset
159 item = item->next;
36017
b3764c930d0c Cosmetic: Format to MPlayer coding style.
ib
parents: 36010
diff changeset
160 }
35988
ad1a5580c91d Make create_URL() static.
ib
parents: 35987
diff changeset
161 }
ad1a5580c91d Make create_URL() static.
ib
parents: 35987
diff changeset
162
36049
31f6a88593b3 Cosmetic: Rename static variables.
ib
parents: 36047
diff changeset
163 if (urlEntries) {
31f6a88593b3 Cosmetic: Rename static variables.
ib
parents: 36047
diff changeset
164 gtk_entry_set_text(GTK_ENTRY(urlEntry), urlEntries->data);
31f6a88593b3 Cosmetic: Rename static variables.
ib
parents: 36047
diff changeset
165 gtk_combo_set_popdown_strings(GTK_COMBO(urlCombo), urlEntries);
36017
b3764c930d0c Cosmetic: Format to MPlayer coding style.
ib
parents: 36010
diff changeset
166 }
35988
ad1a5580c91d Make create_URL() static.
ib
parents: 35987
diff changeset
167
36017
b3764c930d0c Cosmetic: Format to MPlayer coding style.
ib
parents: 36010
diff changeset
168 gtk_widget_show(URLDialog);
35988
ad1a5580c91d Make create_URL() static.
ib
parents: 35987
diff changeset
169 }