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:
Patrick von Reth 2015-07-09 11:52:41 +02:00
parent 892d170791
commit 5cb65c3625
10 changed files with 89 additions and 39 deletions

View File

@ -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;

View File

@ -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<AlertData> d;

View File

@ -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)
{

View File

@ -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;

View File

@ -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

View File

@ -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<QString, Alert> &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;

View File

@ -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);

View File

@ -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<QString, Alert> m_alerts;

View File

@ -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<QString, Application> &SnoreCore::aplications() const

View File

@ -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;