• Skip to content
  • Skip to link menu
KDE 4.3 API Reference
  • KDE API Reference
  • KDE-PIM Libraries
  • Sitemap
  • Contact Us
 

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/QLabel>
00033 #include <QtGui/QLayout>
00034 
00035 #include <unistd.h>
00036 
00037 using namespace KABC;
00038 
00039 ResourceFileConfig::ResourceFileConfig( QWidget *parent )
00040     : ConfigWidget( parent )
00041 {
00042   QGridLayout *mainLayout = new QGridLayout( this );
00043   mainLayout->setMargin( 0 );
00044   mainLayout->setSpacing( KDialog::spacingHint() );
00045 
00046   QLabel *label = new QLabel( i18n( "Format:" ), this );
00047   mFormatBox = new KComboBox( this );
00048 
00049   mainLayout->addWidget( label, 0, 0 );
00050   mainLayout->addWidget( mFormatBox, 0, 1 );
00051 
00052   label = new QLabel( i18n( "Location:" ), this );
00053   mFileNameEdit = new KUrlRequester( this );
00054   mFileNameEdit->setMode( KFile::File | KFile::LocalOnly );
00055 
00056   connect( mFileNameEdit, SIGNAL( textChanged( const QString & ) ),
00057            SLOT( checkFilePermissions( const QString & ) ) );
00058 
00059   mainLayout->addWidget( label, 1, 0 );
00060   mainLayout->addWidget( mFileNameEdit, 1, 1 );
00061 
00062   FormatFactory *factory = FormatFactory::self();
00063   QStringList formats = factory->formats();
00064   QStringList::Iterator it;
00065   for ( it = formats.begin(); it != formats.end(); ++it ) {
00066     FormatInfo info = factory->info( *it );
00067     if ( !info.isNull() ) {
00068       mFormatTypes << (*it);
00069       mFormatBox->addItem( info.nameLabel );
00070     }
00071   }
00072 
00073   mInEditMode = false;
00074 }
00075 
00076 void ResourceFileConfig::setEditMode( bool value )
00077 {
00078   mFormatBox->setEnabled( !value );
00079   mInEditMode = value;
00080 }
00081 
00082 void ResourceFileConfig::loadSettings( KRES::Resource *res )
00083 {
00084   ResourceFile *resource = dynamic_cast<ResourceFile*>( res );
00085 
00086   if ( !resource ) {
00087     kDebug() << "cast failed";
00088     return;
00089   }
00090 
00091   mFormatBox->setCurrentIndex( mFormatTypes.indexOf( resource->format() ) );
00092 
00093   mFileNameEdit->setUrl( KUrl::fromPath( resource->fileName() ) );
00094   if ( mFileNameEdit->url().isEmpty() ) {
00095     mFileNameEdit->setUrl( KUrl::fromPath( KABC::StdAddressBook::fileName() ) );
00096   }
00097 }
00098 
00099 void ResourceFileConfig::saveSettings( KRES::Resource *res )
00100 {
00101   ResourceFile *resource = dynamic_cast<ResourceFile*>( res );
00102 
00103   if ( !resource ) {
00104     kDebug() << "cast failed";
00105     return;
00106   }
00107 
00108   if ( !mInEditMode ) {
00109     resource->setFormat( mFormatTypes[ mFormatBox->currentIndex() ] );
00110   }
00111 
00112   resource->setFileName( mFileNameEdit->url().path() );
00113 }
00114 
00115 void ResourceFileConfig::checkFilePermissions( const QString &fileName )
00116 {
00117   // If file exist but is not writeable...
00118   if ( access( QFile::encodeName( fileName ), F_OK ) == 0 ) {
00119     emit setReadOnly( access( QFile::encodeName( fileName ), W_OK ) < 0 );
00120   }
00121 }
00122 
00123 #include "resourcefileconfig.moc"

kabc

Skip menu "kabc"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

KDE-PIM Libraries

Skip menu "KDE-PIM Libraries"
  • akonadi
  • kabc
  • kblog
  • kcal
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  • kldap
  • kmime
  • kpimidentities
  • kpimtextedit
  •   richtextbuilders
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
Generated for KDE-PIM Libraries by doxygen 1.5.8
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal