kaddressbook

addresseeeditordialog.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 Qt, and distribute the resulting executable,
00021     without including the source code for Qt in the source distribution.
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   // Set this to be the group leader for all subdialogs - this means
00044   // modal subdialogs will only affect this dialog, not the other windows
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   // Destroy this dialog
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   // Destroy this dialog
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"
KDE Home | KDE Accessibility Home | Description of Access Keys