diff options
author | Javier S. Pedro <dev.git@javispedro.com> | 2014-09-27 17:20:54 +0200 |
---|---|---|
committer | Javier S. Pedro <dev.git@javispedro.com> | 2014-09-27 17:20:54 +0200 |
commit | 1cdacce135cad31c2a8d75b95f742c47038211ee (patch) | |
tree | c08a24ab2ae0ded13fceb17672773872cde002f1 /src | |
parent | 51bbe08bbe6093fedc5d265524167bd9fde3682b (diff) | |
download | salmeta-1cdacce135cad31c2a8d75b95f742c47038211ee.tar.gz salmeta-1cdacce135cad31c2a8d75b95f742c47038211ee.zip |
add a few icons for some notifications
Diffstat (limited to 'src')
-rw-r--r-- | src/controller.cpp | 8 | ||||
-rw-r--r-- | src/notificationmonitor.cpp | 49 |
2 files changed, 55 insertions, 2 deletions
diff --git a/src/controller.cpp b/src/controller.cpp index 0a502da..35d6dae 100644 --- a/src/controller.cpp +++ b/src/controller.cpp @@ -239,8 +239,11 @@ void Controller::handleIncomingNotification(const QString &sender, const QIcon & QFont large("MetaWatch Large 16pt"); large.setPixelSize(16); + // Render notification background p.drawImage(0, 0, QImage(SailfishApp::pathTo("qml/watch/notification.png").toLocalFile())); - icon.paint(&p, 0, 96 - 24, 24, 24, Qt::AlignLeft | Qt::AlignBottom); + + // Render the associated icon on the bottom left corner + icon.paint(&p, 0, 96 - 24, 28, 24, Qt::AlignLeft | Qt::AlignBottom); QString title = summary; bool title_drawn_fully = false; @@ -248,6 +251,7 @@ void Controller::handleIncomingNotification(const QString &sender, const QIcon & title = QString("%1 %2").arg(count).arg(summary); } + // Render title area p.setFont(large); if (!title.isEmpty()) { QRect area(2, 2, 96 - 18, 18); @@ -264,6 +268,8 @@ void Controller::handleIncomingNotification(const QString &sender, const QIcon & const int max_y = 96 - 24; int y = 26; + // Now render the contents + // If the title did not fit in the title area, also draw it fully here. p.setFont(small); if (!title_drawn_fully && !title.isEmpty()) { QRect r; diff --git a/src/notificationmonitor.cpp b/src/notificationmonitor.cpp index 2001b25..dfc32f3 100644 --- a/src/notificationmonitor.cpp +++ b/src/notificationmonitor.cpp @@ -2,11 +2,52 @@ #include <QtGui/QIcon> #include <QtDBus/QDBusConnection> #include <QtDBus/QDBusConnectionInterface> + +#include <sailfishapp.h> + #include "notificationmonitor.h" #include "notifications_adaptor.h" static NotificationMonitor *global_monitor = 0; +namespace +{ + +QHash<QString, QString> icons_for_categories; + +QIcon get_builtin_icon(const QString &iconName) +{ + QIcon icon; + + QString filePath = SailfishApp::pathTo("qml/watch/icons/" + iconName + ".png").toLocalFile(); + icon.addFile(filePath); + + return icon; +} + +QIcon icon_for_category(const QString &category) +{ + if (icons_for_categories.isEmpty()) { + icons_for_categories.insert("x-nemo.email", "notification-email"); + icons_for_categories.insert("x-nemo.messaging.im", "notification-sms"); + icons_for_categories.insert("x-nemo.messaging.sms", "notification-sms"); + icons_for_categories.insert("x-nemo.messaging.mms", "notification-sms"); + icons_for_categories.insert("x-nemo.social.twitter.mention", "notification-twitter"); + icons_for_categories.insert("x-nemo.social.twitter.tweet", "notification-twitter"); + icons_for_categories.insert("x-nemo.social.facebook.notification", "notification-facebook"); + icons_for_categories.insert("x-nemo.social.facebook.statuspost", "notification-facebook"); + } + + QString iconName = icons_for_categories.value(category, QString()); + if (!iconName.isEmpty()) { + return get_builtin_icon(iconName); + } else { + return QIcon(); + } +} + +} + NotificationMonitor::NotificationMonitor(QObject *parent) : QObject(parent) { @@ -46,13 +87,19 @@ uint NotificationMonitor::Notify(const QString &app_name, uint replaces_id, cons Q_ASSERT(calledFromDBus()); setDelayedReply(true); + // If the notification mentions a specific icon, then use it. + // But otherwise let's prefer our builtin icons. if (app_icon.startsWith("/")) { icon = QIcon(app_icon); } else if (app_icon.startsWith("file:")) { QUrl url(app_icon); icon = QIcon(url.toLocalFile()); } else { - icon = QIcon::fromTheme(app_icon); + QString category = hints.value("category").toString(); + // Let's hardcode a few categories for now.. + if (!category.isEmpty()) { + icon = icon_for_category(category); + } } int count = hints.value("x-nemo-item-count").toInt(); |