Commit ed23d148 authored by Alexander Lohnau's avatar Alexander Lohnau 💬
Browse files

Expose new history/activity options in KCM

parent 064b0b42
......@@ -30,6 +30,8 @@ target_link_libraries(kcm_plasmasearch
KF5::Runner
KF5::I18n
KF5::NewStuff
KF5::Activities
Qt5::DBus
Qt5::Widgets
)
......
......@@ -28,6 +28,9 @@
#include <KRunner/RunnerManager>
#include <KPluginSelector>
#include <KNS3/Button>
#include <KActivities/Info>
#include <KActivities/Consumer>
#include <QApplication>
#include <QDBusMessage>
#include <QDBusConnection>
......@@ -37,7 +40,10 @@
#include <QDialog>
#include <QPainter>
#include <QFormLayout>
#include <QFileInfo>
#include <QMenu>
#include <QAction>
#include <QToolButton>
#include "krunnersettings.h"
#include "krunnerdata.h"
......@@ -60,20 +66,21 @@ SearchConfigModule::SearchConfigModule(QWidget* parent, const QVariantList& args
}
QVBoxLayout *layout = new QVBoxLayout(this);
m_consumer = new KActivities::Consumer(this);
m_historyConfigGroup = KSharedConfig::openConfig(QStringLiteral("krunnerstaterc"), KConfig::NoGlobals,
QStandardPaths::GenericDataLocation)->group("PlasmaRunnerManager").group("History");
QHBoxLayout *headerLayout = new QHBoxLayout;
layout->addLayout(headerLayout);
QLabel *label = new QLabel(i18n("Enable or disable plugins (used in KRunner and Application Launcher)"));
m_clearHistoryButton = new QPushButton(i18n("Clear History"));
m_clearHistoryButton = new QToolButton(this);
m_clearHistoryButton->setIcon(QIcon::fromTheme(isRightToLeft() ? QStringLiteral("edit-clear-locationbar-ltr")
: QStringLiteral("edit-clear-locationbar-rtl")));
connect(m_clearHistoryButton, &QPushButton::clicked, this, [this] {
KConfigGroup generalConfig(m_config->group("General"));
generalConfig.deleteEntry("history", KConfig::Notify);
generalConfig.sync();
});
m_clearHistoryButton->setPopupMode(QToolButton::InstantPopup);
m_clearHistoryButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
connect(m_clearHistoryButton, &QPushButton::clicked, this, &SearchConfigModule::deleteAllHistory);
QHBoxLayout *configHeaderLayout = new QHBoxLayout;
QVBoxLayout *configHeaderLeft = new QVBoxLayout;
......@@ -96,6 +103,10 @@ SearchConfigModule::SearchConfigModule(QWidget* parent, const QVariantList& args
m_retainPriorSearch = new QCheckBox(i18n("Retain previous search"), this);
m_retainPriorSearch->setObjectName("kcfg_retainPriorSearch");
positionLayout->addRow(QString(), m_retainPriorSearch);
m_activityAware = new QCheckBox(i18n("Activity aware (previous search and history)"), this);
m_activityAware->setObjectName("kcfg_activityAware");
connect(m_activityAware, &QCheckBox::clicked, this, &SearchConfigModule::configureClearHistoryButton);
positionLayout->addRow(QString(), m_activityAware);
configHeaderLeft->addLayout(positionLayout);
configHeaderRight->setSizeConstraint(QLayout::SetNoConstraint);
......@@ -177,6 +188,7 @@ QT_WARNING_POP
if(!m_pluginID.isEmpty()){
m_pluginSelector->showConfiguration(m_pluginID);
}
configureClearHistoryButton();
}
......@@ -187,6 +199,22 @@ void SearchConfigModule::save()
KCModule::save();
// Combine & write history
if (!m_activityAware->isChecked()) {
if (!m_historyConfigGroup.hasKey(nullUuid)) {
QStringList activities = m_consumer->activities();
activities.removeOne(m_consumer->currentActivity());
QStringList newHistory = m_historyConfigGroup.readEntry(m_consumer->currentActivity(), QStringList());
for (const QString &activity : qAsConst(activities)) {
newHistory.append(m_historyConfigGroup.readEntry(activity, QStringList()));
}
newHistory.removeDuplicates();
m_historyConfigGroup.writeEntry(nullUuid, newHistory, KConfig::Notify);
m_historyConfigGroup.sync();
}
}
m_pluginSelector->save();
QDBusMessage message = QDBusMessage::createSignal(QStringLiteral("/krunnerrc"),
......@@ -207,6 +235,56 @@ void SearchConfigModule::defaults()
m_pluginSelector->defaults();
}
void SearchConfigModule::configureClearHistoryButton()
{
const QStringList activities = m_consumer->activities();
const QStringList historyKeys = m_historyConfigGroup.keyList();
if (m_activityAware->isChecked() && activities.length() > 1) {
auto *installMenu = new QMenu(m_clearHistoryButton);
QAction *all = installMenu->addAction(m_clearHistoryButton->icon(),
i18nc("delete history for all activities", "For all activities"));
installMenu->setEnabled(!historyKeys.isEmpty());
connect(all, &QAction::triggered, this, &SearchConfigModule::deleteAllHistory);
for (const auto &key : activities) {
KActivities::Info info(key);
QIcon icon;
const QString iconStr = info.icon();
if (iconStr.isEmpty()) {
icon = m_clearHistoryButton->icon();
} else if (QFileInfo::exists(iconStr)) {
icon = QIcon(iconStr);
} else {
icon = QIcon::fromTheme(iconStr);
}
QAction *singleActivity = installMenu->addAction(icon,
i18nc("delete history for this activity", "For activity \"%1\"", info.name()));
singleActivity->setEnabled(historyKeys.contains(key)); // Otherwise there would be nothing to delete
connect(singleActivity, &QAction::triggered, this, [this, key](){ deleteHistoryGroup(key); });
installMenu->addAction(singleActivity);
m_clearHistoryButton->setText(i18n("Clear History..."));
}
m_clearHistoryButton->setMenu(installMenu);
} else {
m_clearHistoryButton->setText(i18n("Clear History"));
m_clearHistoryButton->setMenu(nullptr);
m_clearHistoryButton->setEnabled(m_settings->historyEnabled() && !historyKeys.isEmpty());
}
}
void SearchConfigModule::deleteHistoryGroup(const QString &key)
{
m_historyConfigGroup.deleteEntry(key, KConfig::Notify);
m_historyConfigGroup.sync();
configureClearHistoryButton();
}
void SearchConfigModule::deleteAllHistory()
{
m_historyConfigGroup.deleteGroup(KConfig::Notify);
m_historyConfigGroup.sync();
configureClearHistoryButton();
}
void SearchConfigModule::updateUnmanagedState()
{
bool isNeedSave = false;
......
......@@ -23,11 +23,12 @@
#include <KCModule>
#include <KSharedConfig>
#include <KConfigGroup>
#include <QRadioButton>
#include <QCheckBox>
#include <QPushButton>
#include <QToolButton>
#include <KActivities/Consumer>
class KPluginSelector;
......@@ -50,6 +51,9 @@ public Q_SLOTS:
void save() override;
void defaults() override;
void updateUnmanagedState();
void configureClearHistoryButton();
void deleteHistoryGroup(const QString &key);
void deleteAllHistory();
private:
void setDefaultIndicatorVisible(QWidget *widget, bool visible);
......@@ -60,9 +64,13 @@ private:
QRadioButton *m_topPositioning;
QRadioButton *m_freeFloating;
QCheckBox *m_retainPriorSearch;
QPushButton *m_clearHistoryButton;
QCheckBox *m_activityAware;
QToolButton *m_clearHistoryButton;
QCheckBox *m_enableHistory;
KRunnerSettings *m_settings;
KActivities::Consumer *m_consumer;
KConfigGroup m_historyConfigGroup;
const QString nullUuid = QStringLiteral("00000000-0000-0000-0000-000000000000");
};
#endif
......@@ -17,5 +17,9 @@
<label></label>
<default>true</default>
</entry>
<entry name="activityAware" key="ActivityAware" type="Bool">
<label></label>
<default>true</default>
</entry>
</group>
</kcfg>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment