kaddressbook

simpleaddresseeeditor.cpp
1/*
2 This file is part of KAddressBook.
3 Copyright (c) 2002 Mike Pilone <mpilone@slac.com>
4
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.
9
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.
14
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.
18
19 As a special exception, permission is given to link this program
20 with any edition of TQt, and distribute the resulting executable,
21 without including the source code for TQt in the source distribution.
22*/
23
24#include <tqlayout.h>
25#include <tqlabel.h>
26
27#include <klineedit.h>
28#include <tdelocale.h>
29#include <kdialog.h>
30
31#include "simpleaddresseeeditor.h"
32
33SimpleAddresseeEditor::SimpleAddresseeEditor( TQWidget *parent, const char *name )
34 : AddresseeEditorBase( parent, name ),
35 mDirty( false ),
36 mBlockModified( false )
37{
38 kdDebug(5720) << "SimpleAddresseeEditor()" << endl;
39
40 initGui();
41}
42
43SimpleAddresseeEditor::~SimpleAddresseeEditor()
44{
45 kdDebug(5720) << "~SimpleAddresseeEditor()" << endl;
46}
47
48void SimpleAddresseeEditor::setAddressee( const TDEABC::Addressee &addr )
49{
50 mAddressee = addr;
51
52 load();
53}
54
55const TDEABC::Addressee &SimpleAddresseeEditor::addressee()
56{
57 return mAddressee;
58}
59
60void SimpleAddresseeEditor::setInitialFocus()
61{
62 mNameEdit->setFocus();
63}
64
65void SimpleAddresseeEditor::initGui()
66{
67 TQGridLayout *topLayout = new TQGridLayout( this, 2, 2, KDialog::marginHint(),
68 KDialog::spacingHint() );
69
70 TQLabel *label = new TQLabel( i18n( "Name:" ), this );
71 topLayout->addWidget( label, 0, 0 );
72
73 mNameEdit = new KLineEdit( this );
74 topLayout->addWidget( mNameEdit, 0, 1 );
75 connect( mNameEdit, TQ_SIGNAL( textChanged( const TQString & ) ),
76 TQ_SLOT( emitModified() ) );
77
78 label = new TQLabel( i18n( "Email:" ), this );
79 topLayout->addWidget( label, 1, 0 );
80
81 mEmailEdit = new KLineEdit( this );
82 topLayout->addWidget( mEmailEdit, 1, 1 );
83 connect( mEmailEdit, TQ_SIGNAL( textChanged( const TQString & ) ),
84 TQ_SLOT( emitModified() ) );
85}
86
87void SimpleAddresseeEditor::load()
88{
89 kdDebug(5720) << "SimpleAddresseeEditor::load()" << endl;
90
91 kdDebug(5720) << "ASSEMBLED NAME: " << mAddressee.assembledName() << endl;
92 kdDebug(5720) << "EMAIL NAME: " << mAddressee.preferredEmail() << endl;
93
94 mBlockModified = true;
95
96 mNameEdit->setText( mAddressee.assembledName() );
97 mEmailEdit->setText( mAddressee.preferredEmail() );
98
99 mBlockModified = false;
100
101 mDirty = false;
102}
103
104void SimpleAddresseeEditor::save()
105{
106 if ( !mDirty ) return;
107
108 mAddressee.setNameFromString( mNameEdit->text() );
109 mAddressee.insertEmail( mEmailEdit->text(), true );
110
111 mDirty = false;
112}
113
114bool SimpleAddresseeEditor::dirty()
115{
116 return mDirty;
117}
118
119void SimpleAddresseeEditor::emitModified()
120{
121 if ( mBlockModified )
122 return;
123
124 mDirty = true;
125
126 emit modified();
127}
128
129#include "simpleaddresseeeditor.moc"