]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/dolphinapplication.cpp
Fix regression concerning the "Places" selector in the location bar
[dolphin.git] / src / dolphinapplication.cpp
index a27a4cb27c2f7fee7a0764652b11b0f27de6a1e9..a4b105b90f31dfbb2be0c9243be710e65f9f889c 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  *
  *   You should have received a copy of the GNU General Public License     *
  *   along with this program; if not, write to the                         *
  *   Free Software Foundation, Inc.,                                       *
- *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
+ *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA            *
  ***************************************************************************/
 
 #include "dolphinapplication.h"
 #include "dolphinmainwindow.h"
+#include "dolphin_generalsettings.h"
 
-DolphinApplication::DolphinApplication()
+#include <KCmdLineArgs>
+#include <KDebug>
+#include <KRun>
+#include <KUrl>
+
+DolphinApplication::DolphinApplication() :
+    m_mainWindow(0)
 {
+    KGlobal::locale()->insertCatalog("libkonq"); // Needed for applications using libkonq
+
+    m_mainWindow = new DolphinMainWindow();
+    m_mainWindow->setAttribute(Qt::WA_DeleteOnClose);
+
+    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);
+        }
+    }
+
+    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;
+
+        // 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);
+        }
+    } else {
+        const KUrl homeUrl(GeneralSettings::homeUrl());
+        m_mainWindow->openNewActivatedTab(homeUrl);
+    }
+
+    if (resetSplitSettings) {
+        GeneralSettings::setSplitView(false);
+    }
+
+    args->clear();
+
+    m_mainWindow->show();
 }
 
-/*
- * cleanup what ever is left from the MainWindows
- */
 DolphinApplication::~DolphinApplication()
 {
-    while( m_mainWindows.count() != 0 )
-        delete m_mainWindows.takeFirst();
 }
 
 DolphinApplication* DolphinApplication::app()
@@ -39,26 +93,14 @@ DolphinApplication* DolphinApplication::app()
     return qobject_cast<DolphinApplication*>(qApp);
 }
 
-DolphinMainWindow* DolphinApplication::createMainWindow()
+void DolphinApplication::restoreSession()
 {
-    DolphinMainWindow* mainwindow = new DolphinMainWindow;
-    mainwindow->init();
-    
-    m_mainWindows.append( mainwindow );
-    return mainwindow;
-}
-
-void DolphinApplication::removeMainWindow( DolphinMainWindow *mainwindow )
-{
-    m_mainWindows.remove( mainwindow );
-}
-
-void DolphinApplication::refreshMainWindows()
-{
-    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!";
     }
 }
 
 #include "dolphinapplication.moc"
-