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
#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
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"