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
remotes/origin/old/work/tiff-improvements
Pino Toscano 18 years ago
parent 0eab41cc97
commit bc966cb0f5
  1. 23
      shell/main.cpp
  2. 6
      shell/shell.cpp

@ -16,8 +16,23 @@
#include <kapplication.h>
#include <kcmdlineargs.h>
#include <klocale.h>
#include <QtDBus/qdbusinterface.h>
#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 <number>", 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);

@ -21,6 +21,7 @@
// qt/kde includes
#include <qtimer.h>
#include <QtDBus/qdbusconnection.h>
#include <kaction.h>
#include <kapplication.h>
#include <kcmdlineargs.h>
@ -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()));
}

Loading…
Cancel
Save