diff --exclude='*orig' -Naur psi-0.10-test3-orig/psics.pri psi-0.10-test3/psics.pri --- psi-0.10-test3-orig/psics.pri 2005-11-08 22:16:09.000000000 +0000 +++ psi-0.10-test3/psics.pri 2005-11-08 23:07:46.000000000 +0000 @@ -64,6 +64,12 @@ INCLUDEPATH += $$MACDOCK_CPP include($$MACDOCK_CPP/mac_dock.pri) + # argumentparser + CONFIG += argumentparser + ARGUMENTPARSER_CPP = $$PSICS_CPP/argumentparser + INCLUDEPATH += $$ARGUMENTPARSER + include($$ARGUMENTPARSER_CPP/argumentparser.pri) + # zip CONFIG += zip ZIP_CPP = $$PSICS_CPP/zip diff --exclude='*orig' -Naur psi-0.10-test3-orig/src/common.cpp psi-0.10-test3/src/common.cpp --- psi-0.10-test3-orig/src/common.cpp 2005-11-08 22:16:13.000000000 +0000 +++ psi-0.10-test3/src/common.cpp 2005-11-08 23:07:46.000000000 +0000 @@ -87,6 +87,8 @@ PsiIconset *is; bool useSound; +ArgumentParser *argp; + QString qstrlower(QString str) { diff --exclude='*orig' -Naur psi-0.10-test3-orig/src/common.h psi-0.10-test3/src/common.h --- psi-0.10-test3-orig/src/common.h 2005-11-08 23:02:04.000000000 +0000 +++ psi-0.10-test3/src/common.h 2005-11-08 23:07:46.000000000 +0000 @@ -37,6 +37,7 @@ #include"psiiconset.h" #include"reasons.h" #include"templates.h" +#include"tools/argumentparser/argumentparser.h" #define PROXY_NONE 0 #define PROXY_HTTPS 1 @@ -378,6 +379,9 @@ extern bool useSound; +extern +ArgumentParser *argp; + // helper class for toolbars class StretchWidget: public QWidget { diff --exclude='*orig' -Naur psi-0.10-test3-orig/src/main.cpp psi-0.10-test3/src/main.cpp --- psi-0.10-test3-orig/src/main.cpp 2005-11-08 22:16:08.000000000 +0000 +++ psi-0.10-test3/src/main.cpp 2005-11-08 23:07:46.000000000 +0000 @@ -168,9 +168,11 @@ s->insertSearchPath(QSettings::Windows, "/Affinix"); s->insertSearchPath(QSettings::Unix, g.pathHome); lastProfile = s->readEntry("/psi/lastProfile"); - lastLang = s->readEntry("/psi/lastLang"); + lastLang = s->readEntry("/psi/lastLang",""); autoOpen = s->readBoolEntry("/psi/autoOpen", FALSE); delete s; + // some of them are overridden afterwards by CLI profile/profiledir + // but not saved if(lastLang.isEmpty()) { lastLang = QTextCodec::locale(); @@ -179,6 +181,53 @@ setLang(lastLang); + // language detected + + // we can now check the validity of the CLI arguments and report bad usage + if (argp->existsArg("profiledir") && g.pathHome=="") + { + QString errmsg; + QMessageBox::critical(0, + tr("Error"), + tr("The specified profile (%1) does not exist.") + .arg( QDir(argp->getString("profiledir")).dirName() ) + ); + QTimer::singleShot(0, this, SLOT(bail())); + return; + } + + if (argp->existsArg("profiledir") && argp->existsArg("datadir")) + { + QMessageBox::critical(0, tr("Error"), + tr("You are not allowed to use \"--datadir\" and \"--profiledir\" at the same time.")); + QTimer::singleShot(0, this, SLOT(bail())); + return; + } + + //start overriding loaded settings + + if (argp->existsArg("profiledir")) + { + QString dir=argp->getString("profiledir"); + if (dir[dir.length()-1]==QDir::separator()) dir.remove(dir.length()-1,1); + //remove trailing slash + int p=dir.findRev(QDir::separator()); + dir.remove(0,p+1); + lastProfile=dir; + autoOpen=true; + //printf("Opening given profile named: %s\n",lastProfile.latin1()); + } + + if (argp->existsArg("profile")) + { + // let's trick Psi think we use autoopen option + // autoopen/lastprofile won't be modified on host machine + // (we made sure settings are not saved when this cmd line param is used) + autoOpen=true; + lastProfile=argp->getString("profile"); + } + + // standard profile loading procedure if(autoOpen && !lastProfile.isEmpty() && profileExists(lastProfile)) { // Auto-open the last profile activeProfile = lastProfile; @@ -209,42 +258,86 @@ { delete pcon; -#ifdef Q_OS_WIN - // remove Psi's settings from HKLM - QSettings *rs = new QSettings; - rs->setPath("Affinix", "psi", QSettings::Global); - rs->removeEntry("/lastProfile"); - rs->removeEntry("/lastLang"); - rs->removeEntry("/autoOpen"); - - QString affinixKey = "Software\\Affinix"; -#ifdef Q_OS_TEMP - RegDeleteKeyW(HKEY_LOCAL_MACHINE, affinixKey.ucs2()); -#else - RegDeleteKeyA(HKEY_LOCAL_MACHINE, affinixKey.latin1()); -#endif - delete rs; -#endif - - QSettings *s = new QSettings; - s->setPath("psi.affinix.com", "Psi", QSettings::User); // make Psi load all prefs from HKCU on Windows systems - s->insertSearchPath(QSettings::Windows, "/Affinix"); - s->insertSearchPath(QSettings::Unix, g.pathHome); - s->writeEntry("/psi/lastProfile", lastProfile); - s->writeEntry("/psi/lastLang", lastLang); - s->writeEntry("/psi/autoOpen", autoOpen); - delete s; + if (!( argp->existsArg("profile") || argp->existsArg("profiledir") )) { + // save settings on exit if profile or profiledir were not given as CLI arg + // we do not want to mess up the settings on the current computer + + #ifdef Q_OS_WIN + // remove Psi's settings from HKLM + QSettings *rs = new QSettings; + rs->setPath("Affinix", "psi", QSettings::Global); + rs->removeEntry("/lastProfile"); + rs->removeEntry("/lastLang"); + rs->removeEntry("/autoOpen"); + + QString affinixKey = "Software\\Affinix"; + #ifdef Q_OS_TEMP + RegDeleteKeyW(HKEY_LOCAL_MACHINE, affinixKey.ucs2()); + #else + RegDeleteKeyA(HKEY_LOCAL_MACHINE, affinixKey.latin1()); + #endif + delete rs; + #endif + + QSettings *s = new QSettings; + s->setPath("psi.affinix.com", "Psi", QSettings::User); + // make Psi load all prefs from HKCU on Windows systems + s->insertSearchPath(QSettings::Windows, "/Affinix"); + s->insertSearchPath(QSettings::Unix, g.pathHome); + s->writeEntry("/psi/lastProfile", lastProfile); + s->writeEntry("/psi/lastLang", lastLang); + s->writeEntry("/psi/autoOpen", autoOpen); + delete s; + } + //else + // printf("We don't want to save settings!\n"); } static bool loadGlobal() { // set the paths g.pathBase = getResourcesDir(); - char *p = getenv("PSIDATADIR"); - if(p) - g.pathHome = p; + + if (argp->existsArg("profiledir")) + { + QString dir=argp->getString("profiledir"); + if (dir[dir.length()-1]==QDir::separator()) dir.remove(dir.length()-1,1); + //remove trailing slash + + QDir d(dir); + if(!d.exists()) { + // can't find profile dir + g.pathHome=""; + // we signal PsiMain to bail-out with an error by setting pathHome="" + return TRUE; + //we have to return true in order to reach PsiMain constuctor + //where we return a translated error + } + + g.pathHome=dir; + + int p=dir.findRev(QDir::separator()); + g.pathProfiles=dir.left(p); + return TRUE; + } + + if (argp->existsArg("datadir")) + { + QString dir=argp->getString("datadir"); + if (dir[dir.length()-1]==QDir::separator()) dir.remove(dir.length()-1,1); + g.pathHome=dir; + } else - g.pathHome = getHomeDir(); + { + // standard behaviour + char *p = getenv("PSIDATADIR"); + if(p) { + g.pathHome = p; + delete p; + } + else + g.pathHome = getHomeDir(); + } g.pathProfiles = g.pathHome + "/profiles"; QDir d(g.pathProfiles); @@ -299,7 +392,6 @@ // only set lastProfile if the user opened it lastProfile = str; - activeProfile = str; sessionStart(); } @@ -338,6 +430,21 @@ int main(int argc, char *argv[]) { + argp = new ArgumentParser(argc, argv); + argp->addArgument("nocrash"); + argp->addArgument("no-gpg"); + argp->addArgument("no-gpg-agent"); + argp->addArgument("linktest"); + + argp->addArgument("datadir","d",true); + argp->addArgument("profile","p",true); + argp->addArgument("profiledir","pd",true); + + argp->addArgument("gpg","",true); + argp->addArgument("gpghome","",true); + + argp->parse(); + // add library paths before creating QApplication if (!loadGlobal()) return 1; @@ -348,13 +455,7 @@ PsiApplication *app = new PsiApplication(argc, argv); #ifdef USE_CRASH - int useCrash = true; - int i; - for(i = 1; i < argc; ++i) { - QString str = argv[i]; - if ( str == "--nocrash" ) - useCrash = false; - } + useCrash = !argp->existsArg("nocrash"); if ( useCrash ) Crash::registerSigsegvHandler(argv[0]); @@ -364,26 +465,13 @@ srand(time(NULL)); //dtcp_port = 8000; - for(int n = 1; n < argc; ++n) { - QString str = argv[n]; - QString var, val; - int x = str.find('='); - if(x == -1) { - var = str; - val = ""; - } - else { - var = str.mid(0,x); - val = str.mid(x+1); - } - - if(var == "--no-gpg") - use_gpg = false; - else if(var == "--no-gpg-agent") - no_gpg_agent = true; - //else if(var == "--linktest") - // link_test = true; - } + + use_gpg = !argp->existsArg("no-gpg"); + no_gpg_agent = argp->existsArg("no-gpg-agent"); + // Note: inconsistent naming of variables (use_gpg, no_gpg_agent), + // although consistent naming of arguments + + //link_test = argp->existsArg("linktest"); //if(link_test) // printf("Link test enabled\n"); @@ -402,7 +490,7 @@ // need SHA1 for Iconset sound if(!QCA::isSupported(QCA::CAP_SHA1)) QCA::insertProvider(XMPP::createProviderHash()); - + PsiMain *psi = new PsiMain; QObject::connect(psi, SIGNAL(quit()), app, SLOT(quit())); app->exec(); @@ -415,6 +503,7 @@ delete qttrans; qttrans = 0; + delete argp; delete app; QCA::unloadAllPlugins(); diff --exclude='*orig' -Naur psi-0.10-test3-orig/src/psiactionlist.cpp psi-0.10-test3/src/psiactionlist.cpp --- psi-0.10-test3-orig/src/psiactionlist.cpp 2005-11-08 22:16:09.000000000 +0000 +++ psi-0.10-test3/src/psiactionlist.cpp 2005-11-08 23:07:46.000000000 +0000 @@ -197,6 +197,7 @@ IconAction *actOptions = new IconAction (tr("Options"), "psi/options", tr("&Options"), 0, this); IconAction *actToolbars = new IconAction(tr("Configure Toolbars"), "psi/toolbars", tr("Configure Tool&bars"), 0, this); IconAction *actChangeProfile = new IconAction (tr("Change Profile"), "psi/profile", tr("&Change profile"), 0, this); + actChangeProfile->setEnabled( !argp->existsArg("profiledir") ); IconAction *actPlaySounds = new IconAction (tr("Play sounds"), "psi/playSounds", tr("Play &sounds"), 0, this, 0, true); actPlaySounds->setWhatsThis (tr("Toggles whether sound should be played or not")); diff --exclude='*orig' -Naur psi-0.10-test3-orig/src/psicon.cpp psi-0.10-test3/src/psicon.cpp --- psi-0.10-test3-orig/src/psicon.cpp 2005-11-08 22:16:11.000000000 +0000 +++ psi-0.10-test3/src/psicon.cpp 2005-11-08 23:07:46.000000000 +0000 @@ -1351,8 +1351,12 @@ { if(id.isEmpty()) return; + + QStringList engineParams; + engineParams << argp->getString("gpg"); + engineParams << argp->getString("gpghome"); - d->pgp = OpenPGP::createEngine(id); + d->pgp = OpenPGP::createEngine(id,engineParams); if(d->pgp) { connect(d->pgp, SIGNAL(initFinished(bool, const QString &)), SLOT(pgp_initFinished(bool, const QString &))); connect(d->pgp, SIGNAL(keysUpdated()), SLOT(pgp_keysUpdated())); diff --exclude='*orig' -Naur psi-0.10-test3-orig/src/tools/argumentparser/argumentparser.cpp psi-0.10-test3/src/tools/argumentparser/argumentparser.cpp --- psi-0.10-test3-orig/src/tools/argumentparser/argumentparser.cpp 1970-01-01 00:00:00.000000000 +0000 +++ psi-0.10-test3/src/tools/argumentparser/argumentparser.cpp 2005-11-08 23:07:46.000000000 +0000 @@ -0,0 +1,215 @@ +/*************************************************************************** + * Copyright (C) 2005 by Mircea Bardac * + * dev@mircea.bardac.net * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#include "argumentparser.h" + +/** + @author Mircea Bardac + @version 1.0 +*/ + + +/** + * Class Constructor (takes main() function arguments and initializes + * the parser engine + * \param c number of arguments + * \param v pointer to the char* arguments + */ +ArgumentParser::ArgumentParser (int c, char **v): + argc(c), argv(v), stopOnUnknownArg(false) {}; + +/** + * Class Destructor + */ +ArgumentParser::~ArgumentParser() { }; + +/** + * Function to convert an abbreviation to its true name + * \param abbrev abbreviation + * \return the corresponding real name of the parameter + */ +QString ArgumentParser::convertAbbrev(const QString abbrev) +{ + QMap::Iterator a=abbrevs.find(abbrev); + if (a!=abbrevs.end()) + { + return a.data(); + } + else + { + if (stopOnUnknownArg) gotError=100; + // just an internal signal + // (will be modified to point the correct argument index) + return ""; + } +} + +/** + * Function to test if an argument takes a value or not + * \param argname the argument tested + * \return TRUE if argument takes a value or FALSE otherwise +*/ +bool ArgumentParser::takesValue(const QString argname) +{ + QMap::Iterator hv=argData.find(argname); + if (hv==argData.end()) return false; + return (hv.data().takesValue); +} + +/** + * Function to test if an argument is known or not + * \param argname the argument tested + * \return TRUE if argument is known or FALSE otherwise +*/ +bool ArgumentParser::knownArg(const QString argname) +{ + return (argData.contains(argname)); +} + +/** + * Function to parse the arguments + * (the 'brain' of the class) + */ +void ArgumentParser::parse() +{ +// printf("Number of arguments: %d\n",argc-1); + gotError=0; + for(int i=1;i0) { gotError=i; return;} + if (takesValue(argname)) // "value" might be missing + { + i++; + if (i==argc) { gotError=i-1; return; } + argvalue=QString(argv[i]); + } + arguments.insert(argname,argvalue); + continue; + } +// printf("Ignored argument: %s\n",argcurrent.latin1()); + } +} + +/* +void ArgumentParser::showArgs() +{ + if (gotError>0) printf("!!! Error at argument %d!\n",gotError); + QMap::Iterator it; + for (it=arguments.begin(); it!=arguments.end(); ++it) + { + printf("ARG: %s -- VALUE: %s\n",it.key().latin1(),it.data().latin1()); + } +} +*/ + +/** + * Function to add an argument to the list of recognized arguments + * \param argname full name of the argument + * \param abbrev abbreviation of the argument (optional) + * \param takesValue indicates wether the argument must have a value or not + * \param helpdesc help description for the given argument + */ +void ArgumentParser::addArgument + (const QString argname, const QString abbrev, + const bool takesValue, const QString helpdesc) +{ + ArgumentDetails d; d.takesValue=takesValue; d.helpdesc=helpdesc; + argData.insert(argname,d); + // printf(">abbrev: %s -> %s\n",abbrev.latin1(),argname.latin1()); + if (abbrev!="") abbrevs.insert(abbrev,argname); +} + + +/** + * Function to test if an agument was passed to the program + * \param argname full name of the argument + */ +bool ArgumentParser::existsArg(const QString argname) +{ + QMap::Iterator a=arguments.find(argname); + return (a!=arguments.end()); +} + +/** + * Function to read the int value of a given argument + * \param argname argument name + * \return the argument int value + */ +int ArgumentParser::getInt(const QString argname) +{ + QMap::Iterator a=arguments.find(argname); + if (a!=arguments.end()) + return a.data().toInt(); + if (!knownArg(argname)) + { + printf("Warning: reading unknown argument \"%s\"!\n",argname.latin1()); + return 0; + } + return 0; +} + + +/** + * Function to read the string value of a given argument + * \param argname argument name + * \return the argument string value + */ +QString ArgumentParser::getString(QString argname) +{ + QMap::Iterator a=arguments.find(argname); + if (a!=arguments.end()) + return a.data(); + if (!knownArg(argname)) + { + printf("Warning: reading unknown argument \"%s\"!\n",argname.latin1()); + return ""; + } + return ""; +} + + diff --exclude='*orig' -Naur psi-0.10-test3-orig/src/tools/argumentparser/argumentparser.h psi-0.10-test3/src/tools/argumentparser/argumentparser.h --- psi-0.10-test3-orig/src/tools/argumentparser/argumentparser.h 1970-01-01 00:00:00.000000000 +0000 +++ psi-0.10-test3/src/tools/argumentparser/argumentparser.h 2005-11-08 23:07:46.000000000 +0000 @@ -0,0 +1,88 @@ +/*************************************************************************** + * Copyright (C) 2005 by Mircea Bardac * + * dev@mircea.bardac.net * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#ifndef ARGUMENTPARSER_H +#define ARGUMENTPARSER_H + +#include +#include + +/** + @author Mircea Bardac + @version 1.0 + */ + +/** + * Structure to hold an argument definition + */ +struct ArgumentDetails { + // we will use this structure to keep extra information + // on the arguments + bool takesValue; + QString helpdesc; +}; + +/** + * Class to handle arguments and their values + */ +class ArgumentParser{ +private: + int argc; + char **argv; + + QMap abbrevs; // association: abbrev => argument name + QMap arguments; // association: agument name => value + QMap argData; + + // control attributes + int gotError; // index where the parsing error occured + bool stopOnUnknownArg; + // flag which indicates if parsing stops when error is encountered + + QString convertAbbrev(const QString); + bool takesValue(QString); + bool knownArg(QString); + // QString argGetValue(QString,int); // get value from --param="value value_continued end" + // QString argGetValue(int &); //get value from -abrevparam "value value_2 ..." + +public: + ArgumentParser(int, char**); + ~ArgumentParser(); + + void parse(); + void addArgument + (const QString argname, const QString abbrev="", + const bool takesValue=false, const QString helpdesc=""); + + // argument list management functions + // void addAbbrev(QString argname, QString abbrev); + // void removeAbbrev(QString abbrev); + + bool existsArg(const QString); + // argument value reading functions + int getInt(const QString); + QString getString(const QString); + // bool getBool(QString argname); // useless (use existsArg() instead) + + // debug functions + bool parseError() { return (gotError>0); }; + // void showArgs(); +}; + +#endif diff --exclude='*orig' -Naur psi-0.10-test3-orig/src/tools/argumentparser/argumentparser.pri psi-0.10-test3/src/tools/argumentparser/argumentparser.pri --- psi-0.10-test3-orig/src/tools/argumentparser/argumentparser.pri 1970-01-01 00:00:00.000000000 +0000 +++ psi-0.10-test3/src/tools/argumentparser/argumentparser.pri 2005-11-08 23:07:46.000000000 +0000 @@ -0,0 +1,4 @@ +argumentparser { + HEADERS += $$ARGUMENTPARSER_CPP/argumentparser.h + SOURCES += $$ARGUMENTPARSER_CPP/argumentparser.cpp +} diff --exclude='*orig' -Naur psi-0.10-test3-orig/src/tools/openpgp/gnupg.cpp psi-0.10-test3/src/tools/openpgp/gnupg.cpp --- psi-0.10-test3-orig/src/tools/openpgp/gnupg.cpp 2005-08-21 17:44:28.000000000 +0000 +++ psi-0.10-test3/src/tools/openpgp/gnupg.cpp 2005-11-08 23:07:46.000000000 +0000 @@ -79,7 +79,7 @@ class GnuPG::Private { public: - Private(const QString &bin) : gpg(bin) {} + Private(const QString &bin, const QString &home) : gpg(bin, home) {} bool available, initialized; QString name; @@ -94,27 +94,34 @@ bool secretDirty, publicDirty; }; -GnuPG::GnuPG(QObject *parent) +GnuPG::GnuPG(const QString &exepath, const QString &homedir, QObject *parent) :Engine(parent) { QString bin = "gpg"; -#ifdef Q_WS_WIN - QString s = find_reg_gpgProgram(); - if(!s.isNull()) - bin = s; -#endif - -#ifdef Q_OS_MAC - // mac-gpg - QFileInfo fi("/usr/local/bin/gpg"); - if(fi.exists()) - bin = fi.filePath(); -#endif - + if (exepath.isEmpty()) + { + #ifdef Q_WS_WIN + QString s = find_reg_gpgProgram(); + if(!s.isNull()) + bin = s; + #endif + + #ifdef Q_OS_MAC + // mac-gpg + QFileInfo fi("/usr/local/bin/gpg"); + if(fi.exists()) + bin = fi.filePath(); + #endif + } + else + { + bin=exepath; + } + #ifdef GPG_DEBUG printf("gpg bin=[%s]\n", bin.latin1()); #endif - d = new Private(bin); + d = new Private(bin,homedir); d->available = false; d->initialized = false; d->name = "GNU Privacy Guard (GPG)"; diff --exclude='*orig' -Naur psi-0.10-test3-orig/src/tools/openpgp/gnupg.h psi-0.10-test3/src/tools/openpgp/gnupg.h --- psi-0.10-test3-orig/src/tools/openpgp/gnupg.h 2005-08-21 17:44:28.000000000 +0000 +++ psi-0.10-test3/src/tools/openpgp/gnupg.h 2005-11-08 23:07:46.000000000 +0000 @@ -27,7 +27,7 @@ { Q_OBJECT public: - GnuPG(QObject *parent=0); + GnuPG(const QString &exepath="", const QString &homedir="", QObject *parent=0); ~GnuPG(); void setTryAgent(bool); diff --exclude='*orig' -Naur psi-0.10-test3-orig/src/tools/openpgp/gpgop.cpp psi-0.10-test3/src/tools/openpgp/gpgop.cpp --- psi-0.10-test3-orig/src/tools/openpgp/gpgop.cpp 2005-08-21 17:44:28.000000000 +0000 +++ psi-0.10-test3/src/tools/openpgp/gpgop.cpp 2005-11-08 23:07:46.000000000 +0000 @@ -19,7 +19,7 @@ public: Private() {} - QString bin; + QString bin, home; int op; GPGProc *proc; bool tryAgent; @@ -38,11 +38,12 @@ QByteArray dec; }; -GpgOp::GpgOp(const QString &bin, QObject *parent) +GpgOp::GpgOp(const QString &bin, const QString &home, QObject *parent) :QObject(parent) { d = new Private; d->bin = bin; + d->home = home; d->proc = 0; d->op = -1; d->tryAgent = true; @@ -323,6 +324,13 @@ bool GpgOp::launchGPG(const QStringList &args, bool useExtra) { + QStringList localargs(args); // can't add extra strings in a QStringList&; this solution works + if (!(d->home.isEmpty())) + { + //GnuPG homedir specified + localargs += "--homedir"; + localargs += d->home; + } d->proc = new GPGProc; connect(d->proc, SIGNAL(readyReadStdout()), SLOT(proc_readyReadStdout())); connect(d->proc, SIGNAL(readyReadStderr()), SLOT(proc_readyReadStderr())); @@ -330,7 +338,7 @@ connect(d->proc, SIGNAL(wroteToStdin()), SLOT(proc_wroteToStdin())); connect(d->proc, SIGNAL(statusLine(const QString &)), SLOT(proc_statusLine(const QString &))); - if(!d->proc->start(d->bin, args, useExtra)) { + if(!d->proc->start(d->bin, localargs, useExtra)) { d->proc->disconnect(this); d->proc->deleteLater(); d->proc = 0; diff --exclude='*orig' -Naur psi-0.10-test3-orig/src/tools/openpgp/gpgop.h psi-0.10-test3/src/tools/openpgp/gpgop.h --- psi-0.10-test3-orig/src/tools/openpgp/gpgop.h 2005-08-21 17:44:28.000000000 +0000 +++ psi-0.10-test3/src/tools/openpgp/gpgop.h 2005-11-08 23:07:46.000000000 +0000 @@ -8,7 +8,7 @@ Q_OBJECT public: enum { Check = 0, SecretKeyringFile, PublicKeyringFile, SecretKeys, PublicKeys, Encrypt, Decrypt, Sign, Verify }; - GpgOp(const QString &bin, QObject *parent=0); + GpgOp(const QString &bin="", const QString &home="", QObject *parent=0); ~GpgOp(); bool isActive() const; diff --exclude='*orig' -Naur psi-0.10-test3-orig/src/tools/openpgp/openpgp.cpp psi-0.10-test3/src/tools/openpgp/openpgp.cpp --- psi-0.10-test3-orig/src/tools/openpgp/openpgp.cpp 2005-08-21 17:44:28.000000000 +0000 +++ psi-0.10-test3/src/tools/openpgp/openpgp.cpp 2005-11-08 23:07:46.000000000 +0000 @@ -286,10 +286,16 @@ return list; } -Engine * OpenPGP::createEngine(const QString &id) +Engine * OpenPGP::createEngine(const QString &id, QStringList ¶ms) { if(id == "gpg") - return (new GnuPG); + { + QStringList::Iterator it = params.begin(); + QString gpgexe = *it; + it++; + QString gpghome = *it; + return (new GnuPG(gpgexe,gpghome)); + } else return 0; } diff --exclude='*orig' -Naur psi-0.10-test3-orig/src/tools/openpgp/openpgp.h psi-0.10-test3/src/tools/openpgp/openpgp.h --- psi-0.10-test3-orig/src/tools/openpgp/openpgp.h 2005-08-21 17:44:28.000000000 +0000 +++ psi-0.10-test3/src/tools/openpgp/openpgp.h 2005-11-08 23:07:46.000000000 +0000 @@ -23,6 +23,7 @@ #include #include +#include #include #include #include @@ -131,7 +132,7 @@ QValueList getAllEngines(); QValueList getAvailableEngines(); - Engine * createEngine(const QString &); + Engine * createEngine(const QString &, QStringList &); QString stripHeaderFooter(const QString &); QString addHeaderFooter(const QString &, int);