mirror of
https://bitbucket.org/smil3y/kdelibs.git
synced 2025-02-23 18:32:49 +00:00
kdeui: implement save for KNotificationConfigWidget
another rewrite of bits dating back to 1997 done: https://ibb.co/5GKtQT1 while working on it the idea of writing custom widget that will act as checkbox but look something like a slider and using that instead of tables popped up (the widget design itself is not new but using the widget in new UIs will be). Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
parent
5d5087023c
commit
031cc87d96
2 changed files with 45 additions and 30 deletions
|
@ -62,12 +62,15 @@ private:
|
|||
K_GLOBAL_STATIC(KNotificationManager, kNotificationManager);
|
||||
|
||||
KNotificationManager::KNotificationManager()
|
||||
: m_config(KGlobal::mainComponent().componentName() + ".notifyrc", KConfig::NoGlobals),
|
||||
: m_config("knotificationrc", KConfig::NoGlobals),
|
||||
m_notificationsiface(nullptr),
|
||||
m_kaudioplayeriface(nullptr)
|
||||
{
|
||||
// TODO: config watch
|
||||
const QStringList notifyconfigs = KGlobal::dirs()->findAllResources("config", "notifications/*.notifyrc");
|
||||
m_config.addConfigSources(notifyconfigs);
|
||||
if (!notifyconfigs.isEmpty()) {
|
||||
m_config.addConfigSources(notifyconfigs);
|
||||
}
|
||||
// qDebug() << Q_FUNC_INFO << notifyconfigs;
|
||||
}
|
||||
|
||||
|
|
|
@ -30,12 +30,10 @@ class KNotificationConfigWidgetPrivate
|
|||
{
|
||||
public:
|
||||
KNotificationConfigWidgetPrivate(KNotificationConfigWidget *q);
|
||||
~KNotificationConfigWidgetPrivate();
|
||||
|
||||
void _k_slotItemChanged(QTreeWidgetItem *item, int column);
|
||||
|
||||
KNotificationConfigWidget* parent;
|
||||
QMap<QString,KConfig*> configs;
|
||||
QVBoxLayout* layout;
|
||||
QTreeWidget* treewidget;
|
||||
QString enabledi18n;
|
||||
|
@ -43,6 +41,7 @@ public:
|
|||
QString popuptooltipi18n;
|
||||
QString soundtooltipi18n;
|
||||
QString taskbartooltipi18n;
|
||||
QMap<QString,QStringList> notificationchanges;
|
||||
};
|
||||
|
||||
KNotificationConfigWidgetPrivate::KNotificationConfigWidgetPrivate(KNotificationConfigWidget *q)
|
||||
|
@ -58,23 +57,31 @@ KNotificationConfigWidgetPrivate::KNotificationConfigWidgetPrivate(KNotification
|
|||
taskbartooltipi18n = i18n("Mark tasbar entry");
|
||||
}
|
||||
|
||||
KNotificationConfigWidgetPrivate::~KNotificationConfigWidgetPrivate()
|
||||
{
|
||||
QMutableMapIterator<QString,KConfig*> iter(configs);
|
||||
while (iter.hasNext()) {
|
||||
iter.next();
|
||||
KConfig* config = iter.value();
|
||||
delete config;
|
||||
iter.remove();
|
||||
}
|
||||
}
|
||||
|
||||
void KNotificationConfigWidgetPrivate::_k_slotItemChanged(QTreeWidgetItem *item, int column)
|
||||
{
|
||||
emit parent->changed(true);
|
||||
if (item && item->flags() & Qt::ItemIsUserCheckable) {
|
||||
if (!item) {
|
||||
kWarning() << "null tree item";
|
||||
return;
|
||||
}
|
||||
if (item->flags() & Qt::ItemIsUserCheckable) {
|
||||
item->setText(column, item->checkState(column) == Qt::Checked ? enabledi18n : disabledi18n);
|
||||
}
|
||||
const QString eventgroup = item->data(0, Qt::UserRole).toString();
|
||||
QStringList eventactions;
|
||||
const bool eventpopup = (item->checkState(1) == Qt::Checked);
|
||||
const bool eventsound = (item->checkState(2) == Qt::Checked);
|
||||
const bool eventtaskbar = (item->checkState(3) == Qt::Checked);
|
||||
if (eventpopup) {
|
||||
eventactions.append(QString::fromLatin1("Popup"));
|
||||
}
|
||||
if (eventsound) {
|
||||
eventactions.append(QString::fromLatin1("Sound"));
|
||||
}
|
||||
if (eventtaskbar) {
|
||||
eventactions.append(QString::fromLatin1("Taskbar"));
|
||||
}
|
||||
notificationchanges.insert(eventgroup, eventactions);
|
||||
}
|
||||
|
||||
|
||||
|
@ -110,7 +117,15 @@ KNotificationConfigWidget::~KNotificationConfigWidget()
|
|||
|
||||
void KNotificationConfigWidget::save()
|
||||
{
|
||||
// TODO:
|
||||
KConfig notificationsconfig("knotificationrc", KConfig::NoGlobals);
|
||||
QMapIterator<QString,QStringList> iter(d->notificationchanges);
|
||||
while (iter.hasNext()) {
|
||||
iter.next();
|
||||
KConfigGroup eventgroupconfig(¬ificationsconfig, iter.key());
|
||||
eventgroupconfig.writeEntry("Actions", iter.value());
|
||||
}
|
||||
notificationsconfig.sync();
|
||||
d->notificationchanges.clear();
|
||||
emit changed(false);
|
||||
}
|
||||
|
||||
|
@ -118,23 +133,20 @@ void KNotificationConfigWidget::setNotification(const QString ¬ification)
|
|||
{
|
||||
d->treewidget->clear();
|
||||
|
||||
KConfig* notificationconfig = d->configs.value(notification, nullptr);
|
||||
if (!notificationconfig) {
|
||||
const QString notifyconfig = KStandardDirs::locate("config", "notifications/" + notification+ ".notifyrc");
|
||||
if (notifyconfig.isEmpty()) {
|
||||
kWarning() << "invalid notification" << notification;
|
||||
return;
|
||||
}
|
||||
notificationconfig = new KConfig(notifyconfig, KConfig::NoGlobals);
|
||||
d->configs.insert(notification, notificationconfig);
|
||||
const QString notifyconfig = KStandardDirs::locate("config", "notifications/" + notification+ ".notifyrc");
|
||||
if (notifyconfig.isEmpty()) {
|
||||
kWarning() << "invalid notification" << notification;
|
||||
return;
|
||||
}
|
||||
KConfigGroup globalgroupconfig(notificationconfig, notification);
|
||||
KConfig notificationconfig("knotificationrc", KConfig::NoGlobals);
|
||||
notificationconfig.addConfigSources(QStringList() << notifyconfig);
|
||||
KConfigGroup globalgroupconfig(¬ificationconfig, notification);
|
||||
KIcon soundicon = KIcon("media-playback-start");
|
||||
foreach (const QString &eventgroup, notificationconfig->groupList()) {
|
||||
if (!eventgroup.contains(QLatin1Char('/'))) {
|
||||
foreach (const QString &eventgroup, notificationconfig.groupList()) {
|
||||
if (!eventgroup.startsWith(notification + QLatin1Char('/'))) {
|
||||
continue;
|
||||
}
|
||||
KConfigGroup eventgroupconfig(notificationconfig, eventgroup);
|
||||
KConfigGroup eventgroupconfig(¬ificationconfig, eventgroup);
|
||||
QString eventtext = eventgroupconfig.readEntry("Name");
|
||||
if (eventtext.isEmpty()) {
|
||||
eventtext = globalgroupconfig.readEntry("Name");
|
||||
|
|
Loading…
Add table
Reference in a new issue