2 #include <stdio.h> /* for FILE etc */
4 #include <unistd.h> /* for unlink */
5 #include <stdlib.h> /* for free */
6 #include <sys/stat.h> /* for stat */
9 #include "pnd_container.h"
11 #include "pnd_discovery.h"
12 #include "pnd_pndfiles.h"
14 #include "pnd_desktop.h"
15 #include "pnd_logger.h"
17 unsigned char pnd_emit_dotdesktop ( char *targetpath, char *pndrun, pnd_disco_t *p ) {
18 char filename [ FILENAME_MAX ];
23 // http://standards.freedesktop.org/desktop-entry-spec
27 if ( ! p -> unique_id ) {
28 pnd_log ( PND_LOG_DEFAULT, "Can't emit dotdesktop for %s, missing unique-id\n", targetpath );
33 pnd_log ( PND_LOG_DEFAULT, "Can't emit dotdesktop for %s, missing exec\n", targetpath );
38 pnd_log ( PND_LOG_DEFAULT, "Can't emit dotdesktop for %s, missing target path\n", targetpath );
43 pnd_log ( PND_LOG_DEFAULT, "Can't emit dotdesktop for %s, missing pnd_run.sh\n", targetpath );
49 sprintf ( filename, "%s/%s#%u.desktop", targetpath, p -> unique_id, p -> subapp_number );
53 //printf ( "EMIT DOTDESKTOP '%s'\n", filename );
55 f = fopen ( filename, "w" );
61 fprintf ( f, "%s\n", PND_DOTDESKTOP_HEADER );
63 if ( p -> title_en ) {
64 snprintf ( buffer, 1020, "Name=%s\n", p -> title_en );
65 fprintf ( f, "%s", buffer );
68 fprintf ( f, "Type=Application\n" );
69 fprintf ( f, "Version=1.0\n" );
72 snprintf ( buffer, 1020, "Icon=%s\n", p -> icon );
73 fprintf ( f, "%s", buffer );
76 if ( p -> unique_id ) {
77 fprintf ( f, "X-Pandora-UID=%s\n", p -> unique_id );
81 if ( p -> desc_en && p -> desc_en [ 0 ] ) {
82 snprintf ( buffer, 1020, "Comment=%s\n", p -> desc_en ); // no [en] needed I suppose, yet
83 fprintf ( f, "%s", buffer );
87 if ( p -> preview_pic1 ) {
88 fprintf ( f, "X-Pandora-Preview-Pic-1=%s\n", p -> preview_pic1 );
91 if ( p -> clockspeed ) {
92 fprintf ( f, "X-Pandora-Clockspeed=%s\n", p -> clockspeed );
95 if ( p -> startdir ) {
96 fprintf ( f, "X-Pandora-Startdir=%s\n", p -> startdir );
99 if ( p -> main_category ) {
100 fprintf ( f, "X-Pandora-MainCategory=%s\n", p -> main_category );
102 if ( p -> main_category1 ) {
103 fprintf ( f, "X-Pandora-MainCategory1=%s\n", p -> main_category1 );
105 if ( p -> main_category2 ) {
106 fprintf ( f, "X-Pandora-MainCategory2=%s\n", p -> main_category2 );
109 if ( p -> alt_category ) {
110 fprintf ( f, "X-Pandora-AltCategory=%s\n", p -> alt_category );
112 if ( p -> alt_category1 ) {
113 fprintf ( f, "X-Pandora-AltCategory1=%s\n", p -> alt_category1 );
115 if ( p -> alt_category2 ) {
116 fprintf ( f, "X-Pandora-AltCategory2=%s\n", p -> alt_category2 );
118 if ( p -> info_filename ) {
119 fprintf ( f, "X-Pandora-Info-Filename=%s\n", p -> info_filename );
121 if ( p -> info_name ) {
122 fprintf ( f, "X-Pandora-Info-Name=%s\n", p -> info_name );
125 #if 0 // we let pnd_run.sh command line handle this instead of in .desktop
126 if ( p -> startdir ) {
127 snprintf ( buffer, 1020, "Path=%s\n", p -> startdir );
128 fprintf ( f, "%s", buffer );
130 fprintf ( f, "Path=%s\n", PND_DEFAULT_WORKDIR );
134 // association requests
135 if ( p -> associationitem1_filetype ) {
136 fprintf ( f, "MimeType=%s\n", p -> associationitem1_filetype );
142 if ( p -> option_no_x11 ) {
143 nohup = "/usr/bin/nohup ";
149 if ( p -> object_type == pnd_object_type_directory ) {
150 snprintf ( buffer, 1020, "Exec=%s%s -p \"%s\" -e \"%s\" -b \"%s\"",
151 nohup, pndrun, p -> object_path, p -> exec,
152 p -> appdata_dirname ? p -> appdata_dirname : p -> unique_id );
153 } else if ( p -> object_type == pnd_object_type_pnd ) {
154 snprintf ( buffer, 1020, "Exec=%s%s -p \"%s/%s\" -e \"%s\" -b \"%s\"",
155 nohup, pndrun, p -> object_path, p -> object_filename, p -> exec,
156 p -> appdata_dirname ? p -> appdata_dirname : p -> unique_id );
160 if ( p -> startdir ) {
161 strncat ( buffer, " -s ", 1020 );
162 strncat ( buffer, p -> startdir, 1020 );
165 // args (regular args, for pnd_run.sh to handle)
166 if ( p -> execargs ) {
167 char argbuf [ 1024 ];
168 snprintf ( argbuf, 1000, " -a \"%s\"", p -> execargs );
169 strncat ( buffer, argbuf, 1020 );
173 if ( p -> clockspeed && atoi ( p -> clockspeed ) != 0 ) {
174 strncat ( buffer, " -c ", 1020 );
175 strncat ( buffer, p -> clockspeed, 1020 );
179 if ( pnd_pxml_get_x11 ( p -> option_no_x11 ) == pnd_pxml_x11_stop ) {
180 strncat ( buffer, " -x ", 1020 );
183 // args (dashdash -- args, that the shell can screw with before pnd_run.sh gets them)
184 if ( p -> exec_dashdash_args ) {
185 char argbuf [ 4096 ];
186 snprintf ( argbuf, 4096, " -- %s", p -> exec_dashdash_args );
187 strncat ( buffer, argbuf, 4096 );
191 strncat ( buffer, "\n", 1020 );
194 fprintf ( f, "%s", buffer );
196 // and lets copy in some stuff in case it makes .desktop consumers life easier
197 if ( p -> exec ) { fprintf ( f, "X-Pandora-Exec=%s\n", p -> exec ); }
198 if ( p -> appdata_dirname ) { fprintf ( f, "X-Pandora-Appdata-Dirname=%s\n", p -> appdata_dirname ); }
199 if ( p -> execargs ) { fprintf ( f, "X-Pandora-ExecArgs=%s\n", p -> execargs ); }
200 if ( p -> object_flags & PND_DISCO_FLAG_OVR ) { fprintf ( f, "X-Pandora-Object-Flag-OVR=%s\n", "Yes" ); }
201 if ( p -> object_type == pnd_object_type_pnd ) {
202 fprintf ( f, "X-Pandora-Object-Path=%s\n", p -> object_path );
203 fprintf ( f, "X-Pandora-Object-Filename=%s\n", p -> object_filename );
210 char cats [ 512 ] = "";
216 // "Application" used to be in the standard and is commonly supported still
217 // Utility and Network should ensure the app is visible 'somewhere' :/
218 char *defaults = PND_DOTDESKTOP_DEFAULT_CATEGORY;
220 // determine searchpath (for conf, not for apps)
221 confpath = pnd_conf_query_searchpath();
223 // inhale the conf file
224 c = pnd_conf_fetch_by_id ( pnd_conf_categories, confpath );
226 // if we can find a default category set, pull it in; otherwise assume
228 if ( pnd_conf_get_as_char ( c, "default" ) ) {
229 defaults = pnd_conf_get_as_char ( c, "default" );
232 // ditch the confpath
238 n = pnd_map_dotdesktop_categories ( c, cats, 511, p );
241 fprintf ( f, "Categories=%s\n", cats );
243 fprintf ( f, "Categories=%s\n", defaults );
247 fprintf ( f, "Categories=%s\n", defaults );
252 fprintf ( f, "%s\n", PND_DOTDESKTOP_SOURCE ); // should we need to know 'who' created the file during trimming
259 unsigned char pnd_emit_dotinfo ( char *targetpath, char *pndrun, pnd_disco_t *p ) {
260 char filename [ FILENAME_MAX ];
261 char buffer [ 1024 ];
263 char *viewer, *searchpath;
264 pnd_conf_handle desktoph;
267 // http://standards.freedesktop.org/desktop-entry-spec
273 searchpath = pnd_conf_query_searchpath();
275 desktoph = pnd_conf_fetch_by_id ( pnd_conf_desktop, searchpath );
281 viewer = pnd_conf_get_as_char ( desktoph, "info.viewer" );
284 return ( 0 ); // no way to view the file
288 if ( ! p -> unique_id ) {
289 pnd_log ( PND_LOG_DEFAULT, "Can't emit dotdesktop for %s, missing unique-id\n", targetpath );
293 if ( ! p -> info_filename ) {
294 pnd_log ( PND_LOG_DEFAULT, "Can't emit dotdesktop for %s, missing info_filename\n", targetpath );
298 if ( ! p -> info_name ) {
299 pnd_log ( PND_LOG_DEFAULT, "Can't emit dotdesktop for %s, missing info_name\n", targetpath );
303 if ( ! targetpath ) {
304 pnd_log ( PND_LOG_DEFAULT, "Can't emit dotdesktop for %s, missing target path\n", targetpath );
309 pnd_log ( PND_LOG_DEFAULT, "Can't emit dotdesktop for %s, missing pnd_run.sh\n", targetpath );
315 sprintf ( filename, "%s/%s#%uinfo.desktop", targetpath, p -> unique_id, p -> subapp_number );
319 f = fopen ( filename, "w" );
325 fprintf ( f, "%s\n", PND_DOTDESKTOP_HEADER );
327 if ( p -> info_name ) {
328 snprintf ( buffer, 1020, "Name=%s\n", p -> info_name );
329 fprintf ( f, "%s", buffer );
332 fprintf ( f, "Type=Application\n" );
333 fprintf ( f, "Version=1.0\n" );
337 snprintf ( buffer, 1020, "Icon=%s\n", p -> icon );
338 fprintf ( f, "%s", buffer );
342 if ( p -> unique_id ) {
343 fprintf ( f, "X-Pandora-UID=%s\n", p -> unique_id );
346 if ( p -> title_en && p -> title_en [ 0 ] ) {
347 snprintf ( buffer, 1020, "Comment=Automatic menu info entry for %s\n", p -> title_en );
348 fprintf ( f, "%s", buffer );
351 #if 0 // we let pnd_run.sh command line handle this instead of in .desktop
352 if ( p -> startdir ) {
353 snprintf ( buffer, 1020, "Path=%s\n", p -> startdir );
354 fprintf ( f, "%s", buffer );
356 fprintf ( f, "Path=%s\n", PND_DEFAULT_WORKDIR );
363 char *viewerargs = pnd_conf_get_as_char ( desktoph, "info.viewer_args" );
364 if ( viewerargs && viewerargs [ 0 ] ) {
365 snprintf ( pargs, 1001, "%s %s",
366 pnd_conf_get_as_char ( desktoph, "info.viewer_args" ), p -> info_filename );
369 // WARNING: This might not be quite right; if no viewer-args, shouldn't we still append the info-filename? likewise,
370 // even if we do have view-args, shouldn't we check if filename is present?
373 char pndfile [ 1024 ];
374 if ( p -> object_type == pnd_object_type_directory ) {
375 // for PXML-app-dir, pnd_run.sh doesn't want the PXML.xml.. it just wants the dir-name
376 strncpy ( pndfile, p -> object_path, 1000 );
377 } else if ( p -> object_type == pnd_object_type_pnd ) {
378 // pnd_run.sh wants the full path and filename for the .pnd file
379 snprintf ( pndfile, 1020, "%s/%s", p -> object_path, p -> object_filename );
382 pnd_apps_exec_info_t info;
383 info.viewer = viewer;
386 if ( ! pnd_apps_exec_disco ( pndrun, p, PND_EXEC_OPTION_NORUN | PND_EXEC_OPTION_INFO, &info ) ) {
390 fprintf ( f, "Exec=%s\n", pnd_apps_exec_runline() );
392 if ( pnd_conf_get_as_char ( desktoph, "info.category" ) ) {
393 fprintf ( f, "Categories=%s\n", pnd_conf_get_as_char ( desktoph, "info.category" ) );
395 fprintf ( f, "Categories=Documentation\n" );
398 fprintf ( f, "%s\n", PND_DOTDESKTOP_SOURCE ); // should we need to know 'who' created the file during trimming
405 unsigned char pnd_emit_icon ( char *targetpath, pnd_disco_t *p ) {
406 //#define BITLEN (8*1024)
407 #define BITLEN (64*1024)
408 char buffer [ FILENAME_MAX ]; // target filename
409 char from [ FILENAME_MAX ]; // source filename
410 unsigned char bits [ BITLEN ];
414 // prelim .. if a pnd file, and no offset found, discovery code didn't locate icon.. so bail.
415 if ( ( p -> object_type == pnd_object_type_pnd ) &&
416 ( ! p -> pnd_icon_pos ) )
418 return ( 0 ); // discover code didn't find it, so FAIL
421 // determine filename for target
422 sprintf ( buffer, "%s/%s.png", targetpath, p -> unique_id /*, p -> subapp_number*/ ); // target
424 /* first.. open the source file, by type of application:
425 * are we looking through a pnd file or a dir?
427 if ( p -> object_type == pnd_object_type_directory ) {
428 sprintf ( from, "%s/%s", p -> object_path, p -> icon );
429 } else if ( p -> object_type == pnd_object_type_pnd ) {
430 sprintf ( from, "%s/%s", p -> object_path, p -> object_filename );
433 pnd = fopen ( from, "rb" );
436 pnd_log ( PND_LOG_DEFAULT, " Emit icon, couldn't open source\n" );
442 target = fopen ( buffer, "wb" );
446 pnd_log ( PND_LOG_DEFAULT, " Emit icon, couldn't open target\n" );
450 fseek ( pnd, 0, SEEK_END );
452 //fseek ( pnd, 0, SEEK_SET );
454 fseek ( pnd, p -> pnd_icon_pos, SEEK_SET );
456 len -= p -> pnd_icon_pos;
458 pnd_log ( PND_LOG_DEFAULT, " Emit icon, length: %u\n", len );
462 if ( len > (BITLEN) ) {
468 if ( fread ( bits, bitlen, 1, pnd ) != 1 ) {
472 pnd_log ( PND_LOG_DEFAULT, " Emit icon, bad read\n" );
479 char bigbuffer [ 200 * 1024 ] = "\0";
481 pnd_log ( PND_LOG_DEFAULT, " Read hexdump\n" );
482 while ( i < bitlen ) {
483 sprintf ( b, "%x,", bits [ i ] );
484 strcat ( bigbuffer, b );
487 pnd_log ( PND_LOG_DEFAULT, bigbuffer );
491 if ( fwrite ( bits, bitlen, 1, target ) != 1 ) {
495 pnd_log ( PND_LOG_DEFAULT, " Emit icon, bad write\n" );
500 //pnd_log ( PND_LOG_DEFAULT, " Emit icon, next block, length: %u\n", len );
506 //pnd_log ( PND_LOG_DEFAULT, " Emit icon, done.\n" );
511 #if 1 // we switched direction to freedesktop standard categories
512 // if no categories herein, return 0; otherwise, if some category-like-text, return 1
513 int pnd_map_dotdesktop_categories ( pnd_conf_handle c, char *target_buffer, unsigned short int len, pnd_disco_t *d ) {
517 // clear target so we can easily append
518 memset ( target_buffer, '\0', len );
520 // for each main-cat and sub-cat, including alternates, just append them all together
521 // we'll try mapping them, since the categories file is there, but we'll default to
522 // copying over; this lets the conf file do merging or renaming of cagtegories, which
523 // could still be useful, but we can leave the conf file empty to effect a pure
524 // trusted-PXML-copying
526 // it would be sort of cumbersome to copy all the freedesktop.org defined categories (as
527 // there are hundreds), and would also mean new ones and peoples custom ones would
530 /* attempt primary category chain
532 #define MAPCAT(field) \
533 if ( ( t = d -> field ) ) { \
534 match = pnd_map_dotdesktop_category ( c, t ); \
535 if ( ( !match ) || ( strcasecmp ( match, "NoCategory" ) ) ) { \
536 strncat ( target_buffer, match ? match : t, len ); \
537 strncat ( target_buffer, ";", len ); \
541 MAPCAT(main_category);
542 MAPCAT(main_category1);
543 MAPCAT(main_category2);
544 MAPCAT(alt_category);
545 MAPCAT(alt_category1);
546 MAPCAT(alt_category2);
548 if ( target_buffer [ 0 ] ) {
549 return ( 1 ); // I guess its 'good'?
553 if ( ( t = d -> main_category ) ) {
554 match = pnd_map_dotdesktop_category ( c, t );
555 strncat ( target_buffer, match ? match : t, len );
556 strncat ( target_buffer, ";", len );
564 #if 0 // we switched direction
565 //int pnd_map_dotdesktop_categories ( pnd_conf_handle c, char *target_buffer, unsigned short int len, pnd_pxml_handle h ) {
566 int pnd_map_dotdesktop_categories ( pnd_conf_handle c, char *target_buffer, unsigned short int len, pnd_disco_t *d ) {
567 unsigned short int n = 0; // no. matches
571 // clear target so we can easily append
572 memset ( target_buffer, '\0', len );
574 /* attempt primary category chain
578 if ( ( t = d -> main_category ) ) {
579 match = pnd_map_dotdesktop_category ( c, t );
583 ( t = d -> main_category1 ) )
585 match = pnd_map_dotdesktop_category ( c, t );
589 ( t = d -> main_category2 ) )
591 match = pnd_map_dotdesktop_category ( c, t );
595 strncat ( target_buffer, match, len );
596 len -= strlen ( target_buffer );
600 /* attempt secondary category chain
604 if ( ( t = d -> alt_category ) ) {
605 match = pnd_map_dotdesktop_category ( c, t );
609 ( t = d -> alt_category1 ) )
611 match = pnd_map_dotdesktop_category ( c, t );
615 ( t = d -> alt_category2 ) )
617 match = pnd_map_dotdesktop_category ( c, t );
621 if ( target_buffer [ 0 ] != '\0' && len > 0 ) {
622 strcat ( target_buffer, ";" );
625 strncat ( target_buffer, match, len );
626 len -= strlen ( target_buffer );
630 #if 0 // doh, originally I was using pxml-t till I realized I pre-boned myself on that one
633 if ( ( t = pnd_pxml_get_main_category ( h ) ) ) {
634 match = pnd_map_dotdesktop_category ( c, t );
638 ( t = pnd_pxml_get_subcategory1 ( h ) ) )
640 match = pnd_map_dotdesktop_category ( c, t );
644 ( t = pnd_pxml_get_subcategory2 ( h ) ) )
646 match = pnd_map_dotdesktop_category ( c, t );
650 strncat ( target_buffer, match, len );
651 len -= strlen ( target_buffer );
655 /* attempt secondary category chain
659 if ( ( t = pnd_pxml_get_altcategory ( h ) ) ) {
660 match = pnd_map_dotdesktop_category ( c, t );
664 ( t = pnd_pxml_get_altsubcategory1 ( h ) ) )
666 match = pnd_map_dotdesktop_category ( c, t );
670 ( t = pnd_pxml_get_altsubcategory2 ( h ) ) )
672 match = pnd_map_dotdesktop_category ( c, t );
676 if ( target_buffer [ 0 ] != '\0' && len > 0 ) {
677 strcat ( target_buffer, ";" );
680 strncat ( target_buffer, match, len );
681 len -= strlen ( target_buffer );
687 strcat ( target_buffer, ";" );
694 // given category 'foo', look it up in the provided config map. return the char* reference, or NULL
695 char *pnd_map_dotdesktop_category ( pnd_conf_handle c, char *single_category ) {
699 key = malloc ( strlen ( single_category ) + 4 + 1 );
701 sprintf ( key, "map.%s", single_category );
703 ret = pnd_conf_get_as_char ( c, key );
710 unsigned char *pnd_emit_icon_to_buffer ( pnd_disco_t *p, unsigned int *r_buflen ) {
711 // this is shamefully mostly a copy of emit_icon() above; really, need to refactor that to use this routine
712 // with a fwrite at the end...
713 char from [ FILENAME_MAX ]; // source filename
714 char bits [ 8 * 1024 ];
717 unsigned char *target = NULL, *targiter = NULL;
719 // prelim .. if a pnd file, and no offset found, discovery code didn't locate icon.. so bail.
720 if ( ( p -> object_type == pnd_object_type_pnd ) &&
721 ( ! p -> pnd_icon_pos ) )
723 return ( NULL ); // discover code didn't find it, so FAIL
726 /* first.. open the source file, by type of application:
727 * are we looking through a pnd file or a dir?
729 if ( p -> object_type == pnd_object_type_directory ) {
730 sprintf ( from, "%s/%s", p -> object_path, p -> icon );
731 } else if ( p -> object_type == pnd_object_type_pnd ) {
732 sprintf ( from, "%s/%s", p -> object_path, p -> object_filename );
735 pnd = fopen ( from, "r" );
741 // determine length of file, then adjust by icon position to find begin of icon
744 fseek ( pnd, 0, SEEK_END );
746 //fseek ( pnd, 0, SEEK_SET );
748 fseek ( pnd, p -> pnd_icon_pos, SEEK_SET );
750 len -= p -> pnd_icon_pos;
752 // create target buffer
753 target = malloc ( len );
766 // copy over icon to target
769 if ( len > (8*1024) ) {
775 if ( fread ( bits, bitlen, 1, pnd ) != 1 ) {
781 memmove ( targiter, bits, bitlen );
792 // parse_dotdesktop() can be used to read a libpnd generated .desktop and return a limited
793 // but useful disco-t structure back; possibly useful for scanning .desktops rather than
794 // scanning pnd-files?
795 pnd_disco_t *pnd_parse_dotdesktop ( char *ddpath, unsigned int flags ) {
797 // will verify the .desktop has the libpnd-marking on it (X-Pandora-Source): PND_DOTDESKTOP_SOURCE
799 // attempt to extract..
800 // - unique-id (from filename or field)
801 // - subapp number (from filename)
802 // - exec required info
805 // - comment (desc-en)
808 // - appdata name (or unique-id if not present)
814 char pndpath [ 1024 ];
815 bzero ( pndpath, 1024 );
817 // filter on filename?
818 if ( flags & PND_DOTDESKTOP_LIBPND_ONLY ) {
819 // too bad we didn't put some libpnd token at the front of the filename or something
820 // hell, we should cleanse unique-id to ensure its not full of special chars like '*' and '..'.. eep!
821 if ( strrchr ( ddpath, '#' ) == NULL ) { // but if requiring libpnd, we can at least check for #subapp-number
826 if ( strstr ( ddpath, ".desktop" ) == NULL ) {
827 return ( NULL ); // no .desktop in filename, must be something else... skip!
830 if ( strstr ( ddpath, "info.desktop" ) != NULL ) {
831 // ".....info.desktop" is the 'document help' (README) emitted from a pnd, not an actual app; minimenu rather
832 // expects the doc-info as part of the main app, not a separate app.. so lets drop it here, to avoid doubling up
833 // the number of applications, needlessly..
837 // determine file length
840 if ( stat ( ddpath, &statbuf) < 0 ) {
841 return ( NULL ); // couldn't open
846 unsigned char libpnd_origin = 0;
849 pnd_disco_t *p = malloc ( sizeof(pnd_disco_t) );
853 bzero ( p, sizeof(pnd_disco_t) );
856 FILE *f = fopen ( ddpath, "r" );
859 return ( NULL ); // not up or shut up!
862 while ( fgets ( dd, 1024, f ) ) {
863 char *nl = strchr ( dd, '\n' );
871 if ( strncmp ( dd, "Name=", 5 ) == 0 ) {
872 p -> title_en = strdup ( dd + 5 );
873 } else if ( strncmp ( dd, "Name[en]=", 9 ) == 0 ) {
874 p -> title_en = strdup ( dd + 9 );
875 } else if ( strncmp ( dd, "Icon=", 5 ) == 0 ) {
876 p -> icon = strdup ( dd + 5 );
877 } else if ( strcmp ( dd, PND_DOTDESKTOP_SOURCE ) == 0 ) {
879 } else if ( strncmp ( dd, "X-Pandora-UID=", 14 ) == 0 ) {
880 p -> unique_id = strdup ( dd + 14 );
881 } else if ( strncmp ( dd, "X-Pandora-Preview-Pic-1=", 24 ) == 0 ) {
882 p -> preview_pic1 = strdup ( dd + 24 );
883 } else if ( strncmp ( dd, "X-Pandora-Clockspeed=", 21 ) == 0 ) {
884 p -> clockspeed = strdup ( dd + 21 );
885 } else if ( strncmp ( dd, "X-Pandora-Startdir=", 19 ) == 0 ) {
886 p -> startdir = strdup ( dd + 19 );
887 } else if ( strncmp ( dd, "X-Pandora-Appdata-Dirname=", 26 ) == 0 ) {
888 p -> appdata_dirname = strdup ( dd + 26 );
889 } else if ( strncmp ( dd, "X-Pandora-ExecArgs=", 19 ) == 0 ) {
890 p -> execargs = strdup ( dd + 19 );
891 } else if ( strncmp ( dd, "X-Pandora-Exec=", 15 ) == 0 ) {
892 p -> exec = strdup ( dd + 15 );
893 } else if ( strncmp ( dd, "X-Pandora-Object-Path=", 22 ) == 0 ) {
894 p -> object_path = strdup ( dd + 22 );
895 } else if ( strncmp ( dd, "X-Pandora-Object-Filename=", 26 ) == 0 ) {
896 p -> object_filename = strdup ( dd + 26 );
897 } else if ( strncmp ( dd, "X-Pandora-Object-Flag-OVR=", 26 ) == 0 ) {
898 p -> object_flags |= PND_DISCO_FLAG_OVR;
900 } else if ( strncmp ( dd, "X-Pandora-MainCategory=", 23 ) == 0 ) {
901 p -> main_category = strdup ( dd + 23 );
902 } else if ( strncmp ( dd, "X-Pandora-MainCategory1=", 24 ) == 0 ) {
903 p -> main_category1 = strdup ( dd + 24 );
904 } else if ( strncmp ( dd, "X-Pandora-MainCategory2=", 24 ) == 0 ) {
905 p -> main_category2 = strdup ( dd + 24 );
907 } else if ( strncmp ( dd, "X-Pandora-AltCategory=", 22 ) == 0 ) {
908 p -> alt_category = strdup ( dd + 22 );
909 } else if ( strncmp ( dd, "X-Pandora-AltCategory1=", 23 ) == 0 ) {
910 p -> alt_category1 = strdup ( dd + 23 );
911 } else if ( strncmp ( dd, "X-Pandora-AltCategory2=", 23 ) == 0 ) {
912 p -> alt_category2 = strdup ( dd + 23 );
914 } else if ( strncmp ( dd, "X-Pandora-Info-Filename=", 24 ) == 0 ) {
915 p -> info_filename = strdup ( dd + 24 );
916 } else if ( strncmp ( dd, "X-Pandora-Info-Name=", 20 ) == 0 ) {
917 p -> info_name = strdup ( dd + 20 );
919 } else if ( strncmp ( dd, "Comment=", 8 ) == 0 ) {
920 p -> desc_en = strdup ( dd + 8 );
921 } else if ( strncmp ( dd, "Comment[en]=", 12 ) == 0 ) {
922 p -> desc_en = strdup ( dd + 12 );
923 } else if ( strncmp ( dd, "Exec=", 5 ) == 0 ) {
925 char *e = strstr ( dd, " -e " );
928 // probably libpnd app
929 #if 0 // no needed due to above X-Pandora attributes
934 char *space = strchr ( e, ' ' );
935 p -> exec = strndup ( e, space - e - 1 );
938 char *b = strstr ( dd, " -b " );
941 char *space = strchr ( b, '\0' );
942 p -> appdata_dirname = strndup ( b, space - b - 1 );
945 char *p = strstr ( dd, " -p " );
948 char *space = strchr ( p, ' ' );
949 strncpy ( pndpath, p, space - p - 1 );
954 // probably not libpnd app
955 p -> exec = strdup ( dd + 5 );
958 #if 0 // ignore; using X- categories now
959 } else if ( strncmp ( dd, "Categories=", 11 ) == 0 ) {
960 // HACK; only honours first category
961 char *semi = strchr ( dd, ';' );
963 p -> main_category = strndup ( dd + 11, semi - dd + 11 );
965 p -> main_category = strdup ( dd + 11 );
967 semi = strchr ( p -> main_category, ';' );
983 if ( ! libpnd_origin ) {
986 if ( flags & PND_DOTDESKTOP_LIBPND_ONLY ) {
987 pnd_disco_destroy ( p );
993 p -> object_flags |= PND_DISCO_LIBPND_DD; // so caller can do something if it wishes
997 if ( ( ! p -> title_en ) ||
1001 pnd_disco_destroy ( p );
1006 if ( ! p -> unique_id ) {
1007 if ( flags & PND_DOTDESKTOP_LIBPND_ONLY ) {
1008 pnd_disco_destroy ( p );
1013 snprintf ( hack, 100, "inode-%lu", statbuf.st_ino );
1014 p -> unique_id = strdup ( hack );
1019 p -> object_type = pnd_object_type_pnd;
1021 #if 0 // nolonger needed due to above X-Pandora attributes
1023 if ( pndpath [ 0 ] ) {
1029 char *slash = strrchr ( source, '/' );
1031 p -> object_path = strndup ( source, slash - source );
1032 p -> object_filename = strdup ( slash + 1 );
1034 p -> object_path = "./";
1035 p -> object_filename = strdup ( source );
1039 // lame guards, in case of lazy consumers and broken .desktop files
1040 if ( p -> object_path == NULL ) {
1041 p -> object_path = strdup ( "/tmp" );
1043 if ( p -> object_filename == NULL ) {
1044 p -> object_filename = strdup ( "" ); // force bad filename