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 );
119 #if 0 // we let pnd_run.sh command line handle this instead of in .desktop
120 if ( p -> startdir ) {
121 snprintf ( buffer, 1020, "Path=%s\n", p -> startdir );
122 fprintf ( f, "%s", buffer );
124 fprintf ( f, "Path=%s\n", PND_DEFAULT_WORKDIR );
131 if ( p -> option_no_x11 ) {
132 nohup = "/usr/bin/nohup ";
138 if ( p -> object_type == pnd_object_type_directory ) {
139 snprintf ( buffer, 1020, "Exec=%s%s -p \"%s\" -e \"%s\" -b \"%s\"",
140 nohup, pndrun, p -> object_path, p -> exec,
141 p -> appdata_dirname ? p -> appdata_dirname : p -> unique_id );
142 } else if ( p -> object_type == pnd_object_type_pnd ) {
143 snprintf ( buffer, 1020, "Exec=%s%s -p \"%s/%s\" -e \"%s\" -b \"%s\"",
144 nohup, pndrun, p -> object_path, p -> object_filename, p -> exec,
145 p -> appdata_dirname ? p -> appdata_dirname : p -> unique_id );
149 if ( p -> startdir ) {
150 strncat ( buffer, " -s ", 1020 );
151 strncat ( buffer, p -> startdir, 1020 );
155 if ( p -> execargs ) {
156 char argbuf [ 1024 ];
157 snprintf ( argbuf, 1000, " -a \"%s\"", p -> execargs );
158 strncat ( buffer, argbuf, 1020 );
162 if ( p -> clockspeed && atoi ( p -> clockspeed ) != 0 ) {
163 strncat ( buffer, " -c ", 1020 );
164 strncat ( buffer, p -> clockspeed, 1020 );
168 if ( pnd_pxml_get_x11 ( p -> option_no_x11 ) == pnd_pxml_x11_stop ) {
169 strncat ( buffer, " -x ", 1020 );
173 strncat ( buffer, "\n", 1020 );
176 fprintf ( f, "%s", buffer );
178 // and lets copy in some stuff in case it makes .desktop consumers life easier
179 if ( p -> exec ) { fprintf ( f, "X-Pandora-Exec=%s\n", p -> exec ); }
180 if ( p -> appdata_dirname ) { fprintf ( f, "X-Pandora-Appdata-Dirname=%s\n", p -> appdata_dirname ); }
181 if ( p -> execargs ) { fprintf ( f, "X-Pandora-ExecArgs=%s\n", p -> execargs ); }
182 if ( p -> object_flags & PND_DISCO_FLAG_OVR ) { fprintf ( f, "X-Pandora-Object-Flag-OVR=%s\n", "Yes" ); }
183 if ( p -> object_type == pnd_object_type_pnd ) {
184 fprintf ( f, "X-Pandora-Object-Path=%s\n", p -> object_path );
185 fprintf ( f, "X-Pandora-Object-Filename=%s\n", p -> object_filename );
192 char cats [ 512 ] = "";
198 // "Application" used to be in the standard and is commonly supported still
199 // Utility and Network should ensure the app is visible 'somewhere' :/
200 char *defaults = PND_DOTDESKTOP_DEFAULT_CATEGORY;
202 // determine searchpath (for conf, not for apps)
203 confpath = pnd_conf_query_searchpath();
205 // inhale the conf file
206 c = pnd_conf_fetch_by_id ( pnd_conf_categories, confpath );
208 // if we can find a default category set, pull it in; otherwise assume
210 if ( pnd_conf_get_as_char ( c, "default" ) ) {
211 defaults = pnd_conf_get_as_char ( c, "default" );
214 // ditch the confpath
220 n = pnd_map_dotdesktop_categories ( c, cats, 511, p );
223 fprintf ( f, "Categories=%s\n", cats );
225 fprintf ( f, "Categories=%s\n", defaults );
229 fprintf ( f, "Categories=%s\n", defaults );
234 fprintf ( f, "%s\n", PND_DOTDESKTOP_SOURCE ); // should we need to know 'who' created the file during trimming
241 unsigned char pnd_emit_dotinfo ( char *targetpath, char *pndrun, pnd_disco_t *p ) {
242 char filename [ FILENAME_MAX ];
243 char buffer [ 1024 ];
245 char *viewer, *searchpath;
246 pnd_conf_handle desktoph;
249 // http://standards.freedesktop.org/desktop-entry-spec
255 searchpath = pnd_conf_query_searchpath();
257 desktoph = pnd_conf_fetch_by_id ( pnd_conf_desktop, searchpath );
263 viewer = pnd_conf_get_as_char ( desktoph, "info.viewer" );
266 return ( 0 ); // no way to view the file
270 if ( ! p -> unique_id ) {
271 pnd_log ( PND_LOG_DEFAULT, "Can't emit dotdesktop for %s, missing unique-id\n", targetpath );
275 if ( ! p -> info_filename ) {
276 pnd_log ( PND_LOG_DEFAULT, "Can't emit dotdesktop for %s, missing info_filename\n", targetpath );
280 if ( ! p -> info_name ) {
281 pnd_log ( PND_LOG_DEFAULT, "Can't emit dotdesktop for %s, missing info_name\n", targetpath );
285 if ( ! targetpath ) {
286 pnd_log ( PND_LOG_DEFAULT, "Can't emit dotdesktop for %s, missing target path\n", targetpath );
291 pnd_log ( PND_LOG_DEFAULT, "Can't emit dotdesktop for %s, missing pnd_run.sh\n", targetpath );
297 sprintf ( filename, "%s/%s#%uinfo.desktop", targetpath, p -> unique_id, p -> subapp_number );
301 f = fopen ( filename, "w" );
307 fprintf ( f, "%s\n", PND_DOTDESKTOP_HEADER );
309 if ( p -> info_name ) {
310 snprintf ( buffer, 1020, "Name=%s\n", p -> info_name );
311 fprintf ( f, "%s", buffer );
314 fprintf ( f, "Type=Application\n" );
315 fprintf ( f, "Version=1.0\n" );
319 snprintf ( buffer, 1020, "Icon=%s\n", p -> icon );
320 fprintf ( f, "%s", buffer );
324 if ( p -> unique_id ) {
325 fprintf ( f, "X-Pandora-UID=%s\n", p -> unique_id );
328 if ( p -> title_en && p -> title_en [ 0 ] ) {
329 snprintf ( buffer, 1020, "Comment=Automatic menu info entry for %s\n", p -> title_en );
330 fprintf ( f, "%s", buffer );
333 #if 0 // we let pnd_run.sh command line handle this instead of in .desktop
334 if ( p -> startdir ) {
335 snprintf ( buffer, 1020, "Path=%s\n", p -> startdir );
336 fprintf ( f, "%s", buffer );
338 fprintf ( f, "Path=%s\n", PND_DEFAULT_WORKDIR );
345 char *viewerargs = pnd_conf_get_as_char ( desktoph, "info.viewer_args" );
346 if ( viewerargs && viewerargs [ 0 ] ) {
347 snprintf ( pargs, 1001, "%s %s",
348 pnd_conf_get_as_char ( desktoph, "info.viewer_args" ), p -> info_filename );
351 // WARNING: This might not be quite right; if no viewer-args, shouldn't we still append the info-filename? likewise,
352 // even if we do have view-args, shouldn't we check if filename is present?
355 char pndfile [ 1024 ];
356 if ( p -> object_type == pnd_object_type_directory ) {
357 // for PXML-app-dir, pnd_run.sh doesn't want the PXML.xml.. it just wants the dir-name
358 strncpy ( pndfile, p -> object_path, 1000 );
359 } else if ( p -> object_type == pnd_object_type_pnd ) {
360 // pnd_run.sh wants the full path and filename for the .pnd file
361 snprintf ( pndfile, 1020, "%s/%s", p -> object_path, p -> object_filename );
364 pnd_apps_exec_info_t info;
365 info.viewer = viewer;
368 if ( ! pnd_apps_exec_disco ( pndrun, p, PND_EXEC_OPTION_NORUN | PND_EXEC_OPTION_INFO, &info ) ) {
372 fprintf ( f, "Exec=%s\n", pnd_apps_exec_runline() );
374 if ( pnd_conf_get_as_char ( desktoph, "info.category" ) ) {
375 fprintf ( f, "Categories=%s\n", pnd_conf_get_as_char ( desktoph, "info.category" ) );
377 fprintf ( f, "Categories=Documentation\n" );
380 fprintf ( f, "%s\n", PND_DOTDESKTOP_SOURCE ); // should we need to know 'who' created the file during trimming
387 unsigned char pnd_emit_icon ( char *targetpath, pnd_disco_t *p ) {
388 //#define BITLEN (8*1024)
389 #define BITLEN (64*1024)
390 char buffer [ FILENAME_MAX ]; // target filename
391 char from [ FILENAME_MAX ]; // source filename
392 unsigned char bits [ BITLEN ];
396 // prelim .. if a pnd file, and no offset found, discovery code didn't locate icon.. so bail.
397 if ( ( p -> object_type == pnd_object_type_pnd ) &&
398 ( ! p -> pnd_icon_pos ) )
400 return ( 0 ); // discover code didn't find it, so FAIL
403 // determine filename for target
404 sprintf ( buffer, "%s/%s.png", targetpath, p -> unique_id /*, p -> subapp_number*/ ); // target
406 /* first.. open the source file, by type of application:
407 * are we looking through a pnd file or a dir?
409 if ( p -> object_type == pnd_object_type_directory ) {
410 sprintf ( from, "%s/%s", p -> object_path, p -> icon );
411 } else if ( p -> object_type == pnd_object_type_pnd ) {
412 sprintf ( from, "%s/%s", p -> object_path, p -> object_filename );
415 pnd = fopen ( from, "rb" );
418 pnd_log ( PND_LOG_DEFAULT, " Emit icon, couldn't open source\n" );
424 target = fopen ( buffer, "wb" );
428 pnd_log ( PND_LOG_DEFAULT, " Emit icon, couldn't open target\n" );
432 fseek ( pnd, 0, SEEK_END );
434 //fseek ( pnd, 0, SEEK_SET );
436 fseek ( pnd, p -> pnd_icon_pos, SEEK_SET );
438 len -= p -> pnd_icon_pos;
440 pnd_log ( PND_LOG_DEFAULT, " Emit icon, length: %u\n", len );
444 if ( len > (BITLEN) ) {
450 if ( fread ( bits, bitlen, 1, pnd ) != 1 ) {
454 pnd_log ( PND_LOG_DEFAULT, " Emit icon, bad read\n" );
461 char bigbuffer [ 200 * 1024 ] = "\0";
463 pnd_log ( PND_LOG_DEFAULT, " Read hexdump\n" );
464 while ( i < bitlen ) {
465 sprintf ( b, "%x,", bits [ i ] );
466 strcat ( bigbuffer, b );
469 pnd_log ( PND_LOG_DEFAULT, bigbuffer );
473 if ( fwrite ( bits, bitlen, 1, target ) != 1 ) {
477 pnd_log ( PND_LOG_DEFAULT, " Emit icon, bad write\n" );
482 //pnd_log ( PND_LOG_DEFAULT, " Emit icon, next block, length: %u\n", len );
488 //pnd_log ( PND_LOG_DEFAULT, " Emit icon, done.\n" );
493 #if 1 // we switched direction to freedesktop standard categories
494 // if no categories herein, return 0; otherwise, if some category-like-text, return 1
495 int pnd_map_dotdesktop_categories ( pnd_conf_handle c, char *target_buffer, unsigned short int len, pnd_disco_t *d ) {
499 // clear target so we can easily append
500 memset ( target_buffer, '\0', len );
502 // for each main-cat and sub-cat, including alternates, just append them all together
503 // we'll try mapping them, since the categories file is there, but we'll default to
504 // copying over; this lets the conf file do merging or renaming of cagtegories, which
505 // could still be useful, but we can leave the conf file empty to effect a pure
506 // trusted-PXML-copying
508 // it would be sort of cumbersome to copy all the freedesktop.org defined categories (as
509 // there are hundreds), and would also mean new ones and peoples custom ones would
512 /* attempt primary category chain
514 #define MAPCAT(field) \
515 if ( ( t = d -> field ) ) { \
516 match = pnd_map_dotdesktop_category ( c, t ); \
517 strncat ( target_buffer, match ? match : t, len ); \
518 strncat ( target_buffer, ";", len ); \
521 MAPCAT(main_category);
522 MAPCAT(main_category1);
523 MAPCAT(main_category2);
524 MAPCAT(alt_category);
525 MAPCAT(alt_category1);
526 MAPCAT(alt_category2);
528 if ( target_buffer [ 0 ] ) {
529 return ( 1 ); // I guess its 'good'?
533 if ( ( t = d -> main_category ) ) {
534 match = pnd_map_dotdesktop_category ( c, t );
535 strncat ( target_buffer, match ? match : t, len );
536 strncat ( target_buffer, ";", len );
544 #if 0 // we switched direction
545 //int pnd_map_dotdesktop_categories ( pnd_conf_handle c, char *target_buffer, unsigned short int len, pnd_pxml_handle h ) {
546 int pnd_map_dotdesktop_categories ( pnd_conf_handle c, char *target_buffer, unsigned short int len, pnd_disco_t *d ) {
547 unsigned short int n = 0; // no. matches
551 // clear target so we can easily append
552 memset ( target_buffer, '\0', len );
554 /* attempt primary category chain
558 if ( ( t = d -> main_category ) ) {
559 match = pnd_map_dotdesktop_category ( c, t );
563 ( t = d -> main_category1 ) )
565 match = pnd_map_dotdesktop_category ( c, t );
569 ( t = d -> main_category2 ) )
571 match = pnd_map_dotdesktop_category ( c, t );
575 strncat ( target_buffer, match, len );
576 len -= strlen ( target_buffer );
580 /* attempt secondary category chain
584 if ( ( t = d -> alt_category ) ) {
585 match = pnd_map_dotdesktop_category ( c, t );
589 ( t = d -> alt_category1 ) )
591 match = pnd_map_dotdesktop_category ( c, t );
595 ( t = d -> alt_category2 ) )
597 match = pnd_map_dotdesktop_category ( c, t );
601 if ( target_buffer [ 0 ] != '\0' && len > 0 ) {
602 strcat ( target_buffer, ";" );
605 strncat ( target_buffer, match, len );
606 len -= strlen ( target_buffer );
610 #if 0 // doh, originally I was using pxml-t till I realized I pre-boned myself on that one
613 if ( ( t = pnd_pxml_get_main_category ( h ) ) ) {
614 match = pnd_map_dotdesktop_category ( c, t );
618 ( t = pnd_pxml_get_subcategory1 ( h ) ) )
620 match = pnd_map_dotdesktop_category ( c, t );
624 ( t = pnd_pxml_get_subcategory2 ( h ) ) )
626 match = pnd_map_dotdesktop_category ( c, t );
630 strncat ( target_buffer, match, len );
631 len -= strlen ( target_buffer );
635 /* attempt secondary category chain
639 if ( ( t = pnd_pxml_get_altcategory ( h ) ) ) {
640 match = pnd_map_dotdesktop_category ( c, t );
644 ( t = pnd_pxml_get_altsubcategory1 ( h ) ) )
646 match = pnd_map_dotdesktop_category ( c, t );
650 ( t = pnd_pxml_get_altsubcategory2 ( h ) ) )
652 match = pnd_map_dotdesktop_category ( c, t );
656 if ( target_buffer [ 0 ] != '\0' && len > 0 ) {
657 strcat ( target_buffer, ";" );
660 strncat ( target_buffer, match, len );
661 len -= strlen ( target_buffer );
667 strcat ( target_buffer, ";" );
674 // given category 'foo', look it up in the provided config map. return the char* reference, or NULL
675 char *pnd_map_dotdesktop_category ( pnd_conf_handle c, char *single_category ) {
679 key = malloc ( strlen ( single_category ) + 4 + 1 );
681 sprintf ( key, "map.%s", single_category );
683 ret = pnd_conf_get_as_char ( c, key );
690 unsigned char *pnd_emit_icon_to_buffer ( pnd_disco_t *p, unsigned int *r_buflen ) {
691 // this is shamefully mostly a copy of emit_icon() above; really, need to refactor that to use this routine
692 // with a fwrite at the end...
693 char from [ FILENAME_MAX ]; // source filename
694 char bits [ 8 * 1024 ];
697 unsigned char *target = NULL, *targiter = NULL;
699 // prelim .. if a pnd file, and no offset found, discovery code didn't locate icon.. so bail.
700 if ( ( p -> object_type == pnd_object_type_pnd ) &&
701 ( ! p -> pnd_icon_pos ) )
703 return ( NULL ); // discover code didn't find it, so FAIL
706 /* first.. open the source file, by type of application:
707 * are we looking through a pnd file or a dir?
709 if ( p -> object_type == pnd_object_type_directory ) {
710 sprintf ( from, "%s/%s", p -> object_path, p -> icon );
711 } else if ( p -> object_type == pnd_object_type_pnd ) {
712 sprintf ( from, "%s/%s", p -> object_path, p -> object_filename );
715 pnd = fopen ( from, "r" );
721 // determine length of file, then adjust by icon position to find begin of icon
724 fseek ( pnd, 0, SEEK_END );
726 //fseek ( pnd, 0, SEEK_SET );
728 fseek ( pnd, p -> pnd_icon_pos, SEEK_SET );
730 len -= p -> pnd_icon_pos;
732 // create target buffer
733 target = malloc ( len );
746 // copy over icon to target
749 if ( len > (8*1024) ) {
755 if ( fread ( bits, bitlen, 1, pnd ) != 1 ) {
761 memmove ( targiter, bits, bitlen );
772 // parse_dotdesktop() can be used to read a libpnd generated .desktop and return a limited
773 // but useful disco-t structure back; possibly useful for scanning .desktops rather than
774 // scanning pnd-files?
775 pnd_disco_t *pnd_parse_dotdesktop ( char *ddpath, unsigned int flags ) {
777 // will verify the .desktop has the libpnd-marking on it (X-Pandora-Source): PND_DOTDESKTOP_SOURCE
779 // attempt to extract..
780 // - unique-id (from filename or field)
781 // - subapp number (from filename)
782 // - exec required info
785 // - comment (desc-en)
788 // - appdata name (or unique-id if not present)
794 char pndpath [ 1024 ];
795 bzero ( pndpath, 1024 );
797 // filter on filename?
798 if ( flags & PND_DOTDESKTOP_LIBPND_ONLY ) {
799 // too bad we didn't put some libpnd token at the front of the filename or something
800 // hell, we should cleanse unique-id to ensure its not full of special chars like '*' and '..'.. eep!
801 if ( strrchr ( ddpath, '#' ) == NULL ) { // but if requiring libpnd, we can at least check for #subapp-number
806 if ( strstr ( ddpath, ".desktop" ) == NULL ) {
810 if ( strstr ( ddpath, "info.desktop" ) != NULL ) {
814 // determine file length
817 if ( stat ( ddpath, &statbuf) < 0 ) {
818 return ( NULL ); // couldn't open
823 unsigned char libpnd_origin = 0;
826 pnd_disco_t *p = malloc ( sizeof(pnd_disco_t) );
830 bzero ( p, sizeof(pnd_disco_t) );
833 FILE *f = fopen ( ddpath, "r" );
836 return ( NULL ); // not up or shut up!
839 while ( fgets ( dd, 1024, f ) ) {
840 char *nl = strchr ( dd, '\n' );
848 if ( strncmp ( dd, "Name=", 5 ) == 0 ) {
849 p -> title_en = strdup ( dd + 5 );
850 } else if ( strncmp ( dd, "Name[en]=", 9 ) == 0 ) {
851 p -> title_en = strdup ( dd + 9 );
852 } else if ( strncmp ( dd, "Icon=", 5 ) == 0 ) {
853 p -> icon = strdup ( dd + 5 );
854 } else if ( strcmp ( dd, PND_DOTDESKTOP_SOURCE ) == 0 ) {
856 } else if ( strncmp ( dd, "X-Pandora-UID=", 14 ) == 0 ) {
857 p -> unique_id = strdup ( dd + 14 );
858 } else if ( strncmp ( dd, "X-Pandora-Preview-Pic-1=", 24 ) == 0 ) {
859 p -> preview_pic1 = strdup ( dd + 24 );
860 } else if ( strncmp ( dd, "X-Pandora-Clockspeed=", 21 ) == 0 ) {
861 p -> clockspeed = strdup ( dd + 21 );
862 } else if ( strncmp ( dd, "X-Pandora-Startdir=", 19 ) == 0 ) {
863 p -> startdir = strdup ( dd + 19 );
864 } else if ( strncmp ( dd, "X-Pandora-Appdata-Dirname=", 26 ) == 0 ) {
865 p -> appdata_dirname = strdup ( dd + 26 );
866 } else if ( strncmp ( dd, "X-Pandora-ExecArgs=", 19 ) == 0 ) {
867 p -> execargs = strdup ( dd + 19 );
868 } else if ( strncmp ( dd, "X-Pandora-Exec=", 15 ) == 0 ) {
869 p -> exec = strdup ( dd + 15 );
870 } else if ( strncmp ( dd, "X-Pandora-Object-Path=", 22 ) == 0 ) {
871 p -> object_path = strdup ( dd + 22 );
872 } else if ( strncmp ( dd, "X-Pandora-Object-Filename=", 26 ) == 0 ) {
873 p -> object_filename = strdup ( dd + 26 );
874 } else if ( strncmp ( dd, "X-Pandora-Object-Flag-OVR=", 26 ) == 0 ) {
875 p -> object_flags |= PND_DISCO_FLAG_OVR;
877 } else if ( strncmp ( dd, "X-Pandora-MainCategory=", 23 ) == 0 ) {
878 p -> main_category = strdup ( dd + 23 );
879 } else if ( strncmp ( dd, "X-Pandora-MainCategory1=", 24 ) == 0 ) {
880 p -> main_category1 = strdup ( dd + 24 );
881 } else if ( strncmp ( dd, "X-Pandora-MainCategory2=", 24 ) == 0 ) {
882 p -> main_category2 = strdup ( dd + 24 );
884 } else if ( strncmp ( dd, "X-Pandora-AltCategory=", 22 ) == 0 ) {
885 p -> alt_category = strdup ( dd + 22 );
886 } else if ( strncmp ( dd, "X-Pandora-AltCategory1=", 23 ) == 0 ) {
887 p -> alt_category1 = strdup ( dd + 23 );
888 } else if ( strncmp ( dd, "X-Pandora-AltCategory2=", 23 ) == 0 ) {
889 p -> alt_category2 = strdup ( dd + 23 );
891 } else if ( strncmp ( dd, "Comment=", 8 ) == 0 ) {
892 p -> desc_en = strdup ( dd + 8 );
893 } else if ( strncmp ( dd, "Comment[en]=", 12 ) == 0 ) {
894 p -> desc_en = strdup ( dd + 12 );
895 } else if ( strncmp ( dd, "Exec=", 5 ) == 0 ) {
897 char *e = strstr ( dd, " -e " );
900 // probably libpnd app
901 #if 0 // no needed due to above X-Pandora attributes
906 char *space = strchr ( e, ' ' );
907 p -> exec = strndup ( e, space - e - 1 );
910 char *b = strstr ( dd, " -b " );
913 char *space = strchr ( b, '\0' );
914 p -> appdata_dirname = strndup ( b, space - b - 1 );
917 char *p = strstr ( dd, " -p " );
920 char *space = strchr ( p, ' ' );
921 strncpy ( pndpath, p, space - p - 1 );
926 // probably not libpnd app
927 p -> exec = strdup ( dd + 5 );
930 #if 0 // ignore; using X- categories now
931 } else if ( strncmp ( dd, "Categories=", 11 ) == 0 ) {
932 // HACK; only honours first category
933 char *semi = strchr ( dd, ';' );
935 p -> main_category = strndup ( dd + 11, semi - dd + 11 );
937 p -> main_category = strdup ( dd + 11 );
939 semi = strchr ( p -> main_category, ';' );
955 if ( ! libpnd_origin ) {
958 if ( flags & PND_DOTDESKTOP_LIBPND_ONLY ) {
959 pnd_disco_destroy ( p );
965 p -> object_flags |= PND_DISCO_LIBPND_DD; // so caller can do something if it wishes
969 if ( ( ! p -> title_en ) ||
973 pnd_disco_destroy ( p );
978 if ( ! p -> unique_id ) {
979 if ( flags & PND_DOTDESKTOP_LIBPND_ONLY ) {
980 pnd_disco_destroy ( p );
985 snprintf ( hack, 100, "inode-%lu", statbuf.st_ino );
986 p -> unique_id = strdup ( hack );
991 p -> object_type = pnd_object_type_pnd;
993 #if 0 // nolonger needed due to above X-Pandora attributes
995 if ( pndpath [ 0 ] ) {
1001 char *slash = strrchr ( source, '/' );
1003 p -> object_path = strndup ( source, slash - source );
1004 p -> object_filename = strdup ( slash + 1 );
1006 p -> object_path = "./";
1007 p -> object_filename = strdup ( source );
1011 // lame guards, in case of lazy consumers and broken .desktop files
1012 if ( p -> object_path == NULL ) {
1013 p -> object_path = strdup ( "/tmp" );
1015 if ( p -> object_filename == NULL ) {
1016 p -> object_filename = strdup ( "" ); // force bad filename