]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/dolphinmainwindow.cpp
Merge branch 'Applications/18.08'
[dolphin.git] / src / dolphinmainwindow.cpp
index b07849ccd4966cfc473d065c6789f0d4a5074db0..7f36e82db08eab46355bc7b7346fbfab999a73c4 100644 (file)
@@ -25,7 +25,6 @@
 #include "dolphindockwidget.h"
 #include "dolphincontextmenu.h"
 #include "dolphinnewfilemenu.h"
-#include "dolphinplacesmodelsingleton.h"
 #include "dolphinrecenttabsmenu.h"
 #include "dolphintabwidget.h"
 #include "dolphinviewcontainer.h"
@@ -48,9 +47,7 @@
 #include <KActionMenu>
 #include <KAuthorized>
 #include <KConfig>
-#include <KDesktopFile>
 #include <KFileItemListProperties>
-#include <KFilePlacesModel>
 #include <KHelpMenu>
 #include <KIO/JobUiDelegate>
 #include <KIO/OpenFileManagerWindowJob>
@@ -138,7 +135,7 @@ DolphinMainWindow::DolphinMainWindow() :
     connect(m_tabWidget, &DolphinTabWidget::tabCountChanged,
             this, &DolphinMainWindow::tabCountChanged);
     connect(m_tabWidget, &DolphinTabWidget::currentUrlChanged,
-            this, &DolphinMainWindow::setUrlAsCaption);
+            this, &DolphinMainWindow::updateWindowTitle);
     setCentralWidget(m_tabWidget);
 
     setupActions();
@@ -403,8 +400,7 @@ void DolphinMainWindow::closeEvent(QCloseEvent* event)
         dialog->setWindowTitle(i18nc("@title:window", "Confirmation"));
         dialog->setModal(true);
         QDialogButtonBox* buttons = new QDialogButtonBox(QDialogButtonBox::Yes | QDialogButtonBox::No | QDialogButtonBox::Cancel);
-        KDesktopFile dolphinDesktopFile(QStringLiteral("%1.desktop").arg(QGuiApplication::desktopFileName()));
-        KGuiItem::assign(buttons->button(QDialogButtonBox::Yes), KGuiItem(i18nc("@action:button 'Quit Dolphin' button", "&Quit %1", dolphinDesktopFile.readName()), QIcon::fromTheme(QStringLiteral("application-exit"))));
+        KGuiItem::assign(buttons->button(QDialogButtonBox::Yes), KGuiItem(i18nc("@action:button 'Quit Dolphin' button", "&Quit %1", QGuiApplication::applicationDisplayName()), QIcon::fromTheme(QStringLiteral("application-exit"))));
         KGuiItem::assign(buttons->button(QDialogButtonBox::No), KGuiItem(i18n("C&lose Current Tab"), QIcon::fromTheme(QStringLiteral("tab-close"))));
         KGuiItem::assign(buttons->button(QDialogButtonBox::Cancel), KStandardGuiItem::cancel());
         buttons->button(QDialogButtonBox::Yes)->setDefault(true);
@@ -590,6 +586,7 @@ void DolphinMainWindow::reloadView()
 {
     clearStatusBar();
     m_activeViewContainer->reload();
+    m_activeViewContainer->statusBar()->updateSpaceInfo();
 }
 
 void DolphinMainWindow::stopLoading()
@@ -806,7 +803,9 @@ void DolphinMainWindow::slotHandleUrlStatFinished(KJob* job)
 
 void DolphinMainWindow::slotWriteStateChanged(bool isFolderWritable)
 {
-    newFileMenu()->setEnabled(isFolderWritable);
+    // trash:/ is writable but we don't want to create new items in it.
+    // TODO: remove the trash check once https://phabricator.kde.org/T8234 is implemented
+    newFileMenu()->setEnabled(isFolderWritable && m_activeViewContainer->url().scheme() != QLatin1String("trash"));
 }
 
 void DolphinMainWindow::openContextMenu(const QPoint& pos,
@@ -872,8 +871,8 @@ void DolphinMainWindow::updateControlMenu()
         menu->addSeparator();
     }
 
-    added = addActionToMenu(ac->action(QStringLiteral("view_mode")), menu) |
-            addActionToMenu(ac->action(QStringLiteral("sort")), menu) |
+    added = addActionToMenu(ac->action(QStringLiteral("sort")), menu) |
+            addActionToMenu(ac->action(QStringLiteral("view_mode")), menu) |
             addActionToMenu(ac->action(QStringLiteral("additional_info")), menu) |
             addActionToMenu(ac->action(QStringLiteral("show_preview")), menu) |
             addActionToMenu(ac->action(QStringLiteral("show_in_groups")), menu) |
@@ -996,46 +995,9 @@ void DolphinMainWindow::tabCountChanged(int count)
     actionCollection()->action(QStringLiteral("activate_prev_tab"))->setEnabled(enableTabActions);
 }
 
-void DolphinMainWindow::setUrlAsCaption(const QUrl& url)
+void DolphinMainWindow::updateWindowTitle()
 {
-    QString schemePrefix;
-    if (!url.isLocalFile()) {
-        schemePrefix.append(url.scheme() + " - ");
-        if (!url.host().isEmpty()) {
-            schemePrefix.append(url.host() + " - ");
-        }
-    }
-
-    if (GeneralSettings::showFullPathInTitlebar()) {
-        const QString path = url.adjusted(QUrl::StripTrailingSlash).path();
-        setWindowTitle(schemePrefix + path);
-        return;
-    }
-
-    KFilePlacesModel *placesModel = DolphinPlacesModelSingleton::instance().placesModel();
-    const auto& matchedPlaces = placesModel->match(placesModel->index(0,0), KFilePlacesModel::UrlRole, url, 1, Qt::MatchExactly);
-
-    if (!matchedPlaces.isEmpty()) {
-        setWindowTitle(placesModel->text(matchedPlaces.first()));
-        return;
-    }
-
-    QString fileName = url.adjusted(QUrl::StripTrailingSlash).fileName();
-    if (fileName.isEmpty()) {
-        fileName = '/';
-    }
-
-    if (m_activeViewContainer->isSearchModeEnabled()) {
-        if(m_activeViewContainer->currentSearchText().isEmpty()){
-            setWindowTitle(i18n("Search"));
-        } else {
-            const auto searchText = i18n("Search for %1", m_activeViewContainer->currentSearchText());
-            setWindowTitle(searchText);
-        }
-        return;
-    }
-
-    setWindowTitle(schemePrefix + fileName);
+    setWindowTitle(m_activeViewContainer->caption());
 }
 
 void DolphinMainWindow::slotStorageTearDownFromPlacesRequested(const QString& mountPath)
@@ -1061,6 +1023,7 @@ void DolphinMainWindow::setupActions()
 {
     // setup 'File' menu
     m_newFileMenu = new DolphinNewFileMenu(actionCollection(), this);
+    m_newFileMenu->setObjectName("newFileMenu");
     QMenu* menu = m_newFileMenu->menu();
     menu->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
     menu->setIcon(QIcon::fromTheme(QStringLiteral("document-new")));
@@ -1074,7 +1037,7 @@ void DolphinMainWindow::setupActions()
     QAction* newTab = actionCollection()->addAction(QStringLiteral("new_tab"));
     newTab->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
     newTab->setText(i18nc("@action:inmenu File", "New Tab"));
-    actionCollection()->setDefaultShortcuts(newTab, {Qt::CTRL + Qt::Key_T, QKeySequence::AddTab});
+    actionCollection()->setDefaultShortcuts(newTab, {Qt::CTRL + Qt::Key_T, Qt::CTRL + Qt::SHIFT + Qt::Key_N});
     connect(newTab, &QAction::triggered, this, static_cast<void(DolphinMainWindow::*)()>(&DolphinMainWindow::openNewActivatedTab));
 
     QAction* closeTab = KStandardAction::close(
@@ -1261,6 +1224,8 @@ void DolphinMainWindow::setupDockWidgets()
     infoDock->setLocked(lock);
     infoDock->setObjectName(QStringLiteral("infoDock"));
     infoDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
+
+#ifdef HAVE_BALOO
     InformationPanel* infoPanel = new InformationPanel(infoDock);
     infoPanel->setCustomContextMenuActions({lockLayoutAction});
     connect(infoPanel, &InformationPanel::urlActivated, this, &DolphinMainWindow::handleUrl);
@@ -1276,6 +1241,7 @@ void DolphinMainWindow::setupDockWidgets()
             infoPanel, &InformationPanel::setSelection);
     connect(this, &DolphinMainWindow::requestItemInfo,
             infoPanel, &InformationPanel::requestDelayedItemInfo);
+#endif
 
     // Setup "Folders"
     DolphinDockWidget* foldersDock = new DolphinDockWidget(i18nc("@title:window", "Folders"));
@@ -1372,7 +1338,9 @@ void DolphinMainWindow::setupDockWidgets()
     panelsMenu->setDelayed(false);
     const KActionCollection* ac = actionCollection();
     panelsMenu->addAction(ac->action(QStringLiteral("show_places_panel")));
+#ifdef HAVE_BALOO
     panelsMenu->addAction(ac->action(QStringLiteral("show_information_panel")));
+#endif
     panelsMenu->addAction(ac->action(QStringLiteral("show_folders_panel")));
     panelsMenu->addAction(ac->action(QStringLiteral("show_terminal_panel")));
     panelsMenu->addSeparator();
@@ -1496,7 +1464,7 @@ void DolphinMainWindow::refreshViews()
         const bool splitView = GeneralSettings::splitView();
         m_tabWidget->currentTabPage()->setSplitViewEnabled(splitView);
         updateSplitAction();
-        setUrlAsCaption(activeViewContainer()->url());
+        updateWindowTitle();
     }
 
     emit settingsChanged();