author | ulf69 <ulf69> | 2004-08-03 20:49:15 (UTC) |
---|---|---|
committer | ulf69 <ulf69> | 2004-08-03 20:49:15 (UTC) |
commit | be52d7d03e57620919b23cb0cbb33ac22d0920e0 (patch) (unidiff) | |
tree | 34e8e29a221c828424126694f865d702c7635f97 /kaddressbook/xxport/sharpdtm_xxport.cpp | |
parent | d5358380edce9a2c39f3eea4df741a148338880c (diff) | |
download | kdepimpi-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/xxport/sharpdtm_xxport.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | kaddressbook/xxport/sharpdtm_xxport.cpp | 224 |
1 files changed, 6 insertions, 218 deletions
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 | |||
@@ -28,32 +28,8 @@ Copyright (c) 2004 Ulf Schenk | |||
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 |
@@ -78,207 +54,19 @@ extern "C" | |||
78 | SharpDTMXXPort::SharpDTMXXPort( KABC::AddressBook *ab, QWidget *parent, const char *name ) | 54 | SharpDTMXXPort::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 | { | ||
85 | mResource = (KABC::Resource*)(mFactory->resource( "sharpdtm", 0, false )); | ||
86 | if ( mResource ) | ||
87 | { | 58 | { |
88 | createImportAction( i18n( "Import Sharp..." ) ); | 59 | createImportAction( i18n( "Import Sharp..." ) ); |
89 | createExportAction( i18n( "Export Sharp..." ) ); | 60 | createExportAction( i18n( "Export Sharp..." ) ); |
90 | } | 61 | } |
91 | } | 62 | } |
92 | } | ||
93 | |||
94 | bool SharpDTMXXPort::exportContacts( const KABC::AddresseeList &list, const QString &data ) | ||
95 | { | ||
96 | /*US | ||
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 | } | ||
197 | |||
198 | KABC::AddresseeList SharpDTMXXPort::importContacts( const QString& ) const | ||
199 | { | ||
200 | /*US | ||
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 | 63 | ||
220 | bool res = mConverter.init(); | 64 | bool SharpDTMXXPort::exportContacts( const KABC::AddresseeList &list, const QString &identifier ) |
221 | if (!res) | ||
222 | { | 65 | { |
223 | QString text( i18n( "Unable to initialize sharp converter.<br>Most likely a problem with the category file." ) ); | 66 | return _exportContacts( list, identifier, QString::null ); |
224 | qDebug(text); | ||
225 | KMessageBox::error( parentWidget(), text ); | ||
226 | delete access; | ||
227 | return KABC::AddresseeList(); | ||
228 | } | 67 | } |
229 | 68 | ||
230 | 69 | KABC::AddresseeList SharpDTMXXPort::importContacts( const QString &identifier ) const | |
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 | { | 70 | { |
243 | adrlst.append( addressee ); | 71 | return _importContacts( identifier, QString::null ); |
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 | } |