#include <string.h>
#include <unistd.h> /* for unlink */
#include <stdlib.h> /* for free */
+#include <sys/stat.h> /* for stat */
#include "pnd_apps.h"
#include "pnd_container.h"
}
#endif
-#if 0 // we let pnd_run.sh handle this
+ if ( p -> preview_pic1 ) {
+ fprintf ( f, "X-Pandora-Preview-Pic-1=%s\n", p -> preview_pic1 );
+ }
+
+ if ( p -> clockspeed ) {
+ fprintf ( f, "X-Pandora-Clockspeed=%s\n", p -> clockspeed );
+ }
+
+ if ( p -> startdir ) {
+ fprintf ( f, "X-Pandora-Startdir=%s\n", p -> startdir );
+ }
+
+ if ( p -> main_category ) {
+ fprintf ( f, "X-Pandora-MainCategory=%s\n", p -> main_category );
+ }
+ if ( p -> main_category1 ) {
+ fprintf ( f, "X-Pandora-MainCategory1=%s\n", p -> main_category1 );
+ }
+ if ( p -> main_category2 ) {
+ fprintf ( f, "X-Pandora-MainCategory2=%s\n", p -> main_category2 );
+ }
+
+ if ( p -> alt_category ) {
+ fprintf ( f, "X-Pandora-AltCategory=%s\n", p -> alt_category );
+ }
+ if ( p -> alt_category1 ) {
+ fprintf ( f, "X-Pandora-AltCategory1=%s\n", p -> alt_category1 );
+ }
+ if ( p -> alt_category2 ) {
+ fprintf ( f, "X-Pandora-AltCategory2=%s\n", p -> alt_category2 );
+ }
+ if ( p -> info_filename ) {
+ fprintf ( f, "X-Pandora-Info-Filename=%s\n", p -> info_filename );
+ }
+ if ( p -> info_name ) {
+ fprintf ( f, "X-Pandora-Info-Name=%s\n", p -> info_name );
+ }
+
+ if ( p -> associationitem1_name || p -> associationitem2_name || p -> associationitem3_name ) {
+ fprintf ( f, "MimeType=" );
+ if ( p -> associationitem1_name ) {
+ fprintf ( f, "%s;", p -> associationitem1_filetype );
+ pnd_log ( PND_LOG_DEFAULT, "App %s is handling mimetype %s [1]\n", p -> title_en, p -> associationitem1_filetype );
+ }
+ if ( p -> associationitem2_name ) {
+ fprintf ( f, "%s;", p -> associationitem2_filetype );
+ pnd_log ( PND_LOG_DEFAULT, "App %s is handling mimetype %s [2]\n", p -> title_en, p -> associationitem2_filetype );
+ }
+ if ( p -> associationitem3_name ) {
+ fprintf ( f, "%s;", p -> associationitem3_filetype );
+ pnd_log ( PND_LOG_DEFAULT, "App %s is handling mimetype %s [3]\n", p -> title_en, p -> associationitem3_filetype );
+ }
+ fprintf ( f, "\n" );
+ }
+
+#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 );
// basics
if ( p -> object_type == pnd_object_type_directory ) {
- snprintf ( buffer, 1020, "Exec=%s%s -p %s -e %s -b %s",
- nohup, pndrun, p -> object_path, p -> exec, p -> unique_id );
+ snprintf ( buffer, 1020, "Exec=%s%s -p \"%s\" -e \"%s\" -b \"%s\"",
+ nohup, pndrun, p -> object_path, p -> exec,
+ p -> appdata_dirname ? p -> appdata_dirname : p -> unique_id );
} else if ( p -> object_type == pnd_object_type_pnd ) {
- snprintf ( buffer, 1020, "Exec=%s%s -p %s/%s -e %s -b %s",
- nohup, pndrun, p -> object_path, p -> object_filename, p -> exec, p -> unique_id );
+ snprintf ( buffer, 1020, "Exec=%s%s -p \"%s/%s\" -e \"%s\" -b \"%s\"",
+ nohup, pndrun, p -> object_path, p -> object_filename, p -> exec,
+ p -> appdata_dirname ? p -> appdata_dirname : p -> unique_id );
}
// start dir
// 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
// emit
fprintf ( f, "%s", buffer );
+
+ // and lets copy in some stuff in case it makes .desktop consumers life easier
+ if ( p -> exec ) { fprintf ( f, "X-Pandora-Exec=%s\n", p -> exec ); }
+ if ( p -> appdata_dirname ) { fprintf ( f, "X-Pandora-Appdata-Dirname=%s\n", p -> appdata_dirname ); }
+ if ( p -> execargs ) { fprintf ( f, "X-Pandora-ExecArgs=%s\n", p -> execargs ); }
+ if ( p -> object_flags & PND_DISCO_FLAG_OVR ) { fprintf ( f, "X-Pandora-Object-Flag-OVR=%s\n", "Yes" ); }
+ if ( p -> object_type == pnd_object_type_pnd ) {
+ fprintf ( f, "X-Pandora-Object-Path=%s\n", p -> object_path );
+ fprintf ( f, "X-Pandora-Object-Filename=%s\n", p -> object_filename );
+ }
+
}
// categories
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#%uinfo.desktop", targetpath, p -> unique_id, p -> subapp_number );
+
+ // 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;
+ char *viewerargs = pnd_conf_get_as_char ( desktoph, "info.viewer_args" );
+ if ( viewerargs && viewerargs [ 0 ] ) {
+ snprintf ( pargs, 1001, "%s %s",
+ pnd_conf_get_as_char ( desktoph, "info.viewer_args" ), p -> info_filename );
+ } else {
+ pargs = NULL;
+ // WARNING: This might not be quite right; if no viewer-args, shouldn't we still append the info-filename? likewise,
+ // even if we do have view-args, shouldn't we check if filename is present?
+ }
+
+ 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 );
+ }
+
+ pnd_apps_exec_info_t info;
+ info.viewer = viewer;
+ info.args = pargs;
+
+ if ( ! pnd_apps_exec_disco ( pndrun, p, PND_EXEC_OPTION_NORUN | PND_EXEC_OPTION_INFO, &info ) ) {
+ 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)
{
match = pnd_map_dotdesktop_category ( c, t );
}
-
+
if ( match ) {
strncat ( target_buffer, match, len );
len -= strlen ( target_buffer );
{
match = pnd_map_dotdesktop_category ( c, t );
}
-
+
if ( match ) {
if ( target_buffer [ 0 ] != '\0' && len > 0 ) {
strcat ( target_buffer, ";" );
{
match = pnd_map_dotdesktop_category ( c, t );
}
-
+
if ( match ) {
strncat ( target_buffer, match, len );
len -= strlen ( target_buffer );
{
match = pnd_map_dotdesktop_category ( c, t );
}
-
+
if ( match ) {
if ( target_buffer [ 0 ] != '\0' && len > 0 ) {
strcat ( target_buffer, ";" );
return ( target );
}
+
+// parse_dotdesktop() can be used to read a libpnd generated .desktop and return a limited
+// but useful disco-t structure back; possibly useful for scanning .desktops rather than
+// scanning pnd-files?
+pnd_disco_t *pnd_parse_dotdesktop ( char *ddpath, unsigned int flags ) {
+
+ // will verify the .desktop has the libpnd-marking on it (X-Pandora-Source): PND_DOTDESKTOP_SOURCE
+
+ // attempt to extract..
+ // - unique-id (from filename or field)
+ // - subapp number (from filename)
+ // - exec required info
+ // - icon path
+ // - name (title-en)
+ // - comment (desc-en)
+ // - option_no_x11
+ // - object path
+ // - appdata name (or unique-id if not present)
+ // - start dir
+ // - args
+ // - 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 ); // no .desktop in filename, must be something else... skip!
+ }
+
+ if ( strstr ( ddpath, "info.desktop" ) != NULL ) {
+ // ".....info.desktop" is the 'document help' (README) emitted from a pnd, not an actual app; minimenu rather
+ // expects the doc-info as part of the main app, not a separate app.. so lets drop it here, to avoid doubling up
+ // the number of applications, needlessly..
+ return ( NULL );
+ }
+
+ // determine file length
+ struct stat statbuf;
+
+ if ( stat ( ddpath, &statbuf) < 0 ) {
+ return ( NULL ); // couldn't open
+ }
+
+ // buffers..
+ char dd [ 1024 ];
+ unsigned char libpnd_origin = 0;
+
+ // disco
+ pnd_disco_t *p = malloc ( sizeof(pnd_disco_t) );
+ if ( ! p ) {
+ return ( NULL );
+ }
+ bzero ( p, sizeof(pnd_disco_t) );
+
+ // inhale file
+ FILE *f = fopen ( ddpath, "r" );
+
+ if ( ! f ) {
+ return ( NULL ); // not up or shut up!
+ }
+
+ while ( fgets ( dd, 1024, f ) ) {
+ char *nl = strchr ( dd, '\n' );
+ if ( nl ) {
+ *nl = '\0';
+ }
+
+ // grep
+ //
+
+ 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 ) {
+ libpnd_origin = 1;
+ } else if ( strncmp ( dd, "X-Pandora-UID=", 14 ) == 0 ) {
+ p -> unique_id = strdup ( dd + 14 );
+ } else if ( strncmp ( dd, "X-Pandora-Preview-Pic-1=", 24 ) == 0 ) {
+ p -> preview_pic1 = strdup ( dd + 24 );
+ } else if ( strncmp ( dd, "X-Pandora-Clockspeed=", 21 ) == 0 ) {
+ p -> clockspeed = strdup ( dd + 21 );
+ } else if ( strncmp ( dd, "X-Pandora-Startdir=", 19 ) == 0 ) {
+ p -> startdir = strdup ( dd + 19 );
+ } else if ( strncmp ( dd, "X-Pandora-Appdata-Dirname=", 26 ) == 0 ) {
+ p -> appdata_dirname = strdup ( dd + 26 );
+ } else if ( strncmp ( dd, "X-Pandora-ExecArgs=", 19 ) == 0 ) {
+ p -> execargs = strdup ( dd + 19 );
+ } else if ( strncmp ( dd, "X-Pandora-Exec=", 15 ) == 0 ) {
+ p -> exec = strdup ( dd + 15 );
+ } else if ( strncmp ( dd, "X-Pandora-Object-Path=", 22 ) == 0 ) {
+ p -> object_path = strdup ( dd + 22 );
+ } else if ( strncmp ( dd, "X-Pandora-Object-Filename=", 26 ) == 0 ) {
+ p -> object_filename = strdup ( dd + 26 );
+ } else if ( strncmp ( dd, "X-Pandora-Object-Flag-OVR=", 26 ) == 0 ) {
+ p -> object_flags |= PND_DISCO_FLAG_OVR;
+
+ } else if ( strncmp ( dd, "X-Pandora-MainCategory=", 23 ) == 0 ) {
+ p -> main_category = strdup ( dd + 23 );
+ } else if ( strncmp ( dd, "X-Pandora-MainCategory1=", 24 ) == 0 ) {
+ p -> main_category1 = strdup ( dd + 24 );
+ } else if ( strncmp ( dd, "X-Pandora-MainCategory2=", 24 ) == 0 ) {
+ p -> main_category2 = strdup ( dd + 24 );
+
+ } else if ( strncmp ( dd, "X-Pandora-AltCategory=", 22 ) == 0 ) {
+ p -> alt_category = strdup ( dd + 22 );
+ } else if ( strncmp ( dd, "X-Pandora-AltCategory1=", 23 ) == 0 ) {
+ p -> alt_category1 = strdup ( dd + 23 );
+ } else if ( strncmp ( dd, "X-Pandora-AltCategory2=", 23 ) == 0 ) {
+ p -> alt_category2 = strdup ( dd + 23 );
+
+ } else if ( strncmp ( dd, "X-Pandora-Info-Filename=", 24 ) == 0 ) {
+ p -> info_filename = strdup ( dd + 24 );
+ } else if ( strncmp ( dd, "X-Pandora-Info-Name=", 20 ) == 0 ) {
+ p -> info_name = strdup ( dd + 20 );
+
+ } 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 ) {
+ // probably libpnd app
+#if 0 // no needed due to above X-Pandora attributes
+
+ if ( e ) {
+ e += 5;
+
+ 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 );
+ }
+#endif
+
+ } else {
+ // probably not libpnd app
+ p -> exec = strdup ( dd + 5 );
+ }
+
+#if 0 // ignore; using X- categories now
+ } else if ( strncmp ( dd, "Categories=", 11 ) == 0 ) {
+ // HACK; only honours first category
+ char *semi = strchr ( dd, ';' );
+ if ( semi ) {
+ p -> main_category = strndup ( dd + 11, semi - dd + 11 );
+ } else {
+ p -> main_category = strdup ( dd + 11 );
+ }
+ semi = strchr ( p -> main_category, ';' );
+ if ( semi ) {
+ *semi = '\0';
+ }
+#endif
+
+ }
+
+ //
+ // /grep
+
+ } // while
+
+ fclose ( f );
+
+ // filter
+ if ( ! libpnd_origin ) {
+
+ // convenience flag
+ if ( flags & PND_DOTDESKTOP_LIBPND_ONLY ) {
+ pnd_disco_destroy ( p );
+ free ( p );
+ return ( NULL );
+ }
+
+ } else {
+ p -> object_flags |= PND_DISCO_LIBPND_DD; // 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;
+
+#if 0 // nolonger needed due to above X-Pandora attributes
+ char *source;
+ if ( pndpath [ 0 ] ) {
+ source = pndpath;
+ } else {
+ source = ddpath;
+ }
+
+ char *slash = strrchr ( source, '/' );
+ if ( slash ) {
+ p -> object_path = strndup ( source, slash - source );
+ p -> object_filename = strdup ( slash + 1 );
+ } else {
+ p -> object_path = "./";
+ p -> object_filename = strdup ( source );
+ }
+#endif
+
+ // lame guards, in case of lazy consumers and broken .desktop files
+ if ( p -> object_path == NULL ) {
+ p -> object_path = strdup ( "/tmp" );
+ }
+ if ( p -> object_filename == NULL ) {
+ p -> object_filename = strdup ( "" ); // force bad filename
+ }
+
+ // return disco-t
+ return ( p );
+}