Add MceInterface object
This commit is contained in:
parent
6140d54b18
commit
3d48125371
8 changed files with 114 additions and 23 deletions
|
@ -28,6 +28,7 @@ SOURCES += src/harbour-fernschreiber.cpp \
|
|||
src/dbusinterface.cpp \
|
||||
src/emojisearchworker.cpp \
|
||||
src/fernschreiberutils.cpp \
|
||||
src/mceinterface.cpp \
|
||||
src/notificationmanager.cpp \
|
||||
src/processlauncher.cpp \
|
||||
src/stickermanager.cpp \
|
||||
|
@ -150,6 +151,7 @@ HEADERS += \
|
|||
src/debuglogjs.h \
|
||||
src/emojisearchworker.h \
|
||||
src/fernschreiberutils.h \
|
||||
src/mceinterface.h \
|
||||
src/notificationmanager.h \
|
||||
src/processlauncher.h \
|
||||
src/stickermanager.h \
|
||||
|
|
|
@ -36,6 +36,7 @@
|
|||
#include "chatlistmodel.h"
|
||||
#include "chatmodel.h"
|
||||
#include "notificationmanager.h"
|
||||
#include "mceinterface.h"
|
||||
#include "dbusadaptor.h"
|
||||
#include "processlauncher.h"
|
||||
#include "stickermanager.h"
|
||||
|
@ -69,7 +70,8 @@ int main(int argc, char *argv[])
|
|||
context->setContextProperty("appSettings", appSettings);
|
||||
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);
|
||||
qmlRegisterUncreatableType<TDLibWrapper>(uri, 1, 0, "TelegramAPI", QString());
|
||||
|
||||
|
@ -85,7 +87,7 @@ int main(int argc, char *argv[])
|
|||
ChatModel chatModel(tdLibWrapper);
|
||||
context->setContextProperty("chatModel", &chatModel);
|
||||
|
||||
NotificationManager notificationManager(tdLibWrapper, appSettings, &chatModel);
|
||||
NotificationManager notificationManager(tdLibWrapper, appSettings, mceInterface, &chatModel);
|
||||
context->setContextProperty("notificationManager", ¬ificationManager);
|
||||
|
||||
ProcessLauncher processLauncher;
|
||||
|
|
54
src/mceinterface.cpp
Normal file
54
src/mceinterface.cpp
Normal 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
37
src/mceinterface.h
Normal 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
|
||||
|
|
@ -120,14 +120,13 @@ NotificationManager::NotificationGroup::~NotificationGroup()
|
|||
delete nemoNotification;
|
||||
}
|
||||
|
||||
NotificationManager::NotificationManager(TDLibWrapper *tdLibWrapper, AppSettings *appSettings, ChatModel *chatModel) :
|
||||
mceInterface("com.nokia.mce", "/com/nokia/mce/request", "com.nokia.mce.request", QDBusConnection::systemBus()),
|
||||
NotificationManager::NotificationManager(TDLibWrapper *tdLibWrapper, AppSettings *appSettings, MceInterface *mceInterface, ChatModel *chatModel) :
|
||||
appIconFile(SailfishApp::pathTo("images/fernschreiber-notification.png").toLocalFile())
|
||||
{
|
||||
LOG("Initializing...");
|
||||
this->tdLibWrapper = tdLibWrapper;
|
||||
this->appSettings = appSettings;
|
||||
this->appSettings = appSettings;
|
||||
this->mceInterface = mceInterface;
|
||||
this->chatModel = chatModel;
|
||||
|
||||
connect(this->tdLibWrapper, SIGNAL(activeNotificationsUpdated(QVariantList)), this, SLOT(handleUpdateActiveNotifications(QVariantList)));
|
||||
|
@ -383,9 +382,9 @@ QString NotificationManager::getNotificationText(const QVariantMap ¬ification
|
|||
void NotificationManager::controlLedNotification(bool enabled)
|
||||
{
|
||||
static const QString PATTERN("PatternCommunicationIM");
|
||||
static const QString ACTIVATE("req_led_pattern_activate");
|
||||
static const QString DEACTIVATE("req_led_pattern_deactivate");
|
||||
|
||||
LOG("Controlling notification LED" << enabled);
|
||||
mceInterface.call(enabled ? ACTIVATE : DEACTIVATE, PATTERN);
|
||||
if (enabled) {
|
||||
mceInterface->ledPatternActivate(PATTERN);
|
||||
} else {
|
||||
mceInterface->ledPatternDeactivate(PATTERN);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,10 +21,10 @@
|
|||
#define NOTIFICATIONMANAGER_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QDBusInterface>
|
||||
#include <nemonotifications-qt5/notification.h>
|
||||
#include "tdlibwrapper.h"
|
||||
#include "appsettings.h"
|
||||
#include "mceinterface.h"
|
||||
|
||||
class ChatModel;
|
||||
|
||||
|
@ -36,7 +36,7 @@ class NotificationManager : public QObject
|
|||
|
||||
public:
|
||||
|
||||
NotificationManager(TDLibWrapper *tdLibWrapper, AppSettings *appSettings, ChatModel *chatModel);
|
||||
NotificationManager(TDLibWrapper *tdLibWrapper, AppSettings *appSettings, MceInterface *mceInterface, ChatModel *chatModel);
|
||||
~NotificationManager() override;
|
||||
|
||||
public slots:
|
||||
|
@ -61,10 +61,10 @@ private:
|
|||
|
||||
TDLibWrapper *tdLibWrapper;
|
||||
AppSettings *appSettings;
|
||||
MceInterface *mceInterface;
|
||||
ChatModel *chatModel;
|
||||
QMap<qlonglong,ChatInfo*> chatMap;
|
||||
QMap<int,NotificationGroup*> notificationGroups;
|
||||
QDBusInterface mceInterface;
|
||||
QString appIconFile;
|
||||
|
||||
};
|
||||
|
|
|
@ -41,10 +41,11 @@ namespace {
|
|||
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...");
|
||||
this->appSettings = appSettings;
|
||||
this->mceInterface = mceInterface;
|
||||
this->tdLibClient = td_json_client_create();
|
||||
this->tdLibReceiver = new TDLibReceiver(this->tdLibClient, this);
|
||||
|
||||
|
@ -892,16 +893,10 @@ void TDLibWrapper::openFileOnDevice(const QString &filePath)
|
|||
|
||||
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) {
|
||||
LOG("Enabling screensaver");
|
||||
dbusInterface.call("req_display_cancel_blanking_pause");
|
||||
mceInterface->displayCancelBlankingPause();
|
||||
} else {
|
||||
LOG("Disabling screensaver");
|
||||
dbusInterface.call("req_display_blanking_pause");
|
||||
mceInterface->displayBlankingPause();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -26,12 +26,13 @@
|
|||
#include "dbusinterface.h"
|
||||
#include "emojisearchworker.h"
|
||||
#include "appsettings.h"
|
||||
#include "mceinterface.h"
|
||||
|
||||
class TDLibWrapper : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit TDLibWrapper(AppSettings *appSettings, QObject *parent = nullptr);
|
||||
explicit TDLibWrapper(AppSettings *appSettings, MceInterface *mceInterface, QObject *parent = nullptr);
|
||||
~TDLibWrapper();
|
||||
|
||||
enum AuthorizationState {
|
||||
|
@ -251,6 +252,7 @@ private:
|
|||
private:
|
||||
void *tdLibClient;
|
||||
AppSettings *appSettings;
|
||||
MceInterface *mceInterface;
|
||||
TDLibReceiver *tdLibReceiver;
|
||||
DBusInterface *dbusInterface;
|
||||
QString version;
|
||||
|
|
Loading…
Reference in a new issue