summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/plugins/dir/resourcedir.cpp10
-rw-r--r--kabc/plugins/file/resourcefile.cpp10
-rw-r--r--kabc/plugins/opie/resourceopie.cpp12
-rw-r--r--kabc/plugins/qtopia/resourceqtopia.cpp9
-rw-r--r--kaddressbook/details/detailsviewcontainer.cpp3
-rw-r--r--kaddressbook/kabcore.cpp1
6 files changed, 33 insertions, 12 deletions
diff --git a/kabc/plugins/dir/resourcedir.cpp b/kabc/plugins/dir/resourcedir.cpp
index 7825c6f..52863d5 100644
--- a/kabc/plugins/dir/resourcedir.cpp
+++ b/kabc/plugins/dir/resourcedir.cpp
@@ -1,362 +1,364 @@
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 28
29#include <sys/types.h> 29#include <sys/types.h>
30#include <sys/stat.h> 30#include <sys/stat.h>
31#ifndef _WIN32_ 31#ifndef _WIN32_
32#include <unistd.h> 32#include <unistd.h>
33#endif 33#endif
34 34
35#include <qregexp.h> 35#include <qregexp.h>
36#include <qtimer.h> 36#include <qtimer.h>
37#include <qwidget.h> 37#include <qwidget.h>
38 38
39#include <kapplication.h> 39#include <kapplication.h>
40#include <kconfig.h> 40#include <kconfig.h>
41#include <kdebug.h> 41#include <kdebug.h>
42//US #include <kgenericfactory.h> 42//US #include <kgenericfactory.h>
43#include <kglobal.h> 43#include <kglobal.h>
44#include <klocale.h> 44#include <klocale.h>
45#include <kstandarddirs.h> 45#include <kstandarddirs.h>
46#include <kurlrequester.h> 46#include <kurlrequester.h>
47#include <kmessagebox.h>
47 48
48#include "addressbook.h" 49#include "addressbook.h"
49 50
50#include "formatfactory.h" 51#include "formatfactory.h"
51 52
52#include "resourcedirconfig.h" 53#include "resourcedirconfig.h"
53#include "stdaddressbook.h" 54#include "stdaddressbook.h"
54 55
55//US 56//US
56#include <qdir.h> 57#include <qdir.h>
57//US #include "../../formats/vcardformatplugin2.h"
58//US #include "../../formats/binaryformat.h"
59 58
60#include "resourcedir.h" 59#include "resourcedir.h"
61 60
62using namespace KABC; 61using namespace KABC;
63 62
64extern "C" 63extern "C"
65#ifdef _WIN32_ 64#ifdef _WIN32_
66__declspec(dllexport) 65__declspec(dllexport)
67#else 66#else
68{ 67{
69#endif 68#endif
70 69
71//US void *init_kabc_dir() 70//US void *init_kabc_dir()
72 void *init_microkabc_dir() 71 void *init_microkabc_dir()
73 { 72 {
74 return new KRES::PluginFactory<ResourceDir,ResourceDirConfig>(); 73 return new KRES::PluginFactory<ResourceDir,ResourceDirConfig>();
75 } 74 }
76#ifndef _WIN32_ 75#ifndef _WIN32_
77} 76}
78#endif 77#endif
79 78
80ResourceDir::ResourceDir( const KConfig *config ) 79ResourceDir::ResourceDir( const KConfig *config )
81 : Resource( config ) 80 : Resource( config )
82{ 81{
83 QString path; 82 QString path;
84 83
85 KConfig *cfg = (KConfig *)config; 84 KConfig *cfg = (KConfig *)config;
86 if ( cfg ) { 85 if ( cfg ) {
87//US path = config->readEntry( "FilePath" ); 86//US path = config->readEntry( "FilePath" );
88 path = cfg->readEntry( "FilePath", StdAddressBook::directoryName() ); 87 path = cfg->readEntry( "FilePath", StdAddressBook::directoryName() );
89//US mFormatName = config->readEntry( "FileFormat" ); 88//US mFormatName = config->readEntry( "FileFormat" );
90 mFormatName = cfg->readEntry( "FileFormat", "vcard" ); 89 mFormatName = cfg->readEntry( "FileFormat", "vcard" );
91 } else { 90 } else {
92 path = StdAddressBook::directoryName(); 91 path = StdAddressBook::directoryName();
93 mFormatName = "vcard"; 92 mFormatName = "vcard";
94 } 93 }
95 94
96 95
97 FormatFactory *factory = FormatFactory::self(); 96 FormatFactory *factory = FormatFactory::self();
98 mFormat = factory->format( mFormatName ); 97 mFormat = factory->format( mFormatName );
99 98
100 if ( !mFormat ) { 99 if ( !mFormat ) {
101 mFormatName = "vcard"; 100 mFormatName = "vcard";
102 mFormat = factory->format( mFormatName ); 101 mFormat = factory->format( mFormatName );
103 } 102 }
104 103
105/*US 104/*US
106//US qDebug("ResourceDir::ResourceDir initialized with format %s ", mFormatName.latin1()); 105//US qDebug("ResourceDir::ResourceDir initialized with format %s ", mFormatName.latin1());
107 if (mFormatName == "vcard") 106 if (mFormatName == "vcard")
108 mFormat = new VCardFormatPlugin2(); 107 mFormat = new VCardFormatPlugin2();
109 else if (mFormatName == "binary") 108 else if (mFormatName == "binary")
110 mFormat = new BinaryFormat(); 109 mFormat = new BinaryFormat();
111 else 110 else
112 qDebug("ResourceFile::init format unknown !!! %s ", mFormatName.latin1()); 111 qDebug("ResourceFile::init format unknown !!! %s ", mFormatName.latin1());
113*/ 112*/
114 113
115 connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( pathChanged() ) ); 114 connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( pathChanged() ) );
116 connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( pathChanged() ) ); 115 connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( pathChanged() ) );
117 connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( pathChanged() ) ); 116 connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( pathChanged() ) );
118 117
119 setPath( path ); 118 setPath( path );
120} 119}
121 120
122ResourceDir::~ResourceDir() 121ResourceDir::~ResourceDir()
123{ 122{
124 delete mFormat; 123 delete mFormat;
125 mFormat = 0; 124 mFormat = 0;
126} 125}
127 126
128void ResourceDir::writeConfig( KConfig *config ) 127void ResourceDir::writeConfig( KConfig *config )
129{ 128{
130 config->setGroup( "Resource_" + identifier() ); 129 config->setGroup( "Resource_" + identifier() );
131 Resource::writeConfig( config ); 130 Resource::writeConfig( config );
132 131
133 config->writeEntry( "FilePath", mPath ); 132 config->writeEntry( "FilePath", mPath );
134 config->writeEntry( "FileFormat", mFormatName ); 133 config->writeEntry( "FileFormat", mFormatName );
135} 134}
136 135
137Ticket *ResourceDir::requestSaveTicket() 136Ticket *ResourceDir::requestSaveTicket()
138{ 137{
139 kdDebug(5700) << "ResourceDir::requestSaveTicket()" << endl; 138 kdDebug(5700) << "ResourceDir::requestSaveTicket()" << endl;
140 139
141 if ( !addressBook() ) return 0; 140 if ( !addressBook() ) return 0;
142 141
143 if ( !lock( mPath ) ) { 142 if ( !lock( mPath ) ) {
144 kdDebug(5700) << "ResourceDir::requestSaveTicket(): Unable to lock path '" 143 kdDebug(5700) << "ResourceDir::requestSaveTicket(): Unable to lock path '"
145 << mPath << "'" << endl; 144 << mPath << "'" << endl;
146 return 0; 145 return 0;
147 } 146 }
148 return createTicket( this ); 147 return createTicket( this );
149} 148}
150 149
151 150
152bool ResourceDir::doOpen() 151bool ResourceDir::doOpen()
153{ 152{
154 QDir dir( mPath ); 153 QDir dir( mPath );
155 if ( !dir.exists() ) { // no directory available 154 if ( !dir.exists() ) { // no directory available
156 return dir.mkdir( dir.path() ); 155 return dir.mkdir( dir.path() );
157 } else { 156 } else {
158 QString testName = dir.entryList( QDir::Files )[0]; 157 QString testName = dir.entryList( QDir::Files )[0];
159 if ( testName.isNull() || testName.isEmpty() ) // no file in directory 158 if ( testName.isNull() || testName.isEmpty() ) // no file in directory
160 return true; 159 return true;
161 160
162 QFile file( mPath + "/" + testName ); 161 QFile file( mPath + "/" + testName );
163 if ( file.open( IO_ReadOnly ) ) 162 if ( file.open( IO_ReadOnly ) )
164 return true; 163 return true;
165 164
166 if ( file.size() == 0 ) 165 if ( file.size() == 0 )
167 return true; 166 return true;
168 167
169 bool ok = mFormat->checkFormat( &file ); 168 bool ok = mFormat->checkFormat( &file );
170 file.close(); 169 file.close();
171 return ok; 170 return ok;
172 } 171 }
173} 172}
174 173
175void ResourceDir::doClose() 174void ResourceDir::doClose()
176{ 175{
177} 176}
178 177
179bool ResourceDir::load() 178bool ResourceDir::load()
180{ 179{
181 kdDebug(5700) << "ResourceDir::load(): '" << mPath << "'" << endl; 180 kdDebug(5700) << "ResourceDir::load(): '" << mPath << "'" << endl;
182 181
183 QDir dir( mPath ); 182 QDir dir( mPath );
184 QStringList files = dir.entryList( QDir::Files ); 183 QStringList files = dir.entryList( QDir::Files );
185 184
186 QStringList::Iterator it; 185 QStringList::Iterator it;
187 bool ok = true; 186 bool ok = true;
188 for ( it = files.begin(); it != files.end(); ++it ) { 187 for ( it = files.begin(); it != files.end(); ++it ) {
189 QFile file( mPath + "/" + (*it) ); 188 QFile file( mPath + "/" + (*it) );
190 189
191 if ( !file.open( IO_ReadOnly ) ) { 190 if ( !file.open( IO_ReadOnly ) ) {
192 addressBook()->error( i18n( "Unable to open file '%1' for reading" ).arg( file.name() ) ); 191 addressBook()->error( i18n( "Unable to open file '%1' for reading" ).arg( file.name() ) );
193 ok = false; 192 ok = false;
194 continue; 193 continue;
195 } 194 }
196 195
197 if ( !mFormat->loadAll( addressBook(), this, &file ) ) 196 if ( !mFormat->loadAll( addressBook(), this, &file ) )
198 ok = false; 197 ok = false;
199 198
200 file.close(); 199 file.close();
201 } 200 }
202 201
203 return ok; 202 return ok;
204} 203}
205 204
206bool ResourceDir::save( Ticket *ticket ) 205bool ResourceDir::save( Ticket *ticket )
207{ 206{
208 kdDebug(5700) << "ResourceDir::save(): '" << mPath << "'" << endl; 207 kdDebug(5700) << "ResourceDir::save(): '" << mPath << "'" << endl;
209 208
210 AddressBook::Iterator it; 209 AddressBook::Iterator it;
211 bool ok = true; 210 bool ok = true;
212 211
213 for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) { 212 for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) {
214 if ( (*it).resource() != this || !(*it).changed() ) 213 if ( (*it).resource() != this || !(*it).changed() )
215 continue; 214 continue;
216 215
217 QFile file( mPath + "/" + (*it).uid() ); 216 QFile file( mPath + "/" + (*it).uid() );
218 if ( !file.open( IO_WriteOnly ) ) { 217 if ( !file.open( IO_WriteOnly ) ) {
219 addressBook()->error( i18n( "Unable to open file '%1' for writing" ).arg( file.name() ) ); 218 addressBook()->error( i18n( "Unable to open file '%1' for writing" ).arg( file.name() ) );
220 continue; 219 continue;
221 } 220 }
222 221
223 mFormat->save( *it, &file ); 222 mFormat->save( *it, &file );
224 223
225 // mark as unchanged 224 // mark as unchanged
226 (*it).setChanged( false ); 225 (*it).setChanged( false );
227 226
228 file.close(); 227 file.close();
229 } 228 }
230 229
231 delete ticket; 230 delete ticket;
232 unlock( mPath ); 231 unlock( mPath );
233 232
234 return ok; 233 return ok;
235} 234}
236 235
237bool ResourceDir::lock( const QString &path ) 236bool ResourceDir::lock( const QString &path )
238{ 237{
239 kdDebug(5700) << "ResourceDir::lock()" << endl; 238 kdDebug(5700) << "ResourceDir::lock()" << endl;
240 239
241 QString p = path; 240 QString p = path;
242//US change the implementation how the lockfilename is getting created 241//US change the implementation how the lockfilename is getting created
243//US p.replace( QRegExp("/"), "_" ); 242//US p.replace( QRegExp("/"), "_" );
244//US QString lockName = locateLocal( "data", "kabc/lock/" + p + ".lock" ); 243//US QString lockName = locateLocal( "data", "kabc/lock/" + p + ".lock" );
245 KURL url(p); 244 KURL url(p);
246 QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); 245 QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" );
247 246
248 247
249 kdDebug(5700) << "-- lock name: " << lockName << endl; 248 kdDebug(5700) << "-- lock name: " << lockName << endl;
250 249
251 if ( QFile::exists( lockName ) ) return false; 250 if ( QFile::exists( lockName ) ) return false;
252 251
253 QString lockUniqueName; 252 QString lockUniqueName;
254 lockUniqueName = p + KApplication::randomString( 8 ); 253 lockUniqueName = p + KApplication::randomString( 8 );
255 254
256 url = lockUniqueName; 255 url = lockUniqueName;
257//US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName ); 256//US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName );
258 mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() ); 257 mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() );
259 258
260 kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl; 259 kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl;
261 260
262 // Create unique file 261 // Create unique file
263 QFile file( mLockUniqueName ); 262 QFile file( mLockUniqueName );
264 file.open( IO_WriteOnly ); 263 file.open( IO_WriteOnly );
265 file.close(); 264 file.close();
266 265
267 // Create lock file 266 // Create lock file
268 int result = 0; 267 int result = 0;
269#ifndef _WIN32_ 268#ifndef _WIN32_
270 result = ::link( QFile::encodeName( mLockUniqueName ), 269 result = ::link( QFile::encodeName( mLockUniqueName ),
271 QFile::encodeName( lockName ) ); 270 QFile::encodeName( lockName ) );
272#endif 271#endif
273 if ( result == 0 ) { 272 if ( result == 0 ) {
274 addressBook()->emitAddressBookLocked(); 273 addressBook()->emitAddressBookLocked();
275 return true; 274 return true;
276 } 275 }
277 276
278 // TODO: check stat 277 // TODO: check stat
279 278
280 return false; 279 return false;
281} 280}
282 281
283void ResourceDir::unlock( const QString &path ) 282void ResourceDir::unlock( const QString &path )
284{ 283{
285 QString p = path; 284 QString p = path;
286//US change the implementation how the lockfilename is getting created 285//US change the implementation how the lockfilename is getting created
287//US p.replace( QRegExp( "/" ), "_" ); 286//US p.replace( QRegExp( "/" ), "_" );
288//US QString lockName = locate( "data", "kabc/lock/" + p + ".lock" ); 287//US QString lockName = locate( "data", "kabc/lock/" + p + ".lock" );
289 KURL url(p); 288 KURL url(p);
290 QString lockName = locate( "data", "kabc/lock/" + url.fileName() + ".lock" ); 289 QString lockName = locate( "data", "kabc/lock/" + url.fileName() + ".lock" );
291 290
292 ::unlink( QFile::encodeName( lockName ) ); 291 ::unlink( QFile::encodeName( lockName ) );
293 QFile::remove( mLockUniqueName ); 292 QFile::remove( mLockUniqueName );
294 addressBook()->emitAddressBookUnlocked(); 293 addressBook()->emitAddressBookUnlocked();
295} 294}
296 295
297void ResourceDir::setPath( const QString &path ) 296void ResourceDir::setPath( const QString &path )
298{ 297{
299 mDirWatch.stopScan(); 298 mDirWatch.stopScan();
300 mDirWatch.removeDir( mPath ); 299 mDirWatch.removeDir( mPath );
301 300
302 mPath = path; 301 mPath = path;
303 302
304 mDirWatch.addDir( mPath, true ); 303 mDirWatch.addDir( mPath, true );
305 mDirWatch.startScan(); 304 mDirWatch.startScan();
306 305
307//US simulate KDirWatch event 306//US simulate KDirWatch event
308//US pathChanged(); 307//US pathChanged();
309 308
310} 309}
311 310
312QString ResourceDir::path() const 311QString ResourceDir::path() const
313{ 312{
314 return mPath; 313 return mPath;
315} 314}
316 315
317void ResourceDir::setFormat( const QString &format ) 316void ResourceDir::setFormat( const QString &format )
318{ 317{
319 mFormatName = format; 318 mFormatName = format;
320 319
321 if ( mFormat ) 320 if ( mFormat )
322 delete mFormat; 321 delete mFormat;
323 322
324 FormatFactory *factory = FormatFactory::self(); 323 FormatFactory *factory = FormatFactory::self();
325 mFormat = factory->format( mFormatName ); 324 mFormat = factory->format( mFormatName );
326/*US 325/*US
327qDebug("ResourceDir::setFormat initialized with format %s ", format.latin1()); 326qDebug("ResourceDir::setFormat initialized with format %s ", format.latin1());
328 if (mFormatName == "vcard") 327 if (mFormatName == "vcard")
329 mFormat = new VCardFormatPlugin2(); 328 mFormat = new VCardFormatPlugin2();
330 else if (mFormatName == "binary") 329 else if (mFormatName == "binary")
331 mFormat = new BinaryFormat(); 330 mFormat = new BinaryFormat();
332 else 331 else
333 qDebug("ResourceDir::setFormat format unknown !!! %s ", format.latin1()); 332 qDebug("ResourceDir::setFormat format unknown !!! %s ", format.latin1());
334*/ 333*/
335 334
336} 335}
337 336
338QString ResourceDir::format() const 337QString ResourceDir::format() const
339{ 338{
340 return mFormatName; 339 return mFormatName;
341} 340}
342 341
343void ResourceDir::pathChanged() 342void ResourceDir::pathChanged()
344{ 343{
345 if ( !addressBook() ) 344 if ( !addressBook() )
346 return; 345 return;
347 346
348 load(); 347 QString text( i18n( "Dir resource '%1'<br> has been changed by third party.<br>Do you want to reload?").arg( mPath ) );
349 addressBook()->emitAddressBookChanged(); 348 if ( readOnly() || KMessageBox::questionYesNo( 0, text ) == KMessageBox::Yes ) {
349 load();
350 addressBook()->emitAddressBookChanged();
351 }
350} 352}
351 353
352void ResourceDir::removeAddressee( const Addressee& addr ) 354void ResourceDir::removeAddressee( const Addressee& addr )
353{ 355{
354 QFile::remove( mPath + "/" + addr.uid() ); 356 QFile::remove( mPath + "/" + addr.uid() );
355} 357}
356 358
357void ResourceDir::cleanUp() 359void ResourceDir::cleanUp()
358{ 360{
359 unlock( mPath ); 361 unlock( mPath );
360} 362}
361 363
362//US #include "resourcedir.moc" 364//US #include "resourcedir.moc"
diff --git a/kabc/plugins/file/resourcefile.cpp b/kabc/plugins/file/resourcefile.cpp
index 9f9b00f..1d3acec 100644
--- a/kabc/plugins/file/resourcefile.cpp
+++ b/kabc/plugins/file/resourcefile.cpp
@@ -1,391 +1,397 @@
1/* 1/*
2 This file is part of libkabc. 2 This file is part of libkabc.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2001 Cornelius Schumacher <schumacher@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 <sys/types.h> 28#include <sys/types.h>
29#include <sys/stat.h> 29#include <sys/stat.h>
30#ifndef _WIN32_ 30#ifndef _WIN32_
31#include <unistd.h> 31#include <unistd.h>
32#endif 32#endif
33 33
34#include <qfile.h> 34#include <qfile.h>
35#include <qfileinfo.h> 35#include <qfileinfo.h>
36#include <qregexp.h> 36#include <qregexp.h>
37#include <qtimer.h> 37#include <qtimer.h>
38 38
39#include <kapplication.h> 39#include <kapplication.h>
40#include <kconfig.h> 40#include <kconfig.h>
41#include <kdebug.h> 41#include <kdebug.h>
42#include <klocale.h> 42#include <klocale.h>
43//US #include <ksavefile.h> 43//US #include <ksavefile.h>
44#include <kstandarddirs.h> 44#include <kstandarddirs.h>
45#include <kmessagebox.h>
45 46
46#include "formatfactory.h" 47#include "formatfactory.h"
47 48
48#include "resource.h" 49#include "resource.h"
49#include "resourcefileconfig.h" 50#include "resourcefileconfig.h"
50#include "stdaddressbook.h" 51#include "stdaddressbook.h"
51 52
52#include "resourcefile.h" 53#include "resourcefile.h"
53 54
54using namespace KABC; 55using namespace KABC;
55 56
56extern "C" 57extern "C"
57#ifdef _WIN32_ 58#ifdef _WIN32_
58__declspec(dllexport) 59__declspec(dllexport)
59#else 60#else
60{ 61{
61#endif 62#endif
62 63
63//US void *init_kabc_file() 64//US void *init_kabc_file()
64 void *init_microkabc_file() 65 void *init_microkabc_file()
65 { 66 {
66 return new KRES::PluginFactory<ResourceFile,ResourceFileConfig>(); 67 return new KRES::PluginFactory<ResourceFile,ResourceFileConfig>();
67 } 68 }
68#ifndef _WIN32_ 69#ifndef _WIN32_
69} 70}
70#endif 71#endif
71 72
72ResourceFile::ResourceFile( const KConfig *config ) 73ResourceFile::ResourceFile( const KConfig *config )
73 : Resource( config ) , mFormat( 0 ) 74 : Resource( config ) , mFormat( 0 )
74{ 75{
75 QString fileName, formatName; 76 QString fileName, formatName;
76 77
77 KConfig *cfg = (KConfig *)config; 78 KConfig *cfg = (KConfig *)config;
78 if ( cfg ) { 79 if ( cfg ) {
79 fileName = cfg->readEntry( "FileName", StdAddressBook::fileName() ); 80 fileName = cfg->readEntry( "FileName", StdAddressBook::fileName() );
80 formatName = cfg->readEntry( "FileFormat", "vcard" ); 81 formatName = cfg->readEntry( "FileFormat", "vcard" );
81// qDebug("ResourceFile::ResourceFile : 1 %s, %s", fileName.latin1(), formatName.latin1() ); 82// qDebug("ResourceFile::ResourceFile : 1 %s, %s", fileName.latin1(), formatName.latin1() );
82 } else { 83 } else {
83 fileName = StdAddressBook::fileName(); 84 fileName = StdAddressBook::fileName();
84 formatName = "vcard"; 85 formatName = "vcard";
85// qDebug("ResourceFile::ResourceFile : 2 %s, %s", fileName.latin1(), formatName.latin1() ); 86// qDebug("ResourceFile::ResourceFile : 2 %s, %s", fileName.latin1(), formatName.latin1() );
86 } 87 }
87 88
88 init( fileName, formatName ); 89 init( fileName, formatName );
89} 90}
90 91
91ResourceFile::ResourceFile( const QString &fileName, 92ResourceFile::ResourceFile( const QString &fileName,
92 const QString &formatName ) 93 const QString &formatName )
93 : Resource( 0 ) 94 : Resource( 0 )
94{ 95{
95// qDebug("ResourceFile::ResourceFile : 3 %s, %s", fileName.latin1(), formatName.latin1()); 96// qDebug("ResourceFile::ResourceFile : 3 %s, %s", fileName.latin1(), formatName.latin1());
96 init( fileName, formatName ); 97 init( fileName, formatName );
97} 98}
98 99
99void ResourceFile::init( const QString &fileName, const QString &formatName ) 100void ResourceFile::init( const QString &fileName, const QString &formatName )
100{ 101{
101 mFormatName = formatName; 102 mFormatName = formatName;
102 103
103 FormatFactory *factory = FormatFactory::self(); 104 FormatFactory *factory = FormatFactory::self();
104 mFormat = factory->format( mFormatName ); 105 mFormat = factory->format( mFormatName );
105 106
106 if ( !mFormat ) { 107 if ( !mFormat ) {
107 mFormatName = "vcard"; 108 mFormatName = "vcard";
108 mFormat = factory->format( mFormatName ); 109 mFormat = factory->format( mFormatName );
109 } 110 }
110 111
111/*US 112/*US
112//US qDebug("ResourceFile::init initialized with format %s ", formatName.latin1()); 113//US qDebug("ResourceFile::init initialized with format %s ", formatName.latin1());
113 if (mFormatName == "vcard") { 114 if (mFormatName == "vcard") {
114 mFormat = new VCardFormatPlugin2(); 115 mFormat = new VCardFormatPlugin2();
115// qDebug("ResourceFile::init format VCardFormatPlugin2"); 116// qDebug("ResourceFile::init format VCardFormatPlugin2");
116 } 117 }
117 else if (mFormatName == "binary") { 118 else if (mFormatName == "binary") {
118 mFormat = new BinaryFormat(); 119 mFormat = new BinaryFormat();
119// qDebug("ResourceFile::init format BinaryFormat"); 120// qDebug("ResourceFile::init format BinaryFormat");
120 } 121 }
121 else 122 else
122 qDebug("ResourceFile::init format unknown !!! %s ", formatName.latin1()); 123 qDebug("ResourceFile::init format unknown !!! %s ", formatName.latin1());
123*/ 124*/
124 125
125 connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) ); 126 connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) );
126 connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) ); 127 connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) );
127 connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) ); 128 connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) );
128 129
129 setFileName( fileName ); 130 setFileName( fileName );
130} 131}
131 132
132ResourceFile::~ResourceFile() 133ResourceFile::~ResourceFile()
133{ 134{
134 delete mFormat; 135 delete mFormat;
135 mFormat = 0; 136 mFormat = 0;
136} 137}
137 138
138void ResourceFile::writeConfig( KConfig *config ) 139void ResourceFile::writeConfig( KConfig *config )
139{ 140{
140 141
141 config->setGroup( "Resource_" + identifier() ); 142 config->setGroup( "Resource_" + identifier() );
142 Resource::writeConfig( config ); 143 Resource::writeConfig( config );
143 144
144 config->writeEntry( "FileName", mFileName ); 145 config->writeEntry( "FileName", mFileName );
145 config->writeEntry( "FileFormat", mFormatName ); 146 config->writeEntry( "FileFormat", mFormatName );
146 147
147// qDebug("ResourceFile::writeConfig format %s, %s", mFileName.latin1(), mFormatName.latin1()); 148// qDebug("ResourceFile::writeConfig format %s, %s", mFileName.latin1(), mFormatName.latin1());
148 149
149} 150}
150 151
151Ticket *ResourceFile::requestSaveTicket() 152Ticket *ResourceFile::requestSaveTicket()
152{ 153{
153 kdDebug(5700) << "ResourceFile::requestSaveTicket()" << endl; 154 kdDebug(5700) << "ResourceFile::requestSaveTicket()" << endl;
154 155
155 if ( !addressBook() ) return 0; 156 if ( !addressBook() ) return 0;
156 157
157 if ( !lock( mFileName ) ) { 158 if ( !lock( mFileName ) ) {
158 kdDebug(5700) << "ResourceFile::requestSaveTicket(): Unable to lock file '" 159 kdDebug(5700) << "ResourceFile::requestSaveTicket(): Unable to lock file '"
159 << mFileName << "'" << endl; 160 << mFileName << "'" << endl;
160 return 0; 161 return 0;
161 } 162 }
162 return createTicket( this ); 163 return createTicket( this );
163} 164}
164 165
165 166
166bool ResourceFile::doOpen() 167bool ResourceFile::doOpen()
167{ 168{
168 QFile file( mFileName ); 169 QFile file( mFileName );
169 170
170 if ( !file.exists() ) { 171 if ( !file.exists() ) {
171 // try to create the file 172 // try to create the file
172 bool ok = file.open( IO_WriteOnly ); 173 bool ok = file.open( IO_WriteOnly );
173 if ( ok ) 174 if ( ok )
174 file.close(); 175 file.close();
175 176
176 return ok; 177 return ok;
177 } else { 178 } else {
178 if ( !file.open( IO_ReadWrite ) ) 179 if ( !file.open( IO_ReadWrite ) )
179 return false; 180 return false;
180 181
181 if ( file.size() == 0 ) { 182 if ( file.size() == 0 ) {
182 file.close(); 183 file.close();
183 return true; 184 return true;
184 } 185 }
185 186
186 bool ok = mFormat->checkFormat( &file ); 187 bool ok = mFormat->checkFormat( &file );
187 file.close(); 188 file.close();
188 189
189 return ok; 190 return ok;
190 } 191 }
191} 192}
192 193
193void ResourceFile::doClose() 194void ResourceFile::doClose()
194{ 195{
195} 196}
196 197
197bool ResourceFile::load() 198bool ResourceFile::load()
198{ 199{
199 200
200 201
201 QFile file( mFileName ); 202 QFile file( mFileName );
202 if ( !file.open( IO_ReadOnly ) ) { 203 if ( !file.open( IO_ReadOnly ) ) {
203 addressBook()->error( i18n( "Unable to open file '%1'." ).arg( mFileName ) ); 204 addressBook()->error( i18n( "Unable to open file '%1'." ).arg( mFileName ) );
204 return false; 205 return false;
205 } 206 }
206 207
207// qDebug("ResourceFile::load format %s, %s", mFileName.latin1(), mFormatName.latin1()); 208// qDebug("ResourceFile::load format %s, %s", mFileName.latin1(), mFormatName.latin1());
208 209
209 return mFormat->loadAll( addressBook(), this, &file ); 210 return mFormat->loadAll( addressBook(), this, &file );
210} 211}
211 212
212bool ResourceFile::save( Ticket *ticket ) 213bool ResourceFile::save( Ticket *ticket )
213{ 214{
214// qDebug("ResourceFile::save format %s, %s", mFileName.latin1(), mFormatName.latin1()); 215// qDebug("ResourceFile::save format %s, %s", mFileName.latin1(), mFormatName.latin1());
215 216
216 217
217 // create backup file 218 // create backup file
218 QString extension = "_" + QString::number( QDate::currentDate().dayOfWeek() ); 219 QString extension = "_" + QString::number( QDate::currentDate().dayOfWeek() );
219 220
220/*US we use a simpler method to create a backupfile 221/*US we use a simpler method to create a backupfile
221 222
222 (void) KSaveFile::backupFile( mFileName, QString::null 223 (void) KSaveFile::backupFile( mFileName, QString::null
223 ,extension ); 224 ,extension );
224 225
225 KSaveFile saveFile( mFileName ); 226 KSaveFile saveFile( mFileName );
226 bool ok = false; 227 bool ok = false;
227 if ( saveFile.status() == 0 && saveFile.file() ) 228 if ( saveFile.status() == 0 && saveFile.file() )
228 { 229 {
229 mFormat->saveAll( addressBook(), this, saveFile.file() ); 230 mFormat->saveAll( addressBook(), this, saveFile.file() );
230 ok = saveFile.close(); 231 ok = saveFile.close();
231 } 232 }
232*/ 233*/
233 234
234//US ToDo: write backupfile 235//US ToDo: write backupfile
235 QFile info; 236 QFile info;
236 info.setName( mFileName ); 237 info.setName( mFileName );
237 bool ok = info.open( IO_WriteOnly ); 238 bool ok = info.open( IO_WriteOnly );
238 if ( ok ) { 239 if ( ok ) {
239 mFormat->saveAll( addressBook(), this, &info ); 240 mFormat->saveAll( addressBook(), this, &info );
240 241
241 info.close(); 242 info.close();
242 ok = true; 243 ok = true;
243 } 244 }
244 else { 245 else {
245 246
246 } 247 }
247 248
248 if ( !ok ) 249 if ( !ok )
249 addressBook()->error( i18n( "Unable to save file '%1'." ).arg( mFileName ) ); 250 addressBook()->error( i18n( "Unable to save file '%1'." ).arg( mFileName ) );
250 251
251 delete ticket; 252 delete ticket;
252 unlock( mFileName ); 253 unlock( mFileName );
253 254
254 return ok; 255 return ok;
255 256
256 qDebug("ResourceFile::save has to be changed"); 257 qDebug("ResourceFile::save has to be changed");
257 return true; 258 return true;
258} 259}
259 260
260bool ResourceFile::lock( const QString &fileName ) 261bool ResourceFile::lock( const QString &fileName )
261{ 262{
262 263
263 264
264 QString fn = fileName; 265 QString fn = fileName;
265 266
266//US change the implementation how the lockfilename is getting created 267//US change the implementation how the lockfilename is getting created
267//US fn.replace( QRegExp("/"), "_" ); 268//US fn.replace( QRegExp("/"), "_" );
268//US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" ); 269//US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" );
269 270
270 KURL url(fn); 271 KURL url(fn);
271 QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); 272 QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" );
272 273
273 274
274 275
275 if (QFile::exists( lockName )) return false; 276 if (QFile::exists( lockName )) return false;
276 277
277 QString lockUniqueName; 278 QString lockUniqueName;
278 lockUniqueName = fn + KApplication::randomString( 8 ); 279 lockUniqueName = fn + KApplication::randomString( 8 );
279 280
280 url = lockUniqueName; 281 url = lockUniqueName;
281//US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName ); 282//US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName );
282 mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() ); 283 mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() );
283 kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl; 284 kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl;
284 285
285 // Create unique file 286 // Create unique file
286 QFile file( mLockUniqueName ); 287 QFile file( mLockUniqueName );
287 file.open( IO_WriteOnly ); 288 file.open( IO_WriteOnly );
288 file.close(); 289 file.close();
289 290
290 // Create lock file 291 // Create lock file
291 int result = 0; 292 int result = 0;
292#ifndef _WIN32_ 293#ifndef _WIN32_
293 result = ::link( QFile::encodeName( mLockUniqueName ), 294 result = ::link( QFile::encodeName( mLockUniqueName ),
294 QFile::encodeName( lockName ) ); 295 QFile::encodeName( lockName ) );
295#endif 296#endif
296 if ( result == 0 ) { 297 if ( result == 0 ) {
297 addressBook()->emitAddressBookLocked(); 298 addressBook()->emitAddressBookLocked();
298 return true; 299 return true;
299 } 300 }
300 301
301 // TODO: check stat 302 // TODO: check stat
302 303
303 return false; 304 return false;
304} 305}
305 306
306void ResourceFile::unlock( const QString &fileName ) 307void ResourceFile::unlock( const QString &fileName )
307{ 308{
308 QString fn = fileName; 309 QString fn = fileName;
309//US change the implementation how the lockfilename is getting created 310//US change the implementation how the lockfilename is getting created
310//US fn.replace( QRegExp( "/" ), "_" ); 311//US fn.replace( QRegExp( "/" ), "_" );
311//US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" ); 312//US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" );
312//US QString lockName = fn + ".lock"; 313//US QString lockName = fn + ".lock";
313 KURL url(fn); 314 KURL url(fn);
314 QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); 315 QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" );
315 316
316 QFile::remove( lockName ); 317 QFile::remove( lockName );
317 QFile::remove( mLockUniqueName ); 318 QFile::remove( mLockUniqueName );
318 addressBook()->emitAddressBookUnlocked(); 319 addressBook()->emitAddressBookUnlocked();
319} 320}
320 321
321void ResourceFile::setFileName( const QString &fileName ) 322void ResourceFile::setFileName( const QString &fileName )
322{ 323{
323 mDirWatch.stopScan(); 324 mDirWatch.stopScan();
324 mDirWatch.removeFile( mFileName ); 325 mDirWatch.removeFile( mFileName );
325 326
326 mFileName = fileName; 327 mFileName = fileName;
327 328
328 329
329 mDirWatch.addFile( mFileName ); 330 mDirWatch.addFile( mFileName );
330 mDirWatch.startScan(); 331 mDirWatch.startScan();
331 332
332//US simulate KDirWatch event 333//US simulate KDirWatch event
333//US fileChanged(); 334//US fileChanged();
334} 335}
335 336
336QString ResourceFile::fileName() const 337QString ResourceFile::fileName() const
337{ 338{
338 return mFileName; 339 return mFileName;
339} 340}
340 341
341void ResourceFile::setFormat( const QString &format ) 342void ResourceFile::setFormat( const QString &format )
342{ 343{
343 mFormatName = format; 344 mFormatName = format;
344 delete mFormat; 345 delete mFormat;
345 346
346 FormatFactory *factory = FormatFactory::self(); 347 FormatFactory *factory = FormatFactory::self();
347 mFormat = factory->format( mFormatName ); 348 mFormat = factory->format( mFormatName );
348/*US 349/*US
349//qDebug("ResourceFile::setFormat initialized with format %s ", format.latin1()); 350//qDebug("ResourceFile::setFormat initialized with format %s ", format.latin1());
350 if (mFormatName == "vcard") { 351 if (mFormatName == "vcard") {
351 mFormat = new VCardFormatPlugin2(); 352 mFormat = new VCardFormatPlugin2();
352// qDebug("ResourceFile::setFormat format %s", mFormatName.latin1()); 353// qDebug("ResourceFile::setFormat format %s", mFormatName.latin1());
353 } 354 }
354 else if (mFormatName == "binary") { 355 else if (mFormatName == "binary") {
355 mFormat = new BinaryFormat(); 356 mFormat = new BinaryFormat();
356// qDebug("ResourceFile::setFormat format %s", mFormatName.latin1()); 357// qDebug("ResourceFile::setFormat format %s", mFormatName.latin1());
357 } 358 }
358 else 359 else
359 qDebug("ResourceFile::setFormat format unknown !!! %s ", format.latin1()); 360 qDebug("ResourceFile::setFormat format unknown !!! %s ", format.latin1());
360*/ 361*/
361 362
362} 363}
363 364
364QString ResourceFile::format() const 365QString ResourceFile::format() const
365{ 366{
366 return mFormatName; 367 return mFormatName;
367} 368}
368 369
369void ResourceFile::fileChanged() 370void ResourceFile::fileChanged()
370{ 371{
371 // There is a small theoretical chance that KDirWatch calls us before 372 // There is a small theoretical chance that KDirWatch calls us before
372 // we are fully constructed 373 // we are fully constructed
373 if (!addressBook()) 374 if (!addressBook())
374 return; 375 return;
375 load(); 376
376 addressBook()->emitAddressBookChanged(); 377
378 QString text( i18n( "File resource '%1'<br> has been changed by third party.<br>Do you want to reload?").arg( mFileName ) );
379 if ( readOnly() || KMessageBox::questionYesNo( 0, text ) == KMessageBox::Yes ) {
380 load();
381 addressBook()->emitAddressBookChanged();
382 }
377} 383}
378 384
379void ResourceFile::removeAddressee( const Addressee &addr ) 385void ResourceFile::removeAddressee( const Addressee &addr )
380{ 386{
381 QFile::remove( QFile::encodeName( locateLocal( "data", "kabc/photos/" ) + addr.uid() ) ); 387 QFile::remove( QFile::encodeName( locateLocal( "data", "kabc/photos/" ) + addr.uid() ) );
382 QFile::remove( QFile::encodeName( locateLocal( "data", "kabc/logos/" ) + addr.uid() ) ); 388 QFile::remove( QFile::encodeName( locateLocal( "data", "kabc/logos/" ) + addr.uid() ) );
383 QFile::remove( QFile::encodeName( locateLocal( "data", "kabc/sounds/" ) + addr.uid() ) ); 389 QFile::remove( QFile::encodeName( locateLocal( "data", "kabc/sounds/" ) + addr.uid() ) );
384} 390}
385 391
386void ResourceFile::cleanUp() 392void ResourceFile::cleanUp()
387{ 393{
388 unlock( mFileName ); 394 unlock( mFileName );
389} 395}
390 396
391//US #include "resourcefile.moc" 397//US #include "resourcefile.moc"
diff --git a/kabc/plugins/opie/resourceopie.cpp b/kabc/plugins/opie/resourceopie.cpp
index 1436508..aaee801 100644
--- a/kabc/plugins/opie/resourceopie.cpp
+++ b/kabc/plugins/opie/resourceopie.cpp
@@ -1,389 +1,395 @@
1/* 1/*
2 This file is part of libkabc. 2 This file is part of libkabc.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2001 Cornelius Schumacher <schumacher@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 <sys/types.h> 28#include <sys/types.h>
29#include <sys/stat.h> 29#include <sys/stat.h>
30#include <unistd.h> 30#include <unistd.h>
31 31
32#include <qdir.h> 32#include <qdir.h>
33#include <qfile.h> 33#include <qfile.h>
34#include <qfileinfo.h> 34#include <qfileinfo.h>
35#include <qregexp.h> 35#include <qregexp.h>
36 36
37#include <kapplication.h> 37#include <kapplication.h>
38#include <kconfig.h> 38#include <kconfig.h>
39#include <kdebug.h> 39#include <kdebug.h>
40#include <klocale.h> 40#include <klocale.h>
41//US #include <ksavefile.h> 41//US #include <ksavefile.h>
42#include <kstandarddirs.h> 42#include <kstandarddirs.h>
43#include <kmessagebox.h>
43 44
44//US #include "formatfactory.h" 45//US #include "formatfactory.h"
45//US #include <qpe/qpeapplication.h> 46//US #include <qpe/qpeapplication.h>
46 47
47#include <opie/ocontactaccess.h> 48#include <opie/ocontactaccess.h>
48#include <opie/ocontactaccessbackend_xml.h> 49#include <opie/ocontactaccessbackend_xml.h>
49 50
50#include "resourceopieconfig.h" 51#include "resourceopieconfig.h"
51#include "stdaddressbook.h" 52#include "stdaddressbook.h"
52 53
53#include "opieconverter.h" 54#include "opieconverter.h"
54 55
55#include "resourceopie.h" 56#include "resourceopie.h"
56 57
57using namespace KABC; 58using namespace KABC;
58extern "C" 59extern "C"
59{ 60{
60 void *init_microkabc_opie() 61 void *init_microkabc_opie()
61 { 62 {
62 return new KRES::PluginFactory<ResourceOpie,ResourceOpieConfig>(); 63 return new KRES::PluginFactory<ResourceOpie,ResourceOpieConfig>();
63 } 64 }
64} 65}
65 66
66ResourceOpie::ResourceOpie( const KConfig *config ) 67ResourceOpie::ResourceOpie( const KConfig *config )
67 : Resource( config ), mConverter (0) 68 : Resource( config ), mConverter (0)
68{ 69{
69 QString fileName = QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml"; 70 QString fileName = QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml";
70 71
71 KConfig *cfg = (KConfig *)config; 72 KConfig *cfg = (KConfig *)config;
72 if ( cfg ) { 73 if ( cfg ) {
73 fileName = cfg->readEntry( "FileName", fileName ); 74 fileName = cfg->readEntry( "FileName", fileName );
74 75
75 } 76 }
76 77
77// qDebug("ResourceOpie::ResourceOpie : %s", fileName.latin1() ); 78// qDebug("ResourceOpie::ResourceOpie : %s", fileName.latin1() );
78 79
79 init( fileName ); 80 init( fileName );
80} 81}
81 82
82ResourceOpie::ResourceOpie( const QString &fileName ) 83ResourceOpie::ResourceOpie( const QString &fileName )
83 : Resource( 0 ) 84 : Resource( 0 )
84{ 85{
85// qDebug("ResourceOpie::ResourceOpie : 3 %s", fileName.latin1()); 86// qDebug("ResourceOpie::ResourceOpie : 3 %s", fileName.latin1());
86 init( fileName ); 87 init( fileName );
87} 88}
88 89
89void ResourceOpie::init( const QString &fileName ) 90void ResourceOpie::init( const QString &fileName )
90{ 91{
91 92
92 connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) ); 93 connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) );
93 connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) ); 94 connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) );
94 connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) ); 95 connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) );
95 96
96 //US opie addressbook is always readonly
97//US setReadOnly( true );
98 97
99 setFileName( fileName ); 98 setFileName( fileName );
100 99
101} 100}
102 101
103ResourceOpie::~ResourceOpie() 102ResourceOpie::~ResourceOpie()
104{ 103{
105 if (mConverter != 0) 104 if (mConverter != 0)
106 delete mConverter; 105 delete mConverter;
107} 106}
108 107
109void ResourceOpie::writeConfig( KConfig *config ) 108void ResourceOpie::writeConfig( KConfig *config )
110{ 109{
111 Resource::writeConfig( config ); 110 Resource::writeConfig( config );
112 111
113 config->writeEntry( "FileName", mFileName ); 112 config->writeEntry( "FileName", mFileName );
114 113
115// qDebug("ResourceFile::writeConfig format %s, %s", mFileName.latin1(), mFormatName.latin1()); 114// qDebug("ResourceFile::writeConfig format %s, %s", mFileName.latin1(), mFormatName.latin1());
116 115
117} 116}
118 117
119Ticket *ResourceOpie::requestSaveTicket() 118Ticket *ResourceOpie::requestSaveTicket()
120{ 119{
121 kdDebug(5700) << "ResourceOpie::requestSaveTicket()" << endl; 120 kdDebug(5700) << "ResourceOpie::requestSaveTicket()" << endl;
122 121
123 if ( !addressBook() ) return 0; 122 if ( !addressBook() ) return 0;
124 123
125 if ( !lock( mFileName ) ) { 124 if ( !lock( mFileName ) ) {
126 kdDebug(5700) << "ResourceOpie::requestSaveTicket(): Unable to lock file '" 125 kdDebug(5700) << "ResourceOpie::requestSaveTicket(): Unable to lock file '"
127 << mFileName << "'" << endl; 126 << mFileName << "'" << endl;
128 return 0; 127 return 0;
129 } 128 }
130 return createTicket( this ); 129 return createTicket( this );
131} 130}
132 131
133 132
134bool ResourceOpie::doOpen() 133bool ResourceOpie::doOpen()
135{ 134{
136// qDebug("ResourceOpie::doOpen() %s", mFileName.latin1()); 135// qDebug("ResourceOpie::doOpen() %s", mFileName.latin1());
137/*US 136/*US
138 QFile file( mFileName ); 137 QFile file( mFileName );
139 138
140 if ( !file.exists() ) { 139 if ( !file.exists() ) {
141 // try to create the file 140 // try to create the file
142 bool ok = file.open( IO_WriteOnly ); 141 bool ok = file.open( IO_WriteOnly );
143 if ( ok ) 142 if ( ok )
144 file.close(); 143 file.close();
145 144
146 return ok; 145 return ok;
147 } else { 146 } else {
148 if ( !file.open( IO_ReadWrite ) ) 147 if ( !file.open( IO_ReadWrite ) )
149 return false; 148 return false;
150 149
151 if ( file.size() == 0 ) { 150 if ( file.size() == 0 ) {
152 file.close(); 151 file.close();
153 return true; 152 return true;
154 } 153 }
155 154
156//US bool ok = mFormat->checkFormat( &file ); 155//US bool ok = mFormat->checkFormat( &file );
157 bool ok = true; 156 bool ok = true;
158 157
159 file.close(); 158 file.close();
160 159
161 return ok; 160 return ok;
162 } 161 }
163*/ 162*/
164 qDebug("ResourceOpie::doOpen() has to be fixed - %s", mFileName.latin1()); 163 qDebug("ResourceOpie::doOpen() has to be fixed - %s", mFileName.latin1());
165 return true; 164 return true;
166} 165}
167 166
168void ResourceOpie::doClose() 167void ResourceOpie::doClose()
169{ 168{
170// qDebug("ResourceOpie::doClose() %s", mFileName.latin1()); 169// qDebug("ResourceOpie::doClose() %s", mFileName.latin1());
171} 170}
172 171
173bool ResourceOpie::load() 172bool ResourceOpie::load()
174{ 173{
175// qDebug("ResourceOpie::load() %s", mFileName.latin1()); 174// qDebug("ResourceOpie::load() %s", mFileName.latin1());
176 kdDebug(5700) << "ResourceOpie::load(): '" << mFileName << "'" << endl; 175 kdDebug(5700) << "ResourceOpie::load(): '" << mFileName << "'" << endl;
177 176
178 qDebug("ResourceOpie::load: Try to load file() %s", mFileName.latin1()); 177 qDebug("ResourceOpie::load: Try to load file() %s", mFileName.latin1());
179 178
180 OContactAccessBackend_XML* backend = new OContactAccessBackend_XML( "KDEPim/Pi", mFileName ); 179 OContactAccessBackend_XML* backend = new OContactAccessBackend_XML( "KDEPim/Pi", mFileName );
181 OContactAccess* access = new OContactAccess("KDEPim/Pi", 0l, backend, false); 180 OContactAccess* access = new OContactAccess("KDEPim/Pi", 0l, backend, false);
182 181
183 if ( !access ) { 182 if ( !access ) {
184 qDebug("Unable to load file() %s", mFileName.latin1()); 183 qDebug("Unable to load file() %s", mFileName.latin1());
185 addressBook()->error( i18n( "Unable to load file '%1'." ).arg( mFileName ) ); 184 addressBook()->error( i18n( "Unable to load file '%1'." ).arg( mFileName ) );
186 return false; 185 return false;
187 } 186 }
188 187
189 access -> setReadAhead( 32 ); // Use ReadAhead-Cache if available 188 access -> setReadAhead( 32 ); // Use ReadAhead-Cache if available
190 189
191 bool res = false; 190 bool res = false;
192 if (mConverter == 0) 191 if (mConverter == 0)
193 { 192 {
194 mConverter = new OpieConverter(); 193 mConverter = new OpieConverter();
195 res = mConverter->init(); 194 res = mConverter->init();
196 if ( !res ) 195 if ( !res )
197 { 196 {
198 qDebug("Unable to initialize opie converter. Most likely a problem with the category file"); 197 qDebug("Unable to initialize opie converter. Most likely a problem with the category file");
199 addressBook()->error( i18n( "Unable to initialize opie converter. Most likely a problem with the category file" ) ); 198 addressBook()->error( i18n( "Unable to initialize opie converter. Most likely a problem with the category file" ) );
200 delete access; 199 delete access;
201 return false; 200 return false;
202 } 201 }
203 } 202 }
204 203
205 204
206 OContactAccess::List::Iterator it; 205 OContactAccess::List::Iterator it;
207 OContactAccess::List allList = access->allRecords(); 206 OContactAccess::List allList = access->allRecords();
208 for ( it = allList.begin(); it != allList.end(); ++it ) 207 for ( it = allList.begin(); it != allList.end(); ++it )
209 { 208 {
210 const OContact c = (*it); 209 const OContact c = (*it);
211 210
212 KABC::Addressee addressee; 211 KABC::Addressee addressee;
213 212
214 res = mConverter->opieToAddressee( c, addressee ); 213 res = mConverter->opieToAddressee( c, addressee );
215 214
216 if ( !addressee.isEmpty() && res ) 215 if ( !addressee.isEmpty() && res )
217 { 216 {
218 addressee.setResource( this ); 217 addressee.setResource( this );
219 addressBook()->insertAddressee( addressee ); 218 addressBook()->insertAddressee( addressee );
220 } 219 }
221 220
222// qDebug("found %s", c.fullName().latin1()); 221// qDebug("found %s", c.fullName().latin1());
223 } 222 }
224 223
225 delete access; 224 delete access;
226 // it seems so, that deletion of access deletes backend as well 225 // it seems so, that deletion of access deletes backend as well
227 //delete backend; 226 //delete backend;
228 227
229 return true; 228 return true;
230} 229}
231 230
232bool ResourceOpie::save( Ticket *ticket ) 231bool ResourceOpie::save( Ticket *ticket )
233{ 232{
234 qDebug("ResourceOpie::save() has to be fixed - %s", mFileName.latin1()); 233 qDebug("ResourceOpie::save() has to be fixed - %s", mFileName.latin1());
235/*US 234/*US
236 235
237 qDebug("ResourceOpie::save %s", mFileName.latin1()); 236 qDebug("ResourceOpie::save %s", mFileName.latin1());
238 kdDebug(5700) << "ResourceOpie::save()" << endl; 237 kdDebug(5700) << "ResourceOpie::save()" << endl;
239 238
240 // create backup file 239 // create backup file
241 QString extension = "_" + QString::number( QDate::currentDate().dayOfWeek() ); 240 QString extension = "_" + QString::number( QDate::currentDate().dayOfWeek() );
242*/ 241*/
243/*US we use a simpler method to create a backupfile 242/*US we use a simpler method to create a backupfile
244 243
245 (void) KSaveFile::backupFile( mFileName, QString::null 244 (void) KSaveFile::backupFile( mFileName, QString::null
246 ,extension ); 245 ,extension );
247 246
248 KSaveFile saveFile( mFileName ); 247 KSaveFile saveFile( mFileName );
249 bool ok = false; 248 bool ok = false;
250 if ( saveFile.status() == 0 && saveFile.file() ) 249 if ( saveFile.status() == 0 && saveFile.file() )
251 { 250 {
252 mFormat->saveAll( addressBook(), this, saveFile.file() ); 251 mFormat->saveAll( addressBook(), this, saveFile.file() );
253 ok = saveFile.close(); 252 ok = saveFile.close();
254 } 253 }
255*/ 254*/
256/*US 255/*US
257//US ToDo: write backupfile 256//US ToDo: write backupfile
258 QFile info; 257 QFile info;
259 info.setName( mFileName ); 258 info.setName( mFileName );
260 bool ok = info.open( IO_WriteOnly ); 259 bool ok = info.open( IO_WriteOnly );
261 if ( ok ) { 260 if ( ok ) {
262//US mFormat->saveAll( addressBook(), this, &info ); 261//US mFormat->saveAll( addressBook(), this, &info );
263 262
264 info.close(); 263 info.close();
265 ok = true; 264 ok = true;
266 } 265 }
267 else { 266 else {
268 267
269 } 268 }
270 269
271 if ( !ok ) 270 if ( !ok )
272 addressBook()->error( i18n( "Unable to save file '%1'." ).arg( mFileName ) ); 271 addressBook()->error( i18n( "Unable to save file '%1'." ).arg( mFileName ) );
273 272
274 delete ticket; 273 delete ticket;
275 unlock( mFileName ); 274 unlock( mFileName );
276 275
277 return ok; 276 return ok;
278 277
279 qDebug("ResourceOpie::save has to be changed"); 278 qDebug("ResourceOpie::save has to be changed");
280*/ 279*/
281 return true; 280 return true;
282 281
283} 282}
284 283
285bool ResourceOpie::lock( const QString &fileName ) 284bool ResourceOpie::lock( const QString &fileName )
286{ 285{
287// qDebug("ResourceOpie::lock() %s", fileName.latin1()); 286// qDebug("ResourceOpie::lock() %s", fileName.latin1());
288 kdDebug(5700) << "ResourceOpie::lock()" << endl; 287 kdDebug(5700) << "ResourceOpie::lock()" << endl;
289 288
290 QString fn = fileName; 289 QString fn = fileName;
291 290
292//US change the implementation how the lockfilename is getting created 291//US change the implementation how the lockfilename is getting created
293//US fn.replace( QRegExp("/"), "_" ); 292//US fn.replace( QRegExp("/"), "_" );
294//US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" ); 293//US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" );
295 294
296 KURL url(fn); 295 KURL url(fn);
297 QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); 296 QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" );
298 297
299 kdDebug(5700) << "-- lock name: " << lockName << endl; 298 kdDebug(5700) << "-- lock name: " << lockName << endl;
300 299
301 if (QFile::exists( lockName )) return false; 300 if (QFile::exists( lockName )) return false;
302 301
303 QString lockUniqueName; 302 QString lockUniqueName;
304 lockUniqueName = fn + KApplication::randomString( 8 ); 303 lockUniqueName = fn + KApplication::randomString( 8 );
305 304
306 url = lockUniqueName; 305 url = lockUniqueName;
307//US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName ); 306//US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName );
308 mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() ); 307 mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() );
309 kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl; 308 kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl;
310 309
311 // Create unique file 310 // Create unique file
312 QFile file( mLockUniqueName ); 311 QFile file( mLockUniqueName );
313 file.open( IO_WriteOnly ); 312 file.open( IO_WriteOnly );
314 file.close(); 313 file.close();
315 314
316 // Create lock file 315 // Create lock file
317 int result = 0; 316 int result = 0;
318#ifndef _WIN32_ 317#ifndef _WIN32_
319 result = ::link( QFile::encodeName( mLockUniqueName ), 318 result = ::link( QFile::encodeName( mLockUniqueName ),
320 QFile::encodeName( lockName ) ); 319 QFile::encodeName( lockName ) );
321#endif 320#endif
322 if ( result == 0 ) { 321 if ( result == 0 ) {
323 addressBook()->emitAddressBookLocked(); 322 addressBook()->emitAddressBookLocked();
324 return true; 323 return true;
325 } 324 }
326 325
327 // TODO: check stat 326 // TODO: check stat
328 327
329 return false; 328 return false;
330} 329}
331 330
332void ResourceOpie::unlock( const QString &fileName ) 331void ResourceOpie::unlock( const QString &fileName )
333{ 332{
334// qDebug("ResourceOpie::unlock() %s", fileName.latin1()); 333// qDebug("ResourceOpie::unlock() %s", fileName.latin1());
335 334
336 QString fn = fileName; 335 QString fn = fileName;
337//US change the implementation how the lockfilename is getting created 336//US change the implementation how the lockfilename is getting created
338//US fn.replace( QRegExp( "/" ), "_" ); 337//US fn.replace( QRegExp( "/" ), "_" );
339//US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" ); 338//US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" );
340//US QString lockName = fn + ".lock"; 339//US QString lockName = fn + ".lock";
341 KURL url(fn); 340 KURL url(fn);
342 QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); 341 QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" );
343 342
344 QFile::remove( lockName ); 343 QFile::remove( lockName );
345 QFile::remove( mLockUniqueName ); 344 QFile::remove( mLockUniqueName );
346 addressBook()->emitAddressBookUnlocked(); 345 addressBook()->emitAddressBookUnlocked();
347} 346}
348 347
349void ResourceOpie::setFileName( const QString &fileName ) 348void ResourceOpie::setFileName( const QString &fileName )
350{ 349{
351 mDirWatch.stopScan(); 350 mDirWatch.stopScan();
352 mDirWatch.removeFile( mFileName ); 351 mDirWatch.removeFile( mFileName );
353 352
354 mFileName = fileName; 353 mFileName = fileName;
355 354
356 mDirWatch.addFile( mFileName ); 355 mDirWatch.addFile( mFileName );
357 mDirWatch.startScan(); 356 mDirWatch.startScan();
358 357
359//US simulate KDirWatch event 358//US simulate KDirWatch event
360//US fileChanged(); 359//US fileChanged();
361} 360}
362 361
363QString ResourceOpie::fileName() const 362QString ResourceOpie::fileName() const
364{ 363{
365 return mFileName; 364 return mFileName;
366} 365}
367 366
368void ResourceOpie::fileChanged() 367void ResourceOpie::fileChanged()
369{ 368{
370 // There is a small theoretical chance that KDirWatch calls us before 369 // There is a small theoretical chance that KDirWatch calls us before
371 // we are fully constructed 370 // we are fully constructed
372 if (!addressBook()) 371 if (!addressBook())
373 return; 372 return;
373
374 QString text( i18n( "Opie resource '%1'<br> has been changed by third party.<br>Do you want to reload?").arg( mFileName ) );
375 if ( readOnly() || KMessageBox::questionYesNo( 0, text ) == KMessageBox::Yes ) {
376 load();
377 addressBook()->emitAddressBookChanged();
378 }
379
374 load(); 380 load();
375 addressBook()->emitAddressBookChanged(); 381 addressBook()->emitAddressBookChanged();
376} 382}
377 383
378void ResourceOpie::removeAddressee( const Addressee &addr ) 384void ResourceOpie::removeAddressee( const Addressee &addr )
379{ 385{
380} 386}
381 387
382void ResourceOpie::cleanUp() 388void ResourceOpie::cleanUp()
383{ 389{
384// qDebug("ResourceOpie::cleanup() %s", mFileName.latin1()); 390// qDebug("ResourceOpie::cleanup() %s", mFileName.latin1());
385 391
386 unlock( mFileName ); 392 unlock( mFileName );
387} 393}
388 394
389//US #include "resourceopie.moc" 395//US #include "resourceopie.moc"
diff --git a/kabc/plugins/qtopia/resourceqtopia.cpp b/kabc/plugins/qtopia/resourceqtopia.cpp
index 4854197..7475685 100644
--- a/kabc/plugins/qtopia/resourceqtopia.cpp
+++ b/kabc/plugins/qtopia/resourceqtopia.cpp
@@ -1,351 +1,356 @@
1/* 1/*
2 This file is part of libkabc. 2 This file is part of libkabc.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2001 Cornelius Schumacher <schumacher@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#include <sys/types.h> 27#include <sys/types.h>
28#include <sys/stat.h> 28#include <sys/stat.h>
29#include <unistd.h> 29#include <unistd.h>
30 30
31#include <qdir.h> 31#include <qdir.h>
32#include <qfile.h> 32#include <qfile.h>
33#include <qfileinfo.h> 33#include <qfileinfo.h>
34#include <qregexp.h> 34#include <qregexp.h>
35//US #include <qtimer.h> 35//US #include <qtimer.h>
36 36
37#include <kapplication.h> 37#include <kapplication.h>
38#include <kconfig.h> 38#include <kconfig.h>
39#include <kdebug.h> 39#include <kdebug.h>
40#include <klocale.h> 40#include <klocale.h>
41//US #include <ksavefile.h> 41//US #include <ksavefile.h>
42#include <kstandarddirs.h> 42#include <kstandarddirs.h>
43#include <kmessagebox.h>
43 44
44#include <qpe/pim/addressbookaccess.h> 45#include <qpe/pim/addressbookaccess.h>
45 46
46 47
47#include "resourceqtopiaconfig.h" 48#include "resourceqtopiaconfig.h"
48#include "stdaddressbook.h" 49#include "stdaddressbook.h"
49 50
50#include "qtopiaconverter.h" 51#include "qtopiaconverter.h"
51 52
52#include "resourceqtopia.h" 53#include "resourceqtopia.h"
53 54
54using namespace KABC; 55using namespace KABC;
55extern "C" 56extern "C"
56{ 57{
57 void *init_microkabc_qtopia() 58 void *init_microkabc_qtopia()
58 { 59 {
59 return new KRES::PluginFactory<ResourceQtopia,ResourceQtopiaConfig>(); 60 return new KRES::PluginFactory<ResourceQtopia,ResourceQtopiaConfig>();
60 } 61 }
61} 62}
62 63
63ResourceQtopia::ResourceQtopia( const KConfig *config ) 64ResourceQtopia::ResourceQtopia( const KConfig *config )
64 : Resource( config ), mConverter (0) 65 : Resource( config ), mConverter (0)
65{ 66{
66 // we can not choose the filename. Therefore use the default to display 67 // we can not choose the filename. Therefore use the default to display
67 QString fileName = QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml"; 68 QString fileName = QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml";
68 69
69 init( fileName ); 70 init( fileName );
70} 71}
71 72
72ResourceQtopia::ResourceQtopia( const QString &fileName ) 73ResourceQtopia::ResourceQtopia( const QString &fileName )
73 : Resource( 0 ) 74 : Resource( 0 )
74{ 75{
75// qDebug("ResourceFile::ResourceFile : 3 %s, %s", fileName.latin1(), formatName.latin1()); 76// qDebug("ResourceFile::ResourceFile : 3 %s, %s", fileName.latin1(), formatName.latin1());
76 init( fileName ); 77 init( fileName );
77} 78}
78 79
79void ResourceQtopia::init( const QString &fileName ) 80void ResourceQtopia::init( const QString &fileName )
80{ 81{
81 82
82 connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) ); 83 connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) );
83 connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) ); 84 connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) );
84 connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) ); 85 connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) );
85 86
86 setFileName( fileName ); 87 setFileName( fileName );
87} 88}
88 89
89ResourceQtopia::~ResourceQtopia() 90ResourceQtopia::~ResourceQtopia()
90{ 91{
91 if (mConverter != 0) 92 if (mConverter != 0)
92 delete mConverter; 93 delete mConverter;
93 94
94} 95}
95 96
96void ResourceQtopia::writeConfig( KConfig *config ) 97void ResourceQtopia::writeConfig( KConfig *config )
97{ 98{
98 Resource::writeConfig( config ); 99 Resource::writeConfig( config );
99} 100}
100 101
101Ticket *ResourceQtopia::requestSaveTicket() 102Ticket *ResourceQtopia::requestSaveTicket()
102{ 103{
103 kdDebug(5700) << "ResourceQtopia::requestSaveTicket()" << endl; 104 kdDebug(5700) << "ResourceQtopia::requestSaveTicket()" << endl;
104 105
105 if ( !addressBook() ) return 0; 106 if ( !addressBook() ) return 0;
106 107
107 if ( !lock( mFileName ) ) { 108 if ( !lock( mFileName ) ) {
108 kdDebug(5700) << "ResourceQtopia::requestSaveTicket(): Unable to lock file '" 109 kdDebug(5700) << "ResourceQtopia::requestSaveTicket(): Unable to lock file '"
109 << mFileName << "'" << endl; 110 << mFileName << "'" << endl;
110 return 0; 111 return 0;
111 } 112 }
112 return createTicket( this ); 113 return createTicket( this );
113} 114}
114 115
115 116
116bool ResourceQtopia::doOpen() 117bool ResourceQtopia::doOpen()
117{ 118{
118/*US 119/*US
119 QFile file( mFileName ); 120 QFile file( mFileName );
120 121
121 if ( !file.exists() ) { 122 if ( !file.exists() ) {
122 // try to create the file 123 // try to create the file
123 bool ok = file.open( IO_WriteOnly ); 124 bool ok = file.open( IO_WriteOnly );
124 if ( ok ) 125 if ( ok )
125 file.close(); 126 file.close();
126 127
127 return ok; 128 return ok;
128 } else { 129 } else {
129 if ( !file.open( IO_ReadWrite ) ) 130 if ( !file.open( IO_ReadWrite ) )
130 return false; 131 return false;
131 132
132 if ( file.size() == 0 ) { 133 if ( file.size() == 0 ) {
133 file.close(); 134 file.close();
134 return true; 135 return true;
135 } 136 }
136 137
137//US bool ok = mFormat->checkFormat( &file ); 138//US bool ok = mFormat->checkFormat( &file );
138 bool ok = true; 139 bool ok = true;
139 140
140 file.close(); 141 file.close();
141 142
142 return ok; 143 return ok;
143 } 144 }
144*/ 145*/
145 return true; 146 return true;
146} 147}
147 148
148void ResourceQtopia::doClose() 149void ResourceQtopia::doClose()
149{ 150{
150} 151}
151 152
152bool ResourceQtopia::load() 153bool ResourceQtopia::load()
153{ 154{
154 kdDebug(5700) << "ResourceQtopia::load(): '" << mFileName << "'" << endl; 155 kdDebug(5700) << "ResourceQtopia::load(): '" << mFileName << "'" << endl;
155 156
156// qDebug("ResourceQtopia::load: Try to load file() %s", mFileName.latin1()); 157// qDebug("ResourceQtopia::load: Try to load file() %s", mFileName.latin1());
157 158
158 AddressBookAccess* access = new AddressBookAccess(); 159 AddressBookAccess* access = new AddressBookAccess();
159 160
160 if ( !access ) { 161 if ( !access ) {
161 qDebug("Unable to load file() %s", mFileName.latin1()); 162 qDebug("Unable to load file() %s", mFileName.latin1());
162 addressBook()->error( i18n( "Unable to load file '%1'." ).arg( mFileName ) ); 163 addressBook()->error( i18n( "Unable to load file '%1'." ).arg( mFileName ) );
163 return false; 164 return false;
164 } 165 }
165 166
166 bool res = false; 167 bool res = false;
167 if (mConverter == 0) 168 if (mConverter == 0)
168 { 169 {
169 mConverter = new QtopiaConverter(); 170 mConverter = new QtopiaConverter();
170 res = mConverter->init(); 171 res = mConverter->init();
171 if ( !res ) 172 if ( !res )
172 { 173 {
173 qDebug("Unable to initialize qtopia converter. Most likely a problem with the category file"); 174 qDebug("Unable to initialize qtopia 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" ) ); 175 addressBook()->error( i18n( "Unable to initialize qtopia converter. Most likely a problem with the category file" ) );
175 delete access; 176 delete access;
176 return false; 177 return false;
177 } 178 }
178 } 179 }
179 180
180 { //create a new scope 181 { //create a new scope
181 AddressBookIterator it(*access); 182 AddressBookIterator it(*access);
182 const PimContact* contact; 183 const PimContact* contact;
183 184
184 for (contact=it.toFirst(); it.current(); ++it) { 185 for (contact=it.toFirst(); it.current(); ++it) {
185 contact = it.current(); 186 contact = it.current();
186 187
187 KABC::Addressee addressee; 188 KABC::Addressee addressee;
188 189
189 res = mConverter->qtopiaToAddressee( (*contact), addressee ); 190 res = mConverter->qtopiaToAddressee( (*contact), addressee );
190 191
191 if ( !addressee.isEmpty() && res ) 192 if ( !addressee.isEmpty() && res )
192 { 193 {
193 addressee.setResource( this ); 194 addressee.setResource( this );
194 addressBook()->insertAddressee( addressee ); 195 addressBook()->insertAddressee( addressee );
195 } 196 }
196 } 197 }
197 } 198 }
198 199
199 delete access; 200 delete access;
200 return true; 201 return true;
201} 202}
202 203
203bool ResourceQtopia::save( Ticket *ticket ) 204bool ResourceQtopia::save( Ticket *ticket )
204{ 205{
205/*US 206/*US
206// qDebug("ResourceFile::save format %s, %s", mFileName.latin1(), mFormatName.latin1()); 207// qDebug("ResourceFile::save format %s, %s", mFileName.latin1(), mFormatName.latin1());
207 kdDebug(5700) << "ResourceQtopia::save()" << endl; 208 kdDebug(5700) << "ResourceQtopia::save()" << endl;
208 209
209 // create backup file 210 // create backup file
210 QString extension = "_" + QString::number( QDate::currentDate().dayOfWeek() ); 211 QString extension = "_" + QString::number( QDate::currentDate().dayOfWeek() );
211 212
212/*US we use a simpler method to create a backupfile 213/*US we use a simpler method to create a backupfile
213 214
214 (void) KSaveFile::backupFile( mFileName, QString::null 215 (void) KSaveFile::backupFile( mFileName, QString::null
215 ,extension ); 216 ,extension );
216 217
217 KSaveFile saveFile( mFileName ); 218 KSaveFile saveFile( mFileName );
218 bool ok = false; 219 bool ok = false;
219 if ( saveFile.status() == 0 && saveFile.file() ) 220 if ( saveFile.status() == 0 && saveFile.file() )
220 { 221 {
221 mFormat->saveAll( addressBook(), this, saveFile.file() ); 222 mFormat->saveAll( addressBook(), this, saveFile.file() );
222 ok = saveFile.close(); 223 ok = saveFile.close();
223 } 224 }
224*/ 225*/
225 226
226/*US 227/*US
227//US ToDo: write backupfile 228//US ToDo: write backupfile
228 QFile info; 229 QFile info;
229 info.setName( mFileName ); 230 info.setName( mFileName );
230 bool ok = info.open( IO_WriteOnly ); 231 bool ok = info.open( IO_WriteOnly );
231 if ( ok ) { 232 if ( ok ) {
232//US mFormat->saveAll( addressBook(), this, &info ); 233//US mFormat->saveAll( addressBook(), this, &info );
233 234
234 info.close(); 235 info.close();
235 ok = true; 236 ok = true;
236 } 237 }
237 else { 238 else {
238 239
239 } 240 }
240 241
241 if ( !ok ) 242 if ( !ok )
242 addressBook()->error( i18n( "Unable to save file '%1'." ).arg( mFileName ) ); 243 addressBook()->error( i18n( "Unable to save file '%1'." ).arg( mFileName ) );
243 244
244 delete ticket; 245 delete ticket;
245 unlock( mFileName ); 246 unlock( mFileName );
246 247
247 return ok; 248 return ok;
248 249
249 qDebug("ResourceQtopia::save has to be changed"); 250 qDebug("ResourceQtopia::save has to be changed");
250*/ 251*/
251 return true; 252 return true;
252} 253}
253 254
254bool ResourceQtopia::lock( const QString &fileName ) 255bool ResourceQtopia::lock( const QString &fileName )
255{ 256{
256 kdDebug(5700) << "ResourceQtopia::lock()" << endl; 257 kdDebug(5700) << "ResourceQtopia::lock()" << endl;
257 258
258 QString fn = fileName; 259 QString fn = fileName;
259 260
260//US change the implementation how the lockfilename is getting created 261//US change the implementation how the lockfilename is getting created
261//US fn.replace( QRegExp("/"), "_" ); 262//US fn.replace( QRegExp("/"), "_" );
262//US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" ); 263//US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" );
263 264
264 KURL url(fn); 265 KURL url(fn);
265 QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); 266 QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" );
266 267
267 kdDebug(5700) << "-- lock name: " << lockName << endl; 268 kdDebug(5700) << "-- lock name: " << lockName << endl;
268 269
269 if (QFile::exists( lockName )) return false; 270 if (QFile::exists( lockName )) return false;
270 271
271 QString lockUniqueName; 272 QString lockUniqueName;
272 lockUniqueName = fn + KApplication::randomString( 8 ); 273 lockUniqueName = fn + KApplication::randomString( 8 );
273 274
274 url = lockUniqueName; 275 url = lockUniqueName;
275//US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName ); 276//US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName );
276 mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() ); 277 mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() );
277 kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl; 278 kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl;
278 279
279 // Create unique file 280 // Create unique file
280 QFile file( mLockUniqueName ); 281 QFile file( mLockUniqueName );
281 file.open( IO_WriteOnly ); 282 file.open( IO_WriteOnly );
282 file.close(); 283 file.close();
283 284
284 // Create lock file 285 // Create lock file
285 int result = ::link( QFile::encodeName( mLockUniqueName ), 286 int result = ::link( QFile::encodeName( mLockUniqueName ),
286 QFile::encodeName( lockName ) ); 287 QFile::encodeName( lockName ) );
287 288
288 if ( result == 0 ) { 289 if ( result == 0 ) {
289 addressBook()->emitAddressBookLocked(); 290 addressBook()->emitAddressBookLocked();
290 return true; 291 return true;
291 } 292 }
292 293
293 // TODO: check stat 294 // TODO: check stat
294 295
295 return false; 296 return false;
296} 297}
297 298
298void ResourceQtopia::unlock( const QString &fileName ) 299void ResourceQtopia::unlock( const QString &fileName )
299{ 300{
300 QString fn = fileName; 301 QString fn = fileName;
301//US change the implementation how the lockfilename is getting created 302//US change the implementation how the lockfilename is getting created
302//US fn.replace( QRegExp( "/" ), "_" ); 303//US fn.replace( QRegExp( "/" ), "_" );
303//US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" ); 304//US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" );
304//US QString lockName = fn + ".lock"; 305//US QString lockName = fn + ".lock";
305 KURL url(fn); 306 KURL url(fn);
306 QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); 307 QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" );
307 308
308 QFile::remove( lockName ); 309 QFile::remove( lockName );
309 QFile::remove( mLockUniqueName ); 310 QFile::remove( mLockUniqueName );
310 addressBook()->emitAddressBookUnlocked(); 311 addressBook()->emitAddressBookUnlocked();
311} 312}
312 313
313void ResourceQtopia::setFileName( const QString &fileName ) 314void ResourceQtopia::setFileName( const QString &fileName )
314{ 315{
315 mDirWatch.stopScan(); 316 mDirWatch.stopScan();
316 mDirWatch.removeFile( mFileName ); 317 mDirWatch.removeFile( mFileName );
317 318
318 mFileName = fileName; 319 mFileName = fileName;
319 320
320 mDirWatch.addFile( mFileName ); 321 mDirWatch.addFile( mFileName );
321 mDirWatch.startScan(); 322 mDirWatch.startScan();
322 323
323//US simulate KDirWatch event 324//US simulate KDirWatch event
324//US fileChanged(); 325//US fileChanged();
325} 326}
326 327
327QString ResourceQtopia::fileName() const 328QString ResourceQtopia::fileName() const
328{ 329{
329 return mFileName; 330 return mFileName;
330} 331}
331 332
332void ResourceQtopia::fileChanged() 333void ResourceQtopia::fileChanged()
333{ 334{
334 // There is a small theoretical chance that KDirWatch calls us before 335 // There is a small theoretical chance that KDirWatch calls us before
335 // we are fully constructed 336 // we are fully constructed
336 if (!addressBook()) 337 if (!addressBook())
337 return; 338 return;
338 load(); 339
339 addressBook()->emitAddressBookChanged(); 340 QString text( i18n( "Qtopia resource '%1'<br> has been changed by third party.<br>Do you want to reload?").arg( mFileName ) );
341 if ( readOnly() || KMessageBox::questionYesNo( 0, text ) == KMessageBox::Yes ) {
342 load();
343 addressBook()->emitAddressBookChanged();
344 }
340} 345}
341 346
342void ResourceQtopia::removeAddressee( const Addressee &addr ) 347void ResourceQtopia::removeAddressee( const Addressee &addr )
343{ 348{
344} 349}
345 350
346void ResourceQtopia::cleanUp() 351void ResourceQtopia::cleanUp()
347{ 352{
348 unlock( mFileName ); 353 unlock( mFileName );
349} 354}
350 355
351//US #include "resourceqtopia.moc" 356//US #include "resourceqtopia.moc"
diff --git a/kaddressbook/details/detailsviewcontainer.cpp b/kaddressbook/details/detailsviewcontainer.cpp
index 8f566cf..a42499f 100644
--- a/kaddressbook/details/detailsviewcontainer.cpp
+++ b/kaddressbook/details/detailsviewcontainer.cpp
@@ -1,171 +1,172 @@
1/* 1/*
2 This file is part of KAddressBook. 2 This file is part of KAddressBook.
3 Copyright (c) 1996-2002 Mirko Boehm <mirko@kde.org> 3 Copyright (c) 1996-2002 Mirko Boehm <mirko@kde.org>
4 4
5 This program is free software; you can redistribute it and/or modify 5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by 6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or 7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version. 8 (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program 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 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details. 13 GNU General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software 16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 18
19 As a special exception, permission is given to link this program 19 As a special exception, permission is given to link this program
20 with any edition of Qt, and distribute the resulting executable, 20 with any edition of Qt, and distribute the resulting executable,
21 without including the source code for Qt in the source distribution. 21 without including the source code for Qt in the source distribution.
22*/ 22*/
23 23
24#include <qcombobox.h> 24#include <qcombobox.h>
25#include <qframe.h> 25#include <qframe.h>
26#include <qlabel.h> 26#include <qlabel.h>
27#include <qlayout.h> 27#include <qlayout.h>
28#include <qwidgetstack.h> 28#include <qwidgetstack.h>
29 29
30#include <kapplication.h> 30#include <kapplication.h>
31#include <kdebug.h> 31#include <kdebug.h>
32#include <kdialog.h> 32#include <kdialog.h>
33 33
34#include "look_basic.h" 34#include "look_basic.h"
35//#include "look_details.h" 35//#include "look_details.h"
36#include "look_html.h" 36#include "look_html.h"
37 37
38#ifdef KAB_EMBEDDED 38#ifdef KAB_EMBEDDED
39#include "kabprefs.h" 39#include "kabprefs.h"
40#endif //KAB_EMBEDDED 40#endif //KAB_EMBEDDED
41 41
42 42
43#include "detailsviewcontainer.h" 43#include "detailsviewcontainer.h"
44 44
45ViewContainer::ViewContainer( QWidget *parent, const char* name ) 45ViewContainer::ViewContainer( QWidget *parent, const char* name )
46 : QWidget( parent, name ), mCurrentLook( 0 ) 46 : QWidget( parent, name ), mCurrentLook( 0 )
47{ 47{
48 QBoxLayout *topLayout = new QVBoxLayout( this ); 48 QBoxLayout *topLayout = new QVBoxLayout( this );
49 //topLayout->setMargin( KDialog::marginHint() ); 49 //topLayout->setMargin( KDialog::marginHint() );
50 //topLayout->setSpacing( KDialog::spacingHint() ); 50 //topLayout->setSpacing( KDialog::spacingHint() );
51 topLayout->setMargin( 0 ); 51 topLayout->setMargin( 0 );
52 topLayout->setSpacing( 0 ); 52 topLayout->setSpacing( 0 );
53 53
54 QBoxLayout *styleLayout = new QHBoxLayout( topLayout ); 54 QBoxLayout *styleLayout = new QHBoxLayout( topLayout );
55 55
56 QLabel *label = new QLabel( i18n("Style:"), this ); 56 QLabel *label = new QLabel( i18n("Style:"), this );
57 styleLayout->addWidget( label ); 57 styleLayout->addWidget( label );
58 58
59 mStyleCombo = new QComboBox( this ); 59 mStyleCombo = new QComboBox( this );
60 styleLayout->addWidget( mStyleCombo ); 60 styleLayout->addWidget( mStyleCombo );
61 61
62 QFrame *frameRuler = new QFrame( this ); 62 QFrame *frameRuler = new QFrame( this );
63//US frameRuler->setFrameShape( QFrame::HLine ); 63//US frameRuler->setFrameShape( QFrame::HLine );
64//US frameRuler->setFrameShadow( QFrame::Sunken ); 64//US frameRuler->setFrameShadow( QFrame::Sunken );
65//US topLayout->addWidget( frameRuler ); 65//US topLayout->addWidget( frameRuler );
66 66
67 mDetailsStack = new QWidgetStack( this ); 67 mDetailsStack = new QWidgetStack( this );
68 topLayout->addWidget( mDetailsStack, 1 ); 68 topLayout->addWidget( mDetailsStack, 1 );
69 69
70 registerLooks(); 70 registerLooks();
71 71
72#if 1 72#if 1
73 // Hide detailed view selection combo box, because we currently have 73 // Hide detailed view selection combo box, because we currently have
74 // only one. Reenable it when there are more detailed views. 74 // only one. Reenable it when there are more detailed views.
75 label->hide(); 75 label->hide();
76 mStyleCombo->hide(); 76 mStyleCombo->hide();
77 frameRuler->hide(); 77 frameRuler->hide();
78#endif 78#endif
79} 79}
80 80
81KABBasicLook *ViewContainer::currentLook() 81KABBasicLook *ViewContainer::currentLook()
82{ 82{
83 return mCurrentLook; 83 return mCurrentLook;
84} 84}
85 85
86void ViewContainer::registerLooks() 86void ViewContainer::registerLooks()
87{ 87{
88 mLookFactories.append( new KABHtmlViewFactory( mDetailsStack ) ); 88 mLookFactories.append( new KABHtmlViewFactory( mDetailsStack ) );
89// mLookFactories.append( new KABDetailedViewFactory( mDetailsStack ) ); 89// mLookFactories.append( new KABDetailedViewFactory( mDetailsStack ) );
90 mStyleCombo->clear(); 90 mStyleCombo->clear();
91 91
92 for ( uint i = 0; i < mLookFactories.count(); ++i ) 92 for ( uint i = 0; i < mLookFactories.count(); ++i )
93 mStyleCombo->insertItem( mLookFactories.at( i )->description() ); 93 mStyleCombo->insertItem( mLookFactories.at( i )->description() );
94 94
95 if ( !mLookFactories.isEmpty() ) 95 if ( !mLookFactories.isEmpty() )
96 slotStyleSelected( 0 ); 96 slotStyleSelected( 0 );
97} 97}
98 98
99void ViewContainer::slotStyleSelected( int index ) 99void ViewContainer::slotStyleSelected( int index )
100{ 100{
101#ifndef KAB_EMBEDDED 101#ifndef KAB_EMBEDDED
102 KConfig *config = kapp->config(); 102 KConfig *config = kapp->config();
103#else //KAB_EMBEDDED 103#else //KAB_EMBEDDED
104 //US I hope I got the same config object as above expected. 104 //US I hope I got the same config object as above expected.
105 KConfig *config = KABPrefs::instance()->getConfig(); 105 KConfig *config = KABPrefs::instance()->getConfig();
106#endif //KAB_EMBEDDED 106#endif //KAB_EMBEDDED
107 KABC::Addressee addr; 107 KABC::Addressee addr;
108 108
109 if ( index >= 0 && index < mStyleCombo->count() ) { 109 if ( index >= 0 && index < mStyleCombo->count() ) {
110 if ( mCurrentLook != 0 ) { 110 if ( mCurrentLook != 0 ) {
111 mCurrentLook->saveSettings( config ); 111 mCurrentLook->saveSettings( config );
112 addr = mCurrentLook->addressee(); 112 addr = mCurrentLook->addressee();
113 113
114 delete mCurrentLook; 114 delete mCurrentLook;
115 mCurrentLook = 0; 115 mCurrentLook = 0;
116 } 116 }
117 117
118 KABLookFactory *factory = mLookFactories.at( index ); 118 KABLookFactory *factory = mLookFactories.at( index );
119 kdDebug(5720) << "ViewContainer::slotStyleSelected: " 119 kdDebug(5720) << "ViewContainer::slotStyleSelected: "
120 << "creating look " 120 << "creating look "
121 << factory->description() << endl; 121 << factory->description() << endl;
122 122
123 mCurrentLook = factory->create(); 123 mCurrentLook = factory->create();
124 mDetailsStack->raiseWidget( mCurrentLook ); 124 mDetailsStack->raiseWidget( mCurrentLook );
125 125
126 connect( mCurrentLook, SIGNAL( sendEmail( const QString& ) ), this, 126 connect( mCurrentLook, SIGNAL( sendEmail( const QString& ) ), this,
127 SIGNAL( sendEmail( const QString& ) ) ); 127 SIGNAL( sendEmail( const QString& ) ) );
128 connect( mCurrentLook, SIGNAL( browse( const QString& ) ), this, 128 connect( mCurrentLook, SIGNAL( browse( const QString& ) ), this,
129 SIGNAL( browse( const QString& ) ) ); 129 SIGNAL( browse( const QString& ) ) );
130 } 130 }
131 131
132 mCurrentLook->restoreSettings( config ); 132 mCurrentLook->restoreSettings( config );
133 mCurrentLook->setAddressee( addr ); 133 mCurrentLook->setAddressee( addr );
134} 134}
135void ViewContainer::refreshView() 135void ViewContainer::refreshView()
136{ 136{
137 if ( mCurrentLook ) 137 if ( mCurrentLook ) {
138 mCurrentLook->setAddressee( mCurrentAddressee ); 138 mCurrentLook->setAddressee( mCurrentAddressee );
139 }
139} 140}
140 141
141void ViewContainer::setAddressee( const KABC::Addressee& addressee ) 142void ViewContainer::setAddressee( const KABC::Addressee& addressee )
142{ 143{
143 if ( mCurrentLook != 0 ) { 144 if ( mCurrentLook != 0 ) {
144 if ( addressee == mCurrentAddressee ) 145 if ( addressee == mCurrentAddressee )
145 return; 146 return;
146 else { 147 else {
147 mCurrentAddressee = addressee; 148 mCurrentAddressee = addressee;
148 mCurrentLook->setAddressee( mCurrentAddressee ); 149 mCurrentLook->setAddressee( mCurrentAddressee );
149 } 150 }
150 } 151 }
151} 152}
152 153
153KABC::Addressee ViewContainer::addressee() 154KABC::Addressee ViewContainer::addressee()
154{ 155{
155 static KABC::Addressee empty; // do not use! 156 static KABC::Addressee empty; // do not use!
156 157
157 if ( !mCurrentLook ) 158 if ( !mCurrentLook )
158 return empty; 159 return empty;
159 else 160 else
160 return mCurrentLook->addressee(); 161 return mCurrentLook->addressee();
161} 162}
162 163
163void ViewContainer::setReadOnly( bool state ) 164void ViewContainer::setReadOnly( bool state )
164{ 165{
165 if ( mCurrentLook ) 166 if ( mCurrentLook )
166 mCurrentLook->setReadOnly( state ); 167 mCurrentLook->setReadOnly( state );
167} 168}
168 169
169#ifndef KAB_EMBEDDED 170#ifndef KAB_EMBEDDED
170#include "detailsviewcontainer.moc" 171#include "detailsviewcontainer.moc"
171#endif //KAB_EMBEDDED 172#endif //KAB_EMBEDDED
diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp
index 2b07541..a7ca0ce 100644
--- a/kaddressbook/kabcore.cpp
+++ b/kaddressbook/kabcore.cpp
@@ -615,1024 +615,1025 @@ void KABCore::pasteContacts( KABC::Addressee::List &list )
615} 615}
616 616
617void KABCore::setWhoAmI() 617void KABCore::setWhoAmI()
618{ 618{
619 KABC::Addressee::List addrList = mViewManager->selectedAddressees(); 619 KABC::Addressee::List addrList = mViewManager->selectedAddressees();
620 620
621 if ( addrList.count() > 1 ) { 621 if ( addrList.count() > 1 ) {
622 KMessageBox::sorry( this, i18n( "Please select only one contact." ) ); 622 KMessageBox::sorry( this, i18n( "Please select only one contact." ) );
623 return; 623 return;
624 } 624 }
625 625
626 QString text( i18n( "<qt>Do you really want to use <b>%1</b> as your new personal contact?</qt>" ) ); 626 QString text( i18n( "<qt>Do you really want to use <b>%1</b> as your new personal contact?</qt>" ) );
627 if ( KMessageBox::questionYesNo( this, text.arg( addrList[ 0 ].assembledName() ) ) == KMessageBox::Yes ) 627 if ( KMessageBox::questionYesNo( this, text.arg( addrList[ 0 ].assembledName() ) ) == KMessageBox::Yes )
628 static_cast<KABC::StdAddressBook*>( KABC::StdAddressBook::self() )->setWhoAmI( addrList[ 0 ] ); 628 static_cast<KABC::StdAddressBook*>( KABC::StdAddressBook::self() )->setWhoAmI( addrList[ 0 ] );
629} 629}
630 630
631void KABCore::setCategories() 631void KABCore::setCategories()
632{ 632{
633 KPIM::CategorySelectDialog dlg( KABPrefs::instance(), this, "", true ); 633 KPIM::CategorySelectDialog dlg( KABPrefs::instance(), this, "", true );
634 if ( !dlg.exec() ) 634 if ( !dlg.exec() )
635 return; 635 return;
636 636
637 bool merge = false; 637 bool merge = false;
638 QString msg = i18n( "Merge with existing categories?" ); 638 QString msg = i18n( "Merge with existing categories?" );
639 if ( KMessageBox::questionYesNo( this, msg ) == KMessageBox::Yes ) 639 if ( KMessageBox::questionYesNo( this, msg ) == KMessageBox::Yes )
640 merge = true; 640 merge = true;
641 641
642 QStringList categories = dlg.selectedCategories(); 642 QStringList categories = dlg.selectedCategories();
643 643
644 QStringList uids = mViewManager->selectedUids(); 644 QStringList uids = mViewManager->selectedUids();
645 QStringList::Iterator it; 645 QStringList::Iterator it;
646 for ( it = uids.begin(); it != uids.end(); ++it ) { 646 for ( it = uids.begin(); it != uids.end(); ++it ) {
647 KABC::Addressee addr = mAddressBook->findByUid( *it ); 647 KABC::Addressee addr = mAddressBook->findByUid( *it );
648 if ( !addr.isEmpty() ) { 648 if ( !addr.isEmpty() ) {
649 if ( !merge ) 649 if ( !merge )
650 addr.setCategories( categories ); 650 addr.setCategories( categories );
651 else { 651 else {
652 QStringList addrCategories = addr.categories(); 652 QStringList addrCategories = addr.categories();
653 QStringList::Iterator catIt; 653 QStringList::Iterator catIt;
654 for ( catIt = categories.begin(); catIt != categories.end(); ++catIt ) { 654 for ( catIt = categories.begin(); catIt != categories.end(); ++catIt ) {
655 if ( !addrCategories.contains( *catIt ) ) 655 if ( !addrCategories.contains( *catIt ) )
656 addrCategories.append( *catIt ); 656 addrCategories.append( *catIt );
657 } 657 }
658 addr.setCategories( addrCategories ); 658 addr.setCategories( addrCategories );
659 } 659 }
660 660
661 mAddressBook->insertAddressee( addr ); 661 mAddressBook->insertAddressee( addr );
662 } 662 }
663 } 663 }
664 664
665 if ( uids.count() > 0 ) 665 if ( uids.count() > 0 )
666 setModified( true ); 666 setModified( true );
667} 667}
668 668
669void KABCore::setSearchFields( const KABC::Field::List &fields ) 669void KABCore::setSearchFields( const KABC::Field::List &fields )
670{ 670{
671 mIncSearchWidget->setFields( fields ); 671 mIncSearchWidget->setFields( fields );
672} 672}
673 673
674void KABCore::incrementalSearch( const QString& text ) 674void KABCore::incrementalSearch( const QString& text )
675{ 675{
676 mViewManager->setSelected( QString::null, false ); 676 mViewManager->setSelected( QString::null, false );
677 677
678 if ( !text.isEmpty() ) { 678 if ( !text.isEmpty() ) {
679 KABC::Field *field = mIncSearchWidget->currentField(); 679 KABC::Field *field = mIncSearchWidget->currentField();
680 680
681 QString pattern = text.lower(); 681 QString pattern = text.lower();
682 682
683#if 1 //KDE_VERSION >= 319 683#if 1 //KDE_VERSION >= 319
684 KABC::AddresseeList list( mAddressBook->allAddressees() ); 684 KABC::AddresseeList list( mAddressBook->allAddressees() );
685 if ( field ) { 685 if ( field ) {
686 list.sortByField( field ); 686 list.sortByField( field );
687 KABC::AddresseeList::Iterator it; 687 KABC::AddresseeList::Iterator it;
688 for ( it = list.begin(); it != list.end(); ++it ) { 688 for ( it = list.begin(); it != list.end(); ++it ) {
689 if ( field->value( *it ).lower().startsWith( pattern ) ) { 689 if ( field->value( *it ).lower().startsWith( pattern ) ) {
690 mViewManager->setSelected( (*it).uid(), true ); 690 mViewManager->setSelected( (*it).uid(), true );
691 return; 691 return;
692 } 692 }
693 } 693 }
694 } else { 694 } else {
695 KABC::AddresseeList::Iterator it; 695 KABC::AddresseeList::Iterator it;
696 for ( it = list.begin(); it != list.end(); ++it ) { 696 for ( it = list.begin(); it != list.end(); ++it ) {
697 KABC::Field::List fieldList = mIncSearchWidget->fields(); 697 KABC::Field::List fieldList = mIncSearchWidget->fields();
698 KABC::Field::List::ConstIterator fieldIt; 698 KABC::Field::List::ConstIterator fieldIt;
699 for ( fieldIt = fieldList.begin(); fieldIt != fieldList.end(); ++fieldIt ) { 699 for ( fieldIt = fieldList.begin(); fieldIt != fieldList.end(); ++fieldIt ) {
700 if ( (*fieldIt)->value( *it ).lower().startsWith( pattern ) ) { 700 if ( (*fieldIt)->value( *it ).lower().startsWith( pattern ) ) {
701 mViewManager->setSelected( (*it).uid(), true ); 701 mViewManager->setSelected( (*it).uid(), true );
702 return; 702 return;
703 } 703 }
704 } 704 }
705 } 705 }
706 } 706 }
707#else 707#else
708 KABC::AddressBook::Iterator it; 708 KABC::AddressBook::Iterator it;
709 for ( it = mAddressBook->begin(); it != mAddressBook->end(); ++it ) { 709 for ( it = mAddressBook->begin(); it != mAddressBook->end(); ++it ) {
710 if ( field ) { 710 if ( field ) {
711 if ( field->value( *it ).lower().startsWith( pattern ) ) { 711 if ( field->value( *it ).lower().startsWith( pattern ) ) {
712 mViewManager->setSelected( (*it).uid(), true ); 712 mViewManager->setSelected( (*it).uid(), true );
713 return; 713 return;
714 } 714 }
715 } else { 715 } else {
716 KABC::Field::List fieldList = mIncSearchWidget->fields(); 716 KABC::Field::List fieldList = mIncSearchWidget->fields();
717 KABC::Field::List::ConstIterator fieldIt; 717 KABC::Field::List::ConstIterator fieldIt;
718 for ( fieldIt = fieldList.begin(); fieldIt != fieldList.end(); ++fieldIt ) { 718 for ( fieldIt = fieldList.begin(); fieldIt != fieldList.end(); ++fieldIt ) {
719 if ( (*fieldIt)->value( *it ).lower().startsWith( pattern ) ) { 719 if ( (*fieldIt)->value( *it ).lower().startsWith( pattern ) ) {
720 mViewManager->setSelected( (*it).uid(), true ); 720 mViewManager->setSelected( (*it).uid(), true );
721 return; 721 return;
722 } 722 }
723 } 723 }
724 } 724 }
725 } 725 }
726#endif 726#endif
727 } 727 }
728} 728}
729 729
730void KABCore::setModified() 730void KABCore::setModified()
731{ 731{
732 setModified( true ); 732 setModified( true );
733} 733}
734 734
735void KABCore::setModifiedWOrefresh() 735void KABCore::setModifiedWOrefresh()
736{ 736{
737 // qDebug("KABCore::setModifiedWOrefresh() "); 737 // qDebug("KABCore::setModifiedWOrefresh() ");
738 mModified = true; 738 mModified = true;
739 mActionSave->setEnabled( mModified ); 739 mActionSave->setEnabled( mModified );
740#ifdef DESKTOP_VERSION 740#ifdef DESKTOP_VERSION
741 mDetails->refreshView(); 741 mDetails->refreshView();
742#endif 742#endif
743 743
744} 744}
745void KABCore::setModified( bool modified ) 745void KABCore::setModified( bool modified )
746{ 746{
747 mModified = modified; 747 mModified = modified;
748 mActionSave->setEnabled( mModified ); 748 mActionSave->setEnabled( mModified );
749 749
750 if ( modified ) 750 if ( modified )
751 mJumpButtonBar->recreateButtons(); 751 mJumpButtonBar->recreateButtons();
752 752
753 mViewManager->refreshView(); 753 mViewManager->refreshView();
754 mDetails->refreshView(); 754 mDetails->refreshView();
755 755
756} 756}
757 757
758bool KABCore::modified() const 758bool KABCore::modified() const
759{ 759{
760 return mModified; 760 return mModified;
761} 761}
762 762
763void KABCore::contactModified( const KABC::Addressee &addr ) 763void KABCore::contactModified( const KABC::Addressee &addr )
764{ 764{
765 765
766 Command *command = 0; 766 Command *command = 0;
767 QString uid; 767 QString uid;
768 768
769 // check if it exists already 769 // check if it exists already
770 KABC::Addressee origAddr = mAddressBook->findByUid( addr.uid() ); 770 KABC::Addressee origAddr = mAddressBook->findByUid( addr.uid() );
771 if ( origAddr.isEmpty() ) 771 if ( origAddr.isEmpty() )
772 command = new PwNewCommand( mAddressBook, addr ); 772 command = new PwNewCommand( mAddressBook, addr );
773 else { 773 else {
774 command = new PwEditCommand( mAddressBook, origAddr, addr ); 774 command = new PwEditCommand( mAddressBook, origAddr, addr );
775 uid = addr.uid(); 775 uid = addr.uid();
776 } 776 }
777 777
778 UndoStack::instance()->push( command ); 778 UndoStack::instance()->push( command );
779 RedoStack::instance()->clear(); 779 RedoStack::instance()->clear();
780 780
781 setModified( true ); 781 setModified( true );
782} 782}
783 783
784void KABCore::newContact() 784void KABCore::newContact()
785{ 785{
786 786
787 787
788 QPtrList<KABC::Resource> kabcResources = mAddressBook->resources(); 788 QPtrList<KABC::Resource> kabcResources = mAddressBook->resources();
789 789
790 QPtrList<KRES::Resource> kresResources; 790 QPtrList<KRES::Resource> kresResources;
791 QPtrListIterator<KABC::Resource> it( kabcResources ); 791 QPtrListIterator<KABC::Resource> it( kabcResources );
792 KABC::Resource *resource; 792 KABC::Resource *resource;
793 while ( ( resource = it.current() ) != 0 ) { 793 while ( ( resource = it.current() ) != 0 ) {
794 ++it; 794 ++it;
795 if ( !resource->readOnly() ) { 795 if ( !resource->readOnly() ) {
796 KRES::Resource *res = static_cast<KRES::Resource*>( resource ); 796 KRES::Resource *res = static_cast<KRES::Resource*>( resource );
797 if ( res ) 797 if ( res )
798 kresResources.append( res ); 798 kresResources.append( res );
799 } 799 }
800 } 800 }
801 801
802 KRES::Resource *res = KRES::SelectDialog::getResource( kresResources, this ); 802 KRES::Resource *res = KRES::SelectDialog::getResource( kresResources, this );
803 resource = static_cast<KABC::Resource*>( res ); 803 resource = static_cast<KABC::Resource*>( res );
804 804
805 if ( resource ) { 805 if ( resource ) {
806 KABC::Addressee addr; 806 KABC::Addressee addr;
807 addr.setResource( resource ); 807 addr.setResource( resource );
808 mEditorDialog->setAddressee( addr ); 808 mEditorDialog->setAddressee( addr );
809 KApplication::execDialog ( mEditorDialog ); 809 KApplication::execDialog ( mEditorDialog );
810 810
811 } else 811 } else
812 return; 812 return;
813 813
814 // mEditorDict.insert( dialog->addressee().uid(), dialog ); 814 // mEditorDict.insert( dialog->addressee().uid(), dialog );
815 815
816 816
817} 817}
818 818
819void KABCore::addEmail( QString aStr ) 819void KABCore::addEmail( QString aStr )
820{ 820{
821#ifndef KAB_EMBEDDED 821#ifndef KAB_EMBEDDED
822 QString fullName, email; 822 QString fullName, email;
823 823
824 KABC::Addressee::parseEmailAddress( aStr, fullName, email ); 824 KABC::Addressee::parseEmailAddress( aStr, fullName, email );
825 825
826 // Try to lookup the addressee matching the email address 826 // Try to lookup the addressee matching the email address
827 bool found = false; 827 bool found = false;
828 QStringList emailList; 828 QStringList emailList;
829 KABC::AddressBook::Iterator it; 829 KABC::AddressBook::Iterator it;
830 for ( it = mAddressBook->begin(); !found && (it != mAddressBook->end()); ++it ) { 830 for ( it = mAddressBook->begin(); !found && (it != mAddressBook->end()); ++it ) {
831 emailList = (*it).emails(); 831 emailList = (*it).emails();
832 if ( emailList.contains( email ) > 0 ) { 832 if ( emailList.contains( email ) > 0 ) {
833 found = true; 833 found = true;
834 (*it).setNameFromString( fullName ); 834 (*it).setNameFromString( fullName );
835 editContact( (*it).uid() ); 835 editContact( (*it).uid() );
836 } 836 }
837 } 837 }
838 838
839 if ( !found ) { 839 if ( !found ) {
840 KABC::Addressee addr; 840 KABC::Addressee addr;
841 addr.setNameFromString( fullName ); 841 addr.setNameFromString( fullName );
842 addr.insertEmail( email, true ); 842 addr.insertEmail( email, true );
843 843
844 mAddressBook->insertAddressee( addr ); 844 mAddressBook->insertAddressee( addr );
845 mViewManager->refreshView( addr.uid() ); 845 mViewManager->refreshView( addr.uid() );
846 editContact( addr.uid() ); 846 editContact( addr.uid() );
847 } 847 }
848#else //KAB_EMBEDDED 848#else //KAB_EMBEDDED
849 qDebug("KABCore::addEmail finsih method"); 849 qDebug("KABCore::addEmail finsih method");
850#endif //KAB_EMBEDDED 850#endif //KAB_EMBEDDED
851} 851}
852 852
853void KABCore::importVCard( const KURL &url, bool showPreview ) 853void KABCore::importVCard( const KURL &url, bool showPreview )
854{ 854{
855 mXXPortManager->importVCard( url, showPreview ); 855 mXXPortManager->importVCard( url, showPreview );
856} 856}
857void KABCore::importFromOL() 857void KABCore::importFromOL()
858{ 858{
859#ifdef _WIN32_ 859#ifdef _WIN32_
860 KAImportOLdialog* idgl = new KAImportOLdialog( i18n("Import Contacts from OL"), mAddressBook, this ); 860 KAImportOLdialog* idgl = new KAImportOLdialog( i18n("Import Contacts from OL"), mAddressBook, this );
861 idgl->exec(); 861 idgl->exec();
862 KABC::Addressee::List list = idgl->getAddressList(); 862 KABC::Addressee::List list = idgl->getAddressList();
863 if ( list.count() > 0 ) { 863 if ( list.count() > 0 ) {
864 KABC::Addressee::List listNew; 864 KABC::Addressee::List listNew;
865 KABC::Addressee::List listExisting; 865 KABC::Addressee::List listExisting;
866 KABC::Addressee::List::Iterator it; 866 KABC::Addressee::List::Iterator it;
867 KABC::AddressBook::Iterator iter; 867 KABC::AddressBook::Iterator iter;
868 for ( it = list.begin(); it != list.end(); ++it ) { 868 for ( it = list.begin(); it != list.end(); ++it ) {
869 if ( mAddressBook->findByUid((*it).uid() ).isEmpty()) 869 if ( mAddressBook->findByUid((*it).uid() ).isEmpty())
870 listNew.append( (*it) ); 870 listNew.append( (*it) );
871 else 871 else
872 listExisting.append( (*it) ); 872 listExisting.append( (*it) );
873 } 873 }
874 if ( listExisting.count() > 0 ) 874 if ( listExisting.count() > 0 )
875 KMessageBox::information( this, i18n("%1 contacts not added to addressbook\nbecause they were already in the addressbook!").arg( listExisting.count() )); 875 KMessageBox::information( this, i18n("%1 contacts not added to addressbook\nbecause they were already in the addressbook!").arg( listExisting.count() ));
876 if ( listNew.count() > 0 ) { 876 if ( listNew.count() > 0 ) {
877 pasteWithNewUid = false; 877 pasteWithNewUid = false;
878 pasteContacts( listNew ); 878 pasteContacts( listNew );
879 pasteWithNewUid = true; 879 pasteWithNewUid = true;
880 } 880 }
881 } 881 }
882 delete idgl; 882 delete idgl;
883#endif 883#endif
884} 884}
885 885
886void KABCore::importVCard( const QString &vCard, bool showPreview ) 886void KABCore::importVCard( const QString &vCard, bool showPreview )
887{ 887{
888 mXXPortManager->importVCard( vCard, showPreview ); 888 mXXPortManager->importVCard( vCard, showPreview );
889} 889}
890 890
891//US added a second method without defaultparameter 891//US added a second method without defaultparameter
892void KABCore::editContact2() { 892void KABCore::editContact2() {
893 editContact( QString::null ); 893 editContact( QString::null );
894} 894}
895 895
896void KABCore::editContact( const QString &uid ) 896void KABCore::editContact( const QString &uid )
897{ 897{
898 898
899 if ( mExtensionManager->isQuickEditVisible() ) 899 if ( mExtensionManager->isQuickEditVisible() )
900 return; 900 return;
901 901
902 // First, locate the contact entry 902 // First, locate the contact entry
903 QString localUID = uid; 903 QString localUID = uid;
904 if ( localUID.isNull() ) { 904 if ( localUID.isNull() ) {
905 QStringList uidList = mViewManager->selectedUids(); 905 QStringList uidList = mViewManager->selectedUids();
906 if ( uidList.count() > 0 ) 906 if ( uidList.count() > 0 )
907 localUID = *( uidList.at( 0 ) ); 907 localUID = *( uidList.at( 0 ) );
908 } 908 }
909 909
910 KABC::Addressee addr = mAddressBook->findByUid( localUID ); 910 KABC::Addressee addr = mAddressBook->findByUid( localUID );
911 if ( !addr.isEmpty() ) { 911 if ( !addr.isEmpty() ) {
912 mEditorDialog->setAddressee( addr ); 912 mEditorDialog->setAddressee( addr );
913 KApplication::execDialog ( mEditorDialog ); 913 KApplication::execDialog ( mEditorDialog );
914 } 914 }
915} 915}
916 916
917void KABCore::save() 917void KABCore::save()
918{ 918{
919 if ( !mModified ) 919 if ( !mModified )
920 return; 920 return;
921 QString text = i18n( "There was an error while attempting to save\n the " 921 QString text = i18n( "There was an error while attempting to save\n the "
922 "address book. Please check that some \nother application is " 922 "address book. Please check that some \nother application is "
923 "not using it. " ); 923 "not using it. " );
924 statusMessage(i18n("Saving addressbook ... ")); 924 statusMessage(i18n("Saving addressbook ... "));
925#ifndef KAB_EMBEDDED 925#ifndef KAB_EMBEDDED
926 KABC::StdAddressBook *b = dynamic_cast<KABC::StdAddressBook*>( mAddressBook ); 926 KABC::StdAddressBook *b = dynamic_cast<KABC::StdAddressBook*>( mAddressBook );
927 if ( !b || !b->save() ) { 927 if ( !b || !b->save() ) {
928 KMessageBox::error( this, text, i18n( "Unable to Save" ) ); 928 KMessageBox::error( this, text, i18n( "Unable to Save" ) );
929 } 929 }
930#else //KAB_EMBEDDED 930#else //KAB_EMBEDDED
931 KABC::StdAddressBook *b = (KABC::StdAddressBook*)( mAddressBook ); 931 KABC::StdAddressBook *b = (KABC::StdAddressBook*)( mAddressBook );
932 if ( !b || !b->save() ) { 932 if ( !b || !b->save() ) {
933 QMessageBox::critical( this, i18n( "Unable to Save" ), text, i18n("Ok")); 933 QMessageBox::critical( this, i18n( "Unable to Save" ), text, i18n("Ok"));
934 } 934 }
935#endif //KAB_EMBEDDED 935#endif //KAB_EMBEDDED
936 936
937 statusMessage(i18n("Addressbook saved!")); 937 statusMessage(i18n("Addressbook saved!"));
938 setModified( false ); 938 setModified( false );
939} 939}
940 940
941void KABCore::statusMessage(QString mess , int time ) 941void KABCore::statusMessage(QString mess , int time )
942{ 942{
943 //topLevelWidget()->setCaption( mess ); 943 //topLevelWidget()->setCaption( mess );
944 // pending setting timer to revome message 944 // pending setting timer to revome message
945} 945}
946void KABCore::undo() 946void KABCore::undo()
947{ 947{
948 UndoStack::instance()->undo(); 948 UndoStack::instance()->undo();
949 949
950 // Refresh the view 950 // Refresh the view
951 mViewManager->refreshView(); 951 mViewManager->refreshView();
952} 952}
953 953
954void KABCore::redo() 954void KABCore::redo()
955{ 955{
956 RedoStack::instance()->redo(); 956 RedoStack::instance()->redo();
957 957
958 // Refresh the view 958 // Refresh the view
959 mViewManager->refreshView(); 959 mViewManager->refreshView();
960} 960}
961 961
962void KABCore::setJumpButtonBarVisible( bool visible ) 962void KABCore::setJumpButtonBarVisible( bool visible )
963{ 963{
964 if ( visible ) 964 if ( visible )
965 mJumpButtonBar->show(); 965 mJumpButtonBar->show();
966 else 966 else
967 mJumpButtonBar->hide(); 967 mJumpButtonBar->hide();
968} 968}
969void KABCore::setDetailsToState() 969void KABCore::setDetailsToState()
970{ 970{
971 setDetailsVisible( mActionDetails->isChecked() ); 971 setDetailsVisible( mActionDetails->isChecked() );
972} 972}
973 973
974void KABCore::setDetailsVisible( bool visible ) 974void KABCore::setDetailsVisible( bool visible )
975{ 975{
976 if ( visible ) 976 if ( visible )
977 mDetails->show(); 977 mDetails->show();
978 else 978 else
979 mDetails->hide(); 979 mDetails->hide();
980} 980}
981 981
982void KABCore::extensionModified( const KABC::Addressee::List &list ) 982void KABCore::extensionModified( const KABC::Addressee::List &list )
983{ 983{
984 984
985 if ( list.count() != 0 ) { 985 if ( list.count() != 0 ) {
986 KABC::Addressee::List::ConstIterator it; 986 KABC::Addressee::List::ConstIterator it;
987 for ( it = list.begin(); it != list.end(); ++it ) 987 for ( it = list.begin(); it != list.end(); ++it )
988 mAddressBook->insertAddressee( *it ); 988 mAddressBook->insertAddressee( *it );
989 if ( list.count() > 1 ) 989 if ( list.count() > 1 )
990 setModified(); 990 setModified();
991 else 991 else
992 setModifiedWOrefresh(); 992 setModifiedWOrefresh();
993 } 993 }
994 if ( list.count() == 0 ) 994 if ( list.count() == 0 )
995 mViewManager->refreshView(); 995 mViewManager->refreshView();
996 else 996 else
997 mViewManager->refreshView( list[ 0 ].uid() ); 997 mViewManager->refreshView( list[ 0 ].uid() );
998 998
999 999
1000 1000
1001} 1001}
1002 1002
1003QString KABCore::getNameByPhone( const QString &phone ) 1003QString KABCore::getNameByPhone( const QString &phone )
1004{ 1004{
1005#ifndef KAB_EMBEDDED 1005#ifndef KAB_EMBEDDED
1006 QRegExp r( "[/*/-/ ]" ); 1006 QRegExp r( "[/*/-/ ]" );
1007 QString localPhone( phone ); 1007 QString localPhone( phone );
1008 1008
1009 bool found = false; 1009 bool found = false;
1010 QString ownerName = ""; 1010 QString ownerName = "";
1011 KABC::AddressBook::Iterator iter; 1011 KABC::AddressBook::Iterator iter;
1012 KABC::PhoneNumber::List::Iterator phoneIter; 1012 KABC::PhoneNumber::List::Iterator phoneIter;
1013 KABC::PhoneNumber::List phoneList; 1013 KABC::PhoneNumber::List phoneList;
1014 for ( iter = mAddressBook->begin(); !found && ( iter != mAddressBook->end() ); ++iter ) { 1014 for ( iter = mAddressBook->begin(); !found && ( iter != mAddressBook->end() ); ++iter ) {
1015 phoneList = (*iter).phoneNumbers(); 1015 phoneList = (*iter).phoneNumbers();
1016 for ( phoneIter = phoneList.begin(); !found && ( phoneIter != phoneList.end() ); 1016 for ( phoneIter = phoneList.begin(); !found && ( phoneIter != phoneList.end() );
1017 ++phoneIter) { 1017 ++phoneIter) {
1018 // Get rid of separator chars so just the numbers are compared. 1018 // Get rid of separator chars so just the numbers are compared.
1019 if ( (*phoneIter).number().replace( r, "" ) == localPhone.replace( r, "" ) ) { 1019 if ( (*phoneIter).number().replace( r, "" ) == localPhone.replace( r, "" ) ) {
1020 ownerName = (*iter).formattedName(); 1020 ownerName = (*iter).formattedName();
1021 found = true; 1021 found = true;
1022 } 1022 }
1023 } 1023 }
1024 } 1024 }
1025 1025
1026 return ownerName; 1026 return ownerName;
1027#else //KAB_EMBEDDED 1027#else //KAB_EMBEDDED
1028 qDebug("KABCore::getNameByPhone finsih method"); 1028 qDebug("KABCore::getNameByPhone finsih method");
1029 return ""; 1029 return "";
1030#endif //KAB_EMBEDDED 1030#endif //KAB_EMBEDDED
1031 1031
1032} 1032}
1033 1033
1034void KABCore::openConfigDialog() 1034void KABCore::openConfigDialog()
1035{ 1035{
1036 KCMultiDialog* ConfigureDialog = new KCMultiDialog( "PIM", this ,"kabconfigdialog", true ); 1036 KCMultiDialog* ConfigureDialog = new KCMultiDialog( "PIM", this ,"kabconfigdialog", true );
1037 KCMKabConfig* kabcfg = new KCMKabConfig( ConfigureDialog->getNewVBoxPage(i18n( "Addressbook")) , "KCMKabConfig" ); 1037 KCMKabConfig* kabcfg = new KCMKabConfig( ConfigureDialog->getNewVBoxPage(i18n( "Addressbook")) , "KCMKabConfig" );
1038 ConfigureDialog->addModule(kabcfg ); 1038 ConfigureDialog->addModule(kabcfg );
1039 connect( ConfigureDialog, SIGNAL( applyClicked() ), 1039 connect( ConfigureDialog, SIGNAL( applyClicked() ),
1040 this, SLOT( configurationChanged() ) ); 1040 this, SLOT( configurationChanged() ) );
1041 connect( ConfigureDialog, SIGNAL( okClicked() ), 1041 connect( ConfigureDialog, SIGNAL( okClicked() ),
1042 this, SLOT( configurationChanged() ) ); 1042 this, SLOT( configurationChanged() ) );
1043 saveSettings(); 1043 saveSettings();
1044 ConfigureDialog->showMaximized(); 1044 ConfigureDialog->showMaximized();
1045 if ( ConfigureDialog->exec() ) 1045 if ( ConfigureDialog->exec() )
1046 KMessageBox::information( this, i18n("If you configured \nExtensions,\nplease restart!\n") ); 1046 KMessageBox::information( this, i18n("If you configured \nExtensions,\nplease restart!\n") );
1047 delete ConfigureDialog; 1047 delete ConfigureDialog;
1048} 1048}
1049 1049
1050void KABCore::openLDAPDialog() 1050void KABCore::openLDAPDialog()
1051{ 1051{
1052#ifndef KAB_EMBEDDED 1052#ifndef KAB_EMBEDDED
1053 if ( !mLdapSearchDialog ) { 1053 if ( !mLdapSearchDialog ) {
1054 mLdapSearchDialog = new LDAPSearchDialog( mAddressBook, this ); 1054 mLdapSearchDialog = new LDAPSearchDialog( mAddressBook, this );
1055 connect( mLdapSearchDialog, SIGNAL( addresseesAdded() ), mViewManager, 1055 connect( mLdapSearchDialog, SIGNAL( addresseesAdded() ), mViewManager,
1056 SLOT( refreshView() ) ); 1056 SLOT( refreshView() ) );
1057 connect( mLdapSearchDialog, SIGNAL( addresseesAdded() ), this, 1057 connect( mLdapSearchDialog, SIGNAL( addresseesAdded() ), this,
1058 SLOT( setModified() ) ); 1058 SLOT( setModified() ) );
1059 } else 1059 } else
1060 mLdapSearchDialog->restoreSettings(); 1060 mLdapSearchDialog->restoreSettings();
1061 1061
1062 if ( mLdapSearchDialog->isOK() ) 1062 if ( mLdapSearchDialog->isOK() )
1063 mLdapSearchDialog->exec(); 1063 mLdapSearchDialog->exec();
1064#else //KAB_EMBEDDED 1064#else //KAB_EMBEDDED
1065 qDebug("KABCore::openLDAPDialog() finsih method"); 1065 qDebug("KABCore::openLDAPDialog() finsih method");
1066#endif //KAB_EMBEDDED 1066#endif //KAB_EMBEDDED
1067} 1067}
1068 1068
1069void KABCore::print() 1069void KABCore::print()
1070{ 1070{
1071#ifndef KAB_EMBEDDED 1071#ifndef KAB_EMBEDDED
1072 KPrinter printer; 1072 KPrinter printer;
1073 if ( !printer.setup( this ) ) 1073 if ( !printer.setup( this ) )
1074 return; 1074 return;
1075 1075
1076 KABPrinting::PrintingWizard wizard( &printer, mAddressBook, 1076 KABPrinting::PrintingWizard wizard( &printer, mAddressBook,
1077 mViewManager->selectedUids(), this ); 1077 mViewManager->selectedUids(), this );
1078 1078
1079 wizard.exec(); 1079 wizard.exec();
1080#else //KAB_EMBEDDED 1080#else //KAB_EMBEDDED
1081 qDebug("KABCore::print() finsih method"); 1081 qDebug("KABCore::print() finsih method");
1082#endif //KAB_EMBEDDED 1082#endif //KAB_EMBEDDED
1083 1083
1084} 1084}
1085 1085
1086 1086
1087void KABCore::addGUIClient( KXMLGUIClient *client ) 1087void KABCore::addGUIClient( KXMLGUIClient *client )
1088{ 1088{
1089 if ( mGUIClient ) 1089 if ( mGUIClient )
1090 mGUIClient->insertChildClient( client ); 1090 mGUIClient->insertChildClient( client );
1091 else 1091 else
1092 KMessageBox::error( this, "no KXMLGUICLient"); 1092 KMessageBox::error( this, "no KXMLGUICLient");
1093} 1093}
1094 1094
1095 1095
1096void KABCore::configurationChanged() 1096void KABCore::configurationChanged()
1097{ 1097{
1098 mExtensionManager->reconfigure(); 1098 mExtensionManager->reconfigure();
1099} 1099}
1100 1100
1101void KABCore::addressBookChanged() 1101void KABCore::addressBookChanged()
1102{ 1102{
1103/*US 1103/*US
1104 QDictIterator<AddresseeEditorDialog> it( mEditorDict ); 1104 QDictIterator<AddresseeEditorDialog> it( mEditorDict );
1105 while ( it.current() ) { 1105 while ( it.current() ) {
1106 if ( it.current()->dirty() ) { 1106 if ( it.current()->dirty() ) {
1107 QString text = i18n( "Data has been changed externally. Unsaved " 1107 QString text = i18n( "Data has been changed externally. Unsaved "
1108 "changes will be lost." ); 1108 "changes will be lost." );
1109 KMessageBox::information( this, text ); 1109 KMessageBox::information( this, text );
1110 } 1110 }
1111 it.current()->setAddressee( mAddressBook->findByUid( it.currentKey() ) ); 1111 it.current()->setAddressee( mAddressBook->findByUid( it.currentKey() ) );
1112 ++it; 1112 ++it;
1113 } 1113 }
1114*/ 1114*/
1115 if (mEditorDialog) 1115 if (mEditorDialog)
1116 { 1116 {
1117 if (mEditorDialog->dirty()) 1117 if (mEditorDialog->dirty())
1118 { 1118 {
1119 QString text = i18n( "Data has been changed externally. Unsaved " 1119 QString text = i18n( "Data has been changed externally. Unsaved "
1120 "changes will be lost." ); 1120 "changes will be lost." );
1121 KMessageBox::information( this, text ); 1121 KMessageBox::information( this, text );
1122 } 1122 }
1123 QString currentuid = mEditorDialog->addressee().uid(); 1123 QString currentuid = mEditorDialog->addressee().uid();
1124 mEditorDialog->setAddressee( mAddressBook->findByUid( currentuid ) ); 1124 mEditorDialog->setAddressee( mAddressBook->findByUid( currentuid ) );
1125 } 1125 }
1126 mViewManager->refreshView(); 1126 mViewManager->refreshView();
1127// mDetails->refreshView();
1127 1128
1128 1129
1129} 1130}
1130 1131
1131AddresseeEditorDialog *KABCore::createAddresseeEditorDialog( QWidget *parent, 1132AddresseeEditorDialog *KABCore::createAddresseeEditorDialog( QWidget *parent,
1132 const char *name ) 1133 const char *name )
1133{ 1134{
1134 1135
1135 if ( mEditorDialog == 0 ) { 1136 if ( mEditorDialog == 0 ) {
1136 mEditorDialog = new AddresseeEditorDialog( this, parent, 1137 mEditorDialog = new AddresseeEditorDialog( this, parent,
1137 name ? name : "editorDialog" ); 1138 name ? name : "editorDialog" );
1138 1139
1139 1140
1140 connect( mEditorDialog, SIGNAL( contactModified( const KABC::Addressee& ) ), 1141 connect( mEditorDialog, SIGNAL( contactModified( const KABC::Addressee& ) ),
1141 SLOT( contactModified( const KABC::Addressee& ) ) ); 1142 SLOT( contactModified( const KABC::Addressee& ) ) );
1142 //connect( mEditorDialog, SIGNAL( editorDestroyed( const QString& ) ), 1143 //connect( mEditorDialog, SIGNAL( editorDestroyed( const QString& ) ),
1143 // SLOT( slotEditorDestroyed( const QString& ) ) ); 1144 // SLOT( slotEditorDestroyed( const QString& ) ) );
1144 } 1145 }
1145 1146
1146 return mEditorDialog; 1147 return mEditorDialog;
1147} 1148}
1148 1149
1149void KABCore::slotEditorDestroyed( const QString &uid ) 1150void KABCore::slotEditorDestroyed( const QString &uid )
1150{ 1151{
1151 //mEditorDict.remove( uid ); 1152 //mEditorDict.remove( uid );
1152} 1153}
1153 1154
1154void KABCore::initGUI() 1155void KABCore::initGUI()
1155{ 1156{
1156#ifndef KAB_EMBEDDED 1157#ifndef KAB_EMBEDDED
1157 QHBoxLayout *topLayout = new QHBoxLayout( this ); 1158 QHBoxLayout *topLayout = new QHBoxLayout( this );
1158 topLayout->setSpacing( KDialogBase::spacingHint() ); 1159 topLayout->setSpacing( KDialogBase::spacingHint() );
1159 1160
1160 mExtensionBarSplitter = new QSplitter( this ); 1161 mExtensionBarSplitter = new QSplitter( this );
1161 mExtensionBarSplitter->setOrientation( Qt::Vertical ); 1162 mExtensionBarSplitter->setOrientation( Qt::Vertical );
1162 1163
1163 mDetailsSplitter = new QSplitter( mExtensionBarSplitter ); 1164 mDetailsSplitter = new QSplitter( mExtensionBarSplitter );
1164 1165
1165 QVBox *viewSpace = new QVBox( mDetailsSplitter ); 1166 QVBox *viewSpace = new QVBox( mDetailsSplitter );
1166 mIncSearchWidget = new IncSearchWidget( viewSpace ); 1167 mIncSearchWidget = new IncSearchWidget( viewSpace );
1167 connect( mIncSearchWidget, SIGNAL( doSearch( const QString& ) ), 1168 connect( mIncSearchWidget, SIGNAL( doSearch( const QString& ) ),
1168 SLOT( incrementalSearch( const QString& ) ) ); 1169 SLOT( incrementalSearch( const QString& ) ) );
1169 1170
1170 mViewManager = new ViewManager( this, viewSpace ); 1171 mViewManager = new ViewManager( this, viewSpace );
1171 viewSpace->setStretchFactor( mViewManager, 1 ); 1172 viewSpace->setStretchFactor( mViewManager, 1 );
1172 1173
1173 mDetails = new ViewContainer( mDetailsSplitter ); 1174 mDetails = new ViewContainer( mDetailsSplitter );
1174 1175
1175 mJumpButtonBar = new JumpButtonBar( this, this ); 1176 mJumpButtonBar = new JumpButtonBar( this, this );
1176 1177
1177 mExtensionManager = new ExtensionManager( this, mExtensionBarSplitter ); 1178 mExtensionManager = new ExtensionManager( this, mExtensionBarSplitter );
1178 1179
1179 topLayout->addWidget( mExtensionBarSplitter ); 1180 topLayout->addWidget( mExtensionBarSplitter );
1180 topLayout->setStretchFactor( mExtensionBarSplitter, 100 ); 1181 topLayout->setStretchFactor( mExtensionBarSplitter, 100 );
1181 topLayout->addWidget( mJumpButtonBar ); 1182 topLayout->addWidget( mJumpButtonBar );
1182 topLayout->setStretchFactor( mJumpButtonBar, 1 ); 1183 topLayout->setStretchFactor( mJumpButtonBar, 1 );
1183 1184
1184 mXXPortManager = new XXPortManager( this, this ); 1185 mXXPortManager = new XXPortManager( this, this );
1185 1186
1186#else //KAB_EMBEDDED 1187#else //KAB_EMBEDDED
1187 //US initialize viewMenu before settingup viewmanager. 1188 //US initialize viewMenu before settingup viewmanager.
1188 // Viewmanager needs this menu to plugin submenues. 1189 // Viewmanager needs this menu to plugin submenues.
1189 viewMenu = new QPopupMenu( this ); 1190 viewMenu = new QPopupMenu( this );
1190 settingsMenu = new QPopupMenu( this ); 1191 settingsMenu = new QPopupMenu( this );
1191 //filterMenu = new QPopupMenu( this ); 1192 //filterMenu = new QPopupMenu( this );
1192 ImportMenu = new QPopupMenu( this ); 1193 ImportMenu = new QPopupMenu( this );
1193 ExportMenu = new QPopupMenu( this ); 1194 ExportMenu = new QPopupMenu( this );
1194 1195
1195 changeMenu= new QPopupMenu( this ); 1196 changeMenu= new QPopupMenu( this );
1196 1197
1197//US since we have no splitter for the embedded system, setup 1198//US since we have no splitter for the embedded system, setup
1198// a layout with two frames. One left and one right. 1199// a layout with two frames. One left and one right.
1199 1200
1200 QBoxLayout *topLayout; 1201 QBoxLayout *topLayout;
1201 1202
1202 // = new QHBoxLayout( this ); 1203 // = new QHBoxLayout( this );
1203// QBoxLayout *topLayout = (QBoxLayout*)layout(); 1204// QBoxLayout *topLayout = (QBoxLayout*)layout();
1204 1205
1205// QWidget *mainBox = new QWidget( this ); 1206// QWidget *mainBox = new QWidget( this );
1206// QBoxLayout * mainBoxLayout = new QHBoxLayout(mainBox); 1207// QBoxLayout * mainBoxLayout = new QHBoxLayout(mainBox);
1207 1208
1208#ifdef DESKTOP_VERSION 1209#ifdef DESKTOP_VERSION
1209 topLayout = new QHBoxLayout( this ); 1210 topLayout = new QHBoxLayout( this );
1210 1211
1211 1212
1212 mMiniSplitter = new KDGanttMinimizeSplitter( Qt::Horizontal, this); 1213 mMiniSplitter = new KDGanttMinimizeSplitter( Qt::Horizontal, this);
1213 mMiniSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Right ); 1214 mMiniSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Right );
1214 1215
1215 topLayout->addWidget(mMiniSplitter ); 1216 topLayout->addWidget(mMiniSplitter );
1216 1217
1217 mExtensionBarSplitter = new KDGanttMinimizeSplitter( Qt::Vertical,mMiniSplitter ); 1218 mExtensionBarSplitter = new KDGanttMinimizeSplitter( Qt::Vertical,mMiniSplitter );
1218 mExtensionBarSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Down ); 1219 mExtensionBarSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Down );
1219 mViewManager = new ViewManager( this, mExtensionBarSplitter ); 1220 mViewManager = new ViewManager( this, mExtensionBarSplitter );
1220 mDetails = new ViewContainer( mMiniSplitter ); 1221 mDetails = new ViewContainer( mMiniSplitter );
1221 mExtensionManager = new ExtensionManager( this, mExtensionBarSplitter ); 1222 mExtensionManager = new ExtensionManager( this, mExtensionBarSplitter );
1222#else 1223#else
1223 if ( QApplication::desktop()->width() > 480 ) { 1224 if ( QApplication::desktop()->width() > 480 ) {
1224 topLayout = new QHBoxLayout( this ); 1225 topLayout = new QHBoxLayout( this );
1225 mMiniSplitter = new KDGanttMinimizeSplitter( Qt::Horizontal, this); 1226 mMiniSplitter = new KDGanttMinimizeSplitter( Qt::Horizontal, this);
1226 mMiniSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Right ); 1227 mMiniSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Right );
1227 } else { 1228 } else {
1228 1229
1229 topLayout = new QHBoxLayout( this ); 1230 topLayout = new QHBoxLayout( this );
1230 mMiniSplitter = new KDGanttMinimizeSplitter( Qt::Vertical, this); 1231 mMiniSplitter = new KDGanttMinimizeSplitter( Qt::Vertical, this);
1231 mMiniSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Down ); 1232 mMiniSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Down );
1232 } 1233 }
1233 1234
1234 topLayout->addWidget(mMiniSplitter ); 1235 topLayout->addWidget(mMiniSplitter );
1235 mViewManager = new ViewManager( this, mMiniSplitter ); 1236 mViewManager = new ViewManager( this, mMiniSplitter );
1236 mDetails = new ViewContainer( mMiniSplitter ); 1237 mDetails = new ViewContainer( mMiniSplitter );
1237 1238
1238 1239
1239 mExtensionManager = new ExtensionManager( this, mMiniSplitter ); 1240 mExtensionManager = new ExtensionManager( this, mMiniSplitter );
1240#endif 1241#endif
1241 //eh->hide(); 1242 //eh->hide();
1242 // topLayout->addWidget(mExtensionManager ); 1243 // topLayout->addWidget(mExtensionManager );
1243 1244
1244 1245
1245/*US 1246/*US
1246#ifndef KAB_NOSPLITTER 1247#ifndef KAB_NOSPLITTER
1247 QHBoxLayout *topLayout = new QHBoxLayout( this ); 1248 QHBoxLayout *topLayout = new QHBoxLayout( this );
1248//US topLayout->setSpacing( KDialogBase::spacingHint() ); 1249//US topLayout->setSpacing( KDialogBase::spacingHint() );
1249 topLayout->setSpacing( 10 ); 1250 topLayout->setSpacing( 10 );
1250 1251
1251 mDetailsSplitter = new QSplitter( this ); 1252 mDetailsSplitter = new QSplitter( this );
1252 1253
1253 QVBox *viewSpace = new QVBox( mDetailsSplitter ); 1254 QVBox *viewSpace = new QVBox( mDetailsSplitter );
1254 1255
1255 mViewManager = new ViewManager( this, viewSpace ); 1256 mViewManager = new ViewManager( this, viewSpace );
1256 viewSpace->setStretchFactor( mViewManager, 1 ); 1257 viewSpace->setStretchFactor( mViewManager, 1 );
1257 1258
1258 mDetails = new ViewContainer( mDetailsSplitter ); 1259 mDetails = new ViewContainer( mDetailsSplitter );
1259 1260
1260 topLayout->addWidget( mDetailsSplitter ); 1261 topLayout->addWidget( mDetailsSplitter );
1261 topLayout->setStretchFactor( mDetailsSplitter, 100 ); 1262 topLayout->setStretchFactor( mDetailsSplitter, 100 );
1262#else //KAB_NOSPLITTER 1263#else //KAB_NOSPLITTER
1263 QHBoxLayout *topLayout = new QHBoxLayout( this ); 1264 QHBoxLayout *topLayout = new QHBoxLayout( this );
1264//US topLayout->setSpacing( KDialogBase::spacingHint() ); 1265//US topLayout->setSpacing( KDialogBase::spacingHint() );
1265 topLayout->setSpacing( 10 ); 1266 topLayout->setSpacing( 10 );
1266 1267
1267// mDetailsSplitter = new QSplitter( this ); 1268// mDetailsSplitter = new QSplitter( this );
1268 1269
1269 QVBox *viewSpace = new QVBox( this ); 1270 QVBox *viewSpace = new QVBox( this );
1270 1271
1271 mViewManager = new ViewManager( this, viewSpace ); 1272 mViewManager = new ViewManager( this, viewSpace );
1272 viewSpace->setStretchFactor( mViewManager, 1 ); 1273 viewSpace->setStretchFactor( mViewManager, 1 );
1273 1274
1274 mDetails = new ViewContainer( this ); 1275 mDetails = new ViewContainer( this );
1275 1276
1276 topLayout->addWidget( viewSpace ); 1277 topLayout->addWidget( viewSpace );
1277// topLayout->setStretchFactor( mDetailsSplitter, 100 ); 1278// topLayout->setStretchFactor( mDetailsSplitter, 100 );
1278 topLayout->addWidget( mDetails ); 1279 topLayout->addWidget( mDetails );
1279#endif //KAB_NOSPLITTER 1280#endif //KAB_NOSPLITTER
1280*/ 1281*/
1281 1282
1282 1283
1283#endif //KAB_EMBEDDED 1284#endif //KAB_EMBEDDED
1284 initActions(); 1285 initActions();
1285 1286
1286#ifdef KAB_EMBEDDED 1287#ifdef KAB_EMBEDDED
1287 addActionsManually(); 1288 addActionsManually();
1288 //US make sure the export and import menues are initialized before creating the xxPortManager. 1289 //US make sure the export and import menues are initialized before creating the xxPortManager.
1289 mXXPortManager = new XXPortManager( this, this ); 1290 mXXPortManager = new XXPortManager( this, this );
1290 1291
1291 // LR mIncSearchWidget = new IncSearchWidget( mMainWindow->getIconToolBar() ); 1292 // LR mIncSearchWidget = new IncSearchWidget( mMainWindow->getIconToolBar() );
1292 //mMainWindow->toolBar()->insertWidget(-1, 4, mIncSearchWidget); 1293 //mMainWindow->toolBar()->insertWidget(-1, 4, mIncSearchWidget);
1293 // mActionQuit->plug ( mMainWindow->toolBar()); 1294 // mActionQuit->plug ( mMainWindow->toolBar());
1294 //mIncSearchWidget = new IncSearchWidget( mMainWindow->toolBar() ); 1295 //mIncSearchWidget = new IncSearchWidget( mMainWindow->toolBar() );
1295 //mMainWindow->toolBar()->insertWidget(-1, 0, mIncSearchWidget); 1296 //mMainWindow->toolBar()->insertWidget(-1, 0, mIncSearchWidget);
1296 // mIncSearchWidget->hide(); 1297 // mIncSearchWidget->hide();
1297 connect( mIncSearchWidget, SIGNAL( doSearch( const QString& ) ), 1298 connect( mIncSearchWidget, SIGNAL( doSearch( const QString& ) ),
1298 SLOT( incrementalSearch( const QString& ) ) ); 1299 SLOT( incrementalSearch( const QString& ) ) );
1299 1300
1300 1301
1301 mJumpButtonBar = new JumpButtonBar( this, this ); 1302 mJumpButtonBar = new JumpButtonBar( this, this );
1302 1303
1303 topLayout->addWidget( mJumpButtonBar ); 1304 topLayout->addWidget( mJumpButtonBar );
1304//US topLayout->setStretchFactor( mJumpButtonBar, 10 ); 1305//US topLayout->setStretchFactor( mJumpButtonBar, 10 );
1305 1306
1306// mMainWindow->getIconToolBar()->raise(); 1307// mMainWindow->getIconToolBar()->raise();
1307 1308
1308#endif //KAB_EMBEDDED 1309#endif //KAB_EMBEDDED
1309 1310
1310} 1311}
1311void KABCore::initActions() 1312void KABCore::initActions()
1312{ 1313{
1313//US qDebug("KABCore::initActions(): mIsPart %i", mIsPart); 1314//US qDebug("KABCore::initActions(): mIsPart %i", mIsPart);
1314 1315
1315#ifndef KAB_EMBEDDED 1316#ifndef KAB_EMBEDDED
1316 connect( QApplication::clipboard(), SIGNAL( dataChanged() ), 1317 connect( QApplication::clipboard(), SIGNAL( dataChanged() ),
1317 SLOT( clipboardDataChanged() ) ); 1318 SLOT( clipboardDataChanged() ) );
1318#endif //KAB_EMBEDDED 1319#endif //KAB_EMBEDDED
1319 1320
1320 // file menu 1321 // file menu
1321 if ( mIsPart ) { 1322 if ( mIsPart ) {
1322 mActionMail = new KAction( i18n( "&Mail" ), "mail_generic", 0, this, 1323 mActionMail = new KAction( i18n( "&Mail" ), "mail_generic", 0, this,
1323 SLOT( sendMail() ), actionCollection(), 1324 SLOT( sendMail() ), actionCollection(),
1324 "kaddressbook_mail" ); 1325 "kaddressbook_mail" );
1325 mActionPrint = new KAction( i18n( "&Print" ), "fileprint", CTRL + Key_P, this, 1326 mActionPrint = new KAction( i18n( "&Print" ), "fileprint", CTRL + Key_P, this,
1326 SLOT( print() ), actionCollection(), "kaddressbook_print" ); 1327 SLOT( print() ), actionCollection(), "kaddressbook_print" );
1327 1328
1328 } else { 1329 } else {
1329 mActionMail = KStdAction::mail( this, SLOT( sendMail() ), actionCollection() ); 1330 mActionMail = KStdAction::mail( this, SLOT( sendMail() ), actionCollection() );
1330 mActionPrint = KStdAction::print( this, SLOT( print() ), actionCollection() ); 1331 mActionPrint = KStdAction::print( this, SLOT( print() ), actionCollection() );
1331 } 1332 }
1332 1333
1333 mActionSave = new KAction( i18n( "&Save" ), "filesave", CTRL+Key_S, this, 1334 mActionSave = new KAction( i18n( "&Save" ), "filesave", CTRL+Key_S, this,
1334 SLOT( save() ), actionCollection(), "file_sync" ); 1335 SLOT( save() ), actionCollection(), "file_sync" );
1335 1336
1336 mActionNewContact = new KAction( i18n( "&New Contact..." ), "filenew", CTRL+Key_N, this, 1337 mActionNewContact = new KAction( i18n( "&New Contact..." ), "filenew", CTRL+Key_N, this,
1337 SLOT( newContact() ), actionCollection(), "file_new_contact" ); 1338 SLOT( newContact() ), actionCollection(), "file_new_contact" );
1338 1339
1339 mActionMailVCard = new KAction(i18n("Mail &vCard..."), "mail_post_to", 0, 1340 mActionMailVCard = new KAction(i18n("Mail &vCard..."), "mail_post_to", 0,
1340 this, SLOT( mailVCard() ), 1341 this, SLOT( mailVCard() ),
1341 actionCollection(), "file_mail_vcard"); 1342 actionCollection(), "file_mail_vcard");
1342 1343
1343 mActionEditAddressee = new KAction( i18n( "&Edit Contact..." ), "edit", 0, 1344 mActionEditAddressee = new KAction( i18n( "&Edit Contact..." ), "edit", 0,
1344 this, SLOT( editContact2() ), 1345 this, SLOT( editContact2() ),
1345 actionCollection(), "file_properties" ); 1346 actionCollection(), "file_properties" );
1346 1347
1347#ifdef KAB_EMBEDDED 1348#ifdef KAB_EMBEDDED
1348 // mActionQuit = KStdAction::quit( mMainWindow, SLOT( exit() ), actionCollection() ); 1349 // mActionQuit = KStdAction::quit( mMainWindow, SLOT( exit() ), actionCollection() );
1349 mActionQuit = new KAction( i18n( "&Exit" ), "exit", 0, 1350 mActionQuit = new KAction( i18n( "&Exit" ), "exit", 0,
1350 mMainWindow, SLOT( exit() ), 1351 mMainWindow, SLOT( exit() ),
1351 actionCollection(), "quit" ); 1352 actionCollection(), "quit" );
1352#endif //KAB_EMBEDDED 1353#endif //KAB_EMBEDDED
1353 1354
1354 // edit menu 1355 // edit menu
1355 if ( mIsPart ) { 1356 if ( mIsPart ) {
1356 mActionCopy = new KAction( i18n( "&Copy" ), "editcopy", CTRL + Key_C, this, 1357 mActionCopy = new KAction( i18n( "&Copy" ), "editcopy", CTRL + Key_C, this,
1357 SLOT( copyContacts() ), actionCollection(), 1358 SLOT( copyContacts() ), actionCollection(),
1358 "kaddressbook_copy" ); 1359 "kaddressbook_copy" );
1359 mActionCut = new KAction( i18n( "Cu&t" ), "editcut", CTRL + Key_X, this, 1360 mActionCut = new KAction( i18n( "Cu&t" ), "editcut", CTRL + Key_X, this,
1360 SLOT( cutContacts() ), actionCollection(), 1361 SLOT( cutContacts() ), actionCollection(),
1361 "kaddressbook_cut" ); 1362 "kaddressbook_cut" );
1362 mActionPaste = new KAction( i18n( "&Paste" ), "editpaste", CTRL + Key_V, this, 1363 mActionPaste = new KAction( i18n( "&Paste" ), "editpaste", CTRL + Key_V, this,
1363 SLOT( pasteContacts() ), actionCollection(), 1364 SLOT( pasteContacts() ), actionCollection(),
1364 "kaddressbook_paste" ); 1365 "kaddressbook_paste" );
1365 mActionSelectAll = new KAction( i18n( "Select &All" ), CTRL + Key_A, this, 1366 mActionSelectAll = new KAction( i18n( "Select &All" ), CTRL + Key_A, this,
1366 SLOT( selectAllContacts() ), actionCollection(), 1367 SLOT( selectAllContacts() ), actionCollection(),
1367 "kaddressbook_select_all" ); 1368 "kaddressbook_select_all" );
1368 mActionUndo = new KAction( i18n( "&Undo" ), "undo", CTRL + Key_Z, this, 1369 mActionUndo = new KAction( i18n( "&Undo" ), "undo", CTRL + Key_Z, this,
1369 SLOT( undo() ), actionCollection(), 1370 SLOT( undo() ), actionCollection(),
1370 "kaddressbook_undo" ); 1371 "kaddressbook_undo" );
1371 mActionRedo = new KAction( i18n( "Re&do" ), "redo", CTRL + SHIFT + Key_Z, 1372 mActionRedo = new KAction( i18n( "Re&do" ), "redo", CTRL + SHIFT + Key_Z,
1372 this, SLOT( redo() ), actionCollection(), 1373 this, SLOT( redo() ), actionCollection(),
1373 "kaddressbook_redo" ); 1374 "kaddressbook_redo" );
1374 } else { 1375 } else {
1375 mActionCopy = KStdAction::copy( this, SLOT( copyContacts() ), actionCollection() ); 1376 mActionCopy = KStdAction::copy( this, SLOT( copyContacts() ), actionCollection() );
1376 mActionCut = KStdAction::cut( this, SLOT( cutContacts() ), actionCollection() ); 1377 mActionCut = KStdAction::cut( this, SLOT( cutContacts() ), actionCollection() );
1377 mActionPaste = KStdAction::paste( this, SLOT( pasteContacts() ), actionCollection() ); 1378 mActionPaste = KStdAction::paste( this, SLOT( pasteContacts() ), actionCollection() );
1378 mActionSelectAll = KStdAction::selectAll( this, SLOT( selectAllContacts() ), actionCollection() ); 1379 mActionSelectAll = KStdAction::selectAll( this, SLOT( selectAllContacts() ), actionCollection() );
1379 mActionUndo = KStdAction::undo( this, SLOT( undo() ), actionCollection() ); 1380 mActionUndo = KStdAction::undo( this, SLOT( undo() ), actionCollection() );
1380 mActionRedo = KStdAction::redo( this, SLOT( redo() ), actionCollection() ); 1381 mActionRedo = KStdAction::redo( this, SLOT( redo() ), actionCollection() );
1381 } 1382 }
1382 1383
1383 mActionDelete = new KAction( i18n( "&Delete Contact" ), "editdelete", 1384 mActionDelete = new KAction( i18n( "&Delete Contact" ), "editdelete",
1384 Key_Delete, this, SLOT( deleteContacts() ), 1385 Key_Delete, this, SLOT( deleteContacts() ),
1385 actionCollection(), "edit_delete" ); 1386 actionCollection(), "edit_delete" );
1386 1387
1387 mActionUndo->setEnabled( false ); 1388 mActionUndo->setEnabled( false );
1388 mActionRedo->setEnabled( false ); 1389 mActionRedo->setEnabled( false );
1389 1390
1390 // settings menu 1391 // settings menu
1391#ifdef KAB_EMBEDDED 1392#ifdef KAB_EMBEDDED
1392//US special menuentry to configure the addressbook resources. On KDE 1393//US special menuentry to configure the addressbook resources. On KDE
1393// you do that through the control center !!! 1394// you do that through the control center !!!
1394 mActionConfigResources = new KAction( i18n( "Configure &Resources..." ), "configure_resources", 0, this, 1395 mActionConfigResources = new KAction( i18n( "Configure &Resources..." ), "configure_resources", 0, this,
1395 SLOT( configureResources() ), actionCollection(), 1396 SLOT( configureResources() ), actionCollection(),
1396 "kaddressbook_configure_resources" ); 1397 "kaddressbook_configure_resources" );
1397#endif //KAB_EMBEDDED 1398#endif //KAB_EMBEDDED
1398 1399
1399 if ( mIsPart ) { 1400 if ( mIsPart ) {
1400 mActionConfigKAddressbook = new KAction( i18n( "&Configure KAddressBook..." ), "configure", 0, this, 1401 mActionConfigKAddressbook = new KAction( i18n( "&Configure KAddressBook..." ), "configure", 0, this,
1401 SLOT( openConfigDialog() ), actionCollection(), 1402 SLOT( openConfigDialog() ), actionCollection(),
1402 "kaddressbook_configure" ); 1403 "kaddressbook_configure" );
1403 1404
1404 mActionConfigShortcuts = new KAction( i18n( "Configure S&hortcuts..." ), "configure_shortcuts", 0, 1405 mActionConfigShortcuts = new KAction( i18n( "Configure S&hortcuts..." ), "configure_shortcuts", 0,
1405 this, SLOT( configureKeyBindings() ), actionCollection(), 1406 this, SLOT( configureKeyBindings() ), actionCollection(),
1406 "kaddressbook_configure_shortcuts" ); 1407 "kaddressbook_configure_shortcuts" );
1407#ifdef KAB_EMBEDDED 1408#ifdef KAB_EMBEDDED
1408 mActionConfigureToolbars = KStdAction::configureToolbars( this, SLOT( mMainWindow->configureToolbars() ), actionCollection() ); 1409 mActionConfigureToolbars = KStdAction::configureToolbars( this, SLOT( mMainWindow->configureToolbars() ), actionCollection() );
1409 mActionConfigureToolbars->setEnabled( false ); 1410 mActionConfigureToolbars->setEnabled( false );
1410#endif //KAB_EMBEDDED 1411#endif //KAB_EMBEDDED
1411 1412
1412 } else { 1413 } else {
1413 mActionConfigKAddressbook = KStdAction::preferences( this, SLOT( openConfigDialog() ), actionCollection() ); 1414 mActionConfigKAddressbook = KStdAction::preferences( this, SLOT( openConfigDialog() ), actionCollection() );
1414 1415
1415 mActionKeyBindings = KStdAction::keyBindings( this, SLOT( configureKeyBindings() ), actionCollection() ); 1416 mActionKeyBindings = KStdAction::keyBindings( this, SLOT( configureKeyBindings() ), actionCollection() );
1416 } 1417 }
1417 1418
1418 mActionJumpBar = new KToggleAction( i18n( "Show Jump Bar" ), 0, 0, 1419 mActionJumpBar = new KToggleAction( i18n( "Show Jump Bar" ), 0, 0,
1419 actionCollection(), "options_show_jump_bar" ); 1420 actionCollection(), "options_show_jump_bar" );
1420 connect( mActionJumpBar, SIGNAL( toggled( bool ) ), SLOT( setJumpButtonBarVisible( bool ) ) ); 1421 connect( mActionJumpBar, SIGNAL( toggled( bool ) ), SLOT( setJumpButtonBarVisible( bool ) ) );
1421 1422
1422 mActionDetails = new KToggleAction( i18n( "Show Details" ), 0, 0, 1423 mActionDetails = new KToggleAction( i18n( "Show Details" ), 0, 0,
1423 actionCollection(), "options_show_details" ); 1424 actionCollection(), "options_show_details" );
1424 connect( mActionDetails, SIGNAL( toggled( bool ) ), SLOT( setDetailsVisible( bool ) ) ); 1425 connect( mActionDetails, SIGNAL( toggled( bool ) ), SLOT( setDetailsVisible( bool ) ) );
1425 1426
1426 // misc 1427 // misc
1427 // only enable LDAP lookup if we can handle the protocol 1428 // only enable LDAP lookup if we can handle the protocol
1428#ifndef KAB_EMBEDDED 1429#ifndef KAB_EMBEDDED
1429 if ( KProtocolInfo::isKnownProtocol( KURL( "ldap://localhost" ) ) ) { 1430 if ( KProtocolInfo::isKnownProtocol( KURL( "ldap://localhost" ) ) ) {
1430 new KAction( i18n( "&Lookup Addresses in Directory" ), "find", 0, 1431 new KAction( i18n( "&Lookup Addresses in Directory" ), "find", 0,
1431 this, SLOT( openLDAPDialog() ), actionCollection(), 1432 this, SLOT( openLDAPDialog() ), actionCollection(),
1432 "ldap_lookup" ); 1433 "ldap_lookup" );
1433 } 1434 }
1434#else //KAB_EMBEDDED 1435#else //KAB_EMBEDDED
1435 //qDebug("KABCore::initActions() LDAP has to be implemented"); 1436 //qDebug("KABCore::initActions() LDAP has to be implemented");
1436#endif //KAB_EMBEDDED 1437#endif //KAB_EMBEDDED
1437 1438
1438 1439
1439 mActionWhoAmI = new KAction( i18n( "Set Who Am I" ), "personal", 0, this, 1440 mActionWhoAmI = new KAction( i18n( "Set Who Am I" ), "personal", 0, this,
1440 SLOT( setWhoAmI() ), actionCollection(), 1441 SLOT( setWhoAmI() ), actionCollection(),
1441 "set_personal" ); 1442 "set_personal" );
1442 1443
1443 mActionCategories = new KAction( i18n( "Set Categories" ), 0, this, 1444 mActionCategories = new KAction( i18n( "Set Categories" ), 0, this,
1444 SLOT( setCategories() ), actionCollection(), 1445 SLOT( setCategories() ), actionCollection(),
1445 "edit_set_categories" ); 1446 "edit_set_categories" );
1446 1447
1447 mActionRemoveVoice = new KAction( i18n( "Remove \"voice\"..." ), 0, this, 1448 mActionRemoveVoice = new KAction( i18n( "Remove \"voice\"..." ), 0, this,
1448 SLOT( removeVoice() ), actionCollection(), 1449 SLOT( removeVoice() ), actionCollection(),
1449 "remove_voice" ); 1450 "remove_voice" );
1450 mActionImportOL = new KAction( i18n( "Import from OL..." ), 0, this, 1451 mActionImportOL = new KAction( i18n( "Import from OL..." ), 0, this,
1451 SLOT( importFromOL() ), actionCollection(), 1452 SLOT( importFromOL() ), actionCollection(),
1452 "import_OL" ); 1453 "import_OL" );
1453#ifdef KAB_EMBEDDED 1454#ifdef KAB_EMBEDDED
1454 1455
1455 mActionAboutKAddressbook = new KAction( i18n( "&About KAddressBook" ), "kaddressbook2", 0, 1456 mActionAboutKAddressbook = new KAction( i18n( "&About KAddressBook" ), "kaddressbook2", 0,
1456 this, SLOT( createAboutData() ), actionCollection(), 1457 this, SLOT( createAboutData() ), actionCollection(),
1457 "kaddressbook_about_data" ); 1458 "kaddressbook_about_data" );
1458#endif //KAB_EMBEDDED 1459#endif //KAB_EMBEDDED
1459 1460
1460 clipboardDataChanged(); 1461 clipboardDataChanged();
1461 connect( UndoStack::instance(), SIGNAL( changed() ), SLOT( updateActionMenu() ) ); 1462 connect( UndoStack::instance(), SIGNAL( changed() ), SLOT( updateActionMenu() ) );
1462 connect( RedoStack::instance(), SIGNAL( changed() ), SLOT( updateActionMenu() ) ); 1463 connect( RedoStack::instance(), SIGNAL( changed() ), SLOT( updateActionMenu() ) );
1463} 1464}
1464 1465
1465//US we need this function, to plug all actions into the correct menues. 1466//US we need this function, to plug all actions into the correct menues.
1466// KDE uses a XML format to plug the actions, but we work her without this overhead. 1467// KDE uses a XML format to plug the actions, but we work her without this overhead.
1467void KABCore::addActionsManually() 1468void KABCore::addActionsManually()
1468{ 1469{
1469//US qDebug("KABCore::initActions(): mIsPart %i", mIsPart); 1470//US qDebug("KABCore::initActions(): mIsPart %i", mIsPart);
1470 1471
1471#ifdef KAB_EMBEDDED 1472#ifdef KAB_EMBEDDED
1472 QPopupMenu *fileMenu = new QPopupMenu( this ); 1473 QPopupMenu *fileMenu = new QPopupMenu( this );
1473 QPopupMenu *editMenu = new QPopupMenu( this ); 1474 QPopupMenu *editMenu = new QPopupMenu( this );
1474 QPopupMenu *helpMenu = new QPopupMenu( this ); 1475 QPopupMenu *helpMenu = new QPopupMenu( this );
1475 1476
1476 KToolBar* tb = mMainWindow->toolBar(); 1477 KToolBar* tb = mMainWindow->toolBar();
1477 1478
1478#ifdef DESKTOP_VERSION 1479#ifdef DESKTOP_VERSION
1479 QMenuBar* mb = mMainWindow->menuBar(); 1480 QMenuBar* mb = mMainWindow->menuBar();
1480 1481
1481 //US setup menubar. 1482 //US setup menubar.
1482 //Disable the following block if you do not want to have a menubar. 1483 //Disable the following block if you do not want to have a menubar.
1483 mb->insertItem( "&File", fileMenu ); 1484 mb->insertItem( "&File", fileMenu );
1484 mb->insertItem( "&Edit", editMenu ); 1485 mb->insertItem( "&Edit", editMenu );
1485 mb->insertItem( "&View", viewMenu ); 1486 mb->insertItem( "&View", viewMenu );
1486 mb->insertItem( "&Settings", settingsMenu ); 1487 mb->insertItem( "&Settings", settingsMenu );
1487 mb->insertItem( "&Change selected", changeMenu ); 1488 mb->insertItem( "&Change selected", changeMenu );
1488 mb->insertItem( "&Help", helpMenu ); 1489 mb->insertItem( "&Help", helpMenu );
1489 mIncSearchWidget = new IncSearchWidget( tb ); 1490 mIncSearchWidget = new IncSearchWidget( tb );
1490 // tb->insertWidget(-1, 0, mIncSearchWidget); 1491 // tb->insertWidget(-1, 0, mIncSearchWidget);
1491 1492
1492#else 1493#else
1493 //US setup toolbar 1494 //US setup toolbar
1494 QMenuBar *menuBarTB = new QMenuBar( tb ); 1495 QMenuBar *menuBarTB = new QMenuBar( tb );
1495 QPopupMenu *popupBarTB = new QPopupMenu( this ); 1496 QPopupMenu *popupBarTB = new QPopupMenu( this );
1496 menuBarTB->insertItem( "ME", popupBarTB); 1497 menuBarTB->insertItem( "ME", popupBarTB);
1497 tb->insertWidget(-1, 0, menuBarTB); 1498 tb->insertWidget(-1, 0, menuBarTB);
1498 mIncSearchWidget = new IncSearchWidget( tb ); 1499 mIncSearchWidget = new IncSearchWidget( tb );
1499 1500
1500 tb->enableMoving(false); 1501 tb->enableMoving(false);
1501 popupBarTB->insertItem( "&File", fileMenu ); 1502 popupBarTB->insertItem( "&File", fileMenu );
1502 popupBarTB->insertItem( "&Edit", editMenu ); 1503 popupBarTB->insertItem( "&Edit", editMenu );
1503 popupBarTB->insertItem( "&View", viewMenu ); 1504 popupBarTB->insertItem( "&View", viewMenu );
1504 popupBarTB->insertItem( "&Settings", settingsMenu ); 1505 popupBarTB->insertItem( "&Settings", settingsMenu );
1505 mViewManager->getFilterAction()->plug ( popupBarTB); 1506 mViewManager->getFilterAction()->plug ( popupBarTB);
1506 popupBarTB->insertItem( "&Change selected", changeMenu ); 1507 popupBarTB->insertItem( "&Change selected", changeMenu );
1507 popupBarTB->insertItem( "&Help", helpMenu ); 1508 popupBarTB->insertItem( "&Help", helpMenu );
1508 if (QApplication::desktop()->width() > 320 ) { 1509 if (QApplication::desktop()->width() > 320 ) {
1509 // mViewManager->getFilterAction()->plug ( tb); 1510 // mViewManager->getFilterAction()->plug ( tb);
1510 } 1511 }
1511#endif 1512#endif
1512 // mActionQuit->plug ( mMainWindow->toolBar()); 1513 // mActionQuit->plug ( mMainWindow->toolBar());
1513 1514
1514 1515
1515 1516
1516 //US Now connect the actions with the menue entries. 1517 //US Now connect the actions with the menue entries.
1517 mActionPrint->plug( fileMenu ); 1518 mActionPrint->plug( fileMenu );
1518 mActionMail->plug( fileMenu ); 1519 mActionMail->plug( fileMenu );
1519 fileMenu->insertSeparator(); 1520 fileMenu->insertSeparator();
1520 1521
1521 mActionNewContact->plug( fileMenu ); 1522 mActionNewContact->plug( fileMenu );
1522 mActionNewContact->plug( tb ); 1523 mActionNewContact->plug( tb );
1523 1524
1524 mActionEditAddressee->plug( fileMenu ); 1525 mActionEditAddressee->plug( fileMenu );
1525 fileMenu->insertSeparator(); 1526 fileMenu->insertSeparator();
1526 mActionSave->plug( fileMenu ); 1527 mActionSave->plug( fileMenu );
1527 fileMenu->insertItem( "&Import", ImportMenu ); 1528 fileMenu->insertItem( "&Import", ImportMenu );
1528 fileMenu->insertItem( "&Emport", ExportMenu ); 1529 fileMenu->insertItem( "&Emport", ExportMenu );
1529 fileMenu->insertSeparator(); 1530 fileMenu->insertSeparator();
1530 mActionMailVCard->plug( fileMenu ); 1531 mActionMailVCard->plug( fileMenu );
1531 fileMenu->insertSeparator(); 1532 fileMenu->insertSeparator();
1532 mActionQuit->plug( fileMenu ); 1533 mActionQuit->plug( fileMenu );
1533#ifdef _WIN32_ 1534#ifdef _WIN32_
1534 mActionImportOL->plug( ImportMenu ); 1535 mActionImportOL->plug( ImportMenu );
1535#endif 1536#endif
1536 // edit menu 1537 // edit menu
1537 mActionUndo->plug( editMenu ); 1538 mActionUndo->plug( editMenu );
1538 mActionRedo->plug( editMenu ); 1539 mActionRedo->plug( editMenu );
1539 editMenu->insertSeparator(); 1540 editMenu->insertSeparator();
1540 mActionCut->plug( editMenu ); 1541 mActionCut->plug( editMenu );
1541 mActionCopy->plug( editMenu ); 1542 mActionCopy->plug( editMenu );
1542 mActionPaste->plug( editMenu ); 1543 mActionPaste->plug( editMenu );
1543 mActionDelete->plug( editMenu ); 1544 mActionDelete->plug( editMenu );
1544 editMenu->insertSeparator(); 1545 editMenu->insertSeparator();
1545 mActionSelectAll->plug( editMenu ); 1546 mActionSelectAll->plug( editMenu );
1546 1547
1547 mActionRemoveVoice->plug( changeMenu ); 1548 mActionRemoveVoice->plug( changeMenu );
1548 // settings menu 1549 // settings menu
1549//US special menuentry to configure the addressbook resources. On KDE 1550//US special menuentry to configure the addressbook resources. On KDE
1550// you do that through the control center !!! 1551// you do that through the control center !!!
1551 mActionConfigResources->plug( settingsMenu ); 1552 mActionConfigResources->plug( settingsMenu );
1552 settingsMenu->insertSeparator(); 1553 settingsMenu->insertSeparator();
1553 1554
1554 mActionConfigKAddressbook->plug( settingsMenu ); 1555 mActionConfigKAddressbook->plug( settingsMenu );
1555 1556
1556 if ( mIsPart ) { 1557 if ( mIsPart ) {
1557 mActionConfigShortcuts->plug( settingsMenu ); 1558 mActionConfigShortcuts->plug( settingsMenu );
1558 mActionConfigureToolbars->plug( settingsMenu ); 1559 mActionConfigureToolbars->plug( settingsMenu );
1559 1560
1560 } else { 1561 } else {
1561 mActionKeyBindings->plug( settingsMenu ); 1562 mActionKeyBindings->plug( settingsMenu );
1562 } 1563 }
1563 1564
1564 settingsMenu->insertSeparator(); 1565 settingsMenu->insertSeparator();
1565 1566
1566 mActionJumpBar->plug( settingsMenu ); 1567 mActionJumpBar->plug( settingsMenu );
1567 mActionDetails->plug( settingsMenu ); 1568 mActionDetails->plug( settingsMenu );
1568 settingsMenu->insertSeparator(); 1569 settingsMenu->insertSeparator();
1569 1570
1570 mActionWhoAmI->plug( settingsMenu ); 1571 mActionWhoAmI->plug( settingsMenu );
1571 mActionCategories->plug( settingsMenu ); 1572 mActionCategories->plug( settingsMenu );
1572 1573
1573 mActionAboutKAddressbook->plug( helpMenu ); 1574 mActionAboutKAddressbook->plug( helpMenu );
1574 1575
1575 1576
1576 if (QApplication::desktop()->width() > 320 ) { 1577 if (QApplication::desktop()->width() > 320 ) {
1577 1578
1578 mActionEditAddressee->plug( tb ); 1579 mActionEditAddressee->plug( tb );
1579 mActionSave->plug( tb ); 1580 mActionSave->plug( tb );
1580 mViewManager->getFilterAction()->plug ( tb); 1581 mViewManager->getFilterAction()->plug ( tb);
1581 if (QApplication::desktop()->width() > 480 ) { 1582 if (QApplication::desktop()->width() > 480 ) {
1582 mActionUndo->plug( tb ); 1583 mActionUndo->plug( tb );
1583 mActionDelete->plug( tb ); 1584 mActionDelete->plug( tb );
1584 mActionRedo->plug( tb ); 1585 mActionRedo->plug( tb );
1585 } 1586 }
1586 } 1587 }
1587 //mActionQuit->plug ( tb ); 1588 //mActionQuit->plug ( tb );
1588 // tb->insertWidget(-1, 0, mIncSearchWidget, 6); 1589 // tb->insertWidget(-1, 0, mIncSearchWidget, 6);
1589 1590
1590 //US link the searchwidget first to this. 1591 //US link the searchwidget first to this.
1591 // The real linkage to the toolbar happens later. 1592 // The real linkage to the toolbar happens later.
1592//US mIncSearchWidget->reparent(tb, 0, QPoint(50,0), TRUE); 1593//US mIncSearchWidget->reparent(tb, 0, QPoint(50,0), TRUE);
1593//US tb->insertItem( mIncSearchWidget ); 1594//US tb->insertItem( mIncSearchWidget );
1594/*US 1595/*US
1595 mIncSearchWidget = new IncSearchWidget( tb ); 1596 mIncSearchWidget = new IncSearchWidget( tb );
1596 connect( mIncSearchWidget, SIGNAL( doSearch( const QString& ) ), 1597 connect( mIncSearchWidget, SIGNAL( doSearch( const QString& ) ),
1597 SLOT( incrementalSearch( const QString& ) ) ); 1598 SLOT( incrementalSearch( const QString& ) ) );
1598 1599
1599 mJumpButtonBar = new JumpButtonBar( this, this ); 1600 mJumpButtonBar = new JumpButtonBar( this, this );
1600 1601
1601//US topLayout->addWidget( mJumpButtonBar ); 1602//US topLayout->addWidget( mJumpButtonBar );
1602 this->layout()->add( mJumpButtonBar ); 1603 this->layout()->add( mJumpButtonBar );
1603*/ 1604*/
1604 1605
1605#endif //KAB_EMBEDDED 1606#endif //KAB_EMBEDDED
1606} 1607}
1607void KABCore::removeVoice() 1608void KABCore::removeVoice()
1608{ 1609{
1609 if ( KMessageBox::questionYesNo( this, i18n("After importing, phone numbers\nmay have two or more types.\n(E.g. work+voice)\nThese numbers are shown as \"other\".\nClick Yes to remove the voice type\nfrom numbers with more than one type.\n\nRemove voice type?") ) == KMessageBox::No ) 1610 if ( KMessageBox::questionYesNo( this, i18n("After importing, phone numbers\nmay have two or more types.\n(E.g. work+voice)\nThese numbers are shown as \"other\".\nClick Yes to remove the voice type\nfrom numbers with more than one type.\n\nRemove voice type?") ) == KMessageBox::No )
1610 return; 1611 return;
1611 KABC::Addressee::List list = mViewManager->selectedAddressees(); 1612 KABC::Addressee::List list = mViewManager->selectedAddressees();
1612 KABC::Addressee::List::Iterator it; 1613 KABC::Addressee::List::Iterator it;
1613 for ( it = list.begin(); it != list.end(); ++it ) { 1614 for ( it = list.begin(); it != list.end(); ++it ) {
1614 PhoneNumber::List phoneNumbers = (*it).phoneNumbers(); 1615 PhoneNumber::List phoneNumbers = (*it).phoneNumbers();
1615 PhoneNumber::List::Iterator phoneIt; 1616 PhoneNumber::List::Iterator phoneIt;
1616 bool found = false; 1617 bool found = false;
1617 for ( phoneIt = phoneNumbers.begin(); phoneIt != phoneNumbers.end(); ++phoneIt ) { 1618 for ( phoneIt = phoneNumbers.begin(); phoneIt != phoneNumbers.end(); ++phoneIt ) {
1618 if ( (*phoneIt).type() & PhoneNumber::Voice) { // voice found 1619 if ( (*phoneIt).type() & PhoneNumber::Voice) { // voice found
1619 if ((*phoneIt).type() - PhoneNumber::Voice ) { 1620 if ((*phoneIt).type() - PhoneNumber::Voice ) {
1620 (*phoneIt).setType((*phoneIt).type() - PhoneNumber::Voice ); 1621 (*phoneIt).setType((*phoneIt).type() - PhoneNumber::Voice );
1621 (*it).insertPhoneNumber( (*phoneIt) ); 1622 (*it).insertPhoneNumber( (*phoneIt) );
1622 found = true; 1623 found = true;
1623 } 1624 }
1624 } 1625 }
1625 1626
1626 } 1627 }
1627 if ( found ) 1628 if ( found )
1628 contactModified((*it) ); 1629 contactModified((*it) );
1629 } 1630 }
1630} 1631}
1631 1632
1632 1633
1633 1634
1634void KABCore::clipboardDataChanged() 1635void KABCore::clipboardDataChanged()
1635{ 1636{
1636 1637
1637 if ( mReadWrite ) 1638 if ( mReadWrite )
1638 mActionPaste->setEnabled( !QApplication::clipboard()->text().isEmpty() ); 1639 mActionPaste->setEnabled( !QApplication::clipboard()->text().isEmpty() );