From 6ee9f08e8fc90cc67cd2ed83ae6f2dd5c1846ba3 Mon Sep 17 00:00:00 2001 From: Peter Penz Date: Thu, 22 Mar 2007 07:19:07 +0000 Subject: [PATCH] Use KUniqueApplication::newInstance() as David suggested some time ago. This simplifies the code and solves the issue that the window is not moved to the foreground when opening new main windows. svn path=/trunk/KDE/kdebase/apps/; revision=645276 --- src/dolphinapplication.cpp | 42 ++++++++++++++++++++++++++++---------- src/dolphinapplication.h | 3 +++ src/main.cpp | 34 +++++++----------------------- 3 files changed, 41 insertions(+), 38 deletions(-) diff --git a/src/dolphinapplication.cpp b/src/dolphinapplication.cpp index 59e870adb4..9e6d0565f5 100644 --- a/src/dolphinapplication.cpp +++ b/src/dolphinapplication.cpp @@ -22,6 +22,7 @@ #include "dolphinmainwindow.h" #include +#include #include #include @@ -55,17 +56,6 @@ DolphinMainWindow* DolphinApplication::createMainWindow() return mainWindow; } -int DolphinApplication::openWindow(const QString& url) -{ - DolphinMainWindow* win = createMainWindow(); - if ((win->activeView() != 0) && !url.isEmpty()) { - win->activeView()->setUrl(KUrl(url)); - } - win->show(); - //TODO find how to raise a window (as if we've launched a new dolphin process) - return win->getId(); -} - void DolphinApplication::removeMainWindow(DolphinMainWindow* mainWindow) { m_mainWindows.removeAll(mainWindow); @@ -78,4 +68,34 @@ void DolphinApplication::refreshMainWindows() } } + +int DolphinApplication::newInstance() +{ + int exitValue = KUniqueApplication::newInstance(); + + KCmdLineArgs* args = KCmdLineArgs::parsedArgs(); + if (args->count() > 0) { + for (int i = 0; i < args->count(); ++i) { + openWindow(args->arg(i)); + } + } + else { + openWindow(QString()); + } + + args->clear(); + + return exitValue; +} + +int DolphinApplication::openWindow(const QString& url) +{ + DolphinMainWindow* win = createMainWindow(); + if ((win->activeView() != 0) && !url.isEmpty()) { + win->activeView()->setUrl(KUrl(url)); + } + win->show(); + return win->getId(); +} + #include "dolphinapplication.moc" diff --git a/src/dolphinapplication.h b/src/dolphinapplication.h index fa6a1ceeef..4ea91db838 100644 --- a/src/dolphinapplication.h +++ b/src/dolphinapplication.h @@ -51,6 +51,9 @@ public: DolphinMainWindow* createMainWindow(); void refreshMainWindows(); + /** @see KUniqueApplication::newInstance(). */ + virtual int newInstance(); + public slots: int openWindow(const QString& url); diff --git a/src/main.cpp b/src/main.cpp index 5a6d3dd8e8..47095c3a5d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -33,18 +33,6 @@ static KCmdLineOptions options[] = KCmdLineLastOption }; -void openWindow(DolphinApplication* app, const QString& url = QString()) -{ - if (app != 0) { - app->openWindow(url); - return; - } - - static QDBusInterface dbusIface("org.kde.dolphin", "/dolphin/Application", "", - QDBusConnection::connectToBus(QDBusConnection::SessionBus, "session_bus")); - QDBusReply reply = dbusIface.call("openWindow", url); -} - int main(int argc, char **argv) { KAboutData about("dolphin", @@ -67,11 +55,10 @@ int main(int argc, char **argv) KCmdLineArgs::init(argc, argv, &about); KCmdLineArgs::addCmdLineOptions(options); - DolphinApplication *app = 0; + + DolphinApplication* app = 0; if (DolphinApplication::start()) { app = new DolphinApplication(); - } - #ifdef __GNUC__ #warning TODO, SessionManagement @@ -85,18 +72,11 @@ int main(int argc, char **argv) } } else { #endif - - KCmdLineArgs* args = KCmdLineArgs::parsedArgs(); - if (args->count() > 0) { - for (int i = 0; i < args->count(); ++i) { - openWindow(app, args->arg(i)); - } - } - else { - openWindow(app); - } - args->clear(); - if (app != 0) { return app->exec(); } + + static QDBusInterface dbusIface("org.kde.dolphin", "/dolphin/Application", "", + QDBusConnection::connectToBus(QDBusConnection::SessionBus, "session_bus")); + dbusIface.call("openWindow"); + return 0; }