• Skip to content
  • Skip to link menu
  • KDE API Reference
  • KDE Home
  • Contact Us
 

Nepomuk-Core

  • KTp
  • Widgets
notificationconfigdialog.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of KDE Telepathy Common Internals
3  *
4  * Copyright (C) 2012 Rohan Garg <rohangarg@kubuntu.org>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 #include "notificationconfigdialog.h"
22 
23 #include <QVBoxLayout>
24 #include <QHBoxLayout>
25 #include <QLabel>
26 #include <QDBusInterface>
27 
28 #include <TelepathyQt/Contact>
29 
30 #include <KNotifyConfigWidget>
31 #include <KComboBox>
32 #include <KAboutData>
33 #include <KConfig>
34 #include <KSharedConfig>
35 
36 KTp::NotificationConfigDialog::NotificationConfigDialog(const Tp::ContactPtr &contact, QWidget *parent)
37  : KDialog(parent)
38  , m_notifyWidget(new KNotifyConfigWidget(this))
39 {
40  Q_ASSERT(contact);
41  m_contact = contact;
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);
47 
48  QWidget *centralWidget = new QWidget(this);
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);
53 
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);
63 
64  m_notifyWidget->setApplication(QLatin1String("ktelepathy"),
65  QLatin1String("contact"),
66  m_contact.data()->id());
67 
68  connect(this, SIGNAL(applyClicked()),
69  SLOT(saveConfig()));
70  connect(comboBox, SIGNAL(currentIndexChanged(int)),
71  SLOT(updateNotifyWidget(int)));
72  connect(this, SIGNAL(defaultClicked()),
73  SLOT(defaults()));
74  connect(m_notifyWidget, SIGNAL(changed(bool)),
75  SLOT(enableButtonApply(bool)));
76 }
77 
78 KTp::NotificationConfigDialog::~NotificationConfigDialog()
79 {
80 }
81 
82 void KTp::NotificationConfigDialog::saveConfig()
83 {
84  m_notifyWidget->save();
85 }
86 
87 void KTp::NotificationConfigDialog::updateNotifyWidget(const int selection)
88 {
89  if (selection == 0) {
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"));
97  }
98 
99  m_currentSelection = selection;
100 }
101 
102 void KTp::NotificationConfigDialog::defaults()
103 {
104  KSharedConfigPtr config = KSharedConfig::openConfig(QLatin1String("ktelepathy.notifyrc"));
105  KConfigGroup *configGroup;
106 
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();
112  delete configGroup;
113  }
114  }
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();
120  delete configGroup;
121  }
122  }
123  }
124  config->sync();
125  //ask the notify daemon to reload the config
126  if (QDBusConnection::sessionBus().interface()->isServiceRegistered(QLatin1String("org.kde.knotify")))
127  {
128  QDBusInterface( QLatin1String("org.kde.knotify"), QLatin1String("/Notify"),
129  QLatin1String("org.kde.KNotify")).call( QLatin1String("reconfigure" ));
130  }
131  updateNotifyWidget(m_currentSelection);
132 }
This file is part of the KDE documentation.
Documentation copyright © 1996-2013 The KDE developers.
Generated on Fri Mar 22 2013 10:58:52 by doxygen 1.8.1.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

ktp-common-internals API Reference

Skip menu "ktp-common-internals API Reference"
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal