X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/037d5db85bb0bd798d40c557d424c5c9b87457a8..4ed0b82b02aa787ba25bdc5a5e5a99037fdb6efa:/src/dolphinmainwindow.cpp diff --git a/src/dolphinmainwindow.cpp b/src/dolphinmainwindow.cpp index df04cee69..da6c5319d 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" @@ -49,13 +48,10 @@ #include #include #include -#include #include -#include #include -#include +#include #include -#include #include #include #include @@ -70,6 +66,7 @@ #include #include +#include #include #include #include @@ -78,6 +75,7 @@ #include #include #include +#include namespace { // Used for GeneralSettings::version() to determine whether @@ -263,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(); @@ -340,7 +333,7 @@ void DolphinMainWindow::openInNewWindow() } if (!newWindowUrl.isEmpty()) { - KRun::run("dolphin %u", QList() << newWindowUrl, this); + KRun::run("dolphin %u", {newWindowUrl}, this); } } @@ -358,17 +351,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); @@ -693,7 +685,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()) { @@ -763,7 +758,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(); @@ -774,7 +769,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; } @@ -787,7 +782,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() @@ -899,11 +897,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(); @@ -969,10 +962,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() @@ -995,7 +992,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"); @@ -1088,6 +1085,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()); @@ -1118,12 +1118,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"); @@ -1175,7 +1173,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); @@ -1196,7 +1194,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(); @@ -1210,7 +1208,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 @@ -1219,7 +1217,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); @@ -1250,7 +1248,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(); @@ -1262,7 +1260,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, @@ -1423,7 +1421,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,