X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/fa988586bc923b33497cbc97aaac07fc93a4ca83..5dd5eaf08da4b7d11e53c90096c2ea0e6a19e840:/src/dolphinmainwindow.cpp diff --git a/src/dolphinmainwindow.cpp b/src/dolphinmainwindow.cpp index f44d3236f..1cde29ce2 100644 --- a/src/dolphinmainwindow.cpp +++ b/src/dolphinmainwindow.cpp @@ -21,7 +21,7 @@ #include "dolphinmainwindow.h" -#include "dolphinapplication.h" +#include "global.h" #include "dolphindockwidget.h" #include "dolphincontextmenu.h" #include "dolphinnewfilemenu.h" @@ -49,13 +49,10 @@ #include #include #include -#include #include -#include #include -#include +#include #include -#include #include #include #include @@ -64,13 +61,13 @@ #include #include #include -#include #include #include #include #include #include +#include #include #include #include @@ -79,6 +76,7 @@ #include #include #include +#include namespace { // Used for GeneralSettings::version() to determine whether @@ -172,14 +170,14 @@ DolphinMainWindow::~DolphinMainWindow() { } -void DolphinMainWindow::openDirectories(const QList& dirs) +void DolphinMainWindow::openDirectories(const QList& dirs, bool splitView) { - m_tabWidget->openDirectories(dirs); + m_tabWidget->openDirectories(dirs, splitView); } -void DolphinMainWindow::openFiles(const QList& files) +void DolphinMainWindow::openFiles(const QList& files, bool splitView) { - m_tabWidget->openFiles(files); + m_tabWidget->openFiles(files, splitView); } void DolphinMainWindow::showCommand(CommandType command) @@ -264,11 +262,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 +301,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 +329,7 @@ void DolphinMainWindow::openInNewWindow() } if (!newWindowUrl.isEmpty()) { - KRun::run("dolphin %u", QList() << newWindowUrl, this); + KRun::run("dolphin %u", {newWindowUrl}, this); } } @@ -359,17 +347,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(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 +485,11 @@ void DolphinMainWindow::updatePasteAction() pasteAction->setText(pasteInfo.second); } +void DolphinMainWindow::slotDirectoryLoadingCompleted() +{ + updatePasteAction(); +} + void DolphinMainWindow::selectAll() { clearStatusBar(); @@ -619,7 +611,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 +621,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 +631,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,8 +639,8 @@ 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) { - openNewTab(GeneralSettings::self()->homeUrl()); + if (buttons == Qt::MiddleButton) { + openNewTab(Dolphin::homeUrl()); } } @@ -689,7 +681,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 +754,7 @@ void DolphinMainWindow::openContextMenu(const QPoint& pos, const QUrl& url, const QList& customActions) { - QWeakPointer contextMenu = new DolphinContextMenu(this, pos, item, url); + QPointer contextMenu = new DolphinContextMenu(this, pos, item, url); contextMenu.data()->setCustomActions(customActions); const DolphinContextMenu::Command command = contextMenu.data()->open(); @@ -770,7 +765,7 @@ void DolphinMainWindow::openContextMenu(const QPoint& pos, case DolphinContextMenu::OpenParentFolderInNewWindow: { - KRun::run("dolphin %u", QList() << KIO::upUrl(item.url()), this); + KRun::run("dolphin %u", {KIO::upUrl(item.url())}, this); break; } @@ -783,7 +778,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 +893,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 +958,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 +988,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(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(&DolphinMainWindow::openNewActivatedTab)); QAction* closeTab = actionCollection()->addAction("close_tab"); @@ -1084,6 +1081,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 +1114,10 @@ void DolphinMainWindow::setupActions() KStandardAction::preferences(this, SLOT(editSettings()), actionCollection()); // not in menu actions - QList nextTabKeys; - nextTabKeys.append(KStandardShortcut::tabNext().first()); //TODO: is this correct + QList nextTabKeys = KStandardShortcut::tabNext(); nextTabKeys.append(QKeySequence(Qt::CTRL | Qt::Key_Tab)); - QList prevTabKeys; - prevTabKeys.append(KStandardShortcut::tabPrev().first()); //TODO: is this correct + QList prevTabKeys = KStandardShortcut::tabPrev(); prevTabKeys.append(QKeySequence(Qt::CTRL | Qt::SHIFT | Qt::Key_Tab)); QAction* activateNextTab = actionCollection()->addAction("activate_next_tab"); @@ -1171,7 +1169,7 @@ void DolphinMainWindow::setupDockWidgets() infoDock->setObjectName("infoDock"); infoDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea); InformationPanel* infoPanel = new InformationPanel(infoDock); - infoPanel->setCustomContextMenuActions(QList() << lockLayoutAction); + infoPanel->setCustomContextMenuActions({lockLayoutAction}); connect(infoPanel, &InformationPanel::urlActivated, this, &DolphinMainWindow::handleUrl); infoDock->setWidget(infoPanel); @@ -1192,7 +1190,7 @@ void DolphinMainWindow::setupDockWidgets() foldersDock->setObjectName("foldersDock"); foldersDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea); FoldersPanel* foldersPanel = new FoldersPanel(foldersDock); - foldersPanel->setCustomContextMenuActions(QList() << lockLayoutAction); + foldersPanel->setCustomContextMenuActions({lockLayoutAction}); foldersDock->setWidget(foldersPanel); QAction* foldersAction = foldersDock->toggleViewAction(); @@ -1206,7 +1204,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 +1213,7 @@ void DolphinMainWindow::setupDockWidgets() terminalDock->setObjectName("terminalDock"); terminalDock->setAllowedAreas(Qt::TopDockWidgetArea | Qt::BottomDockWidgetArea); TerminalPanel* terminalPanel = new TerminalPanel(terminalDock); - terminalPanel->setCustomContextMenuActions(QList() << lockLayoutAction); + terminalPanel->setCustomContextMenuActions({lockLayoutAction}); terminalDock->setWidget(terminalPanel); connect(terminalPanel, &TerminalPanel::hideTerminalPanel, terminalDock, &DolphinDockWidget::hide); @@ -1246,7 +1244,7 @@ void DolphinMainWindow::setupDockWidgets() placesDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea); PlacesPanel* placesPanel = new PlacesPanel(placesDock); - placesPanel->setCustomContextMenuActions(QList() << lockLayoutAction); + placesPanel->setCustomContextMenuActions({lockLayoutAction}); placesDock->setWidget(placesPanel); QAction* placesAction = placesDock->toggleViewAction(); @@ -1258,7 +1256,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 +1417,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 +1426,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(&DolphinMainWindow::goBack)); connect(view, &DolphinView::goForwardRequested,