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

akonadi

imeditwidget.cpp
00001 /*
00002     This file is part of Akonadi Contact.
00003 
00004     Copyright (c) 2009 Tobias Koenig <tokoe@kde.org>
00005 
00006     This library is free software; you can redistribute it and/or modify it
00007     under the terms of the GNU Library General Public License as published by
00008     the Free Software Foundation; either version 2 of the License, or (at your
00009     option) any later version.
00010 
00011     This library is distributed in the hope that it will be useful, but WITHOUT
00012     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00013     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00014     License for more details.
00015 
00016     You should have received a copy of the GNU Library General Public License
00017     along with this library; see the file COPYING.LIB.  If not, write to the
00018     Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00019     02110-1301, USA.
00020 */
00021 
00022 #include "imeditwidget.h"
00023 #include "customfieldseditwidget.h"
00024 
00025 #include "im/imeditordialog.h"
00026 #include "im/improtocols.h"
00027 
00028 #include <QtCore/QPointer>
00029 #include <QtGui/QHBoxLayout>
00030 #include <QtGui/QToolButton>
00031 
00032 #include <kabc/addressee.h>
00033 #include <klineedit.h>
00034 #include <klocale.h>
00035 
00036 
00037 IMEditWidget::IMEditWidget( QWidget *parent )
00038   : QWidget( parent )
00039 {
00040   QHBoxLayout *layout = new QHBoxLayout( this );
00041   layout->setMargin( 0 );
00042 
00043   mIMEdit = new KLineEdit;
00044   layout->addWidget( mIMEdit );
00045 
00046   mEditButton = new QToolButton;
00047   mEditButton->setText( i18n( "..." ) );
00048   layout->addWidget( mEditButton );
00049 
00050   connect( mEditButton, SIGNAL(clicked()), SLOT(edit()) );
00051 }
00052 
00053 IMEditWidget::~IMEditWidget()
00054 {
00055 }
00056 
00057 void IMEditWidget::loadContact( const KABC::Addressee &contact )
00058 {
00059   mIMEdit->setText( contact.custom( QLatin1String( "KADDRESSBOOK" ), QLatin1String( "X-IMAddress" ) ) );
00060 
00061   const QStringList customs = contact.customs();
00062 
00063   foreach ( const QString &custom, customs ) {
00064     QString app, name, value;
00065     splitCustomField( custom, app, name, value );
00066 
00067     if ( app.startsWith( QLatin1String( "messaging/" ) ) ) {
00068       if ( name == QLatin1String( "All" ) ) {
00069         const QString protocol = app;
00070         const QStringList names = value.split( QChar( 0xE000 ), QString::SkipEmptyParts );
00071 
00072         foreach ( const QString &name, names )
00073           mIMAddresses << IMAddress( protocol, name, (name == mIMEdit->text()) );
00074       }
00075     }
00076   }
00077 }
00078 
00079 void IMEditWidget::storeContact( KABC::Addressee &contact ) const
00080 {
00081   if ( !mIMEdit->text().isEmpty() )
00082     contact.insertCustom( QLatin1String( "KADDRESSBOOK" ), QLatin1String( "X-IMAddress" ), mIMEdit->text() );
00083   else
00084     contact.removeCustom( QLatin1String( "KADDRESSBOOK" ), QLatin1String( "X-IMAddress" ) );
00085 
00086   // create a map with protocol as key and list of names for that protocol as value
00087   QMap<QString, QStringList> protocolMap;
00088 
00089   // fill map with all known protocols
00090   foreach ( const QString &protocol, IMProtocols::self()->protocols() )
00091     protocolMap.insert( protocol, QStringList() );
00092 
00093   // add the configured addresses
00094   foreach ( const IMAddress &address, mIMAddresses )
00095     protocolMap[ address.protocol() ].append( address.name() );
00096 
00097   // iterate over this list and modify the contact according
00098   QMapIterator<QString, QStringList> it( protocolMap );
00099   while ( it.hasNext() ) {
00100     it.next();
00101 
00102     if ( !it.value().isEmpty() ) {
00103       contact.insertCustom( it.key(), QLatin1String( "All" ), it.value().join( QString( 0xE000 ) ) );
00104     } else {
00105       contact.removeCustom( it.key(), QLatin1String( "All" ) );
00106     }
00107   }
00108 }
00109 
00110 void IMEditWidget::setReadOnly( bool readOnly )
00111 {
00112   mIMEdit->setReadOnly( readOnly );
00113   mEditButton->setEnabled( !readOnly );
00114 }
00115 
00116 void IMEditWidget::edit()
00117 {
00118   QPointer<IMEditorDialog> dlg = new IMEditorDialog( this );
00119   dlg->setAddresses( mIMAddresses );
00120 
00121   if ( dlg->exec() == QDialog::Accepted ) {
00122     mIMAddresses = dlg->addresses();
00123 
00124     foreach ( const IMAddress &address, mIMAddresses ) {
00125       if ( address.preferred() ) {
00126         mIMEdit->setText( address.name() );
00127         break;
00128       }
00129     }
00130   }
00131 
00132   delete dlg;
00133 }
00134 
00135 #include "imeditwidget.moc"
This file is part of the KDE documentation.
Documentation copyright © 1996-2012 The KDE developers.
Generated on Thu May 10 2012 22:18:33 by doxygen 1.8.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
  • Modules
  • Related Pages

kdepimlibs-4.8.3 API Reference

Skip menu "kdepimlibs-4.8.3 API Reference"
  • akonadi
  •   contact
  •   kmime
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  •   richtextbuilders
  • 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