akonadi
nameeditwidget.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 "nameeditwidget.h" 00023 00024 #include "nameeditdialog.h" 00025 00026 #include <QtCore/QPointer> 00027 #include <QtCore/QString> 00028 #include <QtGui/QHBoxLayout> 00029 #include <QtGui/QToolButton> 00030 00031 #include <kabc/addressee.h> 00032 #include <kdialog.h> 00033 #include <klineedit.h> 00034 #include <klocale.h> 00035 00036 NameEditWidget::NameEditWidget( QWidget *parent ) 00037 : QWidget( parent ) 00038 { 00039 QHBoxLayout *layout = new QHBoxLayout( this ); 00040 layout->setMargin( 0 ); 00041 layout->setSpacing( KDialog::spacingHint() ); 00042 00043 mNameEdit = new KLineEdit; 00044 layout->addWidget( mNameEdit ); 00045 00046 QToolButton *button = new QToolButton; 00047 button->setText( i18n( "..." ) ); 00048 layout->addWidget( button ); 00049 00050 connect( mNameEdit, SIGNAL(textChanged(QString)), this, SLOT(textChanged(QString)) ); 00051 connect( button, SIGNAL(clicked()), this, SLOT(openNameEditDialog()) ); 00052 } 00053 00054 NameEditWidget::~NameEditWidget() 00055 { 00056 } 00057 00058 void NameEditWidget::setReadOnly( bool readOnly ) 00059 { 00060 mNameEdit->setReadOnly( readOnly ); 00061 } 00062 00063 void NameEditWidget::loadContact( const KABC::Addressee &contact ) 00064 { 00065 mContact = contact; 00066 00067 disconnect( mNameEdit, SIGNAL(textChanged(QString)), this, SLOT(textChanged(QString)) ); 00068 mNameEdit->setText( contact.assembledName() ); 00069 connect( mNameEdit, SIGNAL(textChanged(QString)), this, SLOT(textChanged(QString)) ); 00070 } 00071 00072 void NameEditWidget::storeContact( KABC::Addressee &contact ) const 00073 { 00074 contact.setPrefix( mContact.prefix() ); 00075 contact.setGivenName( mContact.givenName() ); 00076 contact.setAdditionalName( mContact.additionalName() ); 00077 contact.setFamilyName( mContact.familyName() ); 00078 contact.setSuffix( mContact.suffix() ); 00079 } 00080 00081 void NameEditWidget::textChanged( const QString &text ) 00082 { 00083 mContact.setNameFromString( text ); 00084 00085 emit nameChanged( mContact ); 00086 } 00087 00088 void NameEditWidget::openNameEditDialog() 00089 { 00090 QPointer<NameEditDialog> dlg = new NameEditDialog( this ); 00091 00092 dlg->setPrefix( mContact.prefix() ); 00093 dlg->setGivenName( mContact.givenName() ); 00094 dlg->setAdditionalName( mContact.additionalName() ); 00095 dlg->setFamilyName( mContact.familyName() ); 00096 dlg->setSuffix( mContact.suffix() ); 00097 00098 if ( dlg->exec() == QDialog::Accepted ) { 00099 mContact.setPrefix( dlg->prefix() ); 00100 mContact.setGivenName( dlg->givenName() ); 00101 mContact.setAdditionalName( dlg->additionalName() ); 00102 mContact.setFamilyName( dlg->familyName() ); 00103 mContact.setSuffix( dlg->suffix() ); 00104 00105 disconnect( mNameEdit, SIGNAL(textChanged(QString)), this, SLOT(textChanged(QString)) ); 00106 mNameEdit->setText( mContact.assembledName() ); 00107 connect( mNameEdit, SIGNAL(textChanged(QString)), this, SLOT(textChanged(QString)) ); 00108 00109 emit nameChanged( mContact ); 00110 } 00111 00112 delete dlg; 00113 } 00114 00115 #include "nameeditwidget.moc"
This file is part of the KDE documentation.
Documentation copyright © 1996-2012 The KDE developers.
Generated on Tue May 8 2012 00:00:45 by doxygen 1.8.0 written by Dimitri van Heesch, © 1997-2006
Documentation copyright © 1996-2012 The KDE developers.
Generated on Tue May 8 2012 00:00:45 by doxygen 1.8.0 written by Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.