preliminary support for ovr edits within mmenu
[pandora-libraries.git] / minimenu / mmcache.c
index 4f68f36..3ebb104 100644 (file)
@@ -5,6 +5,7 @@
 #include <limits.h> /* for PATH_MAX */
 #include <sys/types.h>
 #include <sys/stat.h>
+#include <time.h> /* for time() */
 
 #define __USE_GNU /* for strcasestr */
 #include <string.h> /* for making ftw.h happy */
@@ -42,6 +43,7 @@
 
 extern pnd_conf_handle g_conf;
 extern unsigned char g_pvwcache;
+extern pnd_conf_handle g_desktopconf;
 
 mm_cache_t *g_icon_cache = NULL;
 mm_cache_t *g_preview_cache = NULL;
@@ -224,7 +226,7 @@ unsigned char cache_icon ( pnd_disco_t *app, unsigned char maxwidth, unsigned ch
   unsigned char *iconbuf = NULL;
   unsigned int buflen = 0;
 
-  // same-path override?
+  // same-path icon override?
   char ovrfile [ PATH_MAX ];
   char *fixpxml;
   sprintf ( ovrfile, "%s/%s", app -> object_path, app -> object_filename );
@@ -248,6 +250,37 @@ unsigned char cache_icon ( pnd_disco_t *app, unsigned char maxwidth, unsigned ch
     } // stat
   } // ovr?
 
+  // perhaps pndnotifyd has dropped a copy of the icon into /tmp?
+#if 1
+  {
+    static char *iconpath = NULL;
+
+    if ( ! iconpath ) {
+      iconpath = pnd_conf_get_as_char ( g_desktopconf, "desktop.iconpath" );
+    }
+
+    sprintf ( ovrfile, "%s/%s.png", iconpath, app -> unique_id );
+
+    // making sure the file is at least a few seconds old, to help avoid race condition
+    struct stat statbuf;
+    if ( stat ( ovrfile, &statbuf ) == 0 && time ( NULL ) - statbuf.st_mtime > 5 ) { // race with pndnotifyd
+      buflen = statbuf.st_size;
+      if ( ( iconbuf = malloc ( statbuf.st_size ) ) ) {
+       int fd = open ( ovrfile, O_RDONLY );
+       if ( fd >= 0 ) {
+         if ( read ( fd, iconbuf, statbuf.st_size ) != statbuf.st_size ) {
+           free ( iconbuf );
+           close ( fd );
+           return ( 0 );
+         }
+         close ( fd );
+       } // open
+      } // malloc
+    } // stat
+
+  }
+#endif
+
   // if this is a real pnd file (dir-app or pnd-file-app), then try to pull icon from there
   if ( ! iconbuf ) {