SimpleQmlNotify/notificationdata.cpp

80 lines
1.9 KiB
C++
Raw Permalink Normal View History

2023-04-13 16:21:36 +03:00
/*
2023-12-31 10:03:40 +01:00
* Copyright (C) 2018-2024 QuasarApp.
2023-03-29 12:57:55 +02:00
* Distributed under the GPLv3 software license, see the accompanying
2020-05-23 02:30:51 +03:00
* 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 "notificationdata.h"
namespace QmlNotificationService {
NotificationData::NotificationData(const QString &title,
const QString &text,
2021-01-18 23:20:03 +03:00
const QString &img, int type) {
2019-11-19 15:20:38 +03:00
_text = text;
_title = title;
_img = img;
_type = type;
}
QString NotificationData::text() const {
return _text;
}
QString NotificationData::img() const {
2023-04-13 15:46:01 +03:00
const QString imageSrc = imgSrc();
2023-04-13 16:21:36 +03:00
if(imageSrc.size())
2023-04-13 15:46:01 +03:00
return imageSrc;
2023-04-13 16:21:36 +03:00
return this->getDefaultImage(_type);
2023-04-13 15:46:01 +03:00
}
2023-04-13 16:32:25 +03:00
QString NotificationData::imgSrc() const {
2019-11-19 15:20:38 +03:00
return _img;
}
QString NotificationData::title() const {
return _title;
}
bool NotificationData::operator ==(const NotificationData &righ) {
return _title == righ._title &&
_text == righ._text &&
_img == righ._img &&
_type == righ._type;
}
bool NotificationData::operator !=(const NotificationData &righ) {
return !operator==(righ);
}
2023-04-13 16:32:25 +03:00
QString NotificationData::getDefaultImage(const int code) const {
2023-04-12 11:44:22 +03:00
const auto notificationType = static_cast<NotificationData::Type>(code);
switch (notificationType) {
case NotificationData::Type::Normal:
2023-04-13 15:46:01 +03:00
return "qrc:/icons/info";
2023-04-12 11:44:22 +03:00
case NotificationData::Type::Warning:
2023-04-13 15:46:01 +03:00
return "qrc:/icons/warning";
2023-04-12 11:44:22 +03:00
case NotificationData::Type::Error:
2023-04-13 15:46:01 +03:00
return "qrc:/icons/error";
2023-04-12 11:44:22 +03:00
default:
2023-04-13 15:46:01 +03:00
return "";
2023-04-12 11:44:22 +03:00
}
}
2019-11-19 15:20:38 +03:00
int NotificationData::type() const {
return _type;
}
2019-11-20 17:54:52 +03:00
bool NotificationData::isValid() const {
return _text.size() || _title.size() || _img.size();
}
void NotificationData::setCode(int code) {
_type = code;
}
2019-11-19 15:20:38 +03:00
}