• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdeabc
 

tdeabc

resourcefileconfig.cpp

00001 /*
00002     This file is part of libtdeabc.
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 <tqlabel.h>
00022 #include <tqlayout.h>
00023 
00024 #include <kdebug.h>
00025 #include <tdelocale.h>
00026 #include <kstandarddirs.h>
00027 #include <kdialog.h>
00028 
00029 #include <unistd.h>
00030 
00031 #include "formatfactory.h"
00032 #include "resourcefile.h"
00033 #include "stdaddressbook.h"
00034 
00035 #include "resourcefileconfig.h"
00036 
00037 using namespace TDEABC;
00038 
00039 ResourceFileConfig::ResourceFileConfig( TQWidget* parent,  const char* name )
00040     : ConfigWidget( parent, name )
00041 {
00042   TQGridLayout *mainLayout = new TQGridLayout( this, 2, 2, 0,
00043       KDialog::spacingHint() );
00044 
00045   TQLabel *label = new TQLabel( i18n( "Format:" ), this );
00046   mFormatBox = new KComboBox( this );
00047 
00048   mainLayout->addWidget( label, 0, 0 );
00049   mainLayout->addWidget( mFormatBox, 0, 1 );
00050 
00051   label = new TQLabel( i18n( "Location:" ), this );
00052   mFileNameEdit = new KURLRequester( this );
00053 
00054   connect( mFileNameEdit, TQT_SIGNAL( textChanged( const TQString & ) ),
00055            TQT_SLOT( checkFilePermissions( const TQString & ) ) );
00056 
00057   mainLayout->addWidget( label, 1, 0 );
00058   mainLayout->addWidget( mFileNameEdit, 1, 1 );
00059 
00060   FormatFactory *factory = FormatFactory::self();
00061   TQStringList formats = factory->formats();
00062   TQStringList::Iterator it;
00063   for ( it = formats.begin(); it != formats.end(); ++it ) {
00064     FormatInfo *info = factory->info( *it );
00065     if ( info ) {
00066       mFormatTypes << (*it);
00067       mFormatBox->insertItem( info->nameLabel );
00068     }
00069   }
00070 
00071   mInEditMode = false;
00072 }
00073 
00074 void ResourceFileConfig::setEditMode( bool value )
00075 {
00076   mFormatBox->setEnabled( !value );
00077   mInEditMode = value;
00078 }
00079 
00080 void ResourceFileConfig::loadSettings( KRES::Resource *res  )
00081 {
00082   ResourceFile *resource = dynamic_cast<ResourceFile*>( res );
00083   
00084   if ( !resource ) {
00085     kdDebug(5700) << "ResourceFileConfig::loadSettings(): cast failed" << endl;
00086     return;
00087   }
00088 
00089   mFormatBox->setCurrentItem( mFormatTypes.findIndex( resource->format() ) );
00090 
00091   mFileNameEdit->setURL( resource->fileName() );
00092   if ( mFileNameEdit->url().isEmpty() )
00093     mFileNameEdit->setURL( TDEABC::StdAddressBook::fileName() );
00094 }
00095 
00096 void ResourceFileConfig::saveSettings( KRES::Resource *res )
00097 {
00098   ResourceFile *resource = dynamic_cast<ResourceFile*>( res );
00099   
00100   if ( !resource ) {
00101     kdDebug(5700) << "ResourceFileConfig::saveSettings(): cast failed" << endl;
00102     return;
00103   }
00104 
00105   if ( !mInEditMode )
00106     resource->setFormat( mFormatTypes[ mFormatBox->currentItem() ] );
00107 
00108   resource->setFileName( mFileNameEdit->url() );
00109 }
00110 
00111 void ResourceFileConfig::checkFilePermissions( const TQString& fileName )
00112 {
00113   // If file exist but is not writeable...
00114   if ( access( TQFile::encodeName( fileName ), F_OK ) == 0 )
00115       emit setReadOnly( access( TQFile::encodeName( fileName ), W_OK ) < 0 );
00116 }
00117 
00118 #include "resourcefileconfig.moc"

tdeabc

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

tdeabc

Skip menu "tdeabc"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeabc by doxygen 1.7.1
This website is maintained by Timothy Pearson.