mirror of
https://invent.kde.org/system/dolphin
synced 2024-08-22 01:40:02 +00:00
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
This commit is contained in:
parent
bf1f504039
commit
6ee9f08e8f
|
@ -22,6 +22,7 @@
|
|||
#include "dolphinmainwindow.h"
|
||||
|
||||
#include <applicationadaptor.h>
|
||||
#include <kcmdlineargs.h>
|
||||
#include <kurl.h>
|
||||
#include <QDBusConnection>
|
||||
|
||||
|
@ -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"
|
||||
|
|
|
@ -51,6 +51,9 @@ public:
|
|||
DolphinMainWindow* createMainWindow();
|
||||
void refreshMainWindows();
|
||||
|
||||
/** @see KUniqueApplication::newInstance(). */
|
||||
virtual int newInstance();
|
||||
|
||||
public slots:
|
||||
int openWindow(const QString& url);
|
||||
|
||||
|
|
34
src/main.cpp
34
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<int> 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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue