mirror of
https://bitbucket.org/smil3y/kdelibs.git
synced 2025-02-24 02:42:48 +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);
|
K_GLOBAL_STATIC(KNotificationManager, kNotificationManager);
|
||||||
|
|
||||||
KNotificationManager::KNotificationManager()
|
KNotificationManager::KNotificationManager()
|
||||||
: m_config(KGlobal::mainComponent().componentName() + ".notifyrc", KConfig::NoGlobals),
|
: m_config("knotificationrc", KConfig::NoGlobals),
|
||||||
m_notificationsiface(nullptr),
|
m_notificationsiface(nullptr),
|
||||||
m_kaudioplayeriface(nullptr)
|
m_kaudioplayeriface(nullptr)
|
||||||
{
|
{
|
||||||
|
// TODO: config watch
|
||||||
const QStringList notifyconfigs = KGlobal::dirs()->findAllResources("config", "notifications/*.notifyrc");
|
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;
|
// qDebug() << Q_FUNC_INFO << notifyconfigs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,12 +30,10 @@ class KNotificationConfigWidgetPrivate
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
KNotificationConfigWidgetPrivate(KNotificationConfigWidget *q);
|
KNotificationConfigWidgetPrivate(KNotificationConfigWidget *q);
|
||||||
~KNotificationConfigWidgetPrivate();
|
|
||||||
|
|
||||||
void _k_slotItemChanged(QTreeWidgetItem *item, int column);
|
void _k_slotItemChanged(QTreeWidgetItem *item, int column);
|
||||||
|
|
||||||
KNotificationConfigWidget* parent;
|
KNotificationConfigWidget* parent;
|
||||||
QMap<QString,KConfig*> configs;
|
|
||||||
QVBoxLayout* layout;
|
QVBoxLayout* layout;
|
||||||
QTreeWidget* treewidget;
|
QTreeWidget* treewidget;
|
||||||
QString enabledi18n;
|
QString enabledi18n;
|
||||||
|
@ -43,6 +41,7 @@ public:
|
||||||
QString popuptooltipi18n;
|
QString popuptooltipi18n;
|
||||||
QString soundtooltipi18n;
|
QString soundtooltipi18n;
|
||||||
QString taskbartooltipi18n;
|
QString taskbartooltipi18n;
|
||||||
|
QMap<QString,QStringList> notificationchanges;
|
||||||
};
|
};
|
||||||
|
|
||||||
KNotificationConfigWidgetPrivate::KNotificationConfigWidgetPrivate(KNotificationConfigWidget *q)
|
KNotificationConfigWidgetPrivate::KNotificationConfigWidgetPrivate(KNotificationConfigWidget *q)
|
||||||
|
@ -58,23 +57,31 @@ KNotificationConfigWidgetPrivate::KNotificationConfigWidgetPrivate(KNotification
|
||||||
taskbartooltipi18n = i18n("Mark tasbar entry");
|
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)
|
void KNotificationConfigWidgetPrivate::_k_slotItemChanged(QTreeWidgetItem *item, int column)
|
||||||
{
|
{
|
||||||
emit parent->changed(true);
|
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);
|
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()
|
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);
|
emit changed(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -118,23 +133,20 @@ void KNotificationConfigWidget::setNotification(const QString ¬ification)
|
||||||
{
|
{
|
||||||
d->treewidget->clear();
|
d->treewidget->clear();
|
||||||
|
|
||||||
KConfig* notificationconfig = d->configs.value(notification, nullptr);
|
const QString notifyconfig = KStandardDirs::locate("config", "notifications/" + notification+ ".notifyrc");
|
||||||
if (!notificationconfig) {
|
if (notifyconfig.isEmpty()) {
|
||||||
const QString notifyconfig = KStandardDirs::locate("config", "notifications/" + notification+ ".notifyrc");
|
kWarning() << "invalid notification" << notification;
|
||||||
if (notifyconfig.isEmpty()) {
|
return;
|
||||||
kWarning() << "invalid notification" << notification;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
notificationconfig = new KConfig(notifyconfig, KConfig::NoGlobals);
|
|
||||||
d->configs.insert(notification, notificationconfig);
|
|
||||||
}
|
}
|
||||||
KConfigGroup globalgroupconfig(notificationconfig, notification);
|
KConfig notificationconfig("knotificationrc", KConfig::NoGlobals);
|
||||||
|
notificationconfig.addConfigSources(QStringList() << notifyconfig);
|
||||||
|
KConfigGroup globalgroupconfig(¬ificationconfig, notification);
|
||||||
KIcon soundicon = KIcon("media-playback-start");
|
KIcon soundicon = KIcon("media-playback-start");
|
||||||
foreach (const QString &eventgroup, notificationconfig->groupList()) {
|
foreach (const QString &eventgroup, notificationconfig.groupList()) {
|
||||||
if (!eventgroup.contains(QLatin1Char('/'))) {
|
if (!eventgroup.startsWith(notification + QLatin1Char('/'))) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
KConfigGroup eventgroupconfig(notificationconfig, eventgroup);
|
KConfigGroup eventgroupconfig(¬ificationconfig, eventgroup);
|
||||||
QString eventtext = eventgroupconfig.readEntry("Name");
|
QString eventtext = eventgroupconfig.readEntry("Name");
|
||||||
if (eventtext.isEmpty()) {
|
if (eventtext.isEmpty()) {
|
||||||
eventtext = globalgroupconfig.readEntry("Name");
|
eventtext = globalgroupconfig.readEntry("Name");
|
||||||
|
|
Loading…
Add table
Reference in a new issue