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

akonadi/contact

  • 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 
37 IMEditWidget::IMEditWidget( QWidget *parent )
38  : QWidget( parent )
39 {
40  QHBoxLayout *layout = new QHBoxLayout( this );
41  layout->setMargin( 0 );
42 
43  mIMEdit = new KLineEdit;
44  layout->addWidget( mIMEdit );
45 
46  mEditButton = new QToolButton;
47  mEditButton->setText( i18n( "..." ) );
48  layout->addWidget( mEditButton );
49 
50  connect( mEditButton, SIGNAL(clicked()), SLOT(edit()) );
51 }
52 
53 IMEditWidget::~IMEditWidget()
54 {
55 }
56 
57 void IMEditWidget::loadContact( const KABC::Addressee &contact )
58 {
59  mIMEdit->setText( contact.custom( QLatin1String( "KADDRESSBOOK" ), QLatin1String( "X-IMAddress" ) ) );
60 
61  const QStringList customs = contact.customs();
62 
63  foreach ( const QString &custom, customs ) {
64  QString app, name, value;
65  splitCustomField( custom, app, name, value );
66 
67  if ( app.startsWith( QLatin1String( "messaging/" ) ) ) {
68  if ( name == QLatin1String( "All" ) ) {
69  const QString protocol = app;
70  const QStringList names = value.split( QChar( 0xE000 ), QString::SkipEmptyParts );
71 
72  foreach ( const QString &name, names ) {
73  mIMAddresses << IMAddress( protocol, name, ( name == mIMEdit->text() ) );
74  }
75  }
76  }
77  }
78 }
79 
80 void IMEditWidget::storeContact( KABC::Addressee &contact ) const
81 {
82  if ( !mIMEdit->text().isEmpty() ) {
83  contact.insertCustom( QLatin1String( "KADDRESSBOOK" ), QLatin1String( "X-IMAddress" ), mIMEdit->text() );
84  } else {
85  contact.removeCustom( QLatin1String( "KADDRESSBOOK" ), QLatin1String( "X-IMAddress" ) );
86  }
87 
88  // create a map with protocol as key and list of names for that protocol as value
89  QMap<QString, QStringList> protocolMap;
90 
91  // fill map with all known protocols
92  foreach ( const QString &protocol, IMProtocols::self()->protocols() ) {
93  protocolMap.insert( protocol, QStringList() );
94  }
95 
96  // add the configured addresses
97  foreach ( const IMAddress &address, mIMAddresses ) {
98  protocolMap[ address.protocol() ].append( address.name() );
99  }
100 
101  // iterate over this list and modify the contact according
102  QMapIterator<QString, QStringList> it( protocolMap );
103  while ( it.hasNext() ) {
104  it.next();
105 
106  if ( !it.value().isEmpty() ) {
107  contact.insertCustom( it.key(), QLatin1String( "All" ), it.value().join( QString( 0xE000 ) ) );
108  } else {
109  contact.removeCustom( it.key(), QLatin1String( "All" ) );
110  }
111  }
112 }
113 
114 void IMEditWidget::setReadOnly( bool readOnly )
115 {
116  mIMEdit->setReadOnly( readOnly );
117  mEditButton->setEnabled( !readOnly );
118 }
119 
120 void IMEditWidget::edit()
121 {
122  QPointer<IMEditorDialog> dlg = new IMEditorDialog( this );
123  dlg->setAddresses( mIMAddresses );
124 
125  if ( dlg->exec() == QDialog::Accepted ) {
126  mIMAddresses = dlg->addresses();
127 
128  foreach ( const IMAddress &address, mIMAddresses ) {
129  if ( address.preferred() ) {
130  mIMEdit->setText( address.name() );
131  break;
132  }
133  }
134  }
135 
136  delete dlg;
137 }
138 
This file is part of the KDE documentation.
Documentation copyright © 1996-2013 The KDE developers.
Generated on Tue Nov 26 2013 09:03:47 by doxygen 1.8.5 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-4.11.3 API Reference

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