X-Git-Url: http://git.openpandora.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=apps%2Fpndnotifyd.c;h=346ab25405152e4f6f51f75e10173aa563da26cb;hb=69e4615440db2d9d4fe16371bf279cfca72ffa35;hp=13bfa93193f74b4c9ab997f654f978406af1815d;hpb=c961b47445f435dab11096f65b1d501509b20698;p=pandora-libraries.git diff --git a/apps/pndnotifyd.c b/apps/pndnotifyd.c index 13bfa93..346ab25 100644 --- a/apps/pndnotifyd.c +++ b/apps/pndnotifyd.c @@ -27,6 +27,8 @@ #include "pnd_utility.h" #include "pnd_desktop.h" #include "pnd_logger.h" +#include "pnd_dbusnotify.h" +#include "pnd_pndfiles.h" // this piece of code was simpler once; but need to grow it a bit and in a rush // moving all these to globals rather than refactor the code a bit; tsk tsk.. @@ -56,6 +58,7 @@ char *desktop_appspath = NULL; char *menu_dotdesktoppath = NULL; char *menu_iconpath = NULL; char *menu_appspath = NULL; +char *info_dotdesktoppath = NULL; // pnd runscript char *run_searchpath; // searchpath to find pnd_run.sh char *run_script; // name of pnd_run.sh script from config @@ -65,6 +68,8 @@ char *pndhup = NULL; // full path to located pnd_hup.sh char g_username [ 128 ]; // since we have to wait for login (!!), store username here // notifier handle pnd_notify_handle nh = 0; +pnd_dbusnotify_handle dbh = 0; +unsigned char g_info_p = 0; // spit out info .desktops // constants #define PNDNOTIFYD_LOGLEVEL "pndnotifyd.loglevel" @@ -72,6 +77,7 @@ pnd_notify_handle nh = 0; // decl's void consume_configuration ( void ); void setup_notifications ( void ); +void sigint_handler ( int n ); void sighup_handler ( int n ); void process_discoveries ( pnd_box_handle applist, char *emitdesktoppath, char *emiticonpath ); unsigned char perform_discoveries ( char *appspath, char *overridespath, @@ -110,7 +116,7 @@ int main ( int argc, char *argv[] ) { } } else { - printf ( "%s [-d] [##]\n", argv [ 0 ] ); + printf ( "%s [-d] [-l] [##]\n", argv [ 0 ] ); printf ( "-d\tDaemon mode; detach from terminal, chdir to /tmp, suppress output. Optional.\n" ); printf ( "-n\tDo not scan on launch; default is to run a scan for apps when %s is invoked.\n", argv [ 0 ] ); 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/pndnotifyd.log\n" ); @@ -226,6 +232,7 @@ int main ( int argc, char *argv[] ) { pnd_log ( pndn_rem, "Apps searchpath is '%s'\n", menu_appspath ); pnd_log ( pndn_rem, ".desktop files emit to '%s'\n", menu_dotdesktoppath ); pnd_log ( pndn_rem, ".desktop icon files emit to '%s'\n", menu_iconpath ); + pnd_log ( pndn_rem, ".desktop info files emit to '%s'\n", info_dotdesktoppath ? info_dotdesktoppath : "n/a" ); /* set up signal handler */ @@ -239,6 +246,9 @@ int main ( int argc, char *argv[] ) { sigaction ( SIGHUP, &siggy, NULL ); + siggy.sa_handler = sigint_handler; + sigaction ( SIGINT, &siggy, NULL ); + /* set up notifies */ @@ -248,46 +258,72 @@ int main ( int argc, char *argv[] ) { setup_notifications(); //} + dbh = pnd_dbusnotify_init(); + /* daemon main loop */ + unsigned char watch_inotify, watch_dbus; while ( 1 ) { + watch_dbus = 0; + watch_inotify = 0; + + if ( dbh ) { + watch_dbus = pnd_dbusnotify_rediscover_p ( dbh ); + } + + if ( ! watch_dbus && nh ) { + watch_inotify = pnd_notify_rediscover_p ( nh ); + } + // need to rediscover? - if ( scanonlaunch || - pnd_notify_rediscover_p ( nh ) ) - { + if ( scanonlaunch || watch_inotify || watch_dbus ) { - if ( time ( NULL ) - createtime <= 2 ) { - pnd_log ( pndn_rem, "Rediscovery request comes to soon after previous discovery; skipping.\n" ); - sleep ( interval_secs ); - continue; - } + // by this point, the watched directories have notified us that something of relevent + // has occurred; we should be clever, but we're not, so just re-brute force the + // discovery and spit out .desktop files.. + pnd_log ( pndn_rem, "------------------------------------------------------\n" ); - createtime = time ( NULL ); // all 'new' .destops are created at or after this time; prev are old. + pnd_log ( pndn_rem, "System changes detected in dbus or watched paths .. performing re-discover!\n" ); // if this was a forced scan, lets not do that next iteration if ( scanonlaunch ) { + pnd_log ( pndn_rem, "scan-on-first-launch detected an event\n" ); scanonlaunch = 0; } - // by this point, the watched directories have notified us that something of relevent - // has occurred; we should be clever, but we're not, so just re-brute force the - // discovery and spit out .desktop files.. + if ( watch_inotify ) { + pnd_log ( pndn_rem, "inotify detected an event\n" ); + } + + if ( watch_dbus ) { + pnd_log ( pndn_rem, "dbusnotify detected an event\n" ); + pnd_notify_shutdown ( nh ); + nh = 0; + } + + if ( time ( NULL ) - createtime <= 2 ) { + pnd_log ( pndn_rem, "Rediscovery request comes to soon after previous discovery; skipping.\n" ); + sleep ( interval_secs ); + continue; + } + pnd_log ( pndn_rem, "------------------------------------------------------\n" ); - pnd_log ( pndn_rem, "Changes within watched paths .. performing re-discover!\n" ); + + createtime = time ( NULL ); // all 'new' .destops are created at or after this time; prev are old. /* run the discovery */ - pnd_log ( pndn_rem, "Scanning desktop paths----------------------------\n" ); + pnd_log ( pndn_rem, " Scanning desktop paths----------------------------\n" ); if ( ! perform_discoveries ( desktop_appspath, overridespath, desktop_dotdesktoppath, desktop_iconpath ) ) { - pnd_log ( pndn_rem, "No applications found in desktop search path\n" ); + pnd_log ( pndn_rem, " No applications found in desktop search path\n" ); } if ( menu_appspath && menu_dotdesktoppath && menu_iconpath ) { - pnd_log ( pndn_rem, "Scanning menu paths----------------------------\n" ); + pnd_log ( pndn_rem, " Scanning menu paths----------------------------\n" ); if ( ! perform_discoveries ( menu_appspath, overridespath, menu_dotdesktoppath, menu_iconpath ) ) { - pnd_log ( pndn_rem, "No applications found in menu search path\n" ); + pnd_log ( pndn_rem, " No applications found in menu search path\n" ); } } @@ -300,7 +336,9 @@ int main ( int argc, char *argv[] ) { // since its entirely likely new directories have been found (ie: SD with a directory structure was inserted) // we should re-apply watches to catch all these new directories; ie: user might use on-device browser to // drop in new applications, or use the shell to juggle them around, or any number of activities. - //setup_notifications(); + if ( watch_dbus ) { + setup_notifications(); + } } // need to rediscover? @@ -318,6 +356,7 @@ int main ( int argc, char *argv[] ) { /* shutdown */ pnd_notify_shutdown ( nh ); + pnd_dbusnotify_shutdown ( dbh ); return ( 0 ); } @@ -366,6 +405,7 @@ void consume_configuration ( void ) { desktop_dotdesktoppath = pnd_conf_get_as_char ( desktoph, PND_DESKTOP_DOTDESKTOP_PATH_KEY ); desktop_iconpath = pnd_conf_get_as_char ( desktoph, PND_DESKTOP_ICONS_PATH_KEY ); desktop_appspath = pnd_conf_get_as_char ( desktoph, PND_DESKTOP_SEARCH_KEY ); + info_dotdesktoppath = pnd_conf_get_as_char ( desktoph, "info.dotdesktoppath" ); } if ( ! desktop_dotdesktoppath ) { @@ -387,6 +427,11 @@ void consume_configuration ( void ) { menu_appspath = pnd_conf_get_as_char ( desktoph, PND_MENU_SEARCH_KEY ); } + // info + if ( desktoph ) { + g_info_p = pnd_conf_get_as_int_d ( desktoph, "info.emit_info", 0 ); + } + /* try to locate a runscript and optional hupscript */ @@ -522,6 +567,11 @@ void consume_configuration ( void ) { mkdir ( desktop_dotdesktoppath, 0777 ); mkdir ( desktop_iconpath, 0777 ); + if ( info_dotdesktoppath ) { + info_dotdesktoppath = pnd_expand_tilde ( strdup ( info_dotdesktoppath ) ); + mkdir ( info_dotdesktoppath, 0777 ); + } + if ( menu_dotdesktoppath ) { menu_dotdesktoppath = pnd_expand_tilde ( strdup ( menu_dotdesktoppath ) ); mkdir ( menu_dotdesktoppath, 0777 ); @@ -598,6 +648,21 @@ void sighup_handler ( int n ) { return; } +void sigint_handler ( int n ) { + + pnd_log ( pndn_rem, "---[ SIGINT received ]---\n" ); + + if ( dbh ) { + pnd_dbusnotify_shutdown ( dbh ); + } + + if ( nh ) { + pnd_notify_shutdown ( nh ); + } + + return; +} + // This very recently was inline code; just slight refactor to functionize it so that it can be // reused in a couple of places. Simple code with simple design quickly became too large for // its simple design; should revisit a lot of these little things.. @@ -611,7 +676,7 @@ void process_discoveries ( pnd_box_handle applist, char *emitdesktoppath, char * // check if icon already exists (from a previous extraction say); if so, we needn't // do it again char existingpath [ FILENAME_MAX ]; - sprintf ( existingpath, "%s/%s.png", emiticonpath, d -> unique_id ); + sprintf ( existingpath, "%s/%s.png", emiticonpath, d -> unique_id /*, d -> subapp_number */ ); struct stat dirs; if ( stat ( existingpath, &dirs ) == 0 ) { @@ -629,17 +694,37 @@ void process_discoveries ( pnd_box_handle applist, char *emitdesktoppath, char * pnd_log ( pndn_debug, " Icon not already present, so trying to write it! %s\n", existingpath ); + // handle same-path icon override for davec :) + char ovrfile [ PATH_MAX ]; + char *fixpxml; + sprintf ( ovrfile, "%s/%s", d -> object_path, d -> object_filename ); + fixpxml = strcasestr ( ovrfile, PND_PACKAGE_FILEEXT ); + if ( fixpxml ) { + strcpy ( fixpxml, ".png" ); + fixpxml = NULL; + struct stat statbuf; + if ( stat ( ovrfile, &statbuf ) == 0 ) { + d -> icon = strdup ( ovrfile ); + fixpxml = ovrfile; // !NULL will be the trigger to skip emittinf desktop from .pnd + } // stat + } // ovr? + // attempt to create icon files; if successful, alter the disco struct to contain new // path, otherwise leave it alone (since it could be a generic icon reference..) - if ( pnd_emit_icon ( emiticonpath, d ) ) { - // success; fix up icon path to new one.. - if ( d -> icon ) { - free ( d -> icon ); + if ( fixpxml == NULL ) { + // don't have an same-path override icon, so go fetch something from pnd file + + if ( pnd_emit_icon ( emiticonpath, d ) ) { + // success; fix up icon path to new one.. + if ( d -> icon ) { + free ( d -> icon ); + } + d -> icon = strdup ( existingpath ); + } else { + pnd_log ( pndn_debug, " WARN: Couldn't write out icon %s\n", existingpath ); } - d -> icon = strdup ( existingpath ); - } else { - pnd_log ( pndn_debug, " WARN: Couldn't write out icon %s\n", existingpath ); - } + + } // got ovr icon already? } // icon already exists? @@ -655,6 +740,15 @@ void process_discoveries ( pnd_box_handle applist, char *emitdesktoppath, char * pnd_log ( pndn_rem, "ERROR: Error creating .desktop file for app: %s\n", pnd_box_get_key ( d ) ); } + // info .desktop + if ( g_info_p && info_dotdesktoppath ) { + if ( pnd_emit_dotinfo ( info_dotdesktoppath, pndrun, d ) ) { + // nada + } else { + pnd_log ( pndn_rem, "ERROR: Error creating info .desktop file for app: %s\n", pnd_box_get_key ( d ) ); + } + } + // does this object request any mkdir's? if ( d -> mkdir_sp ) {