resourcenetconfig.cpp

00001 /*
00002     This file is part of libkabc.
00003     Copyright (c) 2003 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., 51 Franklin Street, Fifth Floor,
00018     Boston, MA 02110-1301, USA.
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"
KDE Home | KDE Accessibility Home | Description of Access Keys