// - clockspeed
// - categories
+ char pndpath [ 1024 ];
+ bzero ( pndpath, 1024 );
+
+ // filter on filename?
+ if ( flags & PND_DOTDESKTOP_LIBPND_ONLY ) {
+ // too bad we didn't put some libpnd token at the front of the filename or something
+ // hell, we should cleanse unique-id to ensure its not full of special chars like '*' and '..'.. eep!
+ if ( strrchr ( ddpath, '#' ) == NULL ) { // but if requiring libpnd, we can at least check for #subapp-number
+ return ( NULL );
+ }
+ }
+
+ if ( strstr ( ddpath, ".desktop" ) == NULL ) {
+ return ( NULL );
+ }
+
// determine file length
struct stat statbuf;
if ( strncmp ( dd, "Name=", 5 ) == 0 ) {
p -> title_en = strdup ( dd + 5 );
+ } else if ( strncmp ( dd, "Name[en]=", 9 ) == 0 ) {
+ p -> title_en = strdup ( dd + 9 );
} else if ( strncmp ( dd, "Icon=", 5 ) == 0 ) {
p -> icon = strdup ( dd + 5 );
} else if ( strcmp ( dd, PND_DOTDESKTOP_SOURCE ) == 0 ) {
p -> unique_id = strdup ( dd + 14 );
} else if ( strncmp ( dd, "Comment=", 8 ) == 0 ) {
p -> desc_en = strdup ( dd + 8 );
+ } else if ( strncmp ( dd, "Comment[en]=", 12 ) == 0 ) {
+ p -> desc_en = strdup ( dd + 12 );
} else if ( strncmp ( dd, "Exec=", 5 ) == 0 ) {
char *e = strstr ( dd, " -e " );
+
if ( e ) {
- e += 5;
+ // probably libpnd app
- char *space = strchr ( e, ' ' );
- p -> exec = strndup ( e, space - e - 1 );
- }
+ if ( e ) {
+ e += 5;
- char *b = strstr ( dd, " -b " );
- if ( b ) {
- b += 5;
- char *space = strchr ( b, '\0' );
- p -> appdata_dirname = strndup ( b, space - b - 1 );
+ char *space = strchr ( e, ' ' );
+ p -> exec = strndup ( e, space - e - 1 );
+ }
+
+ char *b = strstr ( dd, " -b " );
+ if ( b ) {
+ b += 5;
+ char *space = strchr ( b, '\0' );
+ p -> appdata_dirname = strndup ( b, space - b - 1 );
+ }
+
+ char *p = strstr ( dd, " -p " );
+ if ( p ) {
+ p += 5;
+ char *space = strchr ( p, ' ' );
+ strncpy ( pndpath, p, space - p - 1 );
+ }
+
+ } else {
+ // probably not libpnd app
+ p -> exec = strdup ( dd + 5 );
}
} else if ( strncmp ( dd, "Categories=", 11 ) == 0 ) {
// filter
if ( ! libpnd_origin ) {
- p -> object_flags |= PND_DISCO_CUSTOM1; // so caller can do something if it wishes
// convenience flag
if ( flags & PND_DOTDESKTOP_LIBPND_ONLY ) {
return ( NULL );
}
+ } else {
+ p -> object_flags |= PND_DISCO_CUSTOM1; // so caller can do something if it wishes
+ }
+
+ // filter on content
+ if ( ( ! p -> title_en ) ||
+ ( ! p -> exec )
+ )
+ {
+ pnd_disco_destroy ( p );
+ free ( p );
+ return ( NULL );
+ }
+
+ if ( ! p -> unique_id ) {
+ if ( flags & PND_DOTDESKTOP_LIBPND_ONLY ) {
+ pnd_disco_destroy ( p );
+ free ( p );
+ return ( NULL );
+ } else {
+ char hack [ 100 ];
+ snprintf ( hack, 100, "inode-%lu", statbuf.st_ino );
+ p -> unique_id = strdup ( hack );
+ }
}
// additional
p -> object_type = pnd_object_type_pnd;
- char *slash = strrchr ( ddpath, '/' );
+
+ char *source;
+ if ( pndpath [ 0 ] ) {
+ source = pndpath;
+ } else {
+ source = ddpath;
+ }
+
+ char *slash = strrchr ( source, '/' );
if ( slash ) {
- p -> object_path = strndup ( ddpath, slash - ddpath );
+ p -> object_path = strndup ( source, slash - source );
p -> object_filename = strdup ( slash + 1 );
} else {
p -> object_path = "./";
- p -> object_filename = strdup ( ddpath );
+ p -> object_filename = strdup ( source );
}
+ fprintf ( stderr, "object %s /// src %s /// %s /// %s\n", ddpath, source, p -> object_path, p -> object_filename );
+
// return disco-t
return ( p );
}
#include "pnd_notify.h"
#include "pnd_dbusnotify.h"
#include "pnd_apps.h"
+#include "pnd_desktop.h"
#include "mmenu.h"
#include "mmwrapcmd.h"
g_active_apps = 0;
pnd_box_handle merge_apps = 0;
- // desktop apps?
- if ( pnd_conf_get_as_int_d ( g_conf, "minimenu.desktop_apps", 1 ) ) {
- pnd_log ( pndn_debug, "Looking for pnd applications here: %s\n",
- pnd_conf_get_as_char ( g_desktopconf, "desktop.searchpath" ) );
- g_active_apps = pnd_disco_search ( pnd_conf_get_as_char ( g_desktopconf, "desktop.searchpath" ), NULL );
- }
+ // boy I wish I built a plugin system here
+ //
- // menu apps?
- if ( pnd_conf_get_as_int_d ( g_conf, "minimenu.menu_apps", 1 ) ) {
- pnd_log ( pndn_debug, "Looking for pnd applications here: %s\n",
- pnd_conf_get_as_char ( g_desktopconf, "menu.searchpath" ) );
- merge_apps = pnd_disco_search ( pnd_conf_get_as_char ( g_desktopconf, "menu.searchpath" ), NULL );
- }
+ // perform application discovery for pnd-files?
+ //
+ if ( pnd_conf_get_as_int_d ( g_conf, "minimenu.disco_pnds", 1 ) ) {
- // merge lists
- if ( merge_apps ) {
- if ( g_active_apps ) {
- // the key from pnd_disco_search() is the _path_, so easy to look for duplicates
- // this is pretty inefficient, being linked lists; perhaps should switch to hash tables when
- // we expect thousands of apps.. or at least an index or something.
- void *a = pnd_box_get_head ( merge_apps );
- void *nexta = NULL;
- while ( a ) {
- nexta = pnd_box_get_next ( a );
-
- // if the key for the node is also found in active apps, toss out the merging one
- if ( pnd_box_find_by_key ( g_active_apps, pnd_box_get_key ( a ) ) ) {
- //fprintf ( stderr, "Merging app id '%s' is duplicate; discarding it.\n", pnd_box_get_key ( a ) );
- pnd_box_delete_node ( merge_apps, a );
+ // desktop apps?
+ if ( pnd_conf_get_as_int_d ( g_conf, "minimenu.desktop_apps", 1 ) ) {
+ pnd_log ( pndn_debug, "Looking for pnd applications here: %s\n",
+ pnd_conf_get_as_char ( g_desktopconf, "desktop.searchpath" ) );
+ g_active_apps = pnd_disco_search ( pnd_conf_get_as_char ( g_desktopconf, "desktop.searchpath" ), NULL );
+ }
+
+ // menu apps?
+ if ( pnd_conf_get_as_int_d ( g_conf, "minimenu.menu_apps", 1 ) ) {
+ pnd_log ( pndn_debug, "Looking for pnd applications here: %s\n",
+ pnd_conf_get_as_char ( g_desktopconf, "menu.searchpath" ) );
+ merge_apps = pnd_disco_search ( pnd_conf_get_as_char ( g_desktopconf, "menu.searchpath" ), NULL );
+ }
+
+ // merge lists
+ if ( merge_apps ) {
+ if ( g_active_apps ) {
+ // the key from pnd_disco_search() is the _path_, so easy to look for duplicates
+ // this is pretty inefficient, being linked lists; perhaps should switch to hash tables when
+ // we expect thousands of apps.. or at least an index or something.
+ void *a = pnd_box_get_head ( merge_apps );
+ void *nexta = NULL;
+ while ( a ) {
+ nexta = pnd_box_get_next ( a );
+
+ // if the key for the node is also found in active apps, toss out the merging one
+ if ( pnd_box_find_by_key ( g_active_apps, pnd_box_get_key ( a ) ) ) {
+ //fprintf ( stderr, "Merging app id '%s' is duplicate; discarding it.\n", pnd_box_get_key ( a ) );
+ pnd_box_delete_node ( merge_apps, a );
+ }
+
+ a = nexta;
}
- a = nexta;
+ // got menu apps, and got desktop apps, merge
+ pnd_box_append ( g_active_apps, merge_apps );
+ } else {
+ // got menu apps, had no desktop apps, so just assign
+ g_active_apps = merge_apps;
}
-
- // got menu apps, and got desktop apps, merge
- pnd_box_append ( g_active_apps, merge_apps );
- } else {
- // got menu apps, had no desktop apps, so just assign
- g_active_apps = merge_apps;
}
- }
- // aux apps?
- char *aux_apps = NULL;
- merge_apps = 0;
- aux_apps = pnd_conf_get_as_char ( g_conf, "minimenu.aux_searchpath" );
- if ( aux_apps && aux_apps [ 0 ] ) {
- pnd_log ( pndn_debug, "Looking for pnd applications here: %s\n", aux_apps );
- merge_apps = pnd_disco_search ( aux_apps, NULL );
- }
+ // aux apps?
+ char *aux_apps = NULL;
+ merge_apps = 0;
+ aux_apps = pnd_conf_get_as_char ( g_conf, "minimenu.aux_searchpath" );
+ if ( aux_apps && aux_apps [ 0 ] ) {
+ pnd_log ( pndn_debug, "Looking for pnd applications here: %s\n", aux_apps );
+ merge_apps = pnd_disco_search ( aux_apps, NULL );
+ }
- // merge aux apps
- if ( merge_apps ) {
- if ( g_active_apps ) {
-
- // LAME: snipped from above; should just catenate the 3 sets of searchpaths into a
- // master searchpath, possibly removing duplicate paths _then_, and keep all this much
- // more efficient
-
- // the key from pnd_disco_search() is the _path_, so easy to look for duplicates
- // this is pretty inefficient, being linked lists; perhaps should switch to hash tables when
- // we expect thousands of apps.. or at least an index or something.
- void *a = pnd_box_get_head ( merge_apps );
- void *nexta = NULL;
- while ( a ) {
- nexta = pnd_box_get_next ( a );
-
- // if the key for the node is also found in active apps, toss out the merging one
- if ( pnd_box_find_by_key ( g_active_apps, pnd_box_get_key ( a ) ) ) {
- fprintf ( stderr, "Merging app id '%s' is duplicate; discarding it.\n", pnd_box_get_key ( a ) );
- pnd_box_delete_node ( merge_apps, a );
+ // merge aux apps
+ if ( merge_apps ) {
+ if ( g_active_apps ) {
+
+ // LAME: snipped from above; should just catenate the 3 sets of searchpaths into a
+ // master searchpath, possibly removing duplicate paths _then_, and keep all this much
+ // more efficient
+
+ // the key from pnd_disco_search() is the _path_, so easy to look for duplicates
+ // this is pretty inefficient, being linked lists; perhaps should switch to hash tables when
+ // we expect thousands of apps.. or at least an index or something.
+ void *a = pnd_box_get_head ( merge_apps );
+ void *nexta = NULL;
+ while ( a ) {
+ nexta = pnd_box_get_next ( a );
+
+ // if the key for the node is also found in active apps, toss out the merging one
+ if ( pnd_box_find_by_key ( g_active_apps, pnd_box_get_key ( a ) ) ) {
+ fprintf ( stderr, "Merging app id '%s' is duplicate; discarding it.\n", pnd_box_get_key ( a ) );
+ pnd_box_delete_node ( merge_apps, a );
+ }
+
+ a = nexta;
}
- a = nexta;
+ pnd_box_append ( g_active_apps, merge_apps );
+ } else {
+ g_active_apps = merge_apps;
}
+ }
- pnd_box_append ( g_active_apps, merge_apps );
- } else {
- g_active_apps = merge_apps;
+ } // app discovery on pnd-files?
+
+ // perform app discovery on .desktop files?
+ //
+ if ( pnd_conf_get_as_int_d ( g_conf, "minimenu.disco_dotdesktop", 0 ) ) {
+ char *chunks[5] = {
+ pnd_conf_get_as_char ( g_desktopconf, "desktop.dotdesktoppath" ),
+ pnd_conf_get_as_char ( g_desktopconf, "menu.dotdesktoppath" ),
+ //"/usr/share/applications",
+ NULL
+ };
+ char ddpath [ 1024 ];
+ unsigned int flags = PND_DOTDESKTOP_LIBPND_ONLY;
+
+ if ( pnd_conf_get_as_int_d ( g_conf, "minimenu.disco_dotdesktop_all", 0 ) ) {
+ flags = 0; // get all
}
- }
+
+ // app box?
+ if ( ! g_active_apps ) {
+ g_active_apps = pnd_box_new ( "discovery-dotdesktop" );
+ }
+
+ // for each searchpath..
+ unsigned char i;
+ for ( i = 0; i < 5; i++ ) {
+
+ if ( ! chunks [ i ] ) {
+ break;
+ }
+
+ DIR *d = opendir ( chunks [ i ] );
+
+ if ( d ) {
+ struct dirent *de = readdir ( d );
+
+ // for each filename found
+ while ( de ) {
+
+ if ( strcmp ( de -> d_name, "." ) == 0 ) {
+ // irrelevent
+ } else if ( strcmp ( de -> d_name, ".." ) == 0 ) {
+ // irrelevent
+ } else {
+ snprintf ( ddpath, 1024, "%s/%s", chunks [ i ], de -> d_name );
+ pnd_disco_t *p = pnd_parse_dotdesktop ( ddpath, flags );
+ if ( p ) {
+ pnd_disco_t *ai = pnd_box_allocinsert ( g_active_apps, ddpath, sizeof(pnd_disco_t) );
+ memmove ( ai, p, sizeof(pnd_disco_t) );
+ }
+ }
+
+ // next!
+ de = readdir ( d );
+ }
+
+ closedir ( d );
+
+ } // for each dir
+
+ } // for each searchpath
+
+ } // app discovery in .desktops
// do it
g_active_appcount = pnd_box_get_size ( g_active_apps );
// cache the icon, unless deferred
if ( pnd_conf_get_as_int_d ( g_conf, "minimenu.load_icons_later", 0 ) == 0 ) {
- if ( iter -> pnd_icon_pos &&
- ! cache_icon ( iter, maxwidth, maxheight ) )
+
+ // if app was from a pnd and has an icon-pos (we've already found where it is in the binary),
+ // OR its a .desktop and we've got a path
+ // THEN go try to cache/load the icon
+ if ( ( iter -> pnd_icon_pos ) ||
+ ( iter -> icon && iter -> object_flags & PND_DISCO_CUSTOM1 )
+ )
{
- pnd_log ( pndn_warning, " Couldn't load icon: '%s'\n", IFNULL(iter->title_en,"No Name") );
+
+ if ( ! cache_icon ( iter, maxwidth, maxheight ) ) {
+ pnd_log ( pndn_warning, " WARNING: Couldn't load icon: '%s'\n", IFNULL(iter->title_en,"No Name") );
+ }
+
}
+
}
// cache the preview --> SHOULD DEFER
// let deferred icon cache go now
ui_post_scan();
+ // log completion
+ pnd_log ( pndn_debug, "Applications scan done.\n" );
+
return;
}