resourcenetconfig.cpp00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <qlabel.h>
00022 #include <qlayout.h>
00023
00024 #include <kdebug.h>
00025 #include <klocale.h>
00026 #include <kdialog.h>
00027
00028 #include "formatfactory.h"
00029 #include "resourcenet.h"
00030 #include "stdaddressbook.h"
00031
00032 #include "resourcenetconfig.h"
00033
00034 using namespace KABC;
00035
00036 ResourceNetConfig::ResourceNetConfig( QWidget* parent, const char* name )
00037 : ConfigWidget( parent, name ), mInEditMode( false )
00038 {
00039 QGridLayout *mainLayout = new QGridLayout( this, 2, 2, 0,
00040 KDialog::spacingHint() );
00041
00042 QLabel *label = new QLabel( i18n( "Format:" ), this );
00043 mFormatBox = new KComboBox( this );
00044
00045 mainLayout->addWidget( label, 0, 0 );
00046 mainLayout->addWidget( mFormatBox, 0, 1 );
00047
00048 label = new QLabel( i18n( "Location:" ), this );
00049 mUrlEdit = new KURLRequester( this );
00050 mUrlEdit->setMode( KFile::File );
00051
00052 mainLayout->addWidget( label, 1, 0 );
00053 mainLayout->addWidget( mUrlEdit, 1, 1 );
00054
00055 FormatFactory *factory = FormatFactory::self();
00056 QStringList formats = factory->formats();
00057 QStringList::Iterator it;
00058 for ( it = formats.begin(); it != formats.end(); ++it ) {
00059 FormatInfo *info = factory->info( *it );
00060 if ( info ) {
00061 mFormatTypes << (*it);
00062 mFormatBox->insertItem( info->nameLabel );
00063 }
00064 }
00065 }
00066
00067 void ResourceNetConfig::setEditMode( bool value )
00068 {
00069 mFormatBox->setEnabled( !value );
00070 mInEditMode = value;
00071 }
00072
00073 void ResourceNetConfig::loadSettings( KRES::Resource *res )
00074 {
00075 ResourceNet *resource = dynamic_cast<ResourceNet*>( res );
00076
00077 if ( !resource ) {
00078 kdDebug(5700) << "ResourceNetConfig::loadSettings(): cast failed" << endl;
00079 return;
00080 }
00081
00082 mFormatBox->setCurrentItem( mFormatTypes.findIndex( resource->format() ) );
00083
00084 mUrlEdit->setURL( resource->url().url() );
00085 }
00086
00087 void ResourceNetConfig::saveSettings( KRES::Resource *res )
00088 {
00089 ResourceNet *resource = dynamic_cast<ResourceNet*>( res );
00090
00091 if ( !resource ) {
00092 kdDebug(5700) << "ResourceNetConfig::saveSettings(): cast failed" << endl;
00093 return;
00094 }
00095
00096 if ( !mInEditMode )
00097 resource->setFormat( mFormatTypes[ mFormatBox->currentItem() ] );
00098
00099 resource->setUrl( KURL( mUrlEdit->url() ) );
00100 }
00101
00102 #include "resourcenetconfig.moc"
|