summaryrefslogtreecommitdiffabout
path: root/kabc/plugins/file/resourcefileconfig.cpp
authorzautrix <zautrix>2004-06-26 19:01:18 (UTC)
committer zautrix <zautrix>2004-06-26 19:01:18 (UTC)
commitb9aad1f15dc600e4dbe4c62d3fcced6363188ba3 (patch) (unidiff)
tree2c3d4004fb21c72cba65793859f9bcd8ffd3a49c /kabc/plugins/file/resourcefileconfig.cpp
downloadkdepimpi-b9aad1f15dc600e4dbe4c62d3fcced6363188ba3.zip
kdepimpi-b9aad1f15dc600e4dbe4c62d3fcced6363188ba3.tar.gz
kdepimpi-b9aad1f15dc600e4dbe4c62d3fcced6363188ba3.tar.bz2
Initial revision
Diffstat (limited to 'kabc/plugins/file/resourcefileconfig.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/plugins/file/resourcefileconfig.cpp144
1 files changed, 144 insertions, 0 deletions
diff --git a/kabc/plugins/file/resourcefileconfig.cpp b/kabc/plugins/file/resourcefileconfig.cpp
new file mode 100644
index 0000000..b63775d
--- a/dev/null
+++ b/kabc/plugins/file/resourcefileconfig.cpp
@@ -0,0 +1,144 @@
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., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21/*
22Enhanced Version of the file for platform independent KDE tools.
23Copyright (c) 2004 Ulf Schenk
24
25$Id$
26*/
27
28#include <qlabel.h>
29#include <qlayout.h>
30#include <qfileinfo.h>
31
32#include <kdebug.h>
33#include <klocale.h>
34#include <kstandarddirs.h>
35#include <kdialog.h>
36#ifndef _WIN32_
37#include <unistd.h>
38#endif
39//US #include "formatfactory.h"
40#include <qfile.h>
41#include "resourcefile.h"
42#include "stdaddressbook.h"
43
44#include "resourcefileconfig.h"
45
46using namespace KABC;
47
48ResourceFileConfig::ResourceFileConfig( QWidget* parent, const char* name )
49 : ConfigWidget( parent, name )
50{
51//qDebug("ResourceFileConfig::ResourceFileConfig");
52
53 QGridLayout *mainLayout = new QGridLayout( this, 2, 2, 0,
54 KDialog::spacingHint() );
55
56 QLabel *label = new QLabel( i18n( "Format:" ), this );
57 mFormatBox = new KComboBox( this );
58
59 mainLayout->addWidget( label, 0, 0 );
60 mainLayout->addWidget( mFormatBox, 0, 1 );
61
62 label = new QLabel( i18n( "Location:" ), this );
63 mFileNameEdit = new KURLRequester( this );
64
65 connect( mFileNameEdit, SIGNAL( textChanged( const QString & ) ),
66 SLOT( checkFilePermissions( const QString & ) ) );
67
68 mainLayout->addWidget( label, 1, 0 );
69 mainLayout->addWidget( mFileNameEdit, 1, 1 );
70
71
72/*US lets hardcode the formats instead of using a factory
73 FormatFactory *factory = FormatFactory::self();
74 QStringList formats = factory->formats();
75 QStringList::Iterator it;
76
77 for ( it = formats.begin(); it != formats.end(); ++it ) {
78 FormatInfo *info = factory->info( *it );
79 if ( info ) {
80 mFormatTypes << (*it);
81 mFormatBox->insertItem( info->nameLabel );
82 }
83 }
84*/
85 mFormatTypes << "vcard";
86 mFormatTypes << "binary";
87 mFormatBox->insertItem( "vcard" );
88 mFormatBox->insertItem( "binary" );
89
90 mInEditMode = false;
91}
92
93void ResourceFileConfig::setEditMode( bool value )
94{
95 mFormatBox->setEnabled( !value );
96 mInEditMode = value;
97}
98
99void ResourceFileConfig::loadSettings( KRES::Resource *res )
100{
101//US ResourceFile *resource = dynamic_cast<ResourceFile*>( res );
102 ResourceFile *resource = (ResourceFile*)( res );
103
104 if ( !resource ) {
105 kdDebug(5700) << "ResourceFileConfig::loadSettings(): cast failed" << endl;
106 return;
107 }
108
109 mFormatBox->setCurrentItem( mFormatTypes.findIndex( resource->format() ) );
110
111 mFileNameEdit->setURL( resource->fileName() );
112 if ( mFileNameEdit->url().isEmpty() )
113 mFileNameEdit->setURL( KABC::StdAddressBook::fileName() );
114}
115
116void ResourceFileConfig::saveSettings( KRES::Resource *res )
117{
118//US ResourceFile *resource = dynamic_cast<ResourceFile*>( res );
119 ResourceFile *resource = (ResourceFile*)( res );
120
121 if ( !resource ) {
122 kdDebug(5700) << "ResourceFileConfig::saveSettings(): cast failed" << endl;
123 return;
124 }
125
126 if ( !mInEditMode )
127 resource->setFormat( mFormatTypes[ mFormatBox->currentItem() ] );
128
129 resource->setFileName( mFileNameEdit->url() );
130}
131void ResourceFileConfig::checkFilePermissions( const QString& fileName )
132{
133 // If file exist but is not writeable...
134#ifdef _WIN32_
135 QFileInfo fi ( QFile::encodeName( fileName ) );
136 if ( fi.exists() )
137 emit setReadOnly(!fi.isReadable() );
138#else
139 if ( access( QFile::encodeName( fileName ), F_OK ) == 0 )
140 emit setReadOnly( access( QFile::encodeName( fileName ), W_OK ) < 0 );
141#endif
142}
143
144//US #include "resourcefileconfig.moc"