From: skeezix Date: Tue, 24 Feb 2009 04:22:46 +0000 (-0500) Subject: Added support for icon emiting from appdir's as well X-Git-Tag: Release-2010-05/1~205 X-Git-Url: http://git.openpandora.org/cgi-bin/gitweb.cgi?p=pandora-libraries.git;a=commitdiff_plain;h=31b39c1423e7e4a3ecdd4b236c23239a0989f4fc Added support for icon emiting from appdir's as well 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? --- diff --git a/apps/pndnotifyd.c b/apps/pndnotifyd.c index 3cc1686..665c4f6 100644 --- a/apps/pndnotifyd.c +++ b/apps/pndnotifyd.c @@ -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? diff --git a/lib/pnd_discovery.c b/lib/pnd_discovery.c index 137b8bc..6ca6205 100644 --- a/lib/pnd_discovery.c +++ b/lib/pnd_discovery.c @@ -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 ); } diff --git a/test/discotest.c b/test/discotest.c index 6254539..0d02104 100644 --- a/test/discotest.c +++ b/test/discotest.c @@ -1,6 +1,7 @@ #include /* for printf, NULL */ #include /* for free */ +#include /* 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! diff --git a/testdata/apps/sampleapp2/PXML.xml b/testdata/apps/sampleapp2/PXML.xml index f289130..f126e60 100644 --- a/testdata/apps/sampleapp2/PXML.xml +++ b/testdata/apps/sampleapp2/PXML.xml @@ -11,8 +11,6 @@ Yes -program.png - This is the [b]English Description[/b] of the file. Can use [i]multiple lines[/i] and BBCode. diff --git a/testdata/apps/sampleapp3/PXML.xml b/testdata/apps/sampleapp3/PXML.xml index 49a9106..a83165f 100644 --- a/testdata/apps/sampleapp3/PXML.xml +++ b/testdata/apps/sampleapp3/PXML.xml @@ -10,7 +10,7 @@ Yes -program.png +zeldaicon.png 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 index 0000000..140a393 Binary files /dev/null and b/testdata/apps/sampleapp3/zeldaicon.png differ diff --git a/testdata/pndsample/x86_echo.pnd b/testdata/pndsample/x86_echo.pnd index 255db68..ad943f6 100644 Binary files a/testdata/pndsample/x86_echo.pnd and b/testdata/pndsample/x86_echo.pnd differ diff --git a/testdata/pndsample/x86_ls.pnd b/testdata/pndsample/x86_ls.pnd index 4dfaf7d..d412a70 100644 Binary files a/testdata/pndsample/x86_ls.pnd and b/testdata/pndsample/x86_ls.pnd differ