kabc
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 "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/QFormLayout> 00032 00033 using namespace KABC; 00034 00035 ResourceNetConfig::ResourceNetConfig( QWidget *parent ) 00036 : ConfigWidget( parent ), mInEditMode( false ) 00037 { 00038 QFormLayout *mainLayout = new QFormLayout( this ); 00039 mainLayout->setMargin( 0 ); 00040 00041 mFormatBox = new KComboBox( this ); 00042 00043 mainLayout->addRow( i18n( "Format:" ), mFormatBox ); 00044 00045 mUrlEdit = new KUrlRequester( this ); 00046 mUrlEdit->setMode( KFile::File ); 00047 00048 mainLayout->addRow( i18n( "Location:" ), mUrlEdit ); 00049 00050 FormatFactory *factory = FormatFactory::self(); 00051 QStringList formats = factory->formats(); 00052 QStringList::Iterator it; 00053 for ( it = formats.begin(); it != formats.end(); ++it ) { 00054 FormatInfo info = factory->info( *it ); 00055 if ( !info.isNull() ) { 00056 mFormatTypes << (*it); 00057 mFormatBox->addItem( info.nameLabel ); 00058 } 00059 } 00060 } 00061 00062 void ResourceNetConfig::setEditMode( bool value ) 00063 { 00064 mFormatBox->setEnabled( !value ); 00065 mInEditMode = value; 00066 } 00067 00068 void ResourceNetConfig::loadSettings( KRES::Resource *res ) 00069 { 00070 ResourceNet *resource = dynamic_cast<ResourceNet*>( res ); 00071 00072 if ( !resource ) { 00073 kDebug() << "cast failed"; 00074 return; 00075 } 00076 00077 mFormatBox->setCurrentIndex( mFormatTypes.indexOf( resource->format() ) ); 00078 00079 mUrlEdit->setUrl( resource->url() ); 00080 } 00081 00082 void ResourceNetConfig::saveSettings( KRES::Resource *res ) 00083 { 00084 ResourceNet *resource = dynamic_cast<ResourceNet*>( res ); 00085 00086 if ( !resource ) { 00087 kDebug() << "cast failed"; 00088 return; 00089 } 00090 00091 if ( !mInEditMode ) { 00092 resource->setFormat( mFormatTypes[ mFormatBox->currentIndex() ] ); 00093 } 00094 00095 resource->setUrl( KUrl( mUrlEdit->url() ) ); 00096 } 00097 00098 #include "resourcenetconfig.moc"
This file is part of the KDE documentation.
Documentation copyright © 1996-2012 The KDE developers.
Generated on Thu Aug 2 2012 15:26:08 by doxygen 1.7.5 written by Dimitri van Heesch, © 1997-2006
Documentation copyright © 1996-2012 The KDE developers.
Generated on Thu Aug 2 2012 15:26:08 by doxygen 1.7.5 written by Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.