Introduce key to Alert and Action.
As the name of them might be a translated string, the lookup of these using the name might be problematic. Key is either identical to name or a fixed untranslated string.
This commit is contained in:
parent
892d170791
commit
5cb65c3625
|
@ -28,9 +28,15 @@ Alert::Alert() :
|
||||||
{}
|
{}
|
||||||
|
|
||||||
Alert::Alert(const QString &name, const Icon &icon):
|
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):
|
Alert::Alert(const Alert &other):
|
||||||
d(other.d)
|
d(other.d)
|
||||||
{
|
{
|
||||||
|
@ -48,6 +54,11 @@ Alert::~Alert()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString Alert::key() const
|
||||||
|
{
|
||||||
|
return d->m_key;
|
||||||
|
}
|
||||||
|
|
||||||
QString Alert::name() const
|
QString Alert::name() const
|
||||||
{
|
{
|
||||||
return d->m_name;
|
return d->m_name;
|
||||||
|
|
|
@ -40,13 +40,23 @@ class SNORE_EXPORT Alert
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Alert();
|
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);
|
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
|
* Creates a copy of other
|
||||||
* @param other
|
* @param other
|
||||||
|
@ -54,29 +64,34 @@ public:
|
||||||
Alert(const Alert &other);
|
Alert(const Alert &other);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a copy of other
|
* Creates a copy of other.
|
||||||
* @param other
|
* @param other
|
||||||
*/
|
*/
|
||||||
Alert &operator=(const Alert &other);
|
Alert &operator=(const Alert &other);
|
||||||
~Alert();
|
~Alert();
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Returns the key of the Alert, used in Application::alerts().
|
||||||
* @return the name
|
* Might be identically to name().
|
||||||
|
*/
|
||||||
|
QString key() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the name of the Alert.
|
||||||
*/
|
*/
|
||||||
QString name() const;
|
QString name() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Returns the icon of the Alert.
|
||||||
* @return the icon
|
|
||||||
*/
|
*/
|
||||||
const Icon &icon() const;
|
const Icon &icon() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Returns whether the Alert is valid.
|
||||||
* @return whether the Alert is valid.
|
|
||||||
*/
|
*/
|
||||||
bool isValid() const;
|
bool isValid() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QExplicitlySharedDataPointer<AlertData> d;
|
QExplicitlySharedDataPointer<AlertData> d;
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,8 @@
|
||||||
|
|
||||||
using namespace Snore;
|
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_name(name),
|
||||||
m_icon(icon)
|
m_icon(icon)
|
||||||
{
|
{
|
||||||
|
|
|
@ -31,9 +31,10 @@ class AlertData : public QSharedData
|
||||||
{
|
{
|
||||||
friend class Alert;
|
friend class Alert;
|
||||||
public:
|
public:
|
||||||
AlertData(const QString &name, const Icon &icon);
|
AlertData(const QString &key, const QString &name, const Icon &icon);
|
||||||
~AlertData();
|
~AlertData();
|
||||||
|
|
||||||
|
QString m_key;
|
||||||
QString m_name;
|
QString m_name;
|
||||||
Icon m_icon;
|
Icon m_icon;
|
||||||
|
|
||||||
|
|
|
@ -27,15 +27,19 @@ Application::Application():
|
||||||
{}
|
{}
|
||||||
|
|
||||||
Application::Application(const QString &name, const Icon &icon) :
|
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):
|
Application::Application(const Application &other):
|
||||||
d(other.d)
|
d(other.d)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Application &Application::operator=(const Application &other)
|
Application &Application::operator=(const Application &other)
|
||||||
|
@ -50,9 +54,14 @@ Application::~Application()
|
||||||
|
|
||||||
void Application::addAlert(const Alert &alert)
|
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." );
|
"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
|
QString Application::name() const
|
||||||
|
|
|
@ -42,13 +42,23 @@ public:
|
||||||
Application();
|
Application();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new Application object
|
* Creates a new Application object.
|
||||||
* @param name
|
* @param name the name of the Application. Used in Snore::applications().
|
||||||
* @param icon
|
* @param icon the icon of the Application.
|
||||||
* @see SnoreCore::registerApplication
|
* @see SnoreCore::registerApplication
|
||||||
*/
|
*/
|
||||||
explicit Application(const QString &name, const Icon &icon);
|
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
|
* The copy constructor
|
||||||
* @param other
|
* @param other
|
||||||
|
@ -71,32 +81,33 @@ public:
|
||||||
void addAlert(const Alert &alert);
|
void addAlert(const Alert &alert);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Returns the key of the Application.
|
||||||
* @return the name of the Application
|
* Might be the same as name().
|
||||||
|
*/
|
||||||
|
QString key() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the name of the Application.
|
||||||
*/
|
*/
|
||||||
QString name() const;
|
QString name() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Returns the icon of this Application.
|
||||||
* @return the default icon for Notifications ans Alerts of this Application.
|
|
||||||
*/
|
*/
|
||||||
const Icon &icon() const;
|
const Icon &icon() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Returns a map with the Alers registered with this Application.
|
||||||
* @return a QHash with the Alers registered with this Application.
|
|
||||||
*/
|
*/
|
||||||
const QHash<QString, Alert> &alerts() const;
|
const QHash<QString, Alert> &alerts() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Returns the default alert for notifications.
|
||||||
* @return the default alert for notifications.
|
|
||||||
*/
|
*/
|
||||||
const Alert defaultAlert() const;
|
const Alert defaultAlert() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Returns whether the Application is valid.
|
||||||
* @return whether the Application is valid.
|
|
||||||
*/
|
*/
|
||||||
bool isValid() const;
|
bool isValid() const;
|
||||||
|
|
||||||
|
|
|
@ -23,13 +23,14 @@
|
||||||
|
|
||||||
using namespace Snore;
|
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_name(name),
|
||||||
m_icon(icon),
|
m_icon(icon),
|
||||||
m_defaultAlert(qApp->translate("Default Alert", "Default"), icon)
|
m_defaultAlert(qApp->translate("Default Alert", "Default"), icon)
|
||||||
{
|
{
|
||||||
Q_ASSERT_X(!name.isEmpty(), Q_FUNC_INFO, "invalid name detected");
|
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("pushover-token", QLatin1String("aFB1TPCyZkkr7mubCGEKy5vJEWak9t"));
|
||||||
m_hint.setValue("use-markup", false);
|
m_hint.setValue("use-markup", false);
|
||||||
|
|
|
@ -29,9 +29,10 @@ namespace Snore
|
||||||
class ApplicationData : public QSharedData
|
class ApplicationData : public QSharedData
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ApplicationData(const QString &name, const Icon &icon);
|
ApplicationData(const QString &key, const QString &name, const Icon &icon);
|
||||||
~ApplicationData();
|
~ApplicationData();
|
||||||
|
|
||||||
|
QString m_key;
|
||||||
QString m_name;
|
QString m_name;
|
||||||
Icon m_icon;
|
Icon m_icon;
|
||||||
QHash<QString, Alert> m_alerts;
|
QHash<QString, Alert> m_alerts;
|
||||||
|
|
|
@ -127,10 +127,10 @@ void SnoreCore::broadcastNotification(Notification notification)
|
||||||
void SnoreCore::registerApplication(const Application &application)
|
void SnoreCore::registerApplication(const Application &application)
|
||||||
{
|
{
|
||||||
Q_D(SnoreCore);
|
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.");
|
"Applications mus be registered only once.");
|
||||||
snoreDebug(SNORE_DEBUG) << "Registering Application:" << application;
|
snoreDebug(SNORE_DEBUG) << "Registering Application:" << application;
|
||||||
d->m_applications.insert(application.name(), application);
|
d->m_applications.insert(application.key(), application);
|
||||||
emit d->applicationRegistered(application);
|
emit d->applicationRegistered(application);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -138,7 +138,7 @@ void SnoreCore::deregisterApplication(const Application &application)
|
||||||
{
|
{
|
||||||
Q_D(SnoreCore);
|
Q_D(SnoreCore);
|
||||||
emit d->applicationDeregistered(application);
|
emit d->applicationDeregistered(application);
|
||||||
d->m_applications.take(application.name());
|
d->m_applications.take(application.key());
|
||||||
}
|
}
|
||||||
|
|
||||||
const QHash<QString, Application> &SnoreCore::aplications() const
|
const QHash<QString, Application> &SnoreCore::aplications() const
|
||||||
|
|
|
@ -55,7 +55,7 @@ SnoreCorePrivate::~SnoreCorePrivate()
|
||||||
|
|
||||||
Application SnoreCorePrivate::defaultApplication()
|
Application SnoreCorePrivate::defaultApplication()
|
||||||
{
|
{
|
||||||
if (!SnoreCore::instance().aplications().contains(m_defaultApp.name())) {
|
if (!SnoreCore::instance().aplications().contains(m_defaultApp.key())) {
|
||||||
SnoreCore::instance().registerApplication(m_defaultApp);
|
SnoreCore::instance().registerApplication(m_defaultApp);
|
||||||
}
|
}
|
||||||
return m_defaultApp;
|
return m_defaultApp;
|
||||||
|
|
Loading…
Reference in New Issue