3c1800f0730f1e422b44414e03edce100921f73f
[pandora-libraries.git] / minimenu / mmenu.c
1
2 /* minimenu
3  * aka "2wm" - too weak menu, two week menu, akin to twm
4  *
5  * Craig wants a super minimal menu ASAP before launch, so lets see what I can put together in 2 weeks with not much
6  * free time ;) I'd like to do a fuller ('tiny', but with plugin support and a decent expansion and customizing design..)
7  * but later, baby!
8  *
9  */
10
11 /* mmenu - This is the actual menu
12  * The goal of this app is to show a application picker screen of some sort, allow the user to perform some useful
13  * activities (such as set clock speed, say), and request an app to run, or shutdown, etc.
14  * To keep the memory footprint down, when invoking an application, the menu _exits_, and simply spits out
15  * an operation for mmwrapper to perform. In the case of no wrapper, the menu will just exit, which is handy for
16  * debugging.
17  */
18
19 /* mmenu lifecycle:
20  * 1) determine app list (via pnd scan, .desktop scan, whatever voodoo)
21  * 2) show a menu, allow user to interact:
22  *    a) user picks an application to run, or -> exit, pass shell run line to wrapper
23  *    b) user requests menu shutdown -> exit, tell wrapper to exit as well
24  *    c) user performsn some operation (set clock, copy files, whatever) -> probably stays within the menu
25  */
26
27 #include <stdio.h> /* for FILE etc */
28 #include <stdlib.h> /* for malloc */
29 #include <unistd.h> /* for unlink */
30 #include <limits.h> /* for PATH_MAX */
31 #include <sys/types.h>
32 #include <sys/stat.h>
33 #define __USE_GNU /* for strcasestr */
34 #include <string.h> /* for making ftw.h happy */
35 #include <strings.h>
36 #include <ctype.h>
37 #include <sys/wait.h>
38 #include <dirent.h>
39 #include <signal.h> // for sigaction
40
41 #include "pnd_logger.h"
42 #include "pnd_pxml.h"
43 #include "pnd_utility.h"
44 #include "pnd_conf.h"
45 #include "pnd_container.h"
46 #include "pnd_discovery.h"
47 #include "pnd_locate.h"
48 #include "pnd_device.h"
49 #include "pnd_pndfiles.h"
50 #include "../lib/pnd_pathiter.h"
51
52 #include "mmenu.h"
53 #include "mmwrapcmd.h"
54 #include "mmapps.h"
55 #include "mmcache.h"
56 #include "mmcat.h"
57 #include "mmui.h"
58
59 pnd_box_handle g_active_apps = NULL;
60 unsigned int g_active_appcount = 0;
61 char g_username [ 128 ]; // since we have to wait for login (!!), store username here
62 pnd_conf_handle g_conf = 0;
63 pnd_conf_handle g_desktopconf = 0;
64
65 char *pnd_run_script = NULL;
66 unsigned char g_x11_present = 1; // >0 if X is present
67 unsigned char g_catmap = 0; // if 1, we're doing category mapping
68 unsigned char g_pvwcache = 0; // if 1, we're trying to do preview caching
69
70 char g_skin_selected [ 100 ] = "default";
71 char *g_skinpath = NULL; // where 'skin_selected' is located .. the fullpath including skin-dir-name
72 pnd_conf_handle g_skinconf = NULL;
73
74 void sigquit_handler ( int n );
75
76 int main ( int argc, char *argv[] ) {
77   int logall = -1; // -1 means normal logging rules; >=0 means log all!
78   int i;
79
80   // boilerplate stuff from pndnotifyd and pndevmapperd
81
82   /* iterate across args
83    */
84   for ( i = 1; i < argc; i++ ) {
85
86     if ( argv [ i ][ 0 ] == '-' && argv [ i ][ 1 ] == 'l' ) {
87
88       if ( isdigit ( argv [ i ][ 2 ] ) ) {
89         unsigned char x = atoi ( argv [ i ] + 2 );
90         if ( x >= 0 &&
91              x < pndn_none )
92         {
93           logall = x;
94         }
95       } else {
96         logall = 0;
97       }
98
99     } else {
100       //printf ( "Unknown: %s\n", argv [ i ] );
101       printf ( "%s [-l##]\n", argv [ 0 ] );
102       printf ( "-l#\tLog-it; -l is 0-and-up (or all), and -l2 means 2-and-up (not all); l[0-3] for now. Log goes to /tmp/mmenu.log\n" );
103       printf ( "-f\tFull path of frontend to run\n" );
104       exit ( 0 );
105     }
106
107   } // for
108
109   /* enable logging?
110    */
111   pnd_log_set_pretext ( "mmenu" );
112   pnd_log_set_flush ( 1 );
113
114   if ( logall == -1 ) {
115     // standard logging; non-daemon versus daemon
116
117 #if 1 // HACK: set debug level to high on desktop, but not on pandora; just a convenience while devving, until the conf file is read
118     struct stat statbuf;
119     if ( stat ( PND_DEVICE_BATTERY_GAUGE_PERC, &statbuf ) == 0 ) {
120       // on pandora
121       pnd_log_set_filter ( pndn_error );
122     } else {
123       pnd_log_set_filter ( pndn_debug );
124     }
125 #endif
126
127     pnd_log_to_stdout();
128
129   } else {
130     FILE *f;
131
132     f = fopen ( "/tmp/mmenu.log", "w" );
133
134     if ( f ) {
135       pnd_log_set_filter ( logall );
136       pnd_log_to_stream ( f );
137       pnd_log ( pndn_rem, "logall mode - logging to /tmp/mmenu.log\n" );
138     }
139
140     if ( logall == pndn_debug ) {
141       pnd_log_set_buried_logging ( 1 ); // log the shit out of it
142       pnd_log ( pndn_rem, "logall mode 0 - turned on buried logging\n" );
143     }
144
145   } // logall
146
147   pnd_log ( pndn_rem, "%s built %s %s", argv [ 0 ], __DATE__, __TIME__ );
148
149   pnd_log ( pndn_rem, "log level starting as %u", pnd_log_get_filter() );
150
151   // wait for a user to be logged in - we should probably get hupped when a user logs in, so we can handle
152   // log-out and back in again, with SDs popping in and out between..
153   pnd_log ( pndn_rem, "Checking to see if a user is logged in\n" );
154   while ( 1 ) {
155     if ( pnd_check_login ( g_username, 127 ) ) {
156       break;
157     }
158     pnd_log ( pndn_debug, "  No one logged in yet .. spinning.\n" );
159     sleep ( 2 );
160   } // spin
161   pnd_log ( pndn_rem, "Looks like user '%s' is in, continue.\n", g_username );
162
163   /* conf file
164    */
165   g_conf = pnd_conf_fetch_by_name ( MMENU_CONF, MMENU_CONF_SEARCHPATH );
166
167   if ( ! g_conf ) {
168     pnd_log ( pndn_error, "ERROR: Couldn't fetch conf file '%s'!\n", MMENU_CONF );
169     emit_and_quit ( MM_QUIT );
170   }
171
172   g_desktopconf = pnd_conf_fetch_by_id ( pnd_conf_desktop, PND_CONF_SEARCHPATH );
173
174   if ( ! g_desktopconf ) {
175     pnd_log ( pndn_error, "ERROR: Couldn't fetch desktop conf file\n" );
176     emit_and_quit ( MM_QUIT );
177   }
178
179   /* set up quit signal handler
180    */
181   sigset_t ss;
182   sigemptyset ( &ss );
183
184   struct sigaction siggy;
185   siggy.sa_handler = sigquit_handler;
186   siggy.sa_mask = ss; /* implicitly blocks the origin signal */
187   siggy.sa_flags = SA_RESTART; /* don't need anything */
188   sigaction ( SIGQUIT, &siggy, NULL );
189
190   /* category conf file
191    */
192   {
193     char *locater = pnd_locate_filename ( pnd_conf_get_as_char ( g_conf, "categories.catmap_searchpath" ),
194                                           pnd_conf_get_as_char ( g_conf, "categories.catmap_confname" ) );
195
196     if ( locater ) {
197       pnd_log ( pndn_rem, "Found category conf at '%s'\n", locater );
198       pnd_conf_handle h = pnd_conf_fetch_by_path ( locater );
199       if ( h ) {
200         // lets just merge the skin conf onto the regular conf, so it just magicly works
201         pnd_box_append ( g_conf, h );
202       }
203     } else {
204       pnd_log ( pndn_debug, "No additional category conf file found.\n" );
205     }
206
207   } // cat conf
208
209   // redo log filter
210   pnd_log_set_filter ( pnd_conf_get_as_int_d ( g_conf, "minimenu.loglevel", pndn_error ) );
211
212   /* setup
213    */
214
215   // X11?
216   if ( pnd_conf_get_as_char ( g_conf, "minimenu.x11_present_sh" ) ) {
217     FILE *fx = popen ( pnd_conf_get_as_char ( g_conf, "minimenu.x11_present_sh" ), "r" );
218     char buffer [ 100 ];
219     if ( fx ) {
220       if ( fgets ( buffer, 100, fx ) ) {
221         if ( atoi ( buffer ) ) {
222           g_x11_present = 1;
223           pnd_log ( pndn_rem, "X11 seems to be present [pid %u]\n", atoi(buffer) );
224         } else {
225           g_x11_present = 0;
226           pnd_log ( pndn_rem, "X11 seems NOT to be present\n" );
227         }
228       } else {
229           g_x11_present = 0;
230           pnd_log ( pndn_rem, "X11 seems NOT to be present\n" );
231       }
232       pclose ( fx );
233     }
234   } // x11?
235
236   // pnd_run.sh
237   pnd_run_script = pnd_locate_filename ( pnd_conf_get_as_char ( g_conf, "minimenu.pndrun" ), "pnd_run.sh" );
238
239   if ( ! pnd_run_script ) {
240     pnd_log ( pndn_error, "ERROR: Couldn't locate pnd_run.sh!\n" );
241     emit_and_quit ( MM_QUIT );
242   }
243
244   pnd_run_script = strdup ( pnd_run_script ); // so we don't lose it next pnd_locate
245
246   pnd_log ( pndn_rem, "Found pnd_run.sh at '%s'\n", pnd_run_script );
247
248   // figure out what skin is selected (or default)
249   FILE *f;
250   char *s = strdup ( pnd_conf_get_as_char ( g_conf, "minimenu.skin_selected" ) );
251   s = pnd_expand_tilde ( s );
252   if ( ( f = fopen ( s, "r" ) ) ) {
253     char buffer [ 100 ];
254     if ( fgets ( buffer, 100, f ) ) {
255       // see if that dir can be located
256       if ( strchr ( buffer, '\n' ) ) {
257         * strchr ( buffer, '\n' ) = '\0';
258       }
259       char *found = pnd_locate_filename ( pnd_conf_get_as_char ( g_conf, "minimenu.skin_searchpath" ), buffer );
260       if ( found ) {
261         strncpy ( g_skin_selected, buffer, 100 );
262         g_skinpath = strdup ( found );
263       } else {
264         pnd_log ( pndn_warning, "Couldn't locate skin named '%s' so falling back.\n", buffer );
265       }
266     }
267     fclose ( f );
268   }
269   free ( s );
270
271   if ( g_skinpath ) {
272     pnd_log ( pndn_rem, "Skin is selected: '%s'\n", g_skin_selected );
273   } else {
274     pnd_log ( pndn_rem, "Skin falling back to: '%s'\n", g_skin_selected );
275
276     char *found = pnd_locate_filename ( pnd_conf_get_as_char ( g_conf, "minimenu.skin_searchpath" ),
277                                         g_skin_selected );
278     if ( found ) {
279       g_skinpath = strdup ( found );
280     } else {
281       pnd_log ( pndn_error, "Couldn't locate skin named '%s'.\n", g_skin_selected );
282       emit_and_quit ( MM_QUIT );
283     }
284
285   }
286   pnd_log ( pndn_rem, "Skin path determined to be: '%s'\n", g_skinpath );
287
288   // lets see if this skin-path actually has a skin conf
289   {
290     char fullpath [ PATH_MAX ];
291     sprintf ( fullpath, "%s/%s", g_skinpath, pnd_conf_get_as_char ( g_conf, "minimenu.skin_confname" ) );
292     g_skinconf = pnd_conf_fetch_by_path ( fullpath );
293   }
294
295   // figure out skin path if we didn't get it already
296   if ( ! g_skinconf ) {
297     pnd_log ( pndn_error, "ERROR: Couldn't set up skin!\n" );
298     emit_and_quit ( MM_QUIT );
299   }
300
301   // lets just merge the skin conf onto the regular conf, so it just magicly works
302   pnd_box_append ( g_conf, g_skinconf );
303
304   // attempt to set up UI
305   if ( ! ui_setup() ) {
306     pnd_log ( pndn_error, "ERROR: Couldn't set up the UI!\n" );
307     emit_and_quit ( MM_QUIT );
308   }
309
310   // show load screen
311   ui_loadscreen();
312
313   // store flag if we're doing preview caching or not
314   if ( pnd_conf_get_as_int_d ( g_conf, "previewpic.do_cache", 0 ) ) {
315     g_pvwcache = 1;
316   }
317
318   // set up static image cache
319   if ( ! ui_imagecache ( g_skinpath ) ) {
320     pnd_log ( pndn_error, "ERROR: Couldn't set up static UI image cache!\n" );
321     emit_and_quit ( MM_QUIT );
322   }
323
324   // create all cat
325   if ( pnd_conf_get_as_int_d ( g_conf, "categories.do_all_cat", 1 ) ) {
326     category_push ( g_x11_present ? CATEGORY_ALL "    (X11)" : CATEGORY_ALL "   (No X11)", NULL /*app*/, 0, NULL /* fspath */ );
327   }
328
329   // set up category mappings
330   if ( pnd_conf_get_as_int_d ( g_conf, "categories.map_on", 0 ) ) {
331     g_catmap = category_map_setup();
332   }
333
334   /* inhale applications, icons, categories, etc
335    */
336   applications_scan();
337
338   /* actual work now
339    */
340
341   while ( 1 ) { // forever!
342
343     // show the menu, or changes thereof
344     ui_render();
345
346     // wait for input or time-based events (like animations)
347     // deal with inputs
348     ui_process_input ( 1 /* block */ );
349
350     // sleep? block?
351     usleep ( 5000 );
352
353   } // while
354
355   return ( 0 );
356 }
357
358 void emit_and_quit ( char *s ) {
359   printf ( "%s\n", s );
360   exit ( 0 );
361 }
362
363 static unsigned int is_dir_empty ( char *fullpath ) {
364   DIR *d = opendir ( fullpath );
365
366   if ( ! d ) {
367     return ( 0 ); // not empty, since we don't know
368   }
369
370   struct dirent *de = readdir ( d );
371
372   while ( de ) {
373
374     if ( strcmp ( de -> d_name, "." ) == 0 ) {
375       // irrelevent
376     } else if ( strcmp ( de -> d_name, ".." ) == 0 ) {
377       // irrelevent
378     } else {
379       // something else came in, so dir must not be empty
380       return ( 0 ); 
381     }
382
383     de = readdir ( d );
384   }
385
386   closedir ( d );
387
388   return ( 1 ); // dir is empty
389 }
390
391 void applications_free ( void ) {
392
393   // free up all our category apprefs, but keep the preview and icon cache's..
394   category_freeall();
395
396   // free up old disco_t
397   if ( g_active_apps ) {
398     pnd_disco_t *p = pnd_box_get_head ( g_active_apps );
399     pnd_disco_t *n;
400     while ( p ) {
401       n = pnd_box_get_next ( p );
402       pnd_disco_destroy ( p );
403       p = n;
404     }
405     pnd_box_delete ( g_active_apps );
406   }
407
408   return;
409 }
410
411 void applications_scan ( void ) {
412
413   // show disco screen
414   ui_discoverscreen ( 1 /* clear screen */ );
415
416   // determine current app list, cache icons
417   // - ignore overrides for now
418
419   g_active_apps = 0;
420   pnd_box_handle merge_apps = 0;
421
422   // desktop apps?
423   if ( pnd_conf_get_as_int_d ( g_conf, "minimenu.desktop_apps", 1 ) ) {
424     pnd_log ( pndn_debug, "Looking for pnd applications here: %s\n",
425               pnd_conf_get_as_char ( g_desktopconf, "desktop.searchpath" ) );
426     g_active_apps = pnd_disco_search ( pnd_conf_get_as_char ( g_desktopconf, "desktop.searchpath" ), NULL );
427   }
428
429   // menu apps?
430   if ( pnd_conf_get_as_int_d ( g_conf, "minimenu.menu_apps", 1 ) ) {
431     pnd_log ( pndn_debug, "Looking for pnd applications here: %s\n",
432               pnd_conf_get_as_char ( g_desktopconf, "menu.searchpath" ) );
433     merge_apps = pnd_disco_search ( pnd_conf_get_as_char ( g_desktopconf, "menu.searchpath" ), NULL );
434   }
435
436   // merge lists
437   if ( merge_apps ) {
438     if ( g_active_apps ) {
439       // got menu apps, and got desktop apps, merge
440       pnd_box_append ( g_active_apps, merge_apps );
441     } else {
442       // got menu apps, had no desktop apps, so just assign
443       g_active_apps = merge_apps;
444     }
445   }
446
447   // aux apps?
448   char *aux_apps = NULL;
449   merge_apps = 0;
450   aux_apps = pnd_conf_get_as_char ( g_conf, "minimenu.aux_searchpath" );
451   if ( aux_apps && aux_apps [ 0 ] ) {
452     pnd_log ( pndn_debug, "Looking for pnd applications here: %s\n", aux_apps );
453     merge_apps = pnd_disco_search ( aux_apps, NULL );
454   }
455
456   // merge aux apps
457   if ( merge_apps ) {
458     if ( g_active_apps ) {
459       pnd_box_append ( g_active_apps, merge_apps );
460     } else {
461       g_active_apps = merge_apps;
462     }
463   }
464
465   // do it
466   g_active_appcount = pnd_box_get_size ( g_active_apps );
467
468   unsigned char maxwidth, maxheight;
469   maxwidth = pnd_conf_get_as_int_d ( g_conf, "grid.icon_max_width", 50 );
470   maxheight = pnd_conf_get_as_int_d ( g_conf, "grid.icon_max_height", 50 );
471
472   // show cache screen
473   ui_cachescreen ( 1 /* clear screen */, NULL );
474
475   pnd_log ( pndn_debug, "Found pnd applications, and caching icons:\n" );
476   pnd_disco_t *iter = pnd_box_get_head ( g_active_apps );
477   unsigned int itercount = 0;
478   while ( iter ) {
479     //pnd_log ( pndn_debug, "  App: '%s'\n", IFNULL(iter->title_en,"No Name") );
480
481     // update cachescreen
482     // ... every 5 filenames, just to avoid slowing it too much
483     if ( itercount % 5 == 0 ) {
484       ui_cachescreen ( 0 /* clear screen */, IFNULL(iter->title_en,"No Name") );
485     }
486
487     // if an ovr was flagged by libpnd, lets go inhale it just so we've got the
488     // notes handy, since notes are not handled by libpnd proper
489     pnd_conf_handle ovrh = 0;
490     if ( iter -> object_flags & PND_DISCO_FLAG_OVR ) {
491       char ovrfile [ PATH_MAX ];
492       char *fixpxml;
493       sprintf ( ovrfile, "%s/%s", iter -> object_path, iter -> object_filename );
494       fixpxml = strcasestr ( ovrfile, PND_PACKAGE_FILEEXT );
495       strcpy ( fixpxml, PXML_SAMEPATH_OVERRIDE_FILEEXT );
496
497       ovrh = pnd_conf_fetch_by_path ( ovrfile );
498
499 #if 0
500       if ( ovrh ) {
501         pnd_log ( pndn_debug, "Found ovr file for %s # %u\n", iter -> object_filename, iter -> subapp_number );
502       }
503 #endif
504
505     } // ovr
506
507     // cache the icon, unless deferred
508     if ( pnd_conf_get_as_int_d ( g_conf, "minimenu.load_icons_later", 0 ) == 0 ) {
509       if ( iter -> pnd_icon_pos &&
510            ! cache_icon ( iter, maxwidth, maxheight ) )
511       {
512         pnd_log ( pndn_warning, "  Couldn't load icon: '%s'\n", IFNULL(iter->title_en,"No Name") );
513       }
514     }
515
516     // cache the preview --> SHOULD DEFER
517     if ( pnd_conf_get_as_int_d ( g_conf, "minimenu.load_previews_now", 0 ) > 0 ) {
518       // load the preview pics now!
519       if ( iter -> preview_pic1 &&
520            ! cache_preview ( iter, pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_width", 200 ), pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_height", 180 ) ) )
521       {
522         pnd_log ( pndn_warning, "  Couldn't load preview pic: '%s' -> '%s'\n", IFNULL(iter->title_en,"No Name"), iter -> preview_pic1 );
523       }
524     } // preview now?
525
526     // push the categories .. or suppress application
527     //
528     if ( ( pnd_pxml_get_x11 ( iter -> option_no_x11 ) != pnd_pxml_x11_required ) ||
529          ( pnd_pxml_get_x11 ( iter -> option_no_x11 ) == pnd_pxml_x11_required && g_x11_present == 1 )
530        )
531     {
532
533       // push to All category
534       // we do this first, so first category is always All
535       if ( pnd_conf_get_as_int_d ( g_conf, "categories.do_all_cat", 1 ) ) {
536         if ( ! category_push ( g_x11_present ? CATEGORY_ALL "    (X11)" : CATEGORY_ALL "   (No X11)", iter, ovrh, NULL /* fspath */ ) ) {
537           pnd_log ( pndn_warning, "  Couldn't categorize to All: '%s'\n", IFNULL(iter -> title_en, "No Name") );
538         }
539       } // all?
540
541       // main categories
542       if ( iter -> main_category && pnd_conf_get_as_int_d ( g_conf, "tabs.top_maincat", 1 ) ) {
543         if ( ! category_meta_push ( iter -> main_category, iter, ovrh ) ) {
544           pnd_log ( pndn_warning, "  Couldn't categorize to %s: '%s'\n", iter -> main_category, IFNULL(iter -> title_en, "No Name") );
545         }
546       }
547
548       if ( iter -> main_category1 && pnd_conf_get_as_int_d ( g_conf, "tabs.top_maincat1", 0 ) ) {
549         if ( ! category_meta_push ( iter -> main_category1, iter, ovrh ) ) {
550           pnd_log ( pndn_warning, "  Couldn't categorize to %s: '%s'\n", iter -> main_category1, IFNULL(iter -> title_en, "No Name") );
551         }
552       }
553
554       if ( iter -> main_category2 && pnd_conf_get_as_int_d ( g_conf, "tabs.top_maincat2", 0 ) ) {
555         if ( ! category_meta_push ( iter -> main_category2, iter, ovrh ) ) {
556           pnd_log ( pndn_warning, "  Couldn't categorize to %s: '%s'\n", iter -> main_category2, IFNULL(iter -> title_en, "No Name") );
557         }
558       }
559
560       // alt categories
561       if ( iter -> alt_category && pnd_conf_get_as_int_d ( g_conf, "tabs.top_altcat", 0 ) ) {
562         if ( ! category_meta_push ( iter -> alt_category, iter, ovrh ) ) {
563           pnd_log ( pndn_warning, "  Couldn't categorize to %s: '%s'\n", iter -> alt_category, IFNULL(iter -> title_en, "No Name") );
564         }
565       }
566
567       if ( iter -> alt_category1 && pnd_conf_get_as_int_d ( g_conf, "tabs.top_altcat1", 0 ) ) {
568         if ( ! category_meta_push ( iter -> alt_category1, iter, ovrh ) ) {
569           pnd_log ( pndn_warning, "  Couldn't categorize to %s: '%s'\n", iter -> alt_category1, IFNULL(iter -> title_en, "No Name") );
570         }
571       }
572
573       if ( iter -> alt_category2 && pnd_conf_get_as_int_d ( g_conf, "tabs.top_altcat2", 0 ) ) {
574         if ( ! category_meta_push ( iter -> alt_category2, iter, ovrh ) ) {
575           pnd_log ( pndn_warning, "  Couldn't categorize to %s: '%s'\n", iter -> alt_category2, IFNULL(iter -> title_en, "No Name") );
576         }
577       }
578
579     } // register with categories or filter out
580
581     // next
582     iter = pnd_box_get_next ( iter );
583     itercount++;
584   } // while
585
586   // set up filesystem browser tabs
587   if ( pnd_conf_get_as_int_d ( g_conf, "filesystem.do_browser", 0 ) ) {
588     char *searchpath = pnd_conf_get_as_char ( g_conf, "filesystem.tab_searchpaths" );
589
590     SEARCHPATH_PRE
591     {
592       char *c, *tabname;
593       c = strrchr ( buffer, '/' );
594       if ( c && (*(c+1)!='\0') ) {
595         tabname = c;
596       } else {
597         tabname = buffer;
598       }
599
600       // check if dir is empty; if so, skip it.
601       if ( ! is_dir_empty ( buffer ) ) {
602         category_push ( tabname /* tab name */, NULL /* app */, 0 /* override */, buffer /* fspath */ );
603       }
604
605     }
606     SEARCHPATH_POST
607
608   } // set up fs browser tabs
609
610   // dump categories
611   //category_dump();
612
613   // let deferred icon cache go now
614   ui_post_scan();
615
616   return;
617 }
618
619 void sigquit_handler ( int n ) {
620   pnd_log ( pndn_rem, "SIGQUIT received; graceful exit.\n" );
621   emit_and_quit ( MM_QUIT );
622 }