diff --git a/harbour-fernschreiber.pro b/harbour-fernschreiber.pro index ac8118d..049199e 100644 --- a/harbour-fernschreiber.pro +++ b/harbour-fernschreiber.pro @@ -34,6 +34,8 @@ SOURCES += src/harbour-fernschreiber.cpp \ src/namedaction.cpp \ src/notificationmanager.cpp \ src/processlauncher.cpp \ + src/stayawakeadaptor.cpp \ + src/stayawakeinterface.cpp \ src/stickermanager.cpp \ src/tdlibfile.cpp \ src/tdlibreceiver.cpp \ @@ -163,6 +165,8 @@ HEADERS += \ src/namedaction.h \ src/notificationmanager.h \ src/processlauncher.h \ + src/stayawakeadaptor.h \ + src/stayawakeinterface.h \ src/stickermanager.h \ src/tdlibfile.h \ src/tdlibreceiver.h \ diff --git a/src/appsettings.cpp b/src/appsettings.cpp index d91a1c1..0522560 100644 --- a/src/appsettings.cpp +++ b/src/appsettings.cpp @@ -22,6 +22,7 @@ #include #include +#include namespace { const QString KEY_SEND_BY_ENTER("sendByEnter"); @@ -76,6 +77,7 @@ void AppSettings::setStayInBackground(bool stayInBackground) if (getStayInBackground() != stayInBackground) { LOG(KEY_STAY_IN_BACKGROUND << stayInBackground); settings.setValue(KEY_STAY_IN_BACKGROUND, stayInBackground); + QGuiApplication::setQuitOnLastWindowClosed(!stayInBackground); emit stayInBackgroundChanged(); } } @@ -153,7 +155,7 @@ void AppSettings::setStorageOptimizer(bool enable) bool AppSettings::isAppRunning() { LOG("Checking via D-Bus if app is already running..."); - QDBusInterface dBusInterface("de.ygriega.fernschreiber", "/de/ygriega/fernschreiber", "", QDBusConnection::sessionBus()); + QDBusInterface dBusInterface("de.ygriega.stayawake", "/de/ygriega/stayawake", "", QDBusConnection::sessionBus()); if (dBusInterface.isValid()) { QDBusReply reply = dBusInterface.call("showUI"); if (reply.isValid()) { diff --git a/src/dbusadaptor.cpp b/src/dbusadaptor.cpp index 01fa14c..16e17ed 100644 --- a/src/dbusadaptor.cpp +++ b/src/dbusadaptor.cpp @@ -26,11 +26,6 @@ DBusAdaptor::DBusAdaptor(QObject *parent): QDBusAbstractAdaptor(parent) { } -void DBusAdaptor::setAppView(QQuickView *appView) -{ - this->appView = appView; -} - void DBusAdaptor::openMessage(const QString &chatId, const QString &messageId) { LOG("Open Message" << chatId << messageId); @@ -44,10 +39,3 @@ void DBusAdaptor::openUrl(const QStringList &arguments) emit pleaseOpenUrl(arguments.first()); } } - -bool DBusAdaptor::showUI() -{ - LOG("UI shall wake up!"); - this->appView->showFullScreen(); - return true; -} diff --git a/src/dbusadaptor.h b/src/dbusadaptor.h index 25998e6..883608e 100644 --- a/src/dbusadaptor.h +++ b/src/dbusadaptor.h @@ -32,8 +32,6 @@ class DBusAdaptor : public QDBusAbstractAdaptor public: DBusAdaptor(QObject *parent); - void setAppView(QQuickView* appView); - signals: void pleaseOpenMessage(const QString &chatId, const QString &messageId); void pleaseOpenUrl(const QString &url); @@ -41,10 +39,6 @@ signals: public slots: void openMessage(const QString &chatId, const QString &messageId); void openUrl(const QStringList &arguments); - bool showUI(); - -private: - QQuickView *appView; }; diff --git a/src/harbour-fernschreiber.cpp b/src/harbour-fernschreiber.cpp index ab9aa57..314492a 100644 --- a/src/harbour-fernschreiber.cpp +++ b/src/harbour-fernschreiber.cpp @@ -41,6 +41,8 @@ #include "mceinterface.h" #include "dbusinterface.h" #include "dbusadaptor.h" +#include "stayawakeinterface.h" +#include "stayawakeadaptor.h" #include "processlauncher.h" #include "stickermanager.h" #include "tgsplugin.h" @@ -76,9 +78,9 @@ int main(int argc, char *argv[]) context->setContextProperty("appSettings", appSettings); qmlRegisterUncreatableType(uri, 1, 0, "AppSettings", QString()); -// if (appSettings->isAppRunning()) { -// return 0; -// } + if (appSettings->isAppRunning()) { + return 0; + } if (appSettings->getStayInBackground()) { app.data()->setQuitOnLastWindowClosed(false); @@ -86,9 +88,13 @@ int main(int argc, char *argv[]) DBusInterface *dBusInterface = new DBusInterface(view.data()); DBusAdaptor *dBusAdaptor = dBusInterface->getDBusAdaptor(); - dBusAdaptor->setAppView(view.data()); context->setContextProperty("dBusAdaptor", dBusAdaptor); + StayAwakeInterface *stayAwakeInterface = new StayAwakeInterface(view.data()); + StayAwakeAdaptor *stayAwakeAdaptor = stayAwakeInterface->getStayAwakeAdaptor(); + stayAwakeAdaptor->setAppView(view.data()); + context->setContextProperty("stayAwakeAdaptor", stayAwakeAdaptor); + MceInterface *mceInterface = new MceInterface(view.data()); TDLibWrapper *tdLibWrapper = new TDLibWrapper(appSettings, mceInterface, view.data()); context->setContextProperty("tdLibWrapper", tdLibWrapper); diff --git a/src/stayawakeadaptor.cpp b/src/stayawakeadaptor.cpp new file mode 100644 index 0000000..bf7bb6f --- /dev/null +++ b/src/stayawakeadaptor.cpp @@ -0,0 +1,41 @@ +/* + Copyright (C) 2020 Sebastian J. Wolf and other contributors + + This file is part of Fernschreiber. + + Fernschreiber is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Fernschreiber is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Fernschreiber. If not, see . +*/ + + +#include "stayawakeadaptor.h" + +#define DEBUG_MODULE StayAwakeAdaptor +#include "debuglog.h" + +StayAwakeAdaptor::StayAwakeAdaptor(QObject *parent): QDBusAbstractAdaptor(parent) +{ + +} + +void StayAwakeAdaptor::setAppView(QQuickView *appView) +{ + this->appView = appView; +} + +bool StayAwakeAdaptor::showUI() +{ + LOG("UI shall wake up!"); + this->appView->showFullScreen(); + return true; +} diff --git a/src/stayawakeadaptor.h b/src/stayawakeadaptor.h new file mode 100644 index 0000000..08ae774 --- /dev/null +++ b/src/stayawakeadaptor.h @@ -0,0 +1,47 @@ +/* + Copyright (C) 2020 Sebastian J. Wolf and other contributors + + This file is part of Fernschreiber. + + Fernschreiber is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Fernschreiber is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Fernschreiber. If not, see . +*/ + + +#ifndef STAYAWAKEADAPTOR_H +#define STAYAWAKEADAPTOR_H + + +#include +#include + +class StayAwakeAdaptor : public QDBusAbstractAdaptor +{ + + Q_OBJECT + Q_CLASSINFO("D-Bus Interface", "de.ygriega.stayawake") + +public: + StayAwakeAdaptor(QObject *parent); + + void setAppView(QQuickView* appView); + +public slots: + bool showUI(); + +private: + QQuickView *appView; + +}; + +#endif // STAYAWAKEADAPTOR_H diff --git a/src/stayawakeinterface.cpp b/src/stayawakeinterface.cpp new file mode 100644 index 0000000..2fc8e54 --- /dev/null +++ b/src/stayawakeinterface.cpp @@ -0,0 +1,50 @@ +/* + Copyright (C) 2020 Sebastian J. Wolf and other contributors + + This file is part of Fernschreiber. + + Fernschreiber is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Fernschreiber is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Fernschreiber. If not, see . +*/ + +#include "stayawakeinterface.h" + +#define DEBUG_MODULE StayAwakeInterface +#include "debuglog.h" + +StayAwakeInterface::StayAwakeInterface(QObject *parent) : QObject(parent) +{ + LOG("Initializing D-BUS connectivity"); + this->stayAwakeAdaptor = new StayAwakeAdaptor(this); + QDBusConnection sessionBusConnection = QDBusConnection::sessionBus(); + + if (!sessionBusConnection.isConnected()) { + WARN("Error connecting to D-BUS"); + return; + } + + if (!sessionBusConnection.registerObject("/de/ygriega/stayawake", this)) { + WARN("Error registering root object to D-BUS" << sessionBusConnection.lastError().message()); + return; + } + + if (!sessionBusConnection.registerService("de.ygriega.stayawake")) { + WARN("Error registering interface to D-BUS" << sessionBusConnection.lastError().message()); + return; + } +} + +StayAwakeAdaptor *StayAwakeInterface::getStayAwakeAdaptor() +{ + return this->stayAwakeAdaptor; +} diff --git a/src/stayawakeinterface.h b/src/stayawakeinterface.h new file mode 100644 index 0000000..755f4a3 --- /dev/null +++ b/src/stayawakeinterface.h @@ -0,0 +1,45 @@ +/* + Copyright (C) 2020 Sebastian J. Wolf and other contributors + + This file is part of Fernschreiber. + + Fernschreiber is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Fernschreiber is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Fernschreiber. If not, see . +*/ + +#ifndef STAYAWAKEINTERFACE_H +#define STAYAWAKEINTERFACE_H + +#include +#include + +#include "stayawakeadaptor.h" + +class StayAwakeInterface : public QObject +{ + Q_OBJECT +public: + explicit StayAwakeInterface(QObject *parent = nullptr); + + StayAwakeAdaptor *getStayAwakeAdaptor(); + +signals: + +public slots: + +private: + StayAwakeAdaptor *stayAwakeAdaptor; + +}; + +#endif // STAYAWAKEINTERFACE_H