#include <KJobWidgets>
#include <KLocalizedString>
#include <KMessageBox>
-#include <KMoreToolsMenuFactory>
#include <KProtocolInfo>
#include <KProtocolManager>
#include <KShell>
#include <QStandardPaths>
#include <QTimer>
#include <QToolButton>
+#include <QtConcurrentRun>
#include <algorithm>
, m_tearDownFromPlacesRequested(false)
, m_backAction(nullptr)
, m_forwardAction(nullptr)
+ , m_sessionSaveTimer(nullptr)
+ , m_sessionSaveWatcher(nullptr)
+ , m_sessionSaveScheduled(false)
+ , m_splitViewAction(nullptr)
+ , m_splitViewMenuAction(nullptr)
{
Q_INIT_RESOURCE(dolphin);
void DolphinMainWindow::slotSplitViewChanged()
{
m_tabWidget->currentTabPage()->setSplitViewEnabled(GeneralSettings::splitView(), WithAnimation);
- updateSplitAction();
+ updateSplitActions();
}
void DolphinMainWindow::openInNewTab()
}
}
- 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<void>::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<void>(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)
{
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();
QPointer<QAction> DolphinMainWindow::preferredSearchTool()
{
m_searchTools.clear();
- KMoreToolsMenuFactory("dolphin/search-tools").fillMenuFromGroupingNames(&m_searchTools, {"files-find"}, m_activeViewContainer->url());
- QList<QAction *> actions = m_searchTools.actions();
- if (actions.isEmpty()) {
- return nullptr;
- }
- QAction *action = actions.first();
- if (action->isSeparator()) {
+
+ KService::Ptr kfind = KService::serviceByDesktopName(QStringLiteral("org.kde.kfind"));
+
+ if (!kfind) {
return nullptr;
}
+
+ auto *action = new QAction(QIcon::fromTheme(kfind->icon()), kfind->name(), this);
+
+ connect(action, &QAction::triggered, this, [kfind] {
+ auto *job = new KIO::ApplicationLauncherJob(kfind);
+ job->start();
+ });
+
return action;
}
void DolphinMainWindow::openContextMenu(const QPoint &pos, const KFileItem &item, const KFileItemList &selectedItems, const QUrl &url)
{
QPointer<DolphinContextMenu> 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) {
"</para>"));
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
// setup 'View' menu
// (note that most of it is set up in DolphinViewActionHandler)
- QAction *split = actionCollection()->addAction(QStringLiteral("split_view"));
- split->setWhatsThis(xi18nc("@info:whatsthis find",
- "<para>This splits "
- "the folder view below into two autonomous views.</para><para>This "
- "way you can see two locations at once and move items between them "
- "quickly.</para>Click this again afterwards to recombine the views."));
- actionCollection()->setDefaultShortcut(split, Qt::Key_F3);
- connect(split, &QAction::triggered, this, &DolphinMainWindow::toggleSplitView);
+ m_splitViewAction = actionCollection()->add<KActionMenu>(QStringLiteral("split_view"));
+ m_splitViewMenuAction = actionCollection()->addAction(QStringLiteral("split_view_menu"));
+
+ m_splitViewAction->setWhatsThis(xi18nc("@info:whatsthis find",
+ "<para>This splits "
+ "the folder view below into two autonomous views.</para><para>This "
+ "way you can see two locations at once and move items between them "
+ "quickly.</para>Click this again afterwards to recombine the views."));
+ m_splitViewMenuAction->setWhatsThis(m_splitViewAction->whatsThis());
+
+ // only set it for the menu version
+ actionCollection()->setDefaultShortcut(m_splitViewMenuAction, Qt::Key_F3);
+
+ m_splitViewAction->setPopupMode(QToolButton::MenuButtonPopup);
+ connect(m_splitViewAction, &QAction::triggered, this, &DolphinMainWindow::toggleSplitView);
+ connect(m_splitViewMenuAction, &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);
+ m_splitViewAction->addAction(popoutSplit);
+ connect(popoutSplit, &QAction::triggered, this, &DolphinMainWindow::popoutSplitView);
QAction *stashSplit = actionCollection()->addAction(QStringLiteral("split_stash"));
actionCollection()->setDefaultShortcut(stashSplit, Qt::CTRL | Qt::Key_S);
connect(infoPanel, &InformationPanel::urlActivated, this, &DolphinMainWindow::handleUrl);
infoDock->setWidget(infoPanel);
- QAction *infoAction = infoDock->toggleViewAction();
- createPanelAction(QIcon::fromTheme(QStringLiteral("dialog-information")), Qt::Key_F11, infoAction, QStringLiteral("show_information_panel"));
+ createPanelAction(QIcon::fromTheme(QStringLiteral("dialog-information")), Qt::Key_F11, infoDock, QStringLiteral("show_information_panel"));
addDockWidget(Qt::RightDockWidgetArea, infoDock);
connect(this, &DolphinMainWindow::urlChanged, infoPanel, &InformationPanel::setUrl);
foldersPanel->setCustomContextMenuActions({lockLayoutAction});
foldersDock->setWidget(foldersPanel);
- QAction *foldersAction = foldersDock->toggleViewAction();
- createPanelAction(QIcon::fromTheme(QStringLiteral("folder")), Qt::Key_F7, foldersAction, QStringLiteral("show_folders_panel"));
+ createPanelAction(QIcon::fromTheme(QStringLiteral("folder")), Qt::Key_F7, foldersDock, QStringLiteral("show_folders_panel"));
addDockWidget(Qt::LeftDockWidgetArea, foldersDock);
connect(this, &DolphinMainWindow::urlChanged, foldersPanel, &FoldersPanel::setUrl);
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);
connect(terminalDock, &DolphinDockWidget::visibilityChanged, m_terminalPanel, &TerminalPanel::dockVisibilityChanged);
connect(terminalDock, &DolphinDockWidget::visibilityChanged, this, &DolphinMainWindow::slotTerminalPanelVisibilityChanged);
- QAction *terminalAction = terminalDock->toggleViewAction();
- createPanelAction(QIcon::fromTheme(QStringLiteral("dialog-scripts")), Qt::Key_F4, terminalAction, QStringLiteral("show_terminal_panel"));
+ createPanelAction(QIcon::fromTheme(QStringLiteral("dialog-scripts")), Qt::Key_F4, terminalDock, QStringLiteral("show_terminal_panel"));
addDockWidget(Qt::BottomDockWidgetArea, terminalDock);
connect(this, &DolphinMainWindow::urlChanged, m_terminalPanel, &TerminalPanel::setUrl);
m_placesPanel->setCustomContextMenuActions({lockLayoutAction});
placesDock->setWidget(m_placesPanel);
- QAction *placesAction = placesDock->toggleViewAction();
- createPanelAction(QIcon::fromTheme(QStringLiteral("compass")), Qt::Key_F9, placesAction, QStringLiteral("show_places_panel"));
+ createPanelAction(QIcon::fromTheme(QStringLiteral("compass")), Qt::Key_F9, placesDock, QStringLiteral("show_places_panel"));
addDockWidget(Qt::LeftDockWidgetArea, placesDock);
connect(m_placesPanel, &PlacesPanel::placeActivated, this, &DolphinMainWindow::slotPlaceActivated);
"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);
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());
});
}
QAction *toggleFilterBarAction = actionCollection()->action(QStringLiteral("toggle_filter"));
toggleFilterBarAction->setChecked(m_activeViewContainer->isFilterBarVisible());
- updateSplitAction();
+ updateSplitActions();
}
void DolphinMainWindow::updateGoActions()
updateWindowTitle();
}
- updateSplitAction();
+ updateSplitActions();
Q_EMIT settingsChanged();
}
{
connect(container, &DolphinViewContainer::showFilterBarChanged, this, &DolphinMainWindow::updateFilterBarAction);
connect(container, &DolphinViewContainer::writeStateChanged, this, &DolphinMainWindow::slotWriteStateChanged);
+ slotWriteStateChanged(container->view()->isFolderWritable());
connect(container, &DolphinViewContainer::searchModeEnabledChanged, this, &DolphinMainWindow::updateSearchAction);
connect(container, &DolphinViewContainer::captionChanged, this, &DolphinMainWindow::updateWindowTitle);
connect(container, &DolphinViewContainer::tabRequested, this, &DolphinMainWindow::openNewTab);
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")));
+ m_splitViewAction->setText(i18nc("@action:intoolbar Close left view", "Close"));
+ m_splitViewAction->setToolTip(i18nc("@info", "Close left view"));
+ m_splitViewAction->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")));
+ m_splitViewAction->setText(i18nc("@action:intoolbar Close right view", "Close"));
+ m_splitViewAction->setToolTip(i18nc("@info", "Close right view"));
+ m_splitViewAction->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->setEnabled(true);
} else {
- splitAction->setText(i18nc("@action:intoolbar Split view", "Split"));
- splitAction->setToolTip(i18nc("@info", "Split view"));
- splitAction->setIcon(QIcon::fromTheme(QStringLiteral("view-right-new")));
+ m_splitViewAction->setText(i18nc("@action:intoolbar Split view", "Split"));
+ m_splitViewAction->setToolTip(i18nc("@info", "Split view"));
+ m_splitViewAction->setIcon(QIcon::fromTheme(QStringLiteral("view-right-new")));
+ popoutSplitAction->setText(i18nc("@action:intoolbar Move active split view to a new window", "Pop out"));
+ popoutSplitAction->setEnabled(false);
}
+
+ // Update state from toolbar action
+ m_splitViewMenuAction->setText(m_splitViewAction->text());
+ m_splitViewMenuAction->setToolTip(m_splitViewAction->toolTip());
+ m_splitViewMenuAction->setIcon(m_splitViewAction->icon());
}
void DolphinMainWindow::updateAllowedToolbarAreas()
return installed;
}
-void DolphinMainWindow::createPanelAction(const QIcon &icon, const QKeySequence &shortcut, QAction *dockAction, const QString &actionName)
+void DolphinMainWindow::createPanelAction(const QIcon &icon, const QKeySequence &shortcut, QDockWidget *dockWidget, const QString &actionName)
{
- QAction *panelAction = actionCollection()->addAction(actionName);
- panelAction->setCheckable(true);
- panelAction->setChecked(dockAction->isChecked());
- panelAction->setText(dockAction->text());
- panelAction->setIcon(icon);
+ auto dockAction = dockWidget->toggleViewAction();
dockAction->setIcon(icon);
dockAction->setEnabled(true);
+
+ QAction *panelAction = actionCollection()->addAction(actionName, dockAction);
actionCollection()->setDefaultShortcut(panelAction, shortcut);
- connect(panelAction, &QAction::triggered, dockAction, &QAction::trigger);
- connect(dockAction, &QAction::toggled, panelAction, &QAction::setChecked);
+ connect(panelAction, &QAction::toggled, dockWidget, &QWidget::setVisible);
}
// clang-format off
void DolphinMainWindow::setupWhatsThis()