From d1dd0db0d1b5149a08a005762e04d4aef2240493 Mon Sep 17 00:00:00 2001 From: skeezix Date: Thu, 7 Mar 2013 23:05:38 -0500 Subject: [PATCH] PXML support for file associations, and spitting out extra .desktop files for them, seems to work --- apps/pndnotifyd.c | 9 +- include/pnd_desktop.h | 8 ++ include/pnd_discovery.h | 9 +- include/pnd_pxml.h | 18 ++-- include/pnd_pxml_names.h | 3 +- lib/pnd_desktop.c | 228 +++++++++++++++++++++++++++++++++++---- lib/pnd_device.c | 1 + lib/pnd_discovery.c | 17 ++- lib/pnd_pxml.c | 48 ++++++--- lib/pnd_tinyxml.cpp | 86 +++++++-------- 10 files changed, 336 insertions(+), 91 deletions(-) diff --git a/apps/pndnotifyd.c b/apps/pndnotifyd.c index 984371b..c488257 100644 --- a/apps/pndnotifyd.c +++ b/apps/pndnotifyd.c @@ -754,13 +754,16 @@ void process_discoveries ( pnd_box_handle applist, char *emitdesktoppath, char * // info .desktop if ( g_info_p && info_dotdesktoppath ) { - if ( pnd_emit_dotinfo ( info_dotdesktoppath, pndrun, d ) ) { - // nada - } else { + if ( ! pnd_emit_dotinfo ( info_dotdesktoppath, pndrun, d ) ) { pnd_log ( pndn_rem, "ERROR: Error creating info .desktop file for app: %s\n", pnd_box_get_key ( d ) ); } } + // file association requests + if ( ! pnd_emit_dotassoc ( info_dotdesktoppath, pndrun, d ) ) { + pnd_log ( pndn_rem, "ERROR: Error creating file association .desktop file for app: %s\n", pnd_box_get_key ( d ) ); + } + // does this object request any mkdir's? if ( d -> mkdir_sp ) { diff --git a/include/pnd_desktop.h b/include/pnd_desktop.h index 3de5627..0729aaa 100644 --- a/include/pnd_desktop.h +++ b/include/pnd_desktop.h @@ -24,6 +24,14 @@ pnd_disco_t *pnd_parse_dotdesktop ( char *ddpath, unsigned int flags ); // sets // extra fields to emit_dotdesktop()'s function and breaking apps, or annoying callers down the road unsigned char pnd_emit_dotinfo ( char *targetpath, char *pndrun, pnd_disco_t *p ); +// emit_dotassoc() will spit out a .desktop executable entry (more or less similar to the emit_dotdesktop above) +// however in this variation the executable line is set up for invokation of a file association instead of the +// normal executable line. +// - lame code is a copy from emit_dotdesktop() .. I really need to clean this up and paramterize a subfunction.. +// - this function will emit all file association .desktops (not just one of them) +unsigned char pnd_emit_dotassoc ( char *targetpath, char *pndrun, pnd_disco_t *p ); +unsigned char _pnd_emit_dotassoc ( char *targetpath, char *pndrun, pnd_disco_t *p, unsigned char i ); // will only emit the requested assoc 1, 2, 3 + // emit_icon() will attempt to copy the icon from a PXML directory, or from a pnd file if appended, // to the given directory; returns 1 on sucess, otherwise is a fail. unsigned char pnd_emit_icon ( char *targetpath, pnd_disco_t *p ); diff --git a/include/pnd_discovery.h b/include/pnd_discovery.h index b296f46..b21bd89 100644 --- a/include/pnd_discovery.h +++ b/include/pnd_discovery.h @@ -93,13 +93,16 @@ typedef struct { // existing above, lets just copy from pxml and use a list of [123] members.. char *associationitem1_name; char *associationitem1_filetype; - char *associationitem1_parameter; // placeholder + char *associationitem1_command; + char *associationitem1_args; char *associationitem2_name; char *associationitem2_filetype; - char *associationitem2_parameter; // placeholder + char *associationitem2_command; + char *associationitem2_args; char *associationitem3_name; char *associationitem3_filetype; - char *associationitem3_parameter; // placeholder + char *associationitem3_command; + char *associationitem3_args; } pnd_disco_t; void pnd_disco_destroy ( pnd_disco_t *p ); // a function name that simply could not be avoided diff --git a/include/pnd_pxml.h b/include/pnd_pxml.h index a7eec6d..d1c8862 100644 --- a/include/pnd_pxml.h +++ b/include/pnd_pxml.h @@ -82,13 +82,16 @@ char *pnd_pxml_get_osversion_release ( pnd_pxml_handle h ); char *pnd_pxml_get_osversion_build ( pnd_pxml_handle h ); char *pnd_pxml_get_associationitem1_name ( pnd_pxml_handle h ); char *pnd_pxml_get_associationitem1_filetype ( pnd_pxml_handle h ); -char *pnd_pxml_get_associationitem1_parameter ( pnd_pxml_handle h ); +char *pnd_pxml_get_associationitem1_command ( pnd_pxml_handle h ); +char *pnd_pxml_get_associationitem1_args ( pnd_pxml_handle h ); char *pnd_pxml_get_associationitem2_name ( pnd_pxml_handle h ); char *pnd_pxml_get_associationitem2_filetype ( pnd_pxml_handle h ); -char *pnd_pxml_get_associationitem2_parameter ( pnd_pxml_handle h ); +char *pnd_pxml_get_associationitem2_command ( pnd_pxml_handle h ); +char *pnd_pxml_get_associationitem2_args ( pnd_pxml_handle h ); char *pnd_pxml_get_associationitem3_name ( pnd_pxml_handle h ); char *pnd_pxml_get_associationitem3_filetype ( pnd_pxml_handle h ); -char *pnd_pxml_get_associationitem3_parameter ( pnd_pxml_handle h ); +char *pnd_pxml_get_associationitem3_command ( pnd_pxml_handle h ); +char *pnd_pxml_get_associationitem3_args ( pnd_pxml_handle h ); char *pnd_pxml_get_clockspeed ( pnd_pxml_handle h ); char *pnd_pxml_get_background ( pnd_pxml_handle h ); char *pnd_pxml_get_startdir ( pnd_pxml_handle h ); @@ -157,13 +160,13 @@ typedef struct char *osversion_build; char *associationitem1_name; char *associationitem1_filetype; - char *associationitem1_parameter; + char *associationitem1_command; char *associationitem2_name; char *associationitem2_filetype; - char *associationitem2_parameter; + char *associationitem2_command; char *associationitem3_name; char *associationitem3_filetype; - char *associationitem3_parameter; + char *associationitem3_command; char *clockspeed; char *background; char *startdir; @@ -180,6 +183,9 @@ typedef struct char *package_version_minor; char *package_version_release; char *package_version_build; + char *associationitem1_args; // wish it could be above, but that would break existing ABI + char *associationitem2_args; // wish it could be above, but that would break existing ABI + char *associationitem3_args; // wish it could be above, but that would break existing ABI } pnd_pxml_t; diff --git a/include/pnd_pxml_names.h b/include/pnd_pxml_names.h index f3ae64c..e57fe8d 100644 --- a/include/pnd_pxml_names.h +++ b/include/pnd_pxml_names.h @@ -80,13 +80,14 @@ extern "C" { #define PND_PXML_ATTRNAME_SUBCATNAME "name" /* - * + * * */ #define PND_PXML_NODENAME_ASSOCS "associations" #define PND_PXML_ENAME_ASSOC "association" #define PND_PXML_ATTRNAME_ASSOCNAME "name" #define PND_PXML_ATTRNAME_ASSOCFTYPE "filetype" +#define PND_PXML_ATTRNAME_ASSOCCMD "command" #define PND_PXML_ATTRNAME_ASSOCARGS "arguments" /* */ diff --git a/lib/pnd_desktop.c b/lib/pnd_desktop.c index 51de406..d6f48d3 100644 --- a/lib/pnd_desktop.c +++ b/lib/pnd_desktop.c @@ -122,26 +122,6 @@ unsigned char pnd_emit_dotdesktop ( char *targetpath, char *pndrun, pnd_disco_t fprintf ( f, "X-Pandora-Info-Name=%s\n", p -> info_name ); } -#if 1 - if ( p -> associationitem1_name || p -> associationitem2_name || p -> associationitem3_name ) { - pnd_log ( PND_LOG_DEFAULT, " EmitDesktop: Found file association request in PXML (%s)\n", p -> title_en ); - 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" ); - } -#endif - #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 ); @@ -410,6 +390,214 @@ unsigned char pnd_emit_dotinfo ( char *targetpath, char *pndrun, pnd_disco_t *p return ( 1 ); } +unsigned char pnd_emit_dotassoc ( char *targetpath, char *pndrun, pnd_disco_t *p ) { + + if ( p -> associationitem1_command ) { + if ( ! _pnd_emit_dotassoc ( targetpath, pndrun, p, 1 ) ) { + return ( 0 ); + } + } + + if ( p -> associationitem2_command ) { + if ( ! _pnd_emit_dotassoc ( targetpath, pndrun, p, 2 ) ) { + return ( 0 ); + } + } + + if ( p -> associationitem3_command ) { + if ( ! _pnd_emit_dotassoc ( targetpath, pndrun, p, 3 ) ) { + return ( 0 ); + } + } + + return ( 1 ); +} + +unsigned char _pnd_emit_dotassoc ( char *targetpath, char *pndrun, pnd_disco_t *p, unsigned char i ) { + char filename [ FILENAME_MAX ]; + char buffer [ 1024 ]; + FILE *f; + + char *command; + char *args; + char *filetype; + char *mimename; + + if ( i == 1 ) { + command = p -> associationitem1_command; + args = p -> associationitem1_args; + filetype = p -> associationitem1_filetype; + mimename = p -> associationitem1_name; + } else if ( i == 2 ) { + command = p -> associationitem2_command; + args = p -> associationitem2_args; + filetype = p -> associationitem2_filetype; + mimename = p -> associationitem2_name; + } else if ( i == 3 ) { + command = p -> associationitem3_command; + args = p -> associationitem3_args; + filetype = p -> associationitem3_filetype; + mimename = p -> associationitem3_name; + } else { + return ( 0 ); // w-t-f + } + + // specification + // http://standards.freedesktop.org/desktop-entry-spec + + // validation + + if ( ! p -> unique_id ) { + pnd_log ( PND_LOG_DEFAULT, "Can't emit dotdesktop for %s, missing unique-id\n", targetpath ); + return ( 0 ); + } + + if ( ! command ) { + pnd_log ( PND_LOG_DEFAULT, "Can't emit dotdesktop for %s, missing exec\n", targetpath ); + return ( 0 ); + } + + if ( ! filetype ) { + pnd_log ( PND_LOG_DEFAULT, "Can't emit dotdesktop for %s, missing MIME-type\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#%u#%u.desktop", targetpath, p -> unique_id, p -> subapp_number, i ); + + // emit + + //printf ( "EMIT DOTDESKTOP '%s'\n", filename ); + + f = fopen ( filename, "w" ); + + if ( ! f ) { + return ( 0 ); + } + + fprintf ( f, "%s\n", PND_DOTDESKTOP_HEADER ); + + fprintf ( f, "NoDisplay=false\n" ); // file association entries shouldn't live in the menus; but if 'true', xfce won't show this association in the dialog.. stupid! + + if ( p -> title_en ) { + snprintf ( buffer, 1020, "Name=%s\n", mimename ); + fprintf ( f, "%s", buffer ); + } + + fprintf ( f, "Type=Application\n" ); + fprintf ( f, "Version=1.0\n" ); + + if ( p -> icon ) { + snprintf ( buffer, 1020, "Icon=%s\n", p -> icon ); + fprintf ( f, "%s", buffer ); + } + + if ( p -> unique_id ) { + fprintf ( f, "X-Pandora-UID=%s\n", p -> unique_id ); + } + + 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 ( filetype ) { + pnd_log ( PND_LOG_DEFAULT, " EmitDesktopAssoc: Found file association request in PXML (%s) for mimetype (%s)\n", p -> title_en, filetype ); + fprintf ( f, "MimeType=%s\n", filetype ); + } + + if ( command ) { + char *nohup; + + if ( p -> option_no_x11 ) { + nohup = "/usr/bin/nohup "; + } else { + nohup = ""; + } + + // 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, command, + 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, command, + p -> appdata_dirname ? p -> appdata_dirname : p -> unique_id ); + } + + // start dir + if ( p -> startdir ) { + strncat ( buffer, " -s ", 1020 ); + strncat ( buffer, p -> startdir, 1020 ); + } + + // args (pxml args) + if ( p -> execargs ) { + char argbuf [ 1024 ]; + snprintf ( argbuf, 1000, " -a \"%s\"", p -> execargs ); + strncat ( buffer, argbuf, 1020 ); + } + + // clockspeed + if ( p -> clockspeed && atoi ( p -> clockspeed ) != 0 ) { + strncat ( buffer, " -c ", 1020 ); + strncat ( buffer, p -> clockspeed, 1020 ); + } + + // exec options + if ( pnd_pxml_get_x11 ( p -> option_no_x11 ) == pnd_pxml_x11_stop ) { + strncat ( buffer, " -x ", 1020 ); + } + + // args (mimetype args) + if ( args ) { + char argbuf [ 1024 ]; + snprintf ( argbuf, 1000, " -- %s", args ); + strncat ( buffer, argbuf, 1020 ); + } + + // newline + strncat ( buffer, "\n", 1020 ); + + // emit + fprintf ( f, "%s", buffer ); + + // and lets copy in some stuff in case it makes .desktop consumers life easier + if ( command ) { fprintf ( f, "X-Pandora-Exec=%s\n", command ); } + if ( args ) { fprintf ( f, "X-Pandora-ExecArgs=%s\n", args ); } + if ( p -> appdata_dirname ) { fprintf ( f, "X-Pandora-Appdata-Dirname=%s\n", p -> appdata_dirname ); } + 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 ); + } + + } + + fprintf ( f, "Categories=Other\n" ); // NoDisplay means can't confirm choice in xfce, so how do we hide this out of the way? + + fprintf ( f, "%s\n", PND_DOTDESKTOP_SOURCE ); // should we need to know 'who' created the file during trimming + + fclose ( f ); + + return ( 1 ); +} // dotassoc + unsigned char pnd_emit_icon ( char *targetpath, pnd_disco_t *p ) { //#define BITLEN (8*1024) #define BITLEN (64*1024) diff --git a/lib/pnd_device.c b/lib/pnd_device.c index b3cf0c4..65ea176 100644 --- a/lib/pnd_device.c +++ b/lib/pnd_device.c @@ -7,6 +7,7 @@ #include #include #include +#include #include "pnd_device.h" diff --git a/lib/pnd_discovery.c b/lib/pnd_discovery.c index a28d89e..90baba0 100644 --- a/lib/pnd_discovery.c +++ b/lib/pnd_discovery.c @@ -63,10 +63,16 @@ void pnd_disco_destroy ( pnd_disco_t *p ) { if ( p -> package_version_build ) { free ( p -> package_version_build ); } if ( p -> associationitem1_name ) { free ( p -> associationitem1_name ); } if ( p -> associationitem1_filetype ) { free ( p -> associationitem1_filetype ); } + if ( p -> associationitem1_command ) { free ( p -> associationitem1_command ); } + if ( p -> associationitem1_args ) { free ( p -> associationitem1_args ); } if ( p -> associationitem2_name ) { free ( p -> associationitem2_name ); } if ( p -> associationitem2_filetype ) { free ( p -> associationitem2_filetype ); } + if ( p -> associationitem2_command ) { free ( p -> associationitem2_command ); } + if ( p -> associationitem2_args ) { free ( p -> associationitem2_args ); } if ( p -> associationitem3_name ) { free ( p -> associationitem3_name ); } if ( p -> associationitem3_filetype ) { free ( p -> associationitem3_filetype ); } + if ( p -> associationitem3_command ) { free ( p -> associationitem3_command ); } + if ( p -> associationitem3_args ) { free ( p -> associationitem3_args ); } return; } @@ -347,18 +353,21 @@ static int pnd_disco_callback ( const char *fpath, const struct stat *sb, if ( pnd_pxml_get_associationitem1_name ( pxmlh ) ) { p -> associationitem1_name = strdup ( pnd_pxml_get_associationitem1_name ( pxmlh ) ); p -> associationitem1_filetype = strdup ( pnd_pxml_get_associationitem1_filetype ( pxmlh ) ); - //p -> associationitem1_parameter = strdup ( pnd_pxml_get_associationitem1_parameter ( pxmlh ) ); - pnd_log ( PND_LOG_DEFAULT, " Disco: Found file association request in PXML (%s)\n", p -> title_en ); + p -> associationitem1_command = strdup ( pnd_pxml_get_associationitem1_command ( pxmlh ) ); + p -> associationitem1_args = strdup ( pnd_pxml_get_associationitem1_args ( pxmlh ) ); + //pnd_log ( PND_LOG_DEFAULT, " Disco: Found file association request in PXML (%s)\n", p -> title_en ); } if ( pnd_pxml_get_associationitem2_name ( pxmlh ) ) { p -> associationitem2_name = strdup ( pnd_pxml_get_associationitem2_name ( pxmlh ) ); p -> associationitem2_filetype = strdup ( pnd_pxml_get_associationitem2_filetype ( pxmlh ) ); - //p -> associationitem2_parameter = strdup ( pnd_pxml_get_associationitem2_parameter ( pxmlh ) ); + p -> associationitem2_command = strdup ( pnd_pxml_get_associationitem2_command ( pxmlh ) ); + p -> associationitem2_args = strdup ( pnd_pxml_get_associationitem2_args ( pxmlh ) ); } if ( pnd_pxml_get_associationitem3_name ( pxmlh ) ) { p -> associationitem3_name = strdup ( pnd_pxml_get_associationitem3_name ( pxmlh ) ); p -> associationitem3_filetype = strdup ( pnd_pxml_get_associationitem3_filetype ( pxmlh ) ); - //p -> associationitem3_parameter = strdup ( pnd_pxml_get_associationitem3_parameter ( pxmlh ) ); + p -> associationitem3_command = strdup ( pnd_pxml_get_associationitem3_command ( pxmlh ) ); + p -> associationitem3_args = strdup ( pnd_pxml_get_associationitem3_args ( pxmlh ) ); } #endif diff --git a/lib/pnd_pxml.c b/lib/pnd_pxml.c index 77fc011..52d5ceb 100644 --- a/lib/pnd_pxml.c +++ b/lib/pnd_pxml.c @@ -160,8 +160,11 @@ void pnd_pxml_delete ( pnd_pxml_handle h ) { if ( p -> associationitem1_filetype ) { free ( p -> associationitem1_filetype ); } - if ( p -> associationitem1_parameter ) { - free ( p -> associationitem1_parameter ); + if ( p -> associationitem1_command ) { + free ( p -> associationitem1_command ); + } + if ( p -> associationitem1_args ) { + free ( p -> associationitem1_args ); } if ( p -> associationitem2_name ) { free ( p -> associationitem2_name ); @@ -169,8 +172,11 @@ void pnd_pxml_delete ( pnd_pxml_handle h ) { if ( p -> associationitem2_filetype ) { free ( p -> associationitem2_filetype ); } - if ( p -> associationitem2_parameter ) { - free ( p -> associationitem2_parameter ); + if ( p -> associationitem2_command ) { + free ( p -> associationitem2_command ); + } + if ( p -> associationitem2_args ) { + free ( p -> associationitem2_args ); } if ( p -> associationitem3_name ) { free ( p -> associationitem3_name ); @@ -178,8 +184,11 @@ void pnd_pxml_delete ( pnd_pxml_handle h ) { if ( p -> associationitem1_filetype ) { free ( p -> associationitem3_filetype ); } - if ( p -> associationitem1_parameter ) { - free ( p -> associationitem3_parameter ); + if ( p -> associationitem1_command ) { + free ( p -> associationitem3_command ); + } + if ( p -> associationitem1_args ) { + free ( p -> associationitem3_args ); } if ( p -> clockspeed ) { free ( p -> clockspeed ); @@ -549,9 +558,14 @@ char *pnd_pxml_get_associationitem1_filetype ( pnd_pxml_handle h ) { return ( p -> associationitem1_filetype ); } -char *pnd_pxml_get_associationitem1_parameter ( pnd_pxml_handle h ) { +char *pnd_pxml_get_associationitem1_command ( pnd_pxml_handle h ) { + pnd_pxml_t *p = (pnd_pxml_t*) h; + return ( p -> associationitem1_command ); +} + +char *pnd_pxml_get_associationitem1_args ( pnd_pxml_handle h ) { pnd_pxml_t *p = (pnd_pxml_t*) h; - return ( p -> associationitem1_parameter ); + return ( p -> associationitem1_args ); } char *pnd_pxml_get_associationitem2_name ( pnd_pxml_handle h ) { @@ -564,9 +578,14 @@ char *pnd_pxml_get_associationitem2_filetype ( pnd_pxml_handle h ) { return ( p -> associationitem2_filetype ); } -char *pnd_pxml_get_associationitem2_parameter ( pnd_pxml_handle h ) { +char *pnd_pxml_get_associationitem2_command ( pnd_pxml_handle h ) { pnd_pxml_t *p = (pnd_pxml_t*) h; - return ( p -> associationitem2_parameter ); + return ( p -> associationitem2_command ); +} + +char *pnd_pxml_get_associationitem2_args ( pnd_pxml_handle h ) { + pnd_pxml_t *p = (pnd_pxml_t*) h; + return ( p -> associationitem2_args ); } char *pnd_pxml_get_associationitem3_name ( pnd_pxml_handle h ) { @@ -579,9 +598,14 @@ char *pnd_pxml_get_associationitem3_filetype ( pnd_pxml_handle h ) { return ( p -> associationitem3_filetype ); } -char *pnd_pxml_get_associationitem3_parameter ( pnd_pxml_handle h ) { +char *pnd_pxml_get_associationitem3_command ( pnd_pxml_handle h ) { + pnd_pxml_t *p = (pnd_pxml_t*) h; + return ( p -> associationitem3_command ); +} + +char *pnd_pxml_get_associationitem3_args ( pnd_pxml_handle h ) { pnd_pxml_t *p = (pnd_pxml_t*) h; - return ( p -> associationitem3_parameter ); + return ( p -> associationitem3_args ); } char *pnd_pxml_get_clockspeed ( pnd_pxml_handle h ) { diff --git a/lib/pnd_tinyxml.cpp b/lib/pnd_tinyxml.cpp index 8ddc538..40c928b 100644 --- a/lib/pnd_tinyxml.cpp +++ b/lib/pnd_tinyxml.cpp @@ -416,55 +416,57 @@ unsigned char pnd_pxml_parse ( const char *pFilename, char *buffer, unsigned int if ( (pElem = hRoot.FirstChild(PND_PXML_NODENAME_ASSOCS).Element()) ) { i = 0; + //Go through all associations. i serves as index; since the format only supports 3 associations we need to keep track of the number. for (pElem = pElem->FirstChildElement(PND_PXML_ENAME_ASSOC); pElem && i < 3; pElem = pElem->NextSiblingElement(PND_PXML_ENAME_ASSOC), i++) { char *name = pnd_pxml_get_attribute(pElem, PND_PXML_ATTRNAME_ASSOCNAME); char *filetype = pnd_pxml_get_attribute(pElem, PND_PXML_ATTRNAME_ASSOCFTYPE); - //char *paramter = pnd_pxml_get_attribute(pElem, PND_PXML_ATTRNAME_ASSOCARGS); - - //pnd_log ( PND_LOG_DEFAULT, " Found file association request in PXML - parse (%p %p)\n", name, filetype/*, paramter */ ); - - if (!(name && filetype /* && paramter*/ )) - { - if(name) free(name); - if(filetype) free(filetype); - //if(paramter) free(paramter); - continue; - } - - switch(i) //TODO: same problem here: only 3 associations supported - { - case 0: - { - app->associationitem1_name = strdup ( name ); - app->associationitem1_filetype = strdup ( filetype ); - //app->associationitem1_parameter = paramter; - pnd_log ( PND_LOG_DEFAULT, " Found file association request in PXML (%d-0)\n", i ); - break; - } - case 1: - { - app->associationitem2_name = strdup ( name ); - app->associationitem2_filetype = strdup ( filetype ); - //app->associationitem2_parameter = paramter; - pnd_log ( PND_LOG_DEFAULT, " Found file association request in PXML (%d-1)\n", i ); - break; + char *command = pnd_pxml_get_attribute(pElem, PND_PXML_ATTRNAME_ASSOCCMD); + char *args = pnd_pxml_get_attribute(pElem, PND_PXML_ATTRNAME_ASSOCARGS); + + if ( ! ( name && filetype && command ) ) { + if ( name ) free(name); + if ( filetype ) free(filetype); + if ( command ) free(command); + if ( args ) free(args); + continue; } - case 2: - { - app->associationitem3_name = strdup ( name ); - app->associationitem3_filetype = strdup ( filetype ); - //app->associationitem3_parameter = paramter; - pnd_log ( PND_LOG_DEFAULT, " Found file association request in PXML (%d-2)\n", i ); - } - } - if(name) free(name); - if(filetype) free(filetype); - //if(paramter) free(paramter); - } - } + + switch ( i ) { //TODO: same problem here: only 3 associations supported + case 0: { + app->associationitem1_name = strdup ( name ); + app->associationitem1_filetype = strdup ( filetype ); + app->associationitem1_command = strdup ( command ); + app->associationitem1_args = strdup ( args ); + //pnd_log ( PND_LOG_DEFAULT, (char*)" Found file association request in PXML (%d-0)\n", i ); + break; + } + case 1: { + app->associationitem2_name = strdup ( name ); + app->associationitem2_filetype = strdup ( filetype ); + app->associationitem2_command = strdup ( command ); + app->associationitem2_args = strdup ( args ); + //pnd_log ( PND_LOG_DEFAULT, (char*)" Found file association request in PXML (%d-1)\n", i ); + break; + } + case 2: { + app->associationitem3_name = strdup ( name ); + app->associationitem3_filetype = strdup ( filetype ); + app->associationitem3_command = strdup ( command ); + app->associationitem3_args = strdup ( args ); + //pnd_log ( PND_LOG_DEFAULT, (char*)" Found file association request in PXML (%d-2)\n", i ); + } // case + } // switch + + if ( name ) free(name); + if ( filetype ) free(filetype); + if ( command ) free(command); + if ( args ) free(args); + + } // for + } // assoc #endif //Performance related things (aka: Clockspeed XD): -- 2.39.2