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

akonadi

  • sources
  • kde-4.14
  • kdepimlibs
  • akonadi
  • contact
  • editor
  • im
imeditordialog.cpp
1 /*
2 IM address editor widget for KDE PIM
3 
4 Copyright 2004,2010 Will Stephenson <wstephenson@kde.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) version 3, or any
10 later version accepted by the membership of KDE e.V. (or its
11 successor approved by the membership of KDE e.V.), which shall
12 act as a proxy defined in Section 6 of version 3 of the license.
13 
14 This library is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 Lesser General Public License for more details.
18 
19 You should have received a copy of the GNU Lesser General Public
20 License along with this library. If not, see <http://www.gnu.org/licenses/>.
21 */
22 
23 #include "imeditordialog.h"
24 
25 #include "imdelegate.h"
26 #include "imitemdialog.h"
27 
28 #include <QGridLayout>
29 #include <QPointer>
30 #include <QPushButton>
31 #include <QTreeView>
32 #include <QHeaderView>
33 
34 #include <klocalizedstring.h>
35 #include <kmessagebox.h>
36 #include <KSharedConfig>
37 
38 IMEditorDialog::IMEditorDialog(QWidget *parent)
39  : KDialog(parent)
40 {
41  setCaption(i18nc("@title:window", "Edit Instant Messaging Addresses"));
42  setButtons(Ok | Cancel);
43  setDefaultButton(Ok);
44 
45  QWidget *widget = new QWidget(this);
46  setMainWidget(widget);
47 
48  QGridLayout *layout = new QGridLayout(widget);
49 
50  mAddButton = new QPushButton(i18nc("@action:button", "Add..."));
51  mEditButton = new QPushButton(i18nc("@action:button", "Edit..."));
52  mRemoveButton = new QPushButton(i18nc("@action:button", "Remove"));
53  mStandardButton = new QPushButton(i18nc("@action:button", "Set as Standard"));
54 
55  mView = new QTreeView;
56  mView->setRootIsDecorated(false);
57 
58  layout->addWidget(mView, 0, 0, 5, 1);
59  layout->addWidget(mAddButton, 0, 1);
60  layout->addWidget(mEditButton, 1, 1);
61  layout->addWidget(mRemoveButton, 2, 1);
62  layout->addWidget(mStandardButton, 3, 1);
63  layout->setRowStretch(4, 1);
64 
65  connect(mAddButton, SIGNAL(clicked()), SLOT(slotAdd()));
66  connect(mEditButton, SIGNAL(clicked()), SLOT(slotEdit()));
67  connect(mRemoveButton, SIGNAL(clicked()), SLOT(slotRemove()));
68  connect(mStandardButton, SIGNAL(clicked()), SLOT(slotSetStandard()));
69 
70  mModel = new IMModel(this);
71 
72  mView->setModel(mModel);
73  mView->setItemDelegate(new IMDelegate(this));
74 
75  connect(mView->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)),
76  this, SLOT(slotUpdateButtons()));
77  connect(mView, SIGNAL(doubleClicked(QModelIndex)),
78  this, SLOT(slotEdit()));
79  slotUpdateButtons();
80  readConfig();
81 }
82 
83 IMEditorDialog::~IMEditorDialog()
84 {
85  writeConfig();
86 }
87 
88 void IMEditorDialog::readConfig()
89 {
90  KConfigGroup group(KGlobal::config(), "IMEditorDialog");
91  const QSize sizeDialog = group.readEntry("Size", QSize(400, 200));
92  if (sizeDialog.isValid()) {
93  resize(sizeDialog);
94  }
95  const QByteArray header = group.readEntry("Header", QByteArray());
96  if (!header.isEmpty())
97  mView->header()->restoreState(header);
98 }
99 
100 void IMEditorDialog::writeConfig()
101 {
102  KConfigGroup group(KGlobal::config(), "IMEditorDialog");
103  group.writeEntry("Size", size());
104  group.writeEntry("Header", mView->header()->saveState());
105 }
106 
107 void IMEditorDialog::setAddresses(const IMAddress::List &addresses)
108 {
109  mModel->setAddresses(addresses);
110 }
111 
112 IMAddress::List IMEditorDialog::addresses() const
113 {
114  return mModel->addresses();
115 }
116 
117 void IMEditorDialog::slotAdd()
118 {
119  QPointer<IMItemDialog> d(new IMItemDialog(this));
120  d->setCaption(i18nc("@title:window", "Add IM Address"));
121  if (d->exec() == QDialog::Accepted && d != 0) {
122  IMAddress newAddress = d->address();
123  int addedRow = mModel->rowCount();
124  mModel->insertRow(addedRow);
125 
126  mModel->setData(mModel->index(addedRow, 0), newAddress.protocol(), IMModel::ProtocolRole);
127  mModel->setData(mModel->index(addedRow, 1), newAddress.name(), Qt::EditRole);
128  }
129  delete d;
130 }
131 
132 void IMEditorDialog::slotEdit()
133 {
134  const int currentRow = mView->currentIndex().row();
135  if (currentRow < 0) {
136  return;
137  }
138 
139  QPointer<IMItemDialog> d(new IMItemDialog(this));
140  d->setCaption(i18nc("@title:window", "Edit IM Address"));
141  d->setAddress(mModel->addresses().at(currentRow));
142 
143  if (d->exec() == QDialog::Accepted && d != 0) {
144  IMAddress editedAddress = d->address();
145  mModel->setData(mModel->index(currentRow, 0), editedAddress.protocol(),
146  IMModel::ProtocolRole);
147  mModel->setData(mModel->index(currentRow, 1), editedAddress.name(),
148  Qt::EditRole);
149  }
150  delete d;
151 }
152 
153 void IMEditorDialog::slotRemove()
154 {
155  const int currentRow = mView->currentIndex().row();
156  if (currentRow < 0) {
157  return;
158  }
159 
160  if (KMessageBox::warningContinueCancel(
161  this,
162  i18nc("@info Instant messaging",
163  "Do you really want to delete the selected <resource>%1</resource> address?",
164  mModel->data(mModel->index(currentRow, 0), Qt::DisplayRole).toString()),
165  i18nc("@title:window", "Confirm Delete Resource"),
166  KStandardGuiItem::del()) != KMessageBox::Continue) {
167  return;
168  }
169 
170  mModel->removeRow(currentRow);
171 }
172 
173 void IMEditorDialog::slotSetStandard()
174 {
175  const int currentRow = mView->currentIndex().row();
176  if (currentRow < 0) {
177  return;
178  }
179 
180  // set current index as preferred and all other as non-preferred
181  for (int i = 0; i < mModel->rowCount(); ++i) {
182  const QModelIndex index = mModel->index(i, 0);
183  mModel->setData(index, (index.row() == currentRow), IMModel::IsPreferredRole);
184  }
185 }
186 
187 void IMEditorDialog::slotUpdateButtons()
188 {
189  const QModelIndex currentIndex = mView->currentIndex();
190 
191  mRemoveButton->setEnabled(currentIndex.isValid());
192  mEditButton->setEnabled(currentIndex.isValid());
193 
194  mStandardButton->setEnabled(currentIndex.isValid() &&
195  !mModel->data(currentIndex, IMModel::IsPreferredRole).toBool());
196 }
QModelIndex
QWidget
QSize::isValid
bool isValid() const
QGridLayout::addWidget
void addWidget(QWidget *widget, int row, int column, QFlags< Qt::AlignmentFlag > alignment)
QByteArray
QPointer
QByteArray::isEmpty
bool isEmpty() const
QGridLayout
QModelIndex::isValid
bool isValid() const
QGridLayout::setRowStretch
void setRowStretch(int row, int stretch)
QModelIndex::row
int row() const
QSize
QVector< IMAddress >
QTest::toString
char * toString(const T &value)
QTreeView
QPushButton
QTreeView::setRootIsDecorated
void setRootIsDecorated(bool show)
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:38:03 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

akonadi

Skip menu "akonadi"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • Modules
  • Related Pages

kdepimlibs API Reference

Skip menu "kdepimlibs API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2

Search



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