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

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/QLabel>
00033 #include <QtGui/QLayout>
00034 
00035 using namespace KABC;
00036 
00037 ResourceDirConfig::ResourceDirConfig( QWidget *parent )
00038     : KRES::ConfigWidget( parent )
00039 {
00040   QGridLayout *mainLayout = new QGridLayout( this );
00041   mainLayout->setMargin( 0 );
00042   mainLayout->setSpacing( KDialog::spacingHint() );
00043 
00044   QLabel *label = new QLabel( i18n( "Format:" ), this );
00045   mFormatBox = new KComboBox( this );
00046 
00047   mainLayout->addWidget( label, 0, 0 );
00048   mainLayout->addWidget( mFormatBox, 0, 1 );
00049 
00050   label = new QLabel( i18n( "Location:" ), this );
00051   mFileNameEdit = new KUrlRequester( this );
00052   mFileNameEdit->setMode( KFile::Directory );
00053 
00054   mainLayout->addWidget( label, 1, 0 );
00055   mainLayout->addWidget( mFileNameEdit, 1, 1 );
00056 
00057   FormatFactory *factory = FormatFactory::self();
00058   QStringList formats = factory->formats();
00059   QStringList::Iterator it;
00060   for ( it = formats.begin(); it != formats.end(); ++it ) {
00061     FormatInfo info = factory->info( *it );
00062     if ( !info.isNull() ) {
00063       mFormatTypes << (*it);
00064       mFormatBox->addItem( info.nameLabel );
00065     }
00066   }
00067 
00068   mInEditMode = false;
00069 }
00070 
00071 void ResourceDirConfig::setEditMode( bool value )
00072 {
00073   mFormatBox->setEnabled( !value );
00074   mInEditMode = value;
00075 }
00076 
00077 void ResourceDirConfig::loadSettings( KRES::Resource *res )
00078 {
00079   ResourceDir *resource = dynamic_cast<ResourceDir*>( res );
00080 
00081   if ( !resource ) {
00082     kDebug() << "cast failed";
00083     return;
00084   }
00085 
00086   mFormatBox->setCurrentIndex( mFormatTypes.indexOf( resource->format() ) );
00087 
00088   mFileNameEdit->setPath( resource->path() );
00089   if ( mFileNameEdit->url().isEmpty() ) {
00090     mFileNameEdit->setPath( KABC::StdAddressBook::directoryName() );
00091   }
00092 }
00093 
00094 void ResourceDirConfig::saveSettings( KRES::Resource *res )
00095 {
00096   ResourceDir *resource = dynamic_cast<ResourceDir*>( res );
00097 
00098   if ( !resource ) {
00099     kDebug() << "cast failed";
00100     return;
00101   }
00102 
00103   if ( mInEditMode ) {
00104     resource->setFormat( mFormatTypes[ mFormatBox->currentIndex() ] );
00105   }
00106 
00107   resource->setPath( mFileNameEdit->url().path() );
00108 }
00109 
00110 #include "resourcedirconfig.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
  • kimap
  • kioslave
  •   imap4
  •   mbox
  • kldap
  • kmime
  • kpimidentities
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
Generated for KDE-PIM Libraries by doxygen 1.5.4
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