From 65f6533ef7d0f4b57897f7fd565b689a03a420ef Mon Sep 17 00:00:00 2001 From: skeezix Date: Thu, 19 Feb 2009 14:33:28 -0500 Subject: [PATCH] Added basic .desktop emit code pndnotifyd is almost ready to spit out .desktops after changes in app searchpath! --- apps/pndnotifyd.c | 26 ++++++++++++-- include/pnd_apps.h | 7 ++++ include/pnd_conf.h | 1 + include/pnd_discovery.h | 14 ++++++-- include/pnd_pxml.h | 4 +-- lib/pnd_conf.c | 1 + lib/pnd_container.c | 2 ++ lib/pnd_discovery.c | 66 ++++++++++++++++++++++++++++++++++++ test/discotest.c | 2 ++ testdata/conf/apps | 2 ++ testdata/conf/desktop | 6 ++++ testdata/dotdesktop/.keepdir | 0 12 files changed, 125 insertions(+), 6 deletions(-) create mode 100644 testdata/conf/desktop create mode 100644 testdata/dotdesktop/.keepdir diff --git a/apps/pndnotifyd.c b/apps/pndnotifyd.c index 2197e87..257de2b 100644 --- a/apps/pndnotifyd.c +++ b/apps/pndnotifyd.c @@ -26,7 +26,8 @@ int main ( int argc, char *argv[] ) { pnd_notify_handle nh; char *configpath; char *appspath; - char *searchpath; + char *searchpath = NULL; + char *dotdesktoppath = NULL; int i; unsigned int interval_secs = 60; @@ -77,8 +78,28 @@ int main ( int argc, char *argv[] ) { appspath = PND_APPS_SEARCHPATH; } + // attempt to figure out where to drop dotfiles + pnd_conf_handle desktoph; + + desktoph = pnd_conf_fetch_by_id ( pnd_conf_desktop, configpath ); + + if ( desktoph ) { + dotdesktoppath = pnd_conf_get_as_char ( desktoph, PND_DOTDESKTOP_KEY ); + + if ( ! dotdesktoppath ) { + dotdesktoppath = PND_DOTDESKTOP_DEFAULT; + } + + } else { + dotdesktoppath = PND_DOTDESKTOP_DEFAULT; + } + + /* startup + */ + if ( ! g_daemon_mode ) { printf ( "Apps searchpath is '%s'\n", appspath ); + printf ( ".desktop files emit to '%s'\n", dotdesktoppath ); } /* set up notifies @@ -121,7 +142,8 @@ int main ( int argc, char *argv[] ) { // has occurred; we should be clever, but we're not, so just re-brute force the // discovery and spit out .desktop files.. if ( ! g_daemon_mode ) { - printf ( "Time to re-discover!\n" ); + printf ( "Changes within watched paths .. performing re-discover!\n" ); + printf ( "Path to emit .desktop files to: '%s'\n", dotdesktoppath ); } // lets not eat up all the CPU diff --git a/include/pnd_apps.h b/include/pnd_apps.h index 086796b..6cf16b4 100644 --- a/include/pnd_apps.h +++ b/include/pnd_apps.h @@ -19,6 +19,13 @@ extern "C" { #define PND_MOUNT_PATH "/mnt/apps/" /* all mounted PND images should be here.. /mnt/apps/myapp/... */ +// .desktop support +#define PND_DOTDESKTOP_KEY "dotfiles.dotdesktoppath" +#define PND_DOTDESKTOP_DEFAULT "/usr/share/applications" + +// apps +#define PND_DEFAULT_WORKDIR "/tmp" + /* pnd_apps_exec() is used to blindly launch an app, be it a .pnd file bundle or a plain executable * (shell, bin, whatever.) pndrun specifies the full path to the pnd_run sh script, which should be * found using searchpaths and locates.. see locatetest.c for a sample diff --git a/include/pnd_conf.h b/include/pnd_conf.h index a1d2193..67b3858 100644 --- a/include/pnd_conf.h +++ b/include/pnd_conf.h @@ -66,6 +66,7 @@ typedef enum { pnd_conf_conf, // provides settings for the config system pnd_conf_apps, // provides application search-path, pxml override location, etc. pnd_conf_startup, // provides list of startup applications, basic shell application, etc. + pnd_conf_desktop, // provides settings for the launchers } pnd_conf_filename_e; typedef struct { diff --git a/include/pnd_discovery.h b/include/pnd_discovery.h index f14ba29..bc74aed 100644 --- a/include/pnd_discovery.h +++ b/include/pnd_discovery.h @@ -31,7 +31,10 @@ pnd_box_handle pnd_disco_search ( char *searchpath, char *overridespath ); * confusion.. it is not displayed. So no big deal. */ -typedef struct +// another struct? Have always intended discovery_t to have minimal members.. just enough to lead to an +// application (PXML, xecutable, name); if the apps want more details, they can use the pnd_pxml code to +// fetch the full PXML and get all the details. But I think we got out of control here :) +typedef struct { char *title_en; char *title_de; @@ -75,11 +78,18 @@ typedef struct char *clockspeed; char *background; char *startdir; - + } pnd_disco_t; void pnd_disco_destroy ( pnd_disco_t *p ); // a function name that simply could not be avoided +// emit_dotdesktop() will determine a filename and create a FILENAME.desktop file in the targetpath +// TODO: Copy the icon into this directory as well, if its source is a .pnd or info is in the dico struct +unsigned char pnd_emit_dotdesktop ( char *targetpath, pnd_disco_t *p ); + +// TODO: A way to release the disco-lists and reclaim RAM :) +// TODO: A way to determine the list of excess .desktop files and remove them (ie: after poo.pnd is removed, ditch the .desktop) + #ifdef __cplusplus } /* "C" */ #endif diff --git a/include/pnd_pxml.h b/include/pnd_pxml.h index 366326c..4bca9b3 100644 --- a/include/pnd_pxml.h +++ b/include/pnd_pxml.h @@ -49,7 +49,7 @@ void pnd_pxml_set_app_name ( pnd_pxml_handle h, char *v ); */ unsigned char pnd_is_pxml_valid_app ( pnd_pxml_handle h ); // returns 1 when pxml seems like a valid application -typedef struct +typedef struct { char *title_en; char *title_de; @@ -93,7 +93,7 @@ typedef struct char *clockspeed; char *background; char *startdir; - + } pnd_pxml_t; #ifdef __cplusplus diff --git a/lib/pnd_conf.c b/lib/pnd_conf.c index 129d278..10dc9d1 100644 --- a/lib/pnd_conf.c +++ b/lib/pnd_conf.c @@ -12,6 +12,7 @@ pnd_conf_filename_t pnd_conf_filenames[] = { { pnd_conf_conf, PND_CONF_FILE }, { pnd_conf_apps, "apps" }, { pnd_conf_startup, "startup" }, + { pnd_conf_desktop, "desktop" }, { pnd_conf_nil, NULL }, }; diff --git a/lib/pnd_container.c b/lib/pnd_container.c index 6bd8236..f1fdef6 100644 --- a/lib/pnd_container.c +++ b/lib/pnd_container.c @@ -92,6 +92,8 @@ void *pnd_box_allocinsert ( pnd_box_handle box, char *key, unsigned int size ) { return ( NULL ); // must be getting bloody tight! } + memset ( n, '\0', sizeof(pnd_box_node_t) + size ); + if ( key ) { n -> key = strdup ( key ); } else { diff --git a/lib/pnd_discovery.c b/lib/pnd_discovery.c index 618bb36..09adad2 100644 --- a/lib/pnd_discovery.c +++ b/lib/pnd_discovery.c @@ -11,6 +11,7 @@ #include "pnd_pxml.h" #include "pnd_discovery.h" #include "pnd_pathiter.h" +#include "pnd_apps.h" #warning "PND/PNZ support is not included yet; scripts need writing" #warning " /usr/pandora/bin/pnd_valid.sh" @@ -149,3 +150,68 @@ pnd_box_handle pnd_disco_search ( char *searchpath, char *overridespath ) { return ( disco_box ); } + +unsigned char pnd_emit_dotdesktop ( char *targetpath, pnd_disco_t *p ) { + char filename [ FILENAME_MAX ]; + char buffer [ 1024 ]; + FILE *f; + + // specification + // http://standards.freedesktop.org/desktop-entry-spec + + // validation + + if ( ! p -> unique_id ) { + return ( 0 ); + } + + if ( ! p -> exec ) { + return ( 0 ); + } + + // set up + + sprintf ( filename, "%s/%s.desktop", targetpath, p -> unique_id ); + + // emit + + f = fopen ( filename, "w" ); + + if ( ! f ) { + return ( 0 ); + } + + if ( p -> title_en ) { + snprintf ( buffer, 1020, "Name=%s\n", p -> title_en ); + fprintf ( f, "%s", buffer ); + } + + fprintf ( f, "Type=Application\n" ); + fprintf ( f, "Version=1.0\n" ); + + if ( p -> icon ) { + snprintf ( buffer, 1020, "Icon=%s\n", p -> icon ); + fprintf ( f, "%s", buffer ); + } + + if ( p -> description_en ) { + snprintf ( buffer, 1020, "Comment=%s\n", p -> description_en ); + fprintf ( f, "%s", buffer ); + } + + if ( p -> startdir ) { + snprintf ( buffer, 1020, "Path=%s\n", p -> startdir ); + fprintf ( f, "%s", buffer ); + } else { + fprintf ( f, "Path=%s\n", PND_DEFAULT_WORKDIR ); + } + + if ( p -> exec ) { + snprintf ( buffer, 1020, "Exec=%s\n", p -> exec ); + fprintf ( f, "%s", buffer ); + } + + fclose ( f ); + + return ( 1 ); +} diff --git a/test/discotest.c b/test/discotest.c index 034afcf..17624e0 100644 --- a/test/discotest.c +++ b/test/discotest.c @@ -82,6 +82,8 @@ int main ( void) { printf ( " Clockspeed: %s\n", d -> clockspeed ); } + pnd_emit_dotdesktop ( "/tmp", d ); + // next! d = pnd_box_get_next ( d ); diff --git a/testdata/conf/apps b/testdata/conf/apps index 63d0e18..fe47925 100644 --- a/testdata/conf/apps +++ b/testdata/conf/apps @@ -5,9 +5,11 @@ [autodiscovery] searchpath /mnt/sd1/pandora/apps:/mnt/sd2/pandora/apps:./testdata/apps # path to depth-search for PXMLs +# PXMLs may be overridden .. ie: overrides are a subset of PXML, where the values are copied over the full PXML [overrides] searchpath ~/pxml-overrides:./testdata/apps-override +# [pnd] defines where to locate the pnd support scripts, so the user may override pnd_run.sh without clobbering built in [pnd] searchpath /mnt/sd1/pandora/scripts:/mnt/sd2/pandora/scripts:./testdata/scripts default pndrun.sh diff --git a/testdata/conf/desktop b/testdata/conf/desktop new file mode 100644 index 0000000..7e9ff76 --- /dev/null +++ b/testdata/conf/desktop @@ -0,0 +1,6 @@ + +# Open Pandora +# Desktop configuration + +[dotfiles] +dotdesktoppath ./testdata/dotdesktop # path for pndnotifyd to spit .desktop files into diff --git a/testdata/dotdesktop/.keepdir b/testdata/dotdesktop/.keepdir new file mode 100644 index 0000000..e69de29 -- 2.39.5