kabc Library API Documentation

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., 59 Temple Place - Suite 330, 00018 Boston, MA 02111-1307, USA. 00019 */ 00020 00021 #include <qlabel.h> 00022 #include <qlayout.h> 00023 00024 #include <kdebug.h> 00025 #include <klocale.h> 00026 #include <kstandarddirs.h> 00027 #include <kdialog.h> 00028 00029 #include "formatfactory.h" 00030 #include "resourcedir.h" 00031 #include "stdaddressbook.h" 00032 00033 #include "resourcedirconfig.h" 00034 00035 using namespace KABC; 00036 00037 ResourceDirConfig::ResourceDirConfig( QWidget* parent, const char* name ) 00038 : KRES::ConfigWidget( parent, name ) 00039 { 00040 QGridLayout *mainLayout = new QGridLayout( this, 2, 2, 0, 00041 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 mFileNameEdit = new KURLRequester( this ); 00051 mFileNameEdit->setMode( KFile::Directory ); 00052 00053 mainLayout->addWidget( label, 1, 0 ); 00054 mainLayout->addWidget( mFileNameEdit, 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 ) { 00062 mFormatTypes << (*it); 00063 mFormatBox->insertItem( info->nameLabel ); 00064 } 00065 } 00066 00067 mInEditMode = false; 00068 } 00069 00070 void ResourceDirConfig::setEditMode( bool value ) 00071 { 00072 mFormatBox->setEnabled( !value ); 00073 mInEditMode = value; 00074 } 00075 00076 void ResourceDirConfig::loadSettings( KRES::Resource *res ) 00077 { 00078 ResourceDir *resource = dynamic_cast<ResourceDir*>( res ); 00079 00080 if ( !resource ) { 00081 kdDebug(5700) << "ResourceDirConfig::loadSettings(): cast failed" << endl; 00082 return; 00083 } 00084 00085 mFormatBox->setCurrentItem( mFormatTypes.findIndex( resource->format() ) ); 00086 00087 mFileNameEdit->setURL( resource->path() ); 00088 if ( mFileNameEdit->url().isEmpty() ) 00089 mFileNameEdit->setURL( KABC::StdAddressBook::directoryName() ); 00090 } 00091 00092 void ResourceDirConfig::saveSettings( KRES::Resource *res ) 00093 { 00094 ResourceDir *resource = dynamic_cast<ResourceDir*>( res ); 00095 00096 if ( !resource ) { 00097 kdDebug(5700) << "ResourceDirConfig::loadSettings(): cast failed" << endl; 00098 return; 00099 } 00100 00101 if ( mInEditMode ) 00102 resource->setFormat( mFormatTypes[ mFormatBox->currentItem() ] ); 00103 00104 resource->setPath( mFileNameEdit->url() ); 00105 } 00106 00107 #include "resourcedirconfig.moc"
KDE Logo
This file is part of the documentation for kabc Library Version 3.2.3.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Fri Oct 8 11:15:48 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003