summaryrefslogtreecommitdiffabout
path: root/kabc/plugins/file/resourcefileconfig.cpp
Unidiff
Diffstat (limited to 'kabc/plugins/file/resourcefileconfig.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/plugins/file/resourcefileconfig.cpp4
1 files changed, 3 insertions, 1 deletions
diff --git a/kabc/plugins/file/resourcefileconfig.cpp b/kabc/plugins/file/resourcefileconfig.cpp
index b63775d..70b0bac 100644
--- a/kabc/plugins/file/resourcefileconfig.cpp
+++ b/kabc/plugins/file/resourcefileconfig.cpp
@@ -1,144 +1,146 @@
1/* 1/*
2 This file is part of libkabc. 2 This file is part of libkabc.
3 Copyright (c) 2002 Tobias Koenig <tokoe@kde.org> 3 Copyright (c) 2002 Tobias Koenig <tokoe@kde.org>
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public 6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either 7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version. 8 version 2 of the License, or (at your option) any later version.
9 9
10 This library is distributed in the hope that it will be useful, 10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details. 13 Library General Public License for more details.
14 14
15 You should have received a copy of the GNU Library General Public License 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 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, 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20 20
21/* 21/*
22Enhanced Version of the file for platform independent KDE tools. 22Enhanced Version of the file for platform independent KDE tools.
23Copyright (c) 2004 Ulf Schenk 23Copyright (c) 2004 Ulf Schenk
24 24
25$Id$ 25$Id$
26*/ 26*/
27 27
28#include <qlabel.h> 28#include <qlabel.h>
29#include <qlayout.h> 29#include <qlayout.h>
30#include <qfileinfo.h> 30#include <qfileinfo.h>
31//Added by qt3to4:
32#include <Q3GridLayout>
31 33
32#include <kdebug.h> 34#include <kdebug.h>
33#include <klocale.h> 35#include <klocale.h>
34#include <kstandarddirs.h> 36#include <kstandarddirs.h>
35#include <kdialog.h> 37#include <kdialog.h>
36#ifndef _WIN32_ 38#ifndef _WIN32_
37#include <unistd.h> 39#include <unistd.h>
38#endif 40#endif
39//US #include "formatfactory.h" 41//US #include "formatfactory.h"
40#include <qfile.h> 42#include <qfile.h>
41#include "resourcefile.h" 43#include "resourcefile.h"
42#include "stdaddressbook.h" 44#include "stdaddressbook.h"
43 45
44#include "resourcefileconfig.h" 46#include "resourcefileconfig.h"
45 47
46using namespace KABC; 48using namespace KABC;
47 49
48ResourceFileConfig::ResourceFileConfig( QWidget* parent, const char* name ) 50ResourceFileConfig::ResourceFileConfig( QWidget* parent, const char* name )
49 : ConfigWidget( parent, name ) 51 : ConfigWidget( parent, name )
50{ 52{
51//qDebug("ResourceFileConfig::ResourceFileConfig"); 53//qDebug("ResourceFileConfig::ResourceFileConfig");
52 54
53 QGridLayout *mainLayout = new QGridLayout( this, 2, 2, 0, 55 Q3GridLayout *mainLayout = new Q3GridLayout( this, 2, 2, 0,
54 KDialog::spacingHint() ); 56 KDialog::spacingHint() );
55 57
56 QLabel *label = new QLabel( i18n( "Format:" ), this ); 58 QLabel *label = new QLabel( i18n( "Format:" ), this );
57 mFormatBox = new KComboBox( this ); 59 mFormatBox = new KComboBox( this );
58 60
59 mainLayout->addWidget( label, 0, 0 ); 61 mainLayout->addWidget( label, 0, 0 );
60 mainLayout->addWidget( mFormatBox, 0, 1 ); 62 mainLayout->addWidget( mFormatBox, 0, 1 );
61 63
62 label = new QLabel( i18n( "Location:" ), this ); 64 label = new QLabel( i18n( "Location:" ), this );
63 mFileNameEdit = new KURLRequester( this ); 65 mFileNameEdit = new KURLRequester( this );
64 66
65 connect( mFileNameEdit, SIGNAL( textChanged( const QString & ) ), 67 connect( mFileNameEdit, SIGNAL( textChanged( const QString & ) ),
66 SLOT( checkFilePermissions( const QString & ) ) ); 68 SLOT( checkFilePermissions( const QString & ) ) );
67 69
68 mainLayout->addWidget( label, 1, 0 ); 70 mainLayout->addWidget( label, 1, 0 );
69 mainLayout->addWidget( mFileNameEdit, 1, 1 ); 71 mainLayout->addWidget( mFileNameEdit, 1, 1 );
70 72
71 73
72/*US lets hardcode the formats instead of using a factory 74/*US lets hardcode the formats instead of using a factory
73 FormatFactory *factory = FormatFactory::self(); 75 FormatFactory *factory = FormatFactory::self();
74 QStringList formats = factory->formats(); 76 QStringList formats = factory->formats();
75 QStringList::Iterator it; 77 QStringList::Iterator it;
76 78
77 for ( it = formats.begin(); it != formats.end(); ++it ) { 79 for ( it = formats.begin(); it != formats.end(); ++it ) {
78 FormatInfo *info = factory->info( *it ); 80 FormatInfo *info = factory->info( *it );
79 if ( info ) { 81 if ( info ) {
80 mFormatTypes << (*it); 82 mFormatTypes << (*it);
81 mFormatBox->insertItem( info->nameLabel ); 83 mFormatBox->insertItem( info->nameLabel );
82 } 84 }
83 } 85 }
84*/ 86*/
85 mFormatTypes << "vcard"; 87 mFormatTypes << "vcard";
86 mFormatTypes << "binary"; 88 mFormatTypes << "binary";
87 mFormatBox->insertItem( "vcard" ); 89 mFormatBox->insertItem( "vcard" );
88 mFormatBox->insertItem( "binary" ); 90 mFormatBox->insertItem( "binary" );
89 91
90 mInEditMode = false; 92 mInEditMode = false;
91} 93}
92 94
93void ResourceFileConfig::setEditMode( bool value ) 95void ResourceFileConfig::setEditMode( bool value )
94{ 96{
95 mFormatBox->setEnabled( !value ); 97 mFormatBox->setEnabled( !value );
96 mInEditMode = value; 98 mInEditMode = value;
97} 99}
98 100
99void ResourceFileConfig::loadSettings( KRES::Resource *res ) 101void ResourceFileConfig::loadSettings( KRES::Resource *res )
100{ 102{
101//US ResourceFile *resource = dynamic_cast<ResourceFile*>( res ); 103//US ResourceFile *resource = dynamic_cast<ResourceFile*>( res );
102 ResourceFile *resource = (ResourceFile*)( res ); 104 ResourceFile *resource = (ResourceFile*)( res );
103 105
104 if ( !resource ) { 106 if ( !resource ) {
105 kdDebug(5700) << "ResourceFileConfig::loadSettings(): cast failed" << endl; 107 kdDebug(5700) << "ResourceFileConfig::loadSettings(): cast failed" << endl;
106 return; 108 return;
107 } 109 }
108 110
109 mFormatBox->setCurrentItem( mFormatTypes.findIndex( resource->format() ) ); 111 mFormatBox->setCurrentItem( mFormatTypes.findIndex( resource->format() ) );
110 112
111 mFileNameEdit->setURL( resource->fileName() ); 113 mFileNameEdit->setURL( resource->fileName() );
112 if ( mFileNameEdit->url().isEmpty() ) 114 if ( mFileNameEdit->url().isEmpty() )
113 mFileNameEdit->setURL( KABC::StdAddressBook::fileName() ); 115 mFileNameEdit->setURL( KABC::StdAddressBook::fileName() );
114} 116}
115 117
116void ResourceFileConfig::saveSettings( KRES::Resource *res ) 118void ResourceFileConfig::saveSettings( KRES::Resource *res )
117{ 119{
118//US ResourceFile *resource = dynamic_cast<ResourceFile*>( res ); 120//US ResourceFile *resource = dynamic_cast<ResourceFile*>( res );
119 ResourceFile *resource = (ResourceFile*)( res ); 121 ResourceFile *resource = (ResourceFile*)( res );
120 122
121 if ( !resource ) { 123 if ( !resource ) {
122 kdDebug(5700) << "ResourceFileConfig::saveSettings(): cast failed" << endl; 124 kdDebug(5700) << "ResourceFileConfig::saveSettings(): cast failed" << endl;
123 return; 125 return;
124 } 126 }
125 127
126 if ( !mInEditMode ) 128 if ( !mInEditMode )
127 resource->setFormat( mFormatTypes[ mFormatBox->currentItem() ] ); 129 resource->setFormat( mFormatTypes[ mFormatBox->currentItem() ] );
128 130
129 resource->setFileName( mFileNameEdit->url() ); 131 resource->setFileName( mFileNameEdit->url() );
130} 132}
131void ResourceFileConfig::checkFilePermissions( const QString& fileName ) 133void ResourceFileConfig::checkFilePermissions( const QString& fileName )
132{ 134{
133 // If file exist but is not writeable... 135 // If file exist but is not writeable...
134#ifdef _WIN32_ 136#ifdef _WIN32_
135 QFileInfo fi ( QFile::encodeName( fileName ) ); 137 QFileInfo fi ( QFile::encodeName( fileName ) );
136 if ( fi.exists() ) 138 if ( fi.exists() )
137 emit setReadOnly(!fi.isReadable() ); 139 emit setReadOnly(!fi.isReadable() );
138#else 140#else
139 if ( access( QFile::encodeName( fileName ), F_OK ) == 0 ) 141 if ( access( QFile::encodeName( fileName ), F_OK ) == 0 )
140 emit setReadOnly( access( QFile::encodeName( fileName ), W_OK ) < 0 ); 142 emit setReadOnly( access( QFile::encodeName( fileName ), W_OK ) < 0 );
141#endif 143#endif
142} 144}
143 145
144//US #include "resourcefileconfig.moc" 146//US #include "resourcefileconfig.moc"