kaddressbook Library API Documentation

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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, 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()->mEditorType == KABPrefs::SimpleEditor ) {
00054     mEditorWidget = new SimpleAddresseeEditor( core, false, page );
00055   } else {
00056     mEditorWidget = new AddresseeEditorWidget( core, false, page );
00057   }
00058   connect( mEditorWidget, SIGNAL( modified( const KABC::Addressee::List& ) ),
00059            SLOT( widgetModified() ) );
00060   layout->addWidget( mEditorWidget );
00061 
00062   enableButton( KDialogBase::Apply, false );
00063 
00064   KConfig config( "kaddressbookrc" );
00065   config.setGroup( "AddresseeEditor" );
00066   QSize defaultSize( 750, 570 );
00067   resize( config.readSizeEntry( "Size", &defaultSize ) );
00068 }
00069 
00070 AddresseeEditorDialog::~AddresseeEditorDialog()
00071 {
00072   kdDebug(5720) << "~AddresseeEditorDialog()" << endl;
00073 
00074   KConfig config( "kaddressbookrc" );
00075   config.setGroup( "AddresseeEditor" );
00076   config.writeEntry( "Size", size() );
00077 
00078   emit editorDestroyed( mEditorWidget->addressee().uid() );
00079 }
00080 
00081 void AddresseeEditorDialog::setAddressee( const KABC::Addressee &addr )
00082 {
00083   enableButton( KDialogBase::Apply, false );
00084 
00085   mEditorWidget->setAddressee( addr );
00086   mEditorWidget->setInitialFocus();
00087 }
00088 
00089 KABC::Addressee AddresseeEditorDialog::addressee()
00090 {
00091   return mEditorWidget->addressee();
00092 }
00093 
00094 bool AddresseeEditorDialog::dirty()
00095 {
00096   return mEditorWidget->dirty();
00097 }
00098 
00099 void AddresseeEditorDialog::slotApply()
00100 {
00101   if ( mEditorWidget->dirty() ) {
00102     QApplication::setOverrideCursor( Qt::waitCursor );
00103     mEditorWidget->save();
00104     emit contactModified( mEditorWidget->addressee() );
00105     QApplication::restoreOverrideCursor();
00106   }
00107 
00108   enableButton( KDialogBase::Apply, false );
00109 
00110   KDialogBase::slotApply();
00111 }
00112 
00113 void AddresseeEditorDialog::slotOk()
00114 {
00115   slotApply();
00116 
00117   KDialogBase::slotOk();
00118 
00119   // Destroy this dialog
00120   delayedDestruct();
00121 }
00122 
00123 void AddresseeEditorDialog::widgetModified()
00124 {
00125   enableButton( KDialogBase::Apply, true );
00126 }
00127 
00128 void AddresseeEditorDialog::slotCancel()
00129 {
00130   KDialogBase::slotCancel();
00131 
00132   // Destroy this dialog
00133   delayedDestruct();
00134 }
00135 
00136 #include "addresseeeditordialog.moc"
KDE Logo
This file is part of the documentation for kaddressbook Library Version 3.3.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Fri Dec 21 14:24:09 2007 by doxygen 1.4.2 written by Dimitri van Heesch, © 1997-2003