resourceselectdialog.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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
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
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
This file is part of the documentation for kdelibs Version 3.1.4.