Diffstat (limited to 'kabc/plugins/opie/resourceopieconfig.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | kabc/plugins/opie/resourceopieconfig.cpp | 107 |
1 files changed, 107 insertions, 0 deletions
diff --git a/kabc/plugins/opie/resourceopieconfig.cpp b/kabc/plugins/opie/resourceopieconfig.cpp new file mode 100644 index 0000000..b92cfa1 --- a/dev/null +++ b/kabc/plugins/opie/resourceopieconfig.cpp | |||
@@ -0,0 +1,107 @@ | |||
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 | /* | ||
22 | Enhanced Version of the file for platform independent KDE tools. | ||
23 | Copyright (c) 2004 Ulf Schenk | ||
24 | |||
25 | $Id$ | ||
26 | */ | ||
27 | |||
28 | #include <qlabel.h> | ||
29 | #include <qlayout.h> | ||
30 | |||
31 | #include <kdebug.h> | ||
32 | #include <klocale.h> | ||
33 | #include <kstandarddirs.h> | ||
34 | #include <kdialog.h> | ||
35 | |||
36 | #include <unistd.h> | ||
37 | |||
38 | #include <qfile.h> | ||
39 | #include "resourceopie.h" | ||
40 | #include "stdaddressbook.h" | ||
41 | |||
42 | #include "resourceopieconfig.h" | ||
43 | |||
44 | using namespace KABC; | ||
45 | |||
46 | ResourceOpieConfig::ResourceOpieConfig( QWidget* parent, const char* name ) | ||
47 | : ConfigWidget( parent, name ) | ||
48 | { | ||
49 | //qDebug("ResourceFileConfig::ResourceFileConfig"); | ||
50 | |||
51 | QGridLayout *mainLayout = new QGridLayout( this, 1, 2, 0, | ||
52 | KDialog::spacingHint() ); | ||
53 | |||
54 | QLabel *label = new QLabel( i18n( "Location:" ), this ); | ||
55 | mFileNameEdit = new KURLRequester( this ); | ||
56 | |||
57 | connect( mFileNameEdit, SIGNAL( textChanged( const QString & ) ), | ||
58 | SLOT( checkFilePermissions( const QString & ) ) ); | ||
59 | |||
60 | mainLayout->addWidget( label, 0, 0 ); | ||
61 | mainLayout->addWidget( mFileNameEdit, 0, 1 ); | ||
62 | |||
63 | //US mInEditMode = false; | ||
64 | } | ||
65 | /*US | ||
66 | void ResourceOpieConfig::setEditMode( bool value ) | ||
67 | { | ||
68 | mInEditMode = value; | ||
69 | } | ||
70 | */ | ||
71 | |||
72 | void ResourceOpieConfig::loadSettings( KRES::Resource *res ) | ||
73 | { | ||
74 | //US ResourceFile *resource = dynamic_cast<ResourceFile*>( res ); | ||
75 | ResourceOpie *resource = (ResourceOpie*)( res ); | ||
76 | |||
77 | if ( !resource ) { | ||
78 | kdDebug(5700) << "ResourceOpieConfig::loadSettings(): cast failed" << endl; | ||
79 | return; | ||
80 | } | ||
81 | |||
82 | mFileNameEdit->setURL( resource->fileName() ); | ||
83 | if ( mFileNameEdit->url().isEmpty() ) | ||
84 | mFileNameEdit->setURL( KABC::StdAddressBook::fileName() ); | ||
85 | } | ||
86 | |||
87 | void ResourceOpieConfig::saveSettings( KRES::Resource *res ) | ||
88 | { | ||
89 | //US ResourceFile *resource = dynamic_cast<ResourceFile*>( res ); | ||
90 | ResourceOpie *resource = (ResourceOpie*)( res ); | ||
91 | |||
92 | if ( !resource ) { | ||
93 | kdDebug(5700) << "ResourceOpieConfig::saveSettings(): cast failed" << endl; | ||
94 | return; | ||
95 | } | ||
96 | |||
97 | resource->setFileName( mFileNameEdit->url() ); | ||
98 | } | ||
99 | |||
100 | void ResourceOpieConfig::checkFilePermissions( const QString& fileName ) | ||
101 | { | ||
102 | // If file exist but is not writeable... | ||
103 | if ( access( QFile::encodeName( fileName ), F_OK ) == 0 ) | ||
104 | emit setReadOnly( access( QFile::encodeName( fileName ), W_OK ) < 0 ); | ||
105 | } | ||
106 | |||
107 | //US #include "resourceopieconfig.moc" | ||