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