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
// 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"
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
*/
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 ) {
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
*/
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 );
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 ) {
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 ] );
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 );
}
}
#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 );
// 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
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)