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

akonadi

  • akonadi
  • contact
  • editor
  • im
imeditordialog.cpp
1/*
2IM address editor widget for KDE PIM
3
4Copyright 2004,2010 Will Stephenson <wstephenson@kde.org>
5
6This library is free software; you can redistribute it and/or
7modify it under the terms of the GNU Lesser General Public
8License as published by the Free Software Foundation; either
9version 2.1 of the License, or (at your option) version 3, or any
10later version accepted by the membership of KDE e.V. (or its
11successor approved by the membership of KDE e.V.), which shall
12act as a proxy defined in Section 6 of version 3 of the license.
13
14This library is distributed in the hope that it will be useful,
15but WITHOUT ANY WARRANTY; without even the implied warranty of
16MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17Lesser General Public License for more details.
18
19You should have received a copy of the GNU Lesser General Public
20License 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
38IMEditorDialog::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
83IMEditorDialog::~IMEditorDialog()
84{
85 writeConfig();
86}
87
88void 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
100void IMEditorDialog::writeConfig()
101{
102 KConfigGroup group(KGlobal::config(), "IMEditorDialog");
103 group.writeEntry("Size", size());
104 group.writeEntry("Header", mView->header()->saveState());
105}
106
107void IMEditorDialog::setAddresses(const IMAddress::List &addresses)
108{
109 mModel->setAddresses(addresses);
110}
111
112IMAddress::List IMEditorDialog::addresses() const
113{
114 return mModel->addresses();
115}
116
117void 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
132void 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
153void 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
173void 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
187void 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}
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Wed Jan 24 2024 00:00:00 by doxygen 1.10.0 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
  • Related Pages

kdepimlibs-4.14.10 API Reference

Skip menu "kdepimlibs-4.14.10 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
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