Commit f210fb10 authored by Kai Uwe Broulik's avatar Kai Uwe Broulik 🍇

Remove traces of activities make removing auto-detected apps work

Activities stuff has been postponed from the initial release and might be
added at a later time.

Also, properly filter out duplicates between Gnome and auto-detected apps
parent bf2be2c7
......@@ -10,7 +10,6 @@ set(kcm_notifications_SRCS
add_library(kcm_notifications MODULE ${kcm_notifications_SRCS})
target_link_libraries(kcm_notifications
KF5::KCMUtils
KF5::Activities
KF5::CoreAddons
KF5::Declarative
KF5::GuiAddons
......
......@@ -28,8 +28,6 @@
#include <KLocalizedString>
#include <KPluginFactory>
#include <KActivities/ActivitiesModel>
#include <algorithm>
#include "sourcesmodel.h"
......@@ -44,22 +42,24 @@ KCMNotifications::KCMNotifications(QObject *parent, const QVariantList &args)
, m_sourcesModel(new SourcesModel(this))
, m_filteredModel(new FilterProxyModel(this))
, m_settings(new NotificationManager::Settings(this))
, m_activitiesModel(new KActivities::ActivitiesModel(this))
{
const char uri[] = "org.kde.private.kcms.notifications";
qmlRegisterUncreatableType<SourcesModel>(uri, 1, 0, "SourcesModel",
QStringLiteral("Cannot create instances of SourcesModel"));
qmlRegisterType<FilterProxyModel>();
qmlProtectModule(uri, 1);
qmlRegisterType<KActivities::ActivitiesModel>();
KAboutData *about = new KAboutData(QStringLiteral("kcm_notifications"), i18n("Notifications"),
QStringLiteral("5.0"), QString(), KAboutLicense::GPL);
about->addAuthor(i18n("Kai Uwe Broulik"), QString(), QStringLiteral("kde@privat.broulik.de"));
setAboutData(about);
m_filteredModel->setSourceModel(m_sourcesModel);
connect(m_sourcesModel, &SourcesModel::pendingDeletionsChanged, this, [this] {
setNeedsSave(true);
});
}
KCMNotifications::~KCMNotifications()
......@@ -82,11 +82,6 @@ NotificationManager::Settings *KCMNotifications::settings() const
return m_settings;
}
KActivities::ActivitiesModel *KCMNotifications::activitiesModel() const
{
return m_activitiesModel;
}
void KCMNotifications::load()
{
m_settings->load();
......@@ -98,6 +93,7 @@ void KCMNotifications::load()
void KCMNotifications::save()
{
processPendingDeletions();
m_settings->save();
//setNeedsSave(false);
}
......@@ -108,4 +104,15 @@ void KCMNotifications::defaults()
//setNeedsSave(true);
}
void KCMNotifications::processPendingDeletions()
{
const QStringList pendingDeletions = m_sourcesModel->pendingDeletions();
for (const QString &desktopEntry : pendingDeletions) {
m_settings->forgetKnownApplication(desktopEntry);
}
m_sourcesModel->removeItemsPendingDeletion();
}
#include "kcm.moc"
......@@ -32,10 +32,6 @@ namespace NotificationManager {
class Settings;
}
namespace KActivities {
class ActivitiesModel;
}
class KCMNotifications : public KQuickAddons::ConfigModule
{
Q_OBJECT
......@@ -45,8 +41,6 @@ class KCMNotifications : public KQuickAddons::ConfigModule
Q_PROPERTY(NotificationManager::Settings *settings READ settings CONSTANT)
Q_PROPERTY(KActivities::ActivitiesModel *activitiesModel READ activitiesModel CONSTANT)
public:
KCMNotifications(QObject *parent, const QVariantList &args);
~KCMNotifications() override;
......@@ -63,19 +57,17 @@ public:
NotificationManager::Settings *settings() const;
KActivities::ActivitiesModel *activitiesModel() const;
public Q_SLOTS:
void load() override;
void save() override;
void defaults() override;
private:
void processPendingDeletions();
SourcesModel *m_sourcesModel;
FilterProxyModel *m_filteredModel;
NotificationManager::Settings *m_settings;
KActivities::ActivitiesModel *m_activitiesModel;
};
......@@ -120,6 +120,7 @@ Kirigami.Page {
width: sourcesList.width
text: model.display
highlighted: ListView.isCurrentItem
opacity: model.pendingDeletion ? 0.6 : 1
onClicked: {
var idx = kcm.filteredModel.makePersistentModelIndex(index, 0);
kcm.filteredModel.setCurrentIndex(idx);
......@@ -132,6 +133,7 @@ Kirigami.Page {
Layout.preferredWidth: Kirigami.Units.iconSizes.small
Layout.preferredHeight: Kirigami.Units.iconSizes.small
source: model.decoration
enabled: !model.pendingDeletion
}
QtControls.Label {
......@@ -144,13 +146,15 @@ Kirigami.Page {
// FIXME alignment
QtControls.ToolButton {
Layout.topMargin: -sourceDelegate.topPadding
Layout.bottomMargin: -sourceDelegate.bottomPadding
Layout.preferredWidth: height
Layout.preferredHeight: Kirigami.Units.iconSizes.small
icon.name: "edit-delete"
opacity: 0.6
Layout.preferredWidth: Kirigami.Units.iconSizes.small + leftPadding + rightPadding
Layout.preferredHeight: Kirigami.Units.iconSizes.small + topPadding + bottomPadding
icon.name: model.pendingDeletion ? "edit-undo" : "edit-delete"
visible: model.removable
onClicked: model.pendingDeletion = !model.pendingDeletion
QtControls.ToolTip {
text: model.pendingDeletion ? i18n("Undo Remove") : i18n("Remove")
}
}
}
}
......
......@@ -80,7 +80,7 @@ QVariant SourcesModel::data(const QModelIndex &index, int role) const
return QVariant();
}
if (index.internalId()) {
if (index.internalId()) { // event
const auto &event = m_data.at(index.internalId() - 1).events.at(index.row());
switch (role) {
......@@ -109,6 +109,7 @@ QVariant SourcesModel::data(const QModelIndex &index, int role) const
case NotifyRcNameRole: return source.notifyRcName;
case DesktopEntryRole: return source.desktopEntry;
case RemovableRole: return source.removable;
case PendingDeletionRole: return source.pendingDeletion;
}
return QVariant();
......@@ -120,18 +121,32 @@ bool SourcesModel::setData(const QModelIndex &index, const QVariant &value, int
return false;
}
if (!index.internalId()) {
return false;
}
bool dirty = false;
auto &event = m_data[index.internalId() - 1].events[index.row()];
switch (role) {
case ActionsRole:
event.actions = value.toStringList();
dirty = true;
break;
if (index.internalId()) { // event
auto &event = m_data[index.internalId() - 1].events[index.row()];
switch (role) {
case ActionsRole: {
const QStringList newActions = value.toStringList();
if (event.actions != newActions) {
event.actions = newActions;
dirty = true;
}
break;
}
}
} else { // source
auto &source = m_data[index.row()];
switch (role) {
case PendingDeletionRole: {
const bool newPending = value.toBool();
if (source.pendingDeletion != newPending) {
source.pendingDeletion = newPending;
dirty = true;
}
emit pendingDeletionsChanged();
}
}
}
if (dirty) {
......@@ -182,7 +197,8 @@ QHash<int, QByteArray> SourcesModel::roleNames() const
{DesktopEntryRole, QByteArrayLiteral("desktopEntry")},
{EventIdRole, QByteArrayLiteral("eventId")},
{ActionsRole, QByteArrayLiteral("actions")},
{RemovableRole, QByteArrayLiteral("removable")}
{RemovableRole, QByteArrayLiteral("removable")},
{PendingDeletionRole, QByteArrayLiteral("pendingDeletion")}
};
}
......@@ -245,7 +261,8 @@ void SourcesModel::load()
desktopEntry,
{}, // events
config,
false // removable
false, // removable
false // pendingDeletion
};
QVector<EventData> events;
......@@ -301,9 +318,12 @@ void SourcesModel::load()
service->desktopEntryName(),
{},
nullptr,
false // removable
false, // removable
false // pendingDeletion
};
fdoAppsData.append(source);
desktopEntries.append(service->desktopEntryName());
}
const QStringList seenApps = KSharedConfig::openConfig(QStringLiteral("plasmanotifyrc"))->group("Applications").groupList();
......@@ -325,7 +345,8 @@ void SourcesModel::load()
service->desktopEntryName(),
{},
nullptr,
true // removable
true, // removable
false // pendingDeletion
};
fdoAppsData.append(source);
}
......@@ -343,3 +364,28 @@ void SourcesModel::load()
endResetModel();
}
QStringList SourcesModel::pendingDeletions() const
{
QStringList pendingDeletions;
for (const auto &item : m_data) {
if (item.pendingDeletion) {
// Only apps can be deleted so we can assume it has a desktopEntry
pendingDeletions.append(item.desktopEntry);
}
}
return pendingDeletions;
}
void SourcesModel::removeItemsPendingDeletion()
{
for (int i = m_data.count() - 1; i >= 0; --i) {
if (m_data.at(i).pendingDeletion) {
beginRemoveRows(QModelIndex(), i, i);
m_data.remove(i);
endRemoveRows();
}
}
}
......@@ -51,6 +51,7 @@ struct SourceData
KConfig *config; // KSharedConfig::Ptr?
bool removable; // for "observed" apps
bool pendingDeletion;
QString display() const
{
......@@ -73,7 +74,8 @@ public:
EventIdRole,
ActionsRole,
RemovableRole // for "observed" apps
RemovableRole, // for "observed" apps
PendingDeletionRole
};
enum Type {
......@@ -96,9 +98,13 @@ public:
QHash<int, QByteArray> roleNames() const override;
QStringList pendingDeletions() const;
void removeItemsPendingDeletion();
void load();
Q_SIGNALS:
void pendingDeletionsChanged();
private:
QVector<SourceData> m_data;
......
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