X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/2cd3d58eec5695899c26ca66a631fb79867b6584..20dafcb1018ca8690288bbd857f58bcc3e0aa040:/src/dolphinmainwindow.cpp diff --git a/src/dolphinmainwindow.cpp b/src/dolphinmainwindow.cpp index 635121062..4a327182e 100644 --- a/src/dolphinmainwindow.cpp +++ b/src/dolphinmainwindow.cpp @@ -79,6 +79,7 @@ #include #include #include +#include #include @@ -114,6 +115,9 @@ DolphinMainWindow::DolphinMainWindow() , m_tearDownFromPlacesRequested(false) , m_backAction(nullptr) , m_forwardAction(nullptr) + , m_sessionSaveTimer(nullptr) + , m_sessionSaveWatcher(nullptr) + , m_sessionSaveScheduled(false) { Q_INIT_RESOURCE(dolphin); @@ -465,7 +469,7 @@ void DolphinMainWindow::openNewWindow(const QUrl &url) void DolphinMainWindow::slotSplitViewChanged() { m_tabWidget->currentTabPage()->setSplitViewEnabled(GeneralSettings::splitView(), WithAnimation); - updateSplitAction(); + updateSplitActions(); } void DolphinMainWindow::openInNewTab() @@ -676,18 +680,74 @@ void DolphinMainWindow::closeEvent(QCloseEvent *event) } } - if (GeneralSettings::rememberOpenedTabs()) { + if (m_sessionSaveTimer && (m_sessionSaveTimer->isActive() || m_sessionSaveWatcher->isRunning())) { + const bool sessionSaveTimerActive = m_sessionSaveTimer->isActive(); + + m_sessionSaveTimer->stop(); + m_sessionSaveWatcher->disconnect(); + m_sessionSaveWatcher->waitForFinished(); + + if (sessionSaveTimerActive || m_sessionSaveScheduled) { + slotSaveSession(); + } + } + + GeneralSettings::setVersion(CurrentDolphinVersion); + GeneralSettings::self()->save(); + + KXmlGuiWindow::closeEvent(event); +} + +void DolphinMainWindow::slotSaveSession() +{ + m_sessionSaveScheduled = false; + + if (m_sessionSaveWatcher->isRunning()) { + // The previous session is still being saved - schedule another save. + m_sessionSaveWatcher->disconnect(); + connect(m_sessionSaveWatcher, &QFutureWatcher::finished, this, &DolphinMainWindow::slotSaveSession, Qt::SingleShotConnection); + m_sessionSaveScheduled = true; + } else if (!m_sessionSaveTimer->isActive()) { + // No point in saving the session if the timer is running (since it will save the session again when it times out). KConfigGui::setSessionConfig(QStringLiteral("dolphin"), QStringLiteral("dolphin")); KConfig *config = KConfigGui::sessionConfig(); saveGlobalProperties(config); savePropertiesInternal(config, 1); - config->sync(); + + auto future = QtConcurrent::run([config]() { + config->sync(); + }); + m_sessionSaveWatcher->setFuture(future); } +} - GeneralSettings::setVersion(CurrentDolphinVersion); - GeneralSettings::self()->save(); +void DolphinMainWindow::setSessionAutoSaveEnabled(bool enable) +{ + if (enable) { + if (!m_sessionSaveTimer) { + m_sessionSaveTimer = new QTimer(this); + m_sessionSaveWatcher = new QFutureWatcher(this); + m_sessionSaveTimer->setSingleShot(true); + m_sessionSaveTimer->setInterval(22000); - KXmlGuiWindow::closeEvent(event); + connect(m_sessionSaveTimer, &QTimer::timeout, this, &DolphinMainWindow::slotSaveSession); + } + + connect(m_tabWidget, &DolphinTabWidget::urlChanged, m_sessionSaveTimer, qOverload<>(&QTimer::start), Qt::UniqueConnection); + connect(m_tabWidget, &DolphinTabWidget::tabCountChanged, m_sessionSaveTimer, qOverload<>(&QTimer::start), Qt::UniqueConnection); + connect(m_tabWidget, &DolphinTabWidget::activeViewChanged, m_sessionSaveTimer, qOverload<>(&QTimer::start), Qt::UniqueConnection); + } else if (m_sessionSaveTimer) { + m_sessionSaveTimer->stop(); + m_sessionSaveWatcher->disconnect(); + m_sessionSaveScheduled = false; + + m_sessionSaveWatcher->waitForFinished(); + + m_sessionSaveTimer->deleteLater(); + m_sessionSaveWatcher->deleteLater(); + m_sessionSaveTimer = nullptr; + m_sessionSaveWatcher = nullptr; + } } void DolphinMainWindow::saveProperties(KConfigGroup &group) @@ -920,9 +980,20 @@ void DolphinMainWindow::toggleSplitView() { DolphinTabPage *tabPage = m_tabWidget->currentTabPage(); tabPage->setSplitViewEnabled(!tabPage->splitViewEnabled(), WithAnimation); + m_tabWidget->updateTabName(m_tabWidget->indexOf(tabPage)); updateViewActions(); } +void DolphinMainWindow::popoutSplitView() +{ + DolphinTabPage *tabPage = m_tabWidget->currentTabPage(); + if (!tabPage->splitViewEnabled()) + return; + openNewWindow((GeneralSettings::closeActiveSplitView() ? tabPage->activeViewContainer() : tabPage->inactiveViewContainer())->url()); + tabPage->setSplitViewEnabled(false, WithAnimation); + updateSplitActions(); +} + void DolphinMainWindow::toggleSplitStash() { DolphinTabPage *tabPage = m_tabWidget->currentTabPage(); @@ -1309,7 +1380,7 @@ void DolphinMainWindow::slotWriteStateChanged(bool isFolderWritable) void DolphinMainWindow::openContextMenu(const QPoint &pos, const KFileItem &item, const KFileItemList &selectedItems, const QUrl &url) { QPointer contextMenu = new DolphinContextMenu(this, item, selectedItems, url, &m_fileItemActions); - contextMenu.data()->exec(pos); + contextMenu->exec(pos); // Delete the menu, unless it has been deleted in its own nested event loop already. if (contextMenu) { @@ -1722,7 +1793,7 @@ void DolphinMainWindow::setupActions() "")); toggleSelectionModeAction->setIcon(QIcon::fromTheme(QStringLiteral("quickwizard"))); toggleSelectionModeAction->setCheckable(true); - actionCollection()->setDefaultShortcut(toggleSelectionModeAction, Qt::Key_Space ); + actionCollection()->setDefaultShortcut(toggleSelectionModeAction, Qt::Key_Space); connect(toggleSelectionModeAction, &QAction::triggered, this, &DolphinMainWindow::toggleSelectionMode); // A special version of the toggleSelectionModeAction for the toolbar that also contains a menu @@ -1768,6 +1839,14 @@ void DolphinMainWindow::setupActions() actionCollection()->setDefaultShortcut(split, Qt::Key_F3); connect(split, &QAction::triggered, this, &DolphinMainWindow::toggleSplitView); + QAction *popoutSplit = actionCollection()->addAction(QStringLiteral("popout_split_view")); + popoutSplit->setWhatsThis(xi18nc("@info:whatsthis", + "If the folder view has been split, this will pop the active folder " + "view out into a new window.")); + popoutSplit->setIcon(QIcon::fromTheme(QStringLiteral("window-new"))); + actionCollection()->setDefaultShortcut(popoutSplit, Qt::SHIFT | Qt::Key_F3); + connect(popoutSplit, &QAction::triggered, this, &DolphinMainWindow::popoutSplitView); + QAction *stashSplit = actionCollection()->addAction(QStringLiteral("split_stash")); actionCollection()->setDefaultShortcut(stashSplit, Qt::CTRL | Qt::Key_S); stashSplit->setText(i18nc("@action:intoolbar Stash", "Stash")); @@ -2139,6 +2218,7 @@ void DolphinMainWindow::setupDockWidgets() DolphinDockWidget *terminalDock = new DolphinDockWidget(i18nc("@title:window Shell terminal", "Terminal")); terminalDock->setLocked(lock); terminalDock->setObjectName(QStringLiteral("terminalDock")); + terminalDock->setContentsMargins(0, 0, 0, 0); m_terminalPanel = new TerminalPanel(terminalDock); m_terminalPanel->setCustomContextMenuActions({lockLayoutAction}); terminalDock->setWidget(m_terminalPanel); @@ -2220,7 +2300,7 @@ void DolphinMainWindow::setupDockWidgets() "all places in the places panel that have been hidden. They will " "appear semi-transparent unless you uncheck their hide property.")); - connect(actionShowAllPlaces, &QAction::triggered, this, [actionShowAllPlaces, this](bool checked) { + connect(actionShowAllPlaces, &QAction::triggered, this, [this](bool checked) { m_placesPanel->setShowAll(checked); }); connect(m_placesPanel, &PlacesPanel::allPlacesShownChanged, actionShowAllPlaces, &QAction::setChecked); @@ -2264,7 +2344,7 @@ void DolphinMainWindow::setupDockWidgets() panelsMenu->addAction(actionShowAllPlaces); panelsMenu->addAction(lockLayoutAction); - connect(panelsMenu->menu(), &QMenu::aboutToShow, this, [actionShowAllPlaces, this] { + connect(panelsMenu->menu(), &QMenu::aboutToShow, this, [actionShowAllPlaces] { actionShowAllPlaces->setEnabled(DolphinPlacesModelSingleton::instance().placesModel()->hiddenCount()); }); } @@ -2355,7 +2435,7 @@ void DolphinMainWindow::updateViewActions() QAction *toggleFilterBarAction = actionCollection()->action(QStringLiteral("toggle_filter")); toggleFilterBarAction->setChecked(m_activeViewContainer->isFilterBarVisible()); - updateSplitAction(); + updateSplitActions(); } void DolphinMainWindow::updateGoActions() @@ -2384,7 +2464,7 @@ void DolphinMainWindow::refreshViews() updateWindowTitle(); } - updateSplitAction(); + updateSplitActions(); Q_EMIT settingsChanged(); } @@ -2443,24 +2523,31 @@ void DolphinMainWindow::connectViewSignals(DolphinViewContainer *container) connect(navigator, &KUrlNavigator::newWindowRequested, this, &DolphinMainWindow::openNewWindow); } -void DolphinMainWindow::updateSplitAction() +void DolphinMainWindow::updateSplitActions() { QAction *splitAction = actionCollection()->action(QStringLiteral("split_view")); + QAction *popoutSplitAction = actionCollection()->action(QStringLiteral("popout_split_view")); const DolphinTabPage *tabPage = m_tabWidget->currentTabPage(); if (tabPage->splitViewEnabled()) { if (GeneralSettings::closeActiveSplitView() ? tabPage->primaryViewActive() : !tabPage->primaryViewActive()) { splitAction->setText(i18nc("@action:intoolbar Close left view", "Close")); splitAction->setToolTip(i18nc("@info", "Close left view")); splitAction->setIcon(QIcon::fromTheme(QStringLiteral("view-left-close"))); + popoutSplitAction->setText(i18nc("@action:intoolbar Move left split view to a new window", "Pop out")); + popoutSplitAction->setToolTip(i18nc("@info", "Move left split view to a new window")); } else { splitAction->setText(i18nc("@action:intoolbar Close right view", "Close")); splitAction->setToolTip(i18nc("@info", "Close right view")); splitAction->setIcon(QIcon::fromTheme(QStringLiteral("view-right-close"))); + popoutSplitAction->setText(i18nc("@action:intoolbar Move right split view to a new window", "Pop out")); + popoutSplitAction->setToolTip(i18nc("@info", "Move right split view to a new window")); } + popoutSplitAction->setVisible(true); } else { splitAction->setText(i18nc("@action:intoolbar Split view", "Split")); splitAction->setToolTip(i18nc("@info", "Split view")); splitAction->setIcon(QIcon::fromTheme(QStringLiteral("view-right-new"))); + popoutSplitAction->setVisible(false); } }