Mercurial > mplayer.hg
annotate gui/ui/gtk/skinbrowser.c @ 35399:4d7adee0a7ba
Check stat() return value before utilizing its information.
author | ib |
---|---|
date | Wed, 28 Nov 2012 11:40:52 +0000 |
parents | a650895d50a5 |
children | 074069bb765a |
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/stat.h> | |
20 #include <glob.h> | |
21 #include <unistd.h> | |
22 #include <string.h> | |
23 #include <stdlib.h> | |
24 #include <stdio.h> | |
25 | |
26 #include "config.h" | |
27 #include "skinbrowser.h" | |
28 #include "tools.h" | |
29 | |
30 #include "gui/app.h" | |
33749 | 31 #include "gui/cfg.h" |
32 #include "gui/skin/skin.h" | |
33572 | 33 #include "help_mp.h" |
34 | |
35 #include "gui/ui/widgets.h" | |
36 | |
37 GtkWidget * SkinList = NULL; | |
38 char * sbSelectedSkin=NULL; | |
39 char * sbMPlayerDirInHome=NULL; | |
40 char * sbMPlayerPrefixDir=NULL; | |
41 | |
42 char * gtkOldSkin=NULL; | |
43 static char * prev=NULL; | |
44 | |
45 GtkWidget * SkinBrowser = NULL; | |
46 | |
47 void ShowSkinBrowser( void ) | |
48 { | |
49 if ( SkinBrowser ) gtkActive( SkinBrowser ); | |
50 else SkinBrowser=create_SkinBrowser(); | |
51 } | |
52 | |
53 static void HideSkinBrowser( void ) | |
54 { | |
55 if ( !SkinBrowser ) return; | |
56 gtk_widget_hide( SkinBrowser ); | |
57 gtk_widget_destroy( SkinBrowser ); | |
58 SkinBrowser=NULL; | |
59 } | |
60 | |
61 int gtkFillSkinList( gchar * mdir ) | |
62 { | |
63 gchar * str[2]; | |
64 gchar * tmp; | |
65 int i; | |
66 glob_t gg; | |
67 struct stat fs; | |
68 | |
69 gtkOldSkin=strdup( skinName ); | |
70 prev=gtkOldSkin; | |
71 | |
72 str[0]="default"; | |
73 str[1]=""; | |
74 if ( gtkFindCList( SkinList,str[0] ) == -1 ) gtk_clist_append( GTK_CLIST( SkinList ),str ); | |
75 | |
76 glob( mdir,GLOB_NOSORT,NULL,&gg ); | |
77 for( i=0;i<(int)gg.gl_pathc;i++ ) | |
78 { | |
79 if ( !strcmp( gg.gl_pathv[i],"." ) || !strcmp( gg.gl_pathv[i],".." ) ) continue; | |
35399
4d7adee0a7ba
Check stat() return value before utilizing its information.
ib
parents:
34466
diff
changeset
|
80 if ( ( stat( gg.gl_pathv[i],&fs ) == 0 ) && S_ISDIR( fs.st_mode ) ) |
33572 | 81 { |
82 tmp=strrchr( gg.gl_pathv[i],'/' ); tmp++; | |
83 if ( !strcmp( tmp,"default" ) ) continue; | |
84 str[0]=tmp; | |
85 if ( gtkFindCList( SkinList,str[0] ) == -1 ) gtk_clist_append( GTK_CLIST( SkinList ),str ); | |
86 } | |
87 } | |
88 globfree( &gg ); | |
89 return 1; | |
90 } | |
91 | |
34466
a650895d50a5
Use correct data types and common variable names in GTK callback functions.
ib
parents:
33749
diff
changeset
|
92 static void prButton( GtkButton * button,gpointer user_data ) |
33572 | 93 { |
94 if ( sbSelectedSkin ) | |
95 { | |
96 switch ( (int)user_data ) | |
97 { | |
98 case 0: // cancel | |
99 if ( strcmp( sbSelectedSkin,gtkOldSkin ) ) uiChangeSkin( gtkOldSkin ); | |
100 break; | |
101 case 1: // ok | |
102 uiChangeSkin( sbSelectedSkin ); // NOTE TO MYSELF: skin already changed! | |
103 free( skinName ); | |
104 skinName=strdup( sbSelectedSkin ); | |
105 break; | |
106 } | |
107 } | |
108 HideSkinBrowser(); | |
109 } | |
110 | |
34466
a650895d50a5
Use correct data types and common variable names in GTK callback functions.
ib
parents:
33749
diff
changeset
|
111 static void on_SkinList_select_row( GtkCList * clist,gint row,gint column,GdkEvent * event,gpointer user_data ) |
33572 | 112 { |
113 gtk_clist_get_text( clist,row,0,&sbSelectedSkin ); | |
114 if ( strcmp( prev,sbSelectedSkin ) ) | |
115 { | |
116 prev=sbSelectedSkin; | |
117 uiChangeSkin( sbSelectedSkin ); | |
118 gtkActive( SkinBrowser ); | |
119 } | |
34466
a650895d50a5
Use correct data types and common variable names in GTK callback functions.
ib
parents:
33749
diff
changeset
|
120 if( !event ) return; |
a650895d50a5
Use correct data types and common variable names in GTK callback functions.
ib
parents:
33749
diff
changeset
|
121 if( event->type == GDK_2BUTTON_PRESS ) |
33572 | 122 { |
123 free( skinName ); | |
124 skinName=strdup( sbSelectedSkin ); | |
125 HideSkinBrowser(); | |
126 } | |
127 } | |
128 | |
129 GtkWidget * create_SkinBrowser( void ) | |
130 { | |
131 GtkWidget * vbox5; | |
132 GtkWidget * scrolledwindow1; | |
133 GtkWidget * hbuttonbox4; | |
134 GtkWidget * Cancel; | |
135 GtkWidget * Ok; | |
136 GtkAccelGroup * accel_group; | |
137 | |
138 accel_group = gtk_accel_group_new (); | |
139 | |
140 SkinBrowser=gtk_window_new( GTK_WINDOW_TOPLEVEL ); | |
141 gtk_widget_set_name( SkinBrowser,MSGTR_SkinBrowser ); | |
142 gtk_object_set_data( GTK_OBJECT( SkinBrowser ),MSGTR_SkinBrowser,SkinBrowser ); | |
143 gtk_widget_set_usize( SkinBrowser,256,320 ); | |
144 gtk_container_set_border_width( GTK_CONTAINER( SkinBrowser ),1 ); | |
145 GTK_WIDGET_SET_FLAGS( SkinBrowser,GTK_CAN_DEFAULT ); | |
146 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 ); | |
147 gtk_window_set_title( GTK_WINDOW( SkinBrowser ),MSGTR_SkinBrowser ); | |
148 gtk_window_set_position( GTK_WINDOW( SkinBrowser ),GTK_WIN_POS_CENTER ); | |
149 gtk_window_set_policy( GTK_WINDOW( SkinBrowser ),FALSE,FALSE,TRUE ); | |
150 gtk_window_set_wmclass( GTK_WINDOW( SkinBrowser ),"SkinBrowser","MPlayer" ); | |
151 | |
152 gtk_widget_realize( SkinBrowser ); | |
153 gtkAddIcon( SkinBrowser ); | |
154 | |
155 vbox5=AddVBox( AddDialogFrame( SkinBrowser ),0 ); | |
156 AddLabel( MSGTR_SKIN_LABEL,vbox5 ); | |
157 AddHSeparator( vbox5 ); | |
158 | |
159 scrolledwindow1=gtk_scrolled_window_new( NULL,NULL ); | |
160 gtk_widget_set_name( scrolledwindow1,"scrolledwindow1" ); | |
161 gtk_widget_ref( scrolledwindow1 ); | |
162 gtk_object_set_data_full( GTK_OBJECT( SkinBrowser ),"scrolledwindow1",scrolledwindow1,(GtkDestroyNotify)gtk_widget_unref ); | |
163 gtk_widget_show( scrolledwindow1 ); | |
164 gtk_box_pack_start( GTK_BOX( vbox5 ),scrolledwindow1,TRUE,TRUE,0 ); | |
165 gtk_container_set_border_width( GTK_CONTAINER( scrolledwindow1 ),2 ); | |
166 gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW( scrolledwindow1 ),GTK_POLICY_NEVER,GTK_POLICY_AUTOMATIC ); | |
167 | |
168 SkinList=gtk_clist_new( 1 ); | |
169 gtk_widget_set_name( SkinList,"SkinList" ); | |
170 gtk_widget_ref( SkinList ); | |
171 gtk_object_set_data_full( GTK_OBJECT( SkinBrowser ),"SkinList",SkinList,(GtkDestroyNotify)gtk_widget_unref ); | |
172 gtk_widget_show( SkinList ); | |
173 gtk_container_add( GTK_CONTAINER( scrolledwindow1 ),SkinList ); | |
174 gtk_clist_set_column_width( GTK_CLIST( SkinList ),0,80 ); | |
175 gtk_clist_set_selection_mode( GTK_CLIST( SkinList ),GTK_SELECTION_SINGLE ); | |
176 gtk_clist_column_titles_hide( GTK_CLIST( SkinList ) ); | |
177 gtk_clist_set_shadow_type( GTK_CLIST( SkinList ),GTK_SHADOW_ETCHED_OUT ); | |
178 | |
179 AddHSeparator( vbox5 ); | |
180 | |
181 hbuttonbox4=AddHButtonBox( vbox5 ); | |
182 gtk_button_box_set_layout( GTK_BUTTON_BOX( hbuttonbox4 ),GTK_BUTTONBOX_SPREAD ); | |
183 gtk_button_box_set_spacing( GTK_BUTTON_BOX( hbuttonbox4 ),10 ); | |
184 | |
185 Ok=AddButton( MSGTR_Ok,hbuttonbox4 ); | |
186 Cancel=AddButton( MSGTR_Cancel,hbuttonbox4 ); | |
187 | |
188 gtk_widget_add_accelerator( Ok,"clicked",accel_group,GDK_Return,0,GTK_ACCEL_VISIBLE ); | |
189 gtk_widget_add_accelerator( Cancel,"clicked",accel_group,GDK_Escape,0,GTK_ACCEL_VISIBLE ); | |
190 | |
191 gtk_signal_connect( GTK_OBJECT( SkinBrowser ),"destroy",GTK_SIGNAL_FUNC( WidgetDestroy ),&SkinBrowser ); | |
192 gtk_signal_connect( GTK_OBJECT( SkinList ),"select_row",GTK_SIGNAL_FUNC( on_SkinList_select_row ),NULL ); | |
193 gtk_signal_connect( GTK_OBJECT( Ok ),"clicked",GTK_SIGNAL_FUNC( prButton ),(void *)1 ); | |
194 gtk_signal_connect( GTK_OBJECT( Cancel ),"clicked",GTK_SIGNAL_FUNC( prButton ),(void *)0 ); | |
195 | |
196 if ( ( sbMPlayerDirInHome=calloc( 1,strlen( skinDirInHome ) + 4 ) ) != NULL ) | |
197 { strcpy( sbMPlayerDirInHome,skinDirInHome ); strcat( sbMPlayerDirInHome,"/*" ); } | |
198 if ( ( sbMPlayerPrefixDir=calloc( 1,strlen( skinMPlayerDir ) + 4 ) ) != NULL ) | |
199 { strcpy( sbMPlayerPrefixDir,skinMPlayerDir ); strcat( sbMPlayerPrefixDir,"/*" ); } | |
200 | |
201 gtk_window_add_accel_group( GTK_WINDOW( SkinBrowser ),accel_group ); | |
202 gtk_widget_grab_focus( SkinList ); | |
203 | |
204 return SkinBrowser; | |
205 } |