Diffstat (limited to 'kaddressbook/xxport/qtopia_xxport.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | kaddressbook/xxport/qtopia_xxport.cpp | 221 |
1 files changed, 6 insertions, 215 deletions
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 | |||
@@ -32,27 +32,4 @@ $Id$ | |||
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" |
@@ -85,9 +62,3 @@ QtopiaXXPort::QtopiaXXPort( KABC::AddressBook *ab, QWidget *parent, const char * | |||
85 | 62 | ||
86 | KRES::Factory* mFactory = KRES::Factory::self( "contact" ); | 63 | if ( mFactory && !mFactory->typeName( "qtopia" ).isEmpty() ) |
87 | |||
88 | if ( mFactory ) | ||
89 | { | ||
90 | mResource = (KABC::Resource*)(mFactory->resource( "qtopia", 0, false )); | ||
91 | |||
92 | if ( mResource ) | ||
93 | { | 64 | { |
@@ -97,191 +68,11 @@ QtopiaXXPort::QtopiaXXPort( KABC::AddressBook *ab, QWidget *parent, const char * | |||
97 | } | 68 | } |
98 | } | ||
99 | |||
100 | bool QtopiaXXPort::exportContacts( const KABC::AddresseeList &list, const QString &data ) | ||
101 | { | ||
102 | /*US | ||
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 | 69 | ||
202 | 70 | bool QtopiaXXPort::exportContacts( const KABC::AddresseeList &list, const QString &identifier ) | |
203 | |||
204 | } | ||
205 | |||
206 | KABC::AddresseeList QtopiaXXPort::importContacts( const QString& ) const | ||
207 | { | 71 | { |
208 | /*US | 72 | return _exportContacts( list, 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 | } | 73 | } |
222 | 74 | ||
223 | KABC::QtopiaConverter mConverter; | 75 | KABC::AddresseeList QtopiaXXPort::importContacts( const QString &identifier ) const |
224 | |||
225 | bool res = mConverter.init(); | ||
226 | if (!res) | ||
227 | { | 76 | { |
228 | QString text( i18n( "Unable to initialize qtopia converter.<br>Most likely a problem with the category file." ) ); | 77 | return _importContacts( identifier, defaultFileName ); |
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 | } |