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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00018 00019 As a special exception, permission is given to link this program 00020 with any edition of TQt, and distribute the resulting executable, 00021 without including the source code for TQt in the source distribution. 00022 */ 00023 00024 #include <tqlayout.h> 00025 #include <tqlabel.h> 00026 00027 #include <klineedit.h> 00028 #include <klocale.h> 00029 #include <kdialog.h> 00030 00031 #include "simpleaddresseeeditor.h" 00032 00033 SimpleAddresseeEditor::SimpleAddresseeEditor( TQWidget *parent, const char *name ) 00034 : AddresseeEditorBase( parent, name ), 00035 mDirty( false ), 00036 mBlockModified( false ) 00037 { 00038 kdDebug(5720) << "SimpleAddresseeEditor()" << endl; 00039 00040 initGui(); 00041 } 00042 00043 SimpleAddresseeEditor::~SimpleAddresseeEditor() 00044 { 00045 kdDebug(5720) << "~SimpleAddresseeEditor()" << endl; 00046 } 00047 00048 void SimpleAddresseeEditor::setAddressee( const KABC::Addressee &addr ) 00049 { 00050 mAddressee = addr; 00051 00052 load(); 00053 } 00054 00055 const KABC::Addressee &SimpleAddresseeEditor::addressee() 00056 { 00057 return mAddressee; 00058 } 00059 00060 void SimpleAddresseeEditor::setInitialFocus() 00061 { 00062 mNameEdit->setFocus(); 00063 } 00064 00065 void SimpleAddresseeEditor::initGui() 00066 { 00067 TQGridLayout *topLayout = new TQGridLayout( this, 2, 2, KDialog::marginHint(), 00068 KDialog::spacingHint() ); 00069 00070 TQLabel *label = new TQLabel( i18n( "Name:" ), this ); 00071 topLayout->addWidget( label, 0, 0 ); 00072 00073 mNameEdit = new KLineEdit( this ); 00074 topLayout->addWidget( mNameEdit, 0, 1 ); 00075 connect( mNameEdit, TQT_SIGNAL( textChanged( const TQString & ) ), 00076 TQT_SLOT( emitModified() ) ); 00077 00078 label = new TQLabel( i18n( "Email:" ), this ); 00079 topLayout->addWidget( label, 1, 0 ); 00080 00081 mEmailEdit = new KLineEdit( this ); 00082 topLayout->addWidget( mEmailEdit, 1, 1 ); 00083 connect( mEmailEdit, TQT_SIGNAL( textChanged( const TQString & ) ), 00084 TQT_SLOT( emitModified() ) ); 00085 } 00086 00087 void SimpleAddresseeEditor::load() 00088 { 00089 kdDebug(5720) << "SimpleAddresseeEditor::load()" << endl; 00090 00091 kdDebug(5720) << "ASSEMBLED NAME: " << mAddressee.assembledName() << endl; 00092 kdDebug(5720) << "EMAIL NAME: " << mAddressee.preferredEmail() << endl; 00093 00094 mBlockModified = true; 00095 00096 mNameEdit->setText( mAddressee.assembledName() ); 00097 mEmailEdit->setText( mAddressee.preferredEmail() ); 00098 00099 mBlockModified = false; 00100 00101 mDirty = false; 00102 } 00103 00104 void SimpleAddresseeEditor::save() 00105 { 00106 if ( !mDirty ) return; 00107 00108 mAddressee.setNameFromString( mNameEdit->text() ); 00109 mAddressee.insertEmail( mEmailEdit->text(), true ); 00110 00111 mDirty = false; 00112 } 00113 00114 bool SimpleAddresseeEditor::dirty() 00115 { 00116 return mDirty; 00117 } 00118 00119 void SimpleAddresseeEditor::emitModified() 00120 { 00121 if ( mBlockModified ) 00122 return; 00123 00124 mDirty = true; 00125 00126 emit modified(); 00127 } 00128 00129 #include "simpleaddresseeeditor.moc"