Mercurial > mplayer.hg
annotate gui/dialog/url.c @ 36016:7ee29db149cd
Cosmetic: Rearrange code.
author | ib |
---|---|
date | Sun, 31 Mar 2013 12:10:42 +0000 |
parents | 5c720c434d56 |
children | b3764c930d0c |
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 | |
19 #include <sys/types.h> | |
20 #include <sys/stat.h> | |
21 #include <unistd.h> | |
22 #include <stdlib.h> | |
23 #include <stdio.h> | |
24 #include <string.h> | |
25 | |
26 #include <gdk/gdkkeysyms.h> | |
27 #include <gtk/gtk.h> | |
28 | |
29 #include "url.h" | |
30 #include "tools.h" | |
31 #include "gui/interface.h" | |
35525 | 32 #include "gui/app/app.h" |
35772 | 33 #include "gui/ui/actions.h" |
35529 | 34 #include "dialog.h" |
33742
e1539e14d60f
Move purely list related parts of gtkSet() from interface.c to list.c.
ib
parents:
33740
diff
changeset
|
35 #include "gui/util/list.h" |
33737 | 36 #include "gui/util/string.h" |
33572 | 37 #include "help_mp.h" |
38 | |
35978 | 39 GtkWidget * URLDialog = NULL; |
33572 | 40 |
41 static GtkWidget * URLCombo; | |
42 static GtkWidget * URLEntry; | |
43 static GList * URLComboEntrys = NULL; | |
44 | |
45 static void on_Button_pressed( GtkButton * button,gpointer user_data ) | |
46 { | |
47 urlItem * item; | |
48 | |
36010 | 49 (void) button; |
50 | |
33572 | 51 if ( (int)user_data ) |
52 { | |
53 gchar * str= strdup( gtk_entry_get_text( GTK_ENTRY( URLEntry ) ) ); | |
54 | |
55 if ( str ) | |
56 { | |
34959 | 57 if ( !strstr( str,"://" ) ) |
33572 | 58 { |
59 gchar * tmp; | |
60 tmp=malloc( strlen( str ) + 8 ); | |
61 sprintf( tmp,"http://%s",str ); | |
62 free( str ); str=tmp; | |
63 } | |
64 URLComboEntrys=g_list_prepend( URLComboEntrys,(gchar *)str ); | |
65 | |
66 item=calloc( 1,sizeof( urlItem ) ); | |
67 item->url=gstrdup( str ); | |
34663 | 68 listMgr( URLLIST_ITEM_ADD,item ); |
33572 | 69 |
35452 | 70 uiSetFile( NULL,str,STREAMTYPE_STREAM ); guiInfo.NewPlay=GUI_FILE_NEW; |
35352 | 71 listMgr(PLAYLIST_DELETE, 0); |
35350 | 72 add_to_gui_playlist(str, PLAYLIST_ITEM_APPEND); |
35773 | 73 uiEvent( evPlay,0 ); |
33572 | 74 } |
75 } | |
35997 | 76 gtk_widget_destroy( URLDialog ); |
33572 | 77 } |
78 | |
35996 | 79 static GtkWidget * CreateURLDialog( void ) |
33572 | 80 { |
81 GtkWidget * vbox1; | |
82 GtkWidget * hbox1; | |
83 GtkWidget * hbuttonbox1; | |
84 GtkWidget * Ok; | |
85 GtkWidget * Cancel; | |
86 GtkAccelGroup * accel_group; | |
87 | |
88 accel_group=gtk_accel_group_new(); | |
89 | |
35978 | 90 URLDialog=gtk_window_new( GTK_WINDOW_TOPLEVEL ); |
91 gtk_widget_set_name( URLDialog,"URL" ); | |
92 gtk_object_set_data( GTK_OBJECT( URLDialog ),"URL",URLDialog ); | |
93 gtk_widget_set_usize( URLDialog,384,70 ); | |
94 GTK_WIDGET_SET_FLAGS( URLDialog,GTK_CAN_DEFAULT ); | |
95 gtk_window_set_title( GTK_WINDOW( URLDialog ),MSGTR_Network ); | |
96 gtk_window_set_position( GTK_WINDOW( URLDialog ),GTK_WIN_POS_CENTER ); | |
97 gtk_window_set_policy( GTK_WINDOW( URLDialog ),TRUE,TRUE,FALSE ); | |
98 gtk_window_set_wmclass( GTK_WINDOW( URLDialog ),"Network","MPlayer" ); | |
33572 | 99 |
35978 | 100 gtk_widget_realize( URLDialog ); |
101 gtkAddIcon( URLDialog ); | |
33572 | 102 |
35978 | 103 vbox1=AddVBox( AddDialogFrame( URLDialog ),0 ); |
33572 | 104 hbox1=AddHBox( vbox1,1 ); |
105 AddLabel( "URL: ",hbox1 ); | |
106 | |
107 URLCombo=AddComboBox( hbox1 ); | |
108 /* | |
109 gtk_combo_new(); | |
110 gtk_widget_set_name( URLCombo,"URLCombo" ); | |
111 gtk_widget_show( URLCombo ); | |
112 gtk_box_pack_start( GTK_BOX( hbox1 ),URLCombo,TRUE,TRUE,0 ); | |
113 */ | |
114 URLEntry=GTK_COMBO( URLCombo )->entry; | |
115 gtk_widget_set_name( URLEntry,"URLEntry" ); | |
116 gtk_widget_show( URLEntry ); | |
117 | |
118 AddHSeparator( vbox1 ); | |
119 | |
120 hbuttonbox1=AddHButtonBox( vbox1 ); | |
121 gtk_button_box_set_layout( GTK_BUTTON_BOX( hbuttonbox1 ),GTK_BUTTONBOX_END ); | |
122 gtk_button_box_set_spacing( GTK_BUTTON_BOX( hbuttonbox1 ),10 ); | |
123 | |
124 Ok=AddButton( MSGTR_Ok,hbuttonbox1 ); | |
125 Cancel=AddButton( MSGTR_Cancel,hbuttonbox1 ); | |
126 | |
127 gtk_widget_add_accelerator( Ok,"clicked",accel_group,GDK_Return,0,GTK_ACCEL_VISIBLE ); | |
128 gtk_widget_add_accelerator( Cancel,"clicked",accel_group,GDK_Escape,0,GTK_ACCEL_VISIBLE ); | |
129 | |
36008 | 130 gtk_signal_connect( GTK_OBJECT( URLDialog ),"destroy",GTK_SIGNAL_FUNC( gtk_widget_destroyed ),&URLDialog ); |
33572 | 131 gtk_signal_connect( GTK_OBJECT( Ok ),"clicked",GTK_SIGNAL_FUNC( on_Button_pressed ),(void *)1 ); |
132 gtk_signal_connect( GTK_OBJECT( Cancel ),"clicked",GTK_SIGNAL_FUNC( on_Button_pressed ),NULL ); | |
133 | |
134 gtk_widget_grab_focus( URLEntry ); | |
35978 | 135 gtk_window_add_accel_group( GTK_WINDOW( URLDialog ),accel_group ); |
33572 | 136 |
35978 | 137 return URLDialog; |
33572 | 138 } |
35988 | 139 |
140 void ShowURLDialog( void ) | |
141 { | |
142 urlItem * item; | |
143 | |
144 if ( URLDialog ) gtkActive( URLDialog ); | |
35996 | 145 else URLDialog=CreateURLDialog(); |
35988 | 146 |
147 item = listMgr( URLLIST_GET,0 ); | |
148 | |
149 if ( item ) | |
150 { | |
151 g_list_free( URLComboEntrys ); | |
152 URLComboEntrys=NULL; | |
153 while( item ) | |
154 { | |
155 URLComboEntrys=g_list_append( URLComboEntrys,(gchar *)item->url ); | |
156 item=item->next; | |
157 } | |
158 } | |
159 | |
160 if ( URLComboEntrys ) | |
161 { | |
162 gtk_entry_set_text( GTK_ENTRY( URLEntry ),URLComboEntrys->data ); | |
163 gtk_combo_set_popdown_strings( GTK_COMBO( URLCombo ),URLComboEntrys ); | |
164 } | |
165 | |
166 gtk_widget_show( URLDialog ); | |
167 } |