kaddressbook
addresseeeditordialog.cpp00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include <qapplication.h>
00025 #include <qlayout.h>
00026
00027 #include <kdebug.h>
00028 #include <klocale.h>
00029
00030 #include "core.h"
00031 #include "addresseeeditorwidget.h"
00032 #include "simpleaddresseeeditor.h"
00033 #include "kabprefs.h"
00034
00035 #include "addresseeeditordialog.h"
00036
00037 AddresseeEditorDialog::AddresseeEditorDialog( KAB::Core *core,
00038 QWidget *parent, const char *name )
00039 : KDialogBase( KDialogBase::Plain, i18n( "Edit Contact" ),
00040 KDialogBase::Ok | KDialogBase::Cancel | KDialogBase::Apply,
00041 KDialogBase::Ok, parent, name, false )
00042 {
00043
00044
00045 setWFlags( getWFlags() | WGroupLeader );
00046
00047 kdDebug(5720) << "AddresseeEditorDialog()" << endl;
00048
00049 QWidget *page = plainPage();
00050
00051 QVBoxLayout *layout = new QVBoxLayout( page );
00052
00053 if ( KABPrefs::instance()->editorType() == KABPrefs::SimpleEditor ) {
00054 mEditorWidget = new SimpleAddresseeEditor( page );
00055 } else {
00056 mEditorWidget = new AddresseeEditorWidget( page );
00057 }
00058 connect( mEditorWidget, SIGNAL( modified() ), SLOT( widgetModified() ) );
00059 layout->addWidget( mEditorWidget );
00060
00061 enableButton( KDialogBase::Apply, false );
00062
00063 KConfig config( "kaddressbookrc" );
00064 config.setGroup( "AddresseeEditor" );
00065 QSize defaultSize( 750, 570 );
00066 resize( config.readSizeEntry( "Size", &defaultSize ) );
00067 }
00068
00069 AddresseeEditorDialog::~AddresseeEditorDialog()
00070 {
00071 kdDebug(5720) << "~AddresseeEditorDialog()" << endl;
00072
00073 KConfig config( "kaddressbookrc" );
00074 config.setGroup( "AddresseeEditor" );
00075 config.writeEntry( "Size", size() );
00076
00077 emit editorDestroyed( mEditorWidget->addressee().uid() );
00078 }
00079
00080 void AddresseeEditorDialog::setAddressee( const KABC::Addressee &addr )
00081 {
00082 enableButton( KDialogBase::Apply, false );
00083
00084 setTitle( addr );
00085
00086 mEditorWidget->setAddressee( addr );
00087 mEditorWidget->setInitialFocus();
00088 }
00089
00090 KABC::Addressee AddresseeEditorDialog::addressee()
00091 {
00092 return mEditorWidget->addressee();
00093 }
00094
00095 bool AddresseeEditorDialog::dirty()
00096 {
00097 return mEditorWidget->dirty();
00098 }
00099
00100 void AddresseeEditorDialog::slotApply()
00101 {
00102 if ( !mEditorWidget->readyToClose() )
00103 return;
00104
00105 if ( mEditorWidget->dirty() ) {
00106 QApplication::setOverrideCursor( Qt::waitCursor );
00107 mEditorWidget->save();
00108 emit contactModified( mEditorWidget->addressee() );
00109 QApplication::restoreOverrideCursor();
00110 }
00111
00112 enableButton( KDialogBase::Apply, false );
00113
00114 KDialogBase::slotApply();
00115 }
00116
00117 void AddresseeEditorDialog::slotOk()
00118 {
00119 if ( !mEditorWidget->readyToClose() )
00120 return;
00121
00122 slotApply();
00123
00124 KDialogBase::slotOk();
00125
00126
00127 delayedDestruct();
00128 }
00129
00130 void AddresseeEditorDialog::widgetModified()
00131 {
00132 const KABC::Addressee addressee = mEditorWidget->addressee();
00133 if ( !addressee.isEmpty() )
00134 setTitle( addressee );
00135
00136 enableButton( KDialogBase::Apply, true );
00137 }
00138
00139 void AddresseeEditorDialog::slotCancel()
00140 {
00141 KDialogBase::slotCancel();
00142
00143
00144 delayedDestruct();
00145 }
00146
00147 void AddresseeEditorDialog::setTitle( const KABC::Addressee &addr )
00148 {
00149 if ( !addr.realName().isEmpty() )
00150 setCaption( i18n( "Edit Contact '%1'" ).arg( addr.realName() ) );
00151 }
00152
00153 #include "addresseeeditordialog.moc"
|