23077
|
1
|
|
2 #include <sys/stat.h>
|
|
3 #include <glob.h>
|
|
4 #include <unistd.h>
|
|
5 #include <string.h>
|
|
6 #include <stdlib.h>
|
|
7 #include <stdio.h>
|
|
8
|
|
9 #include "sb.h"
|
|
10 #include "common.h"
|
|
11
|
|
12 #include "app.h"
|
|
13 #include "config.h"
|
|
14 #include "help_mp.h"
|
|
15
|
|
16 #include "../widgets.h"
|
|
17 #include "app.h"
|
|
18
|
|
19 GtkWidget * SkinList = NULL;
|
|
20 char * sbSelectedSkin=NULL;
|
|
21 /* FIXME: Eventually remove the obsolete directory names. */
|
|
22 char * sbMPlayerDirInHome=NULL;
|
|
23 char * sbMPlayerDirInHome_obsolete=NULL;
|
|
24 char * sbMPlayerPrefixDir=NULL;
|
|
25 char * sbMPlayerPrefixDir_obsolete=NULL;
|
|
26
|
|
27 char * gtkOldSkin=NULL;
|
|
28 static char * prev=NULL;
|
|
29
|
|
30 GtkWidget * SkinBrowser = NULL;
|
|
31
|
|
32 void ShowSkinBrowser( void )
|
|
33 {
|
|
34 if ( SkinBrowser ) gtkActive( SkinBrowser );
|
|
35 else SkinBrowser=create_SkinBrowser();
|
|
36 }
|
|
37
|
|
38 void HideSkinBrowser( void )
|
|
39 {
|
|
40 if ( !SkinBrowser ) return;
|
|
41 gtk_widget_hide( SkinBrowser );
|
|
42 gtk_widget_destroy( SkinBrowser );
|
|
43 SkinBrowser=NULL;
|
|
44 }
|
|
45
|
|
46 int gtkFillSkinList( gchar * mdir )
|
|
47 {
|
|
48 gchar * str[2];
|
|
49 gchar * tmp;
|
|
50 int i;
|
|
51 glob_t gg;
|
|
52 struct stat fs;
|
|
53
|
|
54 gtkOldSkin=strdup( skinName );
|
|
55 prev=gtkOldSkin;
|
|
56
|
|
57 str[0]="default";
|
|
58 str[1]="";
|
|
59 if ( gtkFindCList( SkinList,str[0] ) == -1 ) gtk_clist_append( GTK_CLIST( SkinList ),str );
|
|
60
|
|
61 glob( mdir,GLOB_NOSORT,NULL,&gg );
|
|
62 for( i=0;i<(int)gg.gl_pathc;i++ )
|
|
63 {
|
|
64 if ( !strcmp( gg.gl_pathv[i],"." ) || !strcmp( gg.gl_pathv[i],".." ) ) continue;
|
|
65 stat( gg.gl_pathv[i],&fs );
|
|
66 if ( S_ISDIR( fs.st_mode ) )
|
|
67 {
|
|
68 tmp=strrchr( gg.gl_pathv[i],'/' ); tmp++;
|
|
69 if ( !strcmp( tmp,"default" ) ) continue;
|
|
70 str[0]=tmp;
|
|
71 if ( gtkFindCList( SkinList,str[0] ) == -1 ) gtk_clist_append( GTK_CLIST( SkinList ),str );
|
|
72 }
|
|
73 }
|
|
74 globfree( &gg );
|
|
75 return 1;
|
|
76 }
|
|
77
|
|
78 static void prButton( GtkObject * object,gpointer user_data )
|
|
79 {
|
|
80 if ( sbSelectedSkin )
|
|
81 {
|
|
82 switch ( (int)user_data )
|
|
83 {
|
|
84 case 0: // cancel
|
|
85 if ( strcmp( sbSelectedSkin,gtkOldSkin ) ) ChangeSkin( gtkOldSkin );
|
|
86 break;
|
|
87 case 1: // ok
|
|
88 ChangeSkin( sbSelectedSkin );
|
|
89 if ( skinName ) free( skinName );
|
|
90 skinName=strdup( sbSelectedSkin );
|
|
91 break;
|
|
92 }
|
|
93 }
|
|
94 HideSkinBrowser();
|
|
95 }
|
|
96
|
|
97 static void on_SkinList_select_row( GtkCList * clist,gint row,gint column,GdkEvent * bevent,gpointer user_data )
|
|
98 {
|
|
99 gtk_clist_get_text( clist,row,0,&sbSelectedSkin );
|
|
100 if ( strcmp( prev,sbSelectedSkin ) )
|
|
101 {
|
|
102 prev=sbSelectedSkin;
|
|
103 ChangeSkin( sbSelectedSkin );
|
|
104 gtkActive( SkinBrowser );
|
|
105 }
|
|
106 if( !bevent ) return;
|
|
107 if( bevent->type == GDK_2BUTTON_PRESS )
|
|
108 {
|
|
109 if ( skinName ) free( skinName );
|
|
110 skinName=strdup( sbSelectedSkin );
|
|
111 HideSkinBrowser();
|
|
112 }
|
|
113 }
|
|
114
|
|
115 GtkWidget * create_SkinBrowser( void )
|
|
116 {
|
|
117 GtkWidget * vbox5;
|
|
118 GtkWidget * scrolledwindow1;
|
|
119 GtkWidget * hbuttonbox4;
|
|
120 GtkWidget * Cancel;
|
|
121 GtkWidget * Ok;
|
|
122 GtkAccelGroup * accel_group;
|
|
123
|
|
124 accel_group = gtk_accel_group_new ();
|
|
125
|
|
126 SkinBrowser=gtk_window_new( GTK_WINDOW_TOPLEVEL );
|
|
127 gtk_widget_set_name( SkinBrowser,MSGTR_SkinBrowser );
|
|
128 gtk_object_set_data( GTK_OBJECT( SkinBrowser ),MSGTR_SkinBrowser,SkinBrowser );
|
|
129 gtk_widget_set_usize( SkinBrowser,256,320 );
|
|
130 gtk_container_set_border_width( GTK_CONTAINER( SkinBrowser ),1 );
|
|
131 GTK_WIDGET_SET_FLAGS( SkinBrowser,GTK_CAN_DEFAULT );
|
|
132 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 );
|
|
133 gtk_window_set_title( GTK_WINDOW( SkinBrowser ),MSGTR_SkinBrowser );
|
|
134 gtk_window_set_position( GTK_WINDOW( SkinBrowser ),GTK_WIN_POS_CENTER );
|
|
135 gtk_window_set_policy( GTK_WINDOW( SkinBrowser ),FALSE,FALSE,TRUE );
|
|
136 gtk_window_set_wmclass( GTK_WINDOW( SkinBrowser ),"SkinBrowser","MPlayer" );
|
|
137
|
|
138 gtk_widget_realize( SkinBrowser );
|
|
139 gtkAddIcon( SkinBrowser );
|
|
140
|
|
141 vbox5=AddVBox( AddDialogFrame( SkinBrowser ),0 );
|
|
142 AddLabel( MSGTR_SKIN_LABEL,vbox5 );
|
|
143 AddHSeparator( vbox5 );
|
|
144
|
|
145 scrolledwindow1=gtk_scrolled_window_new( NULL,NULL );
|
|
146 gtk_widget_set_name( scrolledwindow1,"scrolledwindow1" );
|
|
147 gtk_widget_ref( scrolledwindow1 );
|
|
148 gtk_object_set_data_full( GTK_OBJECT( SkinBrowser ),"scrolledwindow1",scrolledwindow1,(GtkDestroyNotify)gtk_widget_unref );
|
|
149 gtk_widget_show( scrolledwindow1 );
|
|
150 gtk_box_pack_start( GTK_BOX( vbox5 ),scrolledwindow1,TRUE,TRUE,0 );
|
|
151 gtk_container_set_border_width( GTK_CONTAINER( scrolledwindow1 ),2 );
|
|
152 gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW( scrolledwindow1 ),GTK_POLICY_NEVER,GTK_POLICY_AUTOMATIC );
|
|
153
|
|
154 SkinList=gtk_clist_new( 1 );
|
|
155 gtk_widget_set_name( SkinList,"SkinList" );
|
|
156 gtk_widget_ref( SkinList );
|
|
157 gtk_object_set_data_full( GTK_OBJECT( SkinBrowser ),"SkinList",SkinList,(GtkDestroyNotify)gtk_widget_unref );
|
|
158 gtk_widget_show( SkinList );
|
|
159 gtk_container_add( GTK_CONTAINER( scrolledwindow1 ),SkinList );
|
|
160 gtk_clist_set_column_width( GTK_CLIST( SkinList ),0,80 );
|
|
161 gtk_clist_set_selection_mode( GTK_CLIST( SkinList ),GTK_SELECTION_SINGLE );
|
|
162 gtk_clist_column_titles_hide( GTK_CLIST( SkinList ) );
|
|
163 gtk_clist_set_shadow_type( GTK_CLIST( SkinList ),GTK_SHADOW_ETCHED_OUT );
|
|
164
|
|
165 AddHSeparator( vbox5 );
|
|
166
|
|
167 hbuttonbox4=AddHButtonBox( vbox5 );
|
|
168 gtk_button_box_set_layout( GTK_BUTTON_BOX( hbuttonbox4 ),GTK_BUTTONBOX_SPREAD );
|
|
169 gtk_button_box_set_spacing( GTK_BUTTON_BOX( hbuttonbox4 ),10 );
|
|
170
|
|
171 Ok=AddButton( MSGTR_Ok,hbuttonbox4 );
|
|
172 Cancel=AddButton( MSGTR_Cancel,hbuttonbox4 );
|
|
173
|
|
174 gtk_widget_add_accelerator( Ok,"clicked",accel_group,GDK_Return,0,GTK_ACCEL_VISIBLE );
|
|
175 gtk_widget_add_accelerator( Cancel,"clicked",accel_group,GDK_Escape,0,GTK_ACCEL_VISIBLE );
|
|
176
|
|
177 gtk_signal_connect( GTK_OBJECT( SkinBrowser ),"destroy",GTK_SIGNAL_FUNC( WidgetDestroy ),&SkinBrowser );
|
|
178 gtk_signal_connect( GTK_OBJECT( SkinList ),"select_row",GTK_SIGNAL_FUNC( on_SkinList_select_row ),NULL );
|
|
179 gtk_signal_connect( GTK_OBJECT( Ok ),"clicked",GTK_SIGNAL_FUNC( prButton ),(void *)1 );
|
|
180 gtk_signal_connect( GTK_OBJECT( Cancel ),"clicked",GTK_SIGNAL_FUNC( prButton ),(void *)0 );
|
|
181
|
|
182 if ( ( sbMPlayerDirInHome_obsolete=calloc( 1,strlen( skinDirInHome_obsolete ) + 4 ) ) != NULL )
|
|
183 { strcpy( sbMPlayerDirInHome_obsolete,skinDirInHome_obsolete ); strcat( sbMPlayerDirInHome_obsolete,"/*" ); }
|
|
184 if ( ( sbMPlayerDirInHome=calloc( 1,strlen( skinDirInHome ) + 4 ) ) != NULL )
|
|
185 { strcpy( sbMPlayerDirInHome,skinDirInHome ); strcat( sbMPlayerDirInHome,"/*" ); }
|
|
186 if ( ( sbMPlayerPrefixDir_obsolete=calloc( 1,strlen( skinMPlayerDir ) + 4 ) ) != NULL )
|
|
187 { strcpy( sbMPlayerPrefixDir_obsolete,skinMPlayerDir ); strcat( sbMPlayerPrefixDir_obsolete,"/*" ); }
|
|
188 if ( ( sbMPlayerPrefixDir=calloc( 1,strlen( skinMPlayerDir ) + 4 ) ) != NULL )
|
|
189 { strcpy( sbMPlayerPrefixDir,skinMPlayerDir ); strcat( sbMPlayerPrefixDir,"/*" ); }
|
|
190
|
|
191 gtk_window_add_accel_group( GTK_WINDOW( SkinBrowser ),accel_group );
|
|
192 gtk_widget_grab_focus( SkinList );
|
|
193
|
|
194 return SkinBrowser;
|
|
195 }
|