2 #include <stdio.h> /* for FILE etc */
3 #include <stdlib.h> /* for malloc */
4 #define __USE_GNU /* for strcasestr */
6 #include <sys/types.h> /* for stat(2) */
11 #include "../lib/pnd_pathiter.h"
12 #include "pnd_logger.h"
14 #include "pnd_container.h"
16 #include "pnd_discovery.h"
17 #include "pnd_desktop.h"
22 mm_app_t *apps_fullscan ( char *searchpath ) {
23 mm_app_t *apphead = NULL;
28 pnd_log ( pndn_debug, "Scanning path '%s'\n", buffer );
30 DIR *d = opendir ( buffer );
33 char fullpath [ PATH_MAX ];
37 while ( ( de = readdir ( d ) ) ) {
38 pnd_log ( pndn_debug, " Found file: '%s'\n", de -> d_name );
41 if ( ( c = strrchr ( de -> d_name, '.' ) ) &&
42 ( strcasecmp ( c, ".desktop" ) == 0 ) )
44 pnd_log ( pndn_debug, " ..filename suggests a .desktop\n" );
46 sprintf ( fullpath, "%s/%s", buffer, de -> d_name );
48 n = apps_fetch_from_dotdesktop ( fullpath );
51 // got an app, prepend to the applist
52 pnd_log ( pndn_rem, "Found application '%s': '%s'\n", n -> dispname, n -> exec );
55 apphead -> next = NULL;
61 pnd_log ( pndn_debug, " No application found.\n" );
62 } // if got an app back
65 pnd_log ( pndn_debug, " ..filename suggests ignore\n" );
72 pnd_log ( pndn_warning, "WARN: Couldn't open directory '%s', skipping\n" );
82 mm_app_t *apps_fetch_from_dotdesktop ( char *path ) {
84 FILE *f = fopen ( path, "r" );
86 mm_app_t *p = (mm_app_t *) malloc ( sizeof(mm_app_t) );
101 bzero ( p, sizeof(mm_app_t) );
103 unsigned char apptype = 0;
104 unsigned char pndcreated = 0;
106 while ( fgets ( buffer, 1000, f ) ) {
110 if ( ( c = strchr ( buffer, '\n' ) ) ) {
111 *c = '\0'; // truncate trailing newline
114 //pnd_log ( pndn_debug, ".desktop line: '%s'\n", buffer );
116 if ( strcmp ( buffer, PND_DOTDESKTOP_SOURCE ) == 0 ) {
120 if ( ( equals = strchr ( buffer, '=' ) ) ) {
124 if ( strcasecmp ( buffer, "type" ) == 0 &&
125 strcasecmp ( equals + 1, "application" ) == 0 )
130 if ( strcasecmp ( buffer, "name" ) == 0 ) {
131 p -> dispname = strdup ( equals + 1 );
134 if ( strcasecmp ( buffer, "exec" ) == 0 ) {
135 p -> exec = strdup ( equals + 1 );
138 if ( strcasecmp ( buffer, "icon" ) == 0 ) {
139 p -> iconpath = strdup ( equals + 1 );
147 pnd_log ( pndn_debug, ".desktop is not an application; ignoring.\n" );
149 return ( NULL ); // not an application
152 if ( ! pndcreated ) {
153 pnd_log ( pndn_debug, ".desktop is not from libpnd; ignoring.\n" );
155 return ( NULL ); // not created by libpnd