diff --git a/harbour-fernschreiber.desktop b/harbour-fernschreiber.desktop index db85a62..f063a12 100644 --- a/harbour-fernschreiber.desktop +++ b/harbour-fernschreiber.desktop @@ -4,3 +4,8 @@ X-Nemo-Application-Type=generic Icon=harbour-fernschreiber Exec=harbour-fernschreiber Name=Fernschreiber + +[X-Sailjail] +Permissions=Audio;Contacts;Documents;Downloads;Internet;Location;MediaIndexing;Microphone;Music;Pictures;PublicDir;UserDirs;Videos +OrganizationName=de.ygriega +ApplicationName=fernschreiber diff --git a/src/appsettings.cpp b/src/appsettings.cpp index 9e68a6d..c5af969 100644 --- a/src/appsettings.cpp +++ b/src/appsettings.cpp @@ -39,7 +39,7 @@ namespace { const QString KEY_SPONSORED_MESS("sponsoredMess"); } -AppSettings::AppSettings(QObject *parent) : QObject(parent), settings("harbour-fernschreiber", "settings") +AppSettings::AppSettings(QObject *parent) : QObject(parent), settings(QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) + "/de.ygriega/fernschreiber/settings.conf", QSettings::NativeFormat) { } diff --git a/src/appsettings.h b/src/appsettings.h index cc5d176..fbd5709 100644 --- a/src/appsettings.h +++ b/src/appsettings.h @@ -20,6 +20,7 @@ #include #include +#include class AppSettings : public QObject { Q_OBJECT diff --git a/src/harbour-fernschreiber.cpp b/src/harbour-fernschreiber.cpp index 319c67f..a584ea7 100644 --- a/src/harbour-fernschreiber.cpp +++ b/src/harbour-fernschreiber.cpp @@ -29,8 +29,15 @@ #include #include #include +#include +#include +#include +#include +#include +#include #include "appsettings.h" +#include "debuglog.h" #include "debuglogjs.h" #include "tdlibfile.h" #include "tdlibwrapper.h" @@ -59,6 +66,55 @@ Q_IMPORT_PLUGIN(TgsIOPlugin) +void migrateSettings() { + const QStringList sailfishOSVersion = QSysInfo::productVersion().split("."); + int sailfishOSMajorVersion = sailfishOSVersion.value(0).toInt(); + int sailfishOSMinorVersion = sailfishOSVersion.value(1).toInt(); + if ((sailfishOSMajorVersion == 4 && sailfishOSMinorVersion >= 4) || sailfishOSMajorVersion > 4) { + LOG("Checking if we need to migrate settings..."); + QSettings settings(QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) + "/de.ygriega/fernschreiber/settings.conf", QSettings::NativeFormat); + if (settings.contains("migrated")) { + return; + } + QSettings oldSettings(QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) + "/harbour-fernschreiber/settings.conf", QSettings::NativeFormat); + const QStringList oldKeys = oldSettings.allKeys(); + if (oldKeys.isEmpty()) { + return; + } + LOG("SailfishOS >= 4.4 and old configuration file detected, migrating settings to new location..."); + for (const QString &key : oldKeys) { + settings.setValue(key, oldSettings.value(key)); + } + + QDir oldDataLocation(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + "/harbour-fernschreiber/harbour-fernschreiber"); + LOG("Old data directory: " + oldDataLocation.path()); + if (oldDataLocation.exists()) { + LOG("Old data files detected, migrating files to new location..."); + const int oldDataPathLength = oldDataLocation.absolutePath().length(); + QString dataLocationPath = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation); + QDir dataLocation(dataLocationPath); + QDirIterator oldDataIterator(oldDataLocation, QDirIterator::Subdirectories); + while (oldDataIterator.hasNext()) { + oldDataIterator.next(); + QFileInfo currentFileInfo = oldDataIterator.fileInfo(); + if (!currentFileInfo.isHidden()) { + const QString subPath = currentFileInfo.absoluteFilePath().mid(oldDataPathLength); + const QString targetPath = dataLocationPath + subPath; + if (currentFileInfo.isDir()) { + LOG("Creating new directory " + targetPath); + dataLocation.mkpath(targetPath); + } else if(currentFileInfo.isFile()) { + LOG("Copying file to " + targetPath); + QFile::copy(currentFileInfo.absoluteFilePath(), targetPath); + } + } + } + } + + settings.setValue("migrated", true); + } +} + int main(int argc, char *argv[]) { QLoggingCategory::setFilterRules(DEFAULT_LOG_FILTER); @@ -68,6 +124,8 @@ int main(int argc, char *argv[]) QQmlContext *context = view.data()->rootContext(); + migrateSettings(); + const char *uri = "WerkWolf.Fernschreiber"; qmlRegisterType(uri, 1, 0, "TDLibFile"); qmlRegisterType(uri, 1, 0, "NamedAction"); diff --git a/src/tdlibwrapper.cpp b/src/tdlibwrapper.cpp index 8182971..8be245e 100644 --- a/src/tdlibwrapper.cpp +++ b/src/tdlibwrapper.cpp @@ -62,7 +62,7 @@ TDLibWrapper::TDLibWrapper(AppSettings *appSettings, MceInterface *mceInterface, this->authorizationState = AuthorizationState::Closed; this->isLoggingOut = false; - initializeTDLibReciever(); + initializeTDLibReceiver(); QString tdLibDatabaseDirectoryPath = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + "/tdlib"; QDir tdLibDatabaseDirectory(tdLibDatabaseDirectoryPath); @@ -98,7 +98,7 @@ TDLibWrapper::~TDLibWrapper() td_json_client_destroy(this->tdLibClient); } -void TDLibWrapper::initializeTDLibReciever() { +void TDLibWrapper::initializeTDLibReceiver() { this->tdLibReceiver = new TDLibReceiver(this->tdLibClient, this); connect(this->tdLibReceiver, SIGNAL(versionDetected(QString)), this, SLOT(handleVersionDetected(QString))); connect(this->tdLibReceiver, SIGNAL(authorizationStateChanged(QString, QVariantMap)), this, SLOT(handleAuthorizationStateChanged(QString, QVariantMap))); @@ -1628,7 +1628,7 @@ void TDLibWrapper::handleAuthorizationStateChanged(const QString &authorizationS QDir appPath(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation)); appPath.removeRecursively(); this->tdLibClient = td_json_client_create(); - initializeTDLibReciever(); + initializeTDLibReceiver(); this->isLoggingOut = false; } this->authorizationStateData = authorizationStateData; @@ -2035,17 +2035,19 @@ void TDLibWrapper::initializeOpenWith() } QString dbusServiceFileName = dbusPathName + "/de.ygriega.fernschreiber.service"; QFile dbusServiceFile(dbusServiceFileName); - if (!dbusServiceFile.exists()) { - LOG("Creating D-Bus service file at" << dbusServiceFile.fileName()); - if (dbusServiceFile.open(QIODevice::WriteOnly | QIODevice::Text)) { - QTextStream fileOut(&dbusServiceFile); - fileOut.setCodec("UTF-8"); - fileOut << QString("[D-BUS Service]").toUtf8() << "\n"; - fileOut << QString("Name=de.ygriega.fernschreiber").toUtf8() << "\n"; - fileOut << QString("Exec=/usr/bin/invoker -s --type=silica-qt5 /usr/bin/harbour-fernschreiber").toUtf8() << "\n"; - fileOut.flush(); - dbusServiceFile.close(); - } + if (dbusServiceFile.exists()) { + LOG("D-BUS service file existing, removing to ensure proper re-creation..."); + dbusServiceFile.remove(); + } + LOG("Creating D-Bus service file at" << dbusServiceFile.fileName()); + if (dbusServiceFile.open(QIODevice::WriteOnly | QIODevice::Text)) { + QTextStream fileOut(&dbusServiceFile); + fileOut.setCodec("UTF-8"); + fileOut << QString("[D-BUS Service]").toUtf8() << "\n"; + fileOut << QString("Name=de.ygriega.fernschreiber").toUtf8() << "\n"; + fileOut << QString("Exec=sailjail -- /usr/bin/harbour-fernschreiber").toUtf8() << "\n"; + fileOut.flush(); + dbusServiceFile.close(); } } diff --git a/src/tdlibwrapper.h b/src/tdlibwrapper.h index fbe5e92..6c3b286 100644 --- a/src/tdlibwrapper.h +++ b/src/tdlibwrapper.h @@ -346,7 +346,7 @@ private: void setEncryptionKey(); void setLogVerbosityLevel(); const Group *updateGroup(qlonglong groupId, const QVariantMap &groupInfo, QHash *groups); - void initializeTDLibReciever(); + void initializeTDLibReceiver(); private: void *tdLibClient;