Skip to content

Commit

Permalink
Fixed portability issues and added CPack packaging support.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
4lex4 committed Apr 19, 2018
1 parent 2a5e019 commit f68c459
Show file tree
Hide file tree
Showing 11 changed files with 270 additions and 186 deletions.
27 changes: 25 additions & 2 deletions Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,12 @@
#include "Application.h"
#include "OutOfMemoryHandler.h"
#include <config.h>
#include <QtCore/QDir>
#include <QDir>
#include <QTemporaryDir>

Application::Application(int& argc, char** argv) : QApplication(argc, argv), m_currentLocale("en") {
initTranslations();
initPortableVersion();
}

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

const QStringList language_file_filter("scantailor_*.qm");
for (const QString& path : translation_dirs) {
QDir dir(QDir::cleanPath(applicationDirPath() + '/' + path));
QDir dir = (QDir::isAbsolutePath(path)) ? QDir(path) : QDir::cleanPath(applicationDirPath() + '/' + path);
if (dir.exists()) {
QStringList translationFileNames = QDir(dir.path()).entryList(language_file_filter);
for (const QString& fileName : translationFileNames) {
Expand All @@ -96,3 +98,24 @@ void Application::initTranslations() {
}
}
}

void Application::initPortableVersion() {
const QString portableConfigDirName = QString::fromUtf8(PORTABLE_CONFIG_DIR);
if (portableConfigDirName.isEmpty()) {
return;
}

const QDir portableConfigPath(applicationDirPath() + '/' + portableConfigDirName);
if ((portableConfigPath.exists() && QTemporaryDir(portableConfigPath.absolutePath()).isValid())
|| (!portableConfigPath.exists() && portableConfigPath.mkpath("."))) {
m_portableConfigPath = portableConfigPath.absolutePath();
}
}

bool Application::isPortableVersion() const {
return !m_portableConfigPath.isNull();
}

const QString& Application::getPortableConfigPath() const {
return m_portableConfigPath;
}
8 changes: 7 additions & 1 deletion Application.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#include <QApplication>
#include <QTimer>
#include <QtCore/QTranslator>
#include "ui_MainWindow.h"
#include "FilterUiInterface.h"
#include "BackgroundTask.h"
#include "OutputFileNameGenerator.h"
Expand All @@ -40,13 +39,20 @@ class Application : public QApplication {

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

bool isPortableVersion() const;

const QString& getPortableConfigPath() const;

private:
void initTranslations();

void initPortableVersion();


QTranslator m_translator;
QString m_currentLocale;
std::map<QString, QString> m_translationsMap;
QString m_portableConfigPath;
};


Expand Down
Loading

0 comments on commit f68c459

Please sign in to comment.