Skip to content

Commit f68c459

Browse files
committed
Fixed portability issues and added CPack packaging support.
Now STA works as a portable application only in custom paths. If installed into a default system directory, where config and data files can't be written in the folder with the application executable, STA works as a standalone app. Appropriate changes have been applied to storing profiles of default params as well. Also PORTABLE_VERSION CMake parameter has been added to control whether to build the portable version. If disabled, the setting are never stored in the folder with the program even if that's a custom path. (Use cmake ... -D PORTABLE_VERSION={ON/OFF} ... when building) Added CPack packaging support: see https://github.com/4lex4/scantailor-libs-build#packaging for more info. Also now on installing on Linux, scantailor project mime-type is registered and STA is added into start menu.
1 parent 2a5e019 commit f68c459

11 files changed

+270
-186
lines changed

Application.cpp

+25-2
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,12 @@
3131
#include "Application.h"
3232
#include "OutOfMemoryHandler.h"
3333
#include <config.h>
34-
#include <QtCore/QDir>
34+
#include <QDir>
35+
#include <QTemporaryDir>
3536

3637
Application::Application(int& argc, char** argv) : QApplication(argc, argv), m_currentLocale("en") {
3738
initTranslations();
39+
initPortableVersion();
3840
}
3941

4042
bool Application::notify(QObject* receiver, QEvent* e) {
@@ -83,7 +85,7 @@ void Application::initTranslations() {
8385

8486
const QStringList language_file_filter("scantailor_*.qm");
8587
for (const QString& path : translation_dirs) {
86-
QDir dir(QDir::cleanPath(applicationDirPath() + '/' + path));
88+
QDir dir = (QDir::isAbsolutePath(path)) ? QDir(path) : QDir::cleanPath(applicationDirPath() + '/' + path);
8789
if (dir.exists()) {
8890
QStringList translationFileNames = QDir(dir.path()).entryList(language_file_filter);
8991
for (const QString& fileName : translationFileNames) {
@@ -96,3 +98,24 @@ void Application::initTranslations() {
9698
}
9799
}
98100
}
101+
102+
void Application::initPortableVersion() {
103+
const QString portableConfigDirName = QString::fromUtf8(PORTABLE_CONFIG_DIR);
104+
if (portableConfigDirName.isEmpty()) {
105+
return;
106+
}
107+
108+
const QDir portableConfigPath(applicationDirPath() + '/' + portableConfigDirName);
109+
if ((portableConfigPath.exists() && QTemporaryDir(portableConfigPath.absolutePath()).isValid())
110+
|| (!portableConfigPath.exists() && portableConfigPath.mkpath("."))) {
111+
m_portableConfigPath = portableConfigPath.absolutePath();
112+
}
113+
}
114+
115+
bool Application::isPortableVersion() const {
116+
return !m_portableConfigPath.isNull();
117+
}
118+
119+
const QString& Application::getPortableConfigPath() const {
120+
return m_portableConfigPath;
121+
}

Application.h

+7-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
#include <QApplication>
2323
#include <QTimer>
2424
#include <QtCore/QTranslator>
25-
#include "ui_MainWindow.h"
2625
#include "FilterUiInterface.h"
2726
#include "BackgroundTask.h"
2827
#include "OutputFileNameGenerator.h"
@@ -40,13 +39,20 @@ class Application : public QApplication {
4039

4140
std::list<QString> getLanguagesList() const;
4241

42+
bool isPortableVersion() const;
43+
44+
const QString& getPortableConfigPath() const;
45+
4346
private:
4447
void initTranslations();
4548

49+
void initPortableVersion();
50+
4651

4752
QTranslator m_translator;
4853
QString m_currentLocale;
4954
std::map<QString, QString> m_translationsMap;
55+
QString m_portableConfigPath;
5056
};
5157

5258

0 commit comments

Comments
 (0)