]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/dolphinapplication.cpp
Remove the space (1 pixel) between the file name and the file
[dolphin.git] / src / dolphinapplication.cpp
index 59e870adb4691680e48db16b9048a21106704690..8e83a85928a0dadf56f5b0969c99c9f409e4d8f6 100644 (file)
@@ -1,5 +1,5 @@
 /***************************************************************************
- *   Copyright (C) 2006 by Peter Penz <peter.penz@gmx.at>                  *
+ *   Copyright (C) 2006-2011 by Peter Penz <peter.penz19@gmail.com>        *
  *   Copyright (C) 2006 by Holger 'zecke' Freyther <freyther@kde.org>      *
  *                                                                         *
  *   This program is free software; you can redistribute it and/or modify  *
 
 #include "dolphinapplication.h"
 #include "dolphinmainwindow.h"
+#include "dolphin_generalsettings.h"
 
-#include <applicationadaptor.h>
-#include <kurl.h>
-#include <QDBusConnection>
+#include <KCmdLineArgs>
+#include <KDebug>
+#include <KRun>
+#include <KUrl>
 
 DolphinApplication::DolphinApplication() :
-    m_lastId(0)
+    m_mainWindow(0)
 {
-    new ApplicationAdaptor(this);
-    QDBusConnection::sessionBus().registerObject("/dolphin/Application", this);
-}
+    KGlobal::locale()->insertCatalog("libkonq"); // Needed for applications using libkonq
 
-DolphinApplication::~DolphinApplication()
-{
-    // cleanup what ever is left from the MainWindows
-    while (m_mainWindows.count() != 0) {
-        delete m_mainWindows.takeFirst();
+    m_mainWindow = new DolphinMainWindow();
+    m_mainWindow->setAttribute(Qt::WA_DeleteOnClose);
+    m_mainWindow->show();
+
+    KCmdLineArgs* args = KCmdLineArgs::parsedArgs();
+
+    const int argsCount = args->count();
+
+    QList<KUrl> urls;
+    for (int i = 0; i < argsCount; ++i) {
+        const KUrl url = args->url(i);
+        if (url.isValid()) {
+            urls.append(url);
+        }
     }
-}
 
-DolphinApplication* DolphinApplication::app()
-{
-    return qobject_cast<DolphinApplication*>(qApp);
-}
+    bool resetSplitSettings = false;
+    if (args->isSet("split") && !GeneralSettings::splitView()) {
+        // Dolphin should be opened with a split view although this is not
+        // set in the GeneralSettings. Temporary adjust the setting until
+        // all passed URLs have been opened.
+        GeneralSettings::setSplitView(true);
+        resetSplitSettings = true;
 
-DolphinMainWindow* DolphinApplication::createMainWindow()
-{
-    DolphinMainWindow* mainWindow = new DolphinMainWindow(m_lastId);
-    ++m_lastId;
-    mainWindow->init();
+        // We need 2 URLs to open Dolphin in split view mode
+        if (urls.isEmpty()) { // No URL given - Open home URL in all two views
+            urls.append(GeneralSettings::homeUrl());
+            urls.append(GeneralSettings::homeUrl());
+        } else if (urls.length() == 1) { // Only 1 URL given - Open given URL in all two views
+            urls.append(urls.at(0));
+        }
+    }
+
+    if (!urls.isEmpty()) {
+        if (args->isSet("select")) {
+            m_mainWindow->openFiles(urls);
+        } else {
+            m_mainWindow->openDirectories(urls);
+        }
+    }
+
+    if (resetSplitSettings) {
+        GeneralSettings::setSplitView(false);
+    }
 
-    m_mainWindows.append(mainWindow);
-    return mainWindow;
+    args->clear();
 }
 
-int DolphinApplication::openWindow(const QString& url)
+DolphinApplication::~DolphinApplication()
 {
-    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)
+DolphinApplication* DolphinApplication::app()
 {
-    m_mainWindows.removeAll(mainWindow);
+    return qobject_cast<DolphinApplication*>(qApp);
 }
 
-void DolphinApplication::refreshMainWindows()
+void DolphinApplication::restoreSession()
 {
-    for (int i = 0; i < m_mainWindows.count(); ++i) {
-        m_mainWindows[i]->refreshViews();
+    const QString className = KXmlGuiWindow::classNameOfToplevel(1);
+    if (className == QLatin1String("DolphinMainWindow")) {
+        m_mainWindow->restore(1);
+    } else {
+        kWarning() << "Unknown class " << className << " in session saved data!";
     }
 }