From 299fb2fd943564f5406a18ebf36ee9e307cbb1c3 Mon Sep 17 00:00:00 2001 From: skeezix Date: Mon, 21 Dec 2009 12:33:28 -0500 Subject: [PATCH] Added Comment= to .desktop emitted files, if description_en is present Switched up category handling code, so it just blindly copies categories from PXML.xml to .desktop --- deployment/etc/pandora/conf/categories | 26 +++++------- lib/pnd_desktop.c | 59 ++++++++++++++++++++++++-- testdata/conf/categories | 27 +++++------- 3 files changed, 78 insertions(+), 34 deletions(-) diff --git a/deployment/etc/pandora/conf/categories b/deployment/etc/pandora/conf/categories index 1291793..1806448 100644 --- a/deployment/etc/pandora/conf/categories +++ b/deployment/etc/pandora/conf/categories @@ -2,26 +2,22 @@ # Open Pandora # dotdesktop configuration -# this config file maps 'PXML' categories to free-desktop standard categories -# ie: category 'Foo' could map to more standard 'Utility', thus making .desktop file -# emitting a more useful thing +# this conf file maps categories from PXML to categories emitted into .desktop files + +# in theory, this file could/should be empty, meaning that whatever categories are in +# PXML we implicitly copy over to .desktop (all of them, including subcats.) We rather +# assume the PXML.xml authors/tools will keep to useful freedesktop defined cats, and +# if not the desktop environment will have behaviour to deal with rogue cats. + +# you can use this file to merge categories, or categories, or create your own +# categories in PXML that in turn map back to freedesktop cats, etc. + +# if PXML.xml doesn't seem to include any cats, the default below is used. # the standard listing of categories is: # http://standards.freedesktop.org/menu-spec/latest/apa.html -# note that 'map' section in the config is _required_ for a match to be found; this -# is done to separate categories from (future) top-level directives - default Application;Utility;Network; [map] Development Development -Education Education -Games Game -Graphics Graphics -Internet Network -Multimedia AudioVideo -Office Office -Settings Settings -System System -Utilities Utility diff --git a/lib/pnd_desktop.c b/lib/pnd_desktop.c index 3760fba..f8ea3d7 100644 --- a/lib/pnd_desktop.c +++ b/lib/pnd_desktop.c @@ -67,9 +67,9 @@ unsigned char pnd_emit_dotdesktop ( char *targetpath, char *pndrun, pnd_disco_t fprintf ( f, "%s", buffer ); } -#if 0 - if ( p -> description_en ) { - snprintf ( buffer, 1020, "Comment=%s\n", p -> description_en ); +#if 1 + if ( p -> desc_en && p -> desc_en [ 0 ] ) { + snprintf ( buffer, 1020, "Comment=%s\n", p -> desc_en ); // no [en] needed I suppose, yet fprintf ( f, "%s", buffer ); } #endif @@ -250,6 +250,58 @@ unsigned char pnd_emit_icon ( char *targetpath, pnd_disco_t *p ) { return ( 1 ); } +#if 1 // we switched direction to freedesktop standard categories +// if no categories herein, return 0; otherwise, if some category-like-text, return 1 +int pnd_map_dotdesktop_categories ( pnd_conf_handle c, char *target_buffer, unsigned short int len, pnd_disco_t *d ) { + char *t; + char *match; + + // clear target so we can easily append + memset ( target_buffer, '\0', len ); + + // for each main-cat and sub-cat, including alternates, just append them all together + // we'll try mapping them, since the categories file is there, but we'll default to + // copying over; this lets the conf file do merging or renaming of cagtegories, which + // could still be useful, but we can leave the conf file empty to effect a pure + // trusted-PXML-copying + + // it would be sort of cumbersome to copy all the freedesktop.org defined categories (as + // there are hundreds), and would also mean new ones and peoples custom ones would + // flop + + /* attempt primary category chain + */ + #define MAPCAT(field) \ + if ( ( t = d -> field ) ) { \ + match = pnd_map_dotdesktop_category ( c, t ); \ + strncat ( target_buffer, match ? match : t, len ); \ + strncat ( target_buffer, ";", len ); \ + } + + MAPCAT(main_category); + MAPCAT(main_category1); + MAPCAT(main_category2); + MAPCAT(alt_category); + MAPCAT(alt_category1); + MAPCAT(alt_category2); + + if ( target_buffer [ 0 ] ) { + return ( 1 ); // I guess its 'good'? + } + +#if 0 + if ( ( t = d -> main_category ) ) { + match = pnd_map_dotdesktop_category ( c, t ); + strncat ( target_buffer, match ? match : t, len ); + strncat ( target_buffer, ";", len ); + } +#endif + + return ( 0 ); +} +#endif + +#if 0 // we switched direction //int pnd_map_dotdesktop_categories ( pnd_conf_handle c, char *target_buffer, unsigned short int len, pnd_pxml_handle h ) { int pnd_map_dotdesktop_categories ( pnd_conf_handle c, char *target_buffer, unsigned short int len, pnd_disco_t *d ) { unsigned short int n = 0; // no. matches @@ -377,6 +429,7 @@ int pnd_map_dotdesktop_categories ( pnd_conf_handle c, char *target_buffer, unsi return ( n ); } +#endif // given category 'foo', look it up in the provided config map. return the char* reference, or NULL char *pnd_map_dotdesktop_category ( pnd_conf_handle c, char *single_category ) { diff --git a/testdata/conf/categories b/testdata/conf/categories index 1d09696..1806448 100644 --- a/testdata/conf/categories +++ b/testdata/conf/categories @@ -2,27 +2,22 @@ # Open Pandora # dotdesktop configuration -# this config file maps 'PXML' categories to free-desktop standard categories -# ie: category 'Foo' could map to more standard 'Utility', thus making .desktop file -# emitting a more useful thing +# this conf file maps categories from PXML to categories emitted into .desktop files + +# in theory, this file could/should be empty, meaning that whatever categories are in +# PXML we implicitly copy over to .desktop (all of them, including subcats.) We rather +# assume the PXML.xml authors/tools will keep to useful freedesktop defined cats, and +# if not the desktop environment will have behaviour to deal with rogue cats. + +# you can use this file to merge categories, or categories, or create your own +# categories in PXML that in turn map back to freedesktop cats, etc. + +# if PXML.xml doesn't seem to include any cats, the default below is used. # the standard listing of categories is: # http://standards.freedesktop.org/menu-spec/latest/apa.html -# note that 'map' section in the config is _required_ for a match to be found; this -# is done to separate categories from (future) top-level directives - default Application;Utility;Network; [map] -Subcategory1 Graphics Development Development -Education Education -Games Game -Graphics Graphics -Internet Network -Multimedia AudioVideo -Office Office -Settings Settings -System System -Utilities Utility -- 2.39.5