Mercurial > mplayer.hg
annotate gui/mplayer/gtk/pl.c @ 33408:dc8779e0e9cc
Allow direct selection with middle mouse button (single click).
This works with both, adding files to and removing files from the playlist
without the necessity of pressing the add or remove button.
author | ib |
---|---|
date | Tue, 24 May 2011 14:57:44 +0000 |
parents | 5310794ef052 |
children | 061c397604f2 |
rev | line source |
---|---|
26458 | 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 */ | |
23077 | 18 |
19 #include <sys/types.h> | |
20 #include <sys/stat.h> | |
21 #include <string.h> | |
22 #include <dirent.h> | |
23 #include <unistd.h> | |
24 #include <stdio.h> | |
25 #include <stdlib.h> | |
26 | |
27 #include <gdk/gdkkeysyms.h> | |
28 #include <gtk/gtk.h> | |
29 | |
30 #include "config.h" | |
31 #include "help_mp.h" | |
32 #include "stream/stream.h" | |
33 | |
26365
10dfbc523184
Add gui/ prefix to some #include paths so that compilation from the
diego
parents:
25601
diff
changeset
|
34 #include "gui/interface.h" |
26382
b2f4abcf20ed
Make include paths consistent; do not use ../ in them.
diego
parents:
26365
diff
changeset
|
35 #include "gui/mplayer/widgets.h" |
23077 | 36 #include "pl.h" |
25601
8a0adeba5910
Rename common.[ch] to gtk_common.[ch], there are too many files by that name.
diego
parents:
23077
diff
changeset
|
37 #include "gtk_common.h" |
23077 | 38 |
39 static char * book_open_xpm[] = { | |
40 "16 16 4 1", | |
41 " c None s None", | |
42 ". c black", | |
43 "X c #808080", | |
44 "o c white", | |
45 " ", | |
46 " .. ", | |
47 " .Xo. ... ", | |
48 " .Xoo. ..oo. ", | |
49 " .Xooo.Xooo... ", | |
50 " .Xooo.oooo.X. ", | |
51 " .Xooo.Xooo.X. ", | |
52 " .Xooo.oooo.X. ", | |
53 " .Xooo.Xooo.X. ", | |
54 " .Xooo.oooo.X. ", | |
55 " .Xoo.Xoo..X. ", | |
56 " .Xo.o..ooX. ", | |
57 " .X..XXXXX. ", | |
58 " ..X....... ", | |
59 " .. ", | |
60 " "}; | |
61 | |
62 static char * book_closed_xpm[] = { | |
63 "16 16 6 1", | |
64 " c None s None", | |
65 ". c black", | |
66 "X c blue", | |
67 "o c yellow", | |
68 "O c #007FEA", | |
69 "# c white", | |
70 " ", | |
71 " .. ", | |
72 " ..XX. ", | |
73 " ..XXXXX. ", | |
74 " ..XXXXXXXX. ", | |
75 ".ooXXXXXXXXX. ", | |
76 "..ooXXXXXXXXX. ", | |
77 ".X.ooXXXXXXXXX. ", | |
78 ".XX.ooXXXXXX.. ", | |
79 " .XX.ooXXX..#O ", | |
80 " .XX.oo..##OO. ", | |
81 " .XX..##OO.. ", | |
82 " .X.#OO.. ", | |
83 " ..O.. ", | |
84 " .. ", | |
85 " "}; | |
86 | |
87 GtkWidget * PlayList = NULL; | |
88 static GtkWidget * CTDirTree; | |
89 static GtkWidget * CLFiles; | |
90 static GtkWidget * CLSelected; | |
91 static GtkWidget * Add; | |
92 static GtkWidget * Remove; | |
93 static GtkWidget * Ok; | |
94 static GtkWidget * Cancel; | |
95 static GdkPixmap * pxOpenedBook; | |
96 static GdkPixmap * pxClosedBook; | |
97 static GdkBitmap * msOpenedBook; | |
98 static GdkBitmap * msClosedBook; | |
99 | |
100 static int NrOfEntrys = 0; | |
101 static int NrOfSelected = 0; | |
102 static int * CLFileSelected = NULL; | |
103 static int * CLListSelected = NULL; | |
104 | |
105 static int sigSel; | |
106 static int sigUnsel; | |
33408
dc8779e0e9cc
Allow direct selection with middle mouse button (single click).
ib
parents:
32723
diff
changeset
|
107 static int sigEvent; |
23077 | 108 |
109 typedef struct | |
110 { | |
111 int scaned; | |
112 char * path; | |
113 } DirNodeType; | |
114 | |
115 static GtkCTreeNode * sibling; | |
116 static GtkCTreeNode * parent; | |
117 static gchar * current_path; | |
118 static gchar * old_path = NULL; | |
119 | |
120 static int compare_func(const void *a, const void *b) | |
121 { | |
122 char * tmp; | |
123 int i; | |
124 if ( !a || !b || !( (DirNodeType *)a )->path ) return -1; | |
125 tmp=strdup( (char *)b ); tmp[strlen( tmp )-1]=0; | |
126 i=strcmp( ( (DirNodeType *)a )->path,tmp ); | |
127 free( tmp ); | |
128 return i; | |
129 } | |
130 | |
131 static void scan_dir( char * path ); | |
132 | |
133 void ShowPlayList( void ) | |
134 { | |
135 if ( PlayList ) gtkActive( PlayList ); | |
136 else PlayList=create_PlayList(); | |
137 | |
138 if ( old_path && *old_path ) | |
139 { | |
140 char * currentdir = strdup( old_path ); | |
141 char * tpath,* pos; | |
142 GtkCTreeNode * node,* nextnode; | |
143 gboolean leaf; | |
144 tpath=strdup( "/" ); | |
145 pos=strtok( currentdir,"/" ); | |
146 node=gtk_ctree_find_by_row_data_custom( GTK_CTREE( CTDirTree ),NULL,"/",compare_func ); | |
147 do | |
148 { | |
149 char * tpathnew = g_strconcat( tpath,pos,"/",NULL ); | |
150 free( tpath ); tpath=tpathnew; | |
151 nextnode=gtk_ctree_find_by_row_data_custom( GTK_CTREE( CTDirTree ),node,tpath,compare_func ); | |
152 if ( !nextnode ) break; | |
153 node=nextnode; | |
154 pos=strtok( NULL,"/" ); | |
155 gtk_ctree_get_node_info( GTK_CTREE( CTDirTree ),node,NULL,NULL,NULL,NULL,NULL,NULL,&leaf,NULL ); | |
156 if ( !leaf && pos ) gtk_ctree_expand( GTK_CTREE( CTDirTree ),node ); | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
26458
diff
changeset
|
157 else |
23077 | 158 { |
159 DirNodeType * DirNode; | |
160 gtk_ctree_select( GTK_CTREE( CTDirTree ),node ); | |
161 DirNode=gtk_ctree_node_get_row_data( GTK_CTREE( CTDirTree ),node ); | |
162 current_path=DirNode->path; | |
163 scan_dir( DirNode->path ); | |
32537
8fa2f43cb760
Remove most of the NULL pointer check before free all over the code
cboesch
parents:
30633
diff
changeset
|
164 free( CLFileSelected ); |
8fa2f43cb760
Remove most of the NULL pointer check before free all over the code
cboesch
parents:
30633
diff
changeset
|
165 CLFileSelected=calloc( 1,NrOfEntrys * sizeof( int ) ); |
23077 | 166 break; |
167 } | |
168 } while( pos ); | |
169 free( tpath ); | |
170 free( currentdir ); | |
171 } | |
172 else gtk_ctree_select( GTK_CTREE( CTDirTree ),parent ); | |
173 | |
174 gtk_clist_freeze( GTK_CLIST( CLSelected ) ); | |
175 gtk_clist_clear( GTK_CLIST( CLSelected ) ); | |
176 if ( plList ) | |
177 { | |
32708 | 178 gchar * name, * path; |
23077 | 179 plItem * next = plList; |
180 while ( next || next->next ) | |
181 { | |
182 char * text[1][3]; text[0][2]=""; | |
32708 | 183 name = g_filename_to_utf8( next->name, -1, NULL, NULL, NULL ); |
184 path = g_filename_to_utf8( next->path, -1, NULL, NULL, NULL ); | |
32723 | 185 text[0][0]=name ? name : next->name; |
186 text[0][1]=path ? path : next->path; | |
23077 | 187 gtk_clist_append( GTK_CLIST( CLSelected ),text[0] ); |
32708 | 188 g_free( path ); |
189 g_free( name ); | |
23077 | 190 NrOfSelected++; |
191 if ( next->next ) next=next->next; else break; | |
192 } | |
193 CLListSelected=calloc( 1,NrOfSelected * sizeof( int ) ); | |
194 } | |
195 gtk_clist_thaw( GTK_CLIST( CLSelected ) ); | |
196 | |
197 gtk_widget_show( PlayList ); | |
198 } | |
199 | |
200 void HidePlayList( void ) | |
201 { | |
202 if ( !PlayList ) return; | |
203 NrOfSelected=NrOfEntrys=0; | |
204 gfree( (void **)&CLListSelected ); gfree( (void **)&CLFileSelected ); | |
32537
8fa2f43cb760
Remove most of the NULL pointer check before free all over the code
cboesch
parents:
30633
diff
changeset
|
205 free( old_path ); |
8fa2f43cb760
Remove most of the NULL pointer check before free all over the code
cboesch
parents:
30633
diff
changeset
|
206 old_path=strdup( current_path ); |
23077 | 207 gtk_widget_hide( PlayList ); |
208 gtk_widget_destroy( PlayList ); | |
209 PlayList=NULL; | |
210 } | |
211 | |
212 static void plRowSelect( GtkCList * clist,gint row,gint column,GdkEvent * event,gpointer user_data ) | |
213 { | |
214 switch ( (int) user_data ) | |
215 { | |
216 case 0: CLFileSelected[row]=1; break; | |
217 case 1: CLListSelected[row]=1; break; | |
218 } | |
219 } | |
220 | |
221 static void plUnRowSelect( GtkCList * clist,gint row,gint column,GdkEvent * event,gpointer user_data ) | |
222 { | |
223 switch ( (int) user_data ) | |
224 { | |
225 case 0: CLFileSelected[row]=0; break; | |
226 case 1: CLListSelected[row]=0; break; | |
227 } | |
228 } | |
229 | |
230 static void plButtonReleased( GtkButton * button,gpointer user_data ) | |
231 { | |
232 switch ( (int) user_data ) | |
233 { | |
234 case 1: // ok | |
235 { | |
236 int i; | |
237 if ( plList ) gtkSet( gtkDelPl,0,NULL ); | |
238 for ( i=0;i<NrOfSelected;i++ ) | |
239 { | |
240 plItem * item; | |
241 char * text[3]; | |
242 item=calloc( 1,sizeof( plItem ) ); | |
243 gtk_clist_get_text( GTK_CLIST( CLSelected ),i,0,&text[0] ); | |
244 gtk_clist_get_text( GTK_CLIST( CLSelected ),i,1,&text[1] ); | |
32708 | 245 item->name=g_filename_from_utf8( text[0], -1, NULL, NULL, NULL ); |
32723 | 246 if ( !item->name ) item->name = strdup( text[0] ); |
32708 | 247 item->path=g_filename_from_utf8( text[1], -1, NULL, NULL, NULL ); |
32723 | 248 if ( !item->path ) item->path = strdup( text[1] ); |
23077 | 249 gtkSet( gtkAddPlItem,0,(void*)item ); |
250 } | |
251 if ( plCurrent ) | |
252 { | |
253 mplSetFileName( plCurrent->path,plCurrent->name,STREAMTYPE_FILE ); | |
254 // guiSetDF( guiIntfStruct.Filename,plCurrent->path,plCurrent->name ); | |
255 // guiIntfStruct.FilenameChanged=1; | |
256 // guiIntfStruct.StreamType=STREAMTYPE_FILE; | |
257 } | |
258 } | |
259 case 0: // cancel | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
26458
diff
changeset
|
260 HidePlayList(); |
23077 | 261 break; |
262 case 2: // remove | |
263 { | |
264 int i; int j; int c=0; | |
265 | |
266 gtk_signal_handler_block( GTK_OBJECT( CLSelected ),sigSel ); | |
267 gtk_signal_handler_block( GTK_OBJECT( CLSelected ),sigUnsel ); | |
33408
dc8779e0e9cc
Allow direct selection with middle mouse button (single click).
ib
parents:
32723
diff
changeset
|
268 gtk_signal_handler_block( GTK_OBJECT( CLSelected ),sigEvent ); |
23077 | 269 |
270 gtk_clist_freeze( GTK_CLIST( CLSelected ) ); | |
271 for ( i=0;i<NrOfSelected-c;i++ ) | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
26458
diff
changeset
|
272 if ( CLListSelected[i] ) |
23077 | 273 { |
274 gtk_clist_remove( GTK_CLIST( CLSelected ),i - c ); | |
275 c++; | |
276 for ( j=i;j<NrOfSelected-c;j++ ) | |
277 CLListSelected[i] = CLListSelected[i+1]; | |
278 } | |
279 NrOfSelected-=c; | |
280 gtk_clist_thaw( GTK_CLIST( CLSelected ) ); | |
281 | |
282 gtk_signal_handler_unblock( GTK_OBJECT( CLSelected ),sigSel ); | |
283 gtk_signal_handler_unblock( GTK_OBJECT( CLSelected ),sigUnsel ); | |
33408
dc8779e0e9cc
Allow direct selection with middle mouse button (single click).
ib
parents:
32723
diff
changeset
|
284 gtk_signal_handler_unblock( GTK_OBJECT( CLSelected ),sigEvent ); |
23077 | 285 |
286 } | |
287 break; | |
288 case 3: // add | |
289 { | |
290 int i; | |
32712 | 291 void *p; |
23077 | 292 char * itext[1][2]; |
32708 | 293 gchar * cpath; |
23077 | 294 char * text[1][3]; text[0][2]=""; |
295 gtk_clist_freeze( GTK_CLIST( CLSelected ) ); | |
296 for ( i=0;i<NrOfEntrys;i++ ) | |
297 { | |
298 if ( CLFileSelected[i] ) | |
299 { | |
300 NrOfSelected++; | |
32712 | 301 p=realloc( CLListSelected,NrOfSelected * sizeof( int ) ); |
302 if ( !p ) NrOfSelected--; | |
303 else | |
304 { | |
305 CLListSelected=p; | |
306 CLListSelected[NrOfSelected - 1]=0; | |
307 gtk_clist_get_text( GTK_CLIST( CLFiles ),i,0,(char **)&itext ); | |
308 cpath=g_filename_to_utf8( current_path, -1, NULL, NULL, NULL ); | |
32723 | 309 text[0][0]=itext[0][0]; text[0][1]=cpath ? cpath : current_path; |
32712 | 310 gtk_clist_append( GTK_CLIST( CLSelected ),text[0] ); |
311 g_free( cpath ); | |
312 } | |
23077 | 313 } |
314 } | |
315 gtk_clist_thaw( GTK_CLIST( CLSelected ) ); | |
316 } | |
317 break; | |
318 } | |
319 } | |
320 | |
33408
dc8779e0e9cc
Allow direct selection with middle mouse button (single click).
ib
parents:
32723
diff
changeset
|
321 static gboolean plEvent ( GtkWidget * widget, |
dc8779e0e9cc
Allow direct selection with middle mouse button (single click).
ib
parents:
32723
diff
changeset
|
322 GdkEvent * event, |
dc8779e0e9cc
Allow direct selection with middle mouse button (single click).
ib
parents:
32723
diff
changeset
|
323 gpointer user_data ) |
dc8779e0e9cc
Allow direct selection with middle mouse button (single click).
ib
parents:
32723
diff
changeset
|
324 { |
dc8779e0e9cc
Allow direct selection with middle mouse button (single click).
ib
parents:
32723
diff
changeset
|
325 GdkEventButton *bevent; |
dc8779e0e9cc
Allow direct selection with middle mouse button (single click).
ib
parents:
32723
diff
changeset
|
326 gint row, col; |
dc8779e0e9cc
Allow direct selection with middle mouse button (single click).
ib
parents:
32723
diff
changeset
|
327 |
dc8779e0e9cc
Allow direct selection with middle mouse button (single click).
ib
parents:
32723
diff
changeset
|
328 (void) user_data; |
dc8779e0e9cc
Allow direct selection with middle mouse button (single click).
ib
parents:
32723
diff
changeset
|
329 |
dc8779e0e9cc
Allow direct selection with middle mouse button (single click).
ib
parents:
32723
diff
changeset
|
330 bevent = (GdkEventButton *) event; |
dc8779e0e9cc
Allow direct selection with middle mouse button (single click).
ib
parents:
32723
diff
changeset
|
331 |
dc8779e0e9cc
Allow direct selection with middle mouse button (single click).
ib
parents:
32723
diff
changeset
|
332 if ( event->type == GDK_BUTTON_RELEASE && bevent->button == 2 ) |
dc8779e0e9cc
Allow direct selection with middle mouse button (single click).
ib
parents:
32723
diff
changeset
|
333 { |
dc8779e0e9cc
Allow direct selection with middle mouse button (single click).
ib
parents:
32723
diff
changeset
|
334 if ( gtk_clist_get_selection_info( GTK_CLIST( widget ), bevent->x, bevent->y, &row, &col ) ) |
dc8779e0e9cc
Allow direct selection with middle mouse button (single click).
ib
parents:
32723
diff
changeset
|
335 { |
dc8779e0e9cc
Allow direct selection with middle mouse button (single click).
ib
parents:
32723
diff
changeset
|
336 switch ( (int) user_data ) |
dc8779e0e9cc
Allow direct selection with middle mouse button (single click).
ib
parents:
32723
diff
changeset
|
337 { |
dc8779e0e9cc
Allow direct selection with middle mouse button (single click).
ib
parents:
32723
diff
changeset
|
338 case 0: |
dc8779e0e9cc
Allow direct selection with middle mouse button (single click).
ib
parents:
32723
diff
changeset
|
339 CLFileSelected[row] = 1; |
dc8779e0e9cc
Allow direct selection with middle mouse button (single click).
ib
parents:
32723
diff
changeset
|
340 plButtonReleased( NULL, (void *) 3 ); |
dc8779e0e9cc
Allow direct selection with middle mouse button (single click).
ib
parents:
32723
diff
changeset
|
341 CLFileSelected[row] = 0; |
dc8779e0e9cc
Allow direct selection with middle mouse button (single click).
ib
parents:
32723
diff
changeset
|
342 return TRUE; |
dc8779e0e9cc
Allow direct selection with middle mouse button (single click).
ib
parents:
32723
diff
changeset
|
343 |
dc8779e0e9cc
Allow direct selection with middle mouse button (single click).
ib
parents:
32723
diff
changeset
|
344 case 1: |
dc8779e0e9cc
Allow direct selection with middle mouse button (single click).
ib
parents:
32723
diff
changeset
|
345 CLListSelected[row] = 1; |
dc8779e0e9cc
Allow direct selection with middle mouse button (single click).
ib
parents:
32723
diff
changeset
|
346 plButtonReleased( NULL, (void *) 2 ); |
dc8779e0e9cc
Allow direct selection with middle mouse button (single click).
ib
parents:
32723
diff
changeset
|
347 return TRUE; |
dc8779e0e9cc
Allow direct selection with middle mouse button (single click).
ib
parents:
32723
diff
changeset
|
348 } |
dc8779e0e9cc
Allow direct selection with middle mouse button (single click).
ib
parents:
32723
diff
changeset
|
349 } |
dc8779e0e9cc
Allow direct selection with middle mouse button (single click).
ib
parents:
32723
diff
changeset
|
350 } |
dc8779e0e9cc
Allow direct selection with middle mouse button (single click).
ib
parents:
32723
diff
changeset
|
351 |
dc8779e0e9cc
Allow direct selection with middle mouse button (single click).
ib
parents:
32723
diff
changeset
|
352 return FALSE; |
dc8779e0e9cc
Allow direct selection with middle mouse button (single click).
ib
parents:
32723
diff
changeset
|
353 } |
dc8779e0e9cc
Allow direct selection with middle mouse button (single click).
ib
parents:
32723
diff
changeset
|
354 |
23077 | 355 static int check_for_subdir( gchar * path ) |
356 { | |
357 DIR * dir; | |
358 struct dirent * dirent; | |
359 struct stat statbuf; | |
360 gchar * npath; | |
361 | |
362 if ( (dir=opendir( path )) ) | |
363 { | |
364 while ( (dirent=readdir( dir )) ) | |
365 { | |
366 if ( dirent->d_name[0] != '.' ) | |
367 { | |
368 npath=calloc( 1,strlen( path ) + strlen( dirent->d_name ) + 3 ); | |
369 sprintf( npath,"%s/%s",path,dirent->d_name ); | |
370 if ( stat( npath,&statbuf ) != -1 && S_ISDIR( statbuf.st_mode ) ) | |
371 { free( npath ); closedir( dir ); return 1; } | |
372 free( npath ); | |
373 } | |
374 } | |
375 closedir( dir ); | |
376 } | |
377 return 0; | |
378 } | |
379 | |
380 static void plCTree( GtkCTree * ctree,GtkCTreeNode * parent_node,gpointer user_data ) | |
381 { | |
382 GtkCTreeNode * node; | |
383 DirNodeType * DirNode; | |
32708 | 384 gchar * text, * name = NULL; |
23077 | 385 gchar * dummy = "dummy"; |
386 int subdir = 1; | |
387 DIR * dir = NULL; | |
388 struct dirent * dirent; | |
389 gchar * path; | |
390 struct stat statbuf; | |
391 | |
392 DirNode=gtk_ctree_node_get_row_data( ctree,parent_node ); | |
393 if ( !DirNode->scaned ) | |
394 { | |
395 DirNode->scaned=1; current_path=DirNode->path; | |
396 gtk_clist_freeze( GTK_CLIST( ctree ) ); | |
397 node=gtk_ctree_find_by_row_data( ctree,parent_node,NULL ); | |
398 gtk_ctree_remove_node( ctree,node ); | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
26458
diff
changeset
|
399 |
23077 | 400 if ( (dir=opendir( DirNode->path ) ) ) |
401 { | |
402 while( (dirent=readdir( dir )) ) | |
403 { | |
404 path=calloc( 1,strlen( DirNode->path ) + strlen( dirent->d_name ) + 2 ); | |
405 if ( !strcmp( current_path,"/" ) ) sprintf( path,"/%s",dirent->d_name ); | |
406 else sprintf( path,"%s/%s",current_path,dirent->d_name ); | |
407 text=dirent->d_name; | |
32708 | 408 g_free( name ); |
409 name=g_filename_to_utf8( text, -1, NULL, NULL, NULL ); | |
23077 | 410 |
411 if ( stat( path,&statbuf ) != -1 && S_ISDIR( statbuf.st_mode ) && dirent->d_name[0] != '.' ) | |
412 { | |
413 DirNode=malloc( sizeof( DirNodeType ) ); DirNode->scaned=0; DirNode->path=strdup( path ); | |
414 subdir=check_for_subdir( path ); | |
32723 | 415 node=gtk_ctree_insert_node( ctree,parent_node,NULL,(name ? &name : &text ),4,pxOpenedBook,msOpenedBook,pxClosedBook,msClosedBook,!subdir,FALSE ); |
23077 | 416 gtk_ctree_node_set_row_data_full( ctree,node,DirNode,NULL ); |
417 if ( subdir ) node=gtk_ctree_insert_node( ctree,node,NULL,&dummy,4,NULL,NULL,NULL,NULL,FALSE,FALSE ); | |
418 } | |
419 free( path ); path=NULL; | |
420 } | |
421 closedir( dir ); | |
422 } | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
26458
diff
changeset
|
423 |
23077 | 424 gtk_ctree_sort_node( ctree,parent_node ); |
425 gtk_clist_thaw( GTK_CLIST( ctree ) ); | |
426 } | |
32708 | 427 |
428 g_free( name ); | |
23077 | 429 } |
430 | |
431 static void scan_dir( char * path ) | |
432 { | |
433 DIR * dir = NULL; | |
434 char * curr; | |
435 struct dirent * dirent; | |
436 struct stat statbuf; | |
32708 | 437 gchar * name; |
23077 | 438 char * text[1][2]; text[0][1]=""; |
439 | |
440 gtk_clist_clear( GTK_CLIST( CLFiles ) ); | |
441 if ( (dir=opendir( path )) ) | |
442 { | |
443 NrOfEntrys=0; | |
444 while( (dirent=readdir( dir )) ) | |
445 { | |
446 curr=calloc( 1,strlen( path ) + strlen( dirent->d_name ) + 3 ); sprintf( curr,"%s/%s",path,dirent->d_name ); | |
447 if ( stat( curr,&statbuf ) != -1 && ( S_ISREG( statbuf.st_mode ) || S_ISLNK( statbuf.st_mode ) ) ) | |
448 { | |
32708 | 449 name=g_filename_to_utf8( dirent->d_name, -1, NULL, NULL, NULL ); |
32723 | 450 text[0][0]=name ? name : dirent->d_name; |
32708 | 451 gtk_clist_append( GTK_CLIST( CLFiles ), text[0] ); |
452 g_free( name ); | |
23077 | 453 NrOfEntrys++; |
454 } | |
455 free( curr ); | |
456 } | |
457 closedir( dir ); | |
458 gtk_clist_sort( GTK_CLIST( CLFiles ) ); | |
459 } | |
460 } | |
461 | |
462 static void plCTRow(GtkWidget * widget, gint row, gint column, GdkEventButton * bevent, gpointer data) | |
463 { | |
464 DirNodeType * DirNode; | |
465 GtkCTreeNode * node; | |
466 node=gtk_ctree_node_nth( GTK_CTREE( widget ),row ); | |
467 DirNode=gtk_ctree_node_get_row_data( GTK_CTREE( widget ),node ); | |
468 current_path=DirNode->path; | |
469 gtk_ctree_expand( GTK_CTREE( widget ),node ); | |
470 scan_dir( DirNode->path ); | |
32537
8fa2f43cb760
Remove most of the NULL pointer check before free all over the code
cboesch
parents:
30633
diff
changeset
|
471 free( CLFileSelected ); |
8fa2f43cb760
Remove most of the NULL pointer check before free all over the code
cboesch
parents:
30633
diff
changeset
|
472 CLFileSelected=calloc( 1,NrOfEntrys * sizeof( int ) ); |
23077 | 473 } |
474 | |
475 GtkWidget * create_PlayList( void ) | |
476 { | |
477 GtkWidget * vbox1; | |
478 GtkWidget * hbox1; | |
479 GtkWidget * scrolledwindow1; | |
480 GtkWidget * vbox2; | |
481 GtkWidget * scrolledwindow2; | |
482 GtkWidget * scrolledwindow3; | |
483 GtkWidget * hbuttonbox1; | |
484 GtkAccelGroup * accel_group; | |
485 GdkColor transparent = { 0,0,0,0 }; | |
486 gchar * root = "/"; | |
487 gchar * dummy = "dummy"; | |
488 DirNodeType * DirNode; | |
489 | |
490 accel_group=gtk_accel_group_new(); | |
491 | |
492 PlayList=gtk_window_new( GTK_WINDOW_TOPLEVEL ); | |
493 gtk_object_set_data( GTK_OBJECT( PlayList ),"PlayList",PlayList ); | |
494 gtk_widget_set_usize( PlayList,512,384 ); | |
495 gtk_window_set_title( GTK_WINDOW( PlayList ),MSGTR_PlayList ); | |
496 gtk_window_set_position( GTK_WINDOW( PlayList ),GTK_WIN_POS_CENTER ); | |
497 // gtk_window_set_policy( GTK_WINDOW( PlayList ),FALSE,FALSE,FALSE ); | |
498 gtk_window_set_wmclass( GTK_WINDOW( PlayList ),"Playlist","MPlayer" ); | |
499 | |
500 gtk_widget_realize( PlayList ); | |
501 gtkAddIcon( PlayList ); | |
502 | |
503 vbox1=AddVBox( AddDialogFrame( PlayList ),0 ); | |
504 hbox1=AddHBox( NULL,1 ); | |
505 gtk_box_pack_start( GTK_BOX( vbox1 ),hbox1,TRUE,TRUE,0 ); | |
506 | |
507 scrolledwindow1=gtk_scrolled_window_new( NULL,NULL ); | |
508 gtk_widget_show( scrolledwindow1 ); | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
26458
diff
changeset
|
509 gtk_container_add( GTK_CONTAINER( |
23077 | 510 AddFrame( NULL,0,hbox1,1 ) ),scrolledwindow1 ); |
511 gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW( scrolledwindow1 ),GTK_POLICY_AUTOMATIC,GTK_POLICY_AUTOMATIC ); | |
512 | |
513 CTDirTree=gtk_ctree_new( 1,0 ); | |
514 gtk_signal_connect( GTK_OBJECT( CTDirTree ),"tree_expand",GTK_SIGNAL_FUNC( plCTree ),(void*)0 ); | |
515 gtk_signal_connect( GTK_OBJECT( CTDirTree ),"select_row",GTK_SIGNAL_FUNC( plCTRow ),(void *)0 ); | |
516 gtk_container_add( GTK_CONTAINER( scrolledwindow1 ),CTDirTree ); | |
517 gtk_clist_set_column_auto_resize( GTK_CLIST( CTDirTree ),0,TRUE ); | |
518 gtk_clist_set_column_width( GTK_CLIST( CTDirTree ),0,80 ); | |
519 gtk_clist_set_selection_mode( GTK_CLIST( CTDirTree ),GTK_SELECTION_SINGLE ); | |
520 gtk_ctree_set_line_style( GTK_CTREE( CTDirTree ),GTK_CTREE_LINES_SOLID ); | |
521 gtk_clist_column_titles_show( GTK_CLIST( CTDirTree ) ); | |
522 gtk_clist_set_shadow_type( GTK_CLIST( CTDirTree ),GTK_SHADOW_NONE ); | |
523 | |
524 if ( !pxOpenedBook ) pxOpenedBook=gdk_pixmap_create_from_xpm_d( PlayList->window,&msOpenedBook,&transparent,book_closed_xpm ); | |
525 if ( !pxClosedBook ) pxClosedBook=gdk_pixmap_create_from_xpm_d( PlayList->window,&msClosedBook,&transparent,book_open_xpm ); | |
526 | |
527 parent=gtk_ctree_insert_node( GTK_CTREE( CTDirTree ),NULL,NULL,&root,4,pxOpenedBook,msOpenedBook,pxClosedBook,msClosedBook,FALSE,FALSE ); | |
528 DirNode=malloc( sizeof( DirNodeType ) ); | |
529 DirNode->scaned=0; DirNode->path=strdup( root ); | |
530 gtk_ctree_node_set_row_data_full(GTK_CTREE( CTDirTree ),parent,DirNode,NULL ); | |
531 sibling=gtk_ctree_insert_node( GTK_CTREE( CTDirTree ),parent,NULL,&dummy,4,NULL,NULL,NULL,NULL,TRUE,TRUE ); | |
532 gtk_ctree_expand( GTK_CTREE( CTDirTree ),parent ); | |
533 gtk_widget_show( CTDirTree ); | |
534 | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
26458
diff
changeset
|
535 |
23077 | 536 gtk_clist_set_column_widget( GTK_CLIST( CTDirTree ),0, |
537 AddLabel( MSGTR_PLAYLIST_DirectoryTree,NULL ) ); | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
26458
diff
changeset
|
538 |
23077 | 539 vbox2=AddVBox( |
540 AddFrame( NULL,1,hbox1,1 ),0 ); | |
541 | |
542 scrolledwindow2=gtk_scrolled_window_new( NULL,NULL ); | |
543 gtk_widget_show( scrolledwindow2 ); | |
544 gtk_box_pack_start( GTK_BOX( vbox2 ),scrolledwindow2,TRUE,TRUE,0 ); | |
545 gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW( scrolledwindow2 ),GTK_POLICY_AUTOMATIC,GTK_POLICY_AUTOMATIC ); | |
546 | |
547 CLFiles=gtk_clist_new( 1 ); | |
548 gtk_widget_show( CLFiles ); | |
549 gtk_container_add( GTK_CONTAINER( scrolledwindow2 ),CLFiles ); | |
550 gtk_clist_set_column_width( GTK_CLIST( CLFiles ),0,80 ); | |
551 gtk_clist_set_selection_mode( GTK_CLIST( CLFiles ),GTK_SELECTION_EXTENDED ); | |
552 gtk_clist_column_titles_show( GTK_CLIST( CLFiles ) ); | |
553 gtk_clist_set_shadow_type( GTK_CLIST( CLFiles ),GTK_SHADOW_NONE ); | |
554 | |
555 gtk_clist_set_column_widget( GTK_CLIST( CLFiles ),0, | |
556 AddLabel( MSGTR_PLAYLIST_Files,NULL ) ); | |
557 | |
558 AddHSeparator( vbox2 ); | |
559 | |
560 scrolledwindow3=gtk_scrolled_window_new( NULL,NULL ); | |
561 gtk_widget_show( scrolledwindow3 ); | |
562 gtk_box_pack_start( GTK_BOX( vbox2 ),scrolledwindow3,TRUE,TRUE,0 ); | |
563 gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW( scrolledwindow3 ),GTK_POLICY_AUTOMATIC,GTK_POLICY_AUTOMATIC ); | |
564 | |
565 CLSelected=gtk_clist_new( 2 ); | |
566 gtk_widget_show( CLSelected ); | |
567 gtk_container_add( GTK_CONTAINER( scrolledwindow3 ),CLSelected ); | |
568 gtk_clist_set_column_width( GTK_CLIST( CLSelected ),0,295 ); | |
569 gtk_clist_set_column_width( GTK_CLIST( CLSelected ),1,295 ); | |
570 gtk_clist_set_selection_mode( GTK_CLIST( CLSelected ),GTK_SELECTION_MULTIPLE ); | |
571 gtk_clist_column_titles_show( GTK_CLIST( CLSelected ) ); | |
572 gtk_clist_set_shadow_type( GTK_CLIST( CLSelected ),GTK_SHADOW_NONE ); | |
573 | |
574 gtk_clist_set_column_widget( GTK_CLIST( CLSelected ),0, | |
575 AddLabel( MSGTR_PLAYLIST_Selected,NULL ) ); | |
576 | |
577 gtk_clist_set_column_widget( GTK_CLIST( CLSelected ),1, | |
578 AddLabel( MSGTR_PLAYLIST_Path,NULL ) ); | |
579 | |
580 AddHSeparator( vbox1 ); | |
581 | |
582 hbuttonbox1=AddHButtonBox( vbox1 ); | |
583 gtk_button_box_set_layout( GTK_BUTTON_BOX( hbuttonbox1 ),GTK_BUTTONBOX_END ); | |
584 gtk_button_box_set_spacing( GTK_BUTTON_BOX( hbuttonbox1 ),10 ); | |
585 | |
586 Add=AddButton( MSGTR_Add,hbuttonbox1 ); | |
587 Remove=AddButton( MSGTR_Remove,hbuttonbox1 ); | |
588 Ok=AddButton( MSGTR_Ok,hbuttonbox1 ); | |
589 Cancel=AddButton( MSGTR_Cancel,hbuttonbox1 ); | |
590 | |
591 gtk_widget_add_accelerator( Cancel,"clicked",accel_group,GDK_Escape,0,GTK_ACCEL_VISIBLE ); | |
592 | |
593 gtk_signal_connect( GTK_OBJECT( PlayList ),"destroy",GTK_SIGNAL_FUNC( WidgetDestroy ),&PlayList ); | |
594 | |
595 gtk_signal_connect( GTK_OBJECT( CLFiles ),"select_row",GTK_SIGNAL_FUNC( plRowSelect ),(void *)0 ); | |
596 gtk_signal_connect( GTK_OBJECT( CLFiles ),"unselect_row",GTK_SIGNAL_FUNC( plUnRowSelect ),(void *)0 ); | |
33408
dc8779e0e9cc
Allow direct selection with middle mouse button (single click).
ib
parents:
32723
diff
changeset
|
597 gtk_signal_connect( GTK_OBJECT( CLFiles ),"event",GTK_SIGNAL_FUNC( plEvent ),(void *)0 ); |
23077 | 598 sigSel=gtk_signal_connect( GTK_OBJECT( CLSelected ),"select_row",GTK_SIGNAL_FUNC( plRowSelect ),(void*)1 ); |
599 sigUnsel=gtk_signal_connect( GTK_OBJECT( CLSelected ),"unselect_row",GTK_SIGNAL_FUNC( plUnRowSelect ),(void*)1 ); | |
33408
dc8779e0e9cc
Allow direct selection with middle mouse button (single click).
ib
parents:
32723
diff
changeset
|
600 sigEvent=gtk_signal_connect( GTK_OBJECT( CLSelected ),"event",GTK_SIGNAL_FUNC( plEvent ),(void *)1 ); |
23077 | 601 |
602 gtk_signal_connect( GTK_OBJECT( Add ),"clicked",GTK_SIGNAL_FUNC( plButtonReleased ),(void*)3 ); | |
603 gtk_signal_connect( GTK_OBJECT( Remove ),"clicked",GTK_SIGNAL_FUNC( plButtonReleased ),(void*)2 ); | |
604 gtk_signal_connect( GTK_OBJECT( Ok ),"clicked",GTK_SIGNAL_FUNC( plButtonReleased ),(void*)1 ); | |
605 gtk_signal_connect( GTK_OBJECT( Cancel ),"clicked",GTK_SIGNAL_FUNC( plButtonReleased ),(void*)0 ); | |
606 | |
607 gtk_window_add_accel_group( GTK_WINDOW( PlayList ),accel_group ); | |
608 | |
609 return PlayList; | |
610 } |