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

tdeabc

  • tdeabc
  • plugins
  • file
resourcefileconfig.cpp
1 /*
2  This file is part of libtdeabc.
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 <tdelocale.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 TDEABC;
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( TDEABC::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"
TDEABC::FormatFactory
Class for loading format plugins.
Definition: formatfactory.h:57
TDEABC::ResourceFile::setFormat
void setFormat(const TQString &name)
Sets a new format by name.
Definition: resourcefile.cpp:360
TDEABC::StdAddressBook::fileName
static TQString fileName()
Returns the default file name for vcard-based addressbook.
Definition: stdaddressbook.cpp:43
kdDebug
kdbgstream kdDebug(int area=0)
TDEABC::FormatFactory::self
static FormatFactory * self()
Returns the global format factory.
Definition: formatfactory.cpp:38
TDEABC
static data, shared by ALL addressee objects
Definition: address.h:48
tdelocale.h
TDEABC::FormatFactory::info
FormatInfo * info(const TQString &type)
Returns the info structure for a special type.
Definition: formatfactory.cpp:101
TDEABC::ResourceFile
This resource allows access to a local file.
Definition: resourcefile.h:40
TDEABC::ResourceFile::format
TQString format() const
Returns the format name.
Definition: resourcefile.cpp:369
TDEABC::FormatFactory::formats
TQStringList formats()
Returns a list of all available format types.
Definition: formatfactory.cpp:86
KComboBox
TDEABC::ResourceFile::fileName
TQString fileName() const
Return name of file used for loading and saving the address book.
Definition: resourcefile.cpp:355
endl
kndbgstream & endl(kndbgstream &s)
TDEABC::ResourceFile::setFileName
void setFileName(const TQString &)
Set name of file to be used for saving.
Definition: resourcefile.cpp:343
TDEStdAccel::label
TQString label(StdAccel id)

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
  •     tdecore
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  • tdeioslave
  •   http
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeabc by doxygen 1.8.8
This website is maintained by Timothy Pearson.