summaryrefslogtreecommitdiffabout
path: root/kaddressbook/kaimportoldialog.cpp
authorzautrix <zautrix>2006-02-24 18:49:56 (UTC)
committer zautrix <zautrix>2006-02-24 18:49:56 (UTC)
commitd7738fdfc685192eb2f8317db6ffad3c246001c8 (patch) (unidiff)
treed9aae6ca97851fd1b53c4d9e74740a5ee2b69ea9 /kaddressbook/kaimportoldialog.cpp
parent987757f168bbae56100f2aff763b865e81ceec18 (diff)
downloadkdepimpi-d7738fdfc685192eb2f8317db6ffad3c246001c8.zip
kdepimpi-d7738fdfc685192eb2f8317db6ffad3c246001c8.tar.gz
kdepimpi-d7738fdfc685192eb2f8317db6ffad3c246001c8.tar.bz2
kapi sync
Diffstat (limited to 'kaddressbook/kaimportoldialog.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--kaddressbook/kaimportoldialog.cpp712
1 files changed, 0 insertions, 712 deletions
diff --git a/kaddressbook/kaimportoldialog.cpp b/kaddressbook/kaimportoldialog.cpp
index 2f794d6..6afc288 100644
--- a/kaddressbook/kaimportoldialog.cpp
+++ b/kaddressbook/kaimportoldialog.cpp
@@ -21,715 +21,3 @@
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#include <qtooltip.h>
25#include <qframe.h>
26#include <qpixmap.h>
27#include <qlayout.h>
28#include <qprogressbar.h>
29#include <qprogressdialog.h>
30#include <qwidgetstack.h>
31#include <qdatetime.h>
32#include <qdir.h>
33#include <qregexp.h>
34#include <qapplication.h>
35#include <qhbox.h>
36#include <qheader.h>
37#include <qdatetime.h>
38#include <qlistview.h>
39
40#include <kdebug.h>
41#include <klocale.h>
42#include <kstandarddirs.h>
43#include <kmessagebox.h>
44#include <kfiledialog.h>
45
46#include <libkdepim/categoryselectdialog.h>
47#include <libkdepim/kinputdialog.h>
48
49#include <libkcal/calendarlocal.h>
50#include <libkcal/icalformat.h>
51
52#include <kabc/addresseelist.h>
53#include <kabc/phonenumber.h>
54
55#include "kaimportoldialog.h"
56
57#include "../outport/msoutl9.h"
58#include <ole2.h>
59#include <comutil.h>
60_Application gOlAppAB;
61
62QDateTime mDdate2Qdtr( DATE dt)
63{
64 COleDateTime odt;
65 SYSTEMTIME st;
66 odt = dt;
67 if ( odt.GetStatus() != 0 )
68 return QDateTime();
69 odt.GetAsSystemTime(st);
70 if ( st.wYear > 4000 ) // this program as a year 4000 bug!
71 return QDateTime();
72 // it seems so, that 1.1.4501 indicates: DATE invalid
73 QDateTime qdt (QDate(st.wYear, st.wMonth,st.wDay ),QTime( st.wHour, st.wMinute,st.wSecond ) );
74 return qdt;
75}
76
77class OLEListViewItem : public QCheckListItem
78{
79 public:
80 OLEListViewItem( QListView *parent, QString text ) :
81 QCheckListItem( parent, text, QCheckListItem::CheckBox ) { ; };
82 OLEListViewItem( QListViewItem *after, QString text ) :
83 QCheckListItem( after, text, QCheckListItem::CheckBox ) { ; };
84 ~OLEListViewItem() {};
85 void setData( DWORD data ) {mData= data; };
86 DWORD data() { return mData ;};
87 private:
88 DWORD mData;
89};
90
91KAImportOLdialog::KAImportOLdialog( const QString &caption,
92 KABC::AddressBook * aBook, QWidget *parent ) :
93 KDialogBase( Plain, caption, User1 | Close, Ok,
94 parent, caption, true, false, i18n("Import!") )
95{
96 QHBox * mw = new QHBox( this );
97 setMainWidget( mw );
98 mListView = new QListView( mw );
99 mListView->addColumn(i18n("Select Folder to import"));
100 mListView->addColumn(i18n("Content Type"));
101 mABook = aBook;
102 connect( this, SIGNAL( user1Clicked() ),SLOT ( slotApply()));
103 setupFolderView();
104 resize( sizeHint().width()+50, sizeHint().height()+50 );
105}
106
107KAImportOLdialog::~KAImportOLdialog()
108{
109
110}
111
112KABC::Addressee::List KAImportOLdialog::getAddressList()
113{
114 return mAList;
115}
116void KAImportOLdialog::setupFolderView()
117{
118 SCODE sc = ::OleInitialize(NULL);
119 if ( FAILED ( sc ) ) {
120 KMessageBox::information(this,"OLE initialisation failed");
121 return;
122 }
123
124 if(!gOlAppAB.CreateDispatch(_T("Outlook.Application"),NULL)){
125 KMessageBox::information(this,"Sorry, cannot access Outlook");
126 return ;
127 }
128 MAPIFolder mfInbox;
129 MAPIFolder mfRoot;
130 CString szName;
131 _NameSpace olNS;
132 olNS = gOlAppAB.GetNamespace(_T("MAPI"));
133 mfInbox = olNS.GetDefaultFolder(6);
134 mfRoot = mfInbox.GetParent();
135 szName = mfRoot.GetName();
136 long iType = mfRoot.GetDefaultItemType();
137 QString mes;
138 mes = QString::fromUcs2( szName.GetBuffer() );
139 OLEListViewItem * root = new OLEListViewItem( mListView, mes );
140 mfRoot.m_lpDispatch->AddRef();
141 addFolder( root, mfRoot.m_lpDispatch );
142 root->setOpen( true );
143 mListView->setSortColumn( 0 );
144 mListView->sort( );
145}
146
147
148void KAImportOLdialog::addFolder(OLEListViewItem* iParent, LPDISPATCH dispParent)
149{
150 MAPIFolder mfParent(dispParent), mfChild;
151 _Folders folders;
152 _variant_t fndx((long)0);
153 CString szName;
154 long iType;
155 OLEListViewItem* hChild;
156
157 folders = mfParent.GetFolders();
158 for(int i=1; i <= folders.GetCount(); ++i)
159 {
160 fndx = (long)i;
161 mfChild = folders.Item(fndx.Detach());
162 mfChild.m_lpDispatch->AddRef();
163 szName = mfChild.GetName();
164 iType = mfChild.GetDefaultItemType();
165 hChild = new OLEListViewItem( iParent , QString::fromUcs2( szName.GetBuffer() ) );
166 if ( iType != 2)
167 hChild->setEnabled( false );
168 QString ts;
169 switch( iType ) {
170 case 0:
171 ts = i18n("Mail");
172 break;
173 case 1:
174 ts = i18n("Calendar");
175 break;
176 case 2:
177 ts = i18n("Contacts");
178 break;
179 case 3:
180 ts = i18n("Todos");
181 break;
182 case 4:
183 ts = i18n("Journals");
184 break;
185 case 5:
186 ts = i18n("Notes");
187 break;
188 default:
189 ts = i18n("Unknown");
190 }
191 hChild->setText( 1,ts);
192 hChild->setData( (DWORD) mfChild.m_lpDispatch );
193 mfChild.m_lpDispatch->AddRef();
194 addFolder(hChild, mfChild.m_lpDispatch);
195 }
196}
197
198void KAImportOLdialog::slotApply()
199{
200 importedItems = 0;
201 OLEListViewItem* child = (OLEListViewItem*) mListView->firstChild();
202 while ( child ) {
203 if ( child->isOn() )
204 readContactData( child->data() );
205 child = (OLEListViewItem*) child->itemBelow();
206 }
207 QString mes = i18n("Importing complete.\n\n%1 items imported.").arg( importedItems);
208 KMessageBox::information(this,mes);
209}
210void KAImportOLdialog::readContactData( DWORD folder )
211{
212
213 LPDISPATCH dispItem = (LPDISPATCH)folder;
214 dispItem->AddRef();
215 MAPIFolder mf(dispItem);
216 mf.m_lpDispatch->AddRef();
217 _Items folderItems;
218 _variant_t indx((long)0);
219 LPDISPATCH itm;
220 int i;
221 folderItems = mf.GetItems();
222 QProgressDialog bar( i18n("Importing contact data"),i18n("Abort"), folderItems.GetCount(),this);
223 bar.setCaption (i18n("Importing!") );
224 int h = bar.sizeHint().height() ;
225 int w = 300;
226 int dw = QApplication::desktop()->width();
227 int dh = QApplication::desktop()->height();
228 //bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
229 bar.show();
230 for(i=1; i <= folderItems.GetCount(); ++i)
231 {
232 qApp->processEvents();
233 if ( ! bar.isVisible() )
234 return ;
235 bar.setProgress( i );
236 indx = (long)i;
237 itm = folderItems.Item(indx.Detach());
238 _ContactItem * pItem = (_ContactItem *)&itm;
239 ol2kapiContact( pItem );
240 itm->Release();
241 }
242}
243void KAImportOLdialog::slotOk()
244{
245 QDialog::accept();
246}
247
248void KAImportOLdialog::ol2kapiContact( _ContactItem * aItem )
249{
250 KABC::Addressee addressee;
251
252 addressee.setUid( QString::fromUcs2(aItem->GetEntryID().GetBuffer()));
253 //GetLastModificationTime()
254 //addressee.setName( const QString &name );
255 //addressee.setFormattedName( const QString &formattedName );
256 addressee.setFamilyName( QString::fromUcs2(aItem->GetLastName().GetBuffer()) );
257 addressee.setGivenName( QString::fromUcs2(aItem->GetFirstName().GetBuffer()) );
258 addressee.setAdditionalName( QString::fromUcs2(aItem->GetMiddleName().GetBuffer()) );
259 addressee.setPrefix(QString::fromUcs2(aItem->GetTitle().GetBuffer()) );
260 addressee.setSuffix( QString::fromUcs2(aItem->GetSuffix().GetBuffer()) );
261 addressee.setNickName( QString::fromUcs2(aItem->GetNickName().GetBuffer()) );
262 QDateTime dtb = mDdate2Qdtr(aItem->GetBirthday());
263 if ( dtb.isValid() )
264 addressee.setBirthday( mDdate2Qdtr(aItem->GetBirthday()));
265
266 //QString::fromUcs2(aItem->.GetBuffer())
267 //addressee.setMailer( const QString &mailer );
268 //addressee.setTimeZone( const TimeZone &timeZone );
269 //addressee.setGeo( const Geo &geo );
270 //addressee.setTitle( QString::fromUcs2(aItem->GetJobTitle().GetBuffer()) );// titel is the prefix
271 addressee.setRole( QString::fromUcs2(aItem->GetJobTitle().GetBuffer()) );
272 addressee.setOrganization( QString::fromUcs2(aItem->GetCompanyName().GetBuffer()).replace( QRegExp("\\r"), "") );
273 QString notesStr = QString::fromUcs2(aItem->GetBody().GetBuffer());
274 notesStr.replace( QRegExp("\\r"), "");
275
276 addressee.setProductId( QString::fromUcs2(aItem->GetCustomerID().GetBuffer()) );
277 //addressee.setRevision( const QDateTime &revision );
278 // addressee.setSortString( const QString &sortString );
279 addressee.setUrl( QString::fromUcs2(aItem->GetWebPage().GetBuffer()) );
280
281 QString tempS;
282 tempS = QString::fromUcs2(aItem->GetNetMeetingAlias().GetBuffer())+" AT SERVER: " +QString::fromUcs2(aItem->GetNetMeetingServer().GetBuffer());
283 if ( tempS.length() > 12 )
284 addressee.insertCustom( "KADDRESSBOOK", "X-IMAddress", tempS );
285 tempS = QString::fromUcs2(aItem->GetSpouse().GetBuffer());
286 if ( !tempS.isEmpty() )
287 addressee.insertCustom( "KADDRESSBOOK", "X-SpousesName", tempS );
288 tempS = QString::fromUcs2(aItem->GetManagerName().GetBuffer());
289 if ( !tempS.isEmpty() )
290 addressee.insertCustom( "KADDRESSBOOK", "X-ManagersName", tempS );
291 tempS = QString::fromUcs2(aItem->GetAssistantName().GetBuffer());
292 if ( !tempS.isEmpty() )
293 addressee.insertCustom( "KADDRESSBOOK", "X-AssistantsName", tempS );
294 tempS = QString::fromUcs2(aItem->GetDepartment().GetBuffer());
295 if ( !tempS.isEmpty() )
296 addressee.insertCustom( "KADDRESSBOOK", "X-Department", tempS );
297 tempS = QString::fromUcs2(aItem->GetOfficeLocation().GetBuffer()).replace( QRegExp("\\r"), "");
298 if ( !tempS.isEmpty() )
299 addressee.insertCustom( "KADDRESSBOOK", "X-Office",tempS );
300 tempS = QString::fromUcs2(aItem->GetProfession().GetBuffer());
301 if ( !tempS.isEmpty() )
302 addressee.insertCustom( "KADDRESSBOOK", "X-Profession", tempS );
303 dtb = mDdate2Qdtr(aItem->GetAnniversary());
304 if (dtb.isValid() ) {
305 QString dt = KGlobal::locale()->formatDate( dtb.date() , true, KLocale::ISODate);
306 addressee.insertCustom( "KADDRESSBOOK", "X-Anniversary", dt);
307 }
308 int sec = aItem->GetSensitivity() ;
309 if ( sec > 1 )// mapping pers -> private
310 --sec;
311 addressee.setSecrecy( sec );
312 //addressee.setLogo( const Picture &logo );
313 //addressee.setPhoto( const Picture &photo );
314 //addressee.setSound( const Sound &sound );
315 //addressee.setAgent( const Agent &agent );
316 QString cat = QString::fromUcs2( aItem->GetCategories().GetBuffer()).replace( QRegExp("\\r"), "");
317 cat = cat.replace( QRegExp("; "), ";");
318 addressee.setCategories( QStringList::split( ";", cat ));
319
320 QString phoneS;
321
322 phoneS = QString::fromUcs2( aItem->GetAssistantTelephoneNumber().GetBuffer());
323 if ( ! phoneS.isEmpty())
324 addressee.insertPhoneNumber( KABC::PhoneNumber(phoneS ,KABC::PhoneNumber::Work + KABC::PhoneNumber::Voice ) );
325 phoneS = QString::fromUcs2( aItem->GetBusinessTelephoneNumber().GetBuffer());
326 if ( ! phoneS.isEmpty())
327 addressee.insertPhoneNumber( KABC::PhoneNumber(phoneS ,KABC::PhoneNumber::Work ) );
328 phoneS = QString::fromUcs2( aItem->GetBusiness2TelephoneNumber().GetBuffer());
329 if ( ! phoneS.isEmpty())
330 addressee.insertPhoneNumber( KABC::PhoneNumber(phoneS ,KABC::PhoneNumber::Work ) );
331 phoneS = QString::fromUcs2( aItem->GetBusinessFaxNumber().GetBuffer());
332 if ( ! phoneS.isEmpty())
333 addressee.insertPhoneNumber( KABC::PhoneNumber(phoneS ,KABC::PhoneNumber::Work + KABC::PhoneNumber::Fax ) );
334 phoneS = QString::fromUcs2( aItem->GetCarTelephoneNumber().GetBuffer());
335 if ( ! phoneS.isEmpty())
336 addressee.insertPhoneNumber( KABC::PhoneNumber(phoneS ,KABC::PhoneNumber::Car ) );
337 phoneS = QString::fromUcs2( aItem->GetHomeTelephoneNumber().GetBuffer());
338 if ( ! phoneS.isEmpty())
339 addressee.insertPhoneNumber( KABC::PhoneNumber(phoneS ,KABC::PhoneNumber::Home ) );
340 phoneS = QString::fromUcs2( aItem->GetHome2TelephoneNumber().GetBuffer());
341 if ( ! phoneS.isEmpty())
342 addressee.insertPhoneNumber( KABC::PhoneNumber(phoneS ,KABC::PhoneNumber::Home ) );
343 phoneS = QString::fromUcs2( aItem->GetHomeFaxNumber().GetBuffer());
344 if ( ! phoneS.isEmpty())
345 addressee.insertPhoneNumber( KABC::PhoneNumber(phoneS ,KABC::PhoneNumber::Home + KABC::PhoneNumber::Fax ) );
346 phoneS = QString::fromUcs2( aItem->GetISDNNumber().GetBuffer());
347 if ( ! phoneS.isEmpty())
348 addressee.insertPhoneNumber( KABC::PhoneNumber(phoneS ,KABC::PhoneNumber::Isdn ) );
349 phoneS = QString::fromUcs2( aItem->GetMobileTelephoneNumber().GetBuffer());
350 if ( ! phoneS.isEmpty())
351 addressee.insertPhoneNumber( KABC::PhoneNumber(phoneS ,KABC::PhoneNumber::Cell ) );
352 phoneS = QString::fromUcs2( aItem->GetOtherFaxNumber().GetBuffer());
353 if ( ! phoneS.isEmpty())
354 addressee.insertPhoneNumber( KABC::PhoneNumber(phoneS ,KABC::PhoneNumber::Fax ) );
355 phoneS = QString::fromUcs2( aItem->GetOtherTelephoneNumber().GetBuffer());
356 if ( ! phoneS.isEmpty())
357 addressee.insertPhoneNumber( KABC::PhoneNumber(phoneS ,KABC::PhoneNumber::Voice ) );
358 phoneS = QString::fromUcs2( aItem->GetPagerNumber().GetBuffer());
359 if ( ! phoneS.isEmpty())
360 addressee.insertPhoneNumber( KABC::PhoneNumber(phoneS ,KABC::PhoneNumber::Pager ) );
361 phoneS = QString::fromUcs2( aItem->GetPrimaryTelephoneNumber().GetBuffer());
362 if ( ! phoneS.isEmpty())
363 addressee.insertPhoneNumber( KABC::PhoneNumber(phoneS ,KABC::PhoneNumber::Pref ) );
364 phoneS = QString::fromUcs2( aItem->GetTTYTDDTelephoneNumber().GetBuffer());
365 if ( ! phoneS.isEmpty())
366 addressee.insertPhoneNumber( KABC::PhoneNumber(phoneS ,KABC::PhoneNumber::Modem ) );
367 phoneS = QString::fromUcs2( aItem->GetTelexNumber().GetBuffer());
368 if ( ! phoneS.isEmpty())
369 addressee.insertPhoneNumber( KABC::PhoneNumber(phoneS ,KABC::PhoneNumber::Fax + KABC::PhoneNumber::Bbs ) );
370 phoneS = QString::fromUcs2( aItem->GetCompanyMainTelephoneNumber().GetBuffer());
371 if ( ! phoneS.isEmpty())
372 addressee.insertPhoneNumber( KABC::PhoneNumber(phoneS ,KABC::PhoneNumber::Work + KABC::PhoneNumber::Pref ) );
373 phoneS = QString::fromUcs2( aItem->GetRadioTelephoneNumber().GetBuffer());
374 if ( ! phoneS.isEmpty())
375 addressee.insertPhoneNumber( KABC::PhoneNumber(phoneS ,KABC::PhoneNumber::Video ) );
376 phoneS = QString::fromUcs2( aItem->GetCallbackTelephoneNumber().GetBuffer());
377 if ( ! phoneS.isEmpty())
378 addressee.insertPhoneNumber( KABC::PhoneNumber(phoneS ,KABC::PhoneNumber::Voice + KABC::PhoneNumber::Pref ) );
379
380 bool preferred = true;
381 phoneS = QString::fromUcs2( aItem->GetEmail1Address().GetBuffer());
382 if ( ! phoneS.isEmpty()) {
383 addressee.insertEmail(phoneS , preferred );
384 preferred = false;
385 }
386 phoneS = QString::fromUcs2( aItem->GetEmail2Address().GetBuffer());
387 if ( ! phoneS.isEmpty()) {
388 addressee.insertEmail(phoneS , preferred );
389 preferred = false;
390 }
391 phoneS = QString::fromUcs2( aItem->GetEmail3Address().GetBuffer());
392 if ( ! phoneS.isEmpty()) {
393 addressee.insertEmail(phoneS , preferred );
394 preferred = false;
395 }
396 // is this the number of the preferred email?
397 //long GetSelectedMailingAddress();???
398
399 KABC::Address addressHome;
400 KABC::Address* addressAdd = &addressHome;
401 bool insert = false;
402 phoneS = QString::fromUcs2( aItem->GetHomeAddressCountry().GetBuffer());
403 phoneS.replace( QRegExp("\\r"), "");
404 if ( ! phoneS.isEmpty()) {
405 addressAdd->setCountry(phoneS );
406 insert = true;
407 }
408 phoneS = QString::fromUcs2( aItem->GetHomeAddressState().GetBuffer());
409 phoneS.replace( QRegExp("\\r"), "");
410 if ( ! phoneS.isEmpty()) {
411 addressAdd->setRegion(phoneS );
412 insert = true;
413 }
414 phoneS = QString::fromUcs2( aItem->GetHomeAddressCity().GetBuffer());
415 phoneS.replace( QRegExp("\\r"), "");
416 if ( ! phoneS.isEmpty()) {
417 addressAdd->setLocality(phoneS );
418 insert = true;
419 }
420 phoneS = QString::fromUcs2( aItem->GetHomeAddressPostalCode().GetBuffer());
421 phoneS.replace( QRegExp("\\r"), "");
422 if ( ! phoneS.isEmpty()) {
423 addressAdd->setPostalCode(phoneS );
424 insert = true;
425 }
426 phoneS = QString::fromUcs2( aItem->GetHomeAddressPostOfficeBox().GetBuffer());
427 phoneS.replace( QRegExp("\\r"), "");
428 if ( ! phoneS.isEmpty()) {
429 addressAdd->setPostOfficeBox(phoneS );
430 insert = true;
431 }
432 phoneS = QString::fromUcs2( aItem->GetHomeAddressStreet().GetBuffer());
433 phoneS.replace( QRegExp("\\r"), "");
434 if ( ! phoneS.isEmpty()) {
435 addressAdd->setStreet(phoneS );
436 insert = true;
437 }
438 phoneS = QString::fromUcs2( aItem->GetHomeAddress().GetBuffer());
439 phoneS.replace( QRegExp("\\r"), "");
440 if ( ! phoneS.isEmpty()) {
441 // redundant !addressAdd->setExtended(phoneS );
442 // insert = true;
443 }
444 addressAdd->setType( KABC::Address::Home );
445 if ( insert )
446 addressee.insertAddress( *addressAdd );
447 // ++++++++++++++++++++++ end of address
448
449 KABC::Address addressWork;
450 addressAdd = &addressWork;
451 insert = false;
452 phoneS = QString::fromUcs2( aItem->GetBusinessAddressCountry().GetBuffer());
453 phoneS.replace( QRegExp("\\r"), "");
454 if ( ! phoneS.isEmpty()) {
455 addressAdd->setCountry(phoneS );
456 insert = true;
457 }
458 phoneS = QString::fromUcs2( aItem->GetBusinessAddressState().GetBuffer());
459 phoneS.replace( QRegExp("\\r"), "");
460 if ( ! phoneS.isEmpty()) {
461 addressAdd->setRegion(phoneS );
462 insert = true;
463 }
464 phoneS = QString::fromUcs2( aItem->GetBusinessAddressCity().GetBuffer());
465 phoneS.replace( QRegExp("\\r"), "");
466 if ( ! phoneS.isEmpty()) {
467 addressAdd->setLocality(phoneS );
468 insert = true;
469 }
470 phoneS = QString::fromUcs2( aItem->GetBusinessAddressPostalCode().GetBuffer());
471 phoneS.replace( QRegExp("\\r"), "");
472 if ( ! phoneS.isEmpty()) {
473 addressAdd->setPostalCode(phoneS );
474 insert = true;
475 }
476 phoneS = QString::fromUcs2( aItem->GetBusinessAddressPostOfficeBox().GetBuffer());
477 phoneS.replace( QRegExp("\\r"), "");
478 if ( ! phoneS.isEmpty()) {
479 addressAdd->setPostOfficeBox(phoneS );
480 insert = true;
481 }
482 phoneS = QString::fromUcs2( aItem->GetBusinessAddressStreet().GetBuffer());
483 phoneS.replace( QRegExp("\\r"), "");
484 if ( ! phoneS.isEmpty()) {
485 addressAdd->setStreet(phoneS );
486 insert = true;
487 }
488 phoneS = QString::fromUcs2( aItem->GetBusinessAddress().GetBuffer());
489 phoneS.replace( QRegExp("\\r"), "");
490 if ( ! phoneS.isEmpty()) {
491 // redundant !addressAdd->setExtended(phoneS );
492 // insert = true;
493 }
494 addressAdd->setType( KABC::Address::Work );
495 if ( insert )
496 addressee.insertAddress( *addressAdd );
497 // ++++++++++++++++++++++ end of address
498
499 KABC::Address addressOther;
500 addressAdd = &addressOther;
501 insert = false;
502 phoneS = QString::fromUcs2( aItem->GetOtherAddressCountry().GetBuffer());
503 phoneS.replace( QRegExp("\\r"), "");
504 if ( ! phoneS.isEmpty()) {
505 addressAdd->setCountry(phoneS );
506 insert = true;
507 }
508 phoneS = QString::fromUcs2( aItem->GetOtherAddressState().GetBuffer());
509 phoneS.replace( QRegExp("\\r"), "");
510 if ( ! phoneS.isEmpty()) {
511 addressAdd->setRegion(phoneS );
512 insert = true;
513 }
514 phoneS = QString::fromUcs2( aItem->GetOtherAddressCity().GetBuffer());
515 phoneS.replace( QRegExp("\\r"), "");
516 if ( ! phoneS.isEmpty()) {
517 addressAdd->setLocality(phoneS );
518 insert = true;
519 }
520 phoneS = QString::fromUcs2( aItem->GetOtherAddressPostalCode().GetBuffer());
521 phoneS.replace( QRegExp("\\r"), "");
522 if ( ! phoneS.isEmpty()) {
523 addressAdd->setPostalCode(phoneS );
524 insert = true;
525 }
526 phoneS = QString::fromUcs2( aItem->GetOtherAddressPostOfficeBox().GetBuffer());
527 phoneS.replace( QRegExp("\\r"), "");
528 if ( ! phoneS.isEmpty()) {
529 addressAdd->setPostOfficeBox(phoneS );
530 insert = true;
531 }
532 phoneS = QString::fromUcs2( aItem->GetOtherAddressStreet().GetBuffer());
533 phoneS.replace( QRegExp("\\r"), "");
534 if ( ! phoneS.isEmpty()) {
535 addressAdd->setStreet(phoneS );
536 insert = true;
537 }
538 phoneS = QString::fromUcs2( aItem->GetOtherAddress().GetBuffer());
539 if ( ! phoneS.isEmpty()) {
540 // redundant !addressAdd->setExtended(phoneS );
541 //insert = true;
542 }
543 //addressAdd->setId( );
544 if ( insert )
545 addressee.insertAddress( *addressAdd );
546 // ++++++++++++++++++++++ end of address
547 KABC::Address addressMail;
548 addressAdd = &addressMail;
549 insert = false;
550 phoneS = QString::fromUcs2( aItem->GetMailingAddressCountry().GetBuffer());
551 phoneS.replace( QRegExp("\\r"), "");
552 if ( ! phoneS.isEmpty()) {
553 addressAdd->setCountry(phoneS );
554 insert = true;
555 }
556 phoneS = QString::fromUcs2( aItem->GetMailingAddressState().GetBuffer());
557 phoneS.replace( QRegExp("\\r"), "");
558 if ( ! phoneS.isEmpty()) {
559 addressAdd->setRegion(phoneS );
560 insert = true;
561 }
562 phoneS = QString::fromUcs2( aItem->GetMailingAddressCity().GetBuffer());
563 phoneS.replace( QRegExp("\\r"), "");
564 if ( ! phoneS.isEmpty()) {
565 addressAdd->setLocality(phoneS );
566 insert = true;
567 }
568 phoneS = QString::fromUcs2( aItem->GetMailingAddressPostalCode().GetBuffer());
569 phoneS.replace( QRegExp("\\r"), "");
570 if ( ! phoneS.isEmpty()) {
571 addressAdd->setPostalCode(phoneS );
572 insert = true;
573 }
574 phoneS = QString::fromUcs2( aItem->GetMailingAddressPostOfficeBox().GetBuffer());
575 phoneS.replace( QRegExp("\\r"), "");
576 if ( ! phoneS.isEmpty()) {
577 addressAdd->setPostOfficeBox(phoneS );
578 insert = true;
579 }
580 phoneS = QString::fromUcs2( aItem->GetMailingAddressStreet().GetBuffer());
581 phoneS.replace( QRegExp("\\r"), "");
582 if ( ! phoneS.isEmpty()) {
583 addressAdd->setStreet(phoneS );
584 insert = true;
585 }
586 phoneS = QString::fromUcs2( aItem->GetMailingAddress().GetBuffer());
587 phoneS.replace( QRegExp("\\r"), "");
588 if ( ! phoneS.isEmpty()) {
589 // redundant ! addressAdd->setExtended(phoneS );
590 // insert = true;
591 }
592 addressAdd->setType( KABC::Address::Postal );
593 if ( insert ) {
594 addressee.insertAddress( *addressAdd );
595 }
596 // the following code is disabled
597 // it does not seem to be useful
598#if 0
599 if ( insert ) {
600 addressAdd->setType( KABC::Address::Home );
601 if ( addressMail == addressHome ) {
602 addressHome.setType( KABC::Address::Postal+ KABC::Address::Home );
603 addressee.insertAddress( addressHome );
604 } else {
605 addressAdd->setType( KABC::Address::Work );
606 if ( addressMail == addressWork ){
607 addressWork.setType( KABC::Address::Postal+ KABC::Address::Work );
608 addressee.insertAddress( addressWork );
609
610 } else {
611 addressAdd->setType( 0 );
612 if ( addressOther == addressMail ){
613 addressOther.setType( KABC::Address::Postal );
614 addressee.insertAddress( addressOther );
615 } else {
616 addressee.insertAddress( *addressAdd );
617 }
618 }
619 }
620 }
621#endif
622 // ++++++++++++++++++++++ end of ALL addresses
623 //GetUserProperties();
624 tempS = QString::fromUcs2(aItem->GetInternetFreeBusyAddress().GetBuffer());
625 phoneS.replace( QRegExp("\\r"), "");
626 if ( !tempS.isEmpty() )
627 addressee.insertCustom( "KADDRESSBOOK", "X-FreeBusyUrl", tempS );
628 tempS = QString::fromUcs2(aItem->GetChildren().GetBuffer());
629 if ( !tempS.isEmpty() )
630 addressee.insertCustom( "KADDRESSBOOK", "X-Children", tempS );
631 int gen = aItem->GetGender();
632 if ( gen != 0 ) { // 0 undef - 1 female - 2 male
633 if ( gen == 1 )
634 addressee.insertCustom( "KADDRESSBOOK", "X-Gender", "female" );
635 else
636 addressee.insertCustom( "KADDRESSBOOK", "X-Gender", "male" );
637 }
638 QString additionalInfo;
639 QString tempAdd;
640 tempAdd = QString::fromUcs2(aItem->GetLanguage().GetBuffer());
641 if ( ! tempAdd.isEmpty() ) {
642 additionalInfo += i18n("\nLanguage: ");
643 additionalInfo += tempAdd;
644 }
645 tempAdd = QString::fromUcs2(aItem->GetHobby().GetBuffer());
646 phoneS.replace( QRegExp("\\r"), "");
647 if ( ! tempAdd.isEmpty() ) {
648 additionalInfo += i18n("\nHobby: ");
649 additionalInfo += tempAdd;;
650 }
651 tempAdd =QString::fromUcs2(aItem->GetPersonalHomePage().GetBuffer());
652 phoneS.replace( QRegExp("\\r"), "");
653 if ( ! tempAdd.isEmpty() ) {
654 additionalInfo += i18n("\nHomepage: ");
655 additionalInfo += tempAdd;;
656 }
657 tempAdd = QString::fromUcs2(aItem->GetBillingInformation().GetBuffer());
658 phoneS.replace( QRegExp("\\r"), "");
659 if ( ! tempAdd.isEmpty() ) {
660 additionalInfo += i18n("\nBilling information: ");
661 additionalInfo += tempAdd;;
662 }
663 tempAdd = QString::fromUcs2(aItem->GetCustomerID().GetBuffer());
664 phoneS.replace( QRegExp("\\r"), "");
665 if ( ! tempAdd.isEmpty() ) {
666 additionalInfo += i18n("\nCustomer ID: ");
667 additionalInfo += tempAdd;;
668 }
669 tempAdd = QString::fromUcs2(aItem->GetUser1().GetBuffer());
670 phoneS.replace( QRegExp("\\r"), "");
671 if ( ! tempAdd.isEmpty() ) {
672 additionalInfo += i18n("\nUser1: ");
673 additionalInfo += tempAdd;;
674 }
675 tempAdd = QString::fromUcs2(aItem->GetUser2().GetBuffer());
676 phoneS.replace( QRegExp("\\r"), "");
677 if ( ! tempAdd.isEmpty() ) {
678 additionalInfo += i18n("\nUser2: ");
679 additionalInfo += tempAdd;;
680 }
681 tempAdd = QString::fromUcs2(aItem->GetUser3().GetBuffer());
682 phoneS.replace( QRegExp("\\r"), "");
683 if ( ! tempAdd.isEmpty() ) {
684 additionalInfo += i18n("\nUser3: ");
685 additionalInfo += tempAdd;;
686 }
687 tempAdd = QString::fromUcs2(aItem->GetUser4().GetBuffer());
688 phoneS.replace( QRegExp("\\r"), "");
689 if ( ! tempAdd.isEmpty() ) {
690 additionalInfo += i18n("\nUser4: ");
691 additionalInfo += tempAdd;;
692 }
693 if (!additionalInfo.isEmpty() ) {
694 tempAdd = notesStr;
695 notesStr = "+++++++++++++++++++++++++++\n";
696 notesStr += i18n("Additonal fields created\nby KA/Pi Outlook import:");
697 notesStr += additionalInfo;
698 notesStr += i18n("\nEnd additonal fields created\nby KA/Pi Outlook import!\n");
699 notesStr += "+++++++++++++++++++++++++++\n";
700 notesStr += tempAdd;
701 }
702 addressee.setNote( notesStr );
703#if 0
704 // pending
705 - IM address: no clue where to get info about the helper ID
706 -custom fields: difficult to implement - not implemented
707 -keys: makes no sense
708#endif
709
710 if ( addAddressee( addressee ))
711 ++importedItems;
712}
713void KAImportOLdialog::slotCancel()
714{
715 reject();
716}
717
718bool KAImportOLdialog::addAddressee( KABC::Addressee a )
719{
720 bool add = true;
721 KABC::Addressee::List::Iterator it;
722 for ( it = mAList.begin(); it != mAList.end(); ++it ) {
723 if ( (*it).uid() == a.uid() ) {
724 add = false;
725 break;
726 }
727 }
728 if ( add ) {
729 if ( mABook->findByUid(a.uid() ).isEmpty())
730 mAList.append ( a );
731 else
732 add = false;
733 }
734 return add;
735}