summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2010-10-05 15:14:08 (GMT)
committerRemko Tronçon <git@el-tramo.be>2010-10-05 15:24:54 (GMT)
commit6cdd48b30526761f5c6365496e30580ed3bd8a82 (patch)
tree790a96ee6a70054165264171a31ead5e8e598baf /Swift/QtUI/FreeDesktopNotifier.cpp
parentcd3017c8730ce66539d539890d72434cf644ab80 (diff)
downloadswift-6cdd48b30526761f5c6365496e30580ed3bd8a82.zip
swift-6cdd48b30526761f5c6365496e30580ed3bd8a82.tar.bz2
Added FreeDesktopNotifier.
Diffstat (limited to 'Swift/QtUI/FreeDesktopNotifier.cpp')
-rw-r--r--Swift/QtUI/FreeDesktopNotifier.cpp52
1 files changed, 52 insertions, 0 deletions
diff --git a/Swift/QtUI/FreeDesktopNotifier.cpp b/Swift/QtUI/FreeDesktopNotifier.cpp
new file mode 100644
index 0000000..2560882
--- /dev/null
+++ b/Swift/QtUI/FreeDesktopNotifier.cpp
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2010 Remko Tronçon
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+
+//#pragma GCC diagnostic ignored "-Wredundant-decls"
+
+#include "Swift/QtUI/FreeDesktopNotifier.h"
+
+#include <QMap>
+#include <QString>
+#include <QStringList>
+#include <QtDBus/QtDBus>
+#include <algorithm>
+
+#include "QtSwiftUtil.h"
+
+namespace Swift {
+
+FreeDesktopNotifier::FreeDesktopNotifier(const String& name) : applicationName(name) {
+}
+
+void FreeDesktopNotifier::doShowMessage(Type type, const String& subject, const String& description, const boost::filesystem::path& picture, boost::function<void()>) {
+ QDBusConnection bus = QDBusConnection::sessionBus();
+ if (!bus.isConnected()) {
+ return;
+ }
+ std::vector<Notifier::Type> defaultTypes = getDefaultTypes();
+ if (std::find(defaultTypes.begin(), defaultTypes.end(), type) == defaultTypes.end()) {
+ return;
+ }
+
+ int timeout = (type == IncomingMessage || type == SystemMessage) ? DEFAULT_MESSAGE_NOTIFICATION_TIMEOUT_SECONDS : DEFAULT_STATUS_NOTIFICATION_TIMEOUT_SECONDS;
+
+ QDBusMessage msg = QDBusMessage::createMethodCall("org.freedesktop.Notifications", "/org/freedesktop/Notifications", "", "Notify");
+
+ QStringList actions;
+ QMap<QString, QVariant> hints;
+ msg << P2QSTRING(applicationName);
+ msg << quint32(0); // ID of previous notification to replace
+ msg << picture.string().c_str(); // Icon to display
+ msg << P2QSTRING(subject); // Summary / Header of the message to display
+ msg << P2QSTRING(description); // Body of the message to display
+ msg << actions; // Actions from which the user may choose
+ msg << hints; // Hints to the server displaying the message
+ msg << qint32(timeout*1000); // Timeout in milliseconds
+
+ bus.call(msg);
+}
+
+}