Some SailJail stuff, eventually need to become SFOS 4.4-ready

This commit is contained in:
Sebastian Wolf 2022-04-21 22:37:14 +02:00
parent 40f60cf4be
commit 9d6ff8e7d7
No known key found for this signature in database
GPG key ID: CEA9522B5F38A90A
6 changed files with 82 additions and 16 deletions

View file

@ -4,3 +4,8 @@ X-Nemo-Application-Type=generic
Icon=harbour-fernschreiber Icon=harbour-fernschreiber
Exec=harbour-fernschreiber Exec=harbour-fernschreiber
Name=Fernschreiber Name=Fernschreiber
[X-Sailjail]
Permissions=Audio;Contacts;Documents;Downloads;Internet;Location;MediaIndexing;Microphone;Music;Pictures;PublicDir;UserDirs;Videos
OrganizationName=de.ygriega
ApplicationName=fernschreiber

View file

@ -39,7 +39,7 @@ namespace {
const QString KEY_SPONSORED_MESS("sponsoredMess"); 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)
{ {
} }

View file

@ -20,6 +20,7 @@
#include <QObject> #include <QObject>
#include <QSettings> #include <QSettings>
#include <QStandardPaths>
class AppSettings : public QObject { class AppSettings : public QObject {
Q_OBJECT Q_OBJECT

View file

@ -29,8 +29,15 @@
#include <QQmlEngine> #include <QQmlEngine>
#include <QGuiApplication> #include <QGuiApplication>
#include <QLoggingCategory> #include <QLoggingCategory>
#include <QSysInfo>
#include <QSettings>
#include <QDir>
#include <QDirIterator>
#include <QFile>
#include <QFileInfo>
#include "appsettings.h" #include "appsettings.h"
#include "debuglog.h"
#include "debuglogjs.h" #include "debuglogjs.h"
#include "tdlibfile.h" #include "tdlibfile.h"
#include "tdlibwrapper.h" #include "tdlibwrapper.h"
@ -59,6 +66,55 @@
Q_IMPORT_PLUGIN(TgsIOPlugin) 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[]) int main(int argc, char *argv[])
{ {
QLoggingCategory::setFilterRules(DEFAULT_LOG_FILTER); QLoggingCategory::setFilterRules(DEFAULT_LOG_FILTER);
@ -68,6 +124,8 @@ int main(int argc, char *argv[])
QQmlContext *context = view.data()->rootContext(); QQmlContext *context = view.data()->rootContext();
migrateSettings();
const char *uri = "WerkWolf.Fernschreiber"; const char *uri = "WerkWolf.Fernschreiber";
qmlRegisterType<TDLibFile>(uri, 1, 0, "TDLibFile"); qmlRegisterType<TDLibFile>(uri, 1, 0, "TDLibFile");
qmlRegisterType<NamedAction>(uri, 1, 0, "NamedAction"); qmlRegisterType<NamedAction>(uri, 1, 0, "NamedAction");

View file

@ -62,7 +62,7 @@ TDLibWrapper::TDLibWrapper(AppSettings *appSettings, MceInterface *mceInterface,
this->authorizationState = AuthorizationState::Closed; this->authorizationState = AuthorizationState::Closed;
this->isLoggingOut = false; this->isLoggingOut = false;
initializeTDLibReciever(); initializeTDLibReceiver();
QString tdLibDatabaseDirectoryPath = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + "/tdlib"; QString tdLibDatabaseDirectoryPath = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + "/tdlib";
QDir tdLibDatabaseDirectory(tdLibDatabaseDirectoryPath); QDir tdLibDatabaseDirectory(tdLibDatabaseDirectoryPath);
@ -98,7 +98,7 @@ TDLibWrapper::~TDLibWrapper()
td_json_client_destroy(this->tdLibClient); td_json_client_destroy(this->tdLibClient);
} }
void TDLibWrapper::initializeTDLibReciever() { void TDLibWrapper::initializeTDLibReceiver() {
this->tdLibReceiver = new TDLibReceiver(this->tdLibClient, this); this->tdLibReceiver = new TDLibReceiver(this->tdLibClient, this);
connect(this->tdLibReceiver, SIGNAL(versionDetected(QString)), this, SLOT(handleVersionDetected(QString))); connect(this->tdLibReceiver, SIGNAL(versionDetected(QString)), this, SLOT(handleVersionDetected(QString)));
connect(this->tdLibReceiver, SIGNAL(authorizationStateChanged(QString, QVariantMap)), this, SLOT(handleAuthorizationStateChanged(QString, QVariantMap))); 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)); QDir appPath(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation));
appPath.removeRecursively(); appPath.removeRecursively();
this->tdLibClient = td_json_client_create(); this->tdLibClient = td_json_client_create();
initializeTDLibReciever(); initializeTDLibReceiver();
this->isLoggingOut = false; this->isLoggingOut = false;
} }
this->authorizationStateData = authorizationStateData; this->authorizationStateData = authorizationStateData;
@ -2035,19 +2035,21 @@ void TDLibWrapper::initializeOpenWith()
} }
QString dbusServiceFileName = dbusPathName + "/de.ygriega.fernschreiber.service"; QString dbusServiceFileName = dbusPathName + "/de.ygriega.fernschreiber.service";
QFile dbusServiceFile(dbusServiceFileName); QFile dbusServiceFile(dbusServiceFileName);
if (!dbusServiceFile.exists()) { 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()); LOG("Creating D-Bus service file at" << dbusServiceFile.fileName());
if (dbusServiceFile.open(QIODevice::WriteOnly | QIODevice::Text)) { if (dbusServiceFile.open(QIODevice::WriteOnly | QIODevice::Text)) {
QTextStream fileOut(&dbusServiceFile); QTextStream fileOut(&dbusServiceFile);
fileOut.setCodec("UTF-8"); fileOut.setCodec("UTF-8");
fileOut << QString("[D-BUS Service]").toUtf8() << "\n"; fileOut << QString("[D-BUS Service]").toUtf8() << "\n";
fileOut << QString("Name=de.ygriega.fernschreiber").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 << QString("Exec=sailjail -- /usr/bin/harbour-fernschreiber").toUtf8() << "\n";
fileOut.flush(); fileOut.flush();
dbusServiceFile.close(); dbusServiceFile.close();
} }
} }
}
void TDLibWrapper::removeOpenWith() void TDLibWrapper::removeOpenWith()
{ {

View file

@ -346,7 +346,7 @@ private:
void setEncryptionKey(); void setEncryptionKey();
void setLogVerbosityLevel(); void setLogVerbosityLevel();
const Group *updateGroup(qlonglong groupId, const QVariantMap &groupInfo, QHash<qlonglong,Group*> *groups); const Group *updateGroup(qlonglong groupId, const QVariantMap &groupInfo, QHash<qlonglong,Group*> *groups);
void initializeTDLibReciever(); void initializeTDLibReceiver();
private: private:
void *tdLibClient; void *tdLibClient;