kabc Library API Documentation

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., 59 Temple Place - Suite 330,
00018     Boston, MA 02111-1307, USA.
00019 */
00020 
00021 #include <qlabel.h>
00022 #include <qlayout.h>
00023 
00024 #include <klocale.h>
00025 #include <kstandarddirs.h>
00026 
00027 #include <unistd.h>
00028 
00029 #include "formatfactory.h"
00030 #include "resourcefileconfig.h"
00031 #include "stdaddressbook.h"
00032 
00033 using namespace KABC;
00034 
00035 ResourceFileConfig::ResourceFileConfig( QWidget* parent,  const char* name )
00036     : ResourceConfigWidget( parent, name )
00037 {
00038   resize( 245, 115 ); 
00039   QGridLayout *mainLayout = new QGridLayout( this, 2, 2 );
00040 
00041   QLabel *label = new QLabel( i18n( "Format:" ), this );
00042   mFormatBox = new KComboBox( this );
00043 
00044   mainLayout->addWidget( label, 0, 0 );
00045   mainLayout->addWidget( mFormatBox, 0, 1 );
00046 
00047   label = new QLabel( i18n( "Location:" ), this );
00048   mFileNameEdit = new KURLRequester( this );
00049 
00050   connect( mFileNameEdit, SIGNAL( textChanged( const QString & ) ), SLOT( checkFilePermissions( const QString & ) ) );
00051 
00052   mainLayout->addWidget( label, 1, 0 );
00053   mainLayout->addWidget( mFileNameEdit, 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 ResourceFileConfig::setEditMode( bool value )
00068 {
00069   mFormatBox->setEnabled( !value );
00070 }
00071 
00072 void ResourceFileConfig::loadSettings( KConfig *config )
00073 {
00074   QString format = config->readEntry( "FileFormat" );
00075   mFormatBox->setCurrentItem( mFormatTypes.findIndex( format ) );
00076 
00077   mFileNameEdit->setURL( config->readEntry( "FileName" ) );    
00078   if ( mFileNameEdit->url().isEmpty() )
00079     mFileNameEdit->setURL( KABC::StdAddressBook::fileName() );
00080 }
00081 
00082 void ResourceFileConfig::saveSettings( KConfig *config )
00083 {
00084   config->writeEntry( "FileFormat", mFormatTypes[ mFormatBox->currentItem() ] );
00085   config->writeEntry( "FileName", mFileNameEdit->url() );
00086 }
00087 
00088 void ResourceFileConfig::checkFilePermissions( const QString& fileName )
00089 {
00090   // If file exist but is not writeable...
00091   if ( access( QFile::encodeName( fileName ), F_OK ) == 0 )
00092       emit setReadOnly( access( QFile::encodeName( fileName ), W_OK ) < 0 );
00093 }
00094 
00095 #include "resourcefileconfig.moc"
KDE Logo
This file is part of the documentation for kdelibs Version 3.1.0.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Wed Oct 8 12:22:08 2003 by doxygen 1.2.18 written by Dimitri van Heesch, © 1997-2001