File indexing completed on 2024-04-28 04:44:14

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 "application.h"
0020 #include "application_p.h"
0021 #include "snore_p.h"
0022 
0023 using namespace Snore;
0024 
0025 Application::Application():
0026     d(nullptr)
0027 {}
0028 
0029 Application::Application(const QString &name, const Icon &icon) :
0030     d(new ApplicationData(name, name, icon))
0031 {
0032 }
0033 
0034 Application::Application(const QString &key, const QString &name, const Icon &icon) :
0035     d(new ApplicationData(key, name, icon))
0036 {
0037 }
0038 
0039 Application::Application(const Application &other):
0040     d(other.d)
0041 {
0042 }
0043 
0044 Application &Application::operator=(const Application &other)
0045 {
0046     d = other.d;
0047     return *this;
0048 }
0049 
0050 Application::~Application()
0051 {
0052 }
0053 
0054 void Application::addAlert(const Alert &alert)
0055 {
0056     Q_ASSERT_X(!SnoreCore::instance().aplications().contains(key()), Q_FUNC_INFO,
0057                "Alerts must be added before the application is Registered.");
0058     d->m_alerts.insert(alert.key(), alert);
0059 }
0060 
0061 QString Application::key() const
0062 {
0063     return d->m_key;
0064 }
0065 
0066 QString Application::name() const
0067 {
0068     return d->m_name;
0069 }
0070 
0071 const Icon &Application::icon()const
0072 {
0073     return d->m_icon;
0074 }
0075 
0076 const QHash<QString, Alert> &Application::alerts() const
0077 {
0078     return d->m_alerts;
0079 }
0080 
0081 const Alert Application::defaultAlert() const
0082 {
0083     return d->m_defaultAlert;
0084 }
0085 
0086 bool Application::isValid() const
0087 {
0088     return d;
0089 }
0090 
0091 Hint &Application::hints()
0092 {
0093     return d->m_hint;
0094 }
0095 
0096 const Hint &Application::constHints() const
0097 {
0098     return  const_cast<Hint &>(const_cast<Application *>(this)->hints());
0099 }
0100 
0101 QDebug operator<< (QDebug debug, const Snore::Application &app)
0102 {
0103     if (app.isValid()) {
0104         debug << "Snore::Application(" << app.name() << ", ";
0105         foreach(const Alert & a, app.alerts()) {
0106             debug << a << ", ";
0107         }
0108         debug << ")" ;
0109     } else {
0110         debug << "Snore::Application(0x00)" ;
0111     }
0112     return debug.maybeSpace();
0113 }