#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)
{
Q_INIT_RESOURCE(dolphin);
}
}
- 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();
}
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
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);
"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());
});
}