kaddressbook Library API Documentation

detailsviewcontainer.cpp

00001 /*                                                                      
00002     This file is part of KAddressBook.
00003     Copyright (c) 1996-2002 Mirko Boehm <mirko@kde.org>
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 <qcombobox.h>
00025 #include <qframe.h>
00026 #include <qlabel.h>
00027 #include <qlayout.h>
00028 #include <qwidgetstack.h>
00029 
00030 #include <kapplication.h>
00031 #include <kdebug.h>
00032 #include <kdialog.h>
00033 
00034 #include "look_basic.h"
00035 //#include "look_details.h"
00036 #include "look_html.h"
00037 
00038 #include "detailsviewcontainer.h"
00039 
00040 ViewContainer::ViewContainer( QWidget *parent, const char* name )
00041   : QWidget( parent, name ), mCurrentLook( 0 )
00042 {
00043   QBoxLayout *topLayout = new QVBoxLayout( this );
00044   topLayout->setMargin( KDialog::marginHint() );
00045   topLayout->setSpacing( KDialog::spacingHint() );
00046 
00047   QBoxLayout *styleLayout = new QHBoxLayout( topLayout );    
00048 
00049   QLabel *label = new QLabel( i18n("Style:"), this );
00050   styleLayout->addWidget( label );
00051 
00052   mStyleCombo = new QComboBox( this );
00053   styleLayout->addWidget( mStyleCombo );
00054 
00055   QFrame *frameRuler = new QFrame( this );
00056   frameRuler->setFrameShape( QFrame::HLine );
00057   frameRuler->setFrameShadow( QFrame::Sunken );
00058   topLayout->addWidget( frameRuler );
00059 
00060   mDetailsStack = new QWidgetStack( this );
00061   topLayout->addWidget( mDetailsStack, 1 );
00062 
00063   registerLooks();
00064 
00065 #if 1
00066     // Hide detailed view selection combo box, because we currently have
00067     // only one. Reenable it when there are more detailed views.
00068     label->hide();
00069     mStyleCombo->hide();
00070     frameRuler->hide();
00071 #endif
00072 }
00073 
00074 KABBasicLook *ViewContainer::currentLook()
00075 {
00076   return mCurrentLook;
00077 }
00078 
00079 void ViewContainer::registerLooks()
00080 {
00081   mLookFactories.append( new KABHtmlViewFactory( mDetailsStack ) );
00082 //  mLookFactories.append( new KABDetailedViewFactory( mDetailsStack ) );
00083   mStyleCombo->clear();
00084 
00085   for ( uint i = 0; i < mLookFactories.count(); ++i )
00086     mStyleCombo->insertItem( mLookFactories.at( i )->description() );
00087 
00088   if ( !mLookFactories.isEmpty() )
00089     slotStyleSelected( 0 );
00090 }
00091 
00092 void ViewContainer::slotStyleSelected( int index )
00093 {
00094   KConfig *config = kapp->config();
00095   KABC::Addressee addr;
00096 
00097   if ( index >= 0 && index < mStyleCombo->count() ) {
00098     if ( mCurrentLook != 0 ) {
00099       mCurrentLook->saveSettings( config );
00100       addr = mCurrentLook->addressee();
00101 
00102       delete mCurrentLook;
00103       mCurrentLook = 0;
00104     }
00105 
00106     KABLookFactory *factory = mLookFactories.at( index );
00107     kdDebug(5720) << "ViewContainer::slotStyleSelected: "
00108                   << "creating look "
00109                   << factory->description() << endl;
00110 
00111     mCurrentLook = factory->create();
00112     mDetailsStack->raiseWidget( mCurrentLook );
00113 
00114     connect( mCurrentLook, SIGNAL( sendEmail( const QString& ) ), this,
00115              SIGNAL( sendEmail( const QString& ) ) );
00116     connect( mCurrentLook, SIGNAL( browse( const QString& ) ), this,
00117              SIGNAL( browse( const QString& ) ) );
00118   }
00119 
00120   mCurrentLook->restoreSettings( config );
00121   mCurrentLook->setAddressee( addr );
00122 }
00123 
00124 void ViewContainer::setAddressee( const KABC::Addressee& addressee )
00125 {
00126   if ( mCurrentLook != 0 ) {
00127     if ( addressee == mCurrentAddressee )
00128       return;
00129     else {
00130       mCurrentAddressee = addressee;
00131       mCurrentLook->setAddressee( mCurrentAddressee );
00132     }
00133   }
00134 }
00135 
00136 KABC::Addressee ViewContainer::addressee()
00137 {
00138   static KABC::Addressee empty; // do not use!
00139 
00140   if ( !mCurrentLook )
00141     return empty;
00142   else
00143     return mCurrentLook->addressee();
00144 }
00145 
00146 void ViewContainer::setReadOnly( bool state )
00147 {
00148   if ( mCurrentLook )
00149     mCurrentLook->setReadOnly( state );
00150 }
00151 
00152 #include "detailsviewcontainer.moc"
KDE Logo
This file is part of the documentation for kaddressbook Library Version 3.2.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat May 1 11:38:51 2004 by doxygen 1.2.15 written by Dimitri van Heesch, © 1997-2003