From 913486037d31316a3637a093ffe371a69b8a66bf Mon Sep 17 00:00:00 2001 From: skeezix Date: Thu, 11 Mar 2010 15:47:07 -0500 Subject: [PATCH] Added 'info' system; PXML.xml can now cause a .desktop to be created, that will launch a browser to show an info page in the pnd-file --- apps/pndnotifyd.c | 23 ++++ deployment/etc/pandora/conf/desktop | 7 ++ include/pnd_desktop.h | 6 ++ lib/pnd_apps.c | 22 +++- lib/pnd_desktop.c | 148 +++++++++++++++++++++++++- testdata/conf/desktop | 7 ++ testdata/menuapps/sampleapp9/PXML.xml | 2 + 7 files changed, 207 insertions(+), 8 deletions(-) diff --git a/apps/pndnotifyd.c b/apps/pndnotifyd.c index 134bcc5..a883cd6 100644 --- a/apps/pndnotifyd.c +++ b/apps/pndnotifyd.c @@ -57,6 +57,7 @@ char *desktop_appspath = NULL; char *menu_dotdesktoppath = NULL; char *menu_iconpath = NULL; char *menu_appspath = NULL; +char *info_dotdesktoppath = NULL; // pnd runscript char *run_searchpath; // searchpath to find pnd_run.sh char *run_script; // name of pnd_run.sh script from config @@ -67,6 +68,7 @@ char g_username [ 128 ]; // since we have to wait for login (!!), store username // notifier handle pnd_notify_handle nh = 0; pnd_dbusnotify_handle dbh = 0; +unsigned char g_info_p = 0; // spit out info .desktops // constants #define PNDNOTIFYD_LOGLEVEL "pndnotifyd.loglevel" @@ -229,6 +231,7 @@ int main ( int argc, char *argv[] ) { pnd_log ( pndn_rem, "Apps searchpath is '%s'\n", menu_appspath ); pnd_log ( pndn_rem, ".desktop files emit to '%s'\n", menu_dotdesktoppath ); pnd_log ( pndn_rem, ".desktop icon files emit to '%s'\n", menu_iconpath ); + pnd_log ( pndn_rem, ".desktop info files emit to '%s'\n", info_dotdesktoppath ? info_dotdesktoppath : "n/a" ); /* set up signal handler */ @@ -401,6 +404,7 @@ void consume_configuration ( void ) { desktop_dotdesktoppath = pnd_conf_get_as_char ( desktoph, PND_DESKTOP_DOTDESKTOP_PATH_KEY ); desktop_iconpath = pnd_conf_get_as_char ( desktoph, PND_DESKTOP_ICONS_PATH_KEY ); desktop_appspath = pnd_conf_get_as_char ( desktoph, PND_DESKTOP_SEARCH_KEY ); + info_dotdesktoppath = pnd_conf_get_as_char ( desktoph, "info.dotdesktoppath" ); } if ( ! desktop_dotdesktoppath ) { @@ -422,6 +426,11 @@ void consume_configuration ( void ) { menu_appspath = pnd_conf_get_as_char ( desktoph, PND_MENU_SEARCH_KEY ); } + // info + if ( desktoph ) { + g_info_p = pnd_conf_get_as_int_d ( desktoph, "info.emit_info", 0 ); + } + /* try to locate a runscript and optional hupscript */ @@ -557,6 +566,11 @@ void consume_configuration ( void ) { mkdir ( desktop_dotdesktoppath, 0777 ); mkdir ( desktop_iconpath, 0777 ); + if ( info_dotdesktoppath ) { + info_dotdesktoppath = pnd_expand_tilde ( strdup ( info_dotdesktoppath ) ); + mkdir ( info_dotdesktoppath, 0777 ); + } + if ( menu_dotdesktoppath ) { menu_dotdesktoppath = pnd_expand_tilde ( strdup ( menu_dotdesktoppath ) ); mkdir ( menu_dotdesktoppath, 0777 ); @@ -705,6 +719,15 @@ void process_discoveries ( pnd_box_handle applist, char *emitdesktoppath, char * pnd_log ( pndn_rem, "ERROR: Error creating .desktop file for app: %s\n", pnd_box_get_key ( d ) ); } + // info .desktop + if ( g_info_p && info_dotdesktoppath ) { + if ( pnd_emit_dotinfo ( info_dotdesktoppath, pndrun, d ) ) { + // nada + } else { + pnd_log ( pndn_rem, "ERROR: Error creating info .desktop file for app: %s\n", pnd_box_get_key ( d ) ); + } + } + // does this object request any mkdir's? if ( d -> mkdir_sp ) { diff --git a/deployment/etc/pandora/conf/desktop b/deployment/etc/pandora/conf/desktop index aa2b205..62e5c3e 100644 --- a/deployment/etc/pandora/conf/desktop +++ b/deployment/etc/pandora/conf/desktop @@ -17,3 +17,10 @@ iconpath /tmp # path for pndnotifyd to drop icons into (can be same as dotdeskto # if it is uncommented, pndnotifyd will attempt to invoke the hupscript after emitting .desktop files # (the hupscript exists to hup the WMs to redisplay .desktop apps) #hupscript pnd_hup.sh + +[info] +emit_info 1 # 0->no info .desktop; !0->yes to info .desktop +dotdesktoppath /usr/share/applications # path for pndnotifyd to spit .desktop files into +viewer ../../../usr/bin/midori # sh-script or prog to run. Use wrapper sh if needed. +viewer_args -a # args. <- plus filename will be passed. ie: "-a filename.html" +category Documentation # freedesktop standard category to use diff --git a/include/pnd_desktop.h b/include/pnd_desktop.h index 367e38b..d9c52e9 100644 --- a/include/pnd_desktop.h +++ b/include/pnd_desktop.h @@ -15,6 +15,12 @@ extern "C" { #define PND_DOTDESKTOP_SOURCE "X-Pandora-Source=libpnd" unsigned char pnd_emit_dotdesktop ( char *targetpath, char *pndrun, pnd_disco_t *p ); +// emit_dotinfo() will spit out a .desktop 'info entry', similar to the way emit_dotdesktop does its thing +// - rather than slide this into emit_dotdesktop(), we wish to allow apps to do this or not by calling this +// function, and also let them specify an alternate path to emit to.. without adding all these +// extra fields to emit_dotdesktop()'s function and breaking apps, or annoying callers down the road +unsigned char pnd_emit_dotinfo ( char *targetpath, char *pndrun, pnd_disco_t *p ); + // emit_icon() will attempt to copy the icon from a PXML directory, or from a pnd file if appended, // to the given directory; returns 1 on sucess, otherwise is a fail. unsigned char pnd_emit_icon ( char *targetpath, pnd_disco_t *p ); diff --git a/lib/pnd_apps.c b/lib/pnd_apps.c index 33b72c8..73a78e3 100644 --- a/lib/pnd_apps.c +++ b/lib/pnd_apps.c @@ -96,6 +96,7 @@ unsigned char pnd_apps_exec ( char *pndrun, char *fullpath, char *unique_id, unsigned char i; bzero ( apps_exec_runline, 1024 ); //pnd_log ( PND_LOG_DEFAULT, "Norun %u\n", f ); + unsigned char quotenext = 0; for ( i = 0; i < ( f - 1 ); i++ ) { //pnd_log ( PND_LOG_DEFAULT, "Norun %u: %s\n", i, argv [ i ] ); @@ -104,19 +105,30 @@ unsigned char pnd_apps_exec ( char *pndrun, char *fullpath, char *unique_id, strncat ( apps_exec_runline, " ", 1000 ); } - // if this is for -a, we need to wrap with quotes - if ( i > 0 && strcmp ( argv [ i - 1 ], "-a" ) == 0 ) { + // quoting + if ( quotenext ) { strncat ( apps_exec_runline, "\"", 1000 ); } + // arg strncat ( apps_exec_runline, argv [ i ], 1000 ); - // if this is for -a, we need to wrap with quotes - if ( i > 0 && strcmp ( argv [ i - 1 ], "-a" ) == 0 ) { + // unquoting + if ( quotenext ) { strncat ( apps_exec_runline, "\"", 1000 ); } - } + // clear quoting + if ( quotenext ) { + quotenext = 0; + } else { + // if this is for -a, we need to wrap with quotes + if ( strcmp ( argv [ i ], "-a" ) == 0 ) { + quotenext = 1; + } + } + + } // for return ( 1 ); } diff --git a/lib/pnd_desktop.c b/lib/pnd_desktop.c index a222b8f..da1b01d 100644 --- a/lib/pnd_desktop.c +++ b/lib/pnd_desktop.c @@ -83,7 +83,7 @@ unsigned char pnd_emit_dotdesktop ( char *targetpath, char *pndrun, pnd_disco_t } #endif -#if 0 // we let pnd_run.sh handle this +#if 0 // we let pnd_run.sh command line handle this instead of in .desktop if ( p -> startdir ) { snprintf ( buffer, 1020, "Path=%s\n", p -> startdir ); fprintf ( f, "%s", buffer ); @@ -118,8 +118,9 @@ unsigned char pnd_emit_dotdesktop ( char *targetpath, char *pndrun, pnd_disco_t // args if ( p -> execargs ) { - strncat ( buffer, " -a ", 1020 ); - strncat ( buffer, p -> execargs, 1020 ); + char argbuf [ 1024 ]; + snprintf ( argbuf, 1000, " -a \"%s\"", p -> execargs ); + strncat ( buffer, argbuf, 1020 ); } // clockspeed @@ -191,6 +192,147 @@ unsigned char pnd_emit_dotdesktop ( char *targetpath, char *pndrun, pnd_disco_t return ( 1 ); } +unsigned char pnd_emit_dotinfo ( char *targetpath, char *pndrun, pnd_disco_t *p ) { + char filename [ FILENAME_MAX ]; + char buffer [ 1024 ]; + FILE *f; + char *viewer, *searchpath; + pnd_conf_handle desktoph; + + // specification + // http://standards.freedesktop.org/desktop-entry-spec + + // validation + // + + // viewer + searchpath = pnd_conf_query_searchpath(); + + desktoph = pnd_conf_fetch_by_id ( pnd_conf_desktop, searchpath ); + + if ( ! desktoph ) { + return ( 0 ); + } + + viewer = pnd_conf_get_as_char ( desktoph, "info.viewer" ); + + if ( ! viewer ) { + return ( 0 ); // no way to view the file + } + + // etc + if ( ! p -> unique_id ) { + pnd_log ( PND_LOG_DEFAULT, "Can't emit dotdesktop for %s, missing unique-id\n", targetpath ); + return ( 0 ); + } + + if ( ! p -> info_filename ) { + pnd_log ( PND_LOG_DEFAULT, "Can't emit dotdesktop for %s, missing info_filename\n", targetpath ); + return ( 0 ); + } + + if ( ! p -> info_name ) { + pnd_log ( PND_LOG_DEFAULT, "Can't emit dotdesktop for %s, missing info_name\n", targetpath ); + return ( 0 ); + } + + if ( ! targetpath ) { + pnd_log ( PND_LOG_DEFAULT, "Can't emit dotdesktop for %s, missing target path\n", targetpath ); + return ( 0 ); + } + + if ( ! pndrun ) { + pnd_log ( PND_LOG_DEFAULT, "Can't emit dotdesktop for %s, missing pnd_run.sh\n", targetpath ); + return ( 0 ); + } + + // set up + + sprintf ( filename, "%s/%s#info.desktop", targetpath, p -> unique_id ); + + // emit + + f = fopen ( filename, "w" ); + + if ( ! f ) { + return ( 0 ); + } + + fprintf ( f, "%s\n", PND_DOTDESKTOP_HEADER ); + + if ( p -> info_name ) { + snprintf ( buffer, 1020, "Name=%s\n", p -> info_name ); + fprintf ( f, "%s", buffer ); + } + + fprintf ( f, "Type=Application\n" ); + fprintf ( f, "Version=1.0\n" ); + +#if 0 + if ( p -> icon ) { + snprintf ( buffer, 1020, "Icon=%s\n", p -> icon ); + fprintf ( f, "%s", buffer ); + } +#endif + + if ( p -> unique_id ) { + fprintf ( f, "X-Pandora-UID=%s\n", p -> unique_id ); + } + + if ( p -> title_en && p -> title_en [ 0 ] ) { + snprintf ( buffer, 1020, "Comment=Automatic menu info entry for %s\n", p -> title_en ); + fprintf ( f, "%s", buffer ); + } + +#if 0 // we let pnd_run.sh command line handle this instead of in .desktop + if ( p -> startdir ) { + snprintf ( buffer, 1020, "Path=%s\n", p -> startdir ); + fprintf ( f, "%s", buffer ); + } else { + fprintf ( f, "Path=%s\n", PND_DEFAULT_WORKDIR ); + } +#endif + + // exec line + char args [ 1001 ]; + char *pargs = args; + if ( pnd_conf_get_as_char ( desktoph, "info.viewer_args" ) ) { + snprintf ( pargs, 1001, "%s %s", + pnd_conf_get_as_char ( desktoph, "info.viewer_args" ), p -> info_filename ); + } else { + pargs = NULL; + } + + char pndfile [ 1024 ]; + if ( p -> object_type == pnd_object_type_directory ) { + // for PXML-app-dir, pnd_run.sh doesn't want the PXML.xml.. it just wants the dir-name + strncpy ( pndfile, p -> object_path, 1000 ); + } else if ( p -> object_type == pnd_object_type_pnd ) { + // pnd_run.sh wants the full path and filename for the .pnd file + snprintf ( pndfile, 1020, "%s/%s", p -> object_path, p -> object_filename ); + } + + if ( ! pnd_apps_exec ( pndrun, pndfile, p -> unique_id, viewer, p -> startdir, pargs, + p -> clockspeed ? atoi ( p -> clockspeed ) : 0, PND_EXEC_OPTION_NORUN ) ) + { + return ( 0 ); + } + + fprintf ( f, "Exec=%s\n", pnd_apps_exec_runline() ); + + if ( pnd_conf_get_as_char ( desktoph, "info.category" ) ) { + fprintf ( f, "Categories=%s\n", pnd_conf_get_as_char ( desktoph, "info.category" ) ); + } else { + fprintf ( f, "Categories=Documentation\n" ); + } + + fprintf ( f, "%s\n", PND_DOTDESKTOP_SOURCE ); // should we need to know 'who' created the file during trimming + + fclose ( f ); + + return ( 1 ); +} + unsigned char pnd_emit_icon ( char *targetpath, pnd_disco_t *p ) { //#define BITLEN (8*1024) #define BITLEN (64*1024) diff --git a/testdata/conf/desktop b/testdata/conf/desktop index 6e3d6ca..0da72c0 100644 --- a/testdata/conf/desktop +++ b/testdata/conf/desktop @@ -14,3 +14,10 @@ iconpath ./testdata/menuicons # path for pndnotifyd to drop icons into (can be s [launcher] hupscript pnd_hup.sh + +[info] +emit_info 1 # 0->no info .desktop; !0->yes to info .desktop +dotdesktoppath ./testdata/menu # path for pndnotifyd to spit .desktop files into +viewer midori # sh-script or prog to run. Use wrapper sh if needed. +viewer_args -a # args. <- plus filename will be passed. ie: "-a filename.html" +category Documentation # freedesktop standard category to use diff --git a/testdata/menuapps/sampleapp9/PXML.xml b/testdata/menuapps/sampleapp9/PXML.xml index 2d59722..33e137f 100644 --- a/testdata/menuapps/sampleapp9/PXML.xml +++ b/testdata/menuapps/sampleapp9/PXML.xml @@ -6,6 +6,8 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" id="jeff.sample.9" xsi:noN + + This is the English Description of the file. This would be the German description. -- 2.39.5