Mercurial > mplayer.hg
comparison gui/ui/gtk/skinbrowser.c @ 33572:d9b805602aa1
Rename some gtk files.
The new names better reflect what the files implement.
List of changes:
eq.* -> equalizer.*
fs.* -> fileselect.*
gtk_common.* -> tools.*
gtk_menu.* -> menu.*
gtk_url.* -> url.*
mb.* -> msgbox.*
opts.* -> preferences.*
pl.* -> playlist.*
sb.* -> skinbrowser.*
author | ib |
---|---|
date | Sun, 19 Jun 2011 15:34:08 +0000 |
parents | |
children | 998f94e62a61 |
comparison
equal
deleted
inserted
replaced
33571:4f9ad91c79b4 | 33572:d9b805602aa1 |
---|---|
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" | |
31 #include "help_mp.h" | |
32 | |
33 #include "gui/ui/widgets.h" | |
34 | |
35 GtkWidget * SkinList = NULL; | |
36 char * sbSelectedSkin=NULL; | |
37 char * sbMPlayerDirInHome=NULL; | |
38 char * sbMPlayerPrefixDir=NULL; | |
39 | |
40 char * gtkOldSkin=NULL; | |
41 static char * prev=NULL; | |
42 | |
43 GtkWidget * SkinBrowser = NULL; | |
44 | |
45 void ShowSkinBrowser( void ) | |
46 { | |
47 if ( SkinBrowser ) gtkActive( SkinBrowser ); | |
48 else SkinBrowser=create_SkinBrowser(); | |
49 } | |
50 | |
51 static void HideSkinBrowser( void ) | |
52 { | |
53 if ( !SkinBrowser ) return; | |
54 gtk_widget_hide( SkinBrowser ); | |
55 gtk_widget_destroy( SkinBrowser ); | |
56 SkinBrowser=NULL; | |
57 } | |
58 | |
59 int gtkFillSkinList( gchar * mdir ) | |
60 { | |
61 gchar * str[2]; | |
62 gchar * tmp; | |
63 int i; | |
64 glob_t gg; | |
65 struct stat fs; | |
66 | |
67 gtkOldSkin=strdup( skinName ); | |
68 prev=gtkOldSkin; | |
69 | |
70 str[0]="default"; | |
71 str[1]=""; | |
72 if ( gtkFindCList( SkinList,str[0] ) == -1 ) gtk_clist_append( GTK_CLIST( SkinList ),str ); | |
73 | |
74 glob( mdir,GLOB_NOSORT,NULL,&gg ); | |
75 for( i=0;i<(int)gg.gl_pathc;i++ ) | |
76 { | |
77 if ( !strcmp( gg.gl_pathv[i],"." ) || !strcmp( gg.gl_pathv[i],".." ) ) continue; | |
78 stat( gg.gl_pathv[i],&fs ); | |
79 if ( S_ISDIR( fs.st_mode ) ) | |
80 { | |
81 tmp=strrchr( gg.gl_pathv[i],'/' ); tmp++; | |
82 if ( !strcmp( tmp,"default" ) ) continue; | |
83 str[0]=tmp; | |
84 if ( gtkFindCList( SkinList,str[0] ) == -1 ) gtk_clist_append( GTK_CLIST( SkinList ),str ); | |
85 } | |
86 } | |
87 globfree( &gg ); | |
88 return 1; | |
89 } | |
90 | |
91 static void prButton( GtkObject * object,gpointer user_data ) | |
92 { | |
93 if ( sbSelectedSkin ) | |
94 { | |
95 switch ( (int)user_data ) | |
96 { | |
97 case 0: // cancel | |
98 if ( strcmp( sbSelectedSkin,gtkOldSkin ) ) uiChangeSkin( gtkOldSkin ); | |
99 break; | |
100 case 1: // ok | |
101 uiChangeSkin( sbSelectedSkin ); // NOTE TO MYSELF: skin already changed! | |
102 free( skinName ); | |
103 skinName=strdup( sbSelectedSkin ); | |
104 break; | |
105 } | |
106 } | |
107 HideSkinBrowser(); | |
108 } | |
109 | |
110 static void on_SkinList_select_row( GtkCList * clist,gint row,gint column,GdkEvent * bevent,gpointer user_data ) | |
111 { | |
112 gtk_clist_get_text( clist,row,0,&sbSelectedSkin ); | |
113 if ( strcmp( prev,sbSelectedSkin ) ) | |
114 { | |
115 prev=sbSelectedSkin; | |
116 uiChangeSkin( sbSelectedSkin ); | |
117 gtkActive( SkinBrowser ); | |
118 } | |
119 if( !bevent ) return; | |
120 if( bevent->type == GDK_2BUTTON_PRESS ) | |
121 { | |
122 free( skinName ); | |
123 skinName=strdup( sbSelectedSkin ); | |
124 HideSkinBrowser(); | |
125 } | |
126 } | |
127 | |
128 GtkWidget * create_SkinBrowser( void ) | |
129 { | |
130 GtkWidget * vbox5; | |
131 GtkWidget * scrolledwindow1; | |
132 GtkWidget * hbuttonbox4; | |
133 GtkWidget * Cancel; | |
134 GtkWidget * Ok; | |
135 GtkAccelGroup * accel_group; | |
136 | |
137 accel_group = gtk_accel_group_new (); | |
138 | |
139 SkinBrowser=gtk_window_new( GTK_WINDOW_TOPLEVEL ); | |
140 gtk_widget_set_name( SkinBrowser,MSGTR_SkinBrowser ); | |
141 gtk_object_set_data( GTK_OBJECT( SkinBrowser ),MSGTR_SkinBrowser,SkinBrowser ); | |
142 gtk_widget_set_usize( SkinBrowser,256,320 ); | |
143 gtk_container_set_border_width( GTK_CONTAINER( SkinBrowser ),1 ); | |
144 GTK_WIDGET_SET_FLAGS( SkinBrowser,GTK_CAN_DEFAULT ); | |
145 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 ); | |
146 gtk_window_set_title( GTK_WINDOW( SkinBrowser ),MSGTR_SkinBrowser ); | |
147 gtk_window_set_position( GTK_WINDOW( SkinBrowser ),GTK_WIN_POS_CENTER ); | |
148 gtk_window_set_policy( GTK_WINDOW( SkinBrowser ),FALSE,FALSE,TRUE ); | |
149 gtk_window_set_wmclass( GTK_WINDOW( SkinBrowser ),"SkinBrowser","MPlayer" ); | |
150 | |
151 gtk_widget_realize( SkinBrowser ); | |
152 gtkAddIcon( SkinBrowser ); | |
153 | |
154 vbox5=AddVBox( AddDialogFrame( SkinBrowser ),0 ); | |
155 AddLabel( MSGTR_SKIN_LABEL,vbox5 ); | |
156 AddHSeparator( vbox5 ); | |
157 | |
158 scrolledwindow1=gtk_scrolled_window_new( NULL,NULL ); | |
159 gtk_widget_set_name( scrolledwindow1,"scrolledwindow1" ); | |
160 gtk_widget_ref( scrolledwindow1 ); | |
161 gtk_object_set_data_full( GTK_OBJECT( SkinBrowser ),"scrolledwindow1",scrolledwindow1,(GtkDestroyNotify)gtk_widget_unref ); | |
162 gtk_widget_show( scrolledwindow1 ); | |
163 gtk_box_pack_start( GTK_BOX( vbox5 ),scrolledwindow1,TRUE,TRUE,0 ); | |
164 gtk_container_set_border_width( GTK_CONTAINER( scrolledwindow1 ),2 ); | |
165 gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW( scrolledwindow1 ),GTK_POLICY_NEVER,GTK_POLICY_AUTOMATIC ); | |
166 | |
167 SkinList=gtk_clist_new( 1 ); | |
168 gtk_widget_set_name( SkinList,"SkinList" ); | |
169 gtk_widget_ref( SkinList ); | |
170 gtk_object_set_data_full( GTK_OBJECT( SkinBrowser ),"SkinList",SkinList,(GtkDestroyNotify)gtk_widget_unref ); | |
171 gtk_widget_show( SkinList ); | |
172 gtk_container_add( GTK_CONTAINER( scrolledwindow1 ),SkinList ); | |
173 gtk_clist_set_column_width( GTK_CLIST( SkinList ),0,80 ); | |
174 gtk_clist_set_selection_mode( GTK_CLIST( SkinList ),GTK_SELECTION_SINGLE ); | |
175 gtk_clist_column_titles_hide( GTK_CLIST( SkinList ) ); | |
176 gtk_clist_set_shadow_type( GTK_CLIST( SkinList ),GTK_SHADOW_ETCHED_OUT ); | |
177 | |
178 AddHSeparator( vbox5 ); | |
179 | |
180 hbuttonbox4=AddHButtonBox( vbox5 ); | |
181 gtk_button_box_set_layout( GTK_BUTTON_BOX( hbuttonbox4 ),GTK_BUTTONBOX_SPREAD ); | |
182 gtk_button_box_set_spacing( GTK_BUTTON_BOX( hbuttonbox4 ),10 ); | |
183 | |
184 Ok=AddButton( MSGTR_Ok,hbuttonbox4 ); | |
185 Cancel=AddButton( MSGTR_Cancel,hbuttonbox4 ); | |
186 | |
187 gtk_widget_add_accelerator( Ok,"clicked",accel_group,GDK_Return,0,GTK_ACCEL_VISIBLE ); | |
188 gtk_widget_add_accelerator( Cancel,"clicked",accel_group,GDK_Escape,0,GTK_ACCEL_VISIBLE ); | |
189 | |
190 gtk_signal_connect( GTK_OBJECT( SkinBrowser ),"destroy",GTK_SIGNAL_FUNC( WidgetDestroy ),&SkinBrowser ); | |
191 gtk_signal_connect( GTK_OBJECT( SkinList ),"select_row",GTK_SIGNAL_FUNC( on_SkinList_select_row ),NULL ); | |
192 gtk_signal_connect( GTK_OBJECT( Ok ),"clicked",GTK_SIGNAL_FUNC( prButton ),(void *)1 ); | |
193 gtk_signal_connect( GTK_OBJECT( Cancel ),"clicked",GTK_SIGNAL_FUNC( prButton ),(void *)0 ); | |
194 | |
195 if ( ( sbMPlayerDirInHome=calloc( 1,strlen( skinDirInHome ) + 4 ) ) != NULL ) | |
196 { strcpy( sbMPlayerDirInHome,skinDirInHome ); strcat( sbMPlayerDirInHome,"/*" ); } | |
197 if ( ( sbMPlayerPrefixDir=calloc( 1,strlen( skinMPlayerDir ) + 4 ) ) != NULL ) | |
198 { strcpy( sbMPlayerPrefixDir,skinMPlayerDir ); strcat( sbMPlayerPrefixDir,"/*" ); } | |
199 | |
200 gtk_window_add_accel_group( GTK_WINDOW( SkinBrowser ),accel_group ); | |
201 gtk_widget_grab_focus( SkinList ); | |
202 | |
203 return SkinBrowser; | |
204 } |