summaryrefslogtreecommitdiffabout
path: root/kaddressbook
authorulf69 <ulf69>2004-07-17 00:38:43 (UTC)
committer ulf69 <ulf69>2004-07-17 00:38:43 (UTC)
commit01570860c92be8977a1ba558ae7c5f15d4635851 (patch) (unidiff)
tree2f3fead3ad0d2b0185d032fb3982c32c4fa15904 /kaddressbook
parent2439711b1ac7ee38269baff704293eb37a27f6c9 (diff)
downloadkdepimpi-01570860c92be8977a1ba558ae7c5f15d4635851.zip
kdepimpi-01570860c92be8977a1ba558ae7c5f15d4635851.tar.gz
kdepimpi-01570860c92be8977a1ba558ae7c5f15d4635851.tar.bz2
implementation of sharp import/export resourcehandling
Diffstat (limited to 'kaddressbook') (more/less context) (ignore whitespace changes)
-rw-r--r--kaddressbook/xxport/qtopia/qtopia_xxport.cpp49
1 files changed, 24 insertions, 25 deletions
diff --git a/kaddressbook/xxport/qtopia/qtopia_xxport.cpp b/kaddressbook/xxport/qtopia/qtopia_xxport.cpp
index bf39fdb..c1ed03e 100644
--- a/kaddressbook/xxport/qtopia/qtopia_xxport.cpp
+++ b/kaddressbook/xxport/qtopia/qtopia_xxport.cpp
@@ -1,201 +1,200 @@
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> 34#include <kmessagebox.h>
35 35
36#include <qpe/pim/addressbookaccess.h> 36#include <qpe/pim/addressbookaccess.h>
37 37
38#include "stdaddressbook.h" 38#include "stdaddressbook.h"
39 39
40/*US 40/*US
41#include <qfile.h> 41#include <qfile.h>
42#include <qtextstream.h> 42#include <qtextstream.h>
43 43
44#include <kabc/vcardconverter.h> 44#include <kabc/vcardconverter.h>
45#ifndef KAB_EMBEDDED 45#ifndef KAB_EMBEDDED
46#include <kio/netaccess.h> 46#include <kio/netaccess.h>
47#endif //KAB_EMBEDDED 47#endif //KAB_EMBEDDED
48 48
49#include <klocale.h> 49#include <klocale.h>
50#include <kmessagebox.h> 50#include <kmessagebox.h>
51#include <ktempfile.h> 51#include <ktempfile.h>
52#include <kurl.h> 52#include <kurl.h>
53*/ 53*/
54 54
55#include "xxportmanager.h" 55#include "xxportmanager.h"
56#include "qtopiaconverter.h" 56#include "qtopiaconverter.h"
57 57
58#include "qtopia_xxport.h" 58#include "qtopia_xxport.h"
59 59
60 60
61class QtopiaXXPortFactory : public XXPortFactory 61class QtopiaXXPortFactory : public XXPortFactory
62{ 62{
63 public: 63 public:
64 XXPortObject *xxportObject( KABC::AddressBook *ab, QWidget *parent, const char *name ) 64 XXPortObject *xxportObject( KABC::AddressBook *ab, QWidget *parent, const char *name )
65 { 65 {
66 return new QtopiaXXPort( ab, parent, name ); 66 return new QtopiaXXPort( ab, parent, name );
67 } 67 }
68}; 68};
69 69
70 70
71extern "C" 71extern "C"
72{ 72{
73 void *init_microkaddrbk_qtopia_xxport() 73 void *init_microkaddrbk_qtopia_xxport()
74 { 74 {
75 return ( new QtopiaXXPortFactory() ); 75 return ( new QtopiaXXPortFactory() );
76 } 76 }
77} 77}
78 78
79 79
80QtopiaXXPort::QtopiaXXPort( KABC::AddressBook *ab, QWidget *parent, const char *name ) 80QtopiaXXPort::QtopiaXXPort( KABC::AddressBook *ab, QWidget *parent, const char *name )
81 : XXPortObject( ab, parent, name ) 81 : XXPortObject( ab, parent, name )
82{ 82{
83 createImportAction( i18n( "Import Qtopia..." ) ); 83 createImportAction( i18n( "Import Qtopia..." ) );
84 createExportAction( i18n( "Export Qtopia..." ) ); 84 createExportAction( i18n( "Export Qtopia..." ) );
85} 85}
86 86
87bool QtopiaXXPort::exportContacts( const KABC::AddresseeList &list, const QString &data ) 87bool QtopiaXXPort::exportContacts( const KABC::AddresseeList &list, const QString &data )
88{ 88{
89 // we can not choose the filename. Therefore use the default to display 89 // we can not choose the filename. Therefore use the default to display
90 QString fileName = QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml"; 90 QString fileName = QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml";
91 91
92 AddressBookAccess* access = new AddressBookAccess(); 92 AddressBookAccess* access = new AddressBookAccess();
93 93
94 if ( !access ) { 94 if ( !access ) {
95 QString text( i18n( "Unable to access file '%1'." ).arg( fileName ) ); 95 QString text( i18n( "Unable to access file '%1'." ).arg( fileName ) );
96 qDebug(text.latin1()); 96 qDebug(text.latin1());
97 KMessageBox::error( parentWidget(), text ); 97 KMessageBox::error( parentWidget(), text );
98 addressBook()->error( text ); 98 addressBook()->error( text );
99 return false; 99 return false;
100 } 100 }
101 101
102 KABC::QtopiaConverter mConverter; 102 KABC::QtopiaConverter mConverter;
103 103
104 bool res = mConverter.init(); 104 bool res = mConverter.init();
105 if (!res) 105 if (!res)
106 { 106 {
107 QString text( i18n( "Unable to initialize qtopia converter.<br>Most likely a problem with the category file." ) ); 107 QString text( i18n( "Unable to initialize qtopia converter.<br>Most likely a problem with the category file." ) );
108 qDebug(text); 108 qDebug(text);
109 KMessageBox::error( parentWidget(), text ); 109 KMessageBox::error( parentWidget(), text );
110 delete access; 110 delete access;
111 return false; 111 return false;
112 } 112 }
113 113
114 //Now check if the file has already entries, and ask the user if he wants to delete them first. 114 //Now check if the file has already entries, and ask the user if he wants to delete them first.
115 { //create a new scope 115 { //create a new scope
116 AddressBookIterator it(*access); 116 AddressBookIterator it(*access);
117 const PimContact* firstcontact = it.toFirst(); 117 const PimContact* firstcontact = it.toFirst();
118 if (firstcontact) 118 if (firstcontact)
119 { 119 {
120 QString text( i18n( "Do you want to remove<br>all existing entries from<br>%1<br>before exporting.?" ) ); 120 QString text( i18n( "Do you want to remove<br>all existing entries from<br>%1<br>before exporting.?" ) );
121 if ( KMessageBox::questionYesNo( parentWidget(), text.arg( fileName ) ) == KMessageBox::Yes ) { 121 if ( KMessageBox::questionYesNo( parentWidget(), text.arg( fileName ) ) == KMessageBox::Yes ) {
122 // Clean the database.. 122 // Clean the database..
123 123
124 AddressBookIterator it2(*access); 124 AddressBookIterator it2(*access);
125 for (it2.toFirst(); it2.current(); ++it2) { 125 for (it2.toFirst(); it2.current(); ++it2) {
126 access->removeContact(*it2.current()); 126 access->removeContact(*it2.current());
127 } 127 }
128 } 128 }
129 } 129 }
130 } 130 }
131 131
132 KABC::Addressee::List::ConstIterator it; 132 KABC::Addressee::List::ConstIterator it;
133 for ( it = list.begin(); it != list.end(); ++it ) { 133 for ( it = list.begin(); it != list.end(); ++it ) {
134 PimContact c; 134 PimContact c;
135 KABC::Addressee addressee = (*it); 135
136
137 res = mConverter.addresseeToQtopia( *it, c ); 136 res = mConverter.addresseeToQtopia( *it, c );
138 if (res == true) 137 if (res == true)
139 { 138 {
140 access->addContact(c); 139 access->addContact(c);
141 } 140 }
142 } 141 }
143 142
144 delete access; 143 delete access;
145 144
146 return true; 145 return true;
147} 146}
148 147
149KABC::AddresseeList QtopiaXXPort::importContacts( const QString& ) const 148KABC::AddresseeList QtopiaXXPort::importContacts( const QString& ) const
150{ 149{
151 KABC::AddresseeList adrlst; 150 KABC::AddresseeList adrlst;
152 151
153 QString fileName = QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml"; 152 QString fileName = QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml";
154 153
155 AddressBookAccess* access = new AddressBookAccess(); 154 AddressBookAccess* access = new AddressBookAccess();
156 155
157 if ( !access ) { 156 if ( !access ) {
158 QString text( i18n( "Unable to access file '%1'." ).arg( fileName ) ); 157 QString text( i18n( "Unable to access file '%1'." ).arg( fileName ) );
159 qDebug(text.latin1()); 158 qDebug(text.latin1());
160 addressBook()->error( text ); 159 addressBook()->error( text );
161 KMessageBox::error( parentWidget(), text ); 160 KMessageBox::error( parentWidget(), text );
162 return KABC::AddresseeList(); 161 return KABC::AddresseeList();
163 } 162 }
164 163
165 KABC::QtopiaConverter mConverter; 164 KABC::QtopiaConverter mConverter;
166 165
167 bool res = mConverter.init(); 166 bool res = mConverter.init();
168 if (!res) 167 if (!res)
169 { 168 {
170 QString text( i18n( "Unable to initialize qtopia converter.<br>Most likely a problem with the category file." ) ); 169 QString text( i18n( "Unable to initialize qtopia converter.<br>Most likely a problem with the category file." ) );
171 qDebug(text); 170 qDebug(text);
172 KMessageBox::error( parentWidget(), text ); 171 KMessageBox::error( parentWidget(), text );
173 delete access; 172 delete access;
174 return KABC::AddresseeList(); 173 return KABC::AddresseeList();
175 } 174 }
176 175
177 176
178 177
179 { //create a new scope 178 { //create a new scope
180 AddressBookIterator it(*access); 179 AddressBookIterator it(*access);
181 180
182 for (it.toFirst(); it.current(); ++it) { 181 for (it.toFirst(); it.current(); ++it) {
183 const PimContact*contact = it.current(); 182 const PimContact*contact = it.current();
184 183
185 KABC::Addressee addressee; 184 KABC::Addressee addressee;
186 185
187 res = mConverter.qtopiaToAddressee( (*contact), addressee ); 186 res = mConverter.qtopiaToAddressee( (*contact), addressee );
188 187
189 if ( !addressee.isEmpty() && res ) 188 if ( !addressee.isEmpty() && res )
190 { 189 {
191 adrlst.append( addressee ); 190 adrlst.append( addressee );
192 } 191 }
193 } 192 }
194 } 193 }
195 194
196 delete access; 195 delete access;
197//US the deletion of the access object deletes the backend object as well. 196//US the deletion of the access object deletes the backend object as well.
198 197
199 return adrlst; 198 return adrlst;
200 199
201} 200}