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