]> cloud.milkyroute.net Git - dolphin.git/commitdiff
React on the redirection signal from DolphinView to properly update the tab and windo...
authorEmmanuel Pescosta <emmanuelpescosta099@gmail.com>
Wed, 13 Aug 2014 20:06:28 +0000 (22:06 +0200)
committerEmmanuel Pescosta <emmanuelpescosta099@gmail.com>
Wed, 13 Aug 2014 20:06:28 +0000 (22:06 +0200)
REVIEW: 119697
BUG: 305721

src/dolphinmainwindow.cpp
src/dolphinmainwindow.h
src/dolphintabpage.cpp
src/dolphintabpage.h
src/dolphintabwidget.cpp
src/dolphintabwidget.h

index 588bfda64fdcc1edcc912b9559cffbe5444b03ea..95b08af96e1d8002aea3f5e490f773d77113e270 100644 (file)
@@ -136,6 +136,8 @@ DolphinMainWindow::DolphinMainWindow() :
             this, SLOT(activeViewChanged(DolphinViewContainer*)));
     connect(m_tabWidget, SIGNAL(tabCountChanged(int)),
             this, SLOT(tabCountChanged(int)));
+    connect(m_tabWidget, SIGNAL(currentUrlChanged(KUrl)),
+            this, SLOT(setUrlAsCaption(KUrl)));
     setCentralWidget(m_tabWidget);
 
     setupActions();
@@ -236,7 +238,6 @@ void DolphinMainWindow::changeUrl(const KUrl& url)
     updatePasteAction();
     updateViewActions();
     updateGoActions();
-    setUrlAsCaption(url);
 
     emit urlChanged(url);
 }
@@ -945,8 +946,6 @@ void DolphinMainWindow::activeViewChanged(DolphinViewContainer* viewContainer)
     updateGoActions();
 
     const KUrl url = viewContainer->url();
-    setUrlAsCaption(url);
-
     emit urlChanged(url);
 }
 
@@ -958,6 +957,22 @@ void DolphinMainWindow::tabCountChanged(int count)
     actionCollection()->action("activate_prev_tab")->setEnabled(enableTabActions);
 }
 
+void DolphinMainWindow::setUrlAsCaption(const KUrl& url)
+{
+    QString caption;
+    if (!url.isLocalFile()) {
+        caption.append(url.protocol() + " - ");
+        if (url.hasHost()) {
+            caption.append(url.host() + " - ");
+        }
+    }
+
+    const QString fileName = url.fileName().isEmpty() ? "/" : url.fileName();
+    caption.append(fileName);
+
+    setCaption(caption);
+}
+
 void DolphinMainWindow::setupActions()
 {
     // setup 'File' menu
@@ -1471,22 +1486,6 @@ bool DolphinMainWindow::isKompareInstalled() const
     return installed;
 }
 
-void DolphinMainWindow::setUrlAsCaption(const KUrl& url)
-{
-    QString caption;
-    if (!url.isLocalFile()) {
-        caption.append(url.protocol() + " - ");
-        if (url.hasHost()) {
-            caption.append(url.host() + " - ");
-        }
-    }
-
-    const QString fileName = url.fileName().isEmpty() ? "/" : url.fileName();
-    caption.append(fileName);
-
-    setCaption(caption);
-}
-
 void DolphinMainWindow::createPanelAction(const KIcon& icon,
                                           const QKeySequence& shortcut,
                                           QAction* dockAction,
index 7bce7f13e982c0252836eab28826d868225693b3..9d4c003af705965391299839438b292c4d2f3057 100644 (file)
@@ -429,6 +429,12 @@ private slots:
      */
     void tabCountChanged(int count);
 
+    /**
+     * Sets the window caption to url.fileName() if this is non-empty,
+     * "/" if the URL is "file:///", and url.protocol() otherwise.
+     */
+    void setUrlAsCaption(const KUrl& url);
+
 private:
     void setupActions();
     void setupDockWidgets();
@@ -464,12 +470,6 @@ private:
 
     bool isKompareInstalled() const;
 
-    /**
-     * Sets the window caption to url.fileName() if this is non-empty,
-     * "/" if the URL is "file:///", and url.protocol() otherwise.
-     */
-    void setUrlAsCaption(const KUrl& url);
-
     /**
      * Creates an action for showing/hiding a panel, that is accessible
      * in "Configure toolbars..." and "Configure shortcuts...". This is necessary
index 23e33c95833b308222afec9f93c8121ea8489928..3d1ba5a3e85babcff66bde960ada232dfbc51063 100644 (file)
@@ -41,6 +41,8 @@ DolphinTabPage::DolphinTabPage(const KUrl& primaryUrl, const KUrl& secondaryUrl,
     m_primaryViewContainer = createViewContainer(primaryUrl);
     connect(m_primaryViewContainer->view(), SIGNAL(urlChanged(KUrl)),
             this, SIGNAL(activeViewUrlChanged(KUrl)));
+    connect(m_primaryViewContainer->view(), SIGNAL(redirection(KUrl,KUrl)),
+            this, SLOT(slotViewUrlRedirection(KUrl,KUrl)));
 
     m_splitter->addWidget(m_primaryViewContainer);
     m_primaryViewContainer->show();
@@ -245,14 +247,25 @@ void DolphinTabPage::slotViewActivated()
     if (newActiveView != oldActiveView) {
         disconnect(oldActiveView, SIGNAL(urlChanged(KUrl)),
                    this, SIGNAL(activeViewUrlChanged(KUrl)));
+        disconnect(oldActiveView, SIGNAL(redirection(KUrl,KUrl)),
+                   this, SLOT(slotViewUrlRedirection(KUrl,KUrl)));
         connect(newActiveView, SIGNAL(urlChanged(KUrl)),
                 this, SIGNAL(activeViewUrlChanged(KUrl)));
+        connect(newActiveView, SIGNAL(redirection(KUrl,KUrl)),
+                this, SLOT(slotViewUrlRedirection(KUrl,KUrl)));
     }
 
     emit activeViewUrlChanged(activeViewContainer()->url());
     emit activeViewChanged(activeViewContainer());
 }
 
+void DolphinTabPage::slotViewUrlRedirection(const KUrl& oldUrl, const KUrl& newUrl)
+{
+    Q_UNUSED(oldUrl);
+
+    emit activeViewUrlChanged(newUrl);
+}
+
 DolphinViewContainer* DolphinTabPage::createViewContainer(const KUrl& url) const
 {
     DolphinViewContainer* container = new DolphinViewContainer(url, m_splitter);
index 278524792cac13f7df95adea962a74aa47380630..de5a589152d7ceeb70031e87c8eb2f677dc128a6 100644 (file)
@@ -133,6 +133,13 @@ private slots:
      */
     void slotViewActivated();
 
+    /**
+     * Handles the view url redirection event.
+     *
+     * It emits the activeViewUrlChanged signal with the url \a newUrl.
+     */
+    void slotViewUrlRedirection(const KUrl& oldUrl, const KUrl& newUrl);
+
 private:
     /**
      * Creates a new view container and does the default initialization.
index ea71b48566c4feb1d1589d2f5c50480aeb66360d..76d4b8d48d48b49a7d1f4585d53d95c3e667992b 100644 (file)
@@ -295,12 +295,19 @@ void DolphinTabWidget::tabUrlChanged(const KUrl& url)
     if (index >= 0) {
         tabBar()->setTabText(index, tabName(url));
         tabBar()->setTabIcon(index, KIcon(KMimeType::iconNameForUrl(url)));
+
+        // Emit the currentUrlChanged signal if the url of the current tab has been changed.
+        if (index == currentIndex()) {
+            emit currentUrlChanged(url);
+        }
     }
 }
 
 void DolphinTabWidget::currentTabChanged(int index)
 {
-    emit activeViewChanged(tabPageAt(index)->activeViewContainer());
+    DolphinViewContainer* viewContainer = tabPageAt(index)->activeViewContainer();
+    emit activeViewChanged(viewContainer);
+    emit currentUrlChanged(viewContainer->url());
 }
 
 void DolphinTabWidget::tabInserted(int index)
index aaadbc997b583e0703826b3e07850b5d841bb8ee..98bcd985abc37cdd3657da8a4f47b73794da245a 100644 (file)
@@ -72,6 +72,12 @@ signals:
      */
     void rememberClosedTab(const KUrl& url, const QByteArray& state);
 
+    /**
+     * Is emitted when the url of the current tab has been changed. This signal
+     * is also emitted when the active view has been changed.
+     */
+    void currentUrlChanged(const KUrl& url);
+
 public slots:
     /**
      * Opens a new view with the current URL that is part of a tab and activates