kabc
resourcefileconfig.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 "resourcefileconfig.h" 00022 #include "resourcefile.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 #include <unistd.h> 00035 00036 using namespace KABC; 00037 00038 ResourceFileConfig::ResourceFileConfig( QWidget *parent ) 00039 : ConfigWidget( parent ) 00040 { 00041 QFormLayout *mainLayout = new QFormLayout( this ); 00042 mainLayout->setMargin( 0 ); 00043 00044 mFormatBox = new KComboBox( this ); 00045 00046 mainLayout->addRow( i18n( "Format:" ), mFormatBox ); 00047 00048 mFileNameEdit = new KUrlRequester( this ); 00049 mFileNameEdit->setMode( KFile::File | KFile::LocalOnly ); 00050 00051 mainLayout->addRow( i18n( "Location:" ), mFileNameEdit ); 00052 00053 connect( mFileNameEdit, SIGNAL(textChanged(QString)), 00054 SLOT(checkFilePermissions(QString)) ); 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 mInEditMode = false; 00068 } 00069 00070 void ResourceFileConfig::setEditMode( bool value ) 00071 { 00072 mFormatBox->setEnabled( !value ); 00073 mInEditMode = value; 00074 } 00075 00076 void ResourceFileConfig::loadSettings( KRES::Resource *res ) 00077 { 00078 ResourceFile *resource = dynamic_cast<ResourceFile*>( res ); 00079 00080 if ( !resource ) { 00081 kDebug() << "cast failed"; 00082 return; 00083 } 00084 00085 mFormatBox->setCurrentIndex( mFormatTypes.indexOf( resource->format() ) ); 00086 00087 mFileNameEdit->setUrl( KUrl::fromPath( resource->fileName() ) ); 00088 if ( mFileNameEdit->url().isEmpty() ) { 00089 mFileNameEdit->setUrl( KUrl::fromPath( KABC::StdAddressBook::fileName() ) ); 00090 } 00091 } 00092 00093 void ResourceFileConfig::saveSettings( KRES::Resource *res ) 00094 { 00095 ResourceFile *resource = dynamic_cast<ResourceFile*>( res ); 00096 00097 if ( !resource ) { 00098 kDebug() << "cast failed"; 00099 return; 00100 } 00101 00102 if ( !mInEditMode ) { 00103 resource->setFormat( mFormatTypes[ mFormatBox->currentIndex() ] ); 00104 } 00105 00106 resource->setFileName( mFileNameEdit->url().path() ); 00107 } 00108 00109 void ResourceFileConfig::checkFilePermissions( const QString &fileName ) 00110 { 00111 // If file exist but is not writeable... 00112 if ( access( QFile::encodeName( fileName ), F_OK ) == 0 ) { 00113 emit setReadOnly( access( QFile::encodeName( fileName ), W_OK ) < 0 ); 00114 } 00115 } 00116 00117 #include "resourcefileconfig.moc"
This file is part of the KDE documentation.
Documentation copyright © 1996-2012 The KDE developers.
Generated on Mon May 14 2012 05:09:41 by doxygen 1.7.5 written by Dimitri van Heesch, © 1997-2006
Documentation copyright © 1996-2012 The KDE developers.
Generated on Mon May 14 2012 05:09:41 by doxygen 1.7.5 written by Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.