KNotifyConfig

knotifyconfigwidget.cpp
1/*
2 This file is part of the KDE libraries
3 SPDX-FileCopyrightText: 2005 Olivier Goffart <ogoffart at kde.org>
4
5 SPDX-License-Identifier: LGPL-2.0-only
6*/
7
8#include "knotifyconfigwidget.h"
9#include "knotifyconfigactionswidget.h"
10#include "knotifyconfigelement.h"
11#include "knotifyeventlist.h"
12
13#include <QDialog>
14#include <QDialogButtonBox>
15#include <QPushButton>
16#include <QVBoxLayout>
17
18#ifdef HAVE_DBUS
19#include <QDBusConnectionInterface>
20#endif
21
22#include <KLocalizedString>
23
24class KNotifyConfigWidgetPrivate
25{
26public:
27 KNotifyEventList *eventList;
28 KNotifyConfigActionsWidget *actionsconfig;
29 KNotifyConfigElement *currentElement;
30 QString application;
31};
32
33KNotifyConfigWidget::KNotifyConfigWidget(QWidget *parent)
34 : QWidget(parent)
35 , d(new KNotifyConfigWidgetPrivate)
36{
37 d->currentElement = nullptr;
38 d->eventList = new KNotifyEventList(this);
39 d->eventList->setFocus();
40 d->actionsconfig = new KNotifyConfigActionsWidget(this);
41 d->actionsconfig->setEnabled(false);
42 connect(d->eventList, SIGNAL(eventSelected(KNotifyConfigElement *)), this, SLOT(slotEventSelected(KNotifyConfigElement *)));
43 connect(d->actionsconfig, SIGNAL(changed()), this, SLOT(slotActionChanged()));
44
45 QVBoxLayout *layout = new QVBoxLayout(this);
46 layout->setContentsMargins(0, 0, 0, 0);
47 layout->addWidget(d->eventList, 1);
48 layout->addWidget(d->actionsconfig);
49}
50
51KNotifyConfigWidget::~KNotifyConfigWidget() = default;
52
54{
55 d->currentElement = nullptr;
56 d->application = app.isEmpty() ? QCoreApplication::instance()->applicationName() : app;
57 d->eventList->fill(d->application);
58}
59
61{
62 d->eventList->selectEvent(eventId);
63}
64
65void KNotifyConfigWidget::slotEventSelected(KNotifyConfigElement *e)
66{
67 if (d->currentElement) {
68 d->actionsconfig->save(d->currentElement);
69 }
70 d->currentElement = e;
71 if (e) {
72 d->actionsconfig->setConfigElement(e);
73 d->actionsconfig->setEnabled(true);
74 } else {
75 d->actionsconfig->setEnabled(false);
76 }
77}
78
80{
81 if (d->currentElement) {
82 d->actionsconfig->save(d->currentElement);
83 }
84
85 d->eventList->save();
86 Q_EMIT changed(false);
87
88#ifdef HAVE_DBUS
89 // ask KNotification objects to reload their config
90 QDBusMessage message =
91 QDBusMessage::createSignal(QStringLiteral("/Config"), QStringLiteral("org.kde.knotification"), QStringLiteral("reparseConfiguration"));
92 message.setArguments(QVariantList() << d->application);
94#endif
95}
96
97void KNotifyConfigWidget::revertToDefaults()
98{
99 d->eventList->fill(d->application, true);
100 Q_EMIT changed(true);
101}
102
103void KNotifyConfigWidget::disableAllSounds()
104{
105 if (d->eventList->disableAllSounds()) {
106 if (d->currentElement) {
107 d->actionsconfig->setConfigElement(d->currentElement);
108 }
109 d->eventList->updateAllItems();
110 Q_EMIT changed(true);
111 }
112}
113
115{
116 QDialog *dialog = new QDialog(parent);
117 dialog->setWindowTitle(i18n("Configure Notifications"));
118
120
121 QDialogButtonBox *buttonBox = new QDialogButtonBox(dialog);
123 buttonBox->button(QDialogButtonBox::Apply)->setEnabled(false);
124
125 QVBoxLayout *layout = new QVBoxLayout(dialog);
126 layout->addWidget(w);
127 layout->addWidget(buttonBox);
128
129 connect(buttonBox->button(QDialogButtonBox::Apply), SIGNAL(clicked()), w, SLOT(save()));
130 connect(buttonBox->button(QDialogButtonBox::Ok), SIGNAL(clicked()), w, SLOT(save()));
131 connect(w, SIGNAL(changed(bool)), buttonBox->button(QDialogButtonBox::Apply), SLOT(setEnabled(bool)));
132
133 connect(buttonBox, SIGNAL(accepted()), dialog, SLOT(accept()));
134 connect(buttonBox, SIGNAL(rejected()), dialog, SLOT(reject()));
135
136 w->setApplication(appname);
138 dialog->show();
139 return w;
140}
141
142void KNotifyConfigWidget::slotActionChanged()
143{
144 Q_EMIT changed(true); // TODO
145 if (d->currentElement) {
146 d->actionsconfig->save(d->currentElement);
147 d->eventList->updateCurrentItem();
148 }
149}
150
151#include "moc_knotifyconfigwidget.cpp"
Represent the config for an event.
Represent the config for an event.
Configure the notification for a given application.
void selectEvent(const QString &eventId)
Select a given notification in the current list.
void setApplication(const QString &appname=QString())
Change the application.
void save()
save to the config file
void changed(bool state)
Indicate that the state of the modules contents has changed.
static KNotifyConfigWidget * configure(QWidget *parent=nullptr, const QString &appname=QString())
Show a dialog with the widget.
QString i18n(const char *text, const TYPE &arg...)
void addWidget(QWidget *widget, int stretch, Qt::Alignment alignment)
QCoreApplication * instance()
bool send(const QDBusMessage &message) const const
QDBusConnection sessionBus()
QDBusMessage createSignal(const QString &path, const QString &interface, const QString &name)
void setArguments(const QList< QVariant > &arguments)
QPushButton * button(StandardButton which) const const
void setStandardButtons(StandardButtons buttons)
void addWidget(QWidget *w)
void setContentsMargins(const QMargins &margins)
Q_EMITQ_EMIT
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
QObject * parent() const const
bool isEmpty() const const
WA_DeleteOnClose
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
void setEnabled(bool)
QLayout * layout() const const
void setAttribute(Qt::WidgetAttribute attribute, bool on)
void show()
void setWindowTitle(const QString &)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 16:57:32 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.