pnd_run.sh: restore fb0 too
[pandora-libraries.git] / apps / pndnotifyd.c
index a883cd6..984371b 100644 (file)
@@ -28,6 +28,7 @@
 #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..
@@ -72,6 +73,7 @@ unsigned char g_info_p = 0; // spit out info .desktops
 
 // constants
 #define PNDNOTIFYD_LOGLEVEL "pndnotifyd.loglevel"
+#define PNDLOCKNAME "pndnotifyd-disco.lock"
 
 // decl's
 void consume_configuration ( void );
@@ -196,7 +198,7 @@ int main ( int argc, char *argv[] ) {
 
     // umask
     umask ( 022 ); // emitted files can be rwxr-xr-x
-    
+
   } // set up daemon
 
   // wait for a user to be logged in - we should probably get hupped when a user logs in, so we can handle
@@ -314,6 +316,13 @@ int main ( int argc, char *argv[] ) {
       /* run the discovery
        */
 
+      // do some 'locking'
+      pnd_log ( pndn_rem, "creating lockfile %s", PNDLOCKNAME );
+      if ( ! pnd_lock ( PNDLOCKNAME ) ) {
+       // problem .. well, too bad, we need to do this .. proceed!
+      }
+
+      // scan..
       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" );
@@ -326,6 +335,10 @@ int main ( int argc, char *argv[] ) {
        }
       }
 
+      // unlock
+      pnd_log ( pndn_rem, "clearing lockfile %s", PNDLOCKNAME );
+      pnd_unlock ( PNDLOCKNAME );
+
       // if we've got a hup script located, lets invoke it
       if ( pndhup ) {
        pnd_log ( pndn_rem, "Invoking hup script '%s'.\n", pndhup );
@@ -693,17 +706,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?