2901
|
1
|
|
2 #include <sys/stat.h>
|
|
3 #include <glob.h>
|
|
4 #include <unistd.h>
|
2985
|
5 #include <string.h>
|
|
6 #include <stdlib.h>
|
2901
|
7
|
|
8 #include "sb.h"
|
|
9 #include "../../events.h"
|
|
10 #include "../../../config.h"
|
|
11 #include "../../../help_mp.h"
|
|
12
|
|
13 #include "../widgets.h"
|
|
14 #include "../app.h"
|
|
15
|
|
16 GtkWidget * SkinList;
|
|
17 char * sbSelectedSkin=NULL;
|
|
18 char * sbMPlayerDirInHome=NULL;
|
|
19 char * sbMPlayerPrefixDir=NULL;
|
|
20
|
|
21 void HideSkinBrowser( void )
|
|
22 {
|
|
23 gtk_widget_hide( SkinBrowser );
|
|
24 gtkVisibleSkinBrowser=0;
|
|
25 gtkShMem->vs.window=evSkinBrowser;
|
|
26 gtkSendMessage( evHideWindow );
|
|
27 gtkSendMessage( evSkinBrowser );
|
|
28 }
|
|
29
|
|
30 char gtkOldSkin[128];
|
|
31
|
|
32 int gtkFillSkinList( gchar * mdir )
|
|
33 {
|
|
34 gchar * str[2];
|
|
35 gchar * tmp;
|
|
36 int i;
|
|
37 glob_t gg;
|
|
38 struct stat fs;
|
|
39
|
|
40 strcpy( gtkOldSkin,gtkShMem->sb.name );
|
|
41 if ( ( str[0]=(char *)calloc( 1,7 ) ) == NULL )
|
|
42 {
|
|
43 gtkMessageBox( GTK_MB_FATAL,MSGTR_SKINBROWSER_NotEnoughMemory );
|
|
44 return 0;
|
|
45 }
|
|
46 str[1]="";
|
|
47 strcpy( str[0],"default" );
|
|
48 if ( gtkFindCList( SkinList,str[0] ) == -1 ) gtk_clist_append( GTK_CLIST( SkinList ),str );
|
|
49 free( str[0] );
|
|
50
|
|
51 glob( mdir,GLOB_NOSORT,NULL,&gg );
|
|
52 for( i=0;i<gg.gl_pathc;i++ )
|
|
53 {
|
|
54 if ( !strcmp( gg.gl_pathv[i],"." ) || !strcmp( gg.gl_pathv[i],".." ) ) continue;
|
|
55 stat( gg.gl_pathv[i],&fs );
|
|
56 if ( S_ISDIR( fs.st_mode ) )
|
|
57 {
|
|
58 tmp=strrchr( gg.gl_pathv[i],'/' ); tmp++;
|
|
59 if ( !strcmp( tmp,"default" ) ) continue;
|
|
60 if ( ( str[0]=(char *)malloc( strlen( tmp ) + 1 ) ) == NULL ) { gtkMessageBox( GTK_MB_FATAL,MSGTR_SKINBROWSER_NotEnoughMemory ); return 0; }
|
|
61 strcpy( str[0],tmp );
|
|
62 if ( gtkFindCList( SkinList,str[0] ) == -1 ) gtk_clist_append( GTK_CLIST( SkinList ),str );
|
|
63 free( str[0] );
|
|
64 }
|
|
65 }
|
|
66 globfree( &gg );
|
|
67 return 1;
|
|
68 }
|
|
69
|
|
70 void on_SkinBrowser_destroy( GtkObject * object,gpointer user_data )
|
|
71 { HideSkinBrowser(); }
|
|
72
|
|
73 void on_SkinBrowser_Cancel( GtkObject * object,gpointer user_data )
|
|
74 {
|
|
75 strcpy( gtkShMem->sb.name,gtkOldSkin );
|
|
76 HideSkinBrowser();
|
|
77 }
|
|
78
|
|
79 void on_SkinList_select_row( GtkCList * clist,gint row,gint column,GdkEvent * bevent,gpointer user_data )
|
|
80 {
|
|
81 gtk_clist_get_text( clist,row,0,&sbSelectedSkin );
|
|
82 strcpy( gtkShMem->sb.name,sbSelectedSkin );
|
|
83 gtkSendMessage( evSkinBrowser );
|
|
84 if( !bevent ) return;
|
|
85 if( bevent->type == GDK_2BUTTON_PRESS ) HideSkinBrowser();
|
|
86 }
|
|
87
|
|
88 GtkWidget * create_SkinBrowser( void )
|
|
89 {
|
|
90 GtkWidget * SkinBrowser;
|
|
91 GtkWidget * frame5;
|
|
92 GtkWidget * frame6;
|
|
93 GtkWidget * frame7;
|
|
94 GtkWidget * frame8;
|
|
95 GtkWidget * vbox5;
|
|
96 GtkWidget * label;
|
|
97 GtkWidget * hseparator4;
|
|
98 GtkWidget * scrolledwindow1;
|
|
99 GtkWidget * label2;
|
|
100 GtkWidget * hseparator5;
|
|
101 GtkWidget * hbuttonbox4;
|
|
102 GtkWidget * Cancel;
|
|
103 GtkWidget * Ok;
|
|
104 GtkAccelGroup * accel_group;
|
|
105
|
|
106 accel_group = gtk_accel_group_new ();
|
|
107
|
|
108 SkinBrowser=gtk_window_new( GTK_WINDOW_DIALOG );
|
|
109 gtk_widget_set_name( SkinBrowser,MSGTR_SkinBrowser );
|
|
110 gtk_object_set_data( GTK_OBJECT( SkinBrowser ),MSGTR_SkinBrowser,SkinBrowser );
|
|
111 gtk_widget_set_usize( SkinBrowser,256,320 );
|
|
112 gtk_container_set_border_width( GTK_CONTAINER( SkinBrowser ),1 );
|
|
113 // GTK_WIDGET_SET_FLAGS( SkinBrowser,GTK_CAN_FOCUS );
|
|
114 GTK_WIDGET_SET_FLAGS( SkinBrowser,GTK_CAN_DEFAULT );
|
|
115 gtk_widget_set_events( SkinBrowser,GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK | GDK_FOCUS_CHANGE_MASK | GDK_STRUCTURE_MASK | GDK_PROPERTY_CHANGE_MASK | GDK_VISIBILITY_NOTIFY_MASK );
|
|
116 gtk_window_set_title( GTK_WINDOW( SkinBrowser ),MSGTR_SkinBrowser );
|
|
117 gtk_window_set_position( GTK_WINDOW( SkinBrowser ),GTK_WIN_POS_CENTER );
|
|
118 gtk_window_set_policy( GTK_WINDOW( SkinBrowser ),FALSE,FALSE,TRUE );
|
|
119
|
|
120 frame5=gtk_frame_new( NULL );
|
|
121 gtk_widget_set_name( frame5,"frame5" );
|
|
122 gtk_widget_ref( frame5 );
|
|
123 gtk_object_set_data_full( GTK_OBJECT( SkinBrowser ),"frame5",frame5,
|
|
124 ( GtkDestroyNotify ) gtk_widget_unref );
|
|
125 gtk_widget_show( frame5 );
|
|
126 gtk_container_add( GTK_CONTAINER( SkinBrowser ),frame5 );
|
|
127 gtk_frame_set_shadow_type( GTK_FRAME( frame5 ),GTK_SHADOW_IN );
|
|
128
|
|
129 frame6=gtk_frame_new( NULL );
|
|
130 gtk_widget_set_name( frame6,"frame6" );
|
|
131 gtk_widget_ref( frame6 );
|
|
132 gtk_object_set_data_full( GTK_OBJECT( SkinBrowser ),"frame6",frame6,
|
|
133 ( GtkDestroyNotify ) gtk_widget_unref );
|
|
134 gtk_widget_show( frame6 );
|
|
135 gtk_container_add( GTK_CONTAINER( frame5 ),frame6 );
|
|
136 gtk_frame_set_shadow_type( GTK_FRAME( frame6 ),GTK_SHADOW_NONE );
|
|
137
|
|
138 frame7=gtk_frame_new( NULL );
|
|
139 gtk_widget_set_name( frame7,"frame7" );
|
|
140 gtk_widget_ref( frame7 );
|
|
141 gtk_object_set_data_full( GTK_OBJECT( SkinBrowser ),"frame7",frame7,
|
|
142 ( GtkDestroyNotify ) gtk_widget_unref );
|
|
143 gtk_widget_show( frame7 );
|
|
144 gtk_container_add( GTK_CONTAINER( frame6 ),frame7 );
|
|
145 gtk_frame_set_shadow_type( GTK_FRAME( frame7 ),GTK_SHADOW_ETCHED_OUT );
|
|
146
|
|
147 frame8=gtk_frame_new( NULL );
|
|
148 gtk_widget_set_name( frame8,"frame8" );
|
|
149 gtk_widget_ref( frame8 );
|
|
150 gtk_object_set_data_full( GTK_OBJECT( SkinBrowser ),"frame8",frame8,
|
|
151 ( GtkDestroyNotify ) gtk_widget_unref );
|
|
152 gtk_widget_show( frame8 );
|
|
153 gtk_container_add( GTK_CONTAINER( frame7 ),frame8 );
|
|
154 gtk_frame_set_shadow_type( GTK_FRAME( frame8 ),GTK_SHADOW_NONE );
|
|
155
|
|
156 vbox5=gtk_vbox_new( FALSE,0 );
|
|
157 gtk_widget_set_name( vbox5,"vbox5" );
|
|
158 gtk_widget_ref( vbox5 );
|
|
159 gtk_object_set_data_full( GTK_OBJECT( SkinBrowser ),"vbox5",vbox5,
|
|
160 ( GtkDestroyNotify ) gtk_widget_unref );
|
|
161 gtk_widget_show( vbox5 );
|
|
162 gtk_container_add( GTK_CONTAINER( frame8 ),vbox5 );
|
|
163
|
|
164 label=gtk_label_new( "Skins:" );
|
|
165 gtk_widget_set_name( label,"label" );
|
|
166 gtk_widget_ref( label );
|
|
167 gtk_object_set_data_full( GTK_OBJECT( SkinBrowser ),"label",label,
|
|
168 ( GtkDestroyNotify ) gtk_widget_unref );
|
|
169 gtk_widget_show( label );
|
|
170 gtk_box_pack_start( GTK_BOX( vbox5 ),label,FALSE,FALSE,0 );
|
|
171 gtk_label_set_justify( GTK_LABEL( label ),GTK_JUSTIFY_RIGHT );
|
|
172 gtk_misc_set_alignment( GTK_MISC( label ),7.45058e-09,7.45058e-09 );
|
|
173
|
|
174 hseparator4=gtk_hseparator_new();
|
|
175 gtk_widget_set_name( hseparator4,"hseparator4" );
|
|
176 gtk_widget_ref( hseparator4 );
|
|
177 gtk_object_set_data_full( GTK_OBJECT( SkinBrowser ),"hseparator4",hseparator4,
|
|
178 ( GtkDestroyNotify ) gtk_widget_unref );
|
|
179 gtk_widget_show( hseparator4 );
|
|
180 gtk_box_pack_start( GTK_BOX( vbox5 ),hseparator4,FALSE,TRUE,0 );
|
|
181 gtk_widget_set_usize( hseparator4,-2,5 );
|
|
182
|
|
183 scrolledwindow1=gtk_scrolled_window_new( NULL,NULL );
|
|
184 gtk_widget_set_name( scrolledwindow1,"scrolledwindow1" );
|
|
185 gtk_widget_ref( scrolledwindow1 );
|
|
186 gtk_object_set_data_full( GTK_OBJECT( SkinBrowser ),"scrolledwindow1",scrolledwindow1,
|
|
187 ( GtkDestroyNotify ) gtk_widget_unref );
|
|
188 gtk_widget_show( scrolledwindow1 );
|
|
189 gtk_box_pack_start( GTK_BOX( vbox5 ),scrolledwindow1,TRUE,TRUE,0 );
|
|
190 gtk_container_set_border_width( GTK_CONTAINER( scrolledwindow1 ),2 );
|
|
191 gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW( scrolledwindow1 ),GTK_POLICY_NEVER,GTK_POLICY_AUTOMATIC );
|
|
192
|
|
193 SkinList=gtk_clist_new( 1 );
|
|
194 gtk_widget_set_name( SkinList,"SkinList" );
|
|
195 gtk_widget_ref( SkinList );
|
|
196 gtk_object_set_data_full( GTK_OBJECT( SkinBrowser ),"SkinList",SkinList,
|
|
197 ( GtkDestroyNotify ) gtk_widget_unref );
|
|
198 gtk_widget_show( SkinList );
|
|
199 gtk_container_add( GTK_CONTAINER( scrolledwindow1 ),SkinList );
|
|
200 gtk_clist_set_column_width( GTK_CLIST( SkinList ),0,80 );
|
|
201 gtk_clist_set_selection_mode( GTK_CLIST( SkinList ),GTK_SELECTION_SINGLE );
|
|
202 gtk_clist_column_titles_hide( GTK_CLIST( SkinList ) );
|
|
203 gtk_clist_set_shadow_type( GTK_CLIST( SkinList ),GTK_SHADOW_ETCHED_OUT );
|
|
204
|
|
205 label2=gtk_label_new( "label2" );
|
|
206 gtk_widget_set_name( label2,"label2" );
|
|
207 gtk_widget_ref( label2 );
|
|
208 gtk_object_set_data_full( GTK_OBJECT( SkinBrowser ),"label2",label2,(GtkDestroyNotify)gtk_widget_unref );
|
|
209 gtk_widget_show( label2 );
|
|
210 gtk_clist_set_column_widget( GTK_CLIST( SkinList ),0,label2 );
|
|
211
|
|
212 hseparator5=gtk_hseparator_new();
|
|
213 gtk_widget_set_name( hseparator5,"hseparator5" );
|
|
214 gtk_widget_ref( hseparator5 );
|
|
215 gtk_object_set_data_full( GTK_OBJECT( SkinBrowser ),"hseparator5",hseparator5,(GtkDestroyNotify)gtk_widget_unref );
|
|
216 gtk_widget_show( hseparator5 );
|
|
217 gtk_box_pack_start( GTK_BOX( vbox5 ),hseparator5,FALSE,TRUE,0 );
|
|
218 gtk_widget_set_usize( hseparator5,-2,9 );
|
|
219
|
|
220 hbuttonbox4=gtk_hbutton_box_new();
|
|
221 gtk_widget_set_name( hbuttonbox4,"hbuttonbox4" );
|
|
222 gtk_widget_ref( hbuttonbox4 );
|
|
223 gtk_object_set_data_full( GTK_OBJECT( SkinBrowser ),"hbuttonbox4",hbuttonbox4,(GtkDestroyNotify)gtk_widget_unref );
|
|
224 gtk_widget_show( hbuttonbox4 );
|
|
225 gtk_box_pack_start( GTK_BOX( vbox5 ),hbuttonbox4,FALSE,TRUE,0 );
|
|
226 gtk_button_box_set_layout( GTK_BUTTON_BOX( hbuttonbox4 ),GTK_BUTTONBOX_END );
|
|
227 gtk_button_box_set_spacing( GTK_BUTTON_BOX( hbuttonbox4 ),0 );
|
|
228 gtk_button_box_set_child_size( GTK_BUTTON_BOX( hbuttonbox4 ),80,0 );
|
|
229
|
|
230 Ok=gtk_button_new_with_label( MSGTR_Ok );
|
|
231 gtk_widget_set_name( Ok,MSGTR_Ok );
|
|
232 gtk_widget_ref( Ok );
|
|
233 gtk_object_set_data_full( GTK_OBJECT( SkinBrowser ),MSGTR_Ok,Ok,(GtkDestroyNotify)gtk_widget_unref );
|
|
234 gtk_widget_show( Ok );
|
|
235 gtk_container_add( GTK_CONTAINER( hbuttonbox4 ),Ok );
|
|
236 gtk_widget_set_usize( Ok,-2,33 );
|
|
237 GTK_WIDGET_SET_FLAGS( Ok,GTK_CAN_DEFAULT );
|
|
238 gtk_widget_add_accelerator( Ok,"released",accel_group,GDK_Return,0,GTK_ACCEL_VISIBLE );
|
|
239
|
|
240 Cancel=gtk_button_new_with_label( MSGTR_Cancel );
|
|
241 gtk_widget_set_name( Cancel,MSGTR_Cancel );
|
|
242 gtk_widget_ref( Cancel );
|
|
243 gtk_object_set_data_full( GTK_OBJECT( SkinBrowser ),MSGTR_Cancel,Cancel,(GtkDestroyNotify)gtk_widget_unref );
|
|
244 gtk_widget_show( Cancel );
|
|
245 gtk_container_add( GTK_CONTAINER( hbuttonbox4 ),Cancel );
|
|
246 gtk_widget_set_usize( Cancel,-2,33 );
|
|
247 GTK_WIDGET_SET_FLAGS( Cancel,GTK_CAN_DEFAULT );
|
|
248 gtk_widget_add_accelerator( Cancel,"released",accel_group,GDK_Escape,0,GTK_ACCEL_VISIBLE );
|
|
249
|
|
250 gtk_signal_connect( GTK_OBJECT( SkinBrowser ),"destroy",GTK_SIGNAL_FUNC( on_SkinBrowser_destroy ),NULL );
|
|
251 gtk_signal_connect( GTK_OBJECT( SkinList ),"select_row",GTK_SIGNAL_FUNC( on_SkinList_select_row ),NULL );
|
|
252 gtk_signal_connect( GTK_OBJECT( Ok ),"released",GTK_SIGNAL_FUNC( on_SkinBrowser_destroy ),NULL );
|
|
253 gtk_signal_connect( GTK_OBJECT( Cancel ),"released",GTK_SIGNAL_FUNC( on_SkinBrowser_Cancel ),NULL );
|
|
254
|
|
255 if ( ( sbMPlayerDirInHome=(char *)calloc( 1,strlen( skinDirInHome ) + 4 ) ) != NULL )
|
|
256 { strcpy( sbMPlayerDirInHome,skinDirInHome ); strcat( sbMPlayerDirInHome,"/*" ); }
|
|
257 if ( ( sbMPlayerPrefixDir=(char *)calloc( 1,strlen( skinMPlayerDir ) + 4 ) ) != NULL )
|
|
258 { strcpy( sbMPlayerPrefixDir,skinMPlayerDir ); strcat( sbMPlayerPrefixDir,"/*" ); }
|
|
259
|
|
260 gtk_window_add_accel_group( GTK_WINDOW( SkinBrowser ),accel_group );
|
|
261 gtk_widget_grab_focus( SkinList );
|
|
262
|
|
263 return SkinBrowser;
|
|
264 }
|