]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/dolphinmainwindow.cpp
Hide the text of the go-back, go-forward and view-mode actions per default when the...
[dolphin.git] / src / dolphinmainwindow.cpp
index e58b81740730e8566740dc0fb6c18e28913b2427..21b1817468c3251edb08b52ade656ae0f2f580cf 100644 (file)
@@ -114,9 +114,13 @@ DolphinMainWindow::DolphinMainWindow(int id) :
     m_actionHandler(0),
     m_remoteEncoding(0),
     m_settingsDialog(0),
-    m_captionStatJob(0),
     m_lastHandleUrlStatJob(0)
 {
+    // Workaround for a X11-issue in combination with KModifierInfo
+    // (see DolphinContextMenu::initializeModifierKeyInfo() for
+    // more information):
+    DolphinContextMenu::initializeModifierKeyInfo();
+
     setObjectName("Dolphin#");
 
     m_viewTab.append(ViewTab());
@@ -335,15 +339,6 @@ void DolphinMainWindow::slotSelectionChanged(const KFileItemList& selection)
     emit selectionChanged(selection);
 }
 
-void DolphinMainWindow::slotWheelMoved(int wheelDelta)
-{
-    if (wheelDelta > 0) {
-        activatePrevTab();
-    } else {
-        activateNextTab();
-    }
-}
-
 void DolphinMainWindow::slotRequestItemInfo(const KFileItem& item)
 {
     emit requestItemInfo(item);
@@ -467,17 +462,27 @@ void DolphinMainWindow::activatePrevTab()
 void DolphinMainWindow::openInNewTab()
 {
     const KFileItemList list = m_activeViewContainer->view()->selectedItems();
-    if ((list.count() == 1) && list[0].isDir()) {
+    if (list.isEmpty()) {
+        openNewTab(m_activeViewContainer->url());
+    } else if ((list.count() == 1) && list[0].isDir()) {
         openNewTab(m_activeViewContainer->view()->selectedUrls()[0]);
     }
 }
 
 void DolphinMainWindow::openInNewWindow()
 {
+    KUrl newWindowUrl;
+
     const KFileItemList list = m_activeViewContainer->view()->selectedItems();
-    if ((list.count() == 1) && list[0].isDir()) {
+    if (list.isEmpty()) {
+        newWindowUrl = m_activeViewContainer->url();
+    } else if ((list.count() == 1) && list[0].isDir()) {
+        newWindowUrl = m_activeViewContainer->view()->selectedUrls()[0];
+    }
+
+    if (!newWindowUrl.isEmpty()) {
         DolphinMainWindow* window = DolphinApplication::app()->createMainWindow();
-        window->changeUrl(m_activeViewContainer->view()->selectedUrls()[0]);
+        window->changeUrl(newWindowUrl);
         window->show();
     }
 }
@@ -796,6 +801,17 @@ void DolphinMainWindow::reloadView()
 
 void DolphinMainWindow::stopLoading()
 {
+    m_activeViewContainer->view()->stopLoading();
+}
+
+void DolphinMainWindow::enableStopAction()
+{
+    actionCollection()->action("stop")->setEnabled(true);
+}
+
+void DolphinMainWindow::disableStopAction()
+{
+    actionCollection()->action("stop")->setEnabled(false);
 }
 
 void DolphinMainWindow::toggleFilterBarVisibility(bool show)
@@ -963,7 +979,7 @@ void DolphinMainWindow::openTerminal()
 void DolphinMainWindow::editSettings()
 {
     if (m_settingsDialog == 0) {
-        const KUrl& url = activeViewContainer()->url();
+        const KUrl url = activeViewContainer()->url();
         m_settingsDialog = new DolphinSettingsDialog(url, this);
         m_settingsDialog->setAttribute(Qt::WA_DeleteOnClose);
         m_settingsDialog->show();
@@ -1167,14 +1183,6 @@ void DolphinMainWindow::tabDropEvent(int tab, QDropEvent* event)
     }
 }
 
-void DolphinMainWindow::slotCaptionStatFinished(KJob* job)
-{
-    m_captionStatJob = 0;
-    const KIO::UDSEntry entry = static_cast<KIO::StatJob*>(job)->statResult();
-    const QString name = entry.stringValue(KIO::UDSEntry::UDS_DISPLAY_NAME);
-    setCaption(name);
-}
-
 void DolphinMainWindow::slotWriteStateChanged(bool isFolderWritable)
 {
     newFileMenu()->setEnabled(isFolderWritable);
@@ -1186,7 +1194,24 @@ void DolphinMainWindow::openContextMenu(const KFileItem& item,
 {
     DolphinContextMenu contextMenu(this, item, url);
     contextMenu.setCustomActions(customActions);
-    contextMenu.open();
+    const DolphinContextMenu::Command command = contextMenu.open();
+
+    switch (command) {
+    case DolphinContextMenu::OpenParentFolderInNewWindow: {
+        DolphinMainWindow* window = DolphinApplication::app()->createMainWindow();
+        window->changeUrl(item.url().upUrl());
+        window->show();
+        break;
+    }
+
+    case DolphinContextMenu::OpenParentFolderInNewTab:
+        openNewTab(item.url().upUrl());
+        break;
+
+    case DolphinContextMenu::None:
+    default:
+        break;
+    }
 }
 
 void DolphinMainWindow::init()
@@ -1208,7 +1233,7 @@ void DolphinMainWindow::init()
 
     setupActions();
 
-    const KUrl& homeUrl = generalSettings->homeUrl();
+    const KUrl homeUrl(generalSettings->homeUrl());
     setUrlAsCaption(homeUrl);
     m_actionHandler = new DolphinViewActionHandler(actionCollection(), this);
     connect(m_actionHandler, SIGNAL(actionBeingHandled()), SLOT(clearStatusBar()));
@@ -1241,8 +1266,6 @@ void DolphinMainWindow::init()
             this, SLOT(openNewTab()));
     connect(m_tabBar, SIGNAL(testCanDecode(const QDragMoveEvent*, bool&)),
             this, SLOT(slotTestCanDecode(const QDragMoveEvent*, bool&)));
-    connect(m_tabBar, SIGNAL(wheelDelta(int)),
-            this, SLOT(slotWheelMoved(int)));
     connect(m_tabBar, SIGNAL(mouseMiddleClick(int)),
             this, SLOT(closeTab(int)));
     connect(m_tabBar, SIGNAL(tabMoved(int, int)),
@@ -1314,9 +1337,9 @@ void DolphinMainWindow::setActiveViewContainer(DolphinViewContainer* viewContain
     updateViewActions();
     updateGoActions();
 
-    const KUrl& url = m_activeViewContainer->url();
+    const KUrl url = m_activeViewContainer->url();
     setUrlAsCaption(url);
-    if (m_viewTab.count() > 1 && m_viewTab[m_tabIndex].secondaryView != 0) {
+    if (m_viewTab.count() > 1) {
         m_tabBar->setTabText(m_tabIndex, tabName(url));
         m_tabBar->setTabIcon(m_tabIndex, KIcon(KMimeType::iconNameForUrl(url)));
     }
@@ -1639,7 +1662,7 @@ void DolphinMainWindow::updateViewActions()
 void DolphinMainWindow::updateGoActions()
 {
     QAction* goUpAction = actionCollection()->action(KStandardAction::name(KStandardAction::Up));
-    const KUrl& currentUrl = m_activeViewContainer->url();
+    const KUrl currentUrl = m_activeViewContainer->url();
     goUpAction->setEnabled(currentUrl.upUrl() != currentUrl);
 }
 
@@ -1704,6 +1727,10 @@ void DolphinMainWindow::connectViewSignals(DolphinViewContainer* container)
             this, SLOT(openNewTab(const KUrl&)));
     connect(view, SIGNAL(requestContextMenu(KFileItem, const KUrl&, const QList<QAction*>&)),
             this, SLOT(openContextMenu(KFileItem, const KUrl&, const QList<QAction*>&)));
+    connect(view, SIGNAL(startedPathLoading(KUrl)),
+            this, SLOT(enableStopAction()));
+    connect(view, SIGNAL(finishedPathLoading(KUrl)),
+            this, SLOT(disableStopAction()));
 
     const KUrlNavigator* navigator = container->urlNavigator();
     connect(navigator, SIGNAL(urlChanged(const KUrl&)),
@@ -1789,26 +1816,18 @@ QString DolphinMainWindow::tabProperty(const QString& property, int tabIndex) co
 
 void DolphinMainWindow::setUrlAsCaption(const KUrl& url)
 {
-    delete m_captionStatJob;
-    m_captionStatJob = 0;
-
-    if (url.protocol() == QLatin1String("file")) {
-        QString caption;
-        if (url.equals(KUrl("file:///"))) {
-            caption = '/';
-        } else {
-            caption = url.fileName();
-            if (caption.isEmpty()) {
-                caption = url.protocol();
-            }
+    QString caption;
+    if (!url.isLocalFile()) {
+        caption.append(url.protocol() + " - ");
+        if (url.hasHost()) {
+            caption.append(url.host() + " - ");
         }
-
-        setCaption(caption);
-    } else {
-        m_captionStatJob = KIO::stat(url, KIO::HideProgressInfo);
-        connect(m_captionStatJob, SIGNAL(result(KJob*)),
-                this, SLOT(slotCaptionStatFinished(KJob*)));
     }
+
+    const QString fileName = url.fileName().isEmpty() ? "/" : url.fileName();
+    caption.append(fileName);
+
+    setCaption(caption);
 }
 
 QString DolphinMainWindow::squeezedText(const QString& text) const