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

kabc

  • kabc
  • plugins
  • file
resourcefileconfig.cpp
1 /*
2  This file is part of libkabc.
3  Copyright (c) 2002 Tobias Koenig <tokoe@kde.org>
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Library General Public
7  License as published by the Free Software Foundation; either
8  version 2 of the License, or (at your option) any later version.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Library General Public License for more details.
14 
15  You should have received a copy of the GNU Library General Public License
16  along with this library; see the file COPYING.LIB. If not, write to
17  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  Boston, MA 02110-1301, USA.
19 */
20 
21 #include <tqlabel.h>
22 #include <tqlayout.h>
23 
24 #include <kdebug.h>
25 #include <klocale.h>
26 #include <kstandarddirs.h>
27 #include <kdialog.h>
28 
29 #include <unistd.h>
30 
31 #include "formatfactory.h"
32 #include "resourcefile.h"
33 #include "stdaddressbook.h"
34 
35 #include "resourcefileconfig.h"
36 
37 using namespace KABC;
38 
39 ResourceFileConfig::ResourceFileConfig( TQWidget* parent, const char* name )
40  : ConfigWidget( parent, name )
41 {
42  TQGridLayout *mainLayout = new TQGridLayout( this, 2, 2, 0,
43  KDialog::spacingHint() );
44 
45  TQLabel *label = new TQLabel( i18n( "Format:" ), this );
46  mFormatBox = new KComboBox( this );
47 
48  mainLayout->addWidget( label, 0, 0 );
49  mainLayout->addWidget( mFormatBox, 0, 1 );
50 
51  label = new TQLabel( i18n( "Location:" ), this );
52  mFileNameEdit = new KURLRequester( this );
53 
54  connect( mFileNameEdit, TQT_SIGNAL( textChanged( const TQString & ) ),
55  TQT_SLOT( checkFilePermissions( const TQString & ) ) );
56 
57  mainLayout->addWidget( label, 1, 0 );
58  mainLayout->addWidget( mFileNameEdit, 1, 1 );
59 
60  FormatFactory *factory = FormatFactory::self();
61  TQStringList formats = factory->formats();
62  TQStringList::Iterator it;
63  for ( it = formats.begin(); it != formats.end(); ++it ) {
64  FormatInfo *info = factory->info( *it );
65  if ( info ) {
66  mFormatTypes << (*it);
67  mFormatBox->insertItem( info->nameLabel );
68  }
69  }
70 
71  mInEditMode = false;
72 }
73 
74 void ResourceFileConfig::setEditMode( bool value )
75 {
76  mFormatBox->setEnabled( !value );
77  mInEditMode = value;
78 }
79 
80 void ResourceFileConfig::loadSettings( KRES::Resource *res )
81 {
82  ResourceFile *resource = dynamic_cast<ResourceFile*>( res );
83 
84  if ( !resource ) {
85  kdDebug(5700) << "ResourceFileConfig::loadSettings(): cast failed" << endl;
86  return;
87  }
88 
89  mFormatBox->setCurrentItem( mFormatTypes.findIndex( resource->format() ) );
90 
91  mFileNameEdit->setURL( resource->fileName() );
92  if ( mFileNameEdit->url().isEmpty() )
93  mFileNameEdit->setURL( KABC::StdAddressBook::fileName() );
94 }
95 
96 void ResourceFileConfig::saveSettings( KRES::Resource *res )
97 {
98  ResourceFile *resource = dynamic_cast<ResourceFile*>( res );
99 
100  if ( !resource ) {
101  kdDebug(5700) << "ResourceFileConfig::saveSettings(): cast failed" << endl;
102  return;
103  }
104 
105  if ( !mInEditMode )
106  resource->setFormat( mFormatTypes[ mFormatBox->currentItem() ] );
107 
108  resource->setFileName( mFileNameEdit->url() );
109 }
110 
111 void ResourceFileConfig::checkFilePermissions( const TQString& fileName )
112 {
113  // If file exist but is not writeable...
114  if ( access( TQFile::encodeName( fileName ), F_OK ) == 0 )
115  emit setReadOnly( access( TQFile::encodeName( fileName ), W_OK ) < 0 );
116 }
117 
118 #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

kabc

Skip menu "kabc"
  • arts
  • dcop
  • dnssd
  • interfaces
  •     interface
  •     library
  •   kspeech
  •   ktexteditor
  • kabc
  • kate
  • kcmshell
  • kdecore
  • kded
  • kdefx
  • kdeprint
  • kdesu
  • kdeui
  • kdoctools
  • khtml
  • kimgio
  • kinit
  • kio
  •   bookmarks
  •   httpfilter
  •   kfile
  •   kio
  •   kioexec
  •   kpasswdserver
  •   kssl
  • kioslave
  •   http
  • kjs
  • kmdi
  •   kmdi
  • knewstuff
  • kparts
  • krandr
  • kresources
  • kspell2
  • kunittest
  • kutils
  • kwallet
  • libkmid
  • libkscreensaver
Generated for kabc by doxygen 1.8.3.1
This website is maintained by Timothy Pearson.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. |