File indexing completed on 2024-05-05 04:45:34
0001 /* 0002 SnoreNotify is a Notification Framework based on Qt 0003 Copyright (C) 2013-2015 Hannah von Reth <vonreth@kde.org> 0004 0005 SnoreNotify is free software: you can redistribute it and/or modify 0006 it under the terms of the GNU Lesser General Public License as published by 0007 the Free Software Foundation, either version 3 of the License, or 0008 (at your option) any later version. 0009 0010 SnoreNotify is distributed in the hope that it will be useful, 0011 but WITHOUT ANY WARRANTY; without even the implied warranty of 0012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0013 GNU Lesser General Public License for more details. 0014 0015 You should have received a copy of the GNU Lesser General Public License 0016 along with SnoreNotify. If not, see <http://www.gnu.org/licenses/>. 0017 */ 0018 0019 #include "notification/notification_p.h" 0020 #include "notification/icon.h" 0021 #include "../hint.h" 0022 #include "libsnore/plugins/plugins.h" 0023 #include "libsnore/snore.h" 0024 0025 #include <QSharedData> 0026 0027 using namespace Snore; 0028 0029 uint NotificationData::notificationCount = 0; 0030 0031 uint NotificationData::m_idCount = 1; 0032 0033 NotificationData::NotificationData(const Snore::Application &application, const Snore::Alert &alert, const QString &title, const QString &text, const Icon &icon, 0034 int timeout, Notification::Prioritys priority): 0035 m_id(m_idCount++), 0036 m_timeout(priority == Notification::Emergency ? 0 : timeout), 0037 m_application(application), 0038 m_alert(alert), 0039 m_title(title), 0040 m_text(text), 0041 m_icon(icon), 0042 m_priority(priority), 0043 m_hints(m_application.constHints()) 0044 { 0045 notificationCount++; 0046 qCDebug(SNORE) << "Creating Notification: ActiveNotifications" << notificationCount << "id" << m_id; 0047 qCDebug(SNORE) << title << text; 0048 } 0049 0050 Snore::NotificationData::NotificationData(const Notification &old, const QString &title, const QString &text, const Icon &icon, int timeout, Notification::Prioritys priority): 0051 m_id(m_idCount++), 0052 m_timeout(priority == Notification::Emergency ? 0 : timeout), 0053 m_application(old.application()), 0054 m_alert(old.alert()), 0055 m_title(title), 0056 m_text(text), 0057 m_icon(icon), 0058 m_priority(priority), 0059 m_hints(m_application.constHints()), 0060 m_toReplace(old) 0061 { 0062 notificationCount++; 0063 qCDebug(SNORE) << "Creating Notification: ActiveNotifications" << notificationCount << "id" << m_id; 0064 qCDebug(SNORE) << title << text; 0065 } 0066 0067 NotificationData::~NotificationData() 0068 { 0069 stopTimeoutTimer(); 0070 notificationCount--; 0071 qCDebug(SNORE) << "Deleting Notification: ActiveNotifications" << notificationCount << "id" << m_id << "Close Reason:" << m_closeReason; 0072 } 0073 0074 void NotificationData::setActionInvoked(const Snore::Action &action) 0075 { 0076 m_actionInvoked = action; 0077 } 0078 0079 void NotificationData::setCloseReason(Snore::Notification::CloseReasons r) 0080 { 0081 m_closeReason = r; 0082 stopTimeoutTimer(); 0083 } 0084 0085 QString NotificationData::resolveMarkup(const QString &string, Utils::MarkupFlags flags) 0086 { 0087 if (!m_hints.value("use-markup").toBool()) { 0088 if (flags == Utils::NoMarkup) { 0089 return string; 0090 } else { 0091 return Utils::normalizeMarkup(string.toHtmlEscaped(), flags); 0092 } 0093 } else { 0094 return Utils::normalizeMarkup(string, flags); 0095 } 0096 } 0097 0098 void NotificationData::setBroadcasted() 0099 { 0100 m_isBroadcasted = true; 0101 } 0102 0103 bool NotificationData::isBroadcasted() const 0104 { 0105 return m_isBroadcasted; 0106 } 0107 0108 void NotificationData::setSource(SnorePlugin *soure) 0109 { 0110 m_source = soure; 0111 } 0112 0113 const SnorePlugin *NotificationData::source() const 0114 { 0115 return m_source; 0116 } 0117 0118 bool NotificationData::sourceAndTargetAreSimilar(const SnorePlugin *target) 0119 { 0120 if (source() && source()->name() == target->name()) { 0121 qCDebug(SNORE) << "Source" << source() << "and Target" << target << "are the same."; 0122 return true; 0123 } 0124 return false; 0125 } 0126 0127 void NotificationData::stopTimeoutTimer() 0128 { 0129 if (m_timeoutTimer) { 0130 m_timeoutTimer->deleteLater(); 0131 m_timeoutTimer = nullptr; 0132 } 0133 } 0134