Added basic icon support
[pandora-libraries.git] / test / discotest.c
index a299e7d..b374f36 100644 (file)
@@ -9,10 +9,35 @@
 #include "pnd_discovery.h"
 #include "pnd_locate.h"
 
-int main ( void) {
+int main ( int argc, char *argv[] ) {
   char *configpath;
   char *appspath;
   char *overridespath;
+  unsigned char i;
+  unsigned char do_exec = 0;
+  unsigned char do_icon = 0;
+  unsigned char do_dotdesktop = 0;
+
+  for ( i = 1; i < argc; i++ ) {
+
+    if ( argv [ i ][ 0 ] == '-' && argv [ i ][ 1 ] == 'e' ) {
+      printf ( "Will attempt a random exec.\n" );
+      do_exec = 1;
+    } else if ( argv [ i ][ 0 ] == '-' && argv [ i ][ 1 ] == 'i' ) {
+      printf ( "Will attempt to extract icons.\n" );
+      do_icon = 1;
+    } else if ( argv [ i ][ 0 ] == '-' && argv [ i ][ 1 ] == 'd' ) {
+      printf ( "Will attempt to extract dotdesktop.\n" );
+      do_dotdesktop = 1;
+    } else {
+      printf ( "%s [-e] [-i] [-d]\n", argv [ 0 ] );
+      printf ( "-e\tOptional. Attempt to exec a random app.\n" );
+      printf ( "-i\tOptional. Attempt to dump icon files from the end of pnd's to /tmp.\n" );
+      printf ( "-d\tOptional. Attempt to dump dotdesktop files from the end of pnd's to /tmp.\n" );
+      exit ( 0 );
+    }
+
+  }
 
   /* attempt to sort out the config file madness
    */
@@ -47,6 +72,36 @@ int main ( void) {
   printf ( "Apps searchpath is '%s'\n", appspath );
   printf ( "Apps overrides searchpath is '%s'\n", overridespath );
 
+  /* find pnd runscript
+   */
+  char *run_searchpath;
+  char *run_script;
+  char *pndrun;
+
+  if ( apph ) {
+    run_searchpath = pnd_conf_get_as_char ( apph, PND_PNDRUN_SEARCHPATH_KEY );
+    run_script = pnd_conf_get_as_char ( apph, PND_PNDRUN_KEY );
+    pndrun = NULL;
+
+    if ( ! run_searchpath ) {
+      run_searchpath = PND_APPS_SEARCHPATH;
+      run_script = PND_PNDRUN_FILENAME;
+    }
+
+  } else {
+    run_searchpath = NULL;
+    run_script = NULL;
+    pndrun = PND_PNDRUN_DEFAULT;
+  }
+
+  if ( ! pndrun ) {
+    pndrun = pnd_locate_filename ( run_searchpath, run_script );
+  }
+
+  if ( run_searchpath ) printf ( "Locating pnd run in %s\n", run_searchpath );
+  if ( run_script ) printf ( "Locating pnd runscript as %s\n", run_script );
+  if ( pndrun ) printf ( "Default pndrun is %s\n", pndrun );
+
   /* attempt to discover apps in the path
    */
   pnd_box_handle applist;
@@ -62,7 +117,7 @@ int main ( void) {
 
       // display the app 'as is'
 
-      printf ( "App: %s\n", pnd_box_get_key ( d ) );
+      printf ( "App: %s (type %u)\n", pnd_box_get_key ( d ), d -> object_type );
 
       printf ( "  Base path: %s\n", d -> path_to_object );
 
@@ -72,6 +127,9 @@ int main ( void) {
       if ( d -> icon ) {
        printf ( "  Icon: %s\n", d -> icon );
       }
+      if ( d -> pnd_icon_pos ) {
+       printf ( "  Icon in pnd might be at: %u\n", d -> pnd_icon_pos );
+      }
       if ( d -> unique_id ) {
        printf ( "  Unique ID: %s\n", d -> unique_id );
       }
@@ -88,7 +146,13 @@ int main ( void) {
        printf ( "  Clockspeed: %s\n", d -> clockspeed );
       }
 
-      //pnd_emit_dotdesktop ( "/tmp", d );
+      if ( do_dotdesktop ) {
+       pnd_emit_dotdesktop ( "/tmp", pndrun, d );
+      }
+
+      if ( do_icon ) {
+       pnd_emit_icon ( "/tmp", d );
+      }
 
       // next!
       d = pnd_box_get_next ( d );
@@ -100,49 +164,25 @@ int main ( void) {
   }
 
   // lets toy with executing an application
-  char *run_searchpath;
-  char *run_script;
-  char *pndrun;
-
-  if ( apph ) {
-    run_searchpath = pnd_conf_get_as_char ( apph, PND_PNDRUN_SEARCHPATH_KEY );
-    run_script = pnd_conf_get_as_char ( apph, PND_PNDRUN_KEY );
-    pndrun = NULL;
-
-    if ( ! run_searchpath ) {
-      run_searchpath = PND_APPS_SEARCHPATH;
-      run_script = PND_PNDRUN_FILENAME;
-    }
+  if ( do_exec ) {
 
-  } else {
-    run_searchpath = NULL;
-    run_script = NULL;
-    pndrun = PND_PNDRUN_DEFAULT;
-  }
-
-  if ( ! pndrun ) {
-    pndrun = pnd_locate_filename ( run_searchpath, run_script );
-  }
-
-  if ( run_searchpath ) printf ( "Locating pnd run in %s\n", run_searchpath );
-  if ( run_script ) printf ( "Locating pnd runscript as %s\n", run_script );
-  if ( pndrun ) printf ( "Default pndrun is %s\n", pndrun );
-
-  if ( ! pndrun ) {
-    printf ( "*** Couldn't locate a pnd runscript.\n" );
-  } else {
-    printf ( "Found a pnd runscript of %s\n", pndrun );
-
-    pnd_disco_t *d = pnd_box_get_head ( applist );
-    if ( d ) {
-      d = pnd_box_get_next ( d );
+    if ( ! pndrun ) {
+      printf ( "*** Couldn't locate a pnd runscript.\n" );
+    } else {
+      printf ( "Found a pnd runscript of %s\n", pndrun );
 
+      pnd_disco_t *d = pnd_box_get_head ( applist );
       if ( d ) {
-       pnd_apps_exec ( pndrun, d -> path_to_object, d -> unique_id, d -> exec, d -> startdir, atoi ( d -> clockspeed ) );
+       d = pnd_box_get_next ( d );
+
+       if ( d ) {
+         pnd_apps_exec ( pndrun, d -> path_to_object, d -> unique_id, d -> exec, d -> startdir, atoi ( d -> clockspeed ) );
+       }
       }
+
     }
 
-  }
+  } // do_exec?
 
   // exeunt with alarums
   free ( configpath );