*************** *** 166,174 **** s->insertSearchPath(QSettings::Windows, "/Affinix"); s->insertSearchPath(QSettings::Unix, g.pathHome); lastProfile = s->readEntry("/psi/lastProfile"); - lastLang = s->readEntry("/psi/lastLang"); autoOpen = s->readBoolEntry("/psi/autoOpen", FALSE); delete s; if(lastLang.isEmpty()) { lastLang = QTextCodec::locale(); --- 166,176 ---- s->insertSearchPath(QSettings::Windows, "/Affinix"); s->insertSearchPath(QSettings::Unix, g.pathHome); lastProfile = s->readEntry("/psi/lastProfile"); + 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(); *************** *** 177,182 **** setLang(lastLang); if(autoOpen && !lastProfile.isEmpty() && profileExists(lastProfile)) { // Auto-open the last profile activeProfile = lastProfile; --- 179,231 ---- 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; *************** *** 207,248 **** { 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; } static bool loadGlobal() { // set the paths g.pathBase = getResourcesDir(); - char *p = getenv("PSIDATADIR"); - if(p) - g.pathHome = p; else - g.pathHome = getHomeDir(); g.pathProfiles = g.pathHome + "/profiles"; QDir d(g.pathProfiles); --- 256,341 ---- { delete pcon; + 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(); + + 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 + { + // 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); *************** *** 297,303 **** // only set lastProfile if the user opened it lastProfile = str; - activeProfile = str; sessionStart(); } --- 390,395 ---- // only set lastProfile if the user opened it lastProfile = str; activeProfile = str; sessionStart(); } *************** *** 336,341 **** int main(int argc, char *argv[]) { // add library paths before creating QApplication if (!loadGlobal()) return 1; --- 428,448 ---- 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; *************** *** 346,358 **** 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; - } if ( useCrash ) Crash::registerSigsegvHandler(argv[0]); --- 453,459 ---- PsiApplication *app = new PsiApplication(argc, argv); #ifdef USE_CRASH + useCrash = !argp->existsArg("nocrash"); if ( useCrash ) Crash::registerSigsegvHandler(argv[0]); *************** *** 362,387 **** 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; - } //if(link_test) // printf("Link test enabled\n"); --- 463,475 ---- srand(time(NULL)); //dtcp_port = 8000; + + 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"); *************** *** 400,406 **** // 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(); --- 488,494 ---- // 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(); *************** *** 413,418 **** delete qttrans; qttrans = 0; delete app; QCA::unloadAllPlugins(); --- 501,507 ---- delete qttrans; qttrans = 0; + delete argp; delete app; QCA::unloadAllPlugins();