diff options
author | Remko Tronçon <git@el-tramo.be> | 2011-04-10 09:34:01 (GMT) |
---|---|---|
committer | Remko Tronçon <git@el-tramo.be> | 2011-04-18 19:11:41 (GMT) |
commit | ec3caf1179834f03c787f46cf44820885edbf4da (patch) | |
tree | 859b3d866bd2fac84e0a264756c7ec1d9dd0a678 /Swift | |
parent | fdfe10dc9dde522e82d381e4641eb98063c4b47f (diff) | |
download | swift-contrib-ec3caf1179834f03c787f46cf44820885edbf4da.zip swift-contrib-ec3caf1179834f03c787f46cf44820885edbf4da.tar.bz2 |
Implemented DBUS URI handler.
Diffstat (limited to 'Swift')
-rw-r--r-- | Swift/QtUI/.gitignore | 1 | ||||
-rw-r--r-- | Swift/QtUI/QtDBUSURIHandler.cpp | 41 | ||||
-rw-r--r-- | Swift/QtUI/QtDBUSURIHandler.h | 17 | ||||
-rw-r--r-- | Swift/QtUI/QtSwift.cpp | 8 | ||||
-rw-r--r-- | Swift/QtUI/QtURIHandler.h | 6 | ||||
-rw-r--r-- | Swift/QtUI/SConscript | 8 | ||||
-rw-r--r-- | Swift/QtUI/swift-open-uri.cpp | 30 |
7 files changed, 102 insertions, 9 deletions
diff --git a/Swift/QtUI/.gitignore b/Swift/QtUI/.gitignore index f539e86..53acb9f 100644 --- a/Swift/QtUI/.gitignore +++ b/Swift/QtUI/.gitignore @@ -1,3 +1,4 @@ Swift BuildVersion.h *.dmg +swift-open-uri diff --git a/Swift/QtUI/QtDBUSURIHandler.cpp b/Swift/QtUI/QtDBUSURIHandler.cpp new file mode 100644 index 0000000..9b69ca6 --- /dev/null +++ b/Swift/QtUI/QtDBUSURIHandler.cpp @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2011 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#include "QtDBUSURIHandler.h" + +#include <QDBusAbstractAdaptor> +#include <QDBusConnection> + +#include "QtSwiftUtil.h" + +using namespace Swift; + +namespace { + class DBUSAdaptor: public QDBusAbstractAdaptor { + Q_OBJECT + Q_CLASSINFO("D-Bus Interface", "im.swift.Swift.URIHandler"); + public: + DBUSAdaptor(QtDBUSURIHandler* uriHandler) : QDBusAbstractAdaptor(uriHandler), uriHandler(uriHandler) { + } + + public slots: + void openURI(const QString& uri) { + uriHandler->onURI(Q2PSTRING(uri)); + } + + private: + QtDBUSURIHandler* uriHandler; + }; +} + +QtDBUSURIHandler::QtDBUSURIHandler() { + new DBUSAdaptor(this); + QDBusConnection connection = QDBusConnection::sessionBus(); + connection.registerService("im.swift.Swift.URIHandler"); + connection.registerObject("/", this); +} + +#include "QtDBUSURIHandler.moc" diff --git a/Swift/QtUI/QtDBUSURIHandler.h b/Swift/QtUI/QtDBUSURIHandler.h new file mode 100644 index 0000000..be1872e --- /dev/null +++ b/Swift/QtUI/QtDBUSURIHandler.h @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2011 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include <QObject> +#include <SwifTools/URIHandler/URIHandler.h> + +namespace Swift { + class QtDBUSURIHandler : public QObject, public URIHandler { + public: + QtDBUSURIHandler(); + }; +} diff --git a/Swift/QtUI/QtSwift.cpp b/Swift/QtUI/QtSwift.cpp index d977637..326cea1 100644 --- a/Swift/QtUI/QtSwift.cpp +++ b/Swift/QtUI/QtSwift.cpp @@ -51,8 +51,10 @@ #if defined(SWIFTEN_PLATFORM_MACOSX) #include "QtURIHandler.h" -#else +#elif defined(SWIFTEN_PLATFORM_WIN32) #include <SwifTools/URIHandler/NullURIHandler.h> +#else +#include "QtDBUSURIHandler.h" #endif namespace Swift{ @@ -133,8 +135,10 @@ QtSwift::QtSwift(const po::variables_map& options) : networkFactories_(&clientMa #if defined(SWIFTEN_PLATFORM_MACOSX) uriHandler_ = new QtURIHandler(); -#else +#elif defined(SWIFTEN_PLATFORM_WIN32) uriHandler_ = new NullURIHandler(); +#else + uriHandler_ = new QtDBUSURIHandler(); #endif if (splitter_) { diff --git a/Swift/QtUI/QtURIHandler.h b/Swift/QtUI/QtURIHandler.h index a4b56f8..a02114a 100644 --- a/Swift/QtUI/QtURIHandler.h +++ b/Swift/QtUI/QtURIHandler.h @@ -16,12 +16,6 @@ namespace Swift { public: QtURIHandler(); - virtual void start() { - } - - virtual void stop() { - } - private: bool eventFilter(QObject* obj, QEvent* event); }; diff --git a/Swift/QtUI/SConscript b/Swift/QtUI/SConscript index e2775a6..d2dd37c 100644 --- a/Swift/QtUI/SConscript +++ b/Swift/QtUI/SConscript @@ -65,6 +65,7 @@ sources = [ "main.cpp", "QtAboutWidget.cpp", "QtAvatarWidget.cpp", + "QtDBUSURIHandler.cpp", "QtUIFactory.cpp", "QtChatWindowFactory.cpp", "QtChatWindow.cpp", @@ -151,6 +152,11 @@ if env["PLATFORM"] == "darwin" or env["PLATFORM"] == "win32" : else : swiftProgram = myenv.Program("swift", sources) +if env["PLATFORM"] != "darwin" and env["PLATFORM"] != "win32" : + openURIProgram = myenv.Program("swift-open-uri", "swift-open-uri.cpp") +else : + openURIProgram = [] + myenv.Uic4("MUCSearch/QtMUCSearchWindow.ui") myenv.Uic4("UserSearch/QtUserSearchWizard.ui") myenv.Uic4("UserSearch/QtUserSearchFirstPage.ui") @@ -221,7 +227,7 @@ if env["PLATFORM"] == "darwin" : myenv.Command(["Swift-${SWIFT_VERSION}.dmg"], [app], ["Swift/Packaging/MacOSX/package.sh " + app.path + " Swift/Packaging/MacOSX/Swift.dmg.gz $TARGET $QTDIR"]) if env.get("SWIFT_INSTALLDIR", "") : - env.Install(os.path.join(env["SWIFT_INSTALLDIR"], "bin"), swiftProgram) + env.Install(os.path.join(env["SWIFT_INSTALLDIR"], "bin"), swiftProgram + openURIProgram) env.InstallAs(os.path.join(env["SWIFT_INSTALLDIR"], "share", "pixmaps", "swift.xpm"), "../resources/logo/logo-icon-32.xpm") icons_path = os.path.join(env["SWIFT_INSTALLDIR"], "share", "icons", "hicolor") env.InstallAs(os.path.join(icons_path, "32x32", "apps", "swift.xpm"), "../resources/logo/logo-icon-32.xpm") diff --git a/Swift/QtUI/swift-open-uri.cpp b/Swift/QtUI/swift-open-uri.cpp new file mode 100644 index 0000000..2d5ef19 --- /dev/null +++ b/Swift/QtUI/swift-open-uri.cpp @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2011 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#include <QCoreApplication> +#include <QDBusConnection> +#include <QDBusMessage> +#include <iostream> + +int main(int argc, char* argv[]) { + QCoreApplication app(argc, argv); + + QDBusConnection bus = QDBusConnection::sessionBus(); + if (!bus.isConnected()) { + return -1; + } + if (argc != 2) { + std::cerr << "Usage: " << argv[0] << " uri" << std::endl; + return -1; + } + + QDBusMessage msg = QDBusMessage::createMethodCall("im.swift.Swift.URIHandler", "/", "im.swift.Swift.URIHandler", "openURI"); + msg << argv[1]; + + bus.call(msg); + + return 0; +} |