kaddressbook

addresseeeditordialog.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 <tqapplication.h>
25#include <tqlayout.h>
26
27#include <kdebug.h>
28#include <tdelocale.h>
29
30#include "core.h"
31#include "addresseeeditorwidget.h"
32#include "simpleaddresseeeditor.h"
33#include "kabprefs.h"
34
35#include "addresseeeditordialog.h"
36
37AddresseeEditorDialog::AddresseeEditorDialog( KAB::Core *core,
38 TQWidget *parent, const char *name )
39 : KDialogBase( KDialogBase::Plain, i18n( "Edit Contact" ),
40 KDialogBase::Ok | KDialogBase::Cancel | KDialogBase::Apply,
41 KDialogBase::Ok, parent, name, false )
42{
43 // Set this to be the group leader for all subdialogs - this means
44 // modal subdialogs will only affect this dialog, not the other windows
45 setWFlags( getWFlags() | WGroupLeader );
46
47 kdDebug(5720) << "AddresseeEditorDialog()" << endl;
48
49 TQWidget *page = plainPage();
50
51 TQVBoxLayout *layout = new TQVBoxLayout( page );
52
53 if ( KABPrefs::instance()->editorType() == KABPrefs::SimpleEditor ) {
54 mEditorWidget = new SimpleAddresseeEditor( page );
55 } else {
56 mEditorWidget = new AddresseeEditorWidget( page );
57 }
58 connect( mEditorWidget, TQ_SIGNAL( modified() ), TQ_SLOT( widgetModified() ) );
59 layout->addWidget( mEditorWidget );
60
61 enableButton( KDialogBase::Apply, false );
62
63 TDEConfig config( "kaddressbookrc" );
64 config.setGroup( "AddresseeEditor" );
65 TQSize defaultSize( 750, 570 );
66 resize( config.readSizeEntry( "Size", &defaultSize ) );
67}
68
69AddresseeEditorDialog::~AddresseeEditorDialog()
70{
71 kdDebug(5720) << "~AddresseeEditorDialog()" << endl;
72
73 TDEConfig config( "kaddressbookrc" );
74 config.setGroup( "AddresseeEditor" );
75 config.writeEntry( "Size", size() );
76
77 emit editorDestroyed( mEditorWidget->addressee().uid() );
78}
79
80void AddresseeEditorDialog::setAddressee( const TDEABC::Addressee &addr )
81{
82 enableButton( KDialogBase::Apply, false );
83
84 setTitle( addr );
85
86 mEditorWidget->setAddressee( addr );
87 mEditorWidget->setInitialFocus();
88}
89
90TDEABC::Addressee AddresseeEditorDialog::addressee()
91{
92 return mEditorWidget->addressee();
93}
94
95bool AddresseeEditorDialog::dirty()
96{
97 return mEditorWidget->dirty();
98}
99
100void AddresseeEditorDialog::slotApply()
101{
102 if ( !mEditorWidget->readyToClose() )
103 return;
104
105 if ( mEditorWidget->dirty() ) {
106 TQApplication::setOverrideCursor( TQt::waitCursor );
107 mEditorWidget->save();
108 emit contactModified( mEditorWidget->addressee() );
109 TQApplication::restoreOverrideCursor();
110 }
111
112 enableButton( KDialogBase::Apply, false );
113
114 KDialogBase::slotApply();
115}
116
117void AddresseeEditorDialog::slotOk()
118{
119 if ( !mEditorWidget->readyToClose() )
120 return;
121
122 slotApply();
123
124 KDialogBase::slotOk();
125
126 // Destroy this dialog
127 delayedDestruct();
128}
129
130void AddresseeEditorDialog::widgetModified()
131{
132 const TDEABC::Addressee addressee = mEditorWidget->addressee();
133 if ( !addressee.isEmpty() )
134 setTitle( addressee );
135
136 enableButton( KDialogBase::Apply, true );
137}
138
139void AddresseeEditorDialog::slotCancel()
140{
141 KDialogBase::slotCancel();
142
143 // Destroy this dialog
144 delayedDestruct();
145}
146
147void AddresseeEditorDialog::setTitle( const TDEABC::Addressee &addr )
148{
149 if ( !addr.realName().isEmpty() )
150 setCaption( i18n( "Edit Contact '%1'" ).arg( addr.realName() ) );
151}
152
153#include "addresseeeditordialog.moc"