]> git.openpandora.org Git - pandora-libraries.git/commitdiff
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 3cc1686ac8a5b6f1e91c1473a07a66d984800604..665c4f6722040271ec1c8a7ff5d64e5e2b617b19 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 137b8bc63201bd9979be8d32ddeb33a08356b02d..6ca62055fa00ae38f157cd912186f5ed18a27832 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 6254539134f9b606d90609e8e175c6572c193267..0d021040972ae196f8412c4d72738d729d70cee8 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 f289130b526926f33bfdba147297f5d50b2536f8..f126e60b29233e759a46141b1efa35c951a5afc4 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 49a910659d4919dd60007f71e79dc8433132432e..a83165f79969709c50164e17039d8a4753b7773f 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 255db686865655e90033246b9c1e92954de9cacb..ad943f659161980a8df94d450eb691e4c32e3241 100644 (file)
Binary files a/testdata/pndsample/x86_echo.pnd and b/testdata/pndsample/x86_echo.pnd differ
index 4dfaf7d08950ae37f1cfdfb9631a322cd903dc57..d412a70155b13b583ccee9631f27cab838b5719b 100644 (file)
Binary files a/testdata/pndsample/x86_ls.pnd and b/testdata/pndsample/x86_ls.pnd differ