X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/01e4f60a0931aba506b184d384a4e2f926b2233c..5acfb27760f3da1d4f794e820008f8a4c8ff7533:/src/dolphinmainwindow.cpp diff --git a/src/dolphinmainwindow.cpp b/src/dolphinmainwindow.cpp index e99788621..f7a761307 100644 --- a/src/dolphinmainwindow.cpp +++ b/src/dolphinmainwindow.cpp @@ -21,7 +21,6 @@ #include "dolphinmainwindow.h" -#include "dolphinapplication.h" #include "dolphindockwidget.h" #include "dolphincontextmenu.h" #include "dolphinnewfilemenu.h" @@ -46,48 +45,37 @@ #include "dolphin_generalsettings.h" -#include #include #include #include -#include -#include #include -#include -#include -#include #include -#include +#include #include -#include -#include #include -#include -#include +#include #include #include -#include #include #include -#include #include #include -#include #include #include #include -#include #include +#include -#include -#include -#include +#include +#include #include #include -#include #include #include #include +#include +#include +#include namespace { // Used for GeneralSettings::version() to determine whether @@ -137,8 +125,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))); + connect(m_tabWidget, SIGNAL(currentUrlChanged(QUrl)), + this, SLOT(setUrlAsCaption(QUrl))); setCentralWidget(m_tabWidget); setupActions(); @@ -181,14 +169,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) @@ -225,7 +213,7 @@ void DolphinMainWindow::pasteIntoFolder() m_activeViewContainer->view()->pasteIntoFolder(); } -void DolphinMainWindow::changeUrl(const KUrl& url) +void DolphinMainWindow::changeUrl(const QUrl &url) { if (!KProtocolManager::supportsListing(url)) { // The URL navigator only checks for validity, not @@ -243,7 +231,7 @@ void DolphinMainWindow::changeUrl(const KUrl& url) emit urlChanged(url); } -void DolphinMainWindow::slotTerminalDirectoryChanged(const KUrl& url) +void DolphinMainWindow::slotTerminalDirectoryChanged(const QUrl& url) { m_activeViewContainer->setAutoGrabFocus(false); changeUrl(url); @@ -273,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(); @@ -304,7 +287,7 @@ void DolphinMainWindow::updateFilterBarAction(bool show) void DolphinMainWindow::openNewMainWindow() { - KRun::run("dolphin %u", KUrl::List(), this); + KRun::run("dolphin %u", QList(), this); } void DolphinMainWindow::openNewActivatedTab() @@ -312,16 +295,11 @@ void DolphinMainWindow::openNewActivatedTab() m_tabWidget->openNewActivatedTab(); } -void DolphinMainWindow::openNewTab(const KUrl& url) +void DolphinMainWindow::openNewTab(const QUrl& url) { m_tabWidget->openNewTab(url); } -void DolphinMainWindow::openNewActivatedTab(const KUrl& url) -{ - m_tabWidget->openNewActivatedTab(url); -} - void DolphinMainWindow::openInNewTab() { const KFileItemList& list = m_activeViewContainer->view()->selectedItems(); @@ -329,7 +307,7 @@ void DolphinMainWindow::openInNewTab() openNewTab(m_activeViewContainer->url()); } else { foreach (const KFileItem& item, list) { - const KUrl& url = DolphinView::openItemAsFolderUrl(item); + const QUrl& url = DolphinView::openItemAsFolderUrl(item); if (!url.isEmpty()) { openNewTab(url); } @@ -339,7 +317,7 @@ void DolphinMainWindow::openInNewTab() void DolphinMainWindow::openInNewWindow() { - KUrl newWindowUrl; + QUrl newWindowUrl; const KFileItemList list = m_activeViewContainer->view()->selectedItems(); if (list.isEmpty()) { @@ -350,7 +328,7 @@ void DolphinMainWindow::openInNewWindow() } if (!newWindowUrl.isEmpty()) { - KRun::run("dolphin %u", QList() << newWindowUrl, this); + KRun::run("dolphin %u", {newWindowUrl}, this); } } @@ -368,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(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); @@ -507,6 +484,11 @@ void DolphinMainWindow::updatePasteAction() pasteAction->setText(pasteInfo.second); } +void DolphinMainWindow::slotDirectoryLoadingCompleted() +{ + updatePasteAction(); +} + void DolphinMainWindow::selectAll() { clearStatusBar(); @@ -628,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)); @@ -638,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)); @@ -648,15 +630,15 @@ 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) { - openNewTab(activeViewContainer()->url().upUrl()); + if (buttons == Qt::MiddleButton) { + openNewTab(KIO::upUrl(activeViewContainer()->url())); } } 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()); } } @@ -670,13 +652,13 @@ void DolphinMainWindow::compareFiles() return; } - KUrl urlA = items.at(0).url(); - KUrl urlB = items.at(1).url(); + QUrl urlA = items.at(0).url(); + QUrl urlB = items.at(1).url(); QString command("kompare -c \""); - command.append(urlA.pathOrUrl()); + command.append(urlA.toDisplayString(QUrl::PreferLocalFile)); command.append("\" \""); - command.append(urlB.pathOrUrl()); + command.append(urlB.toDisplayString(QUrl::PreferLocalFile)); command.append('\"'); KRun::runCommand(command, "Kompare", "kompare", this); } @@ -698,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. - KUrl 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()) { @@ -714,7 +699,7 @@ void DolphinMainWindow::editSettings() DolphinViewContainer* container = activeViewContainer(); container->view()->writeSettings(); - const KUrl url = container->url(); + const QUrl url = container->url(); DolphinSettingsDialog* settingsDialog = new DolphinSettingsDialog(url, this); connect(settingsDialog, &DolphinSettingsDialog::settingsChanged, this, &DolphinMainWindow::refreshViews); settingsDialog->setAttribute(Qt::WA_DeleteOnClose); @@ -725,7 +710,7 @@ void DolphinMainWindow::editSettings() } } -void DolphinMainWindow::handleUrl(const KUrl& url) +void DolphinMainWindow::handleUrl(const QUrl& url) { delete m_lastHandleUrlStatJob; m_lastHandleUrlStatJob = 0; @@ -750,7 +735,7 @@ void DolphinMainWindow::slotHandleUrlStatFinished(KJob* job) { m_lastHandleUrlStatJob = 0; const KIO::UDSEntry entry = static_cast(job)->statResult(); - const KUrl url = static_cast(job)->url(); + const QUrl url = static_cast(job)->url(); if (entry.isDir()) { activeViewContainer()->setUrl(url); } else { @@ -765,10 +750,10 @@ void DolphinMainWindow::slotWriteStateChanged(bool isFolderWritable) void DolphinMainWindow::openContextMenu(const QPoint& pos, const KFileItem& item, - const KUrl& url, + 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(); @@ -779,7 +764,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; } @@ -792,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() @@ -904,12 +892,7 @@ void DolphinMainWindow::slotControlButtonDeleted() m_updateToolBarTimer->start(); } -void DolphinMainWindow::slotPanelErrorMessage(const QString& error) -{ - activeViewContainer()->showMessage(error, DolphinViewContainer::Error); -} - -void DolphinMainWindow::slotPlaceActivated(const KUrl& url) +void DolphinMainWindow::slotPlaceActivated(const QUrl& url) { DolphinViewContainer* view = activeViewContainer(); @@ -952,7 +935,7 @@ void DolphinMainWindow::activeViewChanged(DolphinViewContainer* viewContainer) updateViewActions(); updateGoActions(); - const KUrl url = viewContainer->url(); + const QUrl url = viewContainer->url(); emit urlChanged(url); } @@ -964,20 +947,24 @@ void DolphinMainWindow::tabCountChanged(int count) actionCollection()->action("activate_prev_tab")->setEnabled(enableTabActions); } -void DolphinMainWindow::setUrlAsCaption(const KUrl& url) +void DolphinMainWindow::setUrlAsCaption(const QUrl& url) { QString caption; if (!url.isLocalFile()) { - caption.append(url.protocol() + " - "); - if (url.hasHost()) { + caption.append(url.scheme() + " - "); + if (!url.host().isEmpty()) { caption.append(url.host() + " - "); } } - 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() @@ -1000,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(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"); @@ -1079,8 +1066,8 @@ void DolphinMainWindow::setupActions() DolphinRecentTabsMenu* recentTabsMenu = new DolphinRecentTabsMenu(this); actionCollection()->addAction("closed_tabs", recentTabsMenu); - connect(m_tabWidget, SIGNAL(rememberClosedTab(KUrl,QByteArray)), - recentTabsMenu, SLOT(rememberClosedTab(KUrl,QByteArray))); + connect(m_tabWidget, SIGNAL(rememberClosedTab(QUrl,QByteArray)), + recentTabsMenu, SLOT(rememberClosedTab(QUrl,QByteArray))); connect(recentTabsMenu, SIGNAL(restoreClosedTab(QByteArray)), m_tabWidget, SLOT(restoreClosedTab(QByteArray))); connect(recentTabsMenu, SIGNAL(closedTabsCountChanged(uint)), @@ -1093,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()); @@ -1123,12 +1113,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"); @@ -1180,7 +1168,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); @@ -1201,7 +1189,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(); @@ -1215,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 @@ -1224,7 +1212,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); @@ -1255,7 +1243,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(); @@ -1264,10 +1252,10 @@ void DolphinMainWindow::setupDockWidgets() addDockWidget(Qt::LeftDockWidgetArea, placesDock); connect(placesPanel, &PlacesPanel::placeActivated, this, &DolphinMainWindow::slotPlaceActivated); - connect(placesPanel, SIGNAL(placeMiddleClicked(KUrl)), - this, SLOT(openNewTab(KUrl))); + 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, @@ -1335,8 +1323,8 @@ void DolphinMainWindow::updateViewActions() void DolphinMainWindow::updateGoActions() { QAction* goUpAction = actionCollection()->action(KStandardAction::name(KStandardAction::Up)); - const KUrl currentUrl = m_activeViewContainer->url(); - goUpAction->setEnabled(currentUrl.upUrl() != currentUrl); + const QUrl currentUrl = m_activeViewContainer->url(); + goUpAction->setEnabled(KIO::upUrl(currentUrl) != currentUrl); } void DolphinMainWindow::createControlButton() @@ -1428,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, @@ -1437,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(&DolphinMainWindow::goBack)); connect(view, &DolphinView::goForwardRequested,