summaryrefslogtreecommitdiffstats
path: root/kpdf/shell/main.cpp
diff options
context:
space:
mode:
authorMavridis Philippe <mavridisf@gmail.com>2025-04-09 15:31:05 +0300
committerMavridis Philippe <mavridisf@gmail.com>2025-04-14 19:14:53 +0300
commit1c42c490993492fd52fbbb79ceba7470778c6275 (patch)
treedbdf7af2c364943f70bd079bdcf429943db37995 /kpdf/shell/main.cpp
parent8fc0d1697439a9d020a8a7c0deb504b71b20a671 (diff)
downloadtdegraphics-1c42c490993492fd52fbbb79ceba7470778c6275.tar.gz
tdegraphics-1c42c490993492fd52fbbb79ceba7470778c6275.zip
KPDF Shell: Instances can now be reused
This commit adds support for reusing existing KPDF instances to display externally opened documents in new tabs instead of new windows. The feature depends on whether the corresponding option is checked and on whether KPDF is invoked with any URLs. This commit adds a DCOP interface which contains tab-related methods. Also breakoff tabs are now launched in a new instance instead of creating a new Shell widget in the same app, as this causes problems with the KPDFShellDCOPInterface. As a useful bonus, the new "--new-instance" CLI switch is now available to users and scripts. Signed-off-by: Mavridis Philippe <mavridisf@gmail.com> (cherry picked from commit 77ebecd92cef8d8c368ffb9cee3c856888456546)
Diffstat (limited to 'kpdf/shell/main.cpp')
-rw-r--r--kpdf/shell/main.cpp62
1 files changed, 58 insertions, 4 deletions
diff --git a/kpdf/shell/main.cpp b/kpdf/shell/main.cpp
index dfe6078c..345b6548 100644
--- a/kpdf/shell/main.cpp
+++ b/kpdf/shell/main.cpp
@@ -16,7 +16,11 @@
#include <tdeapplication.h>
#include <tdeaboutdata.h>
#include <tdecmdlineargs.h>
+#include <tdeconfig.h>
#include <tdelocale.h>
+#include <dcopclient.h>
+#include <dcopref.h>
+#include <kdebug.h>
static const char description[] =
I18N_NOOP("KPDF, a TDE PDF viewer based on XPDF");
@@ -25,6 +29,7 @@ static const char version[] = "0.5.10";
static TDECmdLineOptions options[] =
{
+ { "new-instance", I18N_NOOP("Don't reuse existing instance"), 0 },
{ "+[URL]", I18N_NOOP("Document to open"), 0 },
TDECmdLineLastOption
};
@@ -60,12 +65,61 @@ int main(int argc, char** argv)
// no session.. just start up normally
TDECmdLineArgs* args = TDECmdLineArgs::parsedArgs();
- KPDF::Shell* widget = new KPDF::Shell;
- for (int i = 0; i < args->count(); ++i)
+ DCOPClient *client = kapp->dcopClient();
+ if (!client->attach())
{
- widget->openURL(args->url(i));
+ kdError() << "KPDF::Shell cannot attach DCOP client" << endl;
+ return 2;
+ }
+
+ bool reuseKPDF;
+
+ if (args->isSet("new-instance"))
+ {
+ reuseKPDF = false;
+ }
+ else
+ {
+ TDEConfig cfg("kpdfpartrc");
+ cfg.setGroup("General");
+ reuseKPDF = cfg.readBoolEntry("OpenInExistingKPDF", false);
+ }
+
+ TQCString kpdfInstance = "";
+ TQCString regName = client->registerAs(kapp->name(), true);
+
+ if (reuseKPDF && args->count())
+ {
+ QCStringList allClients = client->registeredApplications();
+ for (int c = 0; c < allClients.count(); ++c)
+ {
+ if (allClients[c].left(5) == "kpdf-" && allClients[c] != regName)
+ {
+ kpdfInstance = allClients[c];
+ }
+ }
+ }
+
+ if (kpdfInstance.isEmpty())
+ {
+ KPDF::Shell* widget = new KPDF::Shell;
+ for (int i = 0; i < args->count(); ++i)
+ {
+ widget->openURL(args->url(i));
+ }
+ widget->show();
+ }
+ else
+ {
+ for (int i = 0; i < args->count(); ++i)
+ {
+ DCOPRef ref(kpdfInstance, "KPDFShellDCOPIface");
+ ref.call("openURL", args->url(i));
+ }
+ DCOPRef ref(kpdfInstance, "KPDF::Shell");
+ ref.call("raise");
+ return 1;
}
- widget->show();
args->clear();
}