Add MceInterface object

This commit is contained in:
Slava Monich 2020-11-23 00:32:00 +02:00
parent 6140d54b18
commit 3d48125371
8 changed files with 114 additions and 23 deletions

View file

@ -28,6 +28,7 @@ SOURCES += src/harbour-fernschreiber.cpp \
src/dbusinterface.cpp \ src/dbusinterface.cpp \
src/emojisearchworker.cpp \ src/emojisearchworker.cpp \
src/fernschreiberutils.cpp \ src/fernschreiberutils.cpp \
src/mceinterface.cpp \
src/notificationmanager.cpp \ src/notificationmanager.cpp \
src/processlauncher.cpp \ src/processlauncher.cpp \
src/stickermanager.cpp \ src/stickermanager.cpp \
@ -150,6 +151,7 @@ HEADERS += \
src/debuglogjs.h \ src/debuglogjs.h \
src/emojisearchworker.h \ src/emojisearchworker.h \
src/fernschreiberutils.h \ src/fernschreiberutils.h \
src/mceinterface.h \
src/notificationmanager.h \ src/notificationmanager.h \
src/processlauncher.h \ src/processlauncher.h \
src/stickermanager.h \ src/stickermanager.h \

View file

@ -36,6 +36,7 @@
#include "chatlistmodel.h" #include "chatlistmodel.h"
#include "chatmodel.h" #include "chatmodel.h"
#include "notificationmanager.h" #include "notificationmanager.h"
#include "mceinterface.h"
#include "dbusadaptor.h" #include "dbusadaptor.h"
#include "processlauncher.h" #include "processlauncher.h"
#include "stickermanager.h" #include "stickermanager.h"
@ -69,7 +70,8 @@ int main(int argc, char *argv[])
context->setContextProperty("appSettings", appSettings); context->setContextProperty("appSettings", appSettings);
qmlRegisterUncreatableType<AppSettings>(uri, 1, 0, "AppSettings", QString()); qmlRegisterUncreatableType<AppSettings>(uri, 1, 0, "AppSettings", QString());
TDLibWrapper *tdLibWrapper = new TDLibWrapper(appSettings, view.data()); MceInterface *mceInterface = new MceInterface(view.data());
TDLibWrapper *tdLibWrapper = new TDLibWrapper(appSettings, mceInterface, view.data());
context->setContextProperty("tdLibWrapper", tdLibWrapper); context->setContextProperty("tdLibWrapper", tdLibWrapper);
qmlRegisterUncreatableType<TDLibWrapper>(uri, 1, 0, "TelegramAPI", QString()); qmlRegisterUncreatableType<TDLibWrapper>(uri, 1, 0, "TelegramAPI", QString());
@ -85,7 +87,7 @@ int main(int argc, char *argv[])
ChatModel chatModel(tdLibWrapper); ChatModel chatModel(tdLibWrapper);
context->setContextProperty("chatModel", &chatModel); context->setContextProperty("chatModel", &chatModel);
NotificationManager notificationManager(tdLibWrapper, appSettings, &chatModel); NotificationManager notificationManager(tdLibWrapper, appSettings, mceInterface, &chatModel);
context->setContextProperty("notificationManager", &notificationManager); context->setContextProperty("notificationManager", &notificationManager);
ProcessLauncher processLauncher; ProcessLauncher processLauncher;

54
src/mceinterface.cpp Normal file
View file

@ -0,0 +1,54 @@
/*
Copyright (C) 2020 Slava Monich et al.
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 <http://www.gnu.org/licenses/>.
*/
#include "mceinterface.h"
#include <QDBusConnection>
#define DEBUG_MODULE MceInterface
#include "debuglog.h"
MceInterface::MceInterface(QObject *parent) :
QDBusInterface("com.nokia.mce", "/com/nokia/mce/request", "com.nokia.mce.request",
QDBusConnection::systemBus(), parent)
{
}
void MceInterface::ledPatternActivate(const QString &pattern)
{
LOG("Activating pattern" << pattern);
call(QStringLiteral("req_led_pattern_activate"), pattern);
}
void MceInterface::ledPatternDeactivate(const QString &pattern)
{
LOG("Deactivating pattern" << pattern);
call(QStringLiteral("req_led_pattern_deactivate"), pattern);
}
void MceInterface::displayCancelBlankingPause()
{
LOG("Enabling display blanking");
call(QStringLiteral("req_display_cancel_blanking_pause"));
}
void MceInterface::displayBlankingPause()
{
LOG("Disabling display blanking");
call(QStringLiteral("req_display_blanking_pause"));
}

37
src/mceinterface.h Normal file
View file

@ -0,0 +1,37 @@
/*
Copyright (C) 2020 Slava Monich et al.
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 <http://www.gnu.org/licenses/>.
*/
#ifndef MCE_INTERFACE_H
#define MCE_INTERFACE_H
#include <QDBusInterface>
class MceInterface : public QDBusInterface
{
public:
MceInterface(QObject *parent = Q_NULLPTR);
void ledPatternActivate(const QString &pattern);
void ledPatternDeactivate(const QString &pattern);
void displayCancelBlankingPause();
void displayBlankingPause();
};
#endif // MCE_INTERFACE_H

View file

@ -120,14 +120,13 @@ NotificationManager::NotificationGroup::~NotificationGroup()
delete nemoNotification; delete nemoNotification;
} }
NotificationManager::NotificationManager(TDLibWrapper *tdLibWrapper, AppSettings *appSettings, ChatModel *chatModel) : NotificationManager::NotificationManager(TDLibWrapper *tdLibWrapper, AppSettings *appSettings, MceInterface *mceInterface, ChatModel *chatModel) :
mceInterface("com.nokia.mce", "/com/nokia/mce/request", "com.nokia.mce.request", QDBusConnection::systemBus()),
appIconFile(SailfishApp::pathTo("images/fernschreiber-notification.png").toLocalFile()) appIconFile(SailfishApp::pathTo("images/fernschreiber-notification.png").toLocalFile())
{ {
LOG("Initializing..."); LOG("Initializing...");
this->tdLibWrapper = tdLibWrapper; this->tdLibWrapper = tdLibWrapper;
this->appSettings = appSettings; this->appSettings = appSettings;
this->appSettings = appSettings; this->mceInterface = mceInterface;
this->chatModel = chatModel; this->chatModel = chatModel;
connect(this->tdLibWrapper, SIGNAL(activeNotificationsUpdated(QVariantList)), this, SLOT(handleUpdateActiveNotifications(QVariantList))); connect(this->tdLibWrapper, SIGNAL(activeNotificationsUpdated(QVariantList)), this, SLOT(handleUpdateActiveNotifications(QVariantList)));
@ -383,9 +382,9 @@ QString NotificationManager::getNotificationText(const QVariantMap &notification
void NotificationManager::controlLedNotification(bool enabled) void NotificationManager::controlLedNotification(bool enabled)
{ {
static const QString PATTERN("PatternCommunicationIM"); static const QString PATTERN("PatternCommunicationIM");
static const QString ACTIVATE("req_led_pattern_activate"); if (enabled) {
static const QString DEACTIVATE("req_led_pattern_deactivate"); mceInterface->ledPatternActivate(PATTERN);
} else {
LOG("Controlling notification LED" << enabled); mceInterface->ledPatternDeactivate(PATTERN);
mceInterface.call(enabled ? ACTIVATE : DEACTIVATE, PATTERN); }
} }

View file

@ -21,10 +21,10 @@
#define NOTIFICATIONMANAGER_H #define NOTIFICATIONMANAGER_H
#include <QObject> #include <QObject>
#include <QDBusInterface>
#include <nemonotifications-qt5/notification.h> #include <nemonotifications-qt5/notification.h>
#include "tdlibwrapper.h" #include "tdlibwrapper.h"
#include "appsettings.h" #include "appsettings.h"
#include "mceinterface.h"
class ChatModel; class ChatModel;
@ -36,7 +36,7 @@ class NotificationManager : public QObject
public: public:
NotificationManager(TDLibWrapper *tdLibWrapper, AppSettings *appSettings, ChatModel *chatModel); NotificationManager(TDLibWrapper *tdLibWrapper, AppSettings *appSettings, MceInterface *mceInterface, ChatModel *chatModel);
~NotificationManager() override; ~NotificationManager() override;
public slots: public slots:
@ -61,10 +61,10 @@ private:
TDLibWrapper *tdLibWrapper; TDLibWrapper *tdLibWrapper;
AppSettings *appSettings; AppSettings *appSettings;
MceInterface *mceInterface;
ChatModel *chatModel; ChatModel *chatModel;
QMap<qlonglong,ChatInfo*> chatMap; QMap<qlonglong,ChatInfo*> chatMap;
QMap<int,NotificationGroup*> notificationGroups; QMap<int,NotificationGroup*> notificationGroups;
QDBusInterface mceInterface;
QString appIconFile; QString appIconFile;
}; };

View file

@ -41,10 +41,11 @@ namespace {
const QString _EXTRA("@extra"); const QString _EXTRA("@extra");
} }
TDLibWrapper::TDLibWrapper(AppSettings *appSettings, QObject *parent) : QObject(parent), joinChatRequested(false) TDLibWrapper::TDLibWrapper(AppSettings *appSettings, MceInterface *mceInterface, QObject *parent) : QObject(parent), joinChatRequested(false)
{ {
LOG("Initializing TD Lib..."); LOG("Initializing TD Lib...");
this->appSettings = appSettings; this->appSettings = appSettings;
this->mceInterface = mceInterface;
this->tdLibClient = td_json_client_create(); this->tdLibClient = td_json_client_create();
this->tdLibReceiver = new TDLibReceiver(this->tdLibClient, this); this->tdLibReceiver = new TDLibReceiver(this->tdLibClient, this);
@ -892,16 +893,10 @@ void TDLibWrapper::openFileOnDevice(const QString &filePath)
void TDLibWrapper::controlScreenSaver(bool enabled) void TDLibWrapper::controlScreenSaver(bool enabled)
{ {
LOG("Controlling device screen saver" << enabled);
QDBusConnection dbusConnection = QDBusConnection::connectToBus(QDBusConnection::SystemBus, "system");
QDBusInterface dbusInterface("com.nokia.mce", "/com/nokia/mce/request", "com.nokia.mce.request", dbusConnection);
if (enabled) { if (enabled) {
LOG("Enabling screensaver"); mceInterface->displayCancelBlankingPause();
dbusInterface.call("req_display_cancel_blanking_pause");
} else { } else {
LOG("Disabling screensaver"); mceInterface->displayBlankingPause();
dbusInterface.call("req_display_blanking_pause");
} }
} }

View file

@ -26,12 +26,13 @@
#include "dbusinterface.h" #include "dbusinterface.h"
#include "emojisearchworker.h" #include "emojisearchworker.h"
#include "appsettings.h" #include "appsettings.h"
#include "mceinterface.h"
class TDLibWrapper : public QObject class TDLibWrapper : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit TDLibWrapper(AppSettings *appSettings, QObject *parent = nullptr); explicit TDLibWrapper(AppSettings *appSettings, MceInterface *mceInterface, QObject *parent = nullptr);
~TDLibWrapper(); ~TDLibWrapper();
enum AuthorizationState { enum AuthorizationState {
@ -251,6 +252,7 @@ private:
private: private:
void *tdLibClient; void *tdLibClient;
AppSettings *appSettings; AppSettings *appSettings;
MceInterface *mceInterface;
TDLibReceiver *tdLibReceiver; TDLibReceiver *tdLibReceiver;
DBusInterface *dbusInterface; DBusInterface *dbusInterface;
QString version; QString version;