kabc
resourcedirconfig.cpp
00001 /* 00002 This file is part of libkabc. 00003 Copyright (c) 2002 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 "resourcedirconfig.h" 00022 #include "resourcedir.h" 00023 00024 #include "kabc/formatfactory.h" 00025 #include "kabc/stdaddressbook.h" 00026 00027 #include <kdebug.h> 00028 #include <klocale.h> 00029 #include <kstandarddirs.h> 00030 #include <kdialog.h> 00031 00032 #include <QtGui/QFormLayout> 00033 00034 using namespace KABC; 00035 00036 ResourceDirConfig::ResourceDirConfig( QWidget *parent ) 00037 : KRES::ConfigWidget( parent ) 00038 { 00039 QFormLayout *mainLayout = new QFormLayout( this ); 00040 mainLayout->setMargin( 0 ); 00041 00042 mFormatBox = new KComboBox( this ); 00043 00044 mainLayout->addRow( i18n( "Format:" ), mFormatBox ); 00045 00046 mFileNameEdit = new KUrlRequester( this ); 00047 mFileNameEdit->setMode( KFile::Directory ); 00048 00049 mainLayout->addRow( i18n( "Location:" ), mFileNameEdit ); 00050 00051 FormatFactory *factory = FormatFactory::self(); 00052 QStringList formats = factory->formats(); 00053 QStringList::Iterator it; 00054 for ( it = formats.begin(); it != formats.end(); ++it ) { 00055 FormatInfo info = factory->info( *it ); 00056 if ( !info.isNull() ) { 00057 mFormatTypes << (*it); 00058 mFormatBox->addItem( info.nameLabel ); 00059 } 00060 } 00061 00062 mInEditMode = false; 00063 } 00064 00065 void ResourceDirConfig::setEditMode( bool value ) 00066 { 00067 mFormatBox->setEnabled( !value ); 00068 mInEditMode = value; 00069 } 00070 00071 void ResourceDirConfig::loadSettings( KRES::Resource *res ) 00072 { 00073 ResourceDir *resource = dynamic_cast<ResourceDir*>( res ); 00074 00075 if ( !resource ) { 00076 kDebug() << "cast failed"; 00077 return; 00078 } 00079 00080 mFormatBox->setCurrentIndex( mFormatTypes.indexOf( resource->format() ) ); 00081 00082 mFileNameEdit->setUrl( resource->path() ); 00083 if ( mFileNameEdit->url().isEmpty() ) { 00084 mFileNameEdit->setUrl( KABC::StdAddressBook::directoryName() ); 00085 } 00086 } 00087 00088 void ResourceDirConfig::saveSettings( KRES::Resource *res ) 00089 { 00090 ResourceDir *resource = dynamic_cast<ResourceDir*>( 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->setPath( mFileNameEdit->url().path() ); 00102 } 00103 00104 #include "resourcedirconfig.moc"
This file is part of the KDE documentation.
Documentation copyright © 1996-2012 The KDE developers.
Generated on Mon Aug 27 2012 22:10:23 by doxygen 1.7.5 written by Dimitri van Heesch, © 1997-2006
Documentation copyright © 1996-2012 The KDE developers.
Generated on Mon Aug 27 2012 22:10:23 by doxygen 1.7.5 written by Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.