Added support for icon emiting from appdir's as well
authorskeezix <skeezix@flotsam-vm.(none)>
Tue, 24 Feb 2009 04:22:46 +0000 (23:22 -0500)
committerskeezix <skeezix@flotsam-vm.(none)>
Tue, 24 Feb 2009 04:22:46 +0000 (23:22 -0500)
Added icon dump support better to discotest, and to pndnotifyd
icons are dumped out into dotdesktop dir with unique-id, same as .desktop file
in discotest and pndnotifyd case, the disco struct is edited to refer to the new icon location (on success of course)
As such .desktop now shows new icon, woowoo
NOTE: The icon file is not removed when the .desktop is .. leave icon behind for cache sake?

apps/pndnotifyd.c
lib/pnd_discovery.c
test/discotest.c
testdata/apps/sampleapp2/PXML.xml
testdata/apps/sampleapp3/PXML.xml
testdata/apps/sampleapp3/zeldaicon.png [new file with mode: 0644]
testdata/pndsample/x86_echo.pnd
testdata/pndsample/x86_ls.pnd

index 3cc1686..665c4f6 100644 (file)
@@ -251,6 +251,16 @@ int main ( int argc, char *argv[] ) {
            printf ( "Found app: %s\n", pnd_box_get_key ( d ) );
          }
 
+         // 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 ( dotdesktoppath, d ) ) {
+           // success; fix up icon path to new one..
+           free ( d -> icon );
+           char buffer [ FILENAME_MAX ];
+           sprintf ( buffer, "%s/%s.png", dotdesktoppath, d -> unique_id );
+           d -> icon = strdup ( buffer );
+         }
+
          // create the .desktop file
          if ( pnd_emit_dotdesktop ( dotdesktoppath, pndrun, d ) ) {
            // add a watch onto the newly created .desktop?
index 137b8bc..6ca6205 100644 (file)
@@ -322,77 +322,75 @@ unsigned char pnd_emit_icon ( char *targetpath, pnd_disco_t *p ) {
   unsigned int bitlen;
   FILE *pnd, *target;
 
-  // prelim
+  // prelim .. if a pnd file, and no offset found, discovery code didn't locate icon.. so bail.
   if ( ( p -> object_type == pnd_object_type_pnd ) &&
        ( ! p -> pnd_icon_pos ) )
   {
     return ( 0 ); // discover code didn't find it, so FAIL
   }
 
-  // filenames
+  // determine filename for target
   sprintf ( buffer, "%s/%s.png", targetpath, p -> unique_id ); // target
 
-  // first.. are we looking through a pnd file or a dir?
+  /* first.. open the source file, by type of application:
+   * are we looking through a pnd file or a dir?
+   */
   if ( p -> object_type == pnd_object_type_directory ) {
-    // if we can find icon, copy it in from directory to destination
-
+    sprintf ( from, "%s/%s", p -> object_path, p -> icon );
   } else if ( p -> object_type == pnd_object_type_pnd ) {
-    // if we can get it from pnd file, copy it into destination
-
-    unsigned int len;
-
-    sprintf ( from, "%s/%s", p -> object_path, p -> object_filename ); // target
+    sprintf ( from, "%s/%s", p -> object_path, p -> object_filename );
+  }
 
-    pnd = fopen ( from, "r" );
+  pnd = fopen ( from, "r" );
 
-    if ( ! pnd ) {
-      return ( 0 );
-    }
+  if ( ! pnd ) {
+    return ( 0 );
+  }
 
-    target = fopen ( buffer, "wb" );
+  unsigned int len;
 
-    if ( ! target ) {
-      fclose ( pnd );
-      return ( 0 );
-    }
+  target = fopen ( buffer, "wb" );
 
-    fseek ( pnd, 0, SEEK_END );
-    len = ftell ( pnd );
-    //fseek ( pnd, 0, SEEK_SET );
+  if ( ! target ) {
+    fclose ( pnd );
+    return ( 0 );
+  }
 
-    fseek ( pnd, p -> pnd_icon_pos, SEEK_SET );
+  fseek ( pnd, 0, SEEK_END );
+  len = ftell ( pnd );
+  //fseek ( pnd, 0, SEEK_SET );
 
-    len -= p -> pnd_icon_pos;
+  fseek ( pnd, p -> pnd_icon_pos, SEEK_SET );
 
-    while ( len ) {
+  len -= p -> pnd_icon_pos;
 
-      if ( len > (8*1024) ) {
-       bitlen = (8*1024);
-      } else {
-       bitlen = len;
-      }
+  while ( len ) {
 
-      if ( fread ( bits, bitlen, 1, pnd ) != 1 ) {
-       fclose ( pnd );
-       fclose ( target );
-       unlink ( buffer );
-       return ( 0 );
-      }
+    if ( len > (8*1024) ) {
+      bitlen = (8*1024);
+    } else {
+      bitlen = len;
+    }
 
-      if ( fwrite ( bits, bitlen, 1, target ) != 1 ) {
-       fclose ( pnd );
-       fclose ( target );
-       unlink ( buffer );
-       return ( 0 );
-      }
+    if ( fread ( bits, bitlen, 1, pnd ) != 1 ) {
+      fclose ( pnd );
+      fclose ( target );
+      unlink ( buffer );
+      return ( 0 );
+    }
 
-      len -= bitlen;
-    } // while
+    if ( fwrite ( bits, bitlen, 1, target ) != 1 ) {
+      fclose ( pnd );
+      fclose ( target );
+      unlink ( buffer );
+      return ( 0 );
+    }
 
-    fclose ( pnd );
-    fclose ( target );
+    len -= bitlen;
+  } // while
 
-  }
+  fclose ( pnd );
+  fclose ( target );
 
   return ( 1 );
 }
index 6254539..0d02104 100644 (file)
@@ -1,6 +1,7 @@
 
 #include <stdio.h> /* for printf, NULL */
 #include <stdlib.h> /* for free */
+#include <string.h> /* for strdup */
 
 #include "pnd_conf.h"
 #include "pnd_container.h"
@@ -146,12 +147,27 @@ int main ( int argc, char *argv[] ) {
        printf ( "  Clockspeed: %s\n", d -> clockspeed );
       }
 
-      if ( do_dotdesktop ) {
-       pnd_emit_dotdesktop ( "./testdata/dotdesktop", pndrun, d );
+      if ( do_icon ) {
+       if ( pnd_emit_icon ( "./testdata/dotdesktop", d ) ) {
+         printf ( "  -> icon dump succeeded\n" );
+
+         // fix up icon path to new one..
+         free ( d -> icon );
+         char buffer [ FILENAME_MAX ];
+         sprintf ( buffer, "%s/%s.png", "discotest-temp/", d -> unique_id );
+         d -> icon = strdup ( buffer );
+
+       } else {
+         printf ( "  -> icon dump failed\n" );
+       }
       }
 
-      if ( do_icon ) {
-       pnd_emit_icon ( "./testdata/dotdesktop", d );
+      if ( do_dotdesktop ) {
+       if ( pnd_emit_dotdesktop ( "./testdata/dotdesktop", pndrun, d ) ) {
+         printf ( "  -> dotdesktop dump succeeded\n" );
+       } else {
+         printf ( "  -> dotdesktop dump failed\n" );
+       }
       }
 
       // next!
index f289130..f126e60 100644 (file)
@@ -11,8 +11,6 @@
 
 <standalone>Yes</standalone>
 
-<icon>program.png</icon>
-
 <description>
        <en>This is the [b]English Description[/b] of the file.
             Can use [i]multiple lines[/i] and BBCode.</en>
index 49a9106..a83165f 100644 (file)
@@ -10,7 +10,7 @@
 
 <standalone>Yes</standalone>
 
-<icon>program.png</icon>
+<icon>zeldaicon.png</icon>
 
 <description>
        <en>This is the [b]English Description[/b] of the file.
diff --git a/testdata/apps/sampleapp3/zeldaicon.png b/testdata/apps/sampleapp3/zeldaicon.png
new file mode 100644 (file)
index 0000000..140a393
Binary files /dev/null and b/testdata/apps/sampleapp3/zeldaicon.png differ
index 255db68..ad943f6 100644 (file)
Binary files a/testdata/pndsample/x86_echo.pnd and b/testdata/pndsample/x86_echo.pnd differ
index 4dfaf7d..d412a70 100644 (file)
Binary files a/testdata/pndsample/x86_ls.pnd and b/testdata/pndsample/x86_ls.pnd differ