libkdepim Library API Documentation

resourceselectdialog.cpp

00001 /*
00002     This file is part of libkdepim.
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 
00024 #include <qgroupbox.h>
00025 #include <qlayout.h>
00026 
00027 #include "resourceselectdialog.h"
00028 #include "resourceselectdialog.moc"
00029 
00030 using namespace KPIM;
00031 
00032 ResourceSelectDialog::ResourceSelectDialog( QPtrList<Resource> list, QWidget *parent, const char *name )
00033     : KDialog( parent, name, true )
00034 {
00035   setCaption( i18n( "Resource Selection" ) );
00036   resize( 300, 200 );
00037 
00038   QVBoxLayout *mainLayout = new QVBoxLayout( this );
00039   mainLayout->setMargin( marginHint() );
00040 
00041   QGroupBox *groupBox = new QGroupBox( 2, Qt::Horizontal,  this );
00042   groupBox->setTitle( i18n( "Resources" ) );
00043 
00044   mResourceId = new KListBox( groupBox );
00045 
00046   mainLayout->addWidget( groupBox );
00047 
00048   mainLayout->addSpacing( 10 );
00049 
00050   KButtonBox *buttonBox = new KButtonBox( this );
00051 
00052   buttonBox->addStretch();
00053   buttonBox->addButton( i18n( "&OK" ), this, SLOT( accept() ) );
00054   buttonBox->addButton( i18n( "&Cancel" ), this, SLOT( reject() ) );
00055   buttonBox->layout();
00056 
00057   mainLayout->addWidget( buttonBox );
00058 
00059   // setup listbox
00060   uint counter = 0;
00061   for ( uint i = 0; i < list.count(); ++i ) {
00062     Resource *resource = list.at( i );
00063     if ( resource && !resource->readOnly() ) {
00064       mResourceMap.insert( counter, resource );
00065       mResourceId->insertItem( QString( resource->name() ) + " " +
00066                   ( resource->fastResource() ? i18n( "(search)" ) :
00067                                                QString( "" ) ) );
00068       counter++;
00069     }
00070   }
00071 
00072   mResourceId->setCurrentItem( 0 );
00073 }
00074 /*
00075 ResourceSelectDialog::~ResourceSelectDialog()
00076 {
00077 }
00078 */
00079 Resource *ResourceSelectDialog::resource()
00080 {
00081   if ( mResourceId->currentItem() != -1 )
00082     return mResourceMap[ mResourceId->currentItem() ];
00083   else
00084     return 0;
00085 }
00086 
00087 Resource *ResourceSelectDialog::getResource( QPtrList<Resource> list, QWidget *parent )
00088 {
00089   if ( list.count() == 1 ) return list.first();
00090 
00091   ResourceSelectDialog dlg( list, parent );
00092   if ( dlg.exec() == KDialog::Accepted ) return dlg.resource();
00093   else return 0;
00094 }
00095 
KDE Logo
This file is part of the documentation for kdelibs Version 3.1.4.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Sat Oct 18 02:47:00 2003 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001