Initial commit of libpnd 0.0.5 so we cna restart with GIT
[pandora-libraries.git] / test / discotest.c
1
2 #include <stdio.h> /* for printf, NULL */
3 #include <stdlib.h> /* for free */
4
5 #include "pnd_conf.h"
6 #include "pnd_container.h"
7 #include "pnd_apps.h"
8 #include "pnd_pxml.h"
9 #include "pnd_discovery.h"
10
11 int main ( void) {
12   char *configpath;
13   char *appspath;
14   char *overridespath;
15
16   /* attempt to sort out the config file madness
17    */
18
19   // attempt to fetch a sensible default searchpath for configs
20   configpath = pnd_conf_query_searchpath();
21
22   // attempt to fetch the apps config to pick up a searchpath
23   pnd_conf_handle apph;
24
25   apph = pnd_conf_fetch_by_id ( pnd_conf_apps, configpath );
26
27   if ( apph ) {
28     appspath = pnd_conf_get_as_char ( apph, PND_APPS_KEY );
29
30     if ( ! appspath ) {
31       appspath = PND_APPS_SEARCHPATH;
32     }
33
34     overridespath = pnd_conf_get_as_char ( apph, PND_PXML_OVERRIDE_KEY );
35
36     if ( ! overridespath ) {
37       overridespath = PND_PXML_OVERRIDE_SEARCHPATH;
38     }
39
40   } else {
41     // couldn't find a useful app search path so use the default
42     appspath = PND_APPS_SEARCHPATH;
43     overridespath = PND_PXML_OVERRIDE_SEARCHPATH;
44   }
45
46   printf ( "Apps searchpath is '%s'\n", appspath );
47   printf ( "Apps overrides searchpath is '%s'\n", overridespath );
48
49   /* attempt to discover apps in the path
50    */
51   pnd_box_handle applist;
52
53   applist = pnd_disco_search ( appspath, overridespath );
54
55   // list the found apps (if any)
56
57   if ( applist ) {
58     pnd_disco_t *d = pnd_box_get_head ( applist );
59
60     while ( d ) {
61
62       // display the app 'as is'
63
64       printf ( "App: %s\n", pnd_box_get_key ( d ) );
65
66       if ( d -> title_en ) {
67         printf ( "  Name: %s\n", d -> title_en );
68       }
69       if ( d -> icon ) {
70         printf ( "  Icon: %s\n", d -> icon );
71       }
72       if ( d -> unique_id ) {
73         printf ( "  Unique ID: %s\n", d -> unique_id );
74       }
75       if ( d -> main_category ) {
76         printf ( "  Category: %s\n", d -> main_category );
77       }
78       if ( d -> exec ) {
79         printf ( "  Executable: %s\n", d -> exec );
80       }
81       if ( d -> clockspeed ) {
82         printf ( "  Clockspeed: %s\n", d -> clockspeed );
83       }
84
85       // next!
86       d = pnd_box_get_next ( d );
87
88     } // while applist
89
90   } else {
91     printf ( "No applications found in search path\n" );
92   }
93
94   // exeunt with alarums
95   free ( configpath );
96   if ( apph ) {
97     pnd_box_delete ( apph );
98   }
99
100   return ( 0 );
101 }