author | zautrix <zautrix> | 2006-02-24 18:52:41 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2006-02-24 18:52:41 (UTC) |
commit | 08605356c77351d64e14e0fdd69bdb769f933909 (patch) (unidiff) | |
tree | be4578be1458a6b71f95b7f5fee29a9ca4658132 | |
parent | d7738fdfc685192eb2f8317db6ffad3c246001c8 (diff) | |
download | kdepimpi-08605356c77351d64e14e0fdd69bdb769f933909.zip kdepimpi-08605356c77351d64e14e0fdd69bdb769f933909.tar.gz kdepimpi-08605356c77351d64e14e0fdd69bdb769f933909.tar.bz2 |
files added
-rwxr-xr-x | libkdepim/ol_access.cpp | 2205 | ||||
-rwxr-xr-x | libkdepim/ol_access.h | 174 |
2 files changed, 2379 insertions, 0 deletions
diff --git a/libkdepim/ol_access.cpp b/libkdepim/ol_access.cpp new file mode 100755 index 0000000..1b05693 --- a/dev/null +++ b/libkdepim/ol_access.cpp | |||
@@ -0,0 +1,2205 @@ | |||
1 | /* | ||
2 | This file is part of KDE-Pim/Pi. | ||
3 | Copyright (c) 2006 Lutz Rogowski <rogowski@kde.org> | ||
4 | |||
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 | ||
7 | the Free Software Foundation; either version 2 of the License, or | ||
8 | (at your option) any later version. | ||
9 | |||
10 | This program is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | GNU General Public License for more details. | ||
14 | |||
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 | ||
17 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | ||
18 | |||
19 | As a special exception, permission is given to link this program | ||
20 | with any edition of Qt, and distribute the resulting executable, | ||
21 | without including the source code for Qt in the source distribution. | ||
22 | */ | ||
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 <qpushbutton.h> | ||
34 | #include <qregexp.h> | ||
35 | #include <qapplication.h> | ||
36 | #include <qhbox.h> | ||
37 | #include <qheader.h> | ||
38 | #include <qdatetime.h> | ||
39 | #include <qlistview.h> | ||
40 | |||
41 | #include <kdebug.h> | ||
42 | #include <klocale.h> | ||
43 | #include <kstandarddirs.h> | ||
44 | #include <kmessagebox.h> | ||
45 | #include <kfiledialog.h> | ||
46 | #include <kstaticdeleter.h> | ||
47 | #include <kdialogbase.h> | ||
48 | |||
49 | |||
50 | #include <ol_access.h> | ||
51 | |||
52 | #include "../outport/msoutl9.h" | ||
53 | #include <ole2.h> | ||
54 | #include <comutil.h> | ||
55 | |||
56 | |||
57 | class OLEListViewItem : public QCheckListItem | ||
58 | { | ||
59 | public: | ||
60 | OLEListViewItem( QListView *parent, QString text ) : | ||
61 | QCheckListItem( parent, text, QCheckListItem::CheckBox ) { ; }; | ||
62 | OLEListViewItem( QListViewItem *after, QString text ) : | ||
63 | QCheckListItem( after, text, QCheckListItem::CheckBox ) { ; }; | ||
64 | ~OLEListViewItem() {}; | ||
65 | void setData( DWORD data ) {mData= data; }; | ||
66 | void setDataID( QString data ){ mDataID = data ;} | ||
67 | QString dataID() { return mDataID;} | ||
68 | DWORD data() { return mData ;}; | ||
69 | private: | ||
70 | DWORD mData; | ||
71 | QString mDataID; | ||
72 | }; | ||
73 | |||
74 | class OLEFolderSelect : public KDialogBase | ||
75 | { | ||
76 | public: | ||
77 | OLEFolderSelect() : | ||
78 | KDialogBase( Plain, "", Ok | Cancel, Ok, | ||
79 | 0, "", true, false, i18n("Import!") ) | ||
80 | { | ||
81 | QHBox * mw = new QHBox( this ); | ||
82 | setMainWidget( mw ); | ||
83 | mListView = new QListView( mw ); | ||
84 | mListView->addColumn(i18n("Select Folder")); | ||
85 | mListView->addColumn(i18n("Content Type")); | ||
86 | } | ||
87 | QListView* listView() { return mListView;} | ||
88 | private: | ||
89 | QListView* mListView; | ||
90 | }; | ||
91 | |||
92 | OL_access *OL_access::sInstance = 0; | ||
93 | static KStaticDeleter<OL_access> staticDeleterPim; | ||
94 | |||
95 | OL_access *OL_access::instance() | ||
96 | { | ||
97 | if ( !sInstance ) { | ||
98 | sInstance = staticDeleterPim.setObject( new OL_access() ); | ||
99 | } | ||
100 | return sInstance; | ||
101 | } | ||
102 | |||
103 | |||
104 | OL_access::OL_access() | ||
105 | { | ||
106 | mErrorInit = true; | ||
107 | SCODE sc = ::OleInitialize(NULL); | ||
108 | if ( FAILED ( sc ) ) { | ||
109 | KMessageBox::information( 0 ,i18n("OLE initialisation failed" )); | ||
110 | return; | ||
111 | } | ||
112 | if(!gOlAppAB.CreateDispatch(_T("Outlook.Application"),NULL)){ | ||
113 | KMessageBox::information( 0, i18n("Sorry, cannot access Outlook") ); | ||
114 | return ; | ||
115 | } | ||
116 | mErrorInit = false; | ||
117 | } | ||
118 | OL_access::~OL_access() | ||
119 | { | ||
120 | if (sInstance == this) | ||
121 | sInstance = staticDeleterPim.setObject(0); | ||
122 | } | ||
123 | |||
124 | KABC::Addressee::List OL_access::importOLcontacts() | ||
125 | { | ||
126 | KABC::Addressee::List retval; | ||
127 | if ( mErrorInit ) | ||
128 | return retval; | ||
129 | QStringList folderList = getFolderSelection( OL_CONTACT_DATA , i18n("Select Folders to import")); | ||
130 | int numFolders = folderList.count()/2; | ||
131 | int i; | ||
132 | for ( i = 0; i < numFolders; ++i ) { | ||
133 | readContactData( getFolderFromID( 0, folderList[(i*2)+1] ) , &retval, false ); | ||
134 | } | ||
135 | KMessageBox::information( 0, i18n("%1 contacts read").arg( retval.count() ) ); | ||
136 | return retval; | ||
137 | } | ||
138 | void OL_access::readContactData( LPDISPATCH dispItem, KABC::Addressee::List* list, bool syncMode ) | ||
139 | { | ||
140 | dispItem->AddRef(); | ||
141 | MAPIFolder mf(dispItem); | ||
142 | mf.m_lpDispatch->AddRef(); | ||
143 | _Items folderItems; | ||
144 | _variant_t indx((long)0); | ||
145 | LPDISPATCH itm; | ||
146 | int i; | ||
147 | folderItems = mf.GetItems(); | ||
148 | QString cap = i18n("Importing contact data"); | ||
149 | if ( syncMode ) { | ||
150 | cap = i18n("Reading contact data..."); | ||
151 | } | ||
152 | QProgressDialog bar( cap,i18n("Abort"), folderItems.GetCount(), 0 ); | ||
153 | bar.setCaption (i18n("Accessing OL") ); | ||
154 | int h = bar.sizeHint().height() ; | ||
155 | int w = 300; | ||
156 | int dw = QApplication::desktop()->width(); | ||
157 | int dh = QApplication::desktop()->height(); | ||
158 | bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); | ||
159 | bar.show(); | ||
160 | for(i=1; i <= folderItems.GetCount(); ++i) | ||
161 | { | ||
162 | qApp->processEvents(); | ||
163 | if ( ! bar.isVisible() ) | ||
164 | return ; | ||
165 | bar.setProgress( i ); | ||
166 | indx = (long)i; | ||
167 | itm = folderItems.Item(indx.Detach()); | ||
168 | _ContactItem * pItem = (_ContactItem *)&itm; | ||
169 | list->append( ol2kapiContact( pItem, syncMode ) ); | ||
170 | itm->Release(); | ||
171 | } | ||
172 | } | ||
173 | QStringList OL_access::getFolderSelection( int type , QString caption ) | ||
174 | { | ||
175 | OLEFolderSelect folder_dialog; | ||
176 | QListView * listView = folder_dialog.listView(); | ||
177 | MAPIFolder mfInbox; | ||
178 | MAPIFolder mfRoot; | ||
179 | CString szName; | ||
180 | _NameSpace olNS; | ||
181 | olNS = gOlAppAB.GetNamespace(_T("MAPI")); | ||
182 | mfInbox = olNS.GetDefaultFolder(6); | ||
183 | mfRoot = mfInbox.GetParent(); | ||
184 | szName = mfRoot.GetName(); | ||
185 | long iType = mfRoot.GetDefaultItemType(); | ||
186 | QString mes; | ||
187 | mes = QString::fromUcs2( szName.GetBuffer() ); | ||
188 | OLEListViewItem * root = new OLEListViewItem( listView, mes ); | ||
189 | mfRoot.m_lpDispatch->AddRef(); | ||
190 | addFolder( root, mfRoot.m_lpDispatch, type ); | ||
191 | root->setOpen( true ); | ||
192 | listView->setSortColumn( 0 ); | ||
193 | listView->sort( ); | ||
194 | folder_dialog.setCaption( caption ); | ||
195 | QStringList retval; | ||
196 | folder_dialog.resize( folder_dialog.sizeHint().width()+50, folder_dialog.sizeHint().height()+50 ); | ||
197 | if ( folder_dialog.exec() ) { | ||
198 | OLEListViewItem* child = (OLEListViewItem*) listView->firstChild(); | ||
199 | while ( child ) { | ||
200 | if ( child->isOn() && ! child->firstChild() ) { | ||
201 | retval << child->text( 0 ); | ||
202 | retval << child->dataID(); | ||
203 | } | ||
204 | child = (OLEListViewItem*) child->itemBelow(); | ||
205 | } | ||
206 | //KMessageBox::information(0,retval.join(" \n ")); | ||
207 | } | ||
208 | return retval; | ||
209 | } | ||
210 | void OL_access::addFolder(OLEListViewItem* iParent, LPDISPATCH dispParent, long fType) | ||
211 | { | ||
212 | MAPIFolder mfParent(dispParent), mfChild; | ||
213 | _Folders folders; | ||
214 | _variant_t fndx((long)0); | ||
215 | CString szName; | ||
216 | long iType; | ||
217 | OLEListViewItem* hChild; | ||
218 | |||
219 | folders = mfParent.GetFolders(); | ||
220 | for(int i=1; i <= folders.GetCount(); ++i) | ||
221 | { | ||
222 | iParent->setEnabled( true ); | ||
223 | fndx = (long)i; | ||
224 | mfChild = folders.Item(fndx.Detach()); | ||
225 | mfChild.m_lpDispatch->AddRef(); | ||
226 | szName = mfChild.GetName(); | ||
227 | iType = mfChild.GetDefaultItemType(); | ||
228 | hChild = new OLEListViewItem( iParent , QString::fromUcs2( szName.GetBuffer() ) ); | ||
229 | hChild->setDataID( QString::fromUcs2(mfChild.GetEntryID().GetBuffer()) ); | ||
230 | if ( iType != fType) | ||
231 | hChild->setEnabled( false ); | ||
232 | QString ts; | ||
233 | switch( iType ) { | ||
234 | case 0: | ||
235 | ts = i18n("Mail"); | ||
236 | break; | ||
237 | case 1: | ||
238 | ts = i18n("Calendar"); | ||
239 | break; | ||
240 | case 2: | ||
241 | ts = i18n("Contacts"); | ||
242 | break; | ||
243 | case 3: | ||
244 | ts = i18n("Todos"); | ||
245 | break; | ||
246 | case 4: | ||
247 | ts = i18n("Journals"); | ||
248 | break; | ||
249 | case 5: | ||
250 | ts = i18n("Notes"); | ||
251 | break; | ||
252 | default: | ||
253 | ts = i18n("Unknown"); | ||
254 | } | ||
255 | hChild->setText( 1,ts); | ||
256 | hChild->setData( (DWORD) mfChild.m_lpDispatch ); | ||
257 | mfChild.m_lpDispatch->AddRef(); | ||
258 | addFolder(hChild, mfChild.m_lpDispatch, fType); | ||
259 | } | ||
260 | } | ||
261 | |||
262 | void OL_access::deleteAddressee( KABC::Addressee a ) | ||
263 | { | ||
264 | LPDISPATCH itm = getOLcontactItemFromUid ( a.originalExternalUID() ); | ||
265 | _ContactItem* cItem = (_ContactItem *)&itm; | ||
266 | if ( cItem != 0 ) { | ||
267 | //KMessageBox::information(0,"delete: item found " + a.formattedName() + QString::fromUcs2(cItem->GetLastName().GetBuffer())); | ||
268 | cItem->Delete(); | ||
269 | } | ||
270 | } | ||
271 | KABC::Addressee OL_access::changeAddressee( KABC::Addressee a ) | ||
272 | { | ||
273 | LPDISPATCH itm = getOLcontactItemFromUid ( a.originalExternalUID() ); | ||
274 | _ContactItem* cItem = (_ContactItem *)&itm; | ||
275 | if ( cItem != 0 ) { | ||
276 | //KMessageBox::information(0,"Change: item found " + a.formattedName()); | ||
277 | writeData2OLitem( a, cItem ); | ||
278 | KABC::Addressee retval = ol2kapiContact( cItem , true ); | ||
279 | retval.setUid( a.uid() ); | ||
280 | retval.setExternalUID( a.originalExternalUID() ); | ||
281 | retval.setOriginalExternalUID( a.originalExternalUID() ); | ||
282 | return retval; | ||
283 | } | ||
284 | return KABC::Addressee(); | ||
285 | } | ||
286 | KABC::Addressee OL_access::addAddressee( KABC::Addressee a ) | ||
287 | { | ||
288 | QString newOLid; | ||
289 | LPDISPATCH c_itm = gOlAppAB.CreateItem(2); | ||
290 | _ContactItem * aItem = (_ContactItem *)&c_itm ; | ||
291 | writeData2OLitem( a, aItem ); | ||
292 | newOLid = QString::fromUcs2(aItem->GetEntryID().GetBuffer()); | ||
293 | KABC::Addressee retval = ol2kapiContact( aItem , true ); | ||
294 | retval.setUid( a.uid() ); | ||
295 | retval.setExternalUID( newOLid ); | ||
296 | retval.setOriginalExternalUID( newOLid ); | ||
297 | return retval; | ||
298 | } | ||
299 | |||
300 | LPDISPATCH OL_access::getOLcontactItemFromUid( QString uid ) | ||
301 | { | ||
302 | _variant_t indx((long)0); | ||
303 | LPDISPATCH itm; | ||
304 | int i; | ||
305 | for(i=1; i <= mFolderItems.GetCount(); ++i) | ||
306 | { | ||
307 | qApp->processEvents(); | ||
308 | indx = (long)i; | ||
309 | itm = mFolderItems.Item(indx.Detach()); | ||
310 | _ContactItem * pItem = (_ContactItem *)&itm; | ||
311 | if ( QString::fromUcs2(pItem->GetEntryID().GetBuffer()) == uid ) | ||
312 | return itm; | ||
313 | itm->Release(); | ||
314 | } | ||
315 | return 0; | ||
316 | } | ||
317 | bool OL_access::setSelectedFolder( QString folderID ) | ||
318 | { | ||
319 | if ( mErrorInit ) | ||
320 | return false; | ||
321 | mSelectedFolderID = folderID; | ||
322 | mSelectedFolder = getFolderFromID( 0,mSelectedFolderID ); | ||
323 | if ( mSelectedFolder == 0 ) { | ||
324 | KMessageBox::information(0,i18n("OL access: No folder found for id\n%1").arg( mSelectedFolderID )); | ||
325 | return false; | ||
326 | } | ||
327 | LPDISPATCH dispItem = mSelectedFolder; | ||
328 | dispItem->AddRef(); | ||
329 | MAPIFolder mf(dispItem); | ||
330 | mf.m_lpDispatch->AddRef(); | ||
331 | mFolderItems = mf.GetItems(); | ||
332 | return true; | ||
333 | } | ||
334 | |||
335 | QDateTime OL_access::mDdate2Qdtr( DATE dt) | ||
336 | { | ||
337 | COleDateTime odt; | ||
338 | SYSTEMTIME st; | ||
339 | odt = dt; | ||
340 | if ( odt.GetStatus() != 0 ) | ||
341 | return QDateTime(); | ||
342 | odt.GetAsSystemTime(st); | ||
343 | if ( st.wYear > 4000 ) // this program as a year 4000 bug! | ||
344 | return QDateTime(); | ||
345 | // it seems so, that 1.1.4501 indicates: DATE invalid | ||
346 | QDateTime qdt (QDate(st.wYear, st.wMonth,st.wDay ),QTime( st.wHour, st.wMinute,st.wSecond ) ); | ||
347 | return qdt; | ||
348 | } | ||
349 | DATE OL_access::Qdt2date( QDateTime dt ) | ||
350 | { | ||
351 | DATE ddd; | ||
352 | COleDateTime odt; | ||
353 | odt.SetDateTime(dt.date().year(), dt.date().month(),dt.date().day(), | ||
354 | dt.time().hour(), dt.time().minute(), dt.time().second() ); | ||
355 | ddd = odt; | ||
356 | return ddd; | ||
357 | } | ||
358 | |||
359 | LPDISPATCH OL_access::getFolderFromID( LPDISPATCH parentFolder, QString selectedFolderID ) | ||
360 | { | ||
361 | if ( parentFolder == 0 ) { | ||
362 | MAPIFolder mfInbox; | ||
363 | MAPIFolder mfRoot; | ||
364 | CString szName; | ||
365 | _NameSpace olNS; | ||
366 | olNS = gOlAppAB.GetNamespace(_T("MAPI")); | ||
367 | mfInbox = olNS.GetDefaultFolder(6); | ||
368 | mfRoot = mfInbox.GetParent(); | ||
369 | szName = mfRoot.GetName(); | ||
370 | mfRoot.m_lpDispatch->AddRef(); | ||
371 | return getFolderFromID( mfRoot.m_lpDispatch ,selectedFolderID); | ||
372 | } | ||
373 | |||
374 | MAPIFolder mfParent(parentFolder), mfChild; | ||
375 | _Folders folders; | ||
376 | _variant_t fndx((long)0); | ||
377 | CString szName; | ||
378 | long iType; | ||
379 | OLEListViewItem* hChild; | ||
380 | folders = mfParent.GetFolders(); | ||
381 | for(int i=1; i <= folders.GetCount(); ++i) | ||
382 | { | ||
383 | fndx = (long)i; | ||
384 | mfChild = folders.Item(fndx.Detach()); | ||
385 | mfChild.m_lpDispatch->AddRef(); | ||
386 | szName = mfChild.GetName(); | ||
387 | iType = mfChild.GetDefaultItemType(); | ||
388 | if ( selectedFolderID == QString::fromUcs2(mfChild.GetEntryID().GetBuffer()) ) { | ||
389 | return mfChild.m_lpDispatch; | ||
390 | } | ||
391 | LPDISPATCH resultFolder = getFolderFromID(mfChild.m_lpDispatch ,selectedFolderID); | ||
392 | if ( resultFolder != 0 ) | ||
393 | return resultFolder; | ||
394 | } | ||
395 | return 0; | ||
396 | } | ||
397 | void OL_access::writeData2OLitem( KABC::Addressee addressee, _ContactItem * aItem ) | ||
398 | { | ||
399 | // addressee.setUid( QString::fromUcs2(aItem->GetEntryID().GetBuffer())); | ||
400 | //GetLastModificationTime() | ||
401 | //addressee.setName( const QString &name ); | ||
402 | |||
403 | aItem->SetFileAs(addressee.formattedName().ucs2()); | ||
404 | aItem->SetLastName(addressee.familyName().ucs2()); | ||
405 | aItem->SetFirstName(addressee.givenName( ).ucs2()); | ||
406 | aItem->SetMiddleName(addressee.additionalName( ).ucs2()); | ||
407 | aItem->SetTitle(addressee.prefix().ucs2()); | ||
408 | aItem->SetSuffix(addressee.suffix( ).ucs2()); | ||
409 | aItem->SetNickName(addressee.nickName( ).ucs2()); | ||
410 | if ( addressee.birthday().isValid() ) | ||
411 | aItem->SetBirthday(Qdt2date(addressee.birthday())); | ||
412 | else | ||
413 | aItem->SetBirthday(Qdt2date(QDateTime(QDate( 4501,1,1 )))); | ||
414 | //).ucs2()(aItem->) | ||
415 | //addressee.Mailer( const QString &mailer ); | ||
416 | //addressee.TimeZone( const TimeZone &timeZone ); | ||
417 | //addressee.Geo( const Geo &geo ); | ||
418 | //addressee.Title( ).ucs2()(aItem->SetJobTitle()) );// titel is the prefix | ||
419 | aItem->SetJobTitle(addressee.role( ).ucs2()); | ||
420 | aItem->SetCompanyName(addressee.organization( ).ucs2()); | ||
421 | QString notesStr = addressee.note(); | ||
422 | notesStr.replace( QRegExp("\\n"), "\n\r"); | ||
423 | aItem->SetBody(notesStr.ucs2()); | ||
424 | |||
425 | aItem->SetCustomerID(addressee.productId( ).ucs2()); | ||
426 | //addressee.Revision( const QDateTime &revision ); | ||
427 | // addressee.SortString( const QString &sortString ); | ||
428 | aItem->SetWebPage( addressee.url().url().ucs2()); | ||
429 | |||
430 | QString tempS; | ||
431 | |||
432 | |||
433 | tempS = addressee.custom( "KADDRESSBOOK", "X-IMAddress"); | ||
434 | aItem->SetNetMeetingAlias(tempS.ucs2()); | ||
435 | |||
436 | tempS = addressee.custom( "KADDRESSBOOK", "X-SpousesName" ); | ||
437 | aItem->SetSpouse(tempS.ucs2()); | ||
438 | |||
439 | tempS = addressee.custom( "KADDRESSBOOK", "X-ManagersName" ); | ||
440 | aItem->SetManagerName(tempS.ucs2()); | ||
441 | |||
442 | tempS = addressee.custom( "KADDRESSBOOK", "X-AssistantsName" ); | ||
443 | aItem->SetAssistantName(tempS.ucs2()); | ||
444 | |||
445 | tempS = addressee.custom( "KADDRESSBOOK", "X-Department" ); | ||
446 | aItem->SetDepartment(tempS.ucs2()); | ||
447 | |||
448 | tempS = addressee.custom( "KADDRESSBOOK", "X-Office" ); | ||
449 | aItem->SetOfficeLocation(tempS.ucs2()); | ||
450 | |||
451 | tempS = addressee.custom( "KADDRESSBOOK", "X-Profession"); | ||
452 | aItem->SetProfession(tempS.ucs2()); | ||
453 | |||
454 | tempS = addressee.custom( "KADDRESSBOOK", "X-Anniversary"); | ||
455 | if ( !tempS.isEmpty() ){ | ||
456 | QDateTime dt = QDateTime ( KGlobal::locale()->readDate( tempS,"%Y-%m-%d") ); | ||
457 | aItem->SetAnniversary(Qdt2date( dt )); | ||
458 | } else { | ||
459 | aItem->SetAnniversary(Qdt2date(QDateTime(QDate( 4501,1,1 )))); | ||
460 | } | ||
461 | int sec = (int)addressee.secrecy().type(); | ||
462 | if ( sec > 0 )// mapping pers -> private | ||
463 | ++sec; | ||
464 | aItem->SetSensitivity( sec ) ; | ||
465 | //addressee.Logo( const Picture &logo ); | ||
466 | //addressee.Photo( const Picture &photo ); | ||
467 | //addressee.Sound( const Sound &sound ); | ||
468 | //addressee.Agent( const Agent &agent ); | ||
469 | |||
470 | QString cat = addressee.categories().join("; "); | ||
471 | aItem->SetCategories( cat.ucs2()); | ||
472 | |||
473 | |||
474 | KABC::PhoneNumber::List phoneNumbers; | ||
475 | KABC::PhoneNumber::List::Iterator phoneIter; | ||
476 | phoneNumbers = addressee.phoneNumbers(); | ||
477 | for ( phoneIter = phoneNumbers.begin(); phoneIter != phoneNumbers.end(); | ||
478 | ++phoneIter ) { | ||
479 | |||
480 | } | ||
481 | QString phoneS; | ||
482 | |||
483 | phoneS = addressee.phoneNumberString( | ||
484 | KABC::PhoneNumber::Work + | ||
485 | KABC::PhoneNumber::Voice + | ||
486 | KABC::PhoneNumber::Msg ); | ||
487 | aItem->SetAssistantTelephoneNumber(phoneS.ucs2()); | ||
488 | |||
489 | phoneS = addressee.phoneNumberString( | ||
490 | KABC::PhoneNumber::Work + | ||
491 | KABC::PhoneNumber::Pref) ; | ||
492 | aItem->SetBusinessTelephoneNumber(phoneS.ucs2()); | ||
493 | |||
494 | phoneS = addressee.phoneNumberString( | ||
495 | KABC::PhoneNumber::Work ) ; | ||
496 | aItem->SetBusiness2TelephoneNumber(phoneS.ucs2()); | ||
497 | |||
498 | phoneS = addressee.phoneNumberString( | ||
499 | KABC::PhoneNumber::Work + | ||
500 | KABC::PhoneNumber::Fax ) ; | ||
501 | aItem->SetBusinessFaxNumber(phoneS.ucs2()); | ||
502 | |||
503 | |||
504 | phoneS = addressee.phoneNumberString( | ||
505 | KABC::PhoneNumber::Car ) ; | ||
506 | aItem->SetCarTelephoneNumber(phoneS.ucs2()); | ||
507 | |||
508 | phoneS = addressee.phoneNumberString( | ||
509 | KABC::PhoneNumber::Home + | ||
510 | KABC::PhoneNumber::Pref ) ; | ||
511 | aItem->SetHomeTelephoneNumber(phoneS.ucs2()); | ||
512 | |||
513 | phoneS = addressee.phoneNumberString( | ||
514 | KABC::PhoneNumber::Home ) ; | ||
515 | aItem->SetHome2TelephoneNumber(phoneS.ucs2()); | ||
516 | |||
517 | phoneS = addressee.phoneNumberString( | ||
518 | KABC::PhoneNumber::Home + | ||
519 | KABC::PhoneNumber::Fax ) ; | ||
520 | aItem->SetHomeFaxNumber(phoneS.ucs2()); | ||
521 | |||
522 | phoneS = addressee.phoneNumberString( | ||
523 | KABC::PhoneNumber::Isdn ) ; | ||
524 | aItem->SetISDNNumber(phoneS.ucs2()); | ||
525 | |||
526 | phoneS = addressee.phoneNumberString( | ||
527 | KABC::PhoneNumber::Cell ) ; | ||
528 | aItem->SetMobileTelephoneNumber(phoneS.ucs2()); | ||
529 | |||
530 | phoneS = addressee.phoneNumberString( | ||
531 | KABC::PhoneNumber::Fax ) ; | ||
532 | aItem->SetOtherFaxNumber(phoneS.ucs2()); | ||
533 | |||
534 | phoneS = addressee.phoneNumberString( | ||
535 | KABC::PhoneNumber::Voice ) ; | ||
536 | aItem->SetOtherTelephoneNumber(phoneS.ucs2()); | ||
537 | |||
538 | phoneS = addressee.phoneNumberString( | ||
539 | KABC::PhoneNumber::Pager ) ; | ||
540 | aItem->SetPagerNumber(phoneS.ucs2()); | ||
541 | |||
542 | phoneS = addressee.phoneNumberString( | ||
543 | KABC::PhoneNumber::Pref ) ; | ||
544 | aItem->SetPrimaryTelephoneNumber(phoneS.ucs2()); | ||
545 | |||
546 | phoneS = addressee.phoneNumberString( | ||
547 | KABC::PhoneNumber::Pcs + | ||
548 | KABC::PhoneNumber::Voice) ; | ||
549 | aItem->SetTTYTDDTelephoneNumber(phoneS.ucs2()); | ||
550 | |||
551 | phoneS = addressee.phoneNumberString( | ||
552 | KABC::PhoneNumber::Pcs ) ; | ||
553 | aItem->SetTelexNumber(phoneS.ucs2()); | ||
554 | |||
555 | phoneS = addressee.phoneNumberString( | ||
556 | KABC::PhoneNumber::Work + | ||
557 | KABC::PhoneNumber::Msg ) ; | ||
558 | aItem->SetCompanyMainTelephoneNumber(phoneS.ucs2()); | ||
559 | |||
560 | phoneS = addressee.phoneNumberString( | ||
561 | KABC::PhoneNumber::Pcs + | ||
562 | KABC::PhoneNumber::Pref ) ; | ||
563 | aItem->SetRadioTelephoneNumber(phoneS.ucs2()); | ||
564 | |||
565 | phoneS = addressee.phoneNumberString( | ||
566 | KABC::PhoneNumber::Msg ) ; | ||
567 | aItem->SetCallbackTelephoneNumber(phoneS.ucs2()); | ||
568 | |||
569 | QStringList emails = addressee.emails(); | ||
570 | emails << "" << "" << ""; | ||
571 | aItem->SetEmail1Address(emails[0].ucs2()); | ||
572 | aItem->SetEmail2Address(emails[1].ucs2()); | ||
573 | aItem->SetEmail3Address(emails[2].ucs2()); | ||
574 | |||
575 | // is this the number of the preferred email? | ||
576 | //long GetSelectedMailingAddress();??? | ||
577 | |||
578 | KABC::Address addressHome = addressee.address( KABC::Address::Home ); | ||
579 | KABC::Address* addressAdd = &addressHome; | ||
580 | aItem->SetHomeAddressCountry(addressAdd->country().ucs2()); | ||
581 | aItem->SetHomeAddressState(addressAdd->region().ucs2()); | ||
582 | aItem->SetHomeAddressCity(addressAdd->locality().ucs2()); | ||
583 | aItem->SetHomeAddressPostalCode(addressAdd->postalCode().ucs2()); | ||
584 | aItem->SetHomeAddressPostOfficeBox(addressAdd->postOfficeBox().ucs2()); | ||
585 | aItem->SetHomeAddressStreet(addressAdd->street().ucs2()); | ||
586 | |||
587 | addressHome = addressee.address( KABC::Address::Work ); | ||
588 | addressAdd = &addressHome; | ||
589 | aItem->SetBusinessAddressCountry(addressAdd->country().ucs2()); | ||
590 | aItem->SetBusinessAddressState(addressAdd->region().ucs2()); | ||
591 | aItem->SetBusinessAddressCity(addressAdd->locality().ucs2()); | ||
592 | aItem->SetBusinessAddressPostalCode(addressAdd->postalCode().ucs2()); | ||
593 | aItem->SetBusinessAddressPostOfficeBox(addressAdd->postOfficeBox().ucs2()); | ||
594 | aItem->SetBusinessAddressStreet(addressAdd->street().ucs2()); | ||
595 | |||
596 | addressHome = addressee.otherAddress(); | ||
597 | addressAdd = &addressHome; | ||
598 | aItem->SetOtherAddressCountry(addressAdd->country().ucs2()); | ||
599 | aItem->SetOtherAddressState(addressAdd->region().ucs2()); | ||
600 | aItem->SetOtherAddressCity(addressAdd->locality().ucs2()); | ||
601 | aItem->SetOtherAddressPostalCode(addressAdd->postalCode().ucs2()); | ||
602 | aItem->SetOtherAddressPostOfficeBox(addressAdd->postOfficeBox().ucs2()); | ||
603 | aItem->SetOtherAddressStreet(addressAdd->street().ucs2()); | ||
604 | |||
605 | aItem->SetInternetFreeBusyAddress(addressee.custom( "KADDRESSBOOK", "X-FreeBusyUrl" ).ucs2()); | ||
606 | aItem->SetChildren(addressee.custom( "KADDRESSBOOK", "X-Children").ucs2()); | ||
607 | |||
608 | int gen = 0;// 0 undef - 1 female - 2 male | ||
609 | QString gend = addressee.custom( "KADDRESSBOOK", "X-Gender" ); | ||
610 | if ( gend == "female" ) | ||
611 | gen = 1; | ||
612 | if ( gend == "male" ) | ||
613 | gen = 2; | ||
614 | aItem->SetGender(gen); | ||
615 | |||
616 | aItem->Save(); | ||
617 | } | ||
618 | KABC::Addressee OL_access::ol2kapiContact( _ContactItem * aItem , bool syncMode) | ||
619 | { | ||
620 | KABC::Addressee addressee; | ||
621 | |||
622 | addressee.setUid( QString::fromUcs2(aItem->GetEntryID().GetBuffer())); | ||
623 | //GetLastModificationTime() | ||
624 | //addressee.setName( const QString &name ); | ||
625 | addressee.setFormattedName( QString::fromUcs2(aItem->GetFileAs().GetBuffer()) ); | ||
626 | addressee.setFamilyName( QString::fromUcs2(aItem->GetLastName().GetBuffer()) ); | ||
627 | addressee.setGivenName( QString::fromUcs2(aItem->GetFirstName().GetBuffer()) ); | ||
628 | addressee.setAdditionalName( QString::fromUcs2(aItem->GetMiddleName().GetBuffer()) ); | ||
629 | addressee.setPrefix(QString::fromUcs2(aItem->GetTitle().GetBuffer()) ); | ||
630 | addressee.setSuffix( QString::fromUcs2(aItem->GetSuffix().GetBuffer()) ); | ||
631 | addressee.setNickName( QString::fromUcs2(aItem->GetNickName().GetBuffer()) ); | ||
632 | QDateTime dtb = mDdate2Qdtr(aItem->GetBirthday()); | ||
633 | if ( dtb.isValid() ) | ||
634 | addressee.setBirthday( mDdate2Qdtr(aItem->GetBirthday())); | ||
635 | |||
636 | //QString::fromUcs2(aItem->.GetBuffer()) | ||
637 | //addressee.setMailer( const QString &mailer ); | ||
638 | //addressee.setTimeZone( const TimeZone &timeZone ); | ||
639 | //addressee.setGeo( const Geo &geo ); | ||
640 | //addressee.setTitle( QString::fromUcs2(aItem->GetJobTitle().GetBuffer()) );// titel is the prefix | ||
641 | addressee.setRole( QString::fromUcs2(aItem->GetJobTitle().GetBuffer()) ); | ||
642 | addressee.setOrganization( QString::fromUcs2(aItem->GetCompanyName().GetBuffer()).replace( QRegExp("\\r"), "") ); | ||
643 | QString notesStr = QString::fromUcs2(aItem->GetBody().GetBuffer()); | ||
644 | notesStr.replace( QRegExp("\\r"), ""); | ||
645 | |||
646 | addressee.setProductId( QString::fromUcs2(aItem->GetCustomerID().GetBuffer()) ); | ||
647 | //addressee.setRevision( const QDateTime &revision ); | ||
648 | // addressee.setSortString( const QString &sortString ); | ||
649 | addressee.setUrl( QString::fromUcs2(aItem->GetWebPage().GetBuffer()) ); | ||
650 | |||
651 | QString tempS; | ||
652 | tempS = QString::fromUcs2(aItem->GetNetMeetingAlias().GetBuffer());//+" AT SERVER: " +QString::fromUcs2(aItem->GetNetMeetingServer().GetBuffer()); | ||
653 | if ( tempS.length() > 12 ) | ||
654 | addressee.insertCustom( "KADDRESSBOOK", "X-IMAddress", tempS ); | ||
655 | tempS = QString::fromUcs2(aItem->GetSpouse().GetBuffer()); | ||
656 | if ( !tempS.isEmpty() ) | ||
657 | addressee.insertCustom( "KADDRESSBOOK", "X-SpousesName", tempS ); | ||
658 | tempS = QString::fromUcs2(aItem->GetManagerName().GetBuffer()); | ||
659 | if ( !tempS.isEmpty() ) | ||
660 | addressee.insertCustom( "KADDRESSBOOK", "X-ManagersName", tempS ); | ||
661 | tempS = QString::fromUcs2(aItem->GetAssistantName().GetBuffer()); | ||
662 | if ( !tempS.isEmpty() ) | ||
663 | addressee.insertCustom( "KADDRESSBOOK", "X-AssistantsName", tempS ); | ||
664 | tempS = QString::fromUcs2(aItem->GetDepartment().GetBuffer()); | ||
665 | if ( !tempS.isEmpty() ) | ||
666 | addressee.insertCustom( "KADDRESSBOOK", "X-Department", tempS ); | ||
667 | tempS = QString::fromUcs2(aItem->GetOfficeLocation().GetBuffer()).replace( QRegExp("\\r"), ""); | ||
668 | if ( !tempS.isEmpty() ) | ||
669 | addressee.insertCustom( "KADDRESSBOOK", "X-Office",tempS ); | ||
670 | tempS = QString::fromUcs2(aItem->GetProfession().GetBuffer()); | ||
671 | if ( !tempS.isEmpty() ) | ||
672 | addressee.insertCustom( "KADDRESSBOOK", "X-Profession", tempS ); | ||
673 | dtb = mDdate2Qdtr(aItem->GetAnniversary()); | ||
674 | if (dtb.isValid() ) { | ||
675 | QString dt = KGlobal::locale()->formatDate( dtb.date() , true, KLocale::ISODate); | ||
676 | addressee.insertCustom( "KADDRESSBOOK", "X-Anniversary", dt); | ||
677 | } | ||
678 | int sec = aItem->GetSensitivity() ; | ||
679 | if ( sec > 1 )// mapping pers -> private | ||
680 | --sec; | ||
681 | addressee.setSecrecy( sec ); | ||
682 | //addressee.setLogo( const Picture &logo ); | ||
683 | //addressee.setPhoto( const Picture &photo ); | ||
684 | //addressee.setSound( const Sound &sound ); | ||
685 | //addressee.setAgent( const Agent &agent ); | ||
686 | QString cat = QString::fromUcs2( aItem->GetCategories().GetBuffer()).replace( QRegExp("\\r"), ""); | ||
687 | cat = cat.replace( QRegExp("; "), ";"); | ||
688 | addressee.setCategories( QStringList::split( ";", cat )); | ||
689 | |||
690 | QString phoneS; | ||
691 | |||
692 | phoneS = QString::fromUcs2( aItem->GetAssistantTelephoneNumber().GetBuffer()); | ||
693 | if ( ! phoneS.isEmpty()) | ||
694 | addressee.insertPhoneNumber( KABC::PhoneNumber(phoneS , | ||
695 | KABC::PhoneNumber::Work + | ||
696 | KABC::PhoneNumber::Voice + | ||
697 | KABC::PhoneNumber::Msg ) ); | ||
698 | phoneS = QString::fromUcs2( aItem->GetBusinessTelephoneNumber().GetBuffer()); | ||
699 | if ( ! phoneS.isEmpty()) | ||
700 | addressee.insertPhoneNumber( KABC::PhoneNumber(phoneS , | ||
701 | KABC::PhoneNumber::Work + | ||
702 | KABC::PhoneNumber::Pref) ); | ||
703 | phoneS = QString::fromUcs2( aItem->GetBusiness2TelephoneNumber().GetBuffer()); | ||
704 | if ( ! phoneS.isEmpty()) | ||
705 | addressee.insertPhoneNumber( KABC::PhoneNumber(phoneS , | ||
706 | KABC::PhoneNumber::Work ) ); | ||
707 | phoneS = QString::fromUcs2( aItem->GetBusinessFaxNumber().GetBuffer()); | ||
708 | if ( ! phoneS.isEmpty()) | ||
709 | addressee.insertPhoneNumber( KABC::PhoneNumber(phoneS , | ||
710 | KABC::PhoneNumber::Work + | ||
711 | KABC::PhoneNumber::Fax ) ); | ||
712 | phoneS = QString::fromUcs2( aItem->GetCarTelephoneNumber().GetBuffer()); | ||
713 | if ( ! phoneS.isEmpty()) | ||
714 | addressee.insertPhoneNumber( KABC::PhoneNumber(phoneS , | ||
715 | KABC::PhoneNumber::Car ) ); | ||
716 | phoneS = QString::fromUcs2( aItem->GetHomeTelephoneNumber().GetBuffer()); | ||
717 | if ( ! phoneS.isEmpty()) | ||
718 | addressee.insertPhoneNumber( KABC::PhoneNumber(phoneS , | ||
719 | KABC::PhoneNumber::Home + | ||
720 | KABC::PhoneNumber::Pref ) ); | ||
721 | phoneS = QString::fromUcs2( aItem->GetHome2TelephoneNumber().GetBuffer()); | ||
722 | if ( ! phoneS.isEmpty()) | ||
723 | addressee.insertPhoneNumber( KABC::PhoneNumber(phoneS , | ||
724 | KABC::PhoneNumber::Home ) ); | ||
725 | phoneS = QString::fromUcs2( aItem->GetHomeFaxNumber().GetBuffer()); | ||
726 | if ( ! phoneS.isEmpty()) | ||
727 | addressee.insertPhoneNumber( KABC::PhoneNumber(phoneS , | ||
728 | KABC::PhoneNumber::Home + | ||
729 | KABC::PhoneNumber::Fax ) ); | ||
730 | phoneS = QString::fromUcs2( aItem->GetISDNNumber().GetBuffer()); | ||
731 | if ( ! phoneS.isEmpty()) | ||
732 | addressee.insertPhoneNumber( KABC::PhoneNumber(phoneS , | ||
733 | KABC::PhoneNumber::Isdn ) ); | ||
734 | phoneS = QString::fromUcs2( aItem->GetMobileTelephoneNumber().GetBuffer()); | ||
735 | if ( ! phoneS.isEmpty()) | ||
736 | addressee.insertPhoneNumber( KABC::PhoneNumber(phoneS , | ||
737 | KABC::PhoneNumber::Cell ) ); | ||
738 | phoneS = QString::fromUcs2( aItem->GetOtherFaxNumber().GetBuffer()); | ||
739 | if ( ! phoneS.isEmpty()) | ||
740 | addressee.insertPhoneNumber( KABC::PhoneNumber(phoneS , | ||
741 | KABC::PhoneNumber::Fax ) ); | ||
742 | phoneS = QString::fromUcs2( aItem->GetOtherTelephoneNumber().GetBuffer()); | ||
743 | if ( ! phoneS.isEmpty()) | ||
744 | addressee.insertPhoneNumber( KABC::PhoneNumber(phoneS , | ||
745 | KABC::PhoneNumber::Voice ) ); | ||
746 | phoneS = QString::fromUcs2( aItem->GetPagerNumber().GetBuffer()); | ||
747 | if ( ! phoneS.isEmpty()) | ||
748 | addressee.insertPhoneNumber( KABC::PhoneNumber(phoneS , | ||
749 | KABC::PhoneNumber::Pager ) ); | ||
750 | phoneS = QString::fromUcs2( aItem->GetPrimaryTelephoneNumber().GetBuffer()); | ||
751 | if ( ! phoneS.isEmpty()) | ||
752 | addressee.insertPhoneNumber( KABC::PhoneNumber(phoneS , | ||
753 | KABC::PhoneNumber::Pref ) ); | ||
754 | phoneS = QString::fromUcs2( aItem->GetTTYTDDTelephoneNumber().GetBuffer()); | ||
755 | if ( ! phoneS.isEmpty()) | ||
756 | addressee.insertPhoneNumber( KABC::PhoneNumber(phoneS , | ||
757 | KABC::PhoneNumber::Pcs + | ||
758 | KABC::PhoneNumber::Voice) ); | ||
759 | phoneS = QString::fromUcs2( aItem->GetTelexNumber().GetBuffer()); | ||
760 | if ( ! phoneS.isEmpty()) | ||
761 | addressee.insertPhoneNumber( KABC::PhoneNumber(phoneS , | ||
762 | KABC::PhoneNumber::Pcs ) ); | ||
763 | phoneS = QString::fromUcs2( aItem->GetCompanyMainTelephoneNumber().GetBuffer()); | ||
764 | if ( ! phoneS.isEmpty()) | ||
765 | addressee.insertPhoneNumber( KABC::PhoneNumber(phoneS , | ||
766 | KABC::PhoneNumber::Work + | ||
767 | KABC::PhoneNumber::Msg ) ); | ||
768 | phoneS = QString::fromUcs2( aItem->GetRadioTelephoneNumber().GetBuffer()); | ||
769 | if ( ! phoneS.isEmpty()) | ||
770 | addressee.insertPhoneNumber( KABC::PhoneNumber(phoneS , | ||
771 | KABC::PhoneNumber::Pcs + | ||
772 | KABC::PhoneNumber::Pref ) ); | ||
773 | phoneS = QString::fromUcs2( aItem->GetCallbackTelephoneNumber().GetBuffer()); | ||
774 | if ( ! phoneS.isEmpty()) | ||
775 | addressee.insertPhoneNumber( KABC::PhoneNumber(phoneS , | ||
776 | KABC::PhoneNumber::Msg ) ); | ||
777 | |||
778 | bool preferred = true; | ||
779 | phoneS = QString::fromUcs2( aItem->GetEmail1Address().GetBuffer()); | ||
780 | if ( ! phoneS.isEmpty()) { | ||
781 | addressee.insertEmail(phoneS , preferred ); | ||
782 | preferred = false; | ||
783 | } | ||
784 | phoneS = QString::fromUcs2( aItem->GetEmail2Address().GetBuffer()); | ||
785 | if ( ! phoneS.isEmpty()) { | ||
786 | addressee.insertEmail(phoneS , preferred ); | ||
787 | preferred = false; | ||
788 | } | ||
789 | phoneS = QString::fromUcs2( aItem->GetEmail3Address().GetBuffer()); | ||
790 | if ( ! phoneS.isEmpty()) { | ||
791 | addressee.insertEmail(phoneS , preferred ); | ||
792 | preferred = false; | ||
793 | } | ||
794 | // is this the number of the preferred email? | ||
795 | //long GetSelectedMailingAddress();??? | ||
796 | |||
797 | KABC::Address addressHome; | ||
798 | KABC::Address* addressAdd = &addressHome; | ||
799 | bool insert = false; | ||
800 | phoneS = QString::fromUcs2( aItem->GetHomeAddressCountry().GetBuffer()); | ||
801 | phoneS.replace( QRegExp("\\r"), ""); | ||
802 | if ( ! phoneS.isEmpty()) { | ||
803 | addressAdd->setCountry(phoneS ); | ||
804 | insert = true; | ||
805 | } | ||
806 | phoneS = QString::fromUcs2( aItem->GetHomeAddressState().GetBuffer()); | ||
807 | phoneS.replace( QRegExp("\\r"), ""); | ||
808 | if ( ! phoneS.isEmpty()) { | ||
809 | addressAdd->setRegion(phoneS ); | ||
810 | insert = true; | ||
811 | } | ||
812 | phoneS = QString::fromUcs2( aItem->GetHomeAddressCity().GetBuffer()); | ||
813 | phoneS.replace( QRegExp("\\r"), ""); | ||
814 | if ( ! phoneS.isEmpty()) { | ||
815 | addressAdd->setLocality(phoneS ); | ||
816 | insert = true; | ||
817 | } | ||
818 | phoneS = QString::fromUcs2( aItem->GetHomeAddressPostalCode().GetBuffer()); | ||
819 | phoneS.replace( QRegExp("\\r"), ""); | ||
820 | if ( ! phoneS.isEmpty()) { | ||
821 | addressAdd->setPostalCode(phoneS ); | ||
822 | insert = true; | ||
823 | } | ||
824 | phoneS = QString::fromUcs2( aItem->GetHomeAddressPostOfficeBox().GetBuffer()); | ||
825 | phoneS.replace( QRegExp("\\r"), ""); | ||
826 | if ( ! phoneS.isEmpty()) { | ||
827 | addressAdd->setPostOfficeBox(phoneS ); | ||
828 | insert = true; | ||
829 | } | ||
830 | phoneS = QString::fromUcs2( aItem->GetHomeAddressStreet().GetBuffer()); | ||
831 | phoneS.replace( QRegExp("\\r"), ""); | ||
832 | if ( ! phoneS.isEmpty()) { | ||
833 | addressAdd->setStreet(phoneS ); | ||
834 | insert = true; | ||
835 | } | ||
836 | phoneS = QString::fromUcs2( aItem->GetHomeAddress().GetBuffer()); | ||
837 | phoneS.replace( QRegExp("\\r"), ""); | ||
838 | if ( ! phoneS.isEmpty()) { | ||
839 | // redundant !addressAdd->setExtended(phoneS ); | ||
840 | // insert = true; | ||
841 | } | ||
842 | addressAdd->setType( KABC::Address::Home ); | ||
843 | if ( insert ) | ||
844 | addressee.insertAddress( *addressAdd ); | ||
845 | // ++++++++++++++++++++++ end of address | ||
846 | |||
847 | KABC::Address addressWork; | ||
848 | addressAdd = &addressWork; | ||
849 | insert = false; | ||
850 | phoneS = QString::fromUcs2( aItem->GetBusinessAddressCountry().GetBuffer()); | ||
851 | phoneS.replace( QRegExp("\\r"), ""); | ||
852 | if ( ! phoneS.isEmpty()) { | ||
853 | addressAdd->setCountry(phoneS ); | ||
854 | insert = true; | ||
855 | } | ||
856 | phoneS = QString::fromUcs2( aItem->GetBusinessAddressState().GetBuffer()); | ||
857 | phoneS.replace( QRegExp("\\r"), ""); | ||
858 | if ( ! phoneS.isEmpty()) { | ||
859 | addressAdd->setRegion(phoneS ); | ||
860 | insert = true; | ||
861 | } | ||
862 | phoneS = QString::fromUcs2( aItem->GetBusinessAddressCity().GetBuffer()); | ||
863 | phoneS.replace( QRegExp("\\r"), ""); | ||
864 | if ( ! phoneS.isEmpty()) { | ||
865 | addressAdd->setLocality(phoneS ); | ||
866 | insert = true; | ||
867 | } | ||
868 | phoneS = QString::fromUcs2( aItem->GetBusinessAddressPostalCode().GetBuffer()); | ||
869 | phoneS.replace( QRegExp("\\r"), ""); | ||
870 | if ( ! phoneS.isEmpty()) { | ||
871 | addressAdd->setPostalCode(phoneS ); | ||
872 | insert = true; | ||
873 | } | ||
874 | phoneS = QString::fromUcs2( aItem->GetBusinessAddressPostOfficeBox().GetBuffer()); | ||
875 | phoneS.replace( QRegExp("\\r"), ""); | ||
876 | if ( ! phoneS.isEmpty()) { | ||
877 | addressAdd->setPostOfficeBox(phoneS ); | ||
878 | insert = true; | ||
879 | } | ||
880 | phoneS = QString::fromUcs2( aItem->GetBusinessAddressStreet().GetBuffer()); | ||
881 | phoneS.replace( QRegExp("\\r"), ""); | ||
882 | if ( ! phoneS.isEmpty()) { | ||
883 | addressAdd->setStreet(phoneS ); | ||
884 | insert = true; | ||
885 | } | ||
886 | phoneS = QString::fromUcs2( aItem->GetBusinessAddress().GetBuffer()); | ||
887 | phoneS.replace( QRegExp("\\r"), ""); | ||
888 | if ( ! phoneS.isEmpty()) { | ||
889 | // redundant !addressAdd->setExtended(phoneS ); | ||
890 | // insert = true; | ||
891 | } | ||
892 | addressAdd->setType( KABC::Address::Work ); | ||
893 | if ( insert ) | ||
894 | addressee.insertAddress( *addressAdd ); | ||
895 | // ++++++++++++++++++++++ end of address | ||
896 | |||
897 | KABC::Address addressOther; | ||
898 | addressAdd = &addressOther; | ||
899 | insert = false; | ||
900 | phoneS = QString::fromUcs2( aItem->GetOtherAddressCountry().GetBuffer()); | ||
901 | phoneS.replace( QRegExp("\\r"), ""); | ||
902 | if ( ! phoneS.isEmpty()) { | ||
903 | addressAdd->setCountry(phoneS ); | ||
904 | insert = true; | ||
905 | } | ||
906 | phoneS = QString::fromUcs2( aItem->GetOtherAddressState().GetBuffer()); | ||
907 | phoneS.replace( QRegExp("\\r"), ""); | ||
908 | if ( ! phoneS.isEmpty()) { | ||
909 | addressAdd->setRegion(phoneS ); | ||
910 | insert = true; | ||
911 | } | ||
912 | phoneS = QString::fromUcs2( aItem->GetOtherAddressCity().GetBuffer()); | ||
913 | phoneS.replace( QRegExp("\\r"), ""); | ||
914 | if ( ! phoneS.isEmpty()) { | ||
915 | addressAdd->setLocality(phoneS ); | ||
916 | insert = true; | ||
917 | } | ||
918 | phoneS = QString::fromUcs2( aItem->GetOtherAddressPostalCode().GetBuffer()); | ||
919 | phoneS.replace( QRegExp("\\r"), ""); | ||
920 | if ( ! phoneS.isEmpty()) { | ||
921 | addressAdd->setPostalCode(phoneS ); | ||
922 | insert = true; | ||
923 | } | ||
924 | phoneS = QString::fromUcs2( aItem->GetOtherAddressPostOfficeBox().GetBuffer()); | ||
925 | phoneS.replace( QRegExp("\\r"), ""); | ||
926 | if ( ! phoneS.isEmpty()) { | ||
927 | addressAdd->setPostOfficeBox(phoneS ); | ||
928 | insert = true; | ||
929 | } | ||
930 | phoneS = QString::fromUcs2( aItem->GetOtherAddressStreet().GetBuffer()); | ||
931 | phoneS.replace( QRegExp("\\r"), ""); | ||
932 | if ( ! phoneS.isEmpty()) { | ||
933 | addressAdd->setStreet(phoneS ); | ||
934 | insert = true; | ||
935 | } | ||
936 | phoneS = QString::fromUcs2( aItem->GetOtherAddress().GetBuffer()); | ||
937 | if ( ! phoneS.isEmpty()) { | ||
938 | // redundant !addressAdd->setExtended(phoneS ); | ||
939 | //insert = true; | ||
940 | } | ||
941 | //addressAdd->setId( ); | ||
942 | if ( insert ) | ||
943 | addressee.insertAddress( *addressAdd ); | ||
944 | // ++++++++++++++++++++++ end of address | ||
945 | #if 0 | ||
946 | KABC::Address addressMail; | ||
947 | addressAdd = &addressMail; | ||
948 | insert = false; | ||
949 | phoneS = QString::fromUcs2( aItem->GetMailingAddressCountry().GetBuffer()); | ||
950 | phoneS.replace( QRegExp("\\r"), ""); | ||
951 | if ( ! phoneS.isEmpty()) { | ||
952 | addressAdd->setCountry(phoneS ); | ||
953 | insert = true; | ||
954 | } | ||
955 | phoneS = QString::fromUcs2( aItem->GetMailingAddressState().GetBuffer()); | ||
956 | phoneS.replace( QRegExp("\\r"), ""); | ||
957 | if ( ! phoneS.isEmpty()) { | ||
958 | addressAdd->setRegion(phoneS ); | ||
959 | insert = true; | ||
960 | } | ||
961 | phoneS = QString::fromUcs2( aItem->GetMailingAddressCity().GetBuffer()); | ||
962 | phoneS.replace( QRegExp("\\r"), ""); | ||
963 | if ( ! phoneS.isEmpty()) { | ||
964 | addressAdd->setLocality(phoneS ); | ||
965 | insert = true; | ||
966 | } | ||
967 | phoneS = QString::fromUcs2( aItem->GetMailingAddressPostalCode().GetBuffer()); | ||
968 | phoneS.replace( QRegExp("\\r"), ""); | ||
969 | if ( ! phoneS.isEmpty()) { | ||
970 | addressAdd->setPostalCode(phoneS ); | ||
971 | insert = true; | ||
972 | } | ||
973 | phoneS = QString::fromUcs2( aItem->GetMailingAddressPostOfficeBox().GetBuffer()); | ||
974 | phoneS.replace( QRegExp("\\r"), ""); | ||
975 | if ( ! phoneS.isEmpty()) { | ||
976 | addressAdd->setPostOfficeBox(phoneS ); | ||
977 | insert = true; | ||
978 | } | ||
979 | phoneS = QString::fromUcs2( aItem->GetMailingAddressStreet().GetBuffer()); | ||
980 | phoneS.replace( QRegExp("\\r"), ""); | ||
981 | if ( ! phoneS.isEmpty()) { | ||
982 | addressAdd->setStreet(phoneS ); | ||
983 | insert = true; | ||
984 | } | ||
985 | phoneS = QString::fromUcs2( aItem->GetMailingAddress().GetBuffer()); | ||
986 | phoneS.replace( QRegExp("\\r"), ""); | ||
987 | if ( ! phoneS.isEmpty()) { | ||
988 | // redundant ! addressAdd->setExtended(phoneS ); | ||
989 | // insert = true; | ||
990 | } | ||
991 | addressAdd->setType( KABC::Address::Postal ); | ||
992 | if ( insert ) { | ||
993 | addressee.insertAddress( *addressAdd ); | ||
994 | } | ||
995 | #endif | ||
996 | // the following code is disabled | ||
997 | // it does not seem to be useful | ||
998 | #if 0 | ||
999 | if ( insert ) { | ||
1000 | addressAdd->setType( KABC::Address::Home ); | ||
1001 | if ( addressMail == addressHome ) { | ||
1002 | addressHome.setType( KABC::Address::Postal+ KABC::Address::Home ); | ||
1003 | addressee.insertAddress( addressHome ); | ||
1004 | } else { | ||
1005 | addressAdd->setType( KABC::Address::Work ); | ||
1006 | if ( addressMail == addressWork ){ | ||
1007 | addressWork.setType( KABC::Address::Postal+ KABC::Address::Work ); | ||
1008 | addressee.insertAddress( addressWork ); | ||
1009 | |||
1010 | } else { | ||
1011 | addressAdd->setType( 0 ); | ||
1012 | if ( addressOther == addressMail ){ | ||
1013 | addressOther.setType( KABC::Address::Postal ); | ||
1014 | addressee.insertAddress( addressOther ); | ||
1015 | } else { | ||
1016 | addressee.insertAddress( *addressAdd ); | ||
1017 | } | ||
1018 | } | ||
1019 | } | ||
1020 | } | ||
1021 | #endif | ||
1022 | // ++++++++++++++++++++++ end of ALL addresses | ||
1023 | //GetUserProperties(); | ||
1024 | tempS = QString::fromUcs2(aItem->GetInternetFreeBusyAddress().GetBuffer()); | ||
1025 | phoneS.replace( QRegExp("\\r"), ""); | ||
1026 | if ( !tempS.isEmpty() ) | ||
1027 | addressee.insertCustom( "KADDRESSBOOK", "X-FreeBusyUrl", tempS ); | ||
1028 | tempS = QString::fromUcs2(aItem->GetChildren().GetBuffer()); | ||
1029 | if ( !tempS.isEmpty() ) | ||
1030 | addressee.insertCustom( "KADDRESSBOOK", "X-Children", tempS ); | ||
1031 | int gen = aItem->GetGender(); | ||
1032 | if ( gen != 0 ) { // 0 undef - 1 female - 2 male | ||
1033 | if ( gen == 1 ) | ||
1034 | addressee.insertCustom( "KADDRESSBOOK", "X-Gender", "female" ); | ||
1035 | else | ||
1036 | addressee.insertCustom( "KADDRESSBOOK", "X-Gender", "male" ); | ||
1037 | } | ||
1038 | QString additionalInfo; | ||
1039 | QString tempAdd; | ||
1040 | tempAdd = QString::fromUcs2(aItem->GetLanguage().GetBuffer()); | ||
1041 | if ( ! tempAdd.isEmpty() ) { | ||
1042 | additionalInfo += i18n("\nLanguage: "); | ||
1043 | additionalInfo += tempAdd; | ||
1044 | } | ||
1045 | tempAdd = QString::fromUcs2(aItem->GetHobby().GetBuffer()); | ||
1046 | phoneS.replace( QRegExp("\\r"), ""); | ||
1047 | if ( ! tempAdd.isEmpty() ) { | ||
1048 | additionalInfo += i18n("\nHobby: "); | ||
1049 | additionalInfo += tempAdd;; | ||
1050 | } | ||
1051 | tempAdd =QString::fromUcs2(aItem->GetPersonalHomePage().GetBuffer()); | ||
1052 | phoneS.replace( QRegExp("\\r"), ""); | ||
1053 | if ( ! tempAdd.isEmpty() ) { | ||
1054 | additionalInfo += i18n("\nHomepage: "); | ||
1055 | additionalInfo += tempAdd;; | ||
1056 | } | ||
1057 | tempAdd = QString::fromUcs2(aItem->GetBillingInformation().GetBuffer()); | ||
1058 | phoneS.replace( QRegExp("\\r"), ""); | ||
1059 | if ( ! tempAdd.isEmpty() ) { | ||
1060 | additionalInfo += i18n("\nBilling information: "); | ||
1061 | additionalInfo += tempAdd;; | ||
1062 | } | ||
1063 | tempAdd = QString::fromUcs2(aItem->GetCustomerID().GetBuffer()); | ||
1064 | phoneS.replace( QRegExp("\\r"), ""); | ||
1065 | if ( ! tempAdd.isEmpty() ) { | ||
1066 | additionalInfo += i18n("\nCustomer ID: "); | ||
1067 | additionalInfo += tempAdd;; | ||
1068 | } | ||
1069 | tempAdd = QString::fromUcs2(aItem->GetUser1().GetBuffer()); | ||
1070 | phoneS.replace( QRegExp("\\r"), ""); | ||
1071 | if ( ! tempAdd.isEmpty() ) { | ||
1072 | additionalInfo += i18n("\nUser1: "); | ||
1073 | additionalInfo += tempAdd;; | ||
1074 | } | ||
1075 | tempAdd = QString::fromUcs2(aItem->GetUser2().GetBuffer()); | ||
1076 | phoneS.replace( QRegExp("\\r"), ""); | ||
1077 | if ( ! tempAdd.isEmpty() ) { | ||
1078 | additionalInfo += i18n("\nUser2: "); | ||
1079 | additionalInfo += tempAdd;; | ||
1080 | } | ||
1081 | tempAdd = QString::fromUcs2(aItem->GetUser3().GetBuffer()); | ||
1082 | phoneS.replace( QRegExp("\\r"), ""); | ||
1083 | if ( ! tempAdd.isEmpty() ) { | ||
1084 | additionalInfo += i18n("\nUser3: "); | ||
1085 | additionalInfo += tempAdd;; | ||
1086 | } | ||
1087 | tempAdd = QString::fromUcs2(aItem->GetUser4().GetBuffer()); | ||
1088 | phoneS.replace( QRegExp("\\r"), ""); | ||
1089 | if ( ! tempAdd.isEmpty() ) { | ||
1090 | additionalInfo += i18n("\nUser4: "); | ||
1091 | additionalInfo += tempAdd;; | ||
1092 | } | ||
1093 | if (!additionalInfo.isEmpty() && ! syncMode ) { | ||
1094 | tempAdd = notesStr; | ||
1095 | notesStr = "+++++++++++++++++++++++++++\n"; | ||
1096 | notesStr += i18n("Additonal fields created\nby KA/Pi Outlook import:"); | ||
1097 | notesStr += additionalInfo; | ||
1098 | notesStr += i18n("\nEnd additonal fields created\nby KA/Pi Outlook import!\n"); | ||
1099 | notesStr += "+++++++++++++++++++++++++++\n"; | ||
1100 | notesStr += tempAdd; | ||
1101 | } | ||
1102 | addressee.setNote( notesStr ); | ||
1103 | #if 0 | ||
1104 | // pending | ||
1105 | - IM address: no clue where to get info about the helper ID | ||
1106 | -custom fields: difficult to implement - not implemented | ||
1107 | -keys: makes no sense | ||
1108 | #endif | ||
1109 | return addressee; | ||
1110 | } | ||
1111 | #if 0 | ||
1112 | |||
1113 | |||
1114 | QDateTime mDdate2Qdtr( DATE dt) | ||
1115 | { | ||
1116 | COleDateTime odt; | ||
1117 | SYSTEMTIME st; | ||
1118 | odt = dt; | ||
1119 | if ( odt.GetStatus() != 0 ) | ||
1120 | return QDateTime(); | ||
1121 | odt.GetAsSystemTime(st); | ||
1122 | if ( st.wYear > 4000 ) // this program as a year 4000 bug! | ||
1123 | return QDateTime(); | ||
1124 | // it seems so, that 1.1.4501 indicates: DATE invalid | ||
1125 | QDateTime qdt (QDate(st.wYear, st.wMonth,st.wDay ),QTime( st.wHour, st.wMinute,st.wSecond ) ); | ||
1126 | return qdt; | ||
1127 | } | ||
1128 | DATE Qdt2date( QDateTime dt ) | ||
1129 | { | ||
1130 | DATE ddd; | ||
1131 | COleDateTime odt; | ||
1132 | odt.SetDateTime(dt.date().year(), dt.date().month(),dt.date().day(), | ||
1133 | dt.time().hour(), dt.time().minute(), dt.time().second() ); | ||
1134 | ddd = odt; | ||
1135 | return ddd; | ||
1136 | } | ||
1137 | |||
1138 | class OLEListViewItem : public QCheckListItem | ||
1139 | { | ||
1140 | public: | ||
1141 | OLEListViewItem( QListView *parent, QString text ) : | ||
1142 | QCheckListItem( parent, text, QCheckListItem::CheckBox ) { ; }; | ||
1143 | OLEListViewItem( QListViewItem *after, QString text ) : | ||
1144 | QCheckListItem( after, text, QCheckListItem::CheckBox ) { ; }; | ||
1145 | ~OLEListViewItem() {}; | ||
1146 | void setData( DWORD data ) {mData= data; }; | ||
1147 | void setDataID( QString data ){ mDataID = data ;} | ||
1148 | QString dataID() { return mDataID;} | ||
1149 | DWORD data() { return mData ;}; | ||
1150 | private: | ||
1151 | DWORD mData; | ||
1152 | QString mDataID; | ||
1153 | }; | ||
1154 | bool KAImportOLdialog::sOLDispatch = false; | ||
1155 | |||
1156 | KAImportOLdialog::KAImportOLdialog( const QString &caption, | ||
1157 | KABC::AddressBook * aBook, QWidget *parent ) : | ||
1158 | KDialogBase( Plain, caption, User1 | Close, Ok, | ||
1159 | parent, caption, true, false, i18n("Import!") ) | ||
1160 | { | ||
1161 | mSyncMode = false; | ||
1162 | QHBox * mw = new QHBox( this ); | ||
1163 | setMainWidget( mw ); | ||
1164 | mListView = new QListView( mw ); | ||
1165 | mListView->addColumn(i18n("Select Folder")); | ||
1166 | mListView->addColumn(i18n("Content Type")); | ||
1167 | mABook = aBook; | ||
1168 | connect( this, SIGNAL( user1Clicked() ),SLOT ( slotApply())); | ||
1169 | setupFolderView(); | ||
1170 | resize( sizeHint().width()+50, sizeHint().height()+50 ); | ||
1171 | } | ||
1172 | |||
1173 | KAImportOLdialog::~KAImportOLdialog() | ||
1174 | { | ||
1175 | |||
1176 | } | ||
1177 | |||
1178 | void KAImportOLdialog::setSyncMode() | ||
1179 | { | ||
1180 | mSyncMode = true; | ||
1181 | findButton( User1 )->setText( i18n("Synchronize!") ); | ||
1182 | } | ||
1183 | KABC::Addressee::List KAImportOLdialog::getAddressList() | ||
1184 | { | ||
1185 | return mAList; | ||
1186 | } | ||
1187 | void KAImportOLdialog::setupFolderView() | ||
1188 | { | ||
1189 | SCODE sc = ::OleInitialize(NULL); | ||
1190 | if ( FAILED ( sc ) ) { | ||
1191 | KMessageBox::information(this,"OLE initialisation failed"); | ||
1192 | return; | ||
1193 | } | ||
1194 | if( ! KAImportOLdialog::sOLDispatch ) { | ||
1195 | if(!gOlAppAB.CreateDispatch(_T("Outlook.Application"),NULL)){ | ||
1196 | KMessageBox::information(this,"Sorry, cannot access Outlook"); | ||
1197 | return ; | ||
1198 | } | ||
1199 | KAImportOLdialog::sOLDispatch = true; | ||
1200 | } | ||
1201 | MAPIFolder mfInbox; | ||
1202 | MAPIFolder mfRoot; | ||
1203 | CString szName; | ||
1204 | _NameSpace olNS; | ||
1205 | olNS = gOlAppAB.GetNamespace(_T("MAPI")); | ||
1206 | mfInbox = olNS.GetDefaultFolder(6); | ||
1207 | mfRoot = mfInbox.GetParent(); | ||
1208 | szName = mfRoot.GetName(); | ||
1209 | long iType = mfRoot.GetDefaultItemType(); | ||
1210 | QString mes; | ||
1211 | mes = QString::fromUcs2( szName.GetBuffer() ); | ||
1212 | OLEListViewItem * root = new OLEListViewItem( mListView, mes ); | ||
1213 | mfRoot.m_lpDispatch->AddRef(); | ||
1214 | addFolder( root, mfRoot.m_lpDispatch ); | ||
1215 | root->setOpen( true ); | ||
1216 | mListView->setSortColumn( 0 ); | ||
1217 | mListView->sort( ); | ||
1218 | } | ||
1219 | |||
1220 | |||
1221 | void KAImportOLdialog::addFolder(OLEListViewItem* iParent, LPDISPATCH dispParent) | ||
1222 | { | ||
1223 | MAPIFolder mfParent(dispParent), mfChild; | ||
1224 | _Folders folders; | ||
1225 | _variant_t fndx((long)0); | ||
1226 | CString szName; | ||
1227 | long iType; | ||
1228 | OLEListViewItem* hChild; | ||
1229 | |||
1230 | folders = mfParent.GetFolders(); | ||
1231 | for(int i=1; i <= folders.GetCount(); ++i) | ||
1232 | { | ||
1233 | fndx = (long)i; | ||
1234 | mfChild = folders.Item(fndx.Detach()); | ||
1235 | mfChild.m_lpDispatch->AddRef(); | ||
1236 | szName = mfChild.GetName(); | ||
1237 | iType = mfChild.GetDefaultItemType(); | ||
1238 | hChild = new OLEListViewItem( iParent , QString::fromUcs2( szName.GetBuffer() ) ); | ||
1239 | hChild->setDataID( QString::fromUcs2(mfChild.GetEntryID().GetBuffer()) ); | ||
1240 | if ( iType != 2) | ||
1241 | hChild->setEnabled( false ); | ||
1242 | QString ts; | ||
1243 | switch( iType ) { | ||
1244 | case 0: | ||
1245 | ts = i18n("Mail"); | ||
1246 | break; | ||
1247 | case 1: | ||
1248 | ts = i18n("Calendar"); | ||
1249 | break; | ||
1250 | case 2: | ||
1251 | ts = i18n("Contacts"); | ||
1252 | break; | ||
1253 | case 3: | ||
1254 | ts = i18n("Todos"); | ||
1255 | break; | ||
1256 | case 4: | ||
1257 | ts = i18n("Journals"); | ||
1258 | break; | ||
1259 | case 5: | ||
1260 | ts = i18n("Notes"); | ||
1261 | break; | ||
1262 | default: | ||
1263 | ts = i18n("Unknown"); | ||
1264 | } | ||
1265 | hChild->setText( 1,ts); | ||
1266 | hChild->setData( (DWORD) mfChild.m_lpDispatch ); | ||
1267 | mfChild.m_lpDispatch->AddRef(); | ||
1268 | addFolder(hChild, mfChild.m_lpDispatch); | ||
1269 | } | ||
1270 | } | ||
1271 | |||
1272 | void KAImportOLdialog::slotApply() | ||
1273 | { | ||
1274 | importedItems = 0; | ||
1275 | OLEListViewItem* child = (OLEListViewItem*) mListView->firstChild(); | ||
1276 | while ( child ) { | ||
1277 | if ( child->isOn() ) { | ||
1278 | readContactData( child->data() ); | ||
1279 | if ( mSyncMode ) { | ||
1280 | mSelectedFolderID = child->dataID(); | ||
1281 | accept(); | ||
1282 | return; | ||
1283 | } | ||
1284 | } | ||
1285 | child = (OLEListViewItem*) child->itemBelow(); | ||
1286 | } | ||
1287 | QString mes = i18n("Importing complete.\n\n%1 items imported.").arg( importedItems); | ||
1288 | KMessageBox::information(this,mes); | ||
1289 | } | ||
1290 | void KAImportOLdialog::readContactData( DWORD folder ) | ||
1291 | { | ||
1292 | |||
1293 | LPDISPATCH dispItem = (LPDISPATCH)folder; | ||
1294 | dispItem->AddRef(); | ||
1295 | MAPIFolder mf(dispItem); | ||
1296 | mf.m_lpDispatch->AddRef(); | ||
1297 | _Items folderItems; | ||
1298 | _variant_t indx((long)0); | ||
1299 | LPDISPATCH itm; | ||
1300 | int i; | ||
1301 | folderItems = mf.GetItems(); | ||
1302 | QString cap = i18n("Importing contact data"); | ||
1303 | if ( mSyncMode ) { | ||
1304 | cap = i18n("Reading contact data..."); | ||
1305 | } | ||
1306 | QProgressDialog bar( cap,i18n("Abort"), folderItems.GetCount(),this); | ||
1307 | bar.setCaption (i18n("Accessing OL") ); | ||
1308 | int h = bar.sizeHint().height() ; | ||
1309 | int w = 300; | ||
1310 | int dw = QApplication::desktop()->width(); | ||
1311 | int dh = QApplication::desktop()->height(); | ||
1312 | //bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); | ||
1313 | bar.show(); | ||
1314 | for(i=1; i <= folderItems.GetCount(); ++i) | ||
1315 | { | ||
1316 | qApp->processEvents(); | ||
1317 | if ( ! bar.isVisible() ) | ||
1318 | return ; | ||
1319 | bar.setProgress( i ); | ||
1320 | indx = (long)i; | ||
1321 | itm = folderItems.Item(indx.Detach()); | ||
1322 | _ContactItem * pItem = (_ContactItem *)&itm; | ||
1323 | if ( addAddressee( ol2kapiContact( pItem, mSyncMode ) )) | ||
1324 | ++importedItems; | ||
1325 | itm->Release(); | ||
1326 | } | ||
1327 | } | ||
1328 | void KAImportOLdialog::slotOk() | ||
1329 | { | ||
1330 | QDialog::accept(); | ||
1331 | } | ||
1332 | |||
1333 | KABC::Addressee KAImportOLdialog::ol2kapiContact( _ContactItem * aItem , bool syncMode) | ||
1334 | { | ||
1335 | KABC::Addressee addressee; | ||
1336 | |||
1337 | addressee.setUid( QString::fromUcs2(aItem->GetEntryID().GetBuffer())); | ||
1338 | //GetLastModificationTime() | ||
1339 | //addressee.setName( const QString &name ); | ||
1340 | addressee.setFormattedName( QString::fromUcs2(aItem->GetFileAs().GetBuffer()) ); | ||
1341 | addressee.setFamilyName( QString::fromUcs2(aItem->GetLastName().GetBuffer()) ); | ||
1342 | addressee.setGivenName( QString::fromUcs2(aItem->GetFirstName().GetBuffer()) ); | ||
1343 | addressee.setAdditionalName( QString::fromUcs2(aItem->GetMiddleName().GetBuffer()) ); | ||
1344 | addressee.setPrefix(QString::fromUcs2(aItem->GetTitle().GetBuffer()) ); | ||
1345 | addressee.setSuffix( QString::fromUcs2(aItem->GetSuffix().GetBuffer()) ); | ||
1346 | addressee.setNickName( QString::fromUcs2(aItem->GetNickName().GetBuffer()) ); | ||
1347 | QDateTime dtb = mDdate2Qdtr(aItem->GetBirthday()); | ||
1348 | if ( dtb.isValid() ) | ||
1349 | addressee.setBirthday( mDdate2Qdtr(aItem->GetBirthday())); | ||
1350 | |||
1351 | //QString::fromUcs2(aItem->.GetBuffer()) | ||
1352 | //addressee.setMailer( const QString &mailer ); | ||
1353 | //addressee.setTimeZone( const TimeZone &timeZone ); | ||
1354 | //addressee.setGeo( const Geo &geo ); | ||
1355 | //addressee.setTitle( QString::fromUcs2(aItem->GetJobTitle().GetBuffer()) );// titel is the prefix | ||
1356 | addressee.setRole( QString::fromUcs2(aItem->GetJobTitle().GetBuffer()) ); | ||
1357 | addressee.setOrganization( QString::fromUcs2(aItem->GetCompanyName().GetBuffer()).replace( QRegExp("\\r"), "") ); | ||
1358 | QString notesStr = QString::fromUcs2(aItem->GetBody().GetBuffer()); | ||
1359 | notesStr.replace( QRegExp("\\r"), ""); | ||
1360 | |||
1361 | addressee.setProductId( QString::fromUcs2(aItem->GetCustomerID().GetBuffer()) ); | ||
1362 | //addressee.setRevision( const QDateTime &revision ); | ||
1363 | // addressee.setSortString( const QString &sortString ); | ||
1364 | addressee.setUrl( QString::fromUcs2(aItem->GetWebPage().GetBuffer()) ); | ||
1365 | |||
1366 | QString tempS; | ||
1367 | tempS = QString::fromUcs2(aItem->GetNetMeetingAlias().GetBuffer());//+" AT SERVER: " +QString::fromUcs2(aItem->GetNetMeetingServer().GetBuffer()); | ||
1368 | if ( tempS.length() > 12 ) | ||
1369 | addressee.insertCustom( "KADDRESSBOOK", "X-IMAddress", tempS ); | ||
1370 | tempS = QString::fromUcs2(aItem->GetSpouse().GetBuffer()); | ||
1371 | if ( !tempS.isEmpty() ) | ||
1372 | addressee.insertCustom( "KADDRESSBOOK", "X-SpousesName", tempS ); | ||
1373 | tempS = QString::fromUcs2(aItem->GetManagerName().GetBuffer()); | ||
1374 | if ( !tempS.isEmpty() ) | ||
1375 | addressee.insertCustom( "KADDRESSBOOK", "X-ManagersName", tempS ); | ||
1376 | tempS = QString::fromUcs2(aItem->GetAssistantName().GetBuffer()); | ||
1377 | if ( !tempS.isEmpty() ) | ||
1378 | addressee.insertCustom( "KADDRESSBOOK", "X-AssistantsName", tempS ); | ||
1379 | tempS = QString::fromUcs2(aItem->GetDepartment().GetBuffer()); | ||
1380 | if ( !tempS.isEmpty() ) | ||
1381 | addressee.insertCustom( "KADDRESSBOOK", "X-Department", tempS ); | ||
1382 | tempS = QString::fromUcs2(aItem->GetOfficeLocation().GetBuffer()).replace( QRegExp("\\r"), ""); | ||
1383 | if ( !tempS.isEmpty() ) | ||
1384 | addressee.insertCustom( "KADDRESSBOOK", "X-Office",tempS ); | ||
1385 | tempS = QString::fromUcs2(aItem->GetProfession().GetBuffer()); | ||
1386 | if ( !tempS.isEmpty() ) | ||
1387 | addressee.insertCustom( "KADDRESSBOOK", "X-Profession", tempS ); | ||
1388 | dtb = mDdate2Qdtr(aItem->GetAnniversary()); | ||
1389 | if (dtb.isValid() ) { | ||
1390 | QString dt = KGlobal::locale()->formatDate( dtb.date() , true, KLocale::ISODate); | ||
1391 | addressee.insertCustom( "KADDRESSBOOK", "X-Anniversary", dt); | ||
1392 | } | ||
1393 | int sec = aItem->GetSensitivity() ; | ||
1394 | if ( sec > 1 )// mapping pers -> private | ||
1395 | --sec; | ||
1396 | addressee.setSecrecy( sec ); | ||
1397 | //addressee.setLogo( const Picture &logo ); | ||
1398 | //addressee.setPhoto( const Picture &photo ); | ||
1399 | //addressee.setSound( const Sound &sound ); | ||
1400 | //addressee.setAgent( const Agent &agent ); | ||
1401 | QString cat = QString::fromUcs2( aItem->GetCategories().GetBuffer()).replace( QRegExp("\\r"), ""); | ||
1402 | cat = cat.replace( QRegExp("; "), ";"); | ||
1403 | addressee.setCategories( QStringList::split( ";", cat )); | ||
1404 | |||
1405 | QString phoneS; | ||
1406 | |||
1407 | phoneS = QString::fromUcs2( aItem->GetAssistantTelephoneNumber().GetBuffer()); | ||
1408 | if ( ! phoneS.isEmpty()) | ||
1409 | addressee.insertPhoneNumber( KABC::PhoneNumber(phoneS , | ||
1410 | KABC::PhoneNumber::Work + | ||
1411 | KABC::PhoneNumber::Voice + | ||
1412 | KABC::PhoneNumber::Msg ) ); | ||
1413 | phoneS = QString::fromUcs2( aItem->GetBusinessTelephoneNumber().GetBuffer()); | ||
1414 | if ( ! phoneS.isEmpty()) | ||
1415 | addressee.insertPhoneNumber( KABC::PhoneNumber(phoneS , | ||
1416 | KABC::PhoneNumber::Work + | ||
1417 | KABC::PhoneNumber::Pref) ); | ||
1418 | phoneS = QString::fromUcs2( aItem->GetBusiness2TelephoneNumber().GetBuffer()); | ||
1419 | if ( ! phoneS.isEmpty()) | ||
1420 | addressee.insertPhoneNumber( KABC::PhoneNumber(phoneS , | ||
1421 | KABC::PhoneNumber::Work ) ); | ||
1422 | phoneS = QString::fromUcs2( aItem->GetBusinessFaxNumber().GetBuffer()); | ||
1423 | if ( ! phoneS.isEmpty()) | ||
1424 | addressee.insertPhoneNumber( KABC::PhoneNumber(phoneS , | ||
1425 | KABC::PhoneNumber::Work + | ||
1426 | KABC::PhoneNumber::Fax ) ); | ||
1427 | phoneS = QString::fromUcs2( aItem->GetCarTelephoneNumber().GetBuffer()); | ||
1428 | if ( ! phoneS.isEmpty()) | ||
1429 | addressee.insertPhoneNumber( KABC::PhoneNumber(phoneS , | ||
1430 | KABC::PhoneNumber::Car ) ); | ||
1431 | phoneS = QString::fromUcs2( aItem->GetHomeTelephoneNumber().GetBuffer()); | ||
1432 | if ( ! phoneS.isEmpty()) | ||
1433 | addressee.insertPhoneNumber( KABC::PhoneNumber(phoneS , | ||
1434 | KABC::PhoneNumber::Home + | ||
1435 | KABC::PhoneNumber::Pref ) ); | ||
1436 | phoneS = QString::fromUcs2( aItem->GetHome2TelephoneNumber().GetBuffer()); | ||
1437 | if ( ! phoneS.isEmpty()) | ||
1438 | addressee.insertPhoneNumber( KABC::PhoneNumber(phoneS , | ||
1439 | KABC::PhoneNumber::Home ) ); | ||
1440 | phoneS = QString::fromUcs2( aItem->GetHomeFaxNumber().GetBuffer()); | ||
1441 | if ( ! phoneS.isEmpty()) | ||
1442 | addressee.insertPhoneNumber( KABC::PhoneNumber(phoneS , | ||
1443 | KABC::PhoneNumber::Home + | ||
1444 | KABC::PhoneNumber::Fax ) ); | ||
1445 | phoneS = QString::fromUcs2( aItem->GetISDNNumber().GetBuffer()); | ||
1446 | if ( ! phoneS.isEmpty()) | ||
1447 | addressee.insertPhoneNumber( KABC::PhoneNumber(phoneS , | ||
1448 | KABC::PhoneNumber::Isdn ) ); | ||
1449 | phoneS = QString::fromUcs2( aItem->GetMobileTelephoneNumber().GetBuffer()); | ||
1450 | if ( ! phoneS.isEmpty()) | ||
1451 | addressee.insertPhoneNumber( KABC::PhoneNumber(phoneS , | ||
1452 | KABC::PhoneNumber::Cell ) ); | ||
1453 | phoneS = QString::fromUcs2( aItem->GetOtherFaxNumber().GetBuffer()); | ||
1454 | if ( ! phoneS.isEmpty()) | ||
1455 | addressee.insertPhoneNumber( KABC::PhoneNumber(phoneS , | ||
1456 | KABC::PhoneNumber::Fax ) ); | ||
1457 | phoneS = QString::fromUcs2( aItem->GetOtherTelephoneNumber().GetBuffer()); | ||
1458 | if ( ! phoneS.isEmpty()) | ||
1459 | addressee.insertPhoneNumber( KABC::PhoneNumber(phoneS , | ||
1460 | KABC::PhoneNumber::Voice ) ); | ||
1461 | phoneS = QString::fromUcs2( aItem->GetPagerNumber().GetBuffer()); | ||
1462 | if ( ! phoneS.isEmpty()) | ||
1463 | addressee.insertPhoneNumber( KABC::PhoneNumber(phoneS , | ||
1464 | KABC::PhoneNumber::Pager ) ); | ||
1465 | phoneS = QString::fromUcs2( aItem->GetPrimaryTelephoneNumber().GetBuffer()); | ||
1466 | if ( ! phoneS.isEmpty()) | ||
1467 | addressee.insertPhoneNumber( KABC::PhoneNumber(phoneS , | ||
1468 | KABC::PhoneNumber::Pref ) ); | ||
1469 | phoneS = QString::fromUcs2( aItem->GetTTYTDDTelephoneNumber().GetBuffer()); | ||
1470 | if ( ! phoneS.isEmpty()) | ||
1471 | addressee.insertPhoneNumber( KABC::PhoneNumber(phoneS , | ||
1472 | KABC::PhoneNumber::Pcs + | ||
1473 | KABC::PhoneNumber::Voice) ); | ||
1474 | phoneS = QString::fromUcs2( aItem->GetTelexNumber().GetBuffer()); | ||
1475 | if ( ! phoneS.isEmpty()) | ||
1476 | addressee.insertPhoneNumber( KABC::PhoneNumber(phoneS , | ||
1477 | KABC::PhoneNumber::Pcs ) ); | ||
1478 | phoneS = QString::fromUcs2( aItem->GetCompanyMainTelephoneNumber().GetBuffer()); | ||
1479 | if ( ! phoneS.isEmpty()) | ||
1480 | addressee.insertPhoneNumber( KABC::PhoneNumber(phoneS , | ||
1481 | KABC::PhoneNumber::Work + | ||
1482 | KABC::PhoneNumber::Msg ) ); | ||
1483 | phoneS = QString::fromUcs2( aItem->GetRadioTelephoneNumber().GetBuffer()); | ||
1484 | if ( ! phoneS.isEmpty()) | ||
1485 | addressee.insertPhoneNumber( KABC::PhoneNumber(phoneS , | ||
1486 | KABC::PhoneNumber::Pcs + | ||
1487 | KABC::PhoneNumber::Pref ) ); | ||
1488 | phoneS = QString::fromUcs2( aItem->GetCallbackTelephoneNumber().GetBuffer()); | ||
1489 | if ( ! phoneS.isEmpty()) | ||
1490 | addressee.insertPhoneNumber( KABC::PhoneNumber(phoneS , | ||
1491 | KABC::PhoneNumber::Msg ) ); | ||
1492 | |||
1493 | bool preferred = true; | ||
1494 | phoneS = QString::fromUcs2( aItem->GetEmail1Address().GetBuffer()); | ||
1495 | if ( ! phoneS.isEmpty()) { | ||
1496 | addressee.insertEmail(phoneS , preferred ); | ||
1497 | preferred = false; | ||
1498 | } | ||
1499 | phoneS = QString::fromUcs2( aItem->GetEmail2Address().GetBuffer()); | ||
1500 | if ( ! phoneS.isEmpty()) { | ||
1501 | addressee.insertEmail(phoneS , preferred ); | ||
1502 | preferred = false; | ||
1503 | } | ||
1504 | phoneS = QString::fromUcs2( aItem->GetEmail3Address().GetBuffer()); | ||
1505 | if ( ! phoneS.isEmpty()) { | ||
1506 | addressee.insertEmail(phoneS , preferred ); | ||
1507 | preferred = false; | ||
1508 | } | ||
1509 | // is this the number of the preferred email? | ||
1510 | //long GetSelectedMailingAddress();??? | ||
1511 | |||
1512 | KABC::Address addressHome; | ||
1513 | KABC::Address* addressAdd = &addressHome; | ||
1514 | bool insert = false; | ||
1515 | phoneS = QString::fromUcs2( aItem->GetHomeAddressCountry().GetBuffer()); | ||
1516 | phoneS.replace( QRegExp("\\r"), ""); | ||
1517 | if ( ! phoneS.isEmpty()) { | ||
1518 | addressAdd->setCountry(phoneS ); | ||
1519 | insert = true; | ||
1520 | } | ||
1521 | phoneS = QString::fromUcs2( aItem->GetHomeAddressState().GetBuffer()); | ||
1522 | phoneS.replace( QRegExp("\\r"), ""); | ||
1523 | if ( ! phoneS.isEmpty()) { | ||
1524 | addressAdd->setRegion(phoneS ); | ||
1525 | insert = true; | ||
1526 | } | ||
1527 | phoneS = QString::fromUcs2( aItem->GetHomeAddressCity().GetBuffer()); | ||
1528 | phoneS.replace( QRegExp("\\r"), ""); | ||
1529 | if ( ! phoneS.isEmpty()) { | ||
1530 | addressAdd->setLocality(phoneS ); | ||
1531 | insert = true; | ||
1532 | } | ||
1533 | phoneS = QString::fromUcs2( aItem->GetHomeAddressPostalCode().GetBuffer()); | ||
1534 | phoneS.replace( QRegExp("\\r"), ""); | ||
1535 | if ( ! phoneS.isEmpty()) { | ||
1536 | addressAdd->setPostalCode(phoneS ); | ||
1537 | insert = true; | ||
1538 | } | ||
1539 | phoneS = QString::fromUcs2( aItem->GetHomeAddressPostOfficeBox().GetBuffer()); | ||
1540 | phoneS.replace( QRegExp("\\r"), ""); | ||
1541 | if ( ! phoneS.isEmpty()) { | ||
1542 | addressAdd->setPostOfficeBox(phoneS ); | ||
1543 | insert = true; | ||
1544 | } | ||
1545 | phoneS = QString::fromUcs2( aItem->GetHomeAddressStreet().GetBuffer()); | ||
1546 | phoneS.replace( QRegExp("\\r"), ""); | ||
1547 | if ( ! phoneS.isEmpty()) { | ||
1548 | addressAdd->setStreet(phoneS ); | ||
1549 | insert = true; | ||
1550 | } | ||
1551 | phoneS = QString::fromUcs2( aItem->GetHomeAddress().GetBuffer()); | ||
1552 | phoneS.replace( QRegExp("\\r"), ""); | ||
1553 | if ( ! phoneS.isEmpty()) { | ||
1554 | // redundant !addressAdd->setExtended(phoneS ); | ||
1555 | // insert = true; | ||
1556 | } | ||
1557 | addressAdd->setType( KABC::Address::Home ); | ||
1558 | if ( insert ) | ||
1559 | addressee.insertAddress( *addressAdd ); | ||
1560 | // ++++++++++++++++++++++ end of address | ||
1561 | |||
1562 | KABC::Address addressWork; | ||
1563 | addressAdd = &addressWork; | ||
1564 | insert = false; | ||
1565 | phoneS = QString::fromUcs2( aItem->GetBusinessAddressCountry().GetBuffer()); | ||
1566 | phoneS.replace( QRegExp("\\r"), ""); | ||
1567 | if ( ! phoneS.isEmpty()) { | ||
1568 | addressAdd->setCountry(phoneS ); | ||
1569 | insert = true; | ||
1570 | } | ||
1571 | phoneS = QString::fromUcs2( aItem->GetBusinessAddressState().GetBuffer()); | ||
1572 | phoneS.replace( QRegExp("\\r"), ""); | ||
1573 | if ( ! phoneS.isEmpty()) { | ||
1574 | addressAdd->setRegion(phoneS ); | ||
1575 | insert = true; | ||
1576 | } | ||
1577 | phoneS = QString::fromUcs2( aItem->GetBusinessAddressCity().GetBuffer()); | ||
1578 | phoneS.replace( QRegExp("\\r"), ""); | ||
1579 | if ( ! phoneS.isEmpty()) { | ||
1580 | addressAdd->setLocality(phoneS ); | ||
1581 | insert = true; | ||
1582 | } | ||
1583 | phoneS = QString::fromUcs2( aItem->GetBusinessAddressPostalCode().GetBuffer()); | ||
1584 | phoneS.replace( QRegExp("\\r"), ""); | ||
1585 | if ( ! phoneS.isEmpty()) { | ||
1586 | addressAdd->setPostalCode(phoneS ); | ||
1587 | insert = true; | ||
1588 | } | ||
1589 | phoneS = QString::fromUcs2( aItem->GetBusinessAddressPostOfficeBox().GetBuffer()); | ||
1590 | phoneS.replace( QRegExp("\\r"), ""); | ||
1591 | if ( ! phoneS.isEmpty()) { | ||
1592 | addressAdd->setPostOfficeBox(phoneS ); | ||
1593 | insert = true; | ||
1594 | } | ||
1595 | phoneS = QString::fromUcs2( aItem->GetBusinessAddressStreet().GetBuffer()); | ||
1596 | phoneS.replace( QRegExp("\\r"), ""); | ||
1597 | if ( ! phoneS.isEmpty()) { | ||
1598 | addressAdd->setStreet(phoneS ); | ||
1599 | insert = true; | ||
1600 | } | ||
1601 | phoneS = QString::fromUcs2( aItem->GetBusinessAddress().GetBuffer()); | ||
1602 | phoneS.replace( QRegExp("\\r"), ""); | ||
1603 | if ( ! phoneS.isEmpty()) { | ||
1604 | // redundant !addressAdd->setExtended(phoneS ); | ||
1605 | // insert = true; | ||
1606 | } | ||
1607 | addressAdd->setType( KABC::Address::Work ); | ||
1608 | if ( insert ) | ||
1609 | addressee.insertAddress( *addressAdd ); | ||
1610 | // ++++++++++++++++++++++ end of address | ||
1611 | |||
1612 | KABC::Address addressOther; | ||
1613 | addressAdd = &addressOther; | ||
1614 | insert = false; | ||
1615 | phoneS = QString::fromUcs2( aItem->GetOtherAddressCountry().GetBuffer()); | ||
1616 | phoneS.replace( QRegExp("\\r"), ""); | ||
1617 | if ( ! phoneS.isEmpty()) { | ||
1618 | addressAdd->setCountry(phoneS ); | ||
1619 | insert = true; | ||
1620 | } | ||
1621 | phoneS = QString::fromUcs2( aItem->GetOtherAddressState().GetBuffer()); | ||
1622 | phoneS.replace( QRegExp("\\r"), ""); | ||
1623 | if ( ! phoneS.isEmpty()) { | ||
1624 | addressAdd->setRegion(phoneS ); | ||
1625 | insert = true; | ||
1626 | } | ||
1627 | phoneS = QString::fromUcs2( aItem->GetOtherAddressCity().GetBuffer()); | ||
1628 | phoneS.replace( QRegExp("\\r"), ""); | ||
1629 | if ( ! phoneS.isEmpty()) { | ||
1630 | addressAdd->setLocality(phoneS ); | ||
1631 | insert = true; | ||
1632 | } | ||
1633 | phoneS = QString::fromUcs2( aItem->GetOtherAddressPostalCode().GetBuffer()); | ||
1634 | phoneS.replace( QRegExp("\\r"), ""); | ||
1635 | if ( ! phoneS.isEmpty()) { | ||
1636 | addressAdd->setPostalCode(phoneS ); | ||
1637 | insert = true; | ||
1638 | } | ||
1639 | phoneS = QString::fromUcs2( aItem->GetOtherAddressPostOfficeBox().GetBuffer()); | ||
1640 | phoneS.replace( QRegExp("\\r"), ""); | ||
1641 | if ( ! phoneS.isEmpty()) { | ||
1642 | addressAdd->setPostOfficeBox(phoneS ); | ||
1643 | insert = true; | ||
1644 | } | ||
1645 | phoneS = QString::fromUcs2( aItem->GetOtherAddressStreet().GetBuffer()); | ||
1646 | phoneS.replace( QRegExp("\\r"), ""); | ||
1647 | if ( ! phoneS.isEmpty()) { | ||
1648 | addressAdd->setStreet(phoneS ); | ||
1649 | insert = true; | ||
1650 | } | ||
1651 | phoneS = QString::fromUcs2( aItem->GetOtherAddress().GetBuffer()); | ||
1652 | if ( ! phoneS.isEmpty()) { | ||
1653 | // redundant !addressAdd->setExtended(phoneS ); | ||
1654 | //insert = true; | ||
1655 | } | ||
1656 | //addressAdd->setId( ); | ||
1657 | if ( insert ) | ||
1658 | addressee.insertAddress( *addressAdd ); | ||
1659 | // ++++++++++++++++++++++ end of address | ||
1660 | #if 0 | ||
1661 | KABC::Address addressMail; | ||
1662 | addressAdd = &addressMail; | ||
1663 | insert = false; | ||
1664 | phoneS = QString::fromUcs2( aItem->GetMailingAddressCountry().GetBuffer()); | ||
1665 | phoneS.replace( QRegExp("\\r"), ""); | ||
1666 | if ( ! phoneS.isEmpty()) { | ||
1667 | addressAdd->setCountry(phoneS ); | ||
1668 | insert = true; | ||
1669 | } | ||
1670 | phoneS = QString::fromUcs2( aItem->GetMailingAddressState().GetBuffer()); | ||
1671 | phoneS.replace( QRegExp("\\r"), ""); | ||
1672 | if ( ! phoneS.isEmpty()) { | ||
1673 | addressAdd->setRegion(phoneS ); | ||
1674 | insert = true; | ||
1675 | } | ||
1676 | phoneS = QString::fromUcs2( aItem->GetMailingAddressCity().GetBuffer()); | ||
1677 | phoneS.replace( QRegExp("\\r"), ""); | ||
1678 | if ( ! phoneS.isEmpty()) { | ||
1679 | addressAdd->setLocality(phoneS ); | ||
1680 | insert = true; | ||
1681 | } | ||
1682 | phoneS = QString::fromUcs2( aItem->GetMailingAddressPostalCode().GetBuffer()); | ||
1683 | phoneS.replace( QRegExp("\\r"), ""); | ||
1684 | if ( ! phoneS.isEmpty()) { | ||
1685 | addressAdd->setPostalCode(phoneS ); | ||
1686 | insert = true; | ||
1687 | } | ||
1688 | phoneS = QString::fromUcs2( aItem->GetMailingAddressPostOfficeBox().GetBuffer()); | ||
1689 | phoneS.replace( QRegExp("\\r"), ""); | ||
1690 | if ( ! phoneS.isEmpty()) { | ||
1691 | addressAdd->setPostOfficeBox(phoneS ); | ||
1692 | insert = true; | ||
1693 | } | ||
1694 | phoneS = QString::fromUcs2( aItem->GetMailingAddressStreet().GetBuffer()); | ||
1695 | phoneS.replace( QRegExp("\\r"), ""); | ||
1696 | if ( ! phoneS.isEmpty()) { | ||
1697 | addressAdd->setStreet(phoneS ); | ||
1698 | insert = true; | ||
1699 | } | ||
1700 | phoneS = QString::fromUcs2( aItem->GetMailingAddress().GetBuffer()); | ||
1701 | phoneS.replace( QRegExp("\\r"), ""); | ||
1702 | if ( ! phoneS.isEmpty()) { | ||
1703 | // redundant ! addressAdd->setExtended(phoneS ); | ||
1704 | // insert = true; | ||
1705 | } | ||
1706 | addressAdd->setType( KABC::Address::Postal ); | ||
1707 | if ( insert ) { | ||
1708 | addressee.insertAddress( *addressAdd ); | ||
1709 | } | ||
1710 | #endif | ||
1711 | // the following code is disabled | ||
1712 | // it does not seem to be useful | ||
1713 | #if 0 | ||
1714 | if ( insert ) { | ||
1715 | addressAdd->setType( KABC::Address::Home ); | ||
1716 | if ( addressMail == addressHome ) { | ||
1717 | addressHome.setType( KABC::Address::Postal+ KABC::Address::Home ); | ||
1718 | addressee.insertAddress( addressHome ); | ||
1719 | } else { | ||
1720 | addressAdd->setType( KABC::Address::Work ); | ||
1721 | if ( addressMail == addressWork ){ | ||
1722 | addressWork.setType( KABC::Address::Postal+ KABC::Address::Work ); | ||
1723 | addressee.insertAddress( addressWork ); | ||
1724 | |||
1725 | } else { | ||
1726 | addressAdd->setType( 0 ); | ||
1727 | if ( addressOther == addressMail ){ | ||
1728 | addressOther.setType( KABC::Address::Postal ); | ||
1729 | addressee.insertAddress( addressOther ); | ||
1730 | } else { | ||
1731 | addressee.insertAddress( *addressAdd ); | ||
1732 | } | ||
1733 | } | ||
1734 | } | ||
1735 | } | ||
1736 | #endif | ||
1737 | // ++++++++++++++++++++++ end of ALL addresses | ||
1738 | //GetUserProperties(); | ||
1739 | tempS = QString::fromUcs2(aItem->GetInternetFreeBusyAddress().GetBuffer()); | ||
1740 | phoneS.replace( QRegExp("\\r"), ""); | ||
1741 | if ( !tempS.isEmpty() ) | ||
1742 | addressee.insertCustom( "KADDRESSBOOK", "X-FreeBusyUrl", tempS ); | ||
1743 | tempS = QString::fromUcs2(aItem->GetChildren().GetBuffer()); | ||
1744 | if ( !tempS.isEmpty() ) | ||
1745 | addressee.insertCustom( "KADDRESSBOOK", "X-Children", tempS ); | ||
1746 | int gen = aItem->GetGender(); | ||
1747 | if ( gen != 0 ) { // 0 undef - 1 female - 2 male | ||
1748 | if ( gen == 1 ) | ||
1749 | addressee.insertCustom( "KADDRESSBOOK", "X-Gender", "female" ); | ||
1750 | else | ||
1751 | addressee.insertCustom( "KADDRESSBOOK", "X-Gender", "male" ); | ||
1752 | } | ||
1753 | QString additionalInfo; | ||
1754 | QString tempAdd; | ||
1755 | tempAdd = QString::fromUcs2(aItem->GetLanguage().GetBuffer()); | ||
1756 | if ( ! tempAdd.isEmpty() ) { | ||
1757 | additionalInfo += i18n("\nLanguage: "); | ||
1758 | additionalInfo += tempAdd; | ||
1759 | } | ||
1760 | tempAdd = QString::fromUcs2(aItem->GetHobby().GetBuffer()); | ||
1761 | phoneS.replace( QRegExp("\\r"), ""); | ||
1762 | if ( ! tempAdd.isEmpty() ) { | ||
1763 | additionalInfo += i18n("\nHobby: "); | ||
1764 | additionalInfo += tempAdd;; | ||
1765 | } | ||
1766 | tempAdd =QString::fromUcs2(aItem->GetPersonalHomePage().GetBuffer()); | ||
1767 | phoneS.replace( QRegExp("\\r"), ""); | ||
1768 | if ( ! tempAdd.isEmpty() ) { | ||
1769 | additionalInfo += i18n("\nHomepage: "); | ||
1770 | additionalInfo += tempAdd;; | ||
1771 | } | ||
1772 | tempAdd = QString::fromUcs2(aItem->GetBillingInformation().GetBuffer()); | ||
1773 | phoneS.replace( QRegExp("\\r"), ""); | ||
1774 | if ( ! tempAdd.isEmpty() ) { | ||
1775 | additionalInfo += i18n("\nBilling information: "); | ||
1776 | additionalInfo += tempAdd;; | ||
1777 | } | ||
1778 | tempAdd = QString::fromUcs2(aItem->GetCustomerID().GetBuffer()); | ||
1779 | phoneS.replace( QRegExp("\\r"), ""); | ||
1780 | if ( ! tempAdd.isEmpty() ) { | ||
1781 | additionalInfo += i18n("\nCustomer ID: "); | ||
1782 | additionalInfo += tempAdd;; | ||
1783 | } | ||
1784 | tempAdd = QString::fromUcs2(aItem->GetUser1().GetBuffer()); | ||
1785 | phoneS.replace( QRegExp("\\r"), ""); | ||
1786 | if ( ! tempAdd.isEmpty() ) { | ||
1787 | additionalInfo += i18n("\nUser1: "); | ||
1788 | additionalInfo += tempAdd;; | ||
1789 | } | ||
1790 | tempAdd = QString::fromUcs2(aItem->GetUser2().GetBuffer()); | ||
1791 | phoneS.replace( QRegExp("\\r"), ""); | ||
1792 | if ( ! tempAdd.isEmpty() ) { | ||
1793 | additionalInfo += i18n("\nUser2: "); | ||
1794 | additionalInfo += tempAdd;; | ||
1795 | } | ||
1796 | tempAdd = QString::fromUcs2(aItem->GetUser3().GetBuffer()); | ||
1797 | phoneS.replace( QRegExp("\\r"), ""); | ||
1798 | if ( ! tempAdd.isEmpty() ) { | ||
1799 | additionalInfo += i18n("\nUser3: "); | ||
1800 | additionalInfo += tempAdd;; | ||
1801 | } | ||
1802 | tempAdd = QString::fromUcs2(aItem->GetUser4().GetBuffer()); | ||
1803 | phoneS.replace( QRegExp("\\r"), ""); | ||
1804 | if ( ! tempAdd.isEmpty() ) { | ||
1805 | additionalInfo += i18n("\nUser4: "); | ||
1806 | additionalInfo += tempAdd;; | ||
1807 | } | ||
1808 | if (!additionalInfo.isEmpty() && ! syncMode ) { | ||
1809 | tempAdd = notesStr; | ||
1810 | notesStr = "+++++++++++++++++++++++++++\n"; | ||
1811 | notesStr += i18n("Additonal fields created\nby KA/Pi Outlook import:"); | ||
1812 | notesStr += additionalInfo; | ||
1813 | notesStr += i18n("\nEnd additonal fields created\nby KA/Pi Outlook import!\n"); | ||
1814 | notesStr += "+++++++++++++++++++++++++++\n"; | ||
1815 | notesStr += tempAdd; | ||
1816 | } | ||
1817 | addressee.setNote( notesStr ); | ||
1818 | #if 0 | ||
1819 | // pending | ||
1820 | - IM address: no clue where to get info about the helper ID | ||
1821 | -custom fields: difficult to implement - not implemented | ||
1822 | -keys: makes no sense | ||
1823 | #endif | ||
1824 | return addressee; | ||
1825 | } | ||
1826 | void KAImportOLdialog::slotCancel() | ||
1827 | { | ||
1828 | reject(); | ||
1829 | } | ||
1830 | |||
1831 | bool KAImportOLdialog::addAddressee( KABC::Addressee a ) | ||
1832 | { | ||
1833 | bool add = true; | ||
1834 | KABC::Addressee::List::Iterator it; | ||
1835 | for ( it = mAList.begin(); it != mAList.end(); ++it ) { | ||
1836 | if ( (*it).uid() == a.uid() ) { | ||
1837 | add = false; | ||
1838 | break; | ||
1839 | } | ||
1840 | } | ||
1841 | if ( add ) { | ||
1842 | if ( mABook->findByUid(a.uid() ).isEmpty()) | ||
1843 | mAList.append ( a ); | ||
1844 | else | ||
1845 | add = false; | ||
1846 | } | ||
1847 | return add; | ||
1848 | } | ||
1849 | // ***************************************************************** | ||
1850 | // ***************************************************************** | ||
1851 | KAwritebackOL::KAwritebackOL( const QString &olFolderID ): QObject() | ||
1852 | { | ||
1853 | mSelectedFolderID = olFolderID; | ||
1854 | } | ||
1855 | |||
1856 | |||
1857 | KAwritebackOL::~KAwritebackOL() | ||
1858 | { | ||
1859 | |||
1860 | } | ||
1861 | |||
1862 | bool KAwritebackOL::init() | ||
1863 | { | ||
1864 | mSelectedFolder = getFolderFromID( 0 ); | ||
1865 | if ( mSelectedFolder == 0 ) { | ||
1866 | KMessageBox::information(0,"KAwritebackOL: No contact folder found"); | ||
1867 | return false; | ||
1868 | } | ||
1869 | LPDISPATCH dispItem = mSelectedFolder; | ||
1870 | dispItem->AddRef(); | ||
1871 | MAPIFolder mf(dispItem); | ||
1872 | mf.m_lpDispatch->AddRef(); | ||
1873 | mFolderItems = mf.GetItems(); | ||
1874 | return true; | ||
1875 | } | ||
1876 | void KAwritebackOL::deleteAddressee( KABC::Addressee a ) | ||
1877 | { | ||
1878 | LPDISPATCH itm = getOLitemFromUid ( a.originalExternalUID() ); | ||
1879 | _ContactItem* cItem = (_ContactItem *)&itm; | ||
1880 | if ( cItem != 0 ) { | ||
1881 | //KMessageBox::information(0,"delete: item found " + a.formattedName() + QString::fromUcs2(cItem->GetLastName().GetBuffer())); | ||
1882 | cItem->Delete(); | ||
1883 | } | ||
1884 | } | ||
1885 | KABC::Addressee KAwritebackOL::changeAddressee( KABC::Addressee a ) | ||
1886 | { | ||
1887 | |||
1888 | LPDISPATCH itm = getOLitemFromUid ( a.originalExternalUID() ); | ||
1889 | _ContactItem* cItem = (_ContactItem *)&itm; | ||
1890 | if ( cItem != 0 ) { | ||
1891 | //KMessageBox::information(0,"Change: item found " + a.formattedName()); | ||
1892 | writeData2OLitem( a, cItem ); | ||
1893 | KABC::Addressee retval = KAImportOLdialog::ol2kapiContact( cItem , true ); | ||
1894 | retval.setUid( a.uid() ); | ||
1895 | retval.setExternalUID( a.originalExternalUID() ); | ||
1896 | retval.setOriginalExternalUID( a.originalExternalUID() ); | ||
1897 | return retval; | ||
1898 | } | ||
1899 | return KABC::Addressee(); | ||
1900 | } | ||
1901 | KABC::Addressee KAwritebackOL::addAddressee( KABC::Addressee a ) | ||
1902 | { | ||
1903 | QString newOLid; | ||
1904 | LPDISPATCH c_itm = gOlAppAB.CreateItem(2); | ||
1905 | _ContactItem * aItem = (_ContactItem *)&c_itm ; | ||
1906 | writeData2OLitem( a, aItem ); | ||
1907 | newOLid = QString::fromUcs2(aItem->GetEntryID().GetBuffer()); | ||
1908 | KABC::Addressee retval = KAImportOLdialog::ol2kapiContact( aItem , true ); | ||
1909 | retval.setUid( a.uid() ); | ||
1910 | retval.setExternalUID( newOLid ); | ||
1911 | retval.setOriginalExternalUID( newOLid ); | ||
1912 | return retval; | ||
1913 | } | ||
1914 | void KAwritebackOL::writeData2OLitem( KABC::Addressee addressee, _ContactItem * aItem ) | ||
1915 | { | ||
1916 | // addressee.setUid( QString::fromUcs2(aItem->GetEntryID().GetBuffer())); | ||
1917 | //GetLastModificationTime() | ||
1918 | //addressee.setName( const QString &name ); | ||
1919 | |||
1920 | aItem->SetFileAs(addressee.formattedName().ucs2()); | ||
1921 | aItem->SetLastName(addressee.familyName().ucs2()); | ||
1922 | aItem->SetFirstName(addressee.givenName( ).ucs2()); | ||
1923 | aItem->SetMiddleName(addressee.additionalName( ).ucs2()); | ||
1924 | aItem->SetTitle(addressee.prefix().ucs2()); | ||
1925 | aItem->SetSuffix(addressee.suffix( ).ucs2()); | ||
1926 | aItem->SetNickName(addressee.nickName( ).ucs2()); | ||
1927 | if ( addressee.birthday().isValid() ) | ||
1928 | aItem->SetBirthday(Qdt2date(addressee.birthday())); | ||
1929 | else | ||
1930 | aItem->SetBirthday(Qdt2date(QDateTime(QDate( 4501,1,1 )))); | ||
1931 | //).ucs2()(aItem->) | ||
1932 | //addressee.Mailer( const QString &mailer ); | ||
1933 | //addressee.TimeZone( const TimeZone &timeZone ); | ||
1934 | //addressee.Geo( const Geo &geo ); | ||
1935 | //addressee.Title( ).ucs2()(aItem->SetJobTitle()) );// titel is the prefix | ||
1936 | aItem->SetJobTitle(addressee.role( ).ucs2()); | ||
1937 | aItem->SetCompanyName(addressee.organization( ).ucs2()); | ||
1938 | QString notesStr = addressee.note(); | ||
1939 | notesStr.replace( QRegExp("\\n"), "\n\r"); | ||
1940 | aItem->SetBody(notesStr.ucs2()); | ||
1941 | |||
1942 | aItem->SetCustomerID(addressee.productId( ).ucs2()); | ||
1943 | //addressee.Revision( const QDateTime &revision ); | ||
1944 | // addressee.SortString( const QString &sortString ); | ||
1945 | aItem->SetWebPage( addressee.url().url().ucs2()); | ||
1946 | |||
1947 | QString tempS; | ||
1948 | |||
1949 | |||
1950 | tempS = addressee.custom( "KADDRESSBOOK", "X-IMAddress"); | ||
1951 | aItem->SetNetMeetingAlias(tempS.ucs2()); | ||
1952 | |||
1953 | tempS = addressee.custom( "KADDRESSBOOK", "X-SpousesName" ); | ||
1954 | aItem->SetSpouse(tempS.ucs2()); | ||
1955 | |||
1956 | tempS = addressee.custom( "KADDRESSBOOK", "X-ManagersName" ); | ||
1957 | aItem->SetManagerName(tempS.ucs2()); | ||
1958 | |||
1959 | tempS = addressee.custom( "KADDRESSBOOK", "X-AssistantsName" ); | ||
1960 | aItem->SetAssistantName(tempS.ucs2()); | ||
1961 | |||
1962 | tempS = addressee.custom( "KADDRESSBOOK", "X-Department" ); | ||
1963 | aItem->SetDepartment(tempS.ucs2()); | ||
1964 | |||
1965 | tempS = addressee.custom( "KADDRESSBOOK", "X-Office" ); | ||
1966 | aItem->SetOfficeLocation(tempS.ucs2()); | ||
1967 | |||
1968 | tempS = addressee.custom( "KADDRESSBOOK", "X-Profession"); | ||
1969 | aItem->SetProfession(tempS.ucs2()); | ||
1970 | |||
1971 | tempS = addressee.custom( "KADDRESSBOOK", "X-Anniversary"); | ||
1972 | if ( !tempS.isEmpty() ){ | ||
1973 | QDateTime dt = QDateTime ( KGlobal::locale()->readDate( tempS,"%Y-%m-%d") ); | ||
1974 | aItem->SetAnniversary(Qdt2date( dt )); | ||
1975 | } else { | ||
1976 | aItem->SetAnniversary(Qdt2date(QDateTime(QDate( 4501,1,1 )))); | ||
1977 | } | ||
1978 | int sec = (int)addressee.secrecy().type(); | ||
1979 | if ( sec > 0 )// mapping pers -> private | ||
1980 | ++sec; | ||
1981 | aItem->SetSensitivity( sec ) ; | ||
1982 | //addressee.Logo( const Picture &logo ); | ||
1983 | //addressee.Photo( const Picture &photo ); | ||
1984 | //addressee.Sound( const Sound &sound ); | ||
1985 | //addressee.Agent( const Agent &agent ); | ||
1986 | |||
1987 | QString cat = addressee.categories().join("; "); | ||
1988 | aItem->SetCategories( cat.ucs2()); | ||
1989 | |||
1990 | |||
1991 | KABC::PhoneNumber::List phoneNumbers; | ||
1992 | KABC::PhoneNumber::List::Iterator phoneIter; | ||
1993 | phoneNumbers = addressee.phoneNumbers(); | ||
1994 | for ( phoneIter = phoneNumbers.begin(); phoneIter != phoneNumbers.end(); | ||
1995 | ++phoneIter ) { | ||
1996 | |||
1997 | } | ||
1998 | QString phoneS; | ||
1999 | |||
2000 | phoneS = addressee.phoneNumberString( | ||
2001 | KABC::PhoneNumber::Work + | ||
2002 | KABC::PhoneNumber::Voice + | ||
2003 | KABC::PhoneNumber::Msg ); | ||
2004 | aItem->SetAssistantTelephoneNumber(phoneS.ucs2()); | ||
2005 | |||
2006 | phoneS = addressee.phoneNumberString( | ||
2007 | KABC::PhoneNumber::Work + | ||
2008 | KABC::PhoneNumber::Pref) ; | ||
2009 | aItem->SetBusinessTelephoneNumber(phoneS.ucs2()); | ||
2010 | |||
2011 | phoneS = addressee.phoneNumberString( | ||
2012 | KABC::PhoneNumber::Work ) ; | ||
2013 | aItem->SetBusiness2TelephoneNumber(phoneS.ucs2()); | ||
2014 | |||
2015 | phoneS = addressee.phoneNumberString( | ||
2016 | KABC::PhoneNumber::Work + | ||
2017 | KABC::PhoneNumber::Fax ) ; | ||
2018 | aItem->SetBusinessFaxNumber(phoneS.ucs2()); | ||
2019 | |||
2020 | |||
2021 | phoneS = addressee.phoneNumberString( | ||
2022 | KABC::PhoneNumber::Car ) ; | ||
2023 | aItem->SetCarTelephoneNumber(phoneS.ucs2()); | ||
2024 | |||
2025 | phoneS = addressee.phoneNumberString( | ||
2026 | KABC::PhoneNumber::Home + | ||
2027 | KABC::PhoneNumber::Pref ) ; | ||
2028 | aItem->SetHomeTelephoneNumber(phoneS.ucs2()); | ||
2029 | |||
2030 | phoneS = addressee.phoneNumberString( | ||
2031 | KABC::PhoneNumber::Home ) ; | ||
2032 | aItem->SetHome2TelephoneNumber(phoneS.ucs2()); | ||
2033 | |||
2034 | phoneS = addressee.phoneNumberString( | ||
2035 | KABC::PhoneNumber::Home + | ||
2036 | KABC::PhoneNumber::Fax ) ; | ||
2037 | aItem->SetHomeFaxNumber(phoneS.ucs2()); | ||
2038 | |||
2039 | phoneS = addressee.phoneNumberString( | ||
2040 | KABC::PhoneNumber::Isdn ) ; | ||
2041 | aItem->SetISDNNumber(phoneS.ucs2()); | ||
2042 | |||
2043 | phoneS = addressee.phoneNumberString( | ||
2044 | KABC::PhoneNumber::Cell ) ; | ||
2045 | aItem->SetMobileTelephoneNumber(phoneS.ucs2()); | ||
2046 | |||
2047 | phoneS = addressee.phoneNumberString( | ||
2048 | KABC::PhoneNumber::Fax ) ; | ||
2049 | aItem->SetOtherFaxNumber(phoneS.ucs2()); | ||
2050 | |||
2051 | phoneS = addressee.phoneNumberString( | ||
2052 | KABC::PhoneNumber::Voice ) ; | ||
2053 | aItem->SetOtherTelephoneNumber(phoneS.ucs2()); | ||
2054 | |||
2055 | phoneS = addressee.phoneNumberString( | ||
2056 | KABC::PhoneNumber::Pager ) ; | ||
2057 | aItem->SetPagerNumber(phoneS.ucs2()); | ||
2058 | |||
2059 | phoneS = addressee.phoneNumberString( | ||
2060 | KABC::PhoneNumber::Pref ) ; | ||
2061 | aItem->SetPrimaryTelephoneNumber(phoneS.ucs2()); | ||
2062 | |||
2063 | phoneS = addressee.phoneNumberString( | ||
2064 | KABC::PhoneNumber::Pcs + | ||
2065 | KABC::PhoneNumber::Voice) ; | ||
2066 | aItem->SetTTYTDDTelephoneNumber(phoneS.ucs2()); | ||
2067 | |||
2068 | phoneS = addressee.phoneNumberString( | ||
2069 | KABC::PhoneNumber::Pcs ) ; | ||
2070 | aItem->SetTelexNumber(phoneS.ucs2()); | ||
2071 | |||
2072 | phoneS = addressee.phoneNumberString( | ||
2073 | KABC::PhoneNumber::Work + | ||
2074 | KABC::PhoneNumber::Msg ) ; | ||
2075 | aItem->SetCompanyMainTelephoneNumber(phoneS.ucs2()); | ||
2076 | |||
2077 | phoneS = addressee.phoneNumberString( | ||
2078 | KABC::PhoneNumber::Pcs + | ||
2079 | KABC::PhoneNumber::Pref ) ; | ||
2080 | aItem->SetRadioTelephoneNumber(phoneS.ucs2()); | ||
2081 | |||
2082 | phoneS = addressee.phoneNumberString( | ||
2083 | KABC::PhoneNumber::Msg ) ; | ||
2084 | aItem->SetCallbackTelephoneNumber(phoneS.ucs2()); | ||
2085 | |||
2086 | QStringList emails = addressee.emails(); | ||
2087 | emails << "" << "" << ""; | ||
2088 | aItem->SetEmail1Address(emails[0].ucs2()); | ||
2089 | aItem->SetEmail2Address(emails[1].ucs2()); | ||
2090 | aItem->SetEmail3Address(emails[2].ucs2()); | ||
2091 | |||
2092 | // is this the number of the preferred email? | ||
2093 | //long GetSelectedMailingAddress();??? | ||
2094 | |||
2095 | KABC::Address addressHome = addressee.address( KABC::Address::Home ); | ||
2096 | KABC::Address* addressAdd = &addressHome; | ||
2097 | aItem->SetHomeAddressCountry(addressAdd->country().ucs2()); | ||
2098 | aItem->SetHomeAddressState(addressAdd->region().ucs2()); | ||
2099 | aItem->SetHomeAddressCity(addressAdd->locality().ucs2()); | ||
2100 | aItem->SetHomeAddressPostalCode(addressAdd->postalCode().ucs2()); | ||
2101 | aItem->SetHomeAddressPostOfficeBox(addressAdd->postOfficeBox().ucs2()); | ||
2102 | aItem->SetHomeAddressStreet(addressAdd->street().ucs2()); | ||
2103 | |||
2104 | addressHome = addressee.address( KABC::Address::Work ); | ||
2105 | addressAdd = &addressHome; | ||
2106 | aItem->SetBusinessAddressCountry(addressAdd->country().ucs2()); | ||
2107 | aItem->SetBusinessAddressState(addressAdd->region().ucs2()); | ||
2108 | aItem->SetBusinessAddressCity(addressAdd->locality().ucs2()); | ||
2109 | aItem->SetBusinessAddressPostalCode(addressAdd->postalCode().ucs2()); | ||
2110 | aItem->SetBusinessAddressPostOfficeBox(addressAdd->postOfficeBox().ucs2()); | ||
2111 | aItem->SetBusinessAddressStreet(addressAdd->street().ucs2()); | ||
2112 | |||
2113 | addressHome = addressee.otherAddress(); | ||
2114 | addressAdd = &addressHome; | ||
2115 | aItem->SetOtherAddressCountry(addressAdd->country().ucs2()); | ||
2116 | aItem->SetOtherAddressState(addressAdd->region().ucs2()); | ||
2117 | aItem->SetOtherAddressCity(addressAdd->locality().ucs2()); | ||
2118 | aItem->SetOtherAddressPostalCode(addressAdd->postalCode().ucs2()); | ||
2119 | aItem->SetOtherAddressPostOfficeBox(addressAdd->postOfficeBox().ucs2()); | ||
2120 | aItem->SetOtherAddressStreet(addressAdd->street().ucs2()); | ||
2121 | |||
2122 | aItem->SetInternetFreeBusyAddress(addressee.custom( "KADDRESSBOOK", "X-FreeBusyUrl" ).ucs2()); | ||
2123 | aItem->SetChildren(addressee.custom( "KADDRESSBOOK", "X-Children").ucs2()); | ||
2124 | |||
2125 | int gen = 0;// 0 undef - 1 female - 2 male | ||
2126 | QString gend = addressee.custom( "KADDRESSBOOK", "X-Gender" ); | ||
2127 | if ( gend == "female" ) | ||
2128 | gen = 1; | ||
2129 | if ( gend == "male" ) | ||
2130 | gen = 2; | ||
2131 | aItem->SetGender(gen); | ||
2132 | |||
2133 | aItem->Save(); | ||
2134 | } | ||
2135 | LPDISPATCH KAwritebackOL::getFolderFromID( LPDISPATCH parentFolder ) | ||
2136 | { | ||
2137 | if ( parentFolder == 0 ) { | ||
2138 | SCODE sc = ::OleInitialize(NULL); | ||
2139 | if ( FAILED ( sc ) ) { | ||
2140 | KMessageBox::information(0,"OLE initialisation failed"); | ||
2141 | return 0; | ||
2142 | } | ||
2143 | |||
2144 | |||
2145 | if( ! KAImportOLdialog::sOLDispatch ) { | ||
2146 | if(!gOlAppAB.CreateDispatch(_T("Outlook.Application"),NULL)){ | ||
2147 | KMessageBox::information(0,"Sorry, cannot access Outlook"); | ||
2148 | return 0; | ||
2149 | } | ||
2150 | KAImportOLdialog::sOLDispatch = true; | ||
2151 | } | ||
2152 | |||
2153 | MAPIFolder mfInbox; | ||
2154 | MAPIFolder mfRoot; | ||
2155 | CString szName; | ||
2156 | _NameSpace olNS; | ||
2157 | olNS = gOlAppAB.GetNamespace(_T("MAPI")); | ||
2158 | mfInbox = olNS.GetDefaultFolder(6); | ||
2159 | mfRoot = mfInbox.GetParent(); | ||
2160 | szName = mfRoot.GetName(); | ||
2161 | mfRoot.m_lpDispatch->AddRef(); | ||
2162 | return getFolderFromID( mfRoot.m_lpDispatch ); | ||
2163 | } | ||
2164 | |||
2165 | MAPIFolder mfParent(parentFolder), mfChild; | ||
2166 | _Folders folders; | ||
2167 | _variant_t fndx((long)0); | ||
2168 | CString szName; | ||
2169 | long iType; | ||
2170 | OLEListViewItem* hChild; | ||
2171 | folders = mfParent.GetFolders(); | ||
2172 | for(int i=1; i <= folders.GetCount(); ++i) | ||
2173 | { | ||
2174 | fndx = (long)i; | ||
2175 | mfChild = folders.Item(fndx.Detach()); | ||
2176 | mfChild.m_lpDispatch->AddRef(); | ||
2177 | szName = mfChild.GetName(); | ||
2178 | iType = mfChild.GetDefaultItemType(); | ||
2179 | if (mSelectedFolderID == QString::fromUcs2(mfChild.GetEntryID().GetBuffer()) ) { | ||
2180 | return mfChild.m_lpDispatch; | ||
2181 | } | ||
2182 | LPDISPATCH resultFolder = getFolderFromID(mfChild.m_lpDispatch ); | ||
2183 | if ( resultFolder != 0 ) | ||
2184 | return resultFolder; | ||
2185 | } | ||
2186 | return 0; | ||
2187 | } | ||
2188 | LPDISPATCH KAwritebackOL::getOLitemFromUid( QString uid ) | ||
2189 | { | ||
2190 | _variant_t indx((long)0); | ||
2191 | LPDISPATCH itm; | ||
2192 | int i; | ||
2193 | for(i=1; i <= mFolderItems.GetCount(); ++i) | ||
2194 | { | ||
2195 | qApp->processEvents(); | ||
2196 | indx = (long)i; | ||
2197 | itm = mFolderItems.Item(indx.Detach()); | ||
2198 | _ContactItem * pItem = (_ContactItem *)&itm; | ||
2199 | if ( QString::fromUcs2(pItem->GetEntryID().GetBuffer()) == uid ) | ||
2200 | return itm; | ||
2201 | itm->Release(); | ||
2202 | } | ||
2203 | return 0; | ||
2204 | } | ||
2205 | #endif | ||
diff --git a/libkdepim/ol_access.h b/libkdepim/ol_access.h new file mode 100755 index 0000000..85dbc6c --- a/dev/null +++ b/libkdepim/ol_access.h | |||
@@ -0,0 +1,174 @@ | |||
1 | /* | ||
2 | This file is part of KDE/Pim-Pi | ||
3 | Copyright (c) 2006 Lutz Rogowski | ||
4 | |||
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 | ||
7 | the Free Software Foundation; either version 2 of the License, or | ||
8 | (at your option) any later version. | ||
9 | |||
10 | This program is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | GNU General Public License for more details. | ||
14 | |||
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 | ||
17 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | ||
18 | |||
19 | As a special exception, permission is given to link this program | ||
20 | with any edition of Qt, and distribute the resulting executable, | ||
21 | without including the source code for Qt in the source distribution. | ||
22 | */ | ||
23 | #ifndef OL_ACCESS_H | ||
24 | #define OL_ACCESS_H | ||
25 | |||
26 | #include <qstring.h> | ||
27 | |||
28 | #include <kdialogbase.h> | ||
29 | #include <kabc/addressee.h> | ||
30 | #include <kabc/addressbook.h> | ||
31 | |||
32 | #include <afxdisp.h> | ||
33 | |||
34 | #include "../outport/msoutl9.h" | ||
35 | |||
36 | #define OL_CONTACT_DATA 2 | ||
37 | #define OL_CALENDAR_DATA 1 //pending is this the right number | ||
38 | |||
39 | class QDateTime; | ||
40 | class QListView; | ||
41 | class OLEListViewItem; | ||
42 | class _ContactItem; | ||
43 | class OL_access : public QObject | ||
44 | { | ||
45 | Q_OBJECT | ||
46 | public: | ||
47 | static OL_access *instance(); | ||
48 | ~OL_access(); | ||
49 | //static converter methods | ||
50 | static QDateTime mDdate2Qdtr( DATE dt); | ||
51 | static DATE Qdt2date( QDateTime dt ); | ||
52 | static KABC::Addressee ol2kapiContact( _ContactItem * aItem , bool syncMode); | ||
53 | static void writeData2OLitem( KABC::Addressee addressee, _ContactItem * aItem ); | ||
54 | |||
55 | KABC::Addressee::List importOLcontacts(); | ||
56 | QStringList getFolderSelection( int type, QString caption ); | ||
57 | void readContactData( LPDISPATCH folder, KABC::Addressee::List* list, bool syncMode ); | ||
58 | |||
59 | LPDISPATCH getFolderFromID( LPDISPATCH parentFolder, QString selectedFolderID ); | ||
60 | bool setSelectedFolder( QString folderID ); | ||
61 | //call setSelectedFolder() before using the next methods: | ||
62 | void deleteAddressee( KABC::Addressee a ); | ||
63 | KABC::Addressee changeAddressee( KABC::Addressee a ); | ||
64 | KABC::Addressee addAddressee( KABC::Addressee a ); | ||
65 | |||
66 | |||
67 | |||
68 | |||
69 | public slots: | ||
70 | |||
71 | |||
72 | signals: | ||
73 | |||
74 | protected slots: | ||
75 | |||
76 | |||
77 | protected: | ||
78 | |||
79 | private: | ||
80 | _Application gOlAppAB; | ||
81 | bool mErrorInit; | ||
82 | void addFolder(OLEListViewItem* iParent, LPDISPATCH dispParent, long fType); | ||
83 | LPDISPATCH getOLcontactItemFromUid( QString uid ); | ||
84 | |||
85 | QString mSelectedFolderID; | ||
86 | LPDISPATCH mSelectedFolder; | ||
87 | _Items mFolderItems; | ||
88 | |||
89 | OL_access(); | ||
90 | static OL_access *sInstance; | ||
91 | }; | ||
92 | |||
93 | |||
94 | #if 0 | ||
95 | //using namespace KABC; | ||
96 | //class KABC::AddressBook; | ||
97 | |||
98 | /** | ||
99 | This is the base class for the calendar component editors. | ||
100 | */ | ||
101 | class KAImportOLdialog : public KDialogBase | ||
102 | { | ||
103 | Q__OBJECT | ||
104 | public: | ||
105 | /** | ||
106 | Construct new IncidenceEditor. | ||
107 | */ | ||
108 | KAImportOLdialog( const QString &caption, KABC::AddressBook * aBook, | ||
109 | QWidget *parent ); | ||
110 | ~KAImportOLdialog(); | ||
111 | |||
112 | /** Initialize editor. This function creates the tab widgets. */ | ||
113 | void init(); | ||
114 | void setSyncMode(); | ||
115 | KABC::Addressee::List getAddressList(); | ||
116 | QString selectedFolderID() {return mSelectedFolderID;} | ||
117 | static KABC::Addressee ol2kapiContact( _ContactItem * , bool syncMode ); | ||
118 | static bool sOLDispatch; | ||
119 | pub_lic sl_ots: | ||
120 | |||
121 | |||
122 | sign_als: | ||
123 | |||
124 | prote_cted slo_ts: | ||
125 | void slotApply(); | ||
126 | void slotOk(); | ||
127 | void slotCancel(); | ||
128 | |||
129 | protected: | ||
130 | void setupFolderView(); | ||
131 | void addFolder(OLEListViewItem* iParent, LPDISPATCH dispParent); | ||
132 | void readContactData( DWORD folder ); | ||
133 | |||
134 | KABC::AddressBook * mABook; | ||
135 | QListView * mListView; | ||
136 | KABC::Addressee::List mAList; | ||
137 | bool addAddressee( KABC::Addressee a ); | ||
138 | private: | ||
139 | int importedItems; | ||
140 | bool mSyncMode; | ||
141 | QString mSelectedFolderID; | ||
142 | }; | ||
143 | class KAwritebackOL : public QObject | ||
144 | { | ||
145 | Q__OBJECT | ||
146 | public: | ||
147 | KAwritebackOL( const QString &olFolderID ); | ||
148 | ~KAwritebackOL(); | ||
149 | bool init(); | ||
150 | void deleteAddressee( KABC::Addressee a ); | ||
151 | KABC::Addressee changeAddressee( KABC::Addressee a ); | ||
152 | KABC::Addressee addAddressee( KABC::Addressee a ); | ||
153 | public sl_ots: | ||
154 | |||
155 | |||
156 | signals: | ||
157 | |||
158 | protected sl_ots: | ||
159 | |||
160 | |||
161 | protected: | ||
162 | LPDISPATCH getFolderFromID( LPDISPATCH parentFolder ); | ||
163 | LPDISPATCH getOLitemFromUid( QString uid ); | ||
164 | void writeData2OLitem( KABC::Addressee a, _ContactItem * olitem ); | ||
165 | private: | ||
166 | QString mSelectedFolderID; | ||
167 | LPDISPATCH mSelectedFolder; | ||
168 | _Items mFolderItems; | ||
169 | }; | ||
170 | |||
171 | #endif | ||
172 | #endif | ||
173 | |||
174 | |||