From: skeezix Date: Fri, 11 Jun 2010 20:21:28 +0000 (-0400) Subject: Added default auto-rescan to minimenu on SD insert; disable via conf file. X-Git-Tag: sz_beta3~152 X-Git-Url: https://git.openpandora.org/cgi-bin/gitweb.cgi?p=pandora-libraries.git;a=commitdiff_plain;h=e7c888f5321c521e6b5b4d0fab3237b8373147af Added default auto-rescan to minimenu on SD insert; disable via conf file. Also made pandora button wait a bit longer before being pnd-kill; easier pandora menu now --- diff --git a/deployment/etc/pandora/conf/mmenu.conf b/deployment/etc/pandora/conf/mmenu.conf index 76ca773..8ccd975 100644 --- a/deployment/etc/pandora/conf/mmenu.conf +++ b/deployment/etc/pandora/conf/mmenu.conf @@ -27,6 +27,7 @@ x11_present_sh /bin/pidof X # command to invoke to determine if X11 is running desktop_apps 1 # search the pnd standard desktop searchpath for apps menu_apps 1 # search the pnd standard menu searchpath for apps aux_searchpath /media/*/pandora/mmenu:/usr/pandora/mmenu # if something here, also search this path; can be used for mmenu-only apps? +auto_rescan 1 # if >0, will automaticly rescan for applications, if SD inserts/ejects [utility] terminal /usr/bin/Terminal # could also be /usr/bin/xterm, or a sh-script, or whatever diff --git a/minimenu/mmenu.c b/minimenu/mmenu.c index 0a53ef3..78313f5 100644 --- a/minimenu/mmenu.c +++ b/minimenu/mmenu.c @@ -48,6 +48,9 @@ #include "pnd_device.h" #include "pnd_pndfiles.h" #include "../lib/pnd_pathiter.h" +#include "pnd_notify.h" +#include "pnd_dbusnotify.h" +#include "pnd_apps.h" #include "mmenu.h" #include "mmwrapcmd.h" @@ -66,6 +69,10 @@ char *pnd_run_script = NULL; unsigned char g_x11_present = 1; // >0 if X is present unsigned char g_catmap = 0; // if 1, we're doing category mapping unsigned char g_pvwcache = 0; // if 1, we're trying to do preview caching +unsigned char g_autorescan = 1; // default to auto rescan + +pnd_dbusnotify_handle dbh = 0; // if >0, dbusnotify is active +pnd_notify_handle nh = 0; // if >0, inotify is active char g_skin_selected [ 100 ] = "default"; char *g_skinpath = NULL; // where 'skin_selected' is located .. the fullpath including skin-dir-name @@ -245,6 +252,12 @@ int main ( int argc, char *argv[] ) { pnd_log ( pndn_rem, "Found pnd_run.sh at '%s'\n", pnd_run_script ); + // auto rescan? + if ( pnd_conf_get_as_int ( g_conf, "minimenu.auto_rescan" ) != PND_CONF_BADNUM ) { + g_autorescan = pnd_conf_get_as_int ( g_conf, "minimenu.auto_rescan" ); + } + pnd_log ( pndn_debug, "application rescan is set to: %s\n", g_autorescan ? "auto" : "manual" ); + // figure out what skin is selected (or default) FILE *f; char *s = strdup ( pnd_conf_get_as_char ( g_conf, "minimenu.skin_selected" ) ); @@ -337,6 +350,17 @@ int main ( int argc, char *argv[] ) { /* actual work now */ + unsigned char block = 1; + + if ( g_autorescan ) { + block = 0; + + // set up notifications + dbh = pnd_dbusnotify_init(); + pnd_log ( pndn_debug, "Setting up dbusnotify\n" ); + //setup_notifications(); + + } // set up rescan while ( 1 ) { // forever! @@ -345,7 +369,28 @@ int main ( int argc, char *argv[] ) { // wait for input or time-based events (like animations) // deal with inputs - ui_process_input ( 1 /* block */ ); + ui_process_input ( block /* block */ ); + + // did a rescan event trigger? + if ( g_autorescan ) { + unsigned char watch_dbus = 0; + unsigned char watch_inotify = 0; + + if ( dbh ) { + watch_dbus = pnd_dbusnotify_rediscover_p ( dbh ); + } + + if ( nh ) { + watch_inotify = pnd_notify_rediscover_p ( nh ); + } + + if ( watch_dbus || watch_inotify ) { + pnd_log ( pndn_debug, "dbusnotify detected SD event\n" ); + applications_free(); + applications_scan(); + } + + } // rescan? // sleep? block? usleep ( 5000 ); @@ -357,6 +402,10 @@ int main ( int argc, char *argv[] ) { void emit_and_quit ( char *s ) { printf ( "%s\n", s ); + pnd_dbusnotify_shutdown ( dbh ); + if ( nh ) { + pnd_notify_shutdown ( nh ); + } exit ( 0 ); } @@ -593,3 +642,64 @@ void sigquit_handler ( int n ) { pnd_log ( pndn_rem, "SIGQUIT received; graceful exit.\n" ); emit_and_quit ( MM_QUIT ); } + +void setup_notifications ( void ) { + + // figure out notify path + char *configpath; + char *notifypath = NULL; + + configpath = pnd_conf_query_searchpath(); + + pnd_conf_handle apph; + + apph = pnd_conf_fetch_by_id ( pnd_conf_apps, configpath ); + + if ( apph ) { + + notifypath = pnd_conf_get_as_char ( apph, PND_APPS_NOTIFY_KEY ); + + if ( ! notifypath ) { + notifypath = PND_APPS_NOTIFYPATH; + } + + } + + // given notify path.. ripped from pndnotifyd :( + char *searchpath = notifypath; + + // if this is first time through, we can just set it up; for subsequent times + // through, we need to close existing fd and re-open it, since we're too lame + // to store the list of watches and 'rm' them +#if 1 + if ( nh ) { + pnd_notify_shutdown ( nh ); + nh = 0; + } +#endif + + // set up a new set of notifies + if ( ! nh ) { + nh = pnd_notify_init(); + } + + if ( ! nh ) { + pnd_log ( pndn_rem, "INOTIFY failed to init.\n" ); + exit ( -1 ); + } + +#if 0 + pnd_log ( pndn_rem, "INOTIFY is up.\n" ); +#endif + + SEARCHPATH_PRE + { + + pnd_log ( pndn_rem, "Watching path '%s' and its descendents.\n", buffer ); + pnd_notify_watch_path ( nh, buffer, PND_NOTIFY_RECURSE ); + + } + SEARCHPATH_POST + + return; +} diff --git a/minimenu/mmenu.conf b/minimenu/mmenu.conf index 023af83..391ab98 100644 --- a/minimenu/mmenu.conf +++ b/minimenu/mmenu.conf @@ -27,6 +27,7 @@ x11_present_sh /bin/pidof X # command to invoke to determine if X11 is running desktop_apps 1 # search the pnd standard desktop searchpath for apps menu_apps 1 # search the pnd standard menu searchpath for apps aux_searchpath /media/*/pandora/mmenu # if something here, also search this path; can be used for mmenu-only apps? +auto_rescan 1 # if >0, will automaticly rescan for applications, if SD inserts/ejects [utility] terminal /usr/bin/Terminal # could also be /usr/bin/xterm, or a sh-script, or whatever diff --git a/minimenu/mmenu.h b/minimenu/mmenu.h index 3816ad4..f7de51e 100644 --- a/minimenu/mmenu.h +++ b/minimenu/mmenu.h @@ -24,4 +24,6 @@ void emit_and_quit ( char *s ); void applications_free ( void ); void applications_scan ( void ); +void setup_notifications ( void ); + #endif diff --git a/minimenu/mmui.c b/minimenu/mmui.c index 58ee9f9..0601a0e 100644 --- a/minimenu/mmui.c +++ b/minimenu/mmui.c @@ -2363,6 +2363,9 @@ void ui_post_scan ( void ) { } // default cat + // redraw all + render_mask |= CHANGED_EVERYTHING; + return; } diff --git a/testdata/scripts/op_menu.sh b/testdata/scripts/op_menu.sh index 85f33de..7ed36c8 100755 --- a/testdata/scripts/op_menu.sh +++ b/testdata/scripts/op_menu.sh @@ -2,7 +2,7 @@ #actions done when the menu button is pressed #only argument is the time the button was pressed in seconds -if [ "$1" -ge "1" ]; then #button was pressed 3 sec or longer, show list of apps to kill instead of launcher +if [ "$1" -ge "2" ]; then #button was pressed 3 sec or longer, show list of apps to kill instead of launcher killist=y fi