]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/dolphintabpage.cpp
Adress the first round of Angelaccio's review comments
[dolphin.git] / src / dolphintabpage.cpp
index b2bb5c896d95d720c4cab58a8f4d268c6c46214a..30014eae87181ed2fb4ba77d8d019bb6f68ea653 100644 (file)
@@ -1,21 +1,8 @@
-/***************************************************************************
- * Copyright (C) 2014 by Emmanuel Pescosta <emmanuelpescosta099@gmail.com> *
- *                                                                         *
- *   This program is free software; you can redistribute it and/or modify  *
- *   it under the terms of the GNU General Public License as published by  *
- *   the Free Software Foundation; either version 2 of the License, or     *
- *   (at your option) any later version.                                   *
- *                                                                         *
- *   This program is distributed in the hope that it will be useful,       *
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
- *   GNU General Public License for more details.                          *
- *                                                                         *
- *   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.,                                       *
- *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA            *
- ***************************************************************************/
+/*
+ * SPDX-FileCopyrightText: 2014 Emmanuel Pescosta <emmanuelpescosta099@gmail.com>
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
 
 #include "dolphintabpage.h"
 
@@ -33,7 +20,7 @@ DolphinTabPage::DolphinTabPage(const QUrl &primaryUrl, const QUrl &secondaryUrl,
 {
     QVBoxLayout* layout = new QVBoxLayout(this);
     layout->setSpacing(0);
-    layout->setMargin(0);
+    layout->setContentsMargins(0, 0, 0, 0);
 
     m_splitter = new QSplitter(Qt::Horizontal, this);
     m_splitter->setChildrenCollapsible(false);
@@ -81,20 +68,27 @@ void DolphinTabPage::setSplitViewEnabled(bool enabled, const QUrl &secondaryUrl)
             const QUrl& url = (secondaryUrl.isEmpty()) ? m_primaryViewContainer->url() : secondaryUrl;
             m_secondaryViewContainer = createViewContainer(url);
 
-            const bool placesSelectorVisible = m_primaryViewContainer->urlNavigator()->isPlacesSelectorVisible();
-            m_secondaryViewContainer->urlNavigator()->setPlacesSelectorVisible(placesSelectorVisible);
-
             m_splitter->addWidget(m_secondaryViewContainer);
             m_secondaryViewContainer->show();
             m_secondaryViewContainer->setActive(true);
         } else {
-            // Close the view which is active.
-            DolphinViewContainer* view = activeViewContainer();
-            if (m_primaryViewActive) {
-                // If the primary view is active, we have to swap the pointers
-                // because the secondary view will be the new primary view.
-                qSwap(m_primaryViewContainer, m_secondaryViewContainer);
-                m_primaryViewActive = false;
+            DolphinViewContainer* view;
+            if (GeneralSettings::closeActiveSplitView()) {
+                view = activeViewContainer();
+                if (m_primaryViewActive) {
+                    // If the primary view is active, we have to swap the pointers
+                    // because the secondary view will be the new primary view.
+                    qSwap(m_primaryViewContainer, m_secondaryViewContainer);
+                    m_primaryViewActive = false;
+                }
+            } else {
+                view = m_primaryViewActive ? m_secondaryViewContainer : m_primaryViewContainer;
+                if (!m_primaryViewActive) {
+                    // If the secondary view is active, we have to swap the pointers
+                    // because the secondary view will be the new primary view.
+                    qSwap(m_primaryViewContainer, m_secondaryViewContainer);
+                    m_primaryViewActive = true;
+                }
             }
             m_primaryViewContainer->setActive(true);
             view->close();
@@ -153,14 +147,6 @@ void DolphinTabPage::markUrlAsCurrent(const QUrl& url)
     }
 }
 
-void DolphinTabPage::setPlacesSelectorVisible(bool visible)
-{
-    m_primaryViewContainer->urlNavigator()->setPlacesSelectorVisible(visible);
-    if (m_splitViewEnabled) {
-        m_secondaryViewContainer->urlNavigator()->setPlacesSelectorVisible(visible);
-    }
-}
-
 void DolphinTabPage::refreshViews()
 {
     m_primaryViewContainer->readSettings();
@@ -179,12 +165,12 @@ QByteArray DolphinTabPage::saveState() const
     stream << m_splitViewEnabled;
 
     stream << m_primaryViewContainer->url();
-    stream << m_primaryViewContainer->urlNavigator()->isUrlEditable();
+    stream << m_primaryViewContainer->urlNavigatorInternal()->isUrlEditable();
     m_primaryViewContainer->view()->saveState(stream);
 
     if (m_splitViewEnabled) {
         stream << m_secondaryViewContainer->url();
-        stream << m_secondaryViewContainer->urlNavigator()->isUrlEditable();
+        stream << m_secondaryViewContainer->urlNavigatorInternal()->isUrlEditable();
         m_secondaryViewContainer->view()->saveState(stream);
     }
 
@@ -220,7 +206,7 @@ void DolphinTabPage::restoreState(const QByteArray& state)
     m_primaryViewContainer->setUrl(primaryUrl);
     bool primaryUrlEditable;
     stream >> primaryUrlEditable;
-    m_primaryViewContainer->urlNavigator()->setUrlEditable(primaryUrlEditable);
+    m_primaryViewContainer->urlNavigatorInternal()->setUrlEditable(primaryUrlEditable);
     m_primaryViewContainer->view()->restoreState(stream);
 
     if (isSplitViewEnabled) {
@@ -229,7 +215,7 @@ void DolphinTabPage::restoreState(const QByteArray& state)
         m_secondaryViewContainer->setUrl(secondaryUrl);
         bool secondaryUrlEditable;
         stream >> secondaryUrlEditable;
-        m_secondaryViewContainer->urlNavigator()->setUrlEditable(secondaryUrlEditable);
+        m_secondaryViewContainer->urlNavigatorInternal()->setUrlEditable(secondaryUrlEditable);
         m_secondaryViewContainer->view()->restoreState(stream);
     }
 
@@ -264,7 +250,7 @@ void DolphinTabPage::restoreStateV1(const QByteArray& state)
     m_primaryViewContainer->setUrl(primaryUrl);
     bool primaryUrlEditable;
     stream >> primaryUrlEditable;
-    m_primaryViewContainer->urlNavigator()->setUrlEditable(primaryUrlEditable);
+    m_primaryViewContainer->urlNavigatorInternal()->setUrlEditable(primaryUrlEditable);
 
     if (isSplitViewEnabled) {
         QUrl secondaryUrl;
@@ -272,7 +258,7 @@ void DolphinTabPage::restoreStateV1(const QByteArray& state)
         m_secondaryViewContainer->setUrl(secondaryUrl);
         bool secondaryUrlEditable;
         stream >> secondaryUrlEditable;
-        m_secondaryViewContainer->urlNavigator()->setUrlEditable(secondaryUrlEditable);
+        m_secondaryViewContainer->urlNavigatorInternal()->setUrlEditable(secondaryUrlEditable);
     }
 
     stream >> m_primaryViewActive;
@@ -320,26 +306,27 @@ void DolphinTabPage::slotViewActivated()
 
     const DolphinView* newActiveView = activeViewContainer()->view();
 
-    if (newActiveView != oldActiveView) {
-        disconnect(oldActiveView, &DolphinView::urlChanged,
-                   this, &DolphinTabPage::activeViewUrlChanged);
-        disconnect(oldActiveView, &DolphinView::redirection,
-                   this, &DolphinTabPage::slotViewUrlRedirection);
-        connect(newActiveView, &DolphinView::urlChanged,
-                this, &DolphinTabPage::activeViewUrlChanged);
-        connect(newActiveView, &DolphinView::redirection,
-                this, &DolphinTabPage::slotViewUrlRedirection);
+    if (newActiveView == oldActiveView) {
+        return;
     }
 
-    emit activeViewUrlChanged(activeViewContainer()->url());
-    emit activeViewChanged(activeViewContainer());
+    disconnect(oldActiveView, &DolphinView::urlChanged,
+               this, &DolphinTabPage::activeViewUrlChanged);
+    disconnect(oldActiveView, &DolphinView::redirection,
+               this, &DolphinTabPage::slotViewUrlRedirection);
+    connect(newActiveView, &DolphinView::urlChanged,
+            this, &DolphinTabPage::activeViewUrlChanged);
+    connect(newActiveView, &DolphinView::redirection,
+            this, &DolphinTabPage::slotViewUrlRedirection);
+    Q_EMIT activeViewChanged(activeViewContainer());
+    Q_EMIT activeViewUrlChanged(activeViewContainer()->url());
 }
 
 void DolphinTabPage::slotViewUrlRedirection(const QUrl& oldUrl, const QUrl& newUrl)
 {
-    Q_UNUSED(oldUrl);
+    Q_UNUSED(oldUrl)
 
-    emit activeViewUrlChanged(newUrl);
+    Q_EMIT activeViewUrlChanged(newUrl);
 }
 
 void DolphinTabPage::switchActiveView()