]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/dolphinmainwindow.cpp
Simplify startup split view handling
[dolphin.git] / src / dolphinmainwindow.cpp
index f44d3236fc7fccc0b577090b6f42ce04e951ea22..f7a76130786d58900002c11a85cf33dc09da6faa 100644 (file)
@@ -21,7 +21,6 @@
 
 #include "dolphinmainwindow.h"
 
-#include "dolphinapplication.h"
 #include "dolphindockwidget.h"
 #include "dolphincontextmenu.h"
 #include "dolphinnewfilemenu.h"
 #include <KActionCollection>
 #include <KActionMenu>
 #include <KConfig>
-#include <kdeversion.h>
 #include <kdualaction.h>
-#include <KDialog>
 #include <KJobWidgets>
-#include <KLineEdit>
+#include <QLineEdit>
 #include <KToolBar>
-#include <KIO/NetAccess>
 #include <KIO/JobUiDelegate>
 #include <KLocalizedString>
 #include <KProtocolManager>
 #include <KFileItemListProperties>
 #include <KRun>
 #include <KShell>
-#include <kstatusbar.h>
 #include <KStandardAction>
 #include <KToggleAction>
 #include <KUrlNavigator>
 #include <KToolInvocation>
 #include <KUrlComboBox>
 
+#include <QApplication>
 #include <QMenuBar>
 #include <QClipboard>
 #include <QToolButton>
@@ -79,6 +75,7 @@
 #include <QPushButton>
 #include <QCloseEvent>
 #include <QShowEvent>
+#include <QDialog>
 
 namespace {
     // Used for GeneralSettings::version() to determine whether
@@ -172,14 +169,14 @@ DolphinMainWindow::~DolphinMainWindow()
 {
 }
 
-void DolphinMainWindow::openDirectories(const QList<QUrl>& dirs)
+void DolphinMainWindow::openDirectories(const QList<QUrl>& dirs, bool splitView)
 {
-    m_tabWidget->openDirectories(dirs);
+    m_tabWidget->openDirectories(dirs, splitView);
 }
 
-void DolphinMainWindow::openFiles(const QList<QUrl>& files)
+void DolphinMainWindow::openFiles(const QList<QUrl>& files, bool splitView)
 {
-    m_tabWidget->openFiles(files);
+    m_tabWidget->openFiles(files, splitView);
 }
 
 void DolphinMainWindow::showCommand(CommandType command)
@@ -264,11 +261,6 @@ void DolphinMainWindow::slotSelectionChanged(const KFileItemList& selection)
     emit selectionChanged(selection);
 }
 
-void DolphinMainWindow::slotRequestItemInfo(const KFileItem& item)
-{
-    emit requestItemInfo(item);
-}
-
 void DolphinMainWindow::updateHistory()
 {
     const KUrlNavigator* urlNavigator = m_activeViewContainer->urlNavigator();
@@ -308,11 +300,6 @@ void DolphinMainWindow::openNewTab(const QUrl& url)
     m_tabWidget->openNewTab(url);
 }
 
-void DolphinMainWindow::openNewActivatedTab(const QUrl& url)
-{
-    m_tabWidget->openNewActivatedTab(url);
-}
-
 void DolphinMainWindow::openInNewTab()
 {
     const KFileItemList& list = m_activeViewContainer->view()->selectedItems();
@@ -341,7 +328,7 @@ void DolphinMainWindow::openInNewWindow()
     }
 
     if (!newWindowUrl.isEmpty()) {
-        KRun::run("dolphin %u", QList<QUrl>() << newWindowUrl, this);
+        KRun::run("dolphin %u", {newWindowUrl}, this);
     }
 }
 
@@ -359,17 +346,16 @@ void DolphinMainWindow::closeEvent(QCloseEvent* event)
     // Find out if Dolphin is closed directly by the user or
     // by the session manager because the session is closed
     bool closedByUser = true;
-    DolphinApplication *application = qobject_cast<DolphinApplication*>(qApp);
-    if (application && application->sessionSaving()) {
+    if (qApp->isSessionRestored()) {
         closedByUser = false;
     }
 
     if (m_tabWidget->count() > 1 && GeneralSettings::confirmClosingMultipleTabs() && closedByUser) {
         // Ask the user if he really wants to quit and close all tabs.
         // Open a confirmation dialog with 3 buttons:
-        // KDialog::Yes    -> Quit
-        // KDialog::No     -> Close only the current tab
-        // KDialog::Cancel -> do nothing
+        // QDialogButtonBox::Yes    -> Quit
+        // QDialogButtonBox::No     -> Close only the current tab
+        // QDialogButtonBox::Cancel -> do nothing
         QDialog *dialog = new QDialog(this, Qt::Dialog);
         dialog->setWindowTitle(i18nc("@title:window", "Confirmation"));
         dialog->setModal(true);
@@ -498,6 +484,11 @@ void DolphinMainWindow::updatePasteAction()
     pasteAction->setText(pasteInfo.second);
 }
 
+void DolphinMainWindow::slotDirectoryLoadingCompleted()
+{
+    updatePasteAction();
+}
+
 void DolphinMainWindow::selectAll()
 {
     clearStatusBar();
@@ -619,7 +610,7 @@ void DolphinMainWindow::goHome()
 void DolphinMainWindow::goBack(Qt::MouseButtons buttons)
 {
     // The default case (left button pressed) is handled in goBack().
-    if (buttons == Qt::MidButton) {
+    if (buttons == Qt::MiddleButton) {
         KUrlNavigator* urlNavigator = activeViewContainer()->urlNavigator();
         const int index = urlNavigator->historyIndex() + 1;
         openNewTab(urlNavigator->locationUrl(index));
@@ -629,7 +620,7 @@ void DolphinMainWindow::goBack(Qt::MouseButtons buttons)
 void DolphinMainWindow::goForward(Qt::MouseButtons buttons)
 {
     // The default case (left button pressed) is handled in goForward().
-    if (buttons == Qt::MidButton) {
+    if (buttons == Qt::MiddleButton) {
         KUrlNavigator* urlNavigator = activeViewContainer()->urlNavigator();
         const int index = urlNavigator->historyIndex() - 1;
         openNewTab(urlNavigator->locationUrl(index));
@@ -639,7 +630,7 @@ void DolphinMainWindow::goForward(Qt::MouseButtons buttons)
 void DolphinMainWindow::goUp(Qt::MouseButtons buttons)
 {
     // The default case (left button pressed) is handled in goUp().
-    if (buttons == Qt::MidButton) {
+    if (buttons == Qt::MiddleButton) {
         openNewTab(KIO::upUrl(activeViewContainer()->url()));
     }
 }
@@ -647,7 +638,7 @@ void DolphinMainWindow::goUp(Qt::MouseButtons buttons)
 void DolphinMainWindow::goHome(Qt::MouseButtons buttons)
 {
     // The default case (left button pressed) is handled in goHome().
-    if (buttons == Qt::MidButton) {
+    if (buttons == Qt::MiddleButton) {
         openNewTab(GeneralSettings::self()->homeUrl());
     }
 }
@@ -689,7 +680,10 @@ void DolphinMainWindow::openTerminal()
 
     // If the given directory is not local, it can still be the URL of an
     // ioslave using UDS_LOCAL_PATH which to be converted first.
-    QUrl url = KIO::NetAccess::mostLocalUrl(m_activeViewContainer->url(), this);
+    KIO::StatJob* statJob = KIO::mostLocalUrl(m_activeViewContainer->url());
+    KJobWidgets::setWindow(statJob, this);
+    statJob->exec();
+    QUrl url = statJob->mostLocalUrl();
 
     //If the URL is local after the above conversion, set the directory.
     if (url.isLocalFile()) {
@@ -759,7 +753,7 @@ void DolphinMainWindow::openContextMenu(const QPoint& pos,
                                         const QUrl& url,
                                         const QList<QAction*>& customActions)
 {
-    QWeakPointer<DolphinContextMenu> contextMenu = new DolphinContextMenu(this, pos, item, url);
+    QPointer<DolphinContextMenu> contextMenu = new DolphinContextMenu(this, pos, item, url);
     contextMenu.data()->setCustomActions(customActions);
     const DolphinContextMenu::Command command = contextMenu.data()->open();
 
@@ -770,7 +764,7 @@ void DolphinMainWindow::openContextMenu(const QPoint& pos,
 
     case DolphinContextMenu::OpenParentFolderInNewWindow: {
 
-        KRun::run("dolphin %u", QList<QUrl>() << KIO::upUrl(item.url()), this);
+        KRun::run("dolphin %u", {KIO::upUrl(item.url())}, this);
         break;
     }
 
@@ -783,7 +777,10 @@ void DolphinMainWindow::openContextMenu(const QPoint& pos,
         break;
     }
 
-    delete contextMenu.data();
+    // Delete the menu, unless it has been deleted in its own nested event loop already.
+    if (contextMenu) {
+        contextMenu->deleteLater();
+    }
 }
 
 void DolphinMainWindow::updateControlMenu()
@@ -895,11 +892,6 @@ void DolphinMainWindow::slotControlButtonDeleted()
     m_updateToolBarTimer->start();
 }
 
-void DolphinMainWindow::slotPanelErrorMessage(const QString& error)
-{
-    activeViewContainer()->showMessage(error, DolphinViewContainer::Error);
-}
-
 void DolphinMainWindow::slotPlaceActivated(const QUrl& url)
 {
     DolphinViewContainer* view = activeViewContainer();
@@ -965,10 +957,14 @@ void DolphinMainWindow::setUrlAsCaption(const QUrl& url)
         }
     }
 
-    const QString fileName = url.fileName().isEmpty() ? "/" : url.fileName();
+    QString fileName = url.adjusted(QUrl::StripTrailingSlash).fileName();
+    if (fileName.isEmpty()) {
+        fileName = '/';
+    }
+
     caption.append(fileName);
 
-    setCaption(caption);
+    setWindowTitle(caption);
 }
 
 void DolphinMainWindow::setupActions()
@@ -991,7 +987,7 @@ void DolphinMainWindow::setupActions()
     QAction* newTab = actionCollection()->addAction("new_tab");
     newTab->setIcon(QIcon::fromTheme("tab-new"));
     newTab->setText(i18nc("@action:inmenu File", "New Tab"));
-    actionCollection()->setDefaultShortcuts(newTab, QList<QKeySequence>() << QKeySequence(Qt::CTRL | Qt::Key_T) << QKeySequence(Qt::CTRL | Qt::SHIFT | Qt::Key_N));
+    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 = actionCollection()->addAction("close_tab");
@@ -1084,6 +1080,9 @@ void DolphinMainWindow::setupActions()
     undoCloseTab->setEnabled(false);
     connect(undoCloseTab, SIGNAL(triggered()), recentTabsMenu, SLOT(undoCloseTab()));
 
+    auto undoAction = actionCollection()->action(KStandardAction::name(KStandardAction::Undo));
+    undoAction->setEnabled(false); // undo should be disabled by default
+
     KStandardAction::forward(this, SLOT(goForward()), actionCollection());
     KStandardAction::up(this, SLOT(goUp()), actionCollection());
     KStandardAction::home(this, SLOT(goHome()), actionCollection());
@@ -1114,12 +1113,10 @@ void DolphinMainWindow::setupActions()
     KStandardAction::preferences(this, SLOT(editSettings()), actionCollection());
 
     // not in menu actions
-    QList<QKeySequence> nextTabKeys;
-    nextTabKeys.append(KStandardShortcut::tabNext().first()); //TODO: is this correct
+    QList<QKeySequence> nextTabKeys = KStandardShortcut::tabNext();
     nextTabKeys.append(QKeySequence(Qt::CTRL | Qt::Key_Tab));
 
-    QList<QKeySequence> prevTabKeys;
-    prevTabKeys.append(KStandardShortcut::tabPrev().first()); //TODO: is this correct
+    QList<QKeySequence> prevTabKeys = KStandardShortcut::tabPrev();
     prevTabKeys.append(QKeySequence(Qt::CTRL | Qt::SHIFT | Qt::Key_Tab));
 
     QAction* activateNextTab = actionCollection()->addAction("activate_next_tab");
@@ -1171,7 +1168,7 @@ void DolphinMainWindow::setupDockWidgets()
     infoDock->setObjectName("infoDock");
     infoDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
     InformationPanel* infoPanel = new InformationPanel(infoDock);
-    infoPanel->setCustomContextMenuActions(QList<QAction*>() << lockLayoutAction);
+    infoPanel->setCustomContextMenuActions({lockLayoutAction});
     connect(infoPanel, &InformationPanel::urlActivated, this, &DolphinMainWindow::handleUrl);
     infoDock->setWidget(infoPanel);
 
@@ -1192,7 +1189,7 @@ void DolphinMainWindow::setupDockWidgets()
     foldersDock->setObjectName("foldersDock");
     foldersDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
     FoldersPanel* foldersPanel = new FoldersPanel(foldersDock);
-    foldersPanel->setCustomContextMenuActions(QList<QAction*>() << lockLayoutAction);
+    foldersPanel->setCustomContextMenuActions({lockLayoutAction});
     foldersDock->setWidget(foldersPanel);
 
     QAction* foldersAction = foldersDock->toggleViewAction();
@@ -1206,7 +1203,7 @@ void DolphinMainWindow::setupDockWidgets()
     connect(foldersPanel, &FoldersPanel::folderMiddleClicked,
             this, &DolphinMainWindow::openNewTab);
     connect(foldersPanel, &FoldersPanel::errorMessage,
-            this, &DolphinMainWindow::slotPanelErrorMessage);
+            this, &DolphinMainWindow::showErrorMessage);
 
     // Setup "Terminal"
 #ifndef Q_OS_WIN
@@ -1215,7 +1212,7 @@ void DolphinMainWindow::setupDockWidgets()
     terminalDock->setObjectName("terminalDock");
     terminalDock->setAllowedAreas(Qt::TopDockWidgetArea | Qt::BottomDockWidgetArea);
     TerminalPanel* terminalPanel = new TerminalPanel(terminalDock);
-    terminalPanel->setCustomContextMenuActions(QList<QAction*>() << lockLayoutAction);
+    terminalPanel->setCustomContextMenuActions({lockLayoutAction});
     terminalDock->setWidget(terminalPanel);
 
     connect(terminalPanel, &TerminalPanel::hideTerminalPanel, terminalDock, &DolphinDockWidget::hide);
@@ -1246,7 +1243,7 @@ void DolphinMainWindow::setupDockWidgets()
     placesDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
 
     PlacesPanel* placesPanel = new PlacesPanel(placesDock);
-    placesPanel->setCustomContextMenuActions(QList<QAction*>() << lockLayoutAction);
+    placesPanel->setCustomContextMenuActions({lockLayoutAction});
     placesDock->setWidget(placesPanel);
 
     QAction* placesAction = placesDock->toggleViewAction();
@@ -1258,7 +1255,7 @@ void DolphinMainWindow::setupDockWidgets()
     connect(placesPanel, SIGNAL(placeMiddleClicked(QUrl)),
             this, SLOT(openNewTab(QUrl)));
     connect(placesPanel, &PlacesPanel::errorMessage,
-            this, &DolphinMainWindow::slotPanelErrorMessage);
+            this, &DolphinMainWindow::showErrorMessage);
     connect(this, &DolphinMainWindow::urlChanged,
             placesPanel, &PlacesPanel::setUrl);
     connect(placesDock, &DolphinDockWidget::visibilityChanged,
@@ -1419,7 +1416,7 @@ void DolphinMainWindow::connectViewSignals(DolphinViewContainer* container)
     connect(view, &DolphinView::selectionChanged,
             this, &DolphinMainWindow::slotSelectionChanged);
     connect(view, &DolphinView::requestItemInfo,
-            this, &DolphinMainWindow::slotRequestItemInfo);
+            this, &DolphinMainWindow::requestItemInfo);
     connect(view, &DolphinView::tabRequested,
             this, &DolphinMainWindow::openNewTab);
     connect(view, &DolphinView::requestContextMenu,
@@ -1428,6 +1425,8 @@ void DolphinMainWindow::connectViewSignals(DolphinViewContainer* container)
             this, &DolphinMainWindow::enableStopAction);
     connect(view, &DolphinView::directoryLoadingCompleted,
             this, &DolphinMainWindow::disableStopAction);
+    connect(view, &DolphinView::directoryLoadingCompleted,
+            this, &DolphinMainWindow::slotDirectoryLoadingCompleted);
     connect(view, &DolphinView::goBackRequested,
             this, static_cast<void(DolphinMainWindow::*)()>(&DolphinMainWindow::goBack));
     connect(view, &DolphinView::goForwardRequested,