kaddressbook Library API Documentation

simpleaddresseeeditor.cpp

00001 /* 00002 This file is part of KAddressBook. 00003 Copyright (c) 2002 Mike Pilone <mpilone@slac.com> 00004 00005 This program is free software; you can redistribute it and/or modify 00006 it under the terms of the GNU General Public License as published by 00007 the Free Software Foundation; either version 2 of the License, or 00008 (at your option) any later version. 00009 00010 This program is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 GNU General Public License for more details. 00014 00015 You should have received a copy of the GNU General Public License 00016 along with this program; if not, write to the Free Software 00017 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00018 00019 As a special exception, permission is given to link this program 00020 with any edition of Qt, and distribute the resulting executable, 00021 without including the source code for Qt in the source distribution. 00022 */ 00023 00024 #include <qlayout.h> 00025 #include <qlabel.h> 00026 00027 #include <klineedit.h> 00028 #include <klocale.h> 00029 #include <kdialog.h> 00030 00031 #include "simpleaddresseeeditor.h" 00032 00033 SimpleAddresseeEditor::SimpleAddresseeEditor( KAB::Core *core, bool isExtension, 00034 QWidget *parent, const char *name ) 00035 : AddresseeEditorBase( core, isExtension, parent, name ), mDirty( false ), 00036 mBlockModified( false ) 00037 { 00038 kdDebug(5720) << "SimpleAddresseeEditor()" << endl; 00039 00040 initGui(); 00041 00042 // Load the empty addressee as defaults 00043 load(); 00044 00045 mDirty = false; 00046 } 00047 00048 SimpleAddresseeEditor::~SimpleAddresseeEditor() 00049 { 00050 kdDebug(5720) << "~SimpleAddresseeEditor()" << endl; 00051 } 00052 00053 void SimpleAddresseeEditor::setAddressee( const KABC::Addressee &addr ) 00054 { 00055 mAddressee = addr; 00056 00057 load(); 00058 } 00059 00060 const KABC::Addressee &SimpleAddresseeEditor::addressee() 00061 { 00062 return mAddressee; 00063 } 00064 00065 void SimpleAddresseeEditor::setInitialFocus() 00066 { 00067 mNameEdit->setFocus(); 00068 } 00069 00070 void SimpleAddresseeEditor::initGui() 00071 { 00072 QGridLayout *topLayout = new QGridLayout( this, 2, 2, KDialog::marginHint(), 00073 KDialog::spacingHint() ); 00074 00075 QLabel *label = new QLabel( i18n("Name:" ), this ); 00076 topLayout->addWidget( label, 0, 0 ); 00077 00078 mNameEdit = new KLineEdit( this ); 00079 topLayout->addWidget( mNameEdit, 0, 1 ); 00080 connect( mNameEdit, SIGNAL( textChanged( const QString & ) ), 00081 SLOT( emitModified() ) ); 00082 00083 label = new QLabel( i18n("Email:" ), this ); 00084 topLayout->addWidget( label, 1, 0 ); 00085 00086 mEmailEdit = new KLineEdit( this ); 00087 topLayout->addWidget( mEmailEdit, 1, 1 ); 00088 connect( mEmailEdit, SIGNAL( textChanged( const QString & ) ), 00089 SLOT( emitModified() ) ); 00090 } 00091 00092 void SimpleAddresseeEditor::load() 00093 { 00094 kdDebug(5720) << "SimpleAddresseeEditor::load()" << endl; 00095 00096 kdDebug(5720) << "ASSEMBLED NAME: " << mAddressee.assembledName() << endl; 00097 kdDebug(5720) << "EMAIL NAME: " << mAddressee.preferredEmail() << endl; 00098 00099 mBlockModified = true; 00100 00101 mNameEdit->setText( mAddressee.assembledName() ); 00102 00103 mEmailEdit->setText( mAddressee.preferredEmail() ); 00104 00105 mBlockModified = false; 00106 00107 mDirty = false; 00108 } 00109 00110 void SimpleAddresseeEditor::save() 00111 { 00112 if ( !mDirty ) return; 00113 00114 mAddressee.setNameFromString( mNameEdit->text() ); 00115 mAddressee.insertEmail( mEmailEdit->text(), true ); 00116 00117 mDirty = false; 00118 } 00119 00120 bool SimpleAddresseeEditor::dirty() 00121 { 00122 return mDirty; 00123 } 00124 00125 QString SimpleAddresseeEditor::title() const 00126 { 00127 return i18n( "Simple Contact Editor" ); 00128 } 00129 00130 QString SimpleAddresseeEditor::identifier() const 00131 { 00132 return "simple_contact_editor"; 00133 } 00134 00135 void SimpleAddresseeEditor::emitModified() 00136 { 00137 mDirty = true; 00138 00139 KABC::Addressee::List list; 00140 00141 if ( isExtension() && !mBlockModified ) { 00142 save(); 00143 list.append( mAddressee ); 00144 } 00145 00146 emit modified( list ); 00147 } 00148 00149 #include "simpleaddresseeeditor.moc"
KDE Logo
This file is part of the documentation for kaddressbook Library Version 3.3.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Fri Aug 27 12:51:16 2004 by doxygen 1.3.8 written by Dimitri van Heesch, © 1997-2003