Some SailJail stuff, eventually need to become SFOS 4.4-ready
This commit is contained in:
parent
40f60cf4be
commit
9d6ff8e7d7
6 changed files with 82 additions and 16 deletions
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
|
||||
#include <QObject>
|
||||
#include <QSettings>
|
||||
#include <QStandardPaths>
|
||||
|
||||
class AppSettings : public QObject {
|
||||
Q_OBJECT
|
||||
|
|
|
@ -29,8 +29,15 @@
|
|||
#include <QQmlEngine>
|
||||
#include <QGuiApplication>
|
||||
#include <QLoggingCategory>
|
||||
#include <QSysInfo>
|
||||
#include <QSettings>
|
||||
#include <QDir>
|
||||
#include <QDirIterator>
|
||||
#include <QFile>
|
||||
#include <QFileInfo>
|
||||
|
||||
#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<TDLibFile>(uri, 1, 0, "TDLibFile");
|
||||
qmlRegisterType<NamedAction>(uri, 1, 0, "NamedAction");
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -346,7 +346,7 @@ private:
|
|||
void setEncryptionKey();
|
||||
void setLogVerbosityLevel();
|
||||
const Group *updateGroup(qlonglong groupId, const QVariantMap &groupInfo, QHash<qlonglong,Group*> *groups);
|
||||
void initializeTDLibReciever();
|
||||
void initializeTDLibReceiver();
|
||||
|
||||
private:
|
||||
void *tdLibClient;
|
||||
|
|
Loading…
Reference in a new issue