summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/plugins/qtopia/resourceqtopia.cpp2
-rw-r--r--kaddressbook/xxport/qtopia_xxport.cpp16
-rw-r--r--kaddressbook/xxportobject.cpp85
3 files changed, 57 insertions, 46 deletions
diff --git a/kabc/plugins/qtopia/resourceqtopia.cpp b/kabc/plugins/qtopia/resourceqtopia.cpp
index d6df981..cf6b11a 100644
--- a/kabc/plugins/qtopia/resourceqtopia.cpp
+++ b/kabc/plugins/qtopia/resourceqtopia.cpp
@@ -70,193 +70,193 @@ __declspec(dllexport)
70 70
71ResourceQtopia::ResourceQtopia( const KConfig *config ) 71ResourceQtopia::ResourceQtopia( const KConfig *config )
72 : Resource( config ), mConverter (0) 72 : Resource( config ), mConverter (0)
73{ 73{
74 // we can not choose the filename. Therefore use the default to display 74 // we can not choose the filename. Therefore use the default to display
75 QString fileName = QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml"; 75 QString fileName = QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml";
76 init( fileName ); 76 init( fileName );
77} 77}
78 78
79ResourceQtopia::ResourceQtopia( const QString &fileName ) 79ResourceQtopia::ResourceQtopia( const QString &fileName )
80 : Resource( 0 ) 80 : Resource( 0 )
81{ 81{
82 init( fileName ); 82 init( fileName );
83} 83}
84 84
85void ResourceQtopia::init( const QString &fileName ) 85void ResourceQtopia::init( const QString &fileName )
86{ 86{
87#ifdef _USE_DIRWATCH_ 87#ifdef _USE_DIRWATCH_
88 connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) ); 88 connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) );
89 connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) ); 89 connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) );
90 connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) ); 90 connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) );
91#endif 91#endif
92 setFileName( fileName ); 92 setFileName( fileName );
93} 93}
94 94
95ResourceQtopia::~ResourceQtopia() 95ResourceQtopia::~ResourceQtopia()
96{ 96{
97 if (mConverter != 0) 97 if (mConverter != 0)
98 delete mConverter; 98 delete mConverter;
99 99
100} 100}
101 101
102void ResourceQtopia::writeConfig( KConfig *config ) 102void ResourceQtopia::writeConfig( KConfig *config )
103{ 103{
104 Resource::writeConfig( config ); 104 Resource::writeConfig( config );
105} 105}
106 106
107Ticket *ResourceQtopia::requestSaveTicket() 107Ticket *ResourceQtopia::requestSaveTicket()
108{ 108{
109 kdDebug(5700) << "ResourceQtopia::requestSaveTicket()" << endl; 109 kdDebug(5700) << "ResourceQtopia::requestSaveTicket()" << endl;
110 110
111 qDebug("ResourceQtopia::requestSaveTicket: %s", fileName().latin1()); 111 qDebug("ResourceQtopia::requestSaveTicket: %s", fileName().latin1());
112 112
113 if ( !addressBook() ) return 0; 113 if ( !addressBook() ) return 0;
114 114
115 if ( !lock( fileName() ) ) { 115 if ( !lock( fileName() ) ) {
116 kdDebug(5700) << "ResourceQtopia::requestSaveTicket(): Unable to lock file '" 116 kdDebug(5700) << "ResourceQtopia::requestSaveTicket(): Unable to lock file '"
117 << fileName() << "'" << endl; 117 << fileName() << "'" << endl;
118 return 0; 118 return 0;
119 } 119 }
120 return createTicket( this ); 120 return createTicket( this );
121} 121}
122 122
123 123
124bool ResourceQtopia::doOpen() 124bool ResourceQtopia::doOpen()
125{ 125{
126 qDebug("ResourceQtopia::doOpen(): %s", fileName().latin1()); 126 qDebug("ResourceQtopia::doOpen(): %s", fileName().latin1());
127 127
128 128
129 if (mConverter == 0) 129 if (mConverter == 0)
130 { 130 {
131 mConverter = new QtopiaConverter(); 131 mConverter = new QtopiaConverter();
132 bool res = mConverter->init(); 132 bool res = mConverter->init();
133 if ( !res ) 133 if ( !res )
134 { 134 {
135 QString msg("Unable to initialize qtopia converter. Most likely a problem with the category file"); 135 QString msg("Unable to initialize qtopia converter. Most likely a problem with the category file");
136 qDebug(msg); 136 qDebug(msg);
137 return false; 137 return false;
138 } 138 }
139 } 139 }
140 140
141 return true; 141 return true;
142} 142}
143 143
144void ResourceQtopia::doClose() 144void ResourceQtopia::doClose()
145{ 145{
146 qDebug("ResourceQtopia::doClose: %s", fileName().latin1()); 146 qDebug("ResourceQtopia::doClose: %s", fileName().latin1());
147 147
148 148
149 // it seems so, that deletion of access deletes backend as well 149 // it seems so, that deletion of access deletes backend as well
150 //delete backend; 150 //delete backend;
151 151
152 return; 152 return;
153} 153}
154 154
155bool ResourceQtopia::load() 155bool ResourceQtopia::load()
156{ 156{
157 157
158 QFile file( fileName() ); 158 QFile file( fileName() );
159 if ( !file.open(IO_ReadOnly ) ) { 159 if ( !file.open(IO_ReadOnly ) ) {
160 return false; 160 return false;
161 } 161 }
162 162
163 QDomDocument doc("mydocument" ); 163 QDomDocument doc("mydocument" );
164 if ( !doc.setContent( &file ) ) { 164 if ( !doc.setContent( &file ) ) {
165 file.close(); 165 file.close();
166 return false; 166 return true;
167 } 167 }
168 bool res; 168 bool res;
169 QDomElement docElem = doc.documentElement( ); 169 QDomElement docElem = doc.documentElement( );
170 QDomNode n = docElem.firstChild(); 170 QDomNode n = docElem.firstChild();
171 while ( !n.isNull() ) { 171 while ( !n.isNull() ) {
172 QDomElement e = n.toElement(); 172 QDomElement e = n.toElement();
173 if ( !e.isNull() ) { 173 if ( !e.isNull() ) {
174 if ( e.tagName() == QString::fromLatin1( "Contacts" ) ) { 174 if ( e.tagName() == QString::fromLatin1( "Contacts" ) ) {
175 QDomNode no = e.firstChild(); 175 QDomNode no = e.firstChild();
176 while ( !no.isNull() ) { 176 while ( !no.isNull() ) {
177 QDomElement el = no.toElement(); 177 QDomElement el = no.toElement();
178 if ( !el.isNull() ) { 178 if ( !el.isNull() ) {
179 KABC::Addressee addressee; 179 KABC::Addressee addressee;
180 res = mConverter->qtopiaToAddressee( el, addressee ); 180 res = mConverter->qtopiaToAddressee( el, addressee );
181 if ( !addressee.isEmpty() && res ) 181 if ( !addressee.isEmpty() && res )
182 { 182 {
183 addressee.setResource( this ); 183 addressee.setResource( this );
184 addressBook()->insertAddressee( addressee ); 184 addressBook()->insertAddressee( addressee );
185 } 185 }
186 } 186 }
187 187
188 no = no.nextSibling(); 188 no = no.nextSibling();
189 } 189 }
190 } 190 }
191 } 191 }
192 192
193 n = n.nextSibling(); 193 n = n.nextSibling();
194 } 194 }
195 return true; 195 return true;
196} 196}
197 197
198bool ResourceQtopia::save( Ticket *ticket ) 198bool ResourceQtopia::save( Ticket *ticket )
199{ 199{
200#ifdef _USE_DIRWATCH_ 200#ifdef _USE_DIRWATCH_
201 mDirWatch.stopScan(); 201 mDirWatch.stopScan();
202#endif 202#endif
203 KABC::AddressBook::Iterator it; 203 KABC::AddressBook::Iterator it;
204 bool res; 204 bool res;
205 QFile file( fileName() ); 205 QFile file( fileName() );
206 if (!file.open( IO_WriteOnly ) ) { 206 if (!file.open( IO_WriteOnly ) ) {
207 return false; 207 return false;
208 } 208 }
209 QTextStream ts( &file ); 209 QTextStream ts( &file );
210 QTextStream *stream = &ts; 210 QTextStream *stream = &ts;
211 stream->setEncoding( QTextStream::UnicodeUTF8 ); 211 stream->setEncoding( QTextStream::UnicodeUTF8 );
212 *stream << "<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE Addressbook ><AddressBook>" << endl; 212 *stream << "<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE Addressbook ><AddressBook>" << endl;
213 *stream << " <Groups>" << endl; 213 *stream << " <Groups>" << endl;
214 *stream << " </Groups>" << endl; 214 *stream << " </Groups>" << endl;
215 *stream << " <Contacts> " << endl; 215 *stream << " <Contacts> " << endl;
216 // for all entries 216 // for all entries
217 KABC::Addressee ab; 217 KABC::Addressee ab;
218 for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) { 218 for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) {
219 KABC::Addressee addressee = (*it); 219 KABC::Addressee addressee = (*it);
220 res = mConverter->addresseeToQtopia( addressee, stream ); 220 res = mConverter->addresseeToQtopia( addressee, stream );
221 if (!res == true) 221 if (!res == true)
222 { 222 {
223 qDebug("Unable to convert Addressee %s", addressee.formattedName().latin1()); 223 qDebug("Unable to convert Addressee %s", addressee.formattedName().latin1());
224 } 224 }
225 } 225 }
226 *stream << "</Contacts>" << endl; 226 *stream << "</Contacts>" << endl;
227 *stream << "</AddressBook>" << endl; 227 *stream << "</AddressBook>" << endl;
228 file.close(); 228 file.close();
229#ifdef _USE_DIRWATCH_ 229#ifdef _USE_DIRWATCH_
230 mDirWatch.startScan(); 230 mDirWatch.startScan();
231#endif 231#endif
232 delete ticket; 232 delete ticket;
233 unlock( fileName() ); 233 unlock( fileName() );
234 return true; 234 return true;
235} 235}
236 236
237bool ResourceQtopia::lock( const QString &lockfileName ) 237bool ResourceQtopia::lock( const QString &lockfileName )
238{ 238{
239 //disabled 239 //disabled
240 return true; 240 return true;
241 qDebug("ResourceQtopia::lock: %s", fileName().latin1()); 241 qDebug("ResourceQtopia::lock: %s", fileName().latin1());
242 QString fn = lockfileName; 242 QString fn = lockfileName;
243 243
244 KURL url(fn); 244 KURL url(fn);
245 QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); 245 QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" );
246 246
247 if (QFile::exists( lockName )) 247 if (QFile::exists( lockName ))
248 { 248 {
249 qDebug("ResourceOpie::lock: lockfile %s already exists. (Delete it before continuing if nobody else is accessing the resourcefile %s)", lockName.latin1(), fileName().latin1()); 249 qDebug("ResourceOpie::lock: lockfile %s already exists. (Delete it before continuing if nobody else is accessing the resourcefile %s)", lockName.latin1(), fileName().latin1());
250 return false; 250 return false;
251 } 251 }
252 252
253 QString lockUniqueName; 253 QString lockUniqueName;
254 lockUniqueName = fn + KApplication::randomString( 8 ); 254 lockUniqueName = fn + KApplication::randomString( 8 );
255 255
256 url = lockUniqueName; 256 url = lockUniqueName;
257//US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName ); 257//US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName );
258 mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() ); 258 mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() );
259 kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl; 259 kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl;
260 260
261 // Create unique file 261 // Create unique file
262 QFile file( mLockUniqueName ); 262 QFile file( mLockUniqueName );
diff --git a/kaddressbook/xxport/qtopia_xxport.cpp b/kaddressbook/xxport/qtopia_xxport.cpp
index 0cf6546..fc4abbb 100644
--- a/kaddressbook/xxport/qtopia_xxport.cpp
+++ b/kaddressbook/xxport/qtopia_xxport.cpp
@@ -1,78 +1,86 @@
1/* 1/*
2 This file is part of KAddressbook. 2 This file is part of KAddressbook.
3 Copyright (c) 2003 Tobias Koenig <tokoe@kde.org> 3 Copyright (c) 2003 Tobias Koenig <tokoe@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/* 24/*
25Enhanced Version of the file for platform independent KDE tools. 25Enhanced Version of the file for platform independent KDE tools.
26Copyright (c) 2004 Ulf Schenk 26Copyright (c) 2004 Ulf Schenk
27 27
28$Id$ 28$Id$
29*/ 29*/
30 30
31#include <qdir.h> 31#include <qdir.h>
32 32
33#include "addressee.h" 33#include "addressee.h"
34#include "xxportmanager.h" 34#include "xxportmanager.h"
35#include "qtopia_xxport.h" 35#include "qtopia_xxport.h"
36#include <kfiledialog.h>
36 37
37/*US 38/*US
38class QtopiaXXPortFactory : public XXPortFactory 39class QtopiaXXPortFactory : public XXPortFactory
39{ 40{
40 public: 41 public:
41 XXPortObject *xxportObject( KABC::AddressBook *ab, QWidget *parent, const char *name ) 42 XXPortObject *xxportObject( KABC::AddressBook *ab, QWidget *parent, const char *name )
42 { 43 {
43 return new QtopiaXXPort( ab, parent, name ); 44 return new QtopiaXXPort( ab, parent, name );
44 } 45 }
45}; 46};
46*/ 47*/
47 48
48extern "C" 49extern "C"
49{ 50{
50 void *init_microkaddrbk_qtopia_xxport() 51 void *init_microkaddrbk_qtopia_xxport()
51 { 52 {
52 return ( new QtopiaXXPortFactory() ); 53 return ( new QtopiaXXPortFactory() );
53 } 54 }
54} 55}
55 56
56 57
57 58
58QtopiaXXPort::QtopiaXXPort( KABC::AddressBook *ab, QWidget *parent, const char *name ) 59QtopiaXXPort::QtopiaXXPort( KABC::AddressBook *ab, QWidget *parent, const char *name )
59 : XXPortResourceObject( ab, parent, name ) 60 : XXPortResourceObject( ab, parent, name )
60{ 61{
61 defaultFileName = QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml"; 62 defaultFileName = QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml";
62 63
63 if ( mFactory && !mFactory->typeName( "qtopia" ).isEmpty() ) 64 if ( mFactory && !mFactory->typeName( "qtopia" ).isEmpty() )
64 { 65 {
65 createImportAction( i18n( "Import Qtopia..." ) ); 66 createImportAction( i18n( "Import xml (Qtopia)..." ) );
66 createExportAction( i18n( "Export Qtopia..." ) ); 67 createExportAction( i18n( "Export xml (Qtopia)..." ) );
67 } 68 }
68} 69}
69 70
70bool QtopiaXXPort::exportContacts( const KABC::AddresseeList &list, const QString &identifier ) 71bool QtopiaXXPort::exportContacts( const KABC::AddresseeList &list, const QString &identifier )
71{ 72{
72 return _exportContacts( list, identifier, defaultFileName ); 73 QString fn =KFileDialog::getSaveFileName( defaultFileName, i18n("Import xml file"), 0 );
74 if ( fn == "" )
75 return false;
76
77 return _exportContacts( list, identifier, fn );
73} 78}
74 79
75KABC::AddresseeList QtopiaXXPort::importContacts( const QString &identifier ) const 80KABC::AddresseeList QtopiaXXPort::importContacts( const QString &identifier ) const
76{ 81{
77 return _importContacts( identifier, defaultFileName ); 82 QString fn =KFileDialog::getOpenFileName( defaultFileName, i18n("Import xml file"), 0 );
83 if ( fn == "" )
84 return KABC::AddresseeList() ;
85 return _importContacts( identifier, fn );
78} 86}
diff --git a/kaddressbook/xxportobject.cpp b/kaddressbook/xxportobject.cpp
index 67e8406..bd9d986 100644
--- a/kaddressbook/xxportobject.cpp
+++ b/kaddressbook/xxportobject.cpp
@@ -1,273 +1,276 @@
1/* 1/*
2 This file is part of KAddressbook. 2 This file is part of KAddressbook.
3 Copyright (c) 2003 Tobias Koenig <tokoe@kde.org> 3 Copyright (c) 2003 Tobias Koenig <tokoe@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/* 24/*
25Enhanced Version of the file for platform independent KDE tools. 25Enhanced Version of the file for platform independent KDE tools.
26Copyright (c) 2004 Ulf Schenk 26Copyright (c) 2004 Ulf Schenk
27 27
28$Id$ 28$Id$
29*/ 29*/
30 30
31#include <qmap.h> 31#include <qmap.h>
32#include <qfile.h>
32#include <qsignalmapper.h> 33#include <qsignalmapper.h>
33 34
34#include <kaction.h> 35#include <kaction.h>
35#include <kmessagebox.h> 36#include <kmessagebox.h>
36#include <factory.h> 37#include <factory.h>
37 38
38#include "kabcore.h" 39#include "kabcore.h"
39#include "addressee.h" 40#include "addressee.h"
40#include "tmpaddressbook.h" 41#include "tmpaddressbook.h"
41#include "xxportobject.h" 42#include "xxportobject.h"
42 43
43 44
44class XXPortObject::XXPortObjectPrivate 45class XXPortObject::XXPortObjectPrivate
45{ 46{
46 public: 47 public:
47 QSignalMapper *mExportMapper; 48 QSignalMapper *mExportMapper;
48 QSignalMapper *mImportMapper; 49 QSignalMapper *mImportMapper;
49}; 50};
50 51
51XXPortObject::XXPortObject( KABC::AddressBook *ab, QWidget *parent, 52XXPortObject::XXPortObject( KABC::AddressBook *ab, QWidget *parent,
52 const char *name ) 53 const char *name )
53 : QObject( parent, name ), mAddressBook( ab ), mParentWidget( parent ), 54 : QObject( parent, name ), mAddressBook( ab ), mParentWidget( parent ),
54 d( new XXPortObjectPrivate ) 55 d( new XXPortObjectPrivate )
55{ 56{
56 d->mExportMapper = new QSignalMapper( this ); 57 d->mExportMapper = new QSignalMapper( this );
57 d->mImportMapper = new QSignalMapper( this ); 58 d->mImportMapper = new QSignalMapper( this );
58 59
59 connect( d->mExportMapper, SIGNAL( mapped( const QString& ) ), 60 connect( d->mExportMapper, SIGNAL( mapped( const QString& ) ),
60 SLOT( slotExportActivated( const QString& ) ) ); 61 SLOT( slotExportActivated( const QString& ) ) );
61 connect( d->mImportMapper, SIGNAL( mapped( const QString& ) ), 62 connect( d->mImportMapper, SIGNAL( mapped( const QString& ) ),
62 SLOT( slotImportActivated( const QString& ) ) ); 63 SLOT( slotImportActivated( const QString& ) ) );
63} 64}
64 65
65XXPortObject::~XXPortObject() 66XXPortObject::~XXPortObject()
66{ 67{
67 delete d; 68 delete d;
68 d = 0; 69 d = 0;
69} 70}
70 71
71bool XXPortObject::exportContacts( const KABC::AddresseeList&, const QString& ) 72bool XXPortObject::exportContacts( const KABC::AddresseeList&, const QString& )
72{ 73{
73 // do nothing 74 // do nothing
74 return false; 75 return false;
75} 76}
76 77
77KABC::AddresseeList XXPortObject::importContacts( const QString& ) const 78KABC::AddresseeList XXPortObject::importContacts( const QString& ) const
78{ 79{
79 // do nothing 80 // do nothing
80 return KABC::AddresseeList(); 81 return KABC::AddresseeList();
81} 82}
82 83
83void XXPortObject::createImportAction( const QString &label, const QString &data ) 84void XXPortObject::createImportAction( const QString &label, const QString &data )
84{ 85{
85#ifdef KAB_EMBEDDED 86#ifdef KAB_EMBEDDED
86 KABCore* kabcore = (KABCore*)mParentWidget; 87 KABCore* kabcore = (KABCore*)mParentWidget;
87#endif //KAB_EMBEDDED 88#endif //KAB_EMBEDDED
88 89
89 QString id = "file_import_" + identifier() + ( data.isEmpty() ? QString( "" ) : "_" + data ); 90 QString id = "file_import_" + identifier() + ( data.isEmpty() ? QString( "" ) : "_" + data );
90#ifndef KAB_EMBEDDED 91#ifndef KAB_EMBEDDED
91 KAction *action = new KAction( label, 0, d->mImportMapper, SLOT( map() ), actionCollection(), id.latin1() ); 92 KAction *action = new KAction( label, 0, d->mImportMapper, SLOT( map() ), actionCollection(), id.latin1() );
92#else //KAB_EMBEDDED 93#else //KAB_EMBEDDED
93 KAction *action = new KAction( label, 0, d->mImportMapper, SLOT( map() ), kabcore->actionCollection(), id.latin1() ); 94 KAction *action = new KAction( label, 0, d->mImportMapper, SLOT( map() ), kabcore->actionCollection(), id.latin1() );
94#endif //KAB_EMBEDDED 95#endif //KAB_EMBEDDED
95 96
96 d->mImportMapper->setMapping( action, ( data.isEmpty() ? QString( "<empty>" ) : data ) ); 97 d->mImportMapper->setMapping( action, ( data.isEmpty() ? QString( "<empty>" ) : data ) );
97 98
98#ifndef KAB_EMBEDDED 99#ifndef KAB_EMBEDDED
99 setXMLFile( identifier() + "_xxportui.rc" ); 100 setXMLFile( identifier() + "_xxportui.rc" );
100#endif //KAB_EMBEDDED 101#endif //KAB_EMBEDDED
101 102
102#ifdef KAB_EMBEDDED 103#ifdef KAB_EMBEDDED
103 action->plug((QWidget*)kabcore->getImportMenu()); 104 action->plug((QWidget*)kabcore->getImportMenu());
104#endif //KAB_EMBEDDED 105#endif //KAB_EMBEDDED
105 106
106} 107}
107 108
108void XXPortObject::createExportAction( const QString &label, const QString &data ) 109void XXPortObject::createExportAction( const QString &label, const QString &data )
109{ 110{
110#ifdef KAB_EMBEDDED 111#ifdef KAB_EMBEDDED
111 KABCore* kabcore = (KABCore*)mParentWidget; 112 KABCore* kabcore = (KABCore*)mParentWidget;
112#endif //KAB_EMBEDDED 113#endif //KAB_EMBEDDED
113 114
114 QString id = "file_export_" + identifier() + ( data.isEmpty() ? QString( "" ) : "_" + data ); 115 QString id = "file_export_" + identifier() + ( data.isEmpty() ? QString( "" ) : "_" + data );
115#ifndef KAB_EMBEDDED 116#ifndef KAB_EMBEDDED
116 KAction *action = new KAction( label, 0, d->mExportMapper, SLOT( map() ), actionCollection(), id.latin1() ); 117 KAction *action = new KAction( label, 0, d->mExportMapper, SLOT( map() ), actionCollection(), id.latin1() );
117#else //KAB_EMBEDDED 118#else //KAB_EMBEDDED
118 KAction *action = new KAction( label, 0, d->mExportMapper, SLOT( map() ), kabcore->actionCollection(), id.latin1() ); 119 KAction *action = new KAction( label, 0, d->mExportMapper, SLOT( map() ), kabcore->actionCollection(), id.latin1() );
119#endif //KAB_EMBEDDED 120#endif //KAB_EMBEDDED
120 121
121 d->mExportMapper->setMapping( action, ( data.isEmpty() ? QString( "<empty>" ) : data ) ); 122 d->mExportMapper->setMapping( action, ( data.isEmpty() ? QString( "<empty>" ) : data ) );
122 123
123#ifndef KAB_EMBEDDED 124#ifndef KAB_EMBEDDED
124 setXMLFile( identifier() + "_xxportui.rc" ); 125 setXMLFile( identifier() + "_xxportui.rc" );
125#endif //KAB_EMBEDDED 126#endif //KAB_EMBEDDED
126 127
127#ifdef KAB_EMBEDDED 128#ifdef KAB_EMBEDDED
128 action->plug((QWidget*)kabcore->getExportMenu()); 129 action->plug((QWidget*)kabcore->getExportMenu());
129#endif //KAB_EMBEDDED 130#endif //KAB_EMBEDDED
130 131
131} 132}
132 133
133KABC::AddressBook *XXPortObject::addressBook() const 134KABC::AddressBook *XXPortObject::addressBook() const
134{ 135{
135 return mAddressBook; 136 return mAddressBook;
136} 137}
137 138
138QWidget *XXPortObject::parentWidget() const 139QWidget *XXPortObject::parentWidget() const
139{ 140{
140 return mParentWidget; 141 return mParentWidget;
141} 142}
142 143
143void XXPortObject::slotExportActivated( const QString &data ) 144void XXPortObject::slotExportActivated( const QString &data )
144{ 145{
145 emit exportActivated( identifier(), ( data == "<empty>" ? QString::null : data ) ); 146 emit exportActivated( identifier(), ( data == "<empty>" ? QString::null : data ) );
146} 147}
147 148
148void XXPortObject::slotImportActivated( const QString &data ) 149void XXPortObject::slotImportActivated( const QString &data )
149{ 150{
150 emit importActivated( identifier(), ( data == "<empty>" ? QString::null : data ) ); 151 emit importActivated( identifier(), ( data == "<empty>" ? QString::null : data ) );
151} 152}
152 153
153/******************************************************************** 154/********************************************************************
154 * 155 *
155 *******************************************************************/ 156 *******************************************************************/
156 157
157 158
158XXPortResourceObject::XXPortResourceObject( KABC::AddressBook *ab, QWidget *parent, 159XXPortResourceObject::XXPortResourceObject( KABC::AddressBook *ab, QWidget *parent,
159 const char *name ) 160 const char *name )
160 : XXPortObject( ab, parent, name ), mFactory(0) 161 : XXPortObject( ab, parent, name ), mFactory(0)
161{ 162{
162 mFactory = KRES::Factory::self( "tmpcontact" ); 163 mFactory = KRES::Factory::self( "tmpcontact" );
163} 164}
164 165
165XXPortResourceObject::~XXPortResourceObject() 166XXPortResourceObject::~XXPortResourceObject()
166{ 167{
167 //do not delete the factory. It is a singleton, and selfcontained 168 //do not delete the factory. It is a singleton, and selfcontained
168} 169}
169 170
170bool XXPortResourceObject::isAvailable() 171bool XXPortResourceObject::isAvailable()
171{ 172{
172 return (mFactory != 0); 173 return (mFactory != 0);
173} 174}
174 175
175 176
176bool XXPortResourceObject::_exportContacts( const KABC::AddresseeList &list, const QString& identifier, const QString& fileName ) 177bool XXPortResourceObject::_exportContacts( const KABC::AddresseeList &list, const QString& identifier, const QString& fileName )
177{ 178{
178 //create new resource 179 //create new resource
179 KABC::Resource* mResource = (KABC::Resource*)(mFactory->resource( this->identifier(), 0 )); 180 KABC::Resource* mResource = (KABC::Resource*)(mFactory->resource( this->identifier(), 0 ));
180 181
181 if (mResource == 0) 182 if (mResource == 0)
182 return false; 183 return false;
183 184
184 if (fileName != QString::null) 185 if (fileName != QString::null) {
185 mResource->setFileName( fileName ); 186 mResource->setFileName( fileName );
186 187 } else
187 188 return false;
188 KABC::TmpAddressBook tmpAB; 189
189 190
190 bool res = tmpAB.addResource( mResource ); 191 KABC::TmpAddressBook tmpAB;
191 if (res == false) 192
192 { 193 bool res = tmpAB.addResource( mResource );
193 delete mResource; 194 if (res == false)
194 return false; 195 {
195 } 196 delete mResource;
196 197 return false;
197 res = tmpAB.load(); 198 }
198 if (res == false) 199 if ( QFile::exists ( fileName ) ) {
199 { 200 res = tmpAB.load();
200 //removeResource deletes also the resource object, if the linkcount is 0 201 if (res == false)
201 tmpAB.removeResource( mResource ); 202 {
202 return false; 203 //removeResource deletes also the resource object, if the linkcount is 0
203 } 204 tmpAB.removeResource( mResource );
204 205 return false;
205 206 }
206 //Now check if the file has already entries, and ask the user if he wants to delete them first. 207
207 if (tmpAB.begin() != tmpAB.end()) 208
208 { 209 //Now check if the file has already entries, and ask the user if he wants to delete them first.
209 QString text( i18n( "Do you want to remove<br>all existing entries from<br>%1<br>before exporting.?" ) ); 210 if (tmpAB.begin() != tmpAB.end())
210 if ( KMessageBox::questionYesNo( parentWidget(), text.arg( fileName ) ) == KMessageBox::Yes ) { 211 {
211 // Clean the database.. 212 QString text( i18n( "Do you want to remove<br>all existing entries from<br>%1<br>before exporting.?" ) );
212 tmpAB.clear(); 213 if ( KMessageBox::questionYesNo( parentWidget(), text.arg( fileName ) ) == KMessageBox::Yes ) {
214 // Clean the database..
215 tmpAB.clear();
216 }
217 }
213 } 218 }
214 }
215 219
220 KABC::Addressee::List::ConstIterator it;
221 for ( it = list.begin(); it != list.end(); ++it ) {
222 tmpAB.insertAddressee(*it);
223 }
216 224
217 KABC::Addressee::List::ConstIterator it; 225 KABC::Ticket * ticket = tmpAB.requestSaveTicket(mResource);
218 for ( it = list.begin(); it != list.end(); ++it ) {
219 tmpAB.insertAddressee(*it);
220 }
221
222 KABC::Ticket * ticket = tmpAB.requestSaveTicket(mResource);
223 226
224 res = false; 227 res = false;
225 if (ticket != 0) 228 if (ticket != 0)
226 res = tmpAB.save( ticket ); 229 res = tmpAB.save( ticket );
227 230
228 //removeResource deletes also the resource object, if the linkcount is 0 231 //removeResource deletes also the resource object, if the linkcount is 0
229 tmpAB.removeResource( mResource ); 232 tmpAB.removeResource( mResource );
230 233
231 return res; 234 return res;
232} 235}
233 236
234 237
235KABC::AddresseeList XXPortResourceObject::_importContacts( const QString& identifier, const QString& fileName ) const 238KABC::AddresseeList XXPortResourceObject::_importContacts( const QString& identifier, const QString& fileName ) const
236{ 239{
237 240
238 241
239 KABC::Resource* mResource = (KABC::Resource*)(mFactory->resource( this->identifier(), 0 )); 242 KABC::Resource* mResource = (KABC::Resource*)(mFactory->resource( this->identifier(), 0 ));
240 243
241 if (mResource == 0) 244 if (mResource == 0)
242 return KABC::AddresseeList(); 245 return KABC::AddresseeList();
243 246
244 KABC::AddresseeList adrlst; 247 KABC::AddresseeList adrlst;
245 248
246 if (fileName != QString::null) 249 if (fileName != QString::null)
247 mResource->setFileName( fileName ); 250 mResource->setFileName( fileName );
248 251
249 252
250 KABC::TmpAddressBook tmpAB; 253 KABC::TmpAddressBook tmpAB;
251 254
252 bool res = tmpAB.addResource( mResource ); 255 bool res = tmpAB.addResource( mResource );
253 if (res == false) 256 if (res == false)
254 { 257 {
255 delete mResource; 258 delete mResource;
256 return KABC::AddresseeList(); 259 return KABC::AddresseeList();
257 } 260 }
258 261
259 res = tmpAB.load(); 262 res = tmpAB.load();
260 263
261 adrlst = tmpAB.allAddressees(); 264 adrlst = tmpAB.allAddressees();
262 265
263 //remove resource deletes also the Resourceobject, if the linkcount is 0 266 //remove resource deletes also the Resourceobject, if the linkcount is 0
264 tmpAB.removeResource( mResource ); 267 tmpAB.removeResource( mResource );
265 268
266 return adrlst; 269 return adrlst;
267} 270}
268 271
269 272
270 273
271#ifndef KAB_EMBEDDED 274#ifndef KAB_EMBEDDED
272#include "xxportobject.moc" 275#include "xxportobject.moc"
273#endif //KAB_EMBEDDED 276#endif //KAB_EMBEDDED