author | ulf69 <ulf69> | 2004-07-12 23:34:33 (UTC) |
---|---|---|
committer | ulf69 <ulf69> | 2004-07-12 23:34:33 (UTC) |
commit | bce030bdee5c381d7937ef3d2b1b49ce24bbd1ae (patch) (unidiff) | |
tree | e92c85b28da2db2552f64be567e511c13106cc82 /kabc | |
parent | c4d51e8f5ecf7be146ee53ea2bbe3af6fca25d4d (diff) | |
download | kdepimpi-bce030bdee5c381d7937ef3d2b1b49ce24bbd1ae.zip kdepimpi-bce030bdee5c381d7937ef3d2b1b49ce24bbd1ae.tar.gz kdepimpi-bce030bdee5c381d7937ef3d2b1b49ce24bbd1ae.tar.bz2 |
added first version of the qtopia resourcefiles. The content is of no meaning
-rw-r--r-- | kabc/plugins/qtopia/qtopiaE.pro | 32 | ||||
-rw-r--r-- | kabc/plugins/qtopia/resourceqtopia.cpp | 410 | ||||
-rw-r--r-- | kabc/plugins/qtopia/resourceqtopia.h | 152 | ||||
-rw-r--r-- | kabc/plugins/qtopia/resourceqtopiaconfig.cpp | 107 | ||||
-rw-r--r-- | kabc/plugins/qtopia/resourceqtopiaconfig.h | 58 |
5 files changed, 759 insertions, 0 deletions
diff --git a/kabc/plugins/qtopia/qtopiaE.pro b/kabc/plugins/qtopia/qtopiaE.pro new file mode 100644 index 0000000..d945c31 --- a/dev/null +++ b/kabc/plugins/qtopia/qtopiaE.pro | |||
@@ -0,0 +1,32 @@ | |||
1 | TEMPLATE= lib | ||
2 | CONFIG += qt warn_on | ||
3 | #release debug | ||
4 | TARGET = microkabc_qtopia | ||
5 | |||
6 | INCLUDEPATH += ../.. ../../converter/opie ../../../microkde ../../../microkde/kdecore ../../../microkde/kio/kfile ../../../qtcompat $(QPEDIR)/include $(OPIEDIR)/include | ||
7 | |||
8 | |||
9 | OBJECTS_DIR = obj/$(PLATFORM) | ||
10 | MOC_DIR = moc/$(PLATFORM) | ||
11 | DESTDIR = $(QPEDIR)/lib | ||
12 | LIBS += -lmicrokde | ||
13 | LIBS += -lmicrokabc | ||
14 | LIBS += -L$(QPEDIR)/lib | ||
15 | LIBS += -L$(OPIEDIR)/lib | ||
16 | LIBS += -lopie | ||
17 | LIBS += -lqpe | ||
18 | LIBS += -lqte | ||
19 | LIBS += -lmicrokabc_opieconverter | ||
20 | #LIBS += -L../../lib/$(PLATFORM) | ||
21 | |||
22 | |||
23 | INTERFACES = \ | ||
24 | |||
25 | HEADERS = \ | ||
26 | resourceqtopia.h \ | ||
27 | resourceqtopiaconfig.h \ | ||
28 | |||
29 | SOURCES = \ | ||
30 | resourceqtopia.cpp \ | ||
31 | resourceqtopiaconfig.cpp \ | ||
32 | |||
diff --git a/kabc/plugins/qtopia/resourceqtopia.cpp b/kabc/plugins/qtopia/resourceqtopia.cpp new file mode 100644 index 0000000..3d9d28b --- a/dev/null +++ b/kabc/plugins/qtopia/resourceqtopia.cpp | |||
@@ -0,0 +1,410 @@ | |||
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 <qdir.h> | ||
33 | #include <qfile.h> | ||
34 | #include <qfileinfo.h> | ||
35 | #include <qregexp.h> | ||
36 | #include <qtimer.h> | ||
37 | |||
38 | #include <kapplication.h> | ||
39 | #include <kconfig.h> | ||
40 | #include <kdebug.h> | ||
41 | #include <klocale.h> | ||
42 | //US #include <ksavefile.h> | ||
43 | #include <kstandarddirs.h> | ||
44 | |||
45 | //US #include "formatfactory.h" | ||
46 | //US #include <qpe/qpeapplication.h> | ||
47 | |||
48 | #include <opie/ocontactaccess.h> | ||
49 | #include <opie/ocontactaccessbackend_xml.h> | ||
50 | |||
51 | #include "resource.h" | ||
52 | #include "resourceqtopiaconfig.h" | ||
53 | #include "stdaddressbook.h" | ||
54 | |||
55 | #include "opieconverter.h" | ||
56 | |||
57 | #include "resourceqtopia.h" | ||
58 | |||
59 | using namespace KABC; | ||
60 | extern "C" | ||
61 | { | ||
62 | void *init_microkabc_qtopia() | ||
63 | { | ||
64 | return new KRES::PluginFactory<ResourceOpie,ResourceOpieConfig>(); | ||
65 | } | ||
66 | } | ||
67 | |||
68 | ResourceOpie::ResourceOpie( const KConfig *config ) | ||
69 | : Resource( config ), mConverter (0) | ||
70 | { | ||
71 | QString fileName = QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml"; | ||
72 | |||
73 | KConfig *cfg = (KConfig *)config; | ||
74 | if ( cfg ) { | ||
75 | fileName = cfg->readEntry( "FileName", fileName ); | ||
76 | |||
77 | } | ||
78 | |||
79 | // qDebug("ResourceOpie::ResourceOpie : %s", fileName.latin1() ); | ||
80 | |||
81 | init( fileName ); | ||
82 | } | ||
83 | |||
84 | ResourceOpie::ResourceOpie( const QString &fileName ) | ||
85 | : Resource( 0 ) | ||
86 | { | ||
87 | // qDebug("ResourceOpie::ResourceOpie : 3 %s", fileName.latin1()); | ||
88 | init( fileName ); | ||
89 | } | ||
90 | |||
91 | void ResourceOpie::init( const QString &fileName ) | ||
92 | { | ||
93 | |||
94 | /*US we have no KDirWatch. SO simulate the signals from inside the apropriate methods | ||
95 | connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) ); | ||
96 | connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) ); | ||
97 | connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) ); | ||
98 | */ | ||
99 | //US opie addressbook is always readonly | ||
100 | //US setReadOnly( true ); | ||
101 | |||
102 | setFileName( fileName ); | ||
103 | |||
104 | } | ||
105 | |||
106 | ResourceOpie::~ResourceOpie() | ||
107 | { | ||
108 | if (mConverter != 0) | ||
109 | delete mConverter; | ||
110 | } | ||
111 | |||
112 | void ResourceOpie::writeConfig( KConfig *config ) | ||
113 | { | ||
114 | //US opie addressbook is always readonly | ||
115 | //US setReadOnly( true ); | ||
116 | |||
117 | Resource::writeConfig( config ); | ||
118 | |||
119 | config->writeEntry( "FileName", mFileName ); | ||
120 | |||
121 | // qDebug("ResourceFile::writeConfig format %s, %s", mFileName.latin1(), mFormatName.latin1()); | ||
122 | |||
123 | } | ||
124 | |||
125 | Ticket *ResourceOpie::requestSaveTicket() | ||
126 | { | ||
127 | kdDebug(5700) << "ResourceOpie::requestSaveTicket()" << endl; | ||
128 | |||
129 | if ( !addressBook() ) return 0; | ||
130 | |||
131 | if ( !lock( mFileName ) ) { | ||
132 | kdDebug(5700) << "ResourceOpie::requestSaveTicket(): Unable to lock file '" | ||
133 | << mFileName << "'" << endl; | ||
134 | return 0; | ||
135 | } | ||
136 | return createTicket( this ); | ||
137 | } | ||
138 | |||
139 | |||
140 | bool ResourceOpie::doOpen() | ||
141 | { | ||
142 | // qDebug("ResourceOpie::doOpen() %s", mFileName.latin1()); | ||
143 | /*US | ||
144 | QFile file( mFileName ); | ||
145 | |||
146 | if ( !file.exists() ) { | ||
147 | // try to create the file | ||
148 | bool ok = file.open( IO_WriteOnly ); | ||
149 | if ( ok ) | ||
150 | file.close(); | ||
151 | |||
152 | return ok; | ||
153 | } else { | ||
154 | if ( !file.open( IO_ReadWrite ) ) | ||
155 | return false; | ||
156 | |||
157 | if ( file.size() == 0 ) { | ||
158 | file.close(); | ||
159 | return true; | ||
160 | } | ||
161 | |||
162 | //US bool ok = mFormat->checkFormat( &file ); | ||
163 | bool ok = true; | ||
164 | |||
165 | file.close(); | ||
166 | |||
167 | return ok; | ||
168 | } | ||
169 | */ | ||
170 | qDebug("ResourceOpie::doOpen() has to be fixed - %s", mFileName.latin1()); | ||
171 | return true; | ||
172 | } | ||
173 | |||
174 | void ResourceOpie::doClose() | ||
175 | { | ||
176 | // qDebug("ResourceOpie::doClose() %s", mFileName.latin1()); | ||
177 | } | ||
178 | |||
179 | bool ResourceOpie::load() | ||
180 | { | ||
181 | // qDebug("ResourceOpie::load() %s", mFileName.latin1()); | ||
182 | kdDebug(5700) << "ResourceOpie::load(): '" << mFileName << "'" << endl; | ||
183 | |||
184 | qDebug("ResourceOpie::load: Try to load file() %s", mFileName.latin1()); | ||
185 | |||
186 | OContactAccessBackend_XML* backend = new OContactAccessBackend_XML( "KDEPim/Pi", mFileName ); | ||
187 | OContactAccess* access = new OContactAccess("KDEPim/Pi", 0l, backend, false); | ||
188 | |||
189 | if ( !access ) { | ||
190 | qDebug("Unable to load file() %s", mFileName.latin1()); | ||
191 | addressBook()->error( i18n( "Unable to load file '%1'." ).arg( mFileName ) ); | ||
192 | return false; | ||
193 | } | ||
194 | |||
195 | access -> setReadAhead( 32 ); // Use ReadAhead-Cache if available | ||
196 | |||
197 | bool res = false; | ||
198 | if (mConverter == 0) | ||
199 | { | ||
200 | mConverter = new OpieConverter(); | ||
201 | res = mConverter->init(); | ||
202 | if ( !res ) | ||
203 | { | ||
204 | qDebug("Unable to initialize opie converter. Most likely a problem with the category file"); | ||
205 | addressBook()->error( i18n( "Unable to initialize opie converter. Most likely a problem with the category file" ) ); | ||
206 | delete access; | ||
207 | return false; | ||
208 | } | ||
209 | } | ||
210 | |||
211 | |||
212 | OContactAccess::List::Iterator it; | ||
213 | OContactAccess::List allList = access->allRecords(); | ||
214 | for ( it = allList.begin(); it != allList.end(); ++it ) | ||
215 | { | ||
216 | OContact c = (*it); | ||
217 | |||
218 | KABC::Addressee addressee; | ||
219 | |||
220 | res = mConverter->opieToAddressee( c, addressee ); | ||
221 | |||
222 | if ( !addressee.isEmpty() && res ) | ||
223 | { | ||
224 | addressee.setResource( this ); | ||
225 | addressBook()->insertAddressee( addressee ); | ||
226 | } | ||
227 | |||
228 | // qDebug("found %s", c.fullName().latin1()); | ||
229 | } | ||
230 | |||
231 | delete access; | ||
232 | // it seems so, that deletion of access deletes backend as well | ||
233 | //delete backend; | ||
234 | |||
235 | return true; | ||
236 | } | ||
237 | |||
238 | bool ResourceOpie::save( Ticket *ticket ) | ||
239 | { | ||
240 | qDebug("ResourceOpie::save() has to be fixed - %s", mFileName.latin1()); | ||
241 | /*US | ||
242 | |||
243 | qDebug("ResourceOpie::save %s", mFileName.latin1()); | ||
244 | kdDebug(5700) << "ResourceOpie::save()" << endl; | ||
245 | |||
246 | // create backup file | ||
247 | QString extension = "_" + QString::number( QDate::currentDate().dayOfWeek() ); | ||
248 | */ | ||
249 | /*US we use a simpler method to create a backupfile | ||
250 | |||
251 | (void) KSaveFile::backupFile( mFileName, QString::null | ||
252 | ,extension ); | ||
253 | |||
254 | KSaveFile saveFile( mFileName ); | ||
255 | bool ok = false; | ||
256 | if ( saveFile.status() == 0 && saveFile.file() ) | ||
257 | { | ||
258 | mFormat->saveAll( addressBook(), this, saveFile.file() ); | ||
259 | ok = saveFile.close(); | ||
260 | } | ||
261 | */ | ||
262 | /*US | ||
263 | //US ToDo: write backupfile | ||
264 | QFile info; | ||
265 | info.setName( mFileName ); | ||
266 | bool ok = info.open( IO_WriteOnly ); | ||
267 | if ( ok ) { | ||
268 | //US mFormat->saveAll( addressBook(), this, &info ); | ||
269 | |||
270 | info.close(); | ||
271 | ok = true; | ||
272 | } | ||
273 | else { | ||
274 | |||
275 | } | ||
276 | |||
277 | if ( !ok ) | ||
278 | addressBook()->error( i18n( "Unable to save file '%1'." ).arg( mFileName ) ); | ||
279 | |||
280 | delete ticket; | ||
281 | unlock( mFileName ); | ||
282 | |||
283 | return ok; | ||
284 | |||
285 | qDebug("ResourceOpie::save has to be changed"); | ||
286 | */ | ||
287 | return true; | ||
288 | |||
289 | } | ||
290 | |||
291 | bool ResourceOpie::lock( const QString &fileName ) | ||
292 | { | ||
293 | qDebug("ResourceOpie::lock() has to be fixed - %s", mFileName.latin1()); | ||
294 | |||
295 | /*US | ||
296 | // qDebug("ResourceOpie::lock() %s", fileName.latin1()); | ||
297 | kdDebug(5700) << "ResourceOpie::lock()" << endl; | ||
298 | |||
299 | QString fn = fileName; | ||
300 | |||
301 | //US change the implementation how the lockfilename is getting created | ||
302 | //US fn.replace( QRegExp("/"), "_" ); | ||
303 | //US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" ); | ||
304 | |||
305 | KURL url(fn); | ||
306 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); | ||
307 | |||
308 | kdDebug(5700) << "-- lock name: " << lockName << endl; | ||
309 | |||
310 | if (QFile::exists( lockName )) return false; | ||
311 | |||
312 | QString lockUniqueName; | ||
313 | lockUniqueName = fn + KApplication::randomString( 8 ); | ||
314 | |||
315 | url = lockUniqueName; | ||
316 | //US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName ); | ||
317 | mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() ); | ||
318 | kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl; | ||
319 | |||
320 | // Create unique file | ||
321 | QFile file( mLockUniqueName ); | ||
322 | file.open( IO_WriteOnly ); | ||
323 | file.close(); | ||
324 | |||
325 | // Create lock file | ||
326 | int result = ::link( QFile::encodeName( mLockUniqueName ), | ||
327 | QFile::encodeName( lockName ) ); | ||
328 | |||
329 | if ( result == 0 ) { | ||
330 | addressBook()->emitAddressBookLocked(); | ||
331 | return true; | ||
332 | } | ||
333 | |||
334 | // TODO: check stat | ||
335 | |||
336 | return false; | ||
337 | */ | ||
338 | |||
339 | return true; | ||
340 | } | ||
341 | |||
342 | void ResourceOpie::unlock( const QString &fileName ) | ||
343 | { | ||
344 | qDebug("ResourceOpie::unlock() has to be fixed - %s", mFileName.latin1()); | ||
345 | /*US | ||
346 | // qDebug("ResourceOpie::unlock() %s", fileName.latin1()); | ||
347 | |||
348 | QString fn = fileName; | ||
349 | //US change the implementation how the lockfilename is getting created | ||
350 | //US fn.replace( QRegExp( "/" ), "_" ); | ||
351 | //US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" ); | ||
352 | //US QString lockName = fn + ".lock"; | ||
353 | KURL url(fn); | ||
354 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); | ||
355 | |||
356 | QFile::remove( lockName ); | ||
357 | QFile::remove( mLockUniqueName ); | ||
358 | addressBook()->emitAddressBookUnlocked(); | ||
359 | */ | ||
360 | } | ||
361 | |||
362 | void ResourceOpie::setFileName( const QString &fileName ) | ||
363 | { | ||
364 | /*US ToDo: no synchronization so far. Has to be changed in the future | ||
365 | mDirWatch.stopScan(); | ||
366 | mDirWatch.removeFile( mFileName ); | ||
367 | */ | ||
368 | mFileName = fileName; | ||
369 | |||
370 | |||
371 | /*US ToDo: no synchronization so far. Has to be changed in the future | ||
372 | mDirWatch.addFile( mFileName ); | ||
373 | mDirWatch.startScan(); | ||
374 | */ | ||
375 | //US simulate KDirWatch event | ||
376 | fileChanged(); | ||
377 | } | ||
378 | |||
379 | QString ResourceOpie::fileName() const | ||
380 | { | ||
381 | return mFileName; | ||
382 | } | ||
383 | |||
384 | void ResourceOpie::fileChanged() | ||
385 | { | ||
386 | // There is a small theoretical chance that KDirWatch calls us before | ||
387 | // we are fully constructed | ||
388 | if (!addressBook()) | ||
389 | return; | ||
390 | load(); | ||
391 | addressBook()->emitAddressBookChanged(); | ||
392 | } | ||
393 | |||
394 | void ResourceOpie::removeAddressee( const Addressee &addr ) | ||
395 | { | ||
396 | /*US | ||
397 | QFile::remove( QFile::encodeName( locateLocal( "data", "kabc/photos/" ) + addr.uid() ) ); | ||
398 | QFile::remove( QFile::encodeName( locateLocal( "data", "kabc/logos/" ) + addr.uid() ) ); | ||
399 | QFile::remove( QFile::encodeName( locateLocal( "data", "kabc/sounds/" ) + addr.uid() ) ); | ||
400 | */ | ||
401 | } | ||
402 | |||
403 | void ResourceOpie::cleanUp() | ||
404 | { | ||
405 | // qDebug("ResourceOpie::cleanup() %s", mFileName.latin1()); | ||
406 | |||
407 | unlock( mFileName ); | ||
408 | } | ||
409 | |||
410 | //US #include "resourceopie.moc" | ||
diff --git a/kabc/plugins/qtopia/resourceqtopia.h b/kabc/plugins/qtopia/resourceqtopia.h new file mode 100644 index 0000000..ea0b5ee --- a/dev/null +++ b/kabc/plugins/qtopia/resourceqtopia.h | |||
@@ -0,0 +1,152 @@ | |||
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_RESOURCEQTOPIA_H | ||
30 | #define KABC_RESOURCEQTOPIA_H | ||
31 | |||
32 | #include <kconfig.h> | ||
33 | #include <kdirwatch.h> | ||
34 | |||
35 | #include <sys/types.h> | ||
36 | |||
37 | #include "resource.h" | ||
38 | |||
39 | |||
40 | //class QTimer; | ||
41 | //class FormatPlugin; | ||
42 | |||
43 | namespace KABC { | ||
44 | |||
45 | //US class FormatPlugin; | ||
46 | class ResourceConfigWidget; | ||
47 | class OpieConverter; | ||
48 | /** | ||
49 | @internal | ||
50 | */ | ||
51 | class ResourceOpie : public Resource | ||
52 | { | ||
53 | Q_OBJECT | ||
54 | |||
55 | public: | ||
56 | |||
57 | /** | ||
58 | Constructor. | ||
59 | |||
60 | @param cfg The config object where custom resource settings are stored. | ||
61 | */ | ||
62 | ResourceOpie( const KConfig *cfg ); | ||
63 | |||
64 | /** | ||
65 | Construct file resource on file @arg fileName using format @arg formatName. | ||
66 | */ | ||
67 | ResourceOpie( const QString &fileName ); | ||
68 | |||
69 | /** | ||
70 | * Destructor. | ||
71 | */ | ||
72 | ~ResourceOpie(); | ||
73 | |||
74 | /** | ||
75 | Writes the config back. | ||
76 | */ | ||
77 | virtual void writeConfig( KConfig *cfg ); | ||
78 | |||
79 | /** | ||
80 | * Tries to open the file and checks for the proper format. | ||
81 | * This method should be called before @ref load(). | ||
82 | */ | ||
83 | virtual bool doOpen(); | ||
84 | |||
85 | /** | ||
86 | * Closes the file again. | ||
87 | */ | ||
88 | virtual void doClose(); | ||
89 | |||
90 | /** | ||
91 | * Requests a save ticket, that is used by @ref save() | ||
92 | */ | ||
93 | virtual Ticket *requestSaveTicket(); | ||
94 | |||
95 | /** | ||
96 | * Loads all addressees from file to the address book. | ||
97 | * Returns true if all addressees could be loaded otherwise false. | ||
98 | */ | ||
99 | virtual bool load(); | ||
100 | |||
101 | /** | ||
102 | * Saves all addresses from address book to file. | ||
103 | * Returns true if all addressees could be saved otherwise false. | ||
104 | * | ||
105 | * @param ticket The ticket returned by @ref requestSaveTicket() | ||
106 | */ | ||
107 | virtual bool save( Ticket *ticket ); | ||
108 | |||
109 | /** | ||
110 | * Set name of file to be used for saving. | ||
111 | */ | ||
112 | void setFileName( const QString & ); | ||
113 | |||
114 | /** | ||
115 | * Return name of file used for loading and saving the address book. | ||
116 | */ | ||
117 | QString fileName() const; | ||
118 | |||
119 | /** | ||
120 | * Remove a addressee from its source. | ||
121 | * This method is mainly called by KABC::AddressBook. | ||
122 | */ | ||
123 | virtual void removeAddressee( const Addressee& addr ); | ||
124 | |||
125 | /** | ||
126 | * This method is called by an error handler if the application | ||
127 | * crashed | ||
128 | */ | ||
129 | virtual void cleanUp(); | ||
130 | |||
131 | protected slots: | ||
132 | void fileChanged(); | ||
133 | |||
134 | protected: | ||
135 | void init( const QString &fileName ); | ||
136 | |||
137 | bool lock( const QString &fileName ); | ||
138 | void unlock( const QString &fileName ); | ||
139 | |||
140 | private: | ||
141 | OpieConverter* mConverter; | ||
142 | |||
143 | QString mFileName; | ||
144 | |||
145 | QString mLockUniqueName; | ||
146 | |||
147 | KDirWatch mDirWatch; | ||
148 | }; | ||
149 | |||
150 | } | ||
151 | |||
152 | #endif | ||
diff --git a/kabc/plugins/qtopia/resourceqtopiaconfig.cpp b/kabc/plugins/qtopia/resourceqtopiaconfig.cpp new file mode 100644 index 0000000..8cb8505 --- a/dev/null +++ b/kabc/plugins/qtopia/resourceqtopiaconfig.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 <qdir.h> | ||
39 | #include <qfile.h> | ||
40 | #include "resourceqtopia.h" | ||
41 | //US #include <qpe/qpeapplication.h> | ||
42 | |||
43 | //US #include "stdaddressbook.h" | ||
44 | |||
45 | #include "resourceqtopiaconfig.h" | ||
46 | |||
47 | using namespace KABC; | ||
48 | |||
49 | ResourceOpieConfig::ResourceOpieConfig( QWidget* parent, const char* name ) | ||
50 | : ConfigWidget( parent, name ) | ||
51 | { | ||
52 | //qDebug("ResourceFileConfig::ResourceFileConfig"); | ||
53 | |||
54 | QGridLayout *mainLayout = new QGridLayout( this, 1, 2, 0, | ||
55 | KDialog::spacingHint() ); | ||
56 | |||
57 | QLabel *label = new QLabel( i18n( "Location:" ), this ); | ||
58 | mFileNameEdit = new KURLRequester( this ); | ||
59 | |||
60 | connect( mFileNameEdit, SIGNAL( textChanged( const QString & ) ), | ||
61 | SLOT( checkFilePermissions( const QString & ) ) ); | ||
62 | |||
63 | mainLayout->addWidget( label, 0, 0 ); | ||
64 | mainLayout->addWidget( mFileNameEdit, 0, 1 ); | ||
65 | } | ||
66 | |||
67 | void ResourceOpieConfig::loadSettings( KRES::Resource *res ) | ||
68 | { | ||
69 | //US ResourceFile *resource = dynamic_cast<ResourceFile*>( res ); | ||
70 | ResourceOpie *resource = (ResourceOpie*)( res ); | ||
71 | |||
72 | if ( !resource ) { | ||
73 | kdDebug(5700) << "ResourceOpieConfig::loadSettings(): cast failed" << endl; | ||
74 | return; | ||
75 | } | ||
76 | |||
77 | mFileNameEdit->setURL( resource->fileName() ); | ||
78 | if ( mFileNameEdit->url().isEmpty() ) | ||
79 | mFileNameEdit->setURL( QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml" ); | ||
80 | |||
81 | //US Opie resources are ReadOnly by definition | ||
82 | emit setPersistentReadOnly( true ); | ||
83 | } | ||
84 | |||
85 | void ResourceOpieConfig::saveSettings( KRES::Resource *res ) | ||
86 | { | ||
87 | //US ResourceFile *resource = dynamic_cast<ResourceFile*>( res ); | ||
88 | ResourceOpie *resource = (ResourceOpie*)( res ); | ||
89 | |||
90 | if ( !resource ) { | ||
91 | kdDebug(5700) << "ResourceOpieConfig::saveSettings(): cast failed" << endl; | ||
92 | return; | ||
93 | } | ||
94 | |||
95 | resource->setFileName( mFileNameEdit->url() ); | ||
96 | } | ||
97 | |||
98 | void ResourceOpieConfig::checkFilePermissions( const QString& fileName ) | ||
99 | { | ||
100 | // If file exist but is not writeable... | ||
101 | /*US | ||
102 | if ( access( QFile::encodeName( fileName ), F_OK ) == 0 ) | ||
103 | emit setReadOnly( access( QFile::encodeName( fileName ), W_OK ) < 0 ); | ||
104 | */ | ||
105 | } | ||
106 | |||
107 | //US #include "resourceopieconfig.moc" | ||
diff --git a/kabc/plugins/qtopia/resourceqtopiaconfig.h b/kabc/plugins/qtopia/resourceqtopiaconfig.h new file mode 100644 index 0000000..0d80625 --- a/dev/null +++ b/kabc/plugins/qtopia/resourceqtopiaconfig.h | |||
@@ -0,0 +1,58 @@ | |||
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 RESOURCEQTOPIACONFIG_H | ||
30 | #define RESOURCEQTOPIACONFIG_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 | public slots: | ||
46 | void loadSettings( KRES::Resource *resource ); | ||
47 | void saveSettings( KRES::Resource *resource ); | ||
48 | |||
49 | protected slots: | ||
50 | void checkFilePermissions( const QString& fileName ); | ||
51 | |||
52 | private: | ||
53 | KURLRequester* mFileNameEdit; | ||
54 | }; | ||
55 | |||
56 | } | ||
57 | |||
58 | #endif | ||