diff --git a/src/libsnore/alert.cpp b/src/libsnore/alert.cpp index 4fc71f3..816c520 100644 --- a/src/libsnore/alert.cpp +++ b/src/libsnore/alert.cpp @@ -28,9 +28,15 @@ Alert::Alert() : {} Alert::Alert(const QString &name, const Icon &icon): - d(new AlertData(name, icon)) + d(new AlertData(name, name, icon)) {} +Alert::Alert(const QString &key, const QString &name, const Icon &icon): + d(new AlertData(key,name,icon)) +{ + +} + Alert::Alert(const Alert &other): d(other.d) { @@ -48,6 +54,11 @@ Alert::~Alert() } +QString Alert::key() const +{ + return d->m_key; +} + QString Alert::name() const { return d->m_name; diff --git a/src/libsnore/alert.h b/src/libsnore/alert.h index f017306..ad0f5e8 100644 --- a/src/libsnore/alert.h +++ b/src/libsnore/alert.h @@ -40,13 +40,23 @@ class SNORE_EXPORT Alert { public: Alert(); - /** - * Creates an alert - * @param name the name of the Alert - * @param icon the Icon of the Alert - */ + /** + * Creates an alert. + * @param name the name of the Alert. + * @param icon the Icon of the Alert. + */ explicit Alert(const QString &name, const Icon &icon); + + + /** + * Creates an alert. + * @param name the key of the Alert used in Application::alerts(). + * @param name the name of the Alert. + * @param icon the Icon of the Alert. + */ + explicit Alert(const QString &key, const QString &name, const Icon &icon); + /** * Creates a copy of other * @param other @@ -54,29 +64,34 @@ public: Alert(const Alert &other); /** - * Creates a copy of other + * Creates a copy of other. * @param other */ Alert &operator=(const Alert &other); ~Alert(); + /** - * - * @return the name + * Returns the key of the Alert, used in Application::alerts(). + * Might be identically to name(). + */ + QString key() const; + + /** + * Returns the name of the Alert. */ QString name() const; /** - * - * @return the icon + * Returns the icon of the Alert. */ const Icon &icon() const; /** - * - * @return whether the Alert is valid. + * Returns whether the Alert is valid. */ bool isValid() const; + private: QExplicitlySharedDataPointer d; diff --git a/src/libsnore/alert_p.cpp b/src/libsnore/alert_p.cpp index ed6367d..bc934f6 100644 --- a/src/libsnore/alert_p.cpp +++ b/src/libsnore/alert_p.cpp @@ -20,7 +20,8 @@ using namespace Snore; -AlertData::AlertData(const QString &name, const Icon &icon): +AlertData::AlertData(const QString &key, const QString &name, const Icon &icon): + m_key(key), m_name(name), m_icon(icon) { diff --git a/src/libsnore/alert_p.h b/src/libsnore/alert_p.h index cdd7d3a..31ccb20 100644 --- a/src/libsnore/alert_p.h +++ b/src/libsnore/alert_p.h @@ -31,9 +31,10 @@ class AlertData : public QSharedData { friend class Alert; public: - AlertData(const QString &name, const Icon &icon); + AlertData(const QString &key, const QString &name, const Icon &icon); ~AlertData(); + QString m_key; QString m_name; Icon m_icon; diff --git a/src/libsnore/application.cpp b/src/libsnore/application.cpp index e18e96c..7390752 100644 --- a/src/libsnore/application.cpp +++ b/src/libsnore/application.cpp @@ -27,15 +27,19 @@ Application::Application(): {} Application::Application(const QString &name, const Icon &icon) : - d(new ApplicationData(name, icon)) + d(new ApplicationData(name, name, icon)) { } +Application::Application(const QString key, const QString &name, const Icon &icon) : + d(new ApplicationData(key,name,icon)) +{ +} + Application::Application(const Application &other): d(other.d) { - } Application &Application::operator=(const Application &other) @@ -50,9 +54,14 @@ Application::~Application() void Application::addAlert(const Alert &alert) { - Q_ASSERT_X(!SnoreCore::instance().aplications().contains(name()), Q_FUNC_INFO, + Q_ASSERT_X(!SnoreCore::instance().aplications().contains(key()), Q_FUNC_INFO, "Alerts must be added before the application is Registered." ); - d->m_alerts.insert(alert.name(), alert); + d->m_alerts.insert(alert.key(), alert); +} + +QString Application::key() const +{ + return d->m_key; } QString Application::name() const diff --git a/src/libsnore/application.h b/src/libsnore/application.h index f94fe7d..01588c7 100644 --- a/src/libsnore/application.h +++ b/src/libsnore/application.h @@ -42,13 +42,23 @@ public: Application(); /** - * Creates a new Application object - * @param name - * @param icon + * Creates a new Application object. + * @param name the name of the Application. Used in Snore::applications(). + * @param icon the icon of the Application. * @see SnoreCore::registerApplication */ explicit Application(const QString &name, const Icon &icon); + /** + * Creates a new Application object. + * @param key the key of the application. Used in Snore::applications(). + * @param name the name of the Application. + * @param icon the icon of the Application. + * @see SnoreCore::registerApplication + */ + explicit Application(const QString key, const QString &name, const Icon &icon); + + /** * The copy constructor * @param other @@ -71,32 +81,33 @@ public: void addAlert(const Alert &alert); /** - * - * @return the name of the Application + * Returns the key of the Application. + * Might be the same as name(). + */ + QString key() const; + + /** + * Returns the name of the Application. */ QString name() const; /** - * - * @return the default icon for Notifications ans Alerts of this Application. + * Returns the icon of this Application. */ const Icon &icon() const; /** - * - * @return a QHash with the Alers registered with this Application. + * Returns a map with the Alers registered with this Application. */ const QHash &alerts() const; /** - * - * @return the default alert for notifications. + * Returns the default alert for notifications. */ const Alert defaultAlert() const; /** - * - * @return whether the Application is valid. + * Returns whether the Application is valid. */ bool isValid() const; diff --git a/src/libsnore/application_p.cpp b/src/libsnore/application_p.cpp index f046b6b..2940d5b 100644 --- a/src/libsnore/application_p.cpp +++ b/src/libsnore/application_p.cpp @@ -23,13 +23,14 @@ using namespace Snore; -ApplicationData::ApplicationData(const QString &name, const Icon &icon): +ApplicationData::ApplicationData(const QString &key, const QString &name, const Icon &icon): + m_key(key), m_name(name), m_icon(icon), m_defaultAlert(qApp->translate("Default Alert", "Default"), icon) { Q_ASSERT_X(!name.isEmpty(), Q_FUNC_INFO, "invalid name detected"); - m_alerts.insert(m_defaultAlert.name(), m_defaultAlert); + m_alerts.insert(m_defaultAlert.key(), m_defaultAlert); m_hint.setValue("pushover-token", QLatin1String("aFB1TPCyZkkr7mubCGEKy5vJEWak9t")); m_hint.setValue("use-markup", false); diff --git a/src/libsnore/application_p.h b/src/libsnore/application_p.h index 9c3f2fa..c73c67c 100644 --- a/src/libsnore/application_p.h +++ b/src/libsnore/application_p.h @@ -29,9 +29,10 @@ namespace Snore class ApplicationData : public QSharedData { public: - ApplicationData(const QString &name, const Icon &icon); + ApplicationData(const QString &key, const QString &name, const Icon &icon); ~ApplicationData(); + QString m_key; QString m_name; Icon m_icon; QHash m_alerts; diff --git a/src/libsnore/snore.cpp b/src/libsnore/snore.cpp index 903bdbf..c21112f 100644 --- a/src/libsnore/snore.cpp +++ b/src/libsnore/snore.cpp @@ -127,10 +127,10 @@ void SnoreCore::broadcastNotification(Notification notification) void SnoreCore::registerApplication(const Application &application) { Q_D(SnoreCore); - Q_ASSERT_X(!d->m_applications.contains(application.name()), Q_FUNC_INFO, + Q_ASSERT_X(!d->m_applications.contains(application.key()), Q_FUNC_INFO, "Applications mus be registered only once."); snoreDebug(SNORE_DEBUG) << "Registering Application:" << application; - d->m_applications.insert(application.name(), application); + d->m_applications.insert(application.key(), application); emit d->applicationRegistered(application); } @@ -138,7 +138,7 @@ void SnoreCore::deregisterApplication(const Application &application) { Q_D(SnoreCore); emit d->applicationDeregistered(application); - d->m_applications.take(application.name()); + d->m_applications.take(application.key()); } const QHash &SnoreCore::aplications() const diff --git a/src/libsnore/snore_p.cpp b/src/libsnore/snore_p.cpp index d3c0463..b7f9efb 100644 --- a/src/libsnore/snore_p.cpp +++ b/src/libsnore/snore_p.cpp @@ -55,7 +55,7 @@ SnoreCorePrivate::~SnoreCorePrivate() Application SnoreCorePrivate::defaultApplication() { - if (!SnoreCore::instance().aplications().contains(m_defaultApp.name())) { + if (!SnoreCore::instance().aplications().contains(m_defaultApp.key())) { SnoreCore::instance().registerApplication(m_defaultApp); } return m_defaultApp;