author | ulf69 <ulf69> | 2004-06-29 03:21:44 (UTC) |
---|---|---|
committer | ulf69 <ulf69> | 2004-06-29 03:21:44 (UTC) |
commit | 659b21aed6e02154a1b38ff16a09a432fe3953cb (patch) (unidiff) | |
tree | 17d5e9791d4d3c47ec136b05328c1f402ba4c50a /kabc/plugins | |
parent | a52c5f5a0b10cff057d9bca6046d50bfefb6896c (diff) | |
download | kdepimpi-659b21aed6e02154a1b38ff16a09a432fe3953cb.zip kdepimpi-659b21aed6e02154a1b38ff16a09a432fe3953cb.tar.gz kdepimpi-659b21aed6e02154a1b38ff16a09a432fe3953cb.tar.bz2 |
added support for opie addressbook resources
-rw-r--r-- | kabc/plugins/opie/kabc_opieE.pro | 21 | ||||
-rw-r--r-- | kabc/plugins/opie/resourceopie.cpp | 345 | ||||
-rw-r--r-- | kabc/plugins/opie/resourceopie.h | 149 | ||||
-rw-r--r-- | kabc/plugins/opie/resourceopieconfig.cpp | 107 | ||||
-rw-r--r-- | kabc/plugins/opie/resourceopieconfig.h | 61 |
5 files changed, 683 insertions, 0 deletions
diff --git a/kabc/plugins/opie/kabc_opieE.pro b/kabc/plugins/opie/kabc_opieE.pro new file mode 100644 index 0000000..7341ca8 --- a/dev/null +++ b/kabc/plugins/opie/kabc_opieE.pro | |||
@@ -0,0 +1,21 @@ | |||
1 | TEMPLATE= lib | ||
2 | CONFIG += qt warn_on release | ||
3 | #release debug | ||
4 | |||
5 | TARGET = microkabc_opie | ||
6 | INCLUDEPATH += ../.. ../../../microkde ../../../microkde/kdecore ../../../microkde/kio/kfile ../../../qtcompat | ||
7 | OBJECTS_DIR = obj/$(PLATFORM) | ||
8 | MOC_DIR = moc | ||
9 | DESTDIR = $(QPEDIR)/lib | ||
10 | LIBS += -lmicrokde -lmicrokabc | ||
11 | LIBS += -L$(QPEDIR)/lib | ||
12 | |||
13 | INTERFACES = \ | ||
14 | |||
15 | HEADERS = \ | ||
16 | resourceopie.h \ | ||
17 | resourceopieconfig.h | ||
18 | |||
19 | SOURCES = \ | ||
20 | resourceopie.cpp \ | ||
21 | resourceopieconfig.cpp | ||
diff --git a/kabc/plugins/opie/resourceopie.cpp b/kabc/plugins/opie/resourceopie.cpp new file mode 100644 index 0000000..47e22b4 --- a/dev/null +++ b/kabc/plugins/opie/resourceopie.cpp | |||
@@ -0,0 +1,345 @@ | |||
1 | /* | ||
2 | This file is part of libkabc. | ||
3 | Copyright (c) 2001 Cornelius Schumacher <schumacher@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 <sys/types.h> | ||
29 | #include <sys/stat.h> | ||
30 | #include <unistd.h> | ||
31 | |||
32 | #include <qfile.h> | ||
33 | #include <qfileinfo.h> | ||
34 | #include <qregexp.h> | ||
35 | #include <qtimer.h> | ||
36 | |||
37 | #include <kapplication.h> | ||
38 | #include <kconfig.h> | ||
39 | #include <kdebug.h> | ||
40 | #include <klocale.h> | ||
41 | //US #include <ksavefile.h> | ||
42 | #include <kstandarddirs.h> | ||
43 | |||
44 | //US #include "formatfactory.h" | ||
45 | |||
46 | #include "resource.h" | ||
47 | #include "resourceopieconfig.h" | ||
48 | #include "stdaddressbook.h" | ||
49 | |||
50 | #include "resourceopie.h" | ||
51 | |||
52 | using namespace KABC; | ||
53 | extern "C" | ||
54 | { | ||
55 | //US void *init_kabc_file() | ||
56 | void *init_microkabc_opie() | ||
57 | { | ||
58 | return new KRES::PluginFactory<ResourceOpie,ResourceOpieConfig>(); | ||
59 | } | ||
60 | } | ||
61 | |||
62 | ResourceOpie::ResourceOpie( const KConfig *config ) | ||
63 | : Resource( config ) | ||
64 | { | ||
65 | QString fileName; | ||
66 | |||
67 | KConfig *cfg = (KConfig *)config; | ||
68 | if ( cfg ) { | ||
69 | fileName = cfg->readEntry( "FileName", StdAddressBook::fileName() ); | ||
70 | // qDebug("ResourceFile::ResourceFile : 1 %s, %s", fileName.latin1(), formatName.latin1() ); | ||
71 | } else { | ||
72 | fileName = StdAddressBook::fileName(); | ||
73 | // qDebug("ResourceFile::ResourceFile : 2 %s, %s", fileName.latin1(), formatName.latin1() ); | ||
74 | } | ||
75 | |||
76 | init( fileName ); | ||
77 | } | ||
78 | |||
79 | ResourceOpie::ResourceOpie( const QString &fileName ) | ||
80 | : Resource( 0 ) | ||
81 | { | ||
82 | // qDebug("ResourceFile::ResourceFile : 3 %s, %s", fileName.latin1(), formatName.latin1()); | ||
83 | init( fileName ); | ||
84 | } | ||
85 | |||
86 | void ResourceOpie::init( const QString &fileName ) | ||
87 | { | ||
88 | |||
89 | /*US we have no KDirWatch. SO simulate the signals from inside the apropriate methods | ||
90 | connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) ); | ||
91 | connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) ); | ||
92 | connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) ); | ||
93 | */ | ||
94 | |||
95 | setFileName( fileName ); | ||
96 | } | ||
97 | |||
98 | ResourceOpie::~ResourceOpie() | ||
99 | { | ||
100 | } | ||
101 | |||
102 | void ResourceOpie::writeConfig( KConfig *config ) | ||
103 | { | ||
104 | Resource::writeConfig( config ); | ||
105 | |||
106 | config->writeEntry( "FileName", mFileName ); | ||
107 | |||
108 | // qDebug("ResourceFile::writeConfig format %s, %s", mFileName.latin1(), mFormatName.latin1()); | ||
109 | |||
110 | } | ||
111 | |||
112 | Ticket *ResourceOpie::requestSaveTicket() | ||
113 | { | ||
114 | kdDebug(5700) << "ResourceOpie::requestSaveTicket()" << endl; | ||
115 | |||
116 | if ( !addressBook() ) return 0; | ||
117 | |||
118 | if ( !lock( mFileName ) ) { | ||
119 | kdDebug(5700) << "ResourceOpie::requestSaveTicket(): Unable to lock file '" | ||
120 | << mFileName << "'" << endl; | ||
121 | return 0; | ||
122 | } | ||
123 | return createTicket( this ); | ||
124 | } | ||
125 | |||
126 | |||
127 | bool ResourceOpie::doOpen() | ||
128 | { | ||
129 | QFile file( mFileName ); | ||
130 | |||
131 | if ( !file.exists() ) { | ||
132 | // try to create the file | ||
133 | bool ok = file.open( IO_WriteOnly ); | ||
134 | if ( ok ) | ||
135 | file.close(); | ||
136 | |||
137 | return ok; | ||
138 | } else { | ||
139 | if ( !file.open( IO_ReadWrite ) ) | ||
140 | return false; | ||
141 | |||
142 | if ( file.size() == 0 ) { | ||
143 | file.close(); | ||
144 | return true; | ||
145 | } | ||
146 | |||
147 | //US bool ok = mFormat->checkFormat( &file ); | ||
148 | bool ok = true; | ||
149 | |||
150 | file.close(); | ||
151 | |||
152 | return ok; | ||
153 | } | ||
154 | } | ||
155 | |||
156 | void ResourceOpie::doClose() | ||
157 | { | ||
158 | } | ||
159 | |||
160 | bool ResourceOpie::load() | ||
161 | { | ||
162 | kdDebug(5700) << "ResourceOpie::load(): '" << mFileName << "'" << endl; | ||
163 | |||
164 | QFile file( mFileName ); | ||
165 | if ( !file.open( IO_ReadOnly ) ) { | ||
166 | addressBook()->error( i18n( "Unable to open file '%1'." ).arg( mFileName ) ); | ||
167 | return false; | ||
168 | } | ||
169 | |||
170 | // qDebug("ResourceFile::load format %s, %s", mFileName.latin1(), mFormatName.latin1()); | ||
171 | |||
172 | //US return mFormat->loadAll( addressBook(), this, &file ); | ||
173 | return true; | ||
174 | } | ||
175 | |||
176 | bool ResourceOpie::save( Ticket *ticket ) | ||
177 | { | ||
178 | // qDebug("ResourceFile::save format %s, %s", mFileName.latin1(), mFormatName.latin1()); | ||
179 | kdDebug(5700) << "ResourceOpie::save()" << endl; | ||
180 | |||
181 | // create backup file | ||
182 | QString extension = "_" + QString::number( QDate::currentDate().dayOfWeek() ); | ||
183 | |||
184 | /*US we use a simpler method to create a backupfile | ||
185 | |||
186 | (void) KSaveFile::backupFile( mFileName, QString::null | ||
187 | ,extension ); | ||
188 | |||
189 | KSaveFile saveFile( mFileName ); | ||
190 | bool ok = false; | ||
191 | if ( saveFile.status() == 0 && saveFile.file() ) | ||
192 | { | ||
193 | mFormat->saveAll( addressBook(), this, saveFile.file() ); | ||
194 | ok = saveFile.close(); | ||
195 | } | ||
196 | */ | ||
197 | |||
198 | //US ToDo: write backupfile | ||
199 | QFile info; | ||
200 | info.setName( mFileName ); | ||
201 | bool ok = info.open( IO_WriteOnly ); | ||
202 | if ( ok ) { | ||
203 | //US mFormat->saveAll( addressBook(), this, &info ); | ||
204 | |||
205 | info.close(); | ||
206 | ok = true; | ||
207 | } | ||
208 | else { | ||
209 | |||
210 | } | ||
211 | |||
212 | if ( !ok ) | ||
213 | addressBook()->error( i18n( "Unable to save file '%1'." ).arg( mFileName ) ); | ||
214 | |||
215 | delete ticket; | ||
216 | unlock( mFileName ); | ||
217 | |||
218 | return ok; | ||
219 | |||
220 | qDebug("ResourceOpie::save has to be changed"); | ||
221 | return true; | ||
222 | } | ||
223 | |||
224 | bool ResourceOpie::lock( const QString &fileName ) | ||
225 | { | ||
226 | kdDebug(5700) << "ResourceOpie::lock()" << endl; | ||
227 | |||
228 | QString fn = fileName; | ||
229 | |||
230 | //US change the implementation how the lockfilename is getting created | ||
231 | //US fn.replace( QRegExp("/"), "_" ); | ||
232 | //US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" ); | ||
233 | |||
234 | KURL url(fn); | ||
235 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); | ||
236 | |||
237 | kdDebug(5700) << "-- lock name: " << lockName << endl; | ||
238 | |||
239 | if (QFile::exists( lockName )) return false; | ||
240 | |||
241 | QString lockUniqueName; | ||
242 | lockUniqueName = fn + KApplication::randomString( 8 ); | ||
243 | |||
244 | url = lockUniqueName; | ||
245 | //US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName ); | ||
246 | mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() ); | ||
247 | kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl; | ||
248 | |||
249 | // Create unique file | ||
250 | QFile file( mLockUniqueName ); | ||
251 | file.open( IO_WriteOnly ); | ||
252 | file.close(); | ||
253 | |||
254 | // Create lock file | ||
255 | int result = ::link( QFile::encodeName( mLockUniqueName ), | ||
256 | QFile::encodeName( lockName ) ); | ||
257 | |||
258 | if ( result == 0 ) { | ||
259 | addressBook()->emitAddressBookLocked(); | ||
260 | return true; | ||
261 | } | ||
262 | |||
263 | // TODO: check stat | ||
264 | |||
265 | return false; | ||
266 | } | ||
267 | |||
268 | void ResourceOpie::unlock( const QString &fileName ) | ||
269 | { | ||
270 | QString fn = fileName; | ||
271 | //US change the implementation how the lockfilename is getting created | ||
272 | //US fn.replace( QRegExp( "/" ), "_" ); | ||
273 | //US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" ); | ||
274 | //US QString lockName = fn + ".lock"; | ||
275 | KURL url(fn); | ||
276 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); | ||
277 | |||
278 | QFile::remove( lockName ); | ||
279 | QFile::remove( mLockUniqueName ); | ||
280 | addressBook()->emitAddressBookUnlocked(); | ||
281 | } | ||
282 | |||
283 | void ResourceOpie::setFileName( const QString &fileName ) | ||
284 | { | ||
285 | /*US ToDo: no synchronization so far. Has to be changed in the future | ||
286 | mDirWatch.stopScan(); | ||
287 | mDirWatch.removeFile( mFileName ); | ||
288 | */ | ||
289 | mFileName = fileName; | ||
290 | |||
291 | |||
292 | /*US ToDo: no synchronization so far. Has to be changed in the future | ||
293 | mDirWatch.addFile( mFileName ); | ||
294 | mDirWatch.startScan(); | ||
295 | */ | ||
296 | //US simulate KDirWatch event | ||
297 | fileChanged(); | ||
298 | } | ||
299 | |||
300 | QString ResourceOpie::fileName() const | ||
301 | { | ||
302 | return mFileName; | ||
303 | } | ||
304 | |||
305 | /*US | ||
306 | void ResourceOpie::setFormat( const QString &format ) | ||
307 | { | ||
308 | mFormatName = format; | ||
309 | delete mFormat; | ||
310 | |||
311 | FormatFactory *factory = FormatFactory::self(); | ||
312 | mFormat = factory->format( mFormatName ); | ||
313 | } | ||
314 | |||
315 | QString ResourceOpie::format() const | ||
316 | { | ||
317 | return mFormatName; | ||
318 | } | ||
319 | */ | ||
320 | |||
321 | void ResourceOpie::fileChanged() | ||
322 | { | ||
323 | // There is a small theoretical chance that KDirWatch calls us before | ||
324 | // we are fully constructed | ||
325 | if (!addressBook()) | ||
326 | return; | ||
327 | load(); | ||
328 | addressBook()->emitAddressBookChanged(); | ||
329 | } | ||
330 | |||
331 | void ResourceOpie::removeAddressee( const Addressee &addr ) | ||
332 | { | ||
333 | /*US | ||
334 | QFile::remove( QFile::encodeName( locateLocal( "data", "kabc/photos/" ) + addr.uid() ) ); | ||
335 | QFile::remove( QFile::encodeName( locateLocal( "data", "kabc/logos/" ) + addr.uid() ) ); | ||
336 | QFile::remove( QFile::encodeName( locateLocal( "data", "kabc/sounds/" ) + addr.uid() ) ); | ||
337 | */ | ||
338 | } | ||
339 | |||
340 | void ResourceOpie::cleanUp() | ||
341 | { | ||
342 | unlock( mFileName ); | ||
343 | } | ||
344 | |||
345 | //US #include "resourceopie.moc" | ||
diff --git a/kabc/plugins/opie/resourceopie.h b/kabc/plugins/opie/resourceopie.h new file mode 100644 index 0000000..d21272a --- a/dev/null +++ b/kabc/plugins/opie/resourceopie.h | |||
@@ -0,0 +1,149 @@ | |||
1 | /* | ||
2 | This file is part of libkabc. | ||
3 | Copyright (c) 2001 Cornelius Schumacher <schumacher@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 | |||
29 | #ifndef KABC_RESOURCEOPIE_H | ||
30 | #define KABC_RESOURCEOPIE_H | ||
31 | |||
32 | #include <kconfig.h> | ||
33 | #include <kdirwatch.h> | ||
34 | |||
35 | #include <sys/types.h> | ||
36 | |||
37 | #include "resource.h" | ||
38 | |||
39 | class QTimer; | ||
40 | class FormatPlugin; | ||
41 | |||
42 | namespace KABC { | ||
43 | |||
44 | //US class FormatPlugin; | ||
45 | class ResourceConfigWidget; | ||
46 | |||
47 | /** | ||
48 | @internal | ||
49 | */ | ||
50 | class ResourceOpie : public Resource | ||
51 | { | ||
52 | Q_OBJECT | ||
53 | |||
54 | public: | ||
55 | |||
56 | /** | ||
57 | Constructor. | ||
58 | |||
59 | @param cfg The config object where custom resource settings are stored. | ||
60 | */ | ||
61 | ResourceOpie( const KConfig *cfg ); | ||
62 | |||
63 | /** | ||
64 | Construct file resource on file @arg fileName using format @arg formatName. | ||
65 | */ | ||
66 | ResourceOpie( const QString &fileName ); | ||
67 | |||
68 | /** | ||
69 | * Destructor. | ||
70 | */ | ||
71 | ~ResourceOpie(); | ||
72 | |||
73 | /** | ||
74 | Writes the config back. | ||
75 | */ | ||
76 | virtual void writeConfig( KConfig *cfg ); | ||
77 | |||
78 | /** | ||
79 | * Tries to open the file and checks for the proper format. | ||
80 | * This method should be called before @ref load(). | ||
81 | */ | ||
82 | virtual bool doOpen(); | ||
83 | |||
84 | /** | ||
85 | * Closes the file again. | ||
86 | */ | ||
87 | virtual void doClose(); | ||
88 | |||
89 | /** | ||
90 | * Requests a save ticket, that is used by @ref save() | ||
91 | */ | ||
92 | virtual Ticket *requestSaveTicket(); | ||
93 | |||
94 | /** | ||
95 | * Loads all addressees from file to the address book. | ||
96 | * Returns true if all addressees could be loaded otherwise false. | ||
97 | */ | ||
98 | virtual bool load(); | ||
99 | |||
100 | /** | ||
101 | * Saves all addresses from address book to file. | ||
102 | * Returns true if all addressees could be saved otherwise false. | ||
103 | * | ||
104 | * @param ticket The ticket returned by @ref requestSaveTicket() | ||
105 | */ | ||
106 | virtual bool save( Ticket *ticket ); | ||
107 | |||
108 | /** | ||
109 | * Set name of file to be used for saving. | ||
110 | */ | ||
111 | void setFileName( const QString & ); | ||
112 | |||
113 | /** | ||
114 | * Return name of file used for loading and saving the address book. | ||
115 | */ | ||
116 | QString fileName() const; | ||
117 | |||
118 | /** | ||
119 | * Remove a addressee from its source. | ||
120 | * This method is mainly called by KABC::AddressBook. | ||
121 | */ | ||
122 | virtual void removeAddressee( const Addressee& addr ); | ||
123 | |||
124 | /** | ||
125 | * This method is called by an error handler if the application | ||
126 | * crashed | ||
127 | */ | ||
128 | virtual void cleanUp(); | ||
129 | |||
130 | protected slots: | ||
131 | void fileChanged(); | ||
132 | |||
133 | protected: | ||
134 | void init( const QString &fileName ); | ||
135 | |||
136 | bool lock( const QString &fileName ); | ||
137 | void unlock( const QString &fileName ); | ||
138 | |||
139 | private: | ||
140 | QString mFileName; | ||
141 | |||
142 | QString mLockUniqueName; | ||
143 | |||
144 | KDirWatch mDirWatch; | ||
145 | }; | ||
146 | |||
147 | } | ||
148 | |||
149 | #endif | ||
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" | ||
diff --git a/kabc/plugins/opie/resourceopieconfig.h b/kabc/plugins/opie/resourceopieconfig.h new file mode 100644 index 0000000..533b7f4 --- a/dev/null +++ b/kabc/plugins/opie/resourceopieconfig.h | |||
@@ -0,0 +1,61 @@ | |||
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 | /* | ||
23 | Enhanced Version of the file for platform independent KDE tools. | ||
24 | Copyright (c) 2004 Ulf Schenk | ||
25 | |||
26 | $Id$ | ||
27 | */ | ||
28 | |||
29 | #ifndef RESOURCEOPIECONFIG_H | ||
30 | #define RESOURCEOPIECONFIG_H | ||
31 | |||
32 | #include <kurlrequester.h> | ||
33 | |||
34 | #include <kresources/configwidget.h> | ||
35 | |||
36 | namespace KABC { | ||
37 | |||
38 | class ResourceOpieConfig : public KRES::ConfigWidget | ||
39 | { | ||
40 | Q_OBJECT | ||
41 | |||
42 | public: | ||
43 | ResourceOpieConfig( QWidget* parent = 0, const char* name = 0 ); | ||
44 | |||
45 | //US void setEditMode( bool value ); | ||
46 | |||
47 | public slots: | ||
48 | void loadSettings( KRES::Resource *resource ); | ||
49 | void saveSettings( KRES::Resource *resource ); | ||
50 | |||
51 | protected slots: | ||
52 | void checkFilePermissions( const QString& fileName ); | ||
53 | |||
54 | private: | ||
55 | KURLRequester* mFileNameEdit; | ||
56 | //US bool mInEditMode; | ||
57 | }; | ||
58 | |||
59 | } | ||
60 | |||
61 | #endif | ||