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

akonadi/contact

  • sources
  • kde-4.14
  • kdepimlibs
  • 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 
36 IMEditWidget::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 
55 IMEditWidget::~IMEditWidget()
56 {
57 }
58 
59 void 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 
82 void 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 
116 void IMEditWidget::setReadOnly(bool readOnly)
117 {
118  mIMEdit->setReadOnly(readOnly);
119  mEditButton->setEnabled(!readOnly);
120 }
121 
122 void 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 }
QWidget::layout
QLayout * layout() const
QWidget
QWidget::setFocusPolicy
void setFocusPolicy(Qt::FocusPolicy policy)
QChar
QString::split
QStringList split(const QString &sep, SplitBehavior behavior, Qt::CaseSensitivity cs) const
QMap
QPointer
QHBoxLayout
QObject::name
const char * name() const
QWidget::setEnabled
void setEnabled(bool)
QBoxLayout::addWidget
void addWidget(QWidget *widget, int stretch, QFlags< Qt::AlignmentFlag > alignment)
QMapIterator
QWidget::setFocusProxy
void setFocusProxy(QWidget *w)
QString::startsWith
bool startsWith(const QString &s, Qt::CaseSensitivity cs) const
QString
QLayout::setMargin
void setMargin(int margin)
QStringList
QToolButton
QLatin1String
QAbstractButton::setText
void setText(const QString &text)
QMap::insert
iterator insert(const Key &key, const T &value)
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:19 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

akonadi/contact

Skip menu "akonadi/contact"
  • Main Page
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • 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