kabc Library API Documentation

resourceselectdialog.cpp

00001 /*
00002     This file is part of libkabc.
00003     Copyright (c) 2002 Tobias Koenig <tokoe@kde.org>
00004 
00005     This library is free software; you can redistribute it and/or
00006     modify it under the terms of the GNU Library General Public
00007     License as published by the Free Software Foundation; either
00008     version 2 of the License, or (at your option) any later version.
00009 
00010     This library 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 GNU
00013     Library General Public License for more details.
00014 
00015     You should have received a copy of the GNU Library General Public License
00016     along with this library; see the file COPYING.LIB.  If not, write to
00017     the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00018     Boston, MA 02111-1307, USA.
00019 */
00020 
00021 #include <klocale.h>
00022 #include <kbuttonbox.h>
00023 #include <klistbox.h>
00024 
00025 #include <qgroupbox.h>
00026 #include <qlayout.h>
00027 
00028 #include <kglobalsettings.h>
00029 #include <kiconloader.h>
00030 #include <qpushbutton.h>
00031 
00032 #include "resource.h"
00033 #include "addressbook.h"
00034 
00035 #include "resourceselectdialog.h"
00036 
00037 using namespace KABC;
00038 
00039 ResourceSelectDialog::ResourceSelectDialog( AddressBook *ab, QWidget *parent, const char *name )
00040     : KDialog( parent, name, true )
00041 {
00042   setCaption( i18n( "Resource Selection" ) );
00043   resize( 300, 200 );
00044 
00045   QVBoxLayout *mainLayout = new QVBoxLayout( this );
00046   mainLayout->setMargin( marginHint() );
00047 
00048   QGroupBox *groupBox = new QGroupBox( 2, Qt::Horizontal,  this );
00049   groupBox->setTitle( i18n( "Resources" ) );
00050 
00051   mResourceId = new KListBox( groupBox );
00052 
00053   mainLayout->addWidget( groupBox );
00054 
00055   mainLayout->addSpacing( 10 );
00056 
00057   KButtonBox *buttonBox = new KButtonBox( this );
00058 
00059   buttonBox->addStretch();
00060   QPushButton* ok = buttonBox->addButton( i18n( "&OK" ), this, SLOT( accept() ) );
00061   QPushButton* cancel = buttonBox->addButton( i18n( "&Cancel" ), this, SLOT( reject() ) );
00062   if (KGlobalSettings::showIconsOnPushButtons()) {
00063     ok->setIconSet( SmallIconSet("button_ok") );
00064     cancel->setIconSet( SmallIconSet("button_cancel") );
00065   }
00066 
00067   buttonBox->layout();
00068 
00069   mainLayout->addWidget( buttonBox );
00070 
00071   // setup listbox
00072   uint counter = 0;
00073   QPtrList<Resource> list = ab->resources();
00074   for ( uint i = 0; i < list.count(); ++i ) {
00075     Resource *resource = list.at( i );
00076     if ( resource && !resource->readOnly() ) {
00077       mResourceMap.insert( counter, resource );
00078       mResourceId->insertItem( resource->resourceName() );
00079       counter++;
00080     }
00081   }
00082 
00083   mResourceId->setCurrentItem( 0 );
00084 }
00085 
00086 Resource *ResourceSelectDialog::resource()
00087 {
00088   if ( mResourceId->currentItem() != -1 )
00089     return mResourceMap[ mResourceId->currentItem() ];
00090   else
00091     return 0;
00092 }
00093 
00094 Resource *ResourceSelectDialog::getResource( AddressBook *ab, QWidget *parent )
00095 {
00096   QPtrList<Resource> resources = ab->resources();
00097   if ( resources.count() == 1 ) return resources.first();
00098 
00099   Resource *found = 0;
00100   Resource *r = resources.first();
00101   while( r ) {
00102     if ( !r->readOnly() ) {
00103       if ( found ) {
00104         found = 0;
00105         break;
00106       } else {
00107         found = r;
00108       }
00109     }
00110     r = resources.next();
00111   }
00112   if ( found ) return found;
00113 
00114   ResourceSelectDialog dlg( ab, parent );
00115   if ( dlg.exec() == KDialog::Accepted ) return dlg.resource();
00116   else return 0;
00117 }
00118 
00119 #include "resourceselectdialog.moc"
KDE Logo
This file is part of the documentation for kabc Library Version 3.2.3.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Aug 4 05:28:14 2004 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2003