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

akonadi

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

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