From bc966cb0f5cd7ee9decec92290c772ff33d97474 Mon Sep 17 00:00:00 2001 From: Pino Toscano Date: Sun, 21 Sep 2008 22:52:02 +0000 Subject: [PATCH] Add the --unique command line behaviour ala KDVI. The "unique" instance is registered as "org.kde.okular". BUG: 170151 svn path=/trunk/KDE/kdegraphics/okular/; revision=863380 --- shell/main.cpp | 23 +++++++++++++++++++++++ shell/shell.cpp | 6 ++++++ 2 files changed, 29 insertions(+) diff --git a/shell/main.cpp b/shell/main.cpp index c4cabe9bb..635827d9e 100644 --- a/shell/main.cpp +++ b/shell/main.cpp @@ -16,8 +16,23 @@ #include #include #include +#include #include "aboutdata.h" +static bool attachUniqueInstance(KCmdLineArgs* args) +{ + if (!args->isSet("unique") || args->count() != 1) + return false; + + QDBusInterface iface("org.kde.okular", "/okular", "org.kde.okular"); + if (!iface.isValid()) + return false; + + iface.call("openDocument", args->url(0).pathOrUrl()); + + return true; +} + int main(int argc, char** argv) { KAboutData about = okularAboutData( "okular", I18N_NOOP( "Okular" ) ); @@ -28,6 +43,7 @@ int main(int argc, char** argv) options.add("p"); options.add("page ", ki18n("Page of the document to be shown")); options.add("presentation", ki18n("Start the document in presentation mode")); + options.add("unique", ki18n("\"Unique session\" control")); options.add("+[URL]", ki18n("Document to open")); KCmdLineArgs::addCmdLineOptions( options ); KApplication app; @@ -40,6 +56,13 @@ int main(int argc, char** argv) // no session.. just start up normally KCmdLineArgs* args = KCmdLineArgs::parsedArgs(); + // try to attach the "unique" session: if we succeed, do nothing more and exit + if (attachUniqueInstance(args)) + { + args->clear(); + return 0; + } + if (args->count() == 0) { Shell* widget = new Shell(args); diff --git a/shell/shell.cpp b/shell/shell.cpp index 33f5fb757..8a09d9a82 100644 --- a/shell/shell.cpp +++ b/shell/shell.cpp @@ -21,6 +21,7 @@ // qt/kde includes #include +#include #include #include #include @@ -102,6 +103,11 @@ void Shell::init() } setAutoSaveSettings(); + if (m_args && m_args->isSet("unique") && m_args->count() == 1) + { + QDBusConnection::sessionBus().registerService("org.kde.okular"); + } + if (m_openUrl.isValid()) QTimer::singleShot(0, this, SLOT(delayedOpen())); }