summaryrefslogtreecommitdiffabout
path: root/kaddressbook
authorulf69 <ulf69>2004-08-03 20:49:15 (UTC)
committer ulf69 <ulf69>2004-08-03 20:49:15 (UTC)
commitbe52d7d03e57620919b23cb0cbb33ac22d0920e0 (patch) (unidiff)
tree34e8e29a221c828424126694f865d702c7635f97 /kaddressbook
parentd5358380edce9a2c39f3eea4df741a148338880c (diff)
downloadkdepimpi-be52d7d03e57620919b23cb0cbb33ac22d0920e0.zip
kdepimpi-be52d7d03e57620919b23cb0cbb33ac22d0920e0.tar.gz
kdepimpi-be52d7d03e57620919b23cb0cbb33ac22d0920e0.tar.bz2
hopefully last modifications of resource based export/import functionality
for opie, qtopia and sharpdtm
Diffstat (limited to 'kaddressbook') (more/less context) (ignore whitespace changes)
-rw-r--r--kaddressbook/xxport/opie_xxport.cpp120
-rw-r--r--kaddressbook/xxport/opie_xxport.h4
-rw-r--r--kaddressbook/xxport/qtopia_xxport.cpp225
-rw-r--r--kaddressbook/xxport/sharpdtm_xxport.cpp228
-rw-r--r--kaddressbook/xxport/sharpdtm_xxport.h2
-rw-r--r--kaddressbook/xxportobject.cpp106
-rw-r--r--kaddressbook/xxportobject.h9
7 files changed, 137 insertions, 557 deletions
diff --git a/kaddressbook/xxport/opie_xxport.cpp b/kaddressbook/xxport/opie_xxport.cpp
index 192b803..7b29b0a 100644
--- a/kaddressbook/xxport/opie_xxport.cpp
+++ b/kaddressbook/xxport/opie_xxport.cpp
@@ -1,195 +1,91 @@
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 <kfiledialog.h> 33#include <kfiledialog.h>
34#include <kmessagebox.h>
35
36//US #include <opie/ocontactaccess.h>
37//US #include <opie/ocontactaccessbackend_xml.h>
38
39//US #include "stdaddressbook.h"
40#include "resource.h"
41#include "tmpaddressbook.h"
42
43/*US
44#include <qfile.h>
45#include <qtextstream.h>
46
47#include <kabc/vcardconverter.h>
48#ifndef KAB_EMBEDDED
49#include <kio/netaccess.h>
50#endif //KAB_EMBEDDED
51
52#include <klocale.h>
53#include <kmessagebox.h>
54#include <ktempfile.h>
55#include <kurl.h>
56*/
57
58#include <factory.h>
59
60 34
35#include "addressee.h"
61#include "xxportmanager.h" 36#include "xxportmanager.h"
62
63#include "opie_xxport.h" 37#include "opie_xxport.h"
64 38
65/*US 39/*US
66class OpieXXPortFactory : public XXPortFactory 40class OpieXXPortFactory : public XXPortFactory
67{ 41{
68 public: 42 public:
69 XXPortObject *xxportObject( KABC::AddressBook *ab, QWidget *parent, const char *name ) 43 XXPortObject *xxportObject( KABC::AddressBook *ab, QWidget *parent, const char *name )
70 { 44 {
71 return new OpieXXPort( ab, parent, name ); 45 return new OpieXXPort( ab, parent, name );
72 } 46 }
73}; 47};
74*/ 48*/
75 49
76 50
77extern "C" 51extern "C"
78{ 52{
79 void *init_microkaddrbk_opie_xxport() 53 void *init_microkaddrbk_opie_xxport()
80 { 54 {
81 return ( new OpieXXPortFactory() ); 55 return ( new OpieXXPortFactory() );
82 } 56 }
83} 57}
84 58
85 59
86OpieXXPort::OpieXXPort( KABC::AddressBook *ab, QWidget *parent, const char *name ) 60OpieXXPort::OpieXXPort( KABC::AddressBook *ab, QWidget *parent, const char *name )
87 : XXPortResourceObject( ab, parent, name ) 61 : XXPortResourceObject( ab, parent, name )
88{ 62{
89 defaultFileName = QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml"; 63 defaultFileName = QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml";
90 64
91 KRES::Factory* mFactory = KRES::Factory::self( "contact" ); 65 if ( mFactory && !mFactory->typeName( "opie" ).isEmpty() )
92
93 if ( mFactory )
94 { 66 {
95 mResource = (KABC::Resource*)(mFactory->resource( "opie", 0, false )); 67 createImportAction( i18n( "Import Opie..." ) );
96 68 createExportAction( i18n( "Export Opie..." ) );
97 if ( mResource )
98 {
99 createImportAction( i18n( "Import Opie..." ) );
100 createExportAction( i18n( "Export Opie..." ) );
101 }
102 } 69 }
103} 70}
104 71
105bool OpieXXPort::exportContacts( const KABC::AddresseeList &list, const QString &data ) 72bool OpieXXPort::exportContacts( const KABC::AddresseeList &list, const QString &identifier )
106{ 73{
107 if (mResource == 0)
108 return false;
109
110 QString fileName = KFileDialog::getSaveFileName( defaultFileName, i18n("Save file"), parentWidget() ); 74 QString fileName = KFileDialog::getSaveFileName( defaultFileName, i18n("Save file"), parentWidget() );
111 75
112 if ( fileName.isEmpty() ) 76 if ( fileName.isEmpty() )
113 return false; 77 return false;
114 78
115 mResource->setFileName( fileName ); 79 return _exportContacts( list, identifier, fileName );
116
117
118 KABC::TmpAddressBook tmpAB;
119
120 tmpAB.addResource( mResource );
121
122 qDebug("11111");
123
124 //Now check if the file has already entries, and ask the user if he wants to delete them first.
125 KABC::AddressBook::Iterator it2 = tmpAB.begin();
126 for ( it2 = tmpAB.begin(); it2 != tmpAB.end(); ++it2 ) {
127 KABC::Addressee addressee = (*it2);
128 qDebug("found %s", addressee.formattedName().latin1());
129 }
130
131 if (it2 != tmpAB.end())
132 {
133 QString text( i18n( "Do you want to remove<br>all existing entries from<br>%1<br>before exporting.?" ) );
134 if ( KMessageBox::questionYesNo( parentWidget(), text.arg( fileName ) ) == KMessageBox::Yes ) {
135 // Clean the database..
136 tmpAB.clear();
137 }
138 }
139 qDebug("22222");
140
141//US debug
142 QPtrList<KABC::Resource> kabcResources = tmpAB.resources();
143 QPtrListIterator<KABC::Resource> resIt( kabcResources );
144 KABC::Resource *resource;
145 while ( ( resource = resIt.current() ) != 0 ) {
146 ++resIt;
147 qDebug("tmpAB has resource: %s", resource->identifier().latin1());
148 }
149
150
151 KABC::Addressee::List::ConstIterator it;
152 for ( it = list.begin(); it != list.end(); ++it ) {
153 tmpAB.insertAddressee(*it);
154 }
155
156 bool res = false;
157 KABC::Ticket * ticket = tmpAB.requestSaveTicket(mResource);
158
159 if (ticket != 0)
160 res = tmpAB.save( ticket );
161
162 tmpAB.removeResource( mResource );
163
164 return res;
165} 80}
166 81
167 82
168KABC::AddresseeList OpieXXPort::importContacts( const QString& ) const 83KABC::AddresseeList OpieXXPort::importContacts( const QString &identifier ) const
169{ 84{
170 if (mResource == 0)
171 return KABC::AddresseeList();
172
173 KABC::AddresseeList adrlst;
174
175 QString fileName = KFileDialog::getOpenFileName( defaultFileName, i18n("Load file"), parentWidget() ); 85 QString fileName = KFileDialog::getOpenFileName( defaultFileName, i18n("Load file"), parentWidget() );
176 86
177 if ( fileName.isEmpty() ) 87 if ( fileName.isEmpty() )
178 return KABC::AddresseeList(); 88 return KABC::AddresseeList();
179 89
180 mResource->setFileName( fileName ); 90 return _importContacts( identifier, fileName );
181
182
183 KABC::TmpAddressBook tmpAB;
184
185 tmpAB.addResource( mResource );
186
187 bool res = tmpAB.load();
188
189 adrlst = tmpAB.allAddressees();
190
191 tmpAB.removeResource( mResource );
192
193 return adrlst;
194
195} 91}
diff --git a/kaddressbook/xxport/opie_xxport.h b/kaddressbook/xxport/opie_xxport.h
index 106f38b..d2b55cd 100644
--- a/kaddressbook/xxport/opie_xxport.h
+++ b/kaddressbook/xxport/opie_xxport.h
@@ -1,68 +1,68 @@
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#ifndef OPIE_XXPORT_H 31#ifndef OPIE_XXPORT_H
32#define OPIE_XXPORT_H 32#define OPIE_XXPORT_H
33 33
34#include <xxportobject.h> 34#include <xxportobject.h>
35 35
36 36
37class KABC::Resource; 37class KABC::Resource;
38 38
39class OpieXXPort : public XXPortResourceObject 39class OpieXXPort : public XXPortResourceObject
40{ 40{
41 Q_OBJECT 41 Q_OBJECT
42 42
43 public: 43 public:
44 OpieXXPort( KABC::AddressBook *ab, QWidget *parent, const char *name = 0 ); 44 OpieXXPort( KABC::AddressBook *ab, QWidget *parent, const char *name = 0 );
45 45
46 QString identifier() const { return "opie"; } 46 QString identifier() const { return "opie"; }
47 47
48 public slots: 48 public slots:
49 bool exportContacts( const KABC::AddresseeList &list, const QString &data ); 49 bool exportContacts( const KABC::AddresseeList &list, const QString &identifier );
50 KABC::AddresseeList importContacts( const QString &data ) const; 50 KABC::AddresseeList importContacts( const QString &identifier ) const;
51 51
52 private: 52 private:
53 QString defaultFileName; 53 QString defaultFileName;
54 54
55}; 55};
56 56
57 57
58class OpieXXPortFactory : public XXPortFactory 58class OpieXXPortFactory : public XXPortFactory
59{ 59{
60 public: 60 public:
61 XXPortObject *xxportObject( KABC::AddressBook *ab, QWidget *parent, const char *name ) 61 XXPortObject *xxportObject( KABC::AddressBook *ab, QWidget *parent, const char *name )
62 { 62 {
63 return new OpieXXPort( ab, parent, name ); 63 return new OpieXXPort( ab, parent, name );
64 } 64 }
65}; 65};
66 66
67 67
68#endif 68#endif
diff --git a/kaddressbook/xxport/qtopia_xxport.cpp b/kaddressbook/xxport/qtopia_xxport.cpp
index 8377cd5..0cf6546 100644
--- a/kaddressbook/xxport/qtopia_xxport.cpp
+++ b/kaddressbook/xxport/qtopia_xxport.cpp
@@ -1,287 +1,78 @@
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 <kfiledialog.h> 33#include "addressee.h"
34#include <kmessagebox.h>
35
36//US #include <qpe/pim/addressbookaccess.h>
37
38#include "addressbook.h"
39
40/*US
41#include <qfile.h>
42#include <qtextstream.h>
43
44#include <kabc/vcardconverter.h>
45#ifndef KAB_EMBEDDED
46#include <kio/netaccess.h>
47#endif //KAB_EMBEDDED
48
49#include <klocale.h>
50#include <kmessagebox.h>
51#include <ktempfile.h>
52#include <kurl.h>
53*/
54
55#include "xxportmanager.h" 34#include "xxportmanager.h"
56//US #include "qtopiaconverter.h"
57
58#include "qtopia_xxport.h" 35#include "qtopia_xxport.h"
59 36
60/*US 37/*US
61class QtopiaXXPortFactory : public XXPortFactory 38class QtopiaXXPortFactory : public XXPortFactory
62{ 39{
63 public: 40 public:
64 XXPortObject *xxportObject( KABC::AddressBook *ab, QWidget *parent, const char *name ) 41 XXPortObject *xxportObject( KABC::AddressBook *ab, QWidget *parent, const char *name )
65 { 42 {
66 return new QtopiaXXPort( ab, parent, name ); 43 return new QtopiaXXPort( ab, parent, name );
67 } 44 }
68}; 45};
69*/ 46*/
70 47
71extern "C" 48extern "C"
72{ 49{
73 void *init_microkaddrbk_qtopia_xxport() 50 void *init_microkaddrbk_qtopia_xxport()
74 { 51 {
75 return ( new QtopiaXXPortFactory() ); 52 return ( new QtopiaXXPortFactory() );
76 } 53 }
77} 54}
78 55
79 56
80 57
81QtopiaXXPort::QtopiaXXPort( KABC::AddressBook *ab, QWidget *parent, const char *name ) 58QtopiaXXPort::QtopiaXXPort( KABC::AddressBook *ab, QWidget *parent, const char *name )
82 : XXPortResourceObject( ab, parent, name ) 59 : XXPortResourceObject( ab, parent, name )
83{ 60{
84 defaultFileName = QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml"; 61 defaultFileName = QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml";
85 62
86 KRES::Factory* mFactory = KRES::Factory::self( "contact" ); 63 if ( mFactory && !mFactory->typeName( "qtopia" ).isEmpty() )
87
88 if ( mFactory )
89 { 64 {
90 mResource = (KABC::Resource*)(mFactory->resource( "qtopia", 0, false )); 65 createImportAction( i18n( "Import Qtopia..." ) );
91 66 createExportAction( i18n( "Export Qtopia..." ) );
92 if ( mResource )
93 {
94 createImportAction( i18n( "Import Qtopia..." ) );
95 createExportAction( i18n( "Export Qtopia..." ) );
96 }
97 } 67 }
98} 68}
99 69
100bool QtopiaXXPort::exportContacts( const KABC::AddresseeList &list, const QString &data ) 70bool QtopiaXXPort::exportContacts( const KABC::AddresseeList &list, const QString &identifier )
101{ 71{
102/*US 72 return _exportContacts( list, identifier, defaultFileName );
103 // we can not choose the filename. Therefore use the default to display
104 QString fileName = QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml";
105
106 AddressBookAccess* access = new AddressBookAccess();
107
108 if ( !access ) {
109 QString text( i18n( "Unable to access file '%1'." ).arg( fileName ) );
110 qDebug(text.latin1());
111 KMessageBox::error( parentWidget(), text );
112 addressBook()->error( text );
113 return false;
114 }
115
116 KABC::QtopiaConverter mConverter;
117
118 bool res = mConverter.init();
119 if (!res)
120 {
121 QString text( i18n( "Unable to initialize qtopia converter.<br>Most likely a problem with the category file." ) );
122 qDebug(text);
123 KMessageBox::error( parentWidget(), text );
124 delete access;
125 return false;
126 }
127
128 //Now check if the file has already entries, and ask the user if he wants to delete them first.
129 { //create a new scope
130 AddressBookIterator it(*access);
131 const PimContact* firstcontact = it.toFirst();
132 if (firstcontact)
133 {
134 QString text( i18n( "Do you want to remove<br>all existing entries from<br>%1<br>before exporting.?" ) );
135 if ( KMessageBox::questionYesNo( parentWidget(), text.arg( fileName ) ) == KMessageBox::Yes ) {
136 // Clean the database..
137
138 AddressBookIterator it2(*access);
139 for (it2.toFirst(); it2.current(); ++it2) {
140 access->removeContact(*it2.current());
141 }
142 }
143 }
144 }
145
146 KABC::Addressee::List::ConstIterator it;
147 for ( it = list.begin(); it != list.end(); ++it ) {
148 PimContact c;
149
150 res = mConverter.addresseeToQtopia( *it, c );
151 if (res == true)
152 {
153 access->addContact(c);
154 }
155 }
156
157 delete access;
158
159 return true;
160*/
161
162 if (mResource == 0)
163 return false;
164
165 QString fileName = defaultFileName;
166
167
168 mResource->setFileName( fileName );
169
170 //Now check if the file has already entries, and ask the user if he wants to delete them first.
171 if (mResource->count() > 0)
172 {
173 QString text( i18n( "Do you want to remove<br>all existing entries from<br>%1<br>before exporting.?" ) );
174 if ( KMessageBox::questionYesNo( parentWidget(), text.arg( fileName ) ) == KMessageBox::Yes ) {
175 // Clean the database.
176 mResource->clear();
177 }
178 }
179
180 KABC::AddressBook tmpAB;
181
182 tmpAB.addResource( mResource );
183
184//US debug
185 QPtrList<KABC::Resource> kabcResources = tmpAB.resources();
186 QPtrListIterator<KABC::Resource> resIt( kabcResources );
187 KABC::Resource *resource;
188 while ( ( resource = resIt.current() ) != 0 ) {
189 ++resIt;
190 qDebug("tmpAB has resource: %s", resource->identifier().latin1());
191 }
192
193
194 KABC::Addressee::List::ConstIterator it;
195 for ( it = list.begin(); it != list.end(); ++it ) {
196 tmpAB.insertAddressee(*it);
197 }
198
199 KABC::Ticket * ticket = mResource->requestSaveTicket();
200 return tmpAB.save( ticket );
201
202
203
204} 73}
205 74
206KABC::AddresseeList QtopiaXXPort::importContacts( const QString& ) const 75KABC::AddresseeList QtopiaXXPort::importContacts( const QString &identifier ) const
207{ 76{
208/*US 77 return _importContacts( identifier, defaultFileName );
209 KABC::AddresseeList adrlst;
210
211 QString fileName = QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml";
212
213 AddressBookAccess* access = new AddressBookAccess();
214
215 if ( !access ) {
216 QString text( i18n( "Unable to access file '%1'." ).arg( fileName ) );
217 qDebug(text.latin1());
218 addressBook()->error( text );
219 KMessageBox::error( parentWidget(), text );
220 return KABC::AddresseeList();
221 }
222
223 KABC::QtopiaConverter mConverter;
224
225 bool res = mConverter.init();
226 if (!res)
227 {
228 QString text( i18n( "Unable to initialize qtopia converter.<br>Most likely a problem with the category file." ) );
229 qDebug(text);
230 KMessageBox::error( parentWidget(), text );
231 delete access;
232 return KABC::AddresseeList();
233 }
234
235
236
237 { //create a new scope
238 AddressBookIterator it(*access);
239
240 for (it.toFirst(); it.current(); ++it) {
241 const PimContact*contact = it.current();
242
243 KABC::Addressee addressee;
244
245 res = mConverter.qtopiaToAddressee( (*contact), addressee );
246
247 if ( !addressee.isEmpty() && res )
248 {
249 adrlst.append( addressee );
250 }
251 }
252 }
253
254 delete access;
255//US the deletion of the access object deletes the backend object as well.
256
257 return adrlst;
258*/
259
260 if (mResource == 0)
261 return KABC::AddresseeList();
262
263 KABC::AddresseeList adrlst;
264
265 QString fileName = defaultFileName;
266
267 mResource->setFileName( fileName );
268
269
270 KABC::AddressBook tmpAB;
271
272 tmpAB.addResource( mResource );
273
274//US debug
275 QPtrList<KABC::Resource> kabcResources = tmpAB.resources();
276 QPtrListIterator<KABC::Resource> resIt( kabcResources );
277 KABC::Resource *resource;
278 while ( ( resource = resIt.current() ) != 0 ) {
279 ++resIt;
280 qDebug("tmpAB has resource: %s", resource->identifier().latin1());
281 }
282
283 bool res = tmpAB.load();
284
285 return tmpAB.allAddressees();
286
287} 78}
diff --git a/kaddressbook/xxport/sharpdtm_xxport.cpp b/kaddressbook/xxport/sharpdtm_xxport.cpp
index 8c2e07a..130bc00 100644
--- a/kaddressbook/xxport/sharpdtm_xxport.cpp
+++ b/kaddressbook/xxport/sharpdtm_xxport.cpp
@@ -1,284 +1,72 @@
1/* 1/*
2 This file is part of KAddressbook. 2 This file is part of KAddressbook.
3 Copyright (c) 2004 Ulf Schenk 3 Copyright (c) 2004 Ulf Schenk
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 "addressee.h"
32
33#include <kfiledialog.h>
34#include <kmessagebox.h>
35
36//US #include <sl/slzdb.h>
37
38#include "addressbook.h"
39
40/*US
41#include <qfile.h>
42#include <qtextstream.h>
43
44#include <kabc/vcardconverter.h>
45#ifndef KAB_EMBEDDED
46#include <kio/netaccess.h>
47#endif //KAB_EMBEDDED
48
49#include <klocale.h>
50#include <kmessagebox.h>
51#include <ktempfile.h>
52#include <kurl.h>
53*/
54
55#include "xxportmanager.h" 32#include "xxportmanager.h"
56
57#include "sharpdtm_xxport.h" 33#include "sharpdtm_xxport.h"
58 34
59/*US 35/*US
60class SharpDTMXXPortFactory : public XXPortFactory 36class SharpDTMXXPortFactory : public XXPortFactory
61{ 37{
62 public: 38 public:
63 XXPortObject *xxportObject( KABC::AddressBook *ab, QWidget *parent, const char *name ) 39 XXPortObject *xxportObject( KABC::AddressBook *ab, QWidget *parent, const char *name )
64 { 40 {
65 return new SharpDTMXXPort( ab, parent, name ); 41 return new SharpDTMXXPort( ab, parent, name );
66 } 42 }
67}; 43};
68*/ 44*/
69 45
70extern "C" 46extern "C"
71{ 47{
72 void *init_microkaddrbk_sharpdtm_xxport() 48 void *init_microkaddrbk_sharpdtm_xxport()
73 { 49 {
74 return ( new SharpDTMXXPortFactory() ); 50 return ( new SharpDTMXXPortFactory() );
75 } 51 }
76} 52}
77 53
78SharpDTMXXPort::SharpDTMXXPort( KABC::AddressBook *ab, QWidget *parent, const char *name ) 54SharpDTMXXPort::SharpDTMXXPort( KABC::AddressBook *ab, QWidget *parent, const char *name )
79 : XXPortResourceObject( ab, parent, name ) 55 : XXPortResourceObject( ab, parent, name )
80{ 56{
81 KRES::Factory* mFactory = KRES::Factory::self( "contact" ); 57 if ( mFactory && !mFactory->typeName( "sharpdtm" ).isEmpty() )
82
83 if ( mFactory )
84 { 58 {
85 mResource = (KABC::Resource*)(mFactory->resource( "sharpdtm", 0, false )); 59 createImportAction( i18n( "Import Sharp..." ) );
86 if ( mResource ) 60 createExportAction( i18n( "Export Sharp..." ) );
87 {
88 createImportAction( i18n( "Import Sharp..." ) );
89 createExportAction( i18n( "Export Sharp..." ) );
90 }
91 } 61 }
92} 62}
93 63
94bool SharpDTMXXPort::exportContacts( const KABC::AddresseeList &list, const QString &data ) 64bool SharpDTMXXPort::exportContacts( const KABC::AddresseeList &list, const QString &identifier )
95{ 65{
96/*US 66 return _exportContacts( list, identifier, QString::null );
97 // we can not choose the filename. Therefore use the default to display
98 QString fileName = SlZDataBase::addressbookFileName();
99
100 SlZDataBase* access = new SlZDataBase(fileName,
101 SlZDataBase::addressbookItems());
102
103 if ( !access ) {
104 QString text( i18n( "Unable to access file '%1'." ).arg( fileName ) );
105 qDebug(text.latin1());
106 KMessageBox::error( parentWidget(), text );
107 addressBook()->error( text );
108 return false;
109 }
110
111 KABC::SharpDTMConverter mConverter;
112
113 bool res = mConverter.init();
114 if (!res)
115 {
116 QString text( i18n( "Unable to initialize sharpdtm converter.<br>Most likely a problem with the category file." ) );
117 qDebug(text);
118 KMessageBox::error( parentWidget(), text );
119 delete access;
120 return false;
121 }
122
123 //Now check if the file has already entries, and ask the user if he wants to delete them first.
124 if (access->count() > 0)
125 {
126 QString text( i18n( "Do you want to remove<br>all existing entries from<br>%1<br>before exporting.?" ) );
127 if ( KMessageBox::questionYesNo( parentWidget(), text.arg( fileName ) ) == KMessageBox::Yes ) {
128 // Clean the database..
129 access->deleteCard(0, SlZDataBase::AllCard );
130 }
131 }
132
133 KABC::Addressee::List::ConstIterator it;
134 for ( it = list.begin(); it != list.end(); ++it ) {
135 CardId c;
136 res = access->editNewCard();
137
138 if (res == true)
139 {
140 res = mConverter.addresseeToSharp( *it, access, c );
141
142 if (res == true)
143 access->finishEditCard(&c);
144 else
145 access->cancelEditCard();
146 }
147 }
148
149 delete access;
150
151 return true;
152*/
153
154 if (mResource == 0)
155 return false;
156
157 // we can not choose the filename. Therefore use the default to display
158 QString fileName = mResource->fileName();
159
160 if ( fileName.isEmpty() )
161 return false;
162
163 //Now check if the file has already entries, and ask the user if he wants to delete them first.
164 if (mResource->count() > 0)
165 {
166 QString text( i18n( "Do you want to remove<br>all existing entries from<br>%1<br>before exporting.?" ) );
167 if ( KMessageBox::questionYesNo( parentWidget(), text.arg( fileName ) ) == KMessageBox::Yes ) {
168 // Clean the database..
169 mResource->clear();
170 }
171 }
172
173 KABC::AddressBook tmpAB;
174
175 tmpAB.addResource( mResource );
176
177//US debug
178 QPtrList<KABC::Resource> kabcResources = tmpAB.resources();
179 QPtrListIterator<KABC::Resource> resIt( kabcResources );
180 KABC::Resource *resource;
181 while ( ( resource = resIt.current() ) != 0 ) {
182 ++resIt;
183 qDebug("tmpAB has resource: %s", resource->identifier().latin1());
184 }
185
186
187 KABC::Addressee::List::ConstIterator it;
188 for ( it = list.begin(); it != list.end(); ++it ) {
189 tmpAB.insertAddressee(*it);
190 }
191
192 KABC::Ticket * ticket = mResource->requestSaveTicket();
193 return tmpAB.save( ticket );
194
195
196} 67}
197 68
198KABC::AddresseeList SharpDTMXXPort::importContacts( const QString& ) const 69KABC::AddresseeList SharpDTMXXPort::importContacts( const QString &identifier ) const
199{ 70{
200/*US 71 return _importContacts( identifier, QString::null );
201 KABC::AddresseeList adrlst;
202
203 QString fileName = SlZDataBase::addressbookFileName();
204
205 // the last parameter in the SlZDataBase constructor means "readonly"
206 SlZDataBase* access = new SlZDataBase(fileName,
207 SlZDataBase::addressbookItems(), NULL, true);
208
209
210 if ( !access ) {
211 QString text( i18n( "Unable to access file '%1'." ).arg( fileName ) );
212 qDebug(text.latin1());
213 addressBook()->error( text );
214 KMessageBox::error( parentWidget(), text );
215 return KABC::AddresseeList();
216 }
217
218 KABC::SharpDTMConverter mConverter;
219
220 bool res = mConverter.init();
221 if (!res)
222 {
223 QString text( i18n( "Unable to initialize sharp converter.<br>Most likely a problem with the category file." ) );
224 qDebug(text);
225 KMessageBox::error( parentWidget(), text );
226 delete access;
227 return KABC::AddresseeList();
228 }
229
230
231 { //create a new scope
232 CardId id;
233
234 for (bool res=access->first(); res == true; res=access->next()) {
235 id = access->cardId();
236
237 KABC::Addressee addressee;
238
239 res = mConverter.sharpToAddressee( id, access, addressee );
240
241 if ( !addressee.isEmpty() && res )
242 {
243 adrlst.append( addressee );
244 }
245 }
246 }
247
248 delete access;
249
250 return adrlst;
251*/
252
253 if (mResource == 0)
254 return KABC::AddresseeList();
255
256 KABC::AddresseeList adrlst;
257
258 QString fileName = mResource->fileName();
259
260 if ( fileName.isEmpty() )
261 return KABC::AddresseeList();
262
263 mResource->setFileName( fileName );
264
265
266 KABC::AddressBook tmpAB;
267
268 tmpAB.addResource( mResource );
269
270//US debug
271 QPtrList<KABC::Resource> kabcResources = tmpAB.resources();
272 QPtrListIterator<KABC::Resource> resIt( kabcResources );
273 KABC::Resource *resource;
274 while ( ( resource = resIt.current() ) != 0 ) {
275 ++resIt;
276 qDebug("tmpAB has resource: %s", resource->identifier().latin1());
277 }
278
279 bool res = tmpAB.load();
280
281 return tmpAB.allAddressees();
282
283
284} 72}
diff --git a/kaddressbook/xxport/sharpdtm_xxport.h b/kaddressbook/xxport/sharpdtm_xxport.h
index 43fd434..0797b01 100644
--- a/kaddressbook/xxport/sharpdtm_xxport.h
+++ b/kaddressbook/xxport/sharpdtm_xxport.h
@@ -1,60 +1,60 @@
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#ifndef SHARPDTM_XXPORT_H 31#ifndef SHARPDTM_XXPORT_H
32#define SHARPDTM_XXPORT_H 32#define SHARPDTM_XXPORT_H
33 33
34#include <xxportobject.h> 34#include <xxportobject.h>
35 35
36class SharpDTMXXPort : public XXPortResourceObject 36class SharpDTMXXPort : public XXPortResourceObject
37{ 37{
38 Q_OBJECT 38 Q_OBJECT
39 39
40 public: 40 public:
41 SharpDTMXXPort( KABC::AddressBook *ab, QWidget *parent, const char *name = 0 ); 41 SharpDTMXXPort( KABC::AddressBook *ab, QWidget *parent, const char *name = 0 );
42 42
43 QString identifier() const { return "qtopia"; } 43 QString identifier() const { return "sharpdtm"; }
44 44
45 public slots: 45 public slots:
46 bool exportContacts( const KABC::AddresseeList &list, const QString &data ); 46 bool exportContacts( const KABC::AddresseeList &list, const QString &data );
47 KABC::AddresseeList importContacts( const QString &data ) const; 47 KABC::AddresseeList importContacts( const QString &data ) const;
48 48
49}; 49};
50 50
51class SharpDTMXXPortFactory : public XXPortFactory 51class SharpDTMXXPortFactory : public XXPortFactory
52{ 52{
53 public: 53 public:
54 XXPortObject *xxportObject( KABC::AddressBook *ab, QWidget *parent, const char *name ) 54 XXPortObject *xxportObject( KABC::AddressBook *ab, QWidget *parent, const char *name )
55 { 55 {
56 return new SharpDTMXXPort( ab, parent, name ); 56 return new SharpDTMXXPort( ab, parent, name );
57 } 57 }
58}; 58};
59 59
60#endif 60#endif
diff --git a/kaddressbook/xxportobject.cpp b/kaddressbook/xxportobject.cpp
index bb985a6..4351753 100644
--- a/kaddressbook/xxportobject.cpp
+++ b/kaddressbook/xxportobject.cpp
@@ -1,88 +1,91 @@
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 <qsignalmapper.h> 32#include <qsignalmapper.h>
33 33
34#include <kaction.h> 34#include <kaction.h>
35#include <kmessagebox.h> 35#include <kmessagebox.h>
36#include <factory.h>
36 37
37#include "kabcore.h" 38#include "kabcore.h"
38 39#include "addressee.h"
40#include "tmpaddressbook.h"
39#include "xxportobject.h" 41#include "xxportobject.h"
40 42
43
41class XXPortObject::XXPortObjectPrivate 44class XXPortObject::XXPortObjectPrivate
42{ 45{
43 public: 46 public:
44 QSignalMapper *mExportMapper; 47 QSignalMapper *mExportMapper;
45 QSignalMapper *mImportMapper; 48 QSignalMapper *mImportMapper;
46}; 49};
47 50
48XXPortObject::XXPortObject( KABC::AddressBook *ab, QWidget *parent, 51XXPortObject::XXPortObject( KABC::AddressBook *ab, QWidget *parent,
49 const char *name ) 52 const char *name )
50 : QObject( parent, name ), mAddressBook( ab ), mParentWidget( parent ), 53 : QObject( parent, name ), mAddressBook( ab ), mParentWidget( parent ),
51 d( new XXPortObjectPrivate ) 54 d( new XXPortObjectPrivate )
52{ 55{
53 d->mExportMapper = new QSignalMapper( this ); 56 d->mExportMapper = new QSignalMapper( this );
54 d->mImportMapper = new QSignalMapper( this ); 57 d->mImportMapper = new QSignalMapper( this );
55 58
56 connect( d->mExportMapper, SIGNAL( mapped( const QString& ) ), 59 connect( d->mExportMapper, SIGNAL( mapped( const QString& ) ),
57 SLOT( slotExportActivated( const QString& ) ) ); 60 SLOT( slotExportActivated( const QString& ) ) );
58 connect( d->mImportMapper, SIGNAL( mapped( const QString& ) ), 61 connect( d->mImportMapper, SIGNAL( mapped( const QString& ) ),
59 SLOT( slotImportActivated( const QString& ) ) ); 62 SLOT( slotImportActivated( const QString& ) ) );
60} 63}
61 64
62XXPortObject::~XXPortObject() 65XXPortObject::~XXPortObject()
63{ 66{
64 delete d; 67 delete d;
65 d = 0; 68 d = 0;
66} 69}
67 70
68bool XXPortObject::exportContacts( const KABC::AddresseeList&, const QString& ) 71bool XXPortObject::exportContacts( const KABC::AddresseeList&, const QString& )
69{ 72{
70 // do nothing 73 // do nothing
71 return false; 74 return false;
72} 75}
73 76
74KABC::AddresseeList XXPortObject::importContacts( const QString& ) const 77KABC::AddresseeList XXPortObject::importContacts( const QString& ) const
75{ 78{
76 // do nothing 79 // do nothing
77 return KABC::AddresseeList(); 80 return KABC::AddresseeList();
78} 81}
79 82
80void XXPortObject::createImportAction( const QString &label, const QString &data ) 83void XXPortObject::createImportAction( const QString &label, const QString &data )
81{ 84{
82#ifdef KAB_EMBEDDED 85#ifdef KAB_EMBEDDED
83 KABCore* kabcore = (KABCore*)mParentWidget; 86 KABCore* kabcore = (KABCore*)mParentWidget;
84#endif //KAB_EMBEDDED 87#endif //KAB_EMBEDDED
85 88
86 QString id = "file_import_" + identifier() + ( data.isEmpty() ? QString( "" ) : "_" + data ); 89 QString id = "file_import_" + identifier() + ( data.isEmpty() ? QString( "" ) : "_" + data );
87#ifndef KAB_EMBEDDED 90#ifndef KAB_EMBEDDED
88 KAction *action = new KAction( label, 0, d->mImportMapper, SLOT( map() ), actionCollection(), id.latin1() ); 91 KAction *action = new KAction( label, 0, d->mImportMapper, SLOT( map() ), actionCollection(), id.latin1() );
@@ -109,65 +112,162 @@ void XXPortObject::createExportAction( const QString &label, const QString &data
109#endif //KAB_EMBEDDED 112#endif //KAB_EMBEDDED
110 113
111 QString id = "file_export_" + identifier() + ( data.isEmpty() ? QString( "" ) : "_" + data ); 114 QString id = "file_export_" + identifier() + ( data.isEmpty() ? QString( "" ) : "_" + data );
112#ifndef KAB_EMBEDDED 115#ifndef KAB_EMBEDDED
113 KAction *action = new KAction( label, 0, d->mExportMapper, SLOT( map() ), actionCollection(), id.latin1() ); 116 KAction *action = new KAction( label, 0, d->mExportMapper, SLOT( map() ), actionCollection(), id.latin1() );
114#else //KAB_EMBEDDED 117#else //KAB_EMBEDDED
115 KAction *action = new KAction( label, 0, d->mExportMapper, SLOT( map() ), kabcore->actionCollection(), id.latin1() ); 118 KAction *action = new KAction( label, 0, d->mExportMapper, SLOT( map() ), kabcore->actionCollection(), id.latin1() );
116#endif //KAB_EMBEDDED 119#endif //KAB_EMBEDDED
117 120
118 d->mExportMapper->setMapping( action, ( data.isEmpty() ? QString( "<empty>" ) : data ) ); 121 d->mExportMapper->setMapping( action, ( data.isEmpty() ? QString( "<empty>" ) : data ) );
119 122
120#ifndef KAB_EMBEDDED 123#ifndef KAB_EMBEDDED
121 setXMLFile( identifier() + "_xxportui.rc" ); 124 setXMLFile( identifier() + "_xxportui.rc" );
122#endif //KAB_EMBEDDED 125#endif //KAB_EMBEDDED
123 126
124#ifdef KAB_EMBEDDED 127#ifdef KAB_EMBEDDED
125 action->plug((QWidget*)kabcore->getExportMenu()); 128 action->plug((QWidget*)kabcore->getExportMenu());
126#endif //KAB_EMBEDDED 129#endif //KAB_EMBEDDED
127 130
128} 131}
129 132
130KABC::AddressBook *XXPortObject::addressBook() const 133KABC::AddressBook *XXPortObject::addressBook() const
131{ 134{
132 return mAddressBook; 135 return mAddressBook;
133} 136}
134 137
135QWidget *XXPortObject::parentWidget() const 138QWidget *XXPortObject::parentWidget() const
136{ 139{
137 return mParentWidget; 140 return mParentWidget;
138} 141}
139 142
140void XXPortObject::slotExportActivated( const QString &data ) 143void XXPortObject::slotExportActivated( const QString &data )
141{ 144{
142 emit exportActivated( identifier(), ( data == "<empty>" ? QString::null : data ) ); 145 emit exportActivated( identifier(), ( data == "<empty>" ? QString::null : data ) );
143} 146}
144 147
145void XXPortObject::slotImportActivated( const QString &data ) 148void XXPortObject::slotImportActivated( const QString &data )
146{ 149{
147 emit importActivated( identifier(), ( data == "<empty>" ? QString::null : data ) ); 150 emit importActivated( identifier(), ( data == "<empty>" ? QString::null : data ) );
148} 151}
149 152
150/******************************************************************** 153/********************************************************************
151 * 154 *
152 *******************************************************************/ 155 *******************************************************************/
153 156
154 157
155XXPortResourceObject::XXPortResourceObject( KABC::AddressBook *ab, QWidget *parent, 158XXPortResourceObject::XXPortResourceObject( KABC::AddressBook *ab, QWidget *parent,
156 const char *name ) 159 const char *name )
157 : XXPortObject( ab, parent, name ), mResource(0) 160 : XXPortObject( ab, parent, name ), mFactory(0)
158{ 161{
162 mFactory = KRES::Factory::self( "tmpcontact" );
159} 163}
160 164
161XXPortResourceObject::~XXPortResourceObject() 165XXPortResourceObject::~XXPortResourceObject()
162{ 166{
167 //do not delete the factory. It is a singleton, and selfcontained
163} 168}
164 169
165bool XXPortResourceObject::isAvailable() 170bool XXPortResourceObject::isAvailable()
166{ 171{
167 return (mResource != 0); 172 return (mFactory != 0);
168} 173}
169 174
170 175
176bool XXPortResourceObject::_exportContacts( const KABC::AddresseeList &list, const QString& identifier, const QString& fileName )
177{
178 //create new resource
179 KABC::Resource* mResource = (KABC::Resource*)(mFactory->resource( this->identifier(), 0, false ));
180
181 if (mResource == 0)
182 return false;
183
184 if (fileName != QString::null)
185 mResource->setFileName( fileName );
186
187
188 KABC::TmpAddressBook tmpAB;
189
190 bool res = tmpAB.addResource( mResource );
191 if (res == false)
192 {
193 delete mResource;
194 return false;
195 }
196
197 res = tmpAB.load();
198 if (res == false)
199 {
200 //removeResource deletes also the resource object, if the linkcount is 0
201 tmpAB.removeResource( mResource );
202 return false;
203 }
204
205
206 //Now check if the file has already entries, and ask the user if he wants to delete them first.
207 if (tmpAB.begin() != tmpAB.end())
208 {
209 QString text( i18n( "Do you want to remove<br>all existing entries from<br>%1<br>before exporting.?" ) );
210 if ( KMessageBox::questionYesNo( parentWidget(), text.arg( fileName ) ) == KMessageBox::Yes ) {
211 // Clean the database..
212 tmpAB.clear();
213 }
214 }
215
216
217 KABC::Addressee::List::ConstIterator it;
218 for ( it = list.begin(); it != list.end(); ++it ) {
219 tmpAB.insertAddressee(*it);
220 }
221
222 KABC::Ticket * ticket = tmpAB.requestSaveTicket(mResource);
223
224 res = false;
225 if (ticket != 0)
226 res = tmpAB.save( ticket );
227
228 //removeResource deletes also the resource object, if the linkcount is 0
229 tmpAB.removeResource( mResource );
230
231 return res;
232}
233
234
235KABC::AddresseeList XXPortResourceObject::_importContacts( const QString& identifier, const QString& fileName ) const
236{
237
238
239 KABC::Resource* mResource = (KABC::Resource*)(mFactory->resource( this->identifier(), 0, false ));
240
241 if (mResource == 0)
242 return KABC::AddresseeList();
243
244 KABC::AddresseeList adrlst;
245
246 if (fileName != QString::null)
247 mResource->setFileName( fileName );
248
249
250 KABC::TmpAddressBook tmpAB;
251
252 bool res = tmpAB.addResource( mResource );
253 if (res == false)
254 {
255 delete mResource;
256 return KABC::AddresseeList();
257 }
258
259 res = tmpAB.load();
260
261 adrlst = tmpAB.allAddressees();
262
263 //remove resource deletes also the Resourceobject, if the linkcount is 0
264 tmpAB.removeResource( mResource );
265
266 return adrlst;
267}
268
269
270
171#ifndef KAB_EMBEDDED 271#ifndef KAB_EMBEDDED
172#include "xxportobject.moc" 272#include "xxportobject.moc"
173#endif //KAB_EMBEDDED 273#endif //KAB_EMBEDDED
diff --git a/kaddressbook/xxportobject.h b/kaddressbook/xxportobject.h
index d547855..de39b9f 100644
--- a/kaddressbook/xxportobject.h
+++ b/kaddressbook/xxportobject.h
@@ -1,91 +1,91 @@
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#ifndef XXPORTOBJECT_H 31#ifndef XXPORTOBJECT_H
32#define XXPORTOBJECT_H 32#define XXPORTOBJECT_H
33 33
34#include <qobject.h> 34#include <qobject.h>
35 35
36#include <kabc/addressbook.h> 36#include <kabc/addressbook.h>
37#include <kabc/addresseelist.h> 37#include <kabc/addresseelist.h>
38#include <kabc/resource.h> 38#include <kabc/resource.h>
39#include <kxmlguiclient.h> 39#include <kxmlguiclient.h>
40#include <klibloader.h> 40#include <klibloader.h>
41 41
42 42
43 43class KRES::Factory;
44 44
45 45
46class XXPortObject : public QObject, virtual public KXMLGUIClient 46class XXPortObject : public QObject, virtual public KXMLGUIClient
47{ 47{
48 Q_OBJECT 48 Q_OBJECT
49 49
50 public: 50 public:
51 XXPortObject( KABC::AddressBook *ab, QWidget *parent, const char *name = 0 ); 51 XXPortObject( KABC::AddressBook *ab, QWidget *parent, const char *name = 0 );
52 ~XXPortObject(); 52 ~XXPortObject();
53 53
54 /** 54 /**
55 Returns the unique identifier of this xxport modul, it should 55 Returns the unique identifier of this xxport modul, it should
56 be the lowercase name of the import/export format e.g. 'vcard' 56 be the lowercase name of the import/export format e.g. 'vcard'
57 */ 57 */
58 virtual QString identifier() const = 0; 58 virtual QString identifier() const = 0;
59 59
60 /** 60 /**
61 Reimplement this method if the XXPortManager shall 61 Reimplement this method if the XXPortManager shall
62 pass a sorted list to @ref exportContacts(). 62 pass a sorted list to @ref exportContacts().
63 */ 63 */
64 virtual bool requiresSorting() const { return false; } 64 virtual bool requiresSorting() const { return false; }
65 65
66 /** 66 /**
67 Returns true if the XXPortObject can be used. 67 Returns true if the XXPortObject can be used.
68 One case it can not be used is for example if a needed lib could not be loaded. 68 One case it can not be used is for example if a needed lib could not be loaded.
69 */ 69 */
70 virtual bool isAvailable() const { return true; }; 70 virtual bool isAvailable() const { return true; };
71 71
72 72
73 public slots: 73 public slots:
74 /** 74 /**
75 Reimplement this method for exporting the contacts. 75 Reimplement this method for exporting the contacts.
76 */ 76 */
77 virtual bool exportContacts( const KABC::AddresseeList &list, const QString& identifier ); 77 virtual bool exportContacts( const KABC::AddresseeList &list, const QString& identifier );
78 78
79 /** 79 /**
80 Reimplement this method for importing the contacts. 80 Reimplement this method for importing the contacts.
81 */ 81 */
82 virtual KABC::AddresseeList importContacts( const QString& identifier ) const; 82 virtual KABC::AddresseeList importContacts( const QString& identifier ) const;
83 83
84 signals: 84 signals:
85 /** 85 /**
86 Emitted whenever the export action is activated. 86 Emitted whenever the export action is activated.
87 The parameter contains the @ref identifier() for 87 The parameter contains the @ref identifier() for
88 unique identification. 88 unique identification.
89 */ 89 */
90 void exportActivated( const QString&, const QString& ); 90 void exportActivated( const QString&, const QString& );
91 91
@@ -101,70 +101,75 @@ class XXPortObject : public QObject, virtual public KXMLGUIClient
101 Create the import action. The identifier is passed in the import slot. 101 Create the import action. The identifier is passed in the import slot.
102 */ 102 */
103 void createImportAction( const QString &label, const QString &identifier = QString::null ); 103 void createImportAction( const QString &label, const QString &identifier = QString::null );
104 104
105 /** 105 /**
106 Create the export action. The identifier is passed in the export slot. 106 Create the export action. The identifier is passed in the export slot.
107 */ 107 */
108 void createExportAction( const QString &label, const QString &identifier = QString::null ); 108 void createExportAction( const QString &label, const QString &identifier = QString::null );
109 109
110 /** 110 /**
111 Returns a pointer to the address book object. 111 Returns a pointer to the address book object.
112 */ 112 */
113 KABC::AddressBook *addressBook() const; 113 KABC::AddressBook *addressBook() const;
114 114
115 /** 115 /**
116 Returns a pointer to the parent widget. It can be used as parent for 116 Returns a pointer to the parent widget. It can be used as parent for
117 message boxes. 117 message boxes.
118 */ 118 */
119 QWidget *parentWidget() const; 119 QWidget *parentWidget() const;
120 120
121 121
122 private slots: 122 private slots:
123 void slotImportActivated( const QString& ); 123 void slotImportActivated( const QString& );
124 void slotExportActivated( const QString& ); 124 void slotExportActivated( const QString& );
125 125
126 private: 126 private:
127 KABC::AddressBook *mAddressBook; 127 KABC::AddressBook *mAddressBook;
128 QWidget *mParentWidget; 128 QWidget *mParentWidget;
129 129
130 class XXPortObjectPrivate; 130 class XXPortObjectPrivate;
131 XXPortObjectPrivate *d; 131 XXPortObjectPrivate *d;
132}; 132};
133 133
134 134
135 135
136class XXPortResourceObject : public XXPortObject 136class XXPortResourceObject : public XXPortObject
137{ 137{
138 Q_OBJECT 138 Q_OBJECT
139 139
140 public: 140 public:
141 XXPortResourceObject( KABC::AddressBook *ab, QWidget *parent, const char *name = 0 ); 141 XXPortResourceObject( KABC::AddressBook *ab, QWidget *parent, const char *name = 0 );
142 ~XXPortResourceObject(); 142 ~XXPortResourceObject();
143 143
144 /** 144 /**
145 Returns true if the XXPortObject can be used. 145 Returns true if the XXPortObject can be used.
146 One case it can not be used is for example if a needed lib could not be loaded. 146 One case it can not be used is for example if a needed lib could not be loaded.
147 */ 147 */
148 virtual bool isAvailable(); 148 virtual bool isAvailable();
149
150 protected:
151 bool _exportContacts( const KABC::AddresseeList &list, const QString& identifier, const QString& fileName );
152 KABC::AddresseeList _importContacts( const QString& identifier, const QString& fileName ) const;
153
149 protected: 154 protected:
150 KABC::Resource* mResource; 155 KRES::Factory* mFactory;
151}; 156};
152 157
153 158
154 159
155 160
156class XXPortFactory : public KLibFactory 161class XXPortFactory : public KLibFactory
157{ 162{
158 public: 163 public:
159 virtual XXPortObject *xxportObject( KABC::AddressBook *ab, QWidget *parent, 164 virtual XXPortObject *xxportObject( KABC::AddressBook *ab, QWidget *parent,
160 const char *name = 0 ) = 0; 165 const char *name = 0 ) = 0;
161 166
162 protected: 167 protected:
163 virtual QObject* createObject( QObject*, const char*, const char*, 168 virtual QObject* createObject( QObject*, const char*, const char*,
164 const QStringList & ) 169 const QStringList & )
165 { 170 {
166 return 0; 171 return 0;
167 } 172 }
168}; 173};
169 174
170#endif 175#endif