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