SimpleQmlNotify/notificationservice.cpp

70 lines
1.9 KiB
C++
Raw Normal View History

2020-05-23 02:30:51 +03:00
/*
2021-01-31 19:57:49 +03:00
* Copyright (C) 2018-2021 QuasarApp.
2020-05-23 02:30:51 +03:00
* Distributed under the lgplv3 software license, see the accompanying
* Everyone is permitted to copy and distribute verbatim copies
* of this license document, but changing it is not allowed.
*/
2019-11-19 15:20:38 +03:00
#include "notificationservice.h"
namespace QmlNotificationService {
NotificationService::NotificationService(QObject * ptr): QObject (ptr) {
qRegisterMetaType<NotificationData>("NotificationData");
qRegisterMetaType<QList<NotificationData>> ("QList<NotificationData>");
}
NotificationData NotificationService::notify() const {
return _notify;
}
2021-01-18 23:20:03 +03:00
NotificationData NotificationService::question() const {
return _question;
}
2019-11-19 15:20:38 +03:00
void NotificationService::setNotify(const NotificationData& notify) {
if (_notify != notify)
_history.push_back(_notify);
_notify = notify;
emit notifyChanged();
}
int NotificationService::setQuestion(const NotificationData &question) {
2021-01-18 23:20:03 +03:00
_question = question;
_question.setCode(rand() % std::numeric_limits<int>().max());
2021-01-18 23:20:03 +03:00
emit questionChanged();
return _question.type();
2021-01-18 23:20:03 +03:00
}
void NotificationService::questionComplete(bool accepted, int code) {
emit questionCompleted(accepted, code);
}
2019-11-19 15:20:38 +03:00
void NotificationService::setNotify(const QString &title,
const QString &text,
const QString &img,
int type) {
setNotify(NotificationData(title, text, img,
static_cast<NotificationData::Type>(type)));
}
2021-05-04 18:40:09 +03:00
int NotificationService::setQuestion(const QString &title, const QString &text, const QString &img, int code) {
return setQuestion(NotificationData(title, text, img, code));
2021-01-18 23:20:03 +03:00
}
2019-11-19 15:20:38 +03:00
NotificationService *NotificationService::getService() {
static auto service = new NotificationService;
return service;
}
const QList<NotificationData> &NotificationService::history() const {
return _history;
}
}