-rw-r--r-- | kaddressbook/xxport/qtopia_xxport.cpp | 16 | ||||
-rw-r--r-- | kaddressbook/xxportobject.cpp | 85 |
2 files changed, 56 insertions, 45 deletions
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 | |||
@@ -20,59 +20,67 @@ | |||
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 | /* |
25 | Enhanced Version of the file for platform independent KDE tools. | 25 | Enhanced Version of the file for platform independent KDE tools. |
26 | Copyright (c) 2004 Ulf Schenk | 26 | Copyright (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 |
38 | class QtopiaXXPortFactory : public XXPortFactory | 39 | class 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 | ||
48 | extern "C" | 49 | extern "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 | ||
58 | QtopiaXXPort::QtopiaXXPort( KABC::AddressBook *ab, QWidget *parent, const char *name ) | 59 | QtopiaXXPort::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 | ||
70 | bool QtopiaXXPort::exportContacts( const KABC::AddresseeList &list, const QString &identifier ) | 71 | bool 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 | ||
75 | KABC::AddresseeList QtopiaXXPort::importContacts( const QString &identifier ) const | 80 | KABC::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 | |||
@@ -16,32 +16,33 @@ | |||
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 | /* |
25 | Enhanced Version of the file for platform independent KDE tools. | 25 | Enhanced Version of the file for platform independent KDE tools. |
26 | Copyright (c) 2004 Ulf Schenk | 26 | Copyright (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 | ||
44 | class XXPortObject::XXPortObjectPrivate | 45 | class XXPortObject::XXPortObjectPrivate |
45 | { | 46 | { |
46 | public: | 47 | public: |
47 | QSignalMapper *mExportMapper; | 48 | QSignalMapper *mExportMapper; |
@@ -163,76 +164,78 @@ XXPortResourceObject::XXPortResourceObject( KABC::AddressBook *ab, QWidget *pare | |||
163 | } | 164 | } |
164 | 165 | ||
165 | XXPortResourceObject::~XXPortResourceObject() | 166 | XXPortResourceObject::~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 | ||
170 | bool XXPortResourceObject::isAvailable() | 171 | bool XXPortResourceObject::isAvailable() |
171 | { | 172 | { |
172 | return (mFactory != 0); | 173 | return (mFactory != 0); |
173 | } | 174 | } |
174 | 175 | ||
175 | 176 | ||
176 | bool XXPortResourceObject::_exportContacts( const KABC::AddresseeList &list, const QString& identifier, const QString& fileName ) | 177 | bool 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 | ||
235 | KABC::AddresseeList XXPortResourceObject::_importContacts( const QString& identifier, const QString& fileName ) const | 238 | KABC::AddresseeList XXPortResourceObject::_importContacts( const QString& identifier, const QString& fileName ) const |
236 | { | 239 | { |
237 | 240 | ||
238 | 241 | ||