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

akonadi

  • akonadi
  • contact
  • editor
imeditwidget.cpp
1/*
2 This file is part of Akonadi Contact.
3
4 Copyright (c) 2009 Tobias Koenig <tokoe@kde.org>
5
6 This library is free software; you can redistribute it and/or modify it
7 under the terms of the GNU Library General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or (at your
9 option) any later version.
10
11 This library is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
14 License for more details.
15
16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to the
18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 02110-1301, USA.
20*/
21
22#include "imeditwidget.h"
23#include "customfieldseditwidget.h"
24
25#include "im/imeditordialog.h"
26#include "im/improtocols.h"
27
28#include <QtCore/QPointer>
29#include <QHBoxLayout>
30#include <QToolButton>
31
32#include <kabc/addressee.h>
33#include <klineedit.h>
34#include <klocalizedstring.h>
35
36IMEditWidget::IMEditWidget(QWidget *parent)
37 : QWidget(parent)
38{
39 QHBoxLayout *layout = new QHBoxLayout(this);
40 layout->setMargin(0);
41
42 mIMEdit = new KLineEdit;
43 mIMEdit->setTrapReturnKey(true);
44 layout->addWidget(mIMEdit);
45
46 mEditButton = new QToolButton;
47 mEditButton->setText(i18n("..."));
48 layout->addWidget(mEditButton);
49 setFocusProxy(mEditButton);
50 setFocusPolicy(Qt::StrongFocus);
51
52 connect(mEditButton, SIGNAL(clicked()), SLOT(edit()));
53}
54
55IMEditWidget::~IMEditWidget()
56{
57}
58
59void IMEditWidget::loadContact(const KABC::Addressee &contact)
60{
61 mIMEdit->setText(contact.custom(QLatin1String("KADDRESSBOOK"), QLatin1String("X-IMAddress")));
62
63 const QStringList customs = contact.customs();
64
65 foreach (const QString &custom, customs) {
66 QString app, name, value;
67 splitCustomField(custom, app, name, value);
68
69 if (app.startsWith(QLatin1String("messaging/"))) {
70 if (name == QLatin1String("All")) {
71 const QString protocol = app;
72 const QStringList names = value.split(QChar(0xE000), QString::SkipEmptyParts);
73
74 foreach (const QString &name, names) {
75 mIMAddresses << IMAddress(protocol, name, (name == mIMEdit->text()));
76 }
77 }
78 }
79 }
80}
81
82void IMEditWidget::storeContact(KABC::Addressee &contact) const
83{
84 if (!mIMEdit->text().isEmpty()) {
85 contact.insertCustom(QLatin1String("KADDRESSBOOK"), QLatin1String("X-IMAddress"), mIMEdit->text());
86 } else {
87 contact.removeCustom(QLatin1String("KADDRESSBOOK"), QLatin1String("X-IMAddress"));
88 }
89
90 // create a map with protocol as key and list of names for that protocol as value
91 QMap<QString, QStringList> protocolMap;
92
93 // fill map with all known protocols
94 foreach (const QString &protocol, IMProtocols::self()->protocols()) {
95 protocolMap.insert(protocol, QStringList());
96 }
97
98 // add the configured addresses
99 foreach (const IMAddress &address, mIMAddresses) {
100 protocolMap[address.protocol()].append(address.name());
101 }
102
103 // iterate over this list and modify the contact according
104 QMapIterator<QString, QStringList> it(protocolMap);
105 while (it.hasNext()) {
106 it.next();
107
108 if (!it.value().isEmpty()) {
109 contact.insertCustom(it.key(), QLatin1String("All"), it.value().join(QString(0xE000)));
110 } else {
111 contact.removeCustom(it.key(), QLatin1String("All"));
112 }
113 }
114}
115
116void IMEditWidget::setReadOnly(bool readOnly)
117{
118 mIMEdit->setReadOnly(readOnly);
119 mEditButton->setEnabled(!readOnly);
120}
121
122void IMEditWidget::edit()
123{
124 QPointer<IMEditorDialog> dlg = new IMEditorDialog(this);
125 dlg->setAddresses(mIMAddresses);
126
127 if (dlg->exec() == QDialog::Accepted) {
128 mIMAddresses = dlg->addresses();
129
130 foreach (const IMAddress &address, mIMAddresses) {
131 if (address.preferred()) {
132 mIMEdit->setText(address.name());
133 break;
134 }
135 }
136 }
137
138 delete dlg;
139}
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Thu Jul 21 2022 00:00:00 by doxygen 1.9.5 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-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