Added base path to disco struct
[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       printf ( "  Base path: %s\n", d -> path_to_object );
67
68       if ( d -> title_en ) {
69         printf ( "  Name: %s\n", d -> title_en );
70       }
71       if ( d -> icon ) {
72         printf ( "  Icon: %s\n", d -> icon );
73       }
74       if ( d -> unique_id ) {
75         printf ( "  Unique ID: %s\n", d -> unique_id );
76       }
77       if ( d -> main_category ) {
78         printf ( "  Category: %s\n", d -> main_category );
79       }
80       if ( d -> exec ) {
81         printf ( "  Executable: %s\n", d -> exec );
82       }
83       if ( d -> startdir ) {
84         printf ( "  Start dir: %s\n", d -> startdir );
85       }
86       if ( d -> clockspeed ) {
87         printf ( "  Clockspeed: %s\n", d -> clockspeed );
88       }
89
90       //pnd_emit_dotdesktop ( "/tmp", d );
91
92       // next!
93       d = pnd_box_get_next ( d );
94
95     } // while applist
96
97   } else {
98     printf ( "No applications found in search path\n" );
99   }
100
101   // exeunt with alarums
102   free ( configpath );
103   if ( apph ) {
104     pnd_box_delete ( apph );
105   }
106
107   return ( 0 );
108 }