X-Git-Url: https://vaikene.ee/gitweb/pswgen11.html?a=blobdiff_plain;f=src%2Flibs%2FCommon%2Fapp.cpp;h=53efce95d319ad6cc12eea546d5b9f1189202275;hb=09e5758f2e8557be2f23ed7a8a51ca4ef855e9ab;hp=3956548f4e1656e1c1e7f44d343d0ab89fccec19;hpb=5815060246f84e8efdf3143b4e8c7d00778168cf;p=evaf
diff --git a/src/libs/Common/app.cpp b/src/libs/Common/app.cpp
index 3956548..53efce9 100644
--- a/src/libs/Common/app.cpp
+++ b/src/libs/Common/app.cpp
@@ -20,7 +20,6 @@
#include "app.h"
#include "globals.h"
#include "registry.h"
-#include "ienv.h"
#include "version.h"
#include
@@ -71,6 +70,24 @@ bool App::init()
// Clear the XML file name
mXmlFile.clear();
+ // Set initial bin and root directories
+ mRootDir = mBinDir = qApp->applicationDirPath();
+ int t = mBinDir.lastIndexOf(QChar('/'), -1);
+ if (t >= 0)
+ mRootDir = mBinDir.left(t);
+
+ if (!mBinDir.endsWith('/'))
+ mBinDir.append('/');
+ if (!mRootDir.endsWith('/'))
+ mRootDir.append('/');
+
+ // Clear other directories
+ mDataRootDir.clear();
+ mQtPluginsDir.clear();
+ mEtcDir.clear();
+ mLogDir.clear();
+ mDocDir.clear();
+
// Process environment variables
QStringList env = QProcess::systemEnvironment();
for (int i = 0; i < env.size(); ++i) {
@@ -82,6 +99,36 @@ bool App::init()
mName = value;
else if (name == "EVAF_LANGUAGE")
mLanguage = value;
+ else if (name == "EVAF_ROOT_DIR") {
+ mRootDir = value;
+ if (!mRootDir.endsWith('/'))
+ mRootDir.append('/');
+ }
+ else if (name == "EVAF_DATA_ROOT_DIR") {
+ mDataRootDir = value;
+ if (!mDataRootDir.endsWith('/'))
+ mDataRootDir.append('/');
+ }
+ else if (name == "EVAF_ETC_DIR") {
+ mEtcDir = value;
+ if (!mEtcDir.endsWith('/'))
+ mEtcDir.append('/');
+ }
+ else if (name == "EVAF_LOG_DIR") {
+ mLogDir = value;
+ if (!mLogDir.endsWith('/'))
+ mLogDir.append('/');
+ }
+ else if (name == "EVAF_DOC_DIR") {
+ mDocDir = value;
+ if (!mDocDir.endsWith('/'))
+ mDocDir.append('/');
+ }
+ else if (name == "EVAF_QT_PLUGINS_DIR") {
+ mQtPluginsDir = value;
+ if (!mQtPluginsDir.endsWith('/'))
+ mQtPluginsDir.append('/');
+ }
}
// Then process command-line arguments
@@ -94,11 +141,88 @@ bool App::init()
mName = arg.at(1);
else if (QRegExp("-[-]?lang(uage)?").exactMatch(arg.at(0)) && arg.size() > 1)
mLanguage = arg.at(1);
+ else if (QRegExp("-[-]?root(dir)?").exactMatch(arg.at(0)) && arg.size() > 1) {
+ mRootDir = arg.at(1);
+ if (!mRootDir.endsWith('/'))
+ mRootDir.append('/');
+ }
+ else if (QRegExp("-[-]?dataroot(dir)?").exactMatch(arg.at(0)) && arg.size() > 1) {
+ mDataRootDir = arg.at(1);
+ if (!mDataRootDir.endsWith('/'))
+ mDataRootDir.append('/');
+ }
+ else if (QRegExp("-[-]?etc(dir)?").exactMatch(arg.at(0)) && arg.size() > 1) {
+ mEtcDir = arg.at(1);
+ if (!mEtcDir.endsWith('/'))
+ mEtcDir.append('/');
+ }
+ else if (QRegExp("-[-]?log(dir)?").exactMatch(arg.at(0)) && arg.size() > 1) {
+ mLogDir = arg.at(1);
+ if (!mLogDir.endsWith('/'))
+ mLogDir.append('/');
+ }
+ else if (QRegExp("-[-]?doc(dir)?").exactMatch(arg.at(0)) && arg.size() > 1) {
+ mDocDir = arg.at(1);
+ if (!mDocDir.endsWith('/'))
+ mDocDir.append('/');
+ }
+ else if (QRegExp("-[-]?qtplugins(dir)?").exactMatch(arg.at(0)) && arg.size() > 1) {
+ mQtPluginsDir = arg.at(1);
+ if (!mQtPluginsDir.endsWith('/'))
+ mQtPluginsDir.append('/');
+ }
}
return true;
}
+QString const App::dataRootDir() const
+{
+ if (mDataRootDir.isEmpty()) {
+#ifdef Q_OS_LINUX
+ QString dataLoc = QDir::homePath();
+ if (!dataLoc.endsWith('/'))
+ dataLoc.append('/');
+ dataLoc.append(".local/share/data/");
+ mDataRootDir = dataLoc + name();
+ if (!mDataRootDir.endsWith('/'))
+ mDataRootDir.append('/');
+#endif
+ /// @TODO: Needs local data directory on Windows
+ mDataRootDir = rootDir();
+ }
+
+ return mDataRootDir;
+}
+
+QString const App::etcDir() const
+{
+ if (mEtcDir.isEmpty())
+ mEtcDir = dataRootDir() + "etc/";
+ return mEtcDir;
+}
+
+QString const App::logDir() const
+{
+ if (mLogDir.isEmpty())
+ mLogDir = dataRootDir() + "log/";
+ return mLogDir;
+}
+
+QString const App::docDir() const
+{
+ if (mDocDir.isEmpty())
+ mDocDir = rootDir() + "doc/";
+ return mDocDir;
+}
+
+QString const App::qtPluginsDir() const
+{
+ if (mQtPluginsDir.isEmpty())
+ mQtPluginsDir = binDir();
+ return mQtPluginsDir;
+}
+
QString const App::xmlFileName() const
{
if (mXmlFile.isEmpty()) {
@@ -106,13 +230,13 @@ QString const App::xmlFileName() const
// Try the full application name + country + language combination
QString name = mName + "_" + mLanguage + ".xml";
- fi.setFile(iEnv::instance()->etcDir() + name);
+ fi.setFile(etcDir() + name);
if (fi.isReadable())
mXmlFile = name;
else {
// Try application name + country
name = mName + "_" + mLanguage.left(2) + ".xml";
- fi.setFile(iEnv::instance()->etcDir() + name);
+ fi.setFile(etcDir() + name);
if (fi.isReadable())
mXmlFile = name;
else