Need to store config when changing units, if not very bad things happen
[kdepim.git] / kaddressbook / simpleaddresseeeditor.cpp
blobe377feeedbfff1082a655dd6ad7baa784b40131e
1 /*
2 This file is part of KAddressBook.
3 Copyright (c) 2002 Mike Pilone <mpilone@slac.com>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 As a special exception, permission is given to link this program
20 with any edition of Qt, and distribute the resulting executable,
21 without including the source code for Qt in the source distribution.
24 #include <qlayout.h>
25 #include <qlabel.h>
27 #include <klineedit.h>
28 #include <klocale.h>
29 #include <kdialog.h>
31 #include "simpleaddresseeeditor.h"
33 SimpleAddresseeEditor::SimpleAddresseeEditor( QWidget *parent, const char *name )
34 : AddresseeEditorBase( parent, name ),
35 mDirty( false ),
36 mBlockModified( false )
38 kdDebug(5720) << "SimpleAddresseeEditor()" << endl;
40 initGui();
43 SimpleAddresseeEditor::~SimpleAddresseeEditor()
45 kdDebug(5720) << "~SimpleAddresseeEditor()" << endl;
48 void SimpleAddresseeEditor::setAddressee( const KABC::Addressee &addr )
50 mAddressee = addr;
52 load();
55 const KABC::Addressee &SimpleAddresseeEditor::addressee()
57 return mAddressee;
60 void SimpleAddresseeEditor::setInitialFocus()
62 mNameEdit->setFocus();
65 void SimpleAddresseeEditor::initGui()
67 QGridLayout *topLayout = new QGridLayout( this, 2, 2, KDialog::marginHint(),
68 KDialog::spacingHint() );
70 QLabel *label = new QLabel( i18n( "Name:" ), this );
71 topLayout->addWidget( label, 0, 0 );
73 mNameEdit = new KLineEdit( this );
74 topLayout->addWidget( mNameEdit, 0, 1 );
75 connect( mNameEdit, SIGNAL( textChanged( const QString & ) ),
76 SLOT( emitModified() ) );
78 label = new QLabel( i18n( "Email:" ), this );
79 topLayout->addWidget( label, 1, 0 );
81 mEmailEdit = new KLineEdit( this );
82 topLayout->addWidget( mEmailEdit, 1, 1 );
83 connect( mEmailEdit, SIGNAL( textChanged( const QString & ) ),
84 SLOT( emitModified() ) );
87 void SimpleAddresseeEditor::load()
89 kdDebug(5720) << "SimpleAddresseeEditor::load()" << endl;
91 kdDebug(5720) << "ASSEMBLED NAME: " << mAddressee.assembledName() << endl;
92 kdDebug(5720) << "EMAIL NAME: " << mAddressee.preferredEmail() << endl;
94 mBlockModified = true;
96 mNameEdit->setText( mAddressee.assembledName() );
97 mEmailEdit->setText( mAddressee.preferredEmail() );
99 mBlockModified = false;
101 mDirty = false;
104 void SimpleAddresseeEditor::save()
106 if ( !mDirty ) return;
108 mAddressee.setNameFromString( mNameEdit->text() );
109 mAddressee.insertEmail( mEmailEdit->text(), true );
111 mDirty = false;
114 bool SimpleAddresseeEditor::dirty()
116 return mDirty;
119 void SimpleAddresseeEditor::emitModified()
121 if ( mBlockModified )
122 return;
124 mDirty = true;
126 emit modified();
129 #include "simpleaddresseeeditor.moc"