23 #include <QVBoxLayout>
24 #include <QHBoxLayout>
26 #include <QDBusInterface>
28 #include <TelepathyQt/Contact>
30 #include <KNotifyConfigWidget>
34 #include <KSharedConfig>
38 , m_notifyWidget(new KNotifyConfigWidget(this))
42 m_currentSelection = 0;
43 setCaption(i18n(
"Configure notifications for %1", m_contact.data()->alias()));
44 setAttribute(Qt::WA_DeleteOnClose);
45 setButtons(KDialog::Apply | KDialog::Cancel | KDialog::Default );
46 enableButtonApply(
false);
49 QVBoxLayout *vboxLayout =
new QVBoxLayout(centralWidget);
50 QHBoxLayout *hboxLayout =
new QHBoxLayout(centralWidget);
51 QLabel *label =
new QLabel(i18n(
"Configure notifications for"), centralWidget);
52 KComboBox *comboBox =
new KComboBox(centralWidget);
54 comboBox->setEditable(
false);
55 comboBox->addItem(m_contact.data()->alias());
56 comboBox->addItem(i18n(
"All users"));
57 hboxLayout->addWidget(label);
58 hboxLayout->addWidget(comboBox);
59 vboxLayout->addLayout(hboxLayout);
60 vboxLayout->addWidget(m_notifyWidget);
61 centralWidget->setLayout(vboxLayout);
62 setMainWidget(centralWidget);
64 m_notifyWidget->setApplication(QLatin1String(
"ktelepathy"),
65 QLatin1String(
"contact"),
66 m_contact.data()->id());
68 connect(
this, SIGNAL(applyClicked()),
70 connect(comboBox, SIGNAL(currentIndexChanged(
int)),
71 SLOT(updateNotifyWidget(
int)));
72 connect(
this, SIGNAL(defaultClicked()),
74 connect(m_notifyWidget, SIGNAL(changed(
bool)),
75 SLOT(enableButtonApply(
bool)));
82 void KTp::NotificationConfigDialog::saveConfig()
84 m_notifyWidget->save();
87 void KTp::NotificationConfigDialog::updateNotifyWidget(
const int selection)
90 m_notifyWidget->setApplication(QLatin1String(
"ktelepathy"),
91 QLatin1String(
"contact"),
92 m_contact.data()->id());
93 setCaption(i18n(
"Configure notifications for %1", m_contact.data()->alias()));
94 }
else if (selection == 1) {
95 m_notifyWidget->setApplication(QLatin1String(
"ktelepathy"));
96 setCaption(i18n(
"Configure notifications for all users"));
99 m_currentSelection = selection;
102 void KTp::NotificationConfigDialog::defaults()
104 KSharedConfigPtr config = KSharedConfig::openConfig(QLatin1String(
"ktelepathy.notifyrc"));
105 KConfigGroup *configGroup;
107 if (m_currentSelection == 0) {
108 Q_FOREACH(
const QString &group, config->groupList()) {
109 if (group.endsWith(m_contact.data()->id())) {
110 configGroup =
new KConfigGroup(config, group);
111 configGroup->deleteGroup();
115 }
else if (m_currentSelection == 1) {
116 Q_FOREACH(
const QString &group, config->groupList()) {
117 if (group.startsWith(QLatin1String(
"Event"))) {
118 configGroup =
new KConfigGroup(config, group);
119 configGroup->deleteGroup();
126 if (QDBusConnection::sessionBus().interface()->isServiceRegistered(QLatin1String(
"org.kde.knotify")))
128 QDBusInterface( QLatin1String(
"org.kde.knotify"), QLatin1String(
"/Notify"),
129 QLatin1String(
"org.kde.KNotify")).call( QLatin1String(
"reconfigure" ));
131 updateNotifyWidget(m_currentSelection);