author | zautrix <zautrix> | 2004-09-15 15:08:01 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-09-15 15:08:01 (UTC) |
commit | 93d16eea6d3324611d6150e7ee3e7f7f36320eff (patch) (unidiff) | |
tree | f0437e15f455ddfe1bd4ed8908fdaee67c26d38c | |
parent | d37aeeb9aa023d52b364c971fa4aabd0c8f339b9 (diff) | |
download | kdepimpi-93d16eea6d3324611d6150e7ee3e7f7f36320eff.zip kdepimpi-93d16eea6d3324611d6150e7ee3e7f7f36320eff.tar.gz kdepimpi-93d16eea6d3324611d6150e7ee3e7f7f36320eff.tar.bz2 |
KOPi OLE import changes
-rw-r--r-- | korganizer/koimportoldialog.cpp | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/korganizer/koimportoldialog.cpp b/korganizer/koimportoldialog.cpp index 16f2eca..0a3c2d5 100644 --- a/korganizer/koimportoldialog.cpp +++ b/korganizer/koimportoldialog.cpp | |||
@@ -1,477 +1,485 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of KOrganizer. | 2 | This file is part of KOrganizer. |
3 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> | 3 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> |
4 | 4 | ||
5 | This program is free software; you can redistribute it and/or modify | 5 | This program is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published by | 6 | it under the terms of the GNU General Public License as published by |
7 | the Free Software Foundation; either version 2 of the License, or | 7 | the Free Software Foundation; either version 2 of the License, or |
8 | (at your option) any later version. | 8 | (at your option) any later version. |
9 | 9 | ||
10 | This program is distributed in the hope that it will be useful, | 10 | This program is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | GNU General Public License for more details. | 13 | GNU General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU General Public License | 15 | You should have received a copy of the GNU General Public License |
16 | along with this program; if not, write to the Free Software | 16 | along with this program; if not, write to the Free Software |
17 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | 17 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
18 | 18 | ||
19 | As a special exception, permission is given to link this program | 19 | As a special exception, permission is given to link this program |
20 | with any edition of Qt, and distribute the resulting executable, | 20 | with any edition of Qt, and distribute the resulting executable, |
21 | without including the source code for Qt in the source distribution. | 21 | without including the source code for Qt in the source distribution. |
22 | */ | 22 | */ |
23 | 23 | ||
24 | #include <qtooltip.h> | 24 | #include <qtooltip.h> |
25 | #include <qframe.h> | 25 | #include <qframe.h> |
26 | #include <qpixmap.h> | 26 | #include <qpixmap.h> |
27 | #include <qlayout.h> | 27 | #include <qlayout.h> |
28 | #include <qprogressbar.h> | 28 | #include <qprogressbar.h> |
29 | #include <qwidgetstack.h> | 29 | #include <qwidgetstack.h> |
30 | #include <qdatetime.h> | 30 | #include <qdatetime.h> |
31 | #include <qdir.h> | 31 | #include <qdir.h> |
32 | #include <qapplication.h> | 32 | #include <qapplication.h> |
33 | #include <qhbox.h> | 33 | #include <qhbox.h> |
34 | #include <qheader.h> | 34 | #include <qheader.h> |
35 | #include <qdatetime.h> | 35 | #include <qdatetime.h> |
36 | #include <qlistview.h> | 36 | #include <qlistview.h> |
37 | 37 | ||
38 | #include <kdebug.h> | 38 | #include <kdebug.h> |
39 | #include <klocale.h> | 39 | #include <klocale.h> |
40 | #include <kstandarddirs.h> | 40 | #include <kstandarddirs.h> |
41 | #include <kmessagebox.h> | 41 | #include <kmessagebox.h> |
42 | #include <kfiledialog.h> | 42 | #include <kfiledialog.h> |
43 | 43 | ||
44 | #include <libkdepim/categoryselectdialog.h> | 44 | #include <libkdepim/categoryselectdialog.h> |
45 | #include <libkdepim/kinputdialog.h> | 45 | #include <libkdepim/kinputdialog.h> |
46 | 46 | ||
47 | #include <libkcal/calendarlocal.h> | 47 | #include <libkcal/calendarlocal.h> |
48 | #include <libkcal/icalformat.h> | 48 | #include <libkcal/icalformat.h> |
49 | #include <kabc/stdaddressbook.h> | 49 | #include <kabc/stdaddressbook.h> |
50 | 50 | ||
51 | #include "koprefs.h" | 51 | #include "koprefs.h" |
52 | #include "koglobals.h" | 52 | #include "koglobals.h" |
53 | 53 | ||
54 | #include "koimportoldialog.h" | 54 | #include "koimportoldialog.h" |
55 | 55 | ||
56 | #include "../outport/msoutl9.h" | 56 | #include "../outport/msoutl9.h" |
57 | #include <ole2.h> | 57 | #include <ole2.h> |
58 | #include <comutil.h> | 58 | #include <comutil.h> |
59 | _Application gOlApp; | 59 | _Application gOlApp; |
60 | 60 | ||
61 | QDateTime mDdate2Qdtr( DATE dt) | 61 | QDateTime mDdate2Qdtr( DATE dt) |
62 | { | 62 | { |
63 | COleDateTime odt; | 63 | COleDateTime odt; |
64 | SYSTEMTIME st; | 64 | SYSTEMTIME st; |
65 | odt = dt; | 65 | odt = dt; |
66 | odt.GetAsSystemTime(st); | 66 | odt.GetAsSystemTime(st); |
67 | QDateTime qdt (QDate(st.wYear, st.wMonth,st.wDay ),QTime( st.wHour, st.wMinute,st.wSecond ) ); | 67 | QDateTime qdt (QDate(st.wYear, st.wMonth,st.wDay ),QTime( st.wHour, st.wMinute,st.wSecond ) ); |
68 | return qdt; | 68 | return qdt; |
69 | } | 69 | } |
70 | 70 | ||
71 | class OLEListViewItem : public QCheckListItem | 71 | class OLEListViewItem : public QCheckListItem |
72 | { | 72 | { |
73 | public: | 73 | public: |
74 | OLEListViewItem( QListView *parent, QString text ) : | 74 | OLEListViewItem( QListView *parent, QString text ) : |
75 | QCheckListItem( parent, text, QCheckListItem::CheckBox ) { ; }; | 75 | QCheckListItem( parent, text, QCheckListItem::CheckBox ) { ; }; |
76 | OLEListViewItem( QListViewItem *after, QString text ) : | 76 | OLEListViewItem( QListViewItem *after, QString text ) : |
77 | QCheckListItem( after, text, QCheckListItem::CheckBox ) { ; }; | 77 | QCheckListItem( after, text, QCheckListItem::CheckBox ) { ; }; |
78 | ~OLEListViewItem() {}; | 78 | ~OLEListViewItem() {}; |
79 | void setData( DWORD data ) {mData= data; }; | 79 | void setData( DWORD data ) {mData= data; }; |
80 | DWORD data() { return mData ;}; | 80 | DWORD data() { return mData ;}; |
81 | private: | 81 | private: |
82 | DWORD mData; | 82 | DWORD mData; |
83 | }; | 83 | }; |
84 | 84 | ||
85 | KOImportOLdialog::KOImportOLdialog( const QString &caption, | 85 | KOImportOLdialog::KOImportOLdialog( const QString &caption, |
86 | Calendar *calendar, QWidget *parent ) : | 86 | Calendar *calendar, QWidget *parent ) : |
87 | KDialogBase( Plain, caption, User1 | Close, Ok, | 87 | KDialogBase( Plain, caption, User1 | Close, Ok, |
88 | parent, caption, true, false, i18n("Import!") ) | 88 | parent, caption, true, false, i18n("Import!") ) |
89 | { | 89 | { |
90 | QHBox * mw = new QHBox( this ); | 90 | QHBox * mw = new QHBox( this ); |
91 | setMainWidget( mw ); | 91 | setMainWidget( mw ); |
92 | mListView = new QListView( mw ); | 92 | mListView = new QListView( mw ); |
93 | mListView->addColumn(i18n("Select Folder to import")); | 93 | mListView->addColumn(i18n("Select Folder to import")); |
94 | mListView->addColumn(i18n("Content Type")); | 94 | mListView->addColumn(i18n("Content Type")); |
95 | mCalendar = calendar; | 95 | mCalendar = calendar; |
96 | connect( this, SIGNAL( user1Clicked() ),SLOT ( slotApply())); | 96 | connect( this, SIGNAL( user1Clicked() ),SLOT ( slotApply())); |
97 | setupFolderView(); | 97 | setupFolderView(); |
98 | resize( sizeHint().width()+50, sizeHint().height()+50 ); | 98 | resize( sizeHint().width()+50, sizeHint().height()+50 ); |
99 | } | 99 | } |
100 | 100 | ||
101 | KOImportOLdialog::~KOImportOLdialog() | 101 | KOImportOLdialog::~KOImportOLdialog() |
102 | { | 102 | { |
103 | 103 | ||
104 | } | 104 | } |
105 | 105 | ||
106 | 106 | ||
107 | void KOImportOLdialog::setupFolderView() | 107 | void KOImportOLdialog::setupFolderView() |
108 | { | 108 | { |
109 | SCODE sc = ::OleInitialize(NULL); | 109 | SCODE sc = ::OleInitialize(NULL); |
110 | if ( FAILED ( sc ) ) { | 110 | if ( FAILED ( sc ) ) { |
111 | KMessageBox::information(this,"OLE initialisation failed"); | 111 | KMessageBox::information(this,"OLE initialisation failed"); |
112 | return; | 112 | return; |
113 | } | 113 | } |
114 | 114 | ||
115 | if(!gOlApp.CreateDispatch(_T("Outlook.Application"),NULL)){ | 115 | if(!gOlApp.CreateDispatch(_T("Outlook.Application"),NULL)){ |
116 | KMessageBox::information(this,"Sorry, cannot access Outlook"); | 116 | KMessageBox::information(this,"Sorry, cannot access Outlook"); |
117 | return ; | 117 | return ; |
118 | } | 118 | } |
119 | MAPIFolder mfInbox; | 119 | MAPIFolder mfInbox; |
120 | MAPIFolder mfRoot; | 120 | MAPIFolder mfRoot; |
121 | CString szName; | 121 | CString szName; |
122 | _NameSpace olNS; | 122 | _NameSpace olNS; |
123 | olNS = gOlApp.GetNamespace(_T("MAPI")); | 123 | olNS = gOlApp.GetNamespace(_T("MAPI")); |
124 | mfInbox = olNS.GetDefaultFolder(6); | 124 | mfInbox = olNS.GetDefaultFolder(6); |
125 | mfRoot = mfInbox.GetParent(); | 125 | mfRoot = mfInbox.GetParent(); |
126 | szName = mfRoot.GetName(); | 126 | szName = mfRoot.GetName(); |
127 | long iType = mfRoot.GetDefaultItemType(); | 127 | long iType = mfRoot.GetDefaultItemType(); |
128 | QString mes; | 128 | QString mes; |
129 | mes = QString::fromUcs2( szName.GetBuffer() ); | 129 | mes = QString::fromUcs2( szName.GetBuffer() ); |
130 | OLEListViewItem * root = new OLEListViewItem( mListView, mes ); | 130 | OLEListViewItem * root = new OLEListViewItem( mListView, mes ); |
131 | mfRoot.m_lpDispatch->AddRef(); | 131 | mfRoot.m_lpDispatch->AddRef(); |
132 | addFolder( root, mfRoot.m_lpDispatch ); | 132 | addFolder( root, mfRoot.m_lpDispatch ); |
133 | root->setOpen( true ); | 133 | root->setOpen( true ); |
134 | mListView->setSortColumn( 0 ); | 134 | mListView->setSortColumn( 0 ); |
135 | mListView->sort( ); | 135 | mListView->sort( ); |
136 | } | 136 | } |
137 | 137 | ||
138 | 138 | ||
139 | void KOImportOLdialog::addFolder(OLEListViewItem* iParent, LPDISPATCH dispParent) | 139 | void KOImportOLdialog::addFolder(OLEListViewItem* iParent, LPDISPATCH dispParent) |
140 | { | 140 | { |
141 | MAPIFolder mfParent(dispParent), mfChild; | 141 | MAPIFolder mfParent(dispParent), mfChild; |
142 | _Folders folders; | 142 | _Folders folders; |
143 | _variant_t fndx((long)0); | 143 | _variant_t fndx((long)0); |
144 | CString szName; | 144 | CString szName; |
145 | long iType; | 145 | long iType; |
146 | OLEListViewItem* hChild; | 146 | OLEListViewItem* hChild; |
147 | 147 | ||
148 | folders = mfParent.GetFolders(); | 148 | folders = mfParent.GetFolders(); |
149 | for(int i=1; i <= folders.GetCount(); ++i) | 149 | for(int i=1; i <= folders.GetCount(); ++i) |
150 | { | 150 | { |
151 | fndx = (long)i; | 151 | fndx = (long)i; |
152 | mfChild = folders.Item(fndx.Detach()); | 152 | mfChild = folders.Item(fndx.Detach()); |
153 | mfChild.m_lpDispatch->AddRef(); | 153 | mfChild.m_lpDispatch->AddRef(); |
154 | szName = mfChild.GetName(); | 154 | szName = mfChild.GetName(); |
155 | iType = mfChild.GetDefaultItemType(); | 155 | iType = mfChild.GetDefaultItemType(); |
156 | hChild = new OLEListViewItem( iParent , QString::fromUcs2( szName.GetBuffer() ) ); | 156 | hChild = new OLEListViewItem( iParent , QString::fromUcs2( szName.GetBuffer() ) ); |
157 | if ( iType != 1) | 157 | if ( iType != 1) |
158 | hChild->setEnabled( false ); | 158 | hChild->setEnabled( false ); |
159 | QString ts; | 159 | QString ts; |
160 | switch( iType ) { | 160 | switch( iType ) { |
161 | case 0: | 161 | case 0: |
162 | ts = i18n("Mail"); | 162 | ts = i18n("Mail"); |
163 | break; | 163 | break; |
164 | case 1: | 164 | case 1: |
165 | ts = i18n("Calendar"); | 165 | ts = i18n("Calendar"); |
166 | break; | 166 | break; |
167 | case 2: | 167 | case 2: |
168 | ts = i18n("Contacts"); | 168 | ts = i18n("Contacts"); |
169 | break; | 169 | break; |
170 | case 3: | 170 | case 3: |
171 | ts = i18n("Todos"); | 171 | ts = i18n("Todos"); |
172 | break; | 172 | break; |
173 | case 4: | 173 | case 4: |
174 | ts = i18n("Journals"); | 174 | ts = i18n("Journals"); |
175 | break; | 175 | break; |
176 | case 5: | 176 | case 5: |
177 | ts = i18n("Notes"); | 177 | ts = i18n("Notes"); |
178 | break; | 178 | break; |
179 | default: | 179 | default: |
180 | ts = i18n("Unknown"); | 180 | ts = i18n("Unknown"); |
181 | } | 181 | } |
182 | hChild->setText( 1,ts); | 182 | hChild->setText( 1,ts); |
183 | hChild->setData( (DWORD) mfChild.m_lpDispatch ); | 183 | hChild->setData( (DWORD) mfChild.m_lpDispatch ); |
184 | mfChild.m_lpDispatch->AddRef(); | 184 | mfChild.m_lpDispatch->AddRef(); |
185 | addFolder(hChild, mfChild.m_lpDispatch); | 185 | addFolder(hChild, mfChild.m_lpDispatch); |
186 | } | 186 | } |
187 | } | 187 | } |
188 | 188 | ||
189 | void KOImportOLdialog::slotApply() | 189 | void KOImportOLdialog::slotApply() |
190 | { | 190 | { |
191 | importedItems = 0; | 191 | importedItems = 0; |
192 | OLEListViewItem* child = (OLEListViewItem*) mListView->firstChild(); | 192 | OLEListViewItem* child = (OLEListViewItem*) mListView->firstChild(); |
193 | while ( child ) { | 193 | while ( child ) { |
194 | if ( child->isOn() ) | 194 | if ( child->isOn() ) |
195 | readCalendarData( child->data() ); | 195 | readCalendarData( child->data() ); |
196 | child = (OLEListViewItem*) child->itemBelow(); | 196 | child = (OLEListViewItem*) child->itemBelow(); |
197 | } | 197 | } |
198 | QString mes = i18n("Importing complete.\n\n%1 items imported.").arg( importedItems); | 198 | QString mes = i18n("Importing complete.\n\n%1 items imported.").arg( importedItems); |
199 | KMessageBox::information(this,mes); | 199 | KMessageBox::information(this,mes); |
200 | } | 200 | } |
201 | void KOImportOLdialog::readCalendarData( DWORD folder ) | 201 | void KOImportOLdialog::readCalendarData( DWORD folder ) |
202 | { | 202 | { |
203 | 203 | ||
204 | LPDISPATCH dispItem = (LPDISPATCH)folder; | 204 | LPDISPATCH dispItem = (LPDISPATCH)folder; |
205 | dispItem->AddRef(); | 205 | dispItem->AddRef(); |
206 | MAPIFolder mf(dispItem); | 206 | MAPIFolder mf(dispItem); |
207 | mf.m_lpDispatch->AddRef(); | 207 | mf.m_lpDispatch->AddRef(); |
208 | _Items folderItems; | 208 | _Items folderItems; |
209 | _variant_t indx((long)0); | 209 | _variant_t indx((long)0); |
210 | LPDISPATCH itm; | 210 | LPDISPATCH itm; |
211 | int i; | 211 | int i; |
212 | folderItems = mf.GetItems(); | 212 | folderItems = mf.GetItems(); |
213 | QProgressBar bar( folderItems.GetCount(),0 ); | 213 | QProgressBar bar( folderItems.GetCount(),0 ); |
214 | bar.setCaption (i18n("Importing - close to abort!") ); | 214 | bar.setCaption (i18n("Importing - close to abort!") ); |
215 | int h = bar.sizeHint().height() ; | 215 | int h = bar.sizeHint().height() ; |
216 | int w = 300; | 216 | int w = 300; |
217 | int dw = QApplication::desktop()->width(); | 217 | int dw = QApplication::desktop()->width(); |
218 | int dh = QApplication::desktop()->height(); | 218 | int dh = QApplication::desktop()->height(); |
219 | bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); | 219 | bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); |
220 | bar.show(); | 220 | bar.show(); |
221 | for(i=1; i <= folderItems.GetCount(); ++i) | 221 | for(i=1; i <= folderItems.GetCount(); ++i) |
222 | { | 222 | { |
223 | qApp->processEvents(); | 223 | qApp->processEvents(); |
224 | if ( ! bar.isVisible() ) | 224 | if ( ! bar.isVisible() ) |
225 | return ; | 225 | return ; |
226 | bar.setProgress( i ); | 226 | bar.setProgress( i ); |
227 | indx = (long)i; | 227 | indx = (long)i; |
228 | itm = folderItems.Item(indx.Detach()); | 228 | itm = folderItems.Item(indx.Detach()); |
229 | _AppointmentItem * pItem = (_AppointmentItem *)&itm; | 229 | _AppointmentItem * pItem = (_AppointmentItem *)&itm; |
230 | ol2kopiCalendar( pItem ); | 230 | ol2kopiCalendar( pItem ); |
231 | itm->Release(); | 231 | itm->Release(); |
232 | } | 232 | } |
233 | } | 233 | } |
234 | void KOImportOLdialog::slotOk() | 234 | void KOImportOLdialog::slotOk() |
235 | { | 235 | { |
236 | QDialog::accept(); | 236 | QDialog::accept(); |
237 | } | 237 | } |
238 | 238 | ||
239 | void KOImportOLdialog::ol2kopiCalendar( _AppointmentItem * aItem, bool computeRecurrence ) | 239 | void KOImportOLdialog::ol2kopiCalendar( _AppointmentItem * aItem, bool computeRecurrence ) |
240 | { | 240 | { |
241 | KCal::Event* event = new KCal::Event(); | 241 | KCal::Event* event = new KCal::Event(); |
242 | if ( aItem->GetAllDayEvent() ){ | 242 | if ( aItem->GetAllDayEvent() ){ |
243 | event->setDtStart( QDateTime( mDdate2Qdtr( aItem->GetStart()).date(),QTime(0,0,0 ) )); | 243 | event->setDtStart( QDateTime( mDdate2Qdtr( aItem->GetStart()).date(),QTime(0,0,0 ) )); |
244 | event->setDtEnd( QDateTime( mDdate2Qdtr( aItem->GetEnd()) .date(),QTime(0,0,0 )).addDays(-1)); | 244 | event->setDtEnd( QDateTime( mDdate2Qdtr( aItem->GetEnd()) .date(),QTime(0,0,0 )).addDays(-1)); |
245 | event->setFloats( true ); | 245 | event->setFloats( true ); |
246 | } else { | 246 | } else { |
247 | event->setDtStart( mDdate2Qdtr( aItem->GetStart()) ); | 247 | event->setDtStart( mDdate2Qdtr( aItem->GetStart()) ); |
248 | event->setDtEnd( mDdate2Qdtr( aItem->GetEnd()) ); | 248 | event->setDtEnd( mDdate2Qdtr( aItem->GetEnd()) ); |
249 | event->setFloats( false ); | 249 | event->setFloats( false ); |
250 | } | 250 | } |
251 | event->setSummary( QString::fromUcs2( aItem->GetSubject().GetBuffer()) ); | 251 | event->setSummary( QString::fromUcs2( aItem->GetSubject().GetBuffer()) ); |
252 | event->setLocation( QString::fromUcs2( aItem->GetLocation().GetBuffer()) ); | 252 | event->setLocation( QString::fromUcs2( aItem->GetLocation().GetBuffer()) ); |
253 | event->setDescription( QString::fromUcs2( aItem->GetBody().GetBuffer()) ); | 253 | event->setDescription( QString::fromUcs2( aItem->GetBody().GetBuffer()) ); |
254 | QString cat = QString::fromUcs2( aItem->GetCategories().GetBuffer()); | 254 | QString cat = QString::fromUcs2( aItem->GetCategories().GetBuffer()); |
255 | event->setCategories( QStringList::split( ";", cat )); | 255 | event->setCategories( QStringList::split( ";", cat )); |
256 | if ( aItem->GetReminderSet() ) { | 256 | if ( aItem->GetReminderSet() ) { |
257 | event->clearAlarms(); | 257 | event->clearAlarms(); |
258 | Alarm* alarm = event->newAlarm(); | 258 | Alarm* alarm = event->newAlarm(); |
259 | alarm->setStartOffset( -aItem->GetReminderMinutesBeforeStart()*60 ); | 259 | alarm->setStartOffset( -aItem->GetReminderMinutesBeforeStart()*60 ); |
260 | alarm->setEnabled( true ); | 260 | alarm->setEnabled( true ); |
261 | if ( aItem->GetReminderPlaySound() ) { | 261 | if ( aItem->GetReminderPlaySound() ) { |
262 | alarm->setType( Alarm::Audio ); | 262 | alarm->setType( Alarm::Audio ); |
263 | alarm->setAudioFile( QString::fromUcs2( aItem->GetReminderSoundFile().GetBuffer())); | 263 | alarm->setAudioFile( QString::fromUcs2( aItem->GetReminderSoundFile().GetBuffer())); |
264 | } | 264 | } |
265 | else | 265 | else |
266 | alarm->setType( Alarm::Display ); | 266 | alarm->setType( Alarm::Display ); |
267 | alarm->setRepeatCount( aItem->GetReplyTime() ); | 267 | alarm->setRepeatCount( aItem->GetReplyTime() ); |
268 | } | 268 | } |
269 | // OL :pub 0 - pers 1 - priv 2 - conf 3 | 269 | // OL :pub 0 - pers 1 - priv 2 - conf 3 |
270 | // KO : pub 0 - priv 1 - conf 2 | 270 | // KO : pub 0 - priv 1 - conf 2 |
271 | int sec = aItem->GetSensitivity() ; | 271 | int sec = aItem->GetSensitivity() ; |
272 | if ( sec > 1 )// mapping pers -> private | 272 | if ( sec > 1 )// mapping pers -> private |
273 | --sec; | 273 | --sec; |
274 | event->setSecrecy( sec ); | 274 | event->setSecrecy( sec ); |
275 | if ( aItem->GetBusyStatus() == 0 ) | 275 | if ( aItem->GetBusyStatus() == 0 ) |
276 | event->setTransparency( Event::Transparent);// OL free | 276 | event->setTransparency( Event::Transparent);// OL free |
277 | else | 277 | else |
278 | event->setTransparency( Event::Opaque);//OL all other | 278 | event->setTransparency( Event::Opaque);//OL all other |
279 | 279 | ||
280 | if ( aItem->GetIsRecurring() && computeRecurrence ) { //recur | 280 | if ( aItem->GetIsRecurring() && computeRecurrence ) { //recur |
281 | 281 | ||
282 | RecurrencePattern recpat = aItem->GetRecurrencePattern(); | 282 | RecurrencePattern recpat = aItem->GetRecurrencePattern(); |
283 | 283 | ||
284 | QDate startDate = mDdate2Qdtr(recpat.GetPatternStartDate()).date(); | 284 | QDate startDate = mDdate2Qdtr(recpat.GetPatternStartDate()).date(); |
285 | int freq = recpat.GetInterval(); | 285 | int freq = recpat.GetInterval(); |
286 | 286 | ||
287 | bool hasEndDate = !recpat.GetNoEndDate(); | 287 | bool hasEndDate = !recpat.GetNoEndDate(); |
288 | QDate endDate = mDdate2Qdtr(recpat.GetPatternEndDate()).date(); | 288 | QDate endDate = mDdate2Qdtr(recpat.GetPatternEndDate()).date(); |
289 | QBitArray weekDays( 7 ); | 289 | QBitArray weekDays( 7 ); |
290 | weekDays.fill(false ); | 290 | weekDays.fill(false ); |
291 | uint weekDaysNum = recpat.GetDayOfWeekMask(); | 291 | uint weekDaysNum = recpat.GetDayOfWeekMask(); |
292 | int i; | 292 | int i; |
293 | int bb = 2; | 293 | int bb = 2; |
294 | for( i = 1; i <= 6; ++i ) { | 294 | for( i = 1; i <= 6; ++i ) { |
295 | weekDays.setBit( i - 1, ( bb & weekDaysNum )); | 295 | weekDays.setBit( i - 1, ( bb & weekDaysNum )); |
296 | bb = 4 << (i-1); | 296 | bb = 4 << (i-1); |
297 | //qDebug(" %d bit %d ",i-1,weekDays.at(i-1) ); | 297 | //qDebug(" %d bit %d ",i-1,weekDays.at(i-1) ); |
298 | } | 298 | } |
299 | if ( 1 & weekDaysNum) | 299 | if ( 1 & weekDaysNum) |
300 | weekDays.setBit( 6 ); | 300 | weekDays.setBit( 6 ); |
301 | // int pos = 1;// pending | 301 | // int pos = 1;// pending |
302 | 302 | ||
303 | Recurrence *r = event->recurrence(); | 303 | Recurrence *r = event->recurrence(); |
304 | int rtype = recpat.GetRecurrenceType(); | 304 | int rtype = recpat.GetRecurrenceType(); |
305 | //recurrence types are: | 305 | //recurrence types are: |
306 | /* | 306 | /* |
307 | olRecursDaily(0) | 307 | olRecursDaily(0) |
308 | olRecursWeekly(1) | 308 | olRecursWeekly(1) |
309 | olRecursMonthly(2) | 309 | olRecursMonthly(2) |
310 | olRecursMonthNth(3) | 310 | olRecursMonthNth(3) |
311 | olRecursYearly(5) | 311 | olRecursYearly(5) |
312 | olRecursYearNth(6) | 312 | olRecursYearNth(6) |
313 | */ | 313 | */ |
314 | 314 | ||
315 | int duration = recpat.GetOccurrences(); | 315 | int duration = recpat.GetOccurrences(); |
316 | if ( !hasEndDate ) | 316 | if ( !hasEndDate ) |
317 | duration = -1; | 317 | duration = -1; |
318 | 318 | ||
319 | //LPDISPATCH RecurrencePattern::GetExceptions() | 319 | //LPDISPATCH RecurrencePattern::GetExceptions() |
320 | //long RecurrencePattern::GetMonthOfYear() | 320 | //long RecurrencePattern::GetMonthOfYear() |
321 | if ( rtype == 0 ) { | 321 | if ( rtype == 0 ) { |
322 | if ( hasEndDate ) r->setDaily( freq, endDate ); | 322 | if ( hasEndDate ) r->setDaily( freq, endDate ); |
323 | else r->setDaily( freq, duration ); | 323 | else r->setDaily( freq, duration ); |
324 | } else if ( rtype == 1 ) { | 324 | } else if ( rtype == 1 ) { |
325 | if ( hasEndDate ) r->setWeekly( freq, weekDays, endDate ); | 325 | if ( hasEndDate ) r->setWeekly( freq, weekDays, endDate ); |
326 | else r->setWeekly( freq, weekDays, duration ); | 326 | else r->setWeekly( freq, weekDays, duration ); |
327 | } else if ( rtype == 2 ) { | 327 | } else if ( rtype == 2 ) { |
328 | if ( hasEndDate ) | 328 | if ( hasEndDate ) |
329 | r->setMonthly( Recurrence::rMonthlyDay, freq, endDate ); | 329 | r->setMonthly( Recurrence::rMonthlyDay, freq, endDate ); |
330 | else | 330 | else |
331 | r->setMonthly( Recurrence::rMonthlyDay, freq, duration ); | 331 | r->setMonthly( Recurrence::rMonthlyDay, freq, duration ); |
332 | //r->addMonthlyDay( startDate.day() ); | 332 | //r->addMonthlyDay( startDate.day() ); |
333 | r->addMonthlyDay( recpat.GetDayOfMonth() ); | 333 | r->addMonthlyDay( recpat.GetDayOfMonth() ); |
334 | } else if ( rtype == 3 ) { | 334 | } else if ( rtype == 3 ) { |
335 | if ( hasEndDate ) | 335 | if ( hasEndDate ) |
336 | r->setMonthly( Recurrence::rMonthlyPos, freq, endDate ); | 336 | r->setMonthly( Recurrence::rMonthlyPos, freq, endDate ); |
337 | else | 337 | else |
338 | r->setMonthly( Recurrence::rMonthlyPos, freq, duration ); | 338 | r->setMonthly( Recurrence::rMonthlyPos, freq, duration ); |
339 | QBitArray days( 7 ); | 339 | QBitArray days( 7 ); |
340 | days.fill( false ); | 340 | days.fill( false ); |
341 | days.setBit( startDate.dayOfWeek() - 1 ); | 341 | days.setBit( startDate.dayOfWeek() - 1 ); |
342 | int pos = (startDate.day()/7)+1; | 342 | int pos = (startDate.day()/7)+1; |
343 | r->addMonthlyPos( pos, days ); | 343 | r->addMonthlyPos( pos, days ); |
344 | //QString mes = i18n("Importing monthlypos.\n\npos: %1 , day: %2").arg( pos).arg( startDate.dayOfWeek() - 1); | 344 | //QString mes = i18n("Importing monthlypos.\n\npos: %1 , day: %2").arg( pos).arg( startDate.dayOfWeek() - 1); |
345 | //KMessageBox::information(this,mes); | 345 | //KMessageBox::information(this,mes); |
346 | } else if ( rtype == 5 ) { | 346 | } else if ( rtype == 5 ) { |
347 | freq = 1; | 347 | freq = 1; |
348 | if ( hasEndDate ) | 348 | if ( hasEndDate ) |
349 | r->setYearly( Recurrence::rYearlyMonth, freq, endDate ); | 349 | r->setYearly( Recurrence::rYearlyMonth, freq, endDate ); |
350 | else | 350 | else |
351 | r->setYearly( Recurrence::rYearlyMonth, freq, duration ); | 351 | r->setYearly( Recurrence::rYearlyMonth, freq, duration ); |
352 | r->addYearlyNum( startDate.month() ); | 352 | r->addYearlyNum( startDate.month() ); |
353 | } else if ( true /*rtype == 6*/ ) { | 353 | } else if ( true /*rtype == 6*/ ) { |
354 | // KOganizer cannot handle this in the GUI | 354 | // KOganizer cannot handle this in the GUI |
355 | // we are mapping this to monthly - every 12. month | 355 | // we are mapping this to monthly - every 12. month |
356 | freq = 12; | 356 | freq = 12; |
357 | if ( hasEndDate ) | 357 | if ( hasEndDate ) |
358 | r->setMonthly( Recurrence::rMonthlyPos, freq, endDate ); | 358 | r->setMonthly( Recurrence::rMonthlyPos, freq, endDate ); |
359 | else | 359 | else |
360 | r->setMonthly( Recurrence::rMonthlyPos, freq, duration ); | 360 | r->setMonthly( Recurrence::rMonthlyPos, freq, duration ); |
361 | QBitArray days( 7 ); | 361 | QBitArray days( 7 ); |
362 | days.fill( false ); | 362 | days.fill( false ); |
363 | days.setBit( startDate.dayOfWeek() - 1 ); | 363 | days.setBit( startDate.dayOfWeek() - 1 ); |
364 | int pos = (startDate.day()/7)+1; | 364 | int pos = (startDate.day()/7)+1; |
365 | r->addMonthlyPos( pos, days ); | 365 | r->addMonthlyPos( pos, days ); |
366 | } | 366 | } |
367 | // recurrence exceptions | 367 | // recurrence exceptions |
368 | LPDISPATCH dispItem = recpat.GetExceptions(); | 368 | LPDISPATCH dispItem = recpat.GetExceptions(); |
369 | dispItem->AddRef(); | 369 | dispItem->AddRef(); |
370 | Exceptions ex(dispItem); | 370 | Exceptions ex(dispItem); |
371 | _variant_t indx((long)0); | 371 | _variant_t indx((long)0); |
372 | LPDISPATCH itm; | 372 | LPDISPATCH itm; |
373 | for(i=1; i <= ex.GetCount(); ++i) { | 373 | for(i=1; i <= ex.GetCount(); ++i) { |
374 | indx = (long)i; | 374 | indx = (long)i; |
375 | itm = ex.Item( indx.Detach() ); | 375 | itm = ex.Item( indx.Detach() ); |
376 | ::Exception * pItem = (::Exception *)&itm; | 376 | ::Exception * pItem = (::Exception *)&itm; |
377 | event->addExDate( QDateTime( mDdate2Qdtr( pItem->GetOriginalDate())).date() ); | 377 | event->addExDate( QDateTime( mDdate2Qdtr( pItem->GetOriginalDate())).date() ); |
378 | if ( !pItem->GetDeleted() ) { | 378 | if ( !pItem->GetDeleted() ) { |
379 | LPDISPATCH appIt = pItem->GetAppointmentItem(); | 379 | LPDISPATCH appIt = pItem->GetAppointmentItem(); |
380 | _AppointmentItem * paItem = (_AppointmentItem *)&appIt; | 380 | _AppointmentItem * paItem = (_AppointmentItem *)&appIt; |
381 | ol2kopiCalendar( paItem, false ); | 381 | ol2kopiCalendar( paItem, false ); |
382 | } | 382 | } |
383 | itm->Release(); | 383 | itm->Release(); |
384 | } | 384 | } |
385 | } | 385 | } |
386 | // recurrence ENTE | 386 | // recurrence ENTE |
387 | event->setOrganizer( QString::fromUcs2( aItem->GetOrganizer().GetBuffer())); | 387 | event->setOrganizer( QString::fromUcs2( aItem->GetOrganizer().GetBuffer())); |
388 | 388 | ||
389 | //GetOptionalAttendees() | 389 | //GetOptionalAttendees() |
390 | //GetRequiredAttendees() | 390 | //GetRequiredAttendees() |
391 | LPDISPATCH dispItem = aItem->GetRecipients(); | 391 | LPDISPATCH dispItem = aItem->GetRecipients(); |
392 | dispItem->AddRef(); | 392 | dispItem->AddRef(); |
393 | _Folders mf(dispItem); | 393 | _Folders mf(dispItem); |
394 | mf.m_lpDispatch->AddRef(); | 394 | mf.m_lpDispatch->AddRef(); |
395 | _variant_t indx((long)0); | 395 | _variant_t indx((long)0); |
396 | LPDISPATCH itm; | 396 | LPDISPATCH itm; |
397 | int i; | 397 | int i; |
398 | QString optAtt = QString::fromUcs2( aItem->GetOptionalAttendees().GetBuffer()); | 398 | QString optAtt = QString::fromUcs2( aItem->GetOptionalAttendees().GetBuffer()); |
399 | QString reqAtt = QString::fromUcs2( aItem->GetRequiredAttendees().GetBuffer()); | 399 | QString reqAtt = QString::fromUcs2( aItem->GetRequiredAttendees().GetBuffer()); |
400 | //GetRequiredAttendees() | 400 | //GetRequiredAttendees() |
401 | for(i=1; i <= mf.GetCount(); ++i) { | 401 | for(i=1; i <= mf.GetCount(); ++i) { |
402 | indx = (long)i; | 402 | indx = (long)i; |
403 | itm = mf.Item( indx.Detach() ); | 403 | itm = mf.Item( indx.Detach() ); |
404 | Recipient * pItem = (Recipient *)&itm; | 404 | Recipient * pItem = (Recipient *)&itm; |
405 | 405 | ||
406 | //a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; | 406 | //a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; |
407 | QString name = QString::fromUcs2( pItem->GetName().GetBuffer()); | 407 | QString name = QString::fromUcs2( pItem->GetName().GetBuffer()); |
408 | KCal::Attendee::PartStat stat; | 408 | KCal::Attendee::PartStat stat; |
409 | bool rsvp = false; | 409 | bool rsvp = false; |
410 | switch ( pItem->GetMeetingResponseStatus() ) { | 410 | switch ( pItem->GetMeetingResponseStatus() ) { |
411 | case 0: //not answered | 411 | case 0: //not answered |
412 | rsvp = true; | 412 | rsvp = true; |
413 | case 5: //not answered | 413 | case 5: //not answered |
414 | stat = Attendee::NeedsAction; | 414 | stat = Attendee::NeedsAction; |
415 | break; | 415 | break; |
416 | case 1: //organizer | 416 | case 1: //organizer |
417 | stat = Attendee::Delegated ; | 417 | stat = Attendee::Delegated ; |
418 | break; | 418 | break; |
419 | case 2: //tentative | 419 | case 2: //tentative |
420 | stat = Attendee::Tentative ; | 420 | stat = Attendee::Tentative ; |
421 | break; | 421 | break; |
422 | case 3: //accepted | 422 | case 3: //accepted |
423 | stat = Attendee::Accepted; | 423 | stat = Attendee::Accepted; |
424 | break; | 424 | break; |
425 | case 4: //declined | 425 | case 4: //declined |
426 | stat =Attendee::Declined ; | 426 | stat =Attendee::Declined ; |
427 | break; | 427 | break; |
428 | default: | 428 | default: |
429 | stat = Attendee::NeedsAction ; | 429 | stat = Attendee::NeedsAction ; |
430 | 430 | ||
431 | } | 431 | } |
432 | KCal::Attendee::Role role; | 432 | KCal::Attendee::Role role; |
433 | if ( event->organizer() == name ) | 433 | if ( event->organizer() == name ) |
434 | role = KCal::Attendee::Chair; | 434 | role = KCal::Attendee::Chair; |
435 | else if ( reqAtt.find( name ) >= 0 ) | 435 | else if ( reqAtt.find( name ) >= 0 ) |
436 | role = KCal::Attendee::ReqParticipant; | 436 | role = KCal::Attendee::ReqParticipant; |
437 | else if ( optAtt.find( name ) >= 0 ) | 437 | else if ( optAtt.find( name ) >= 0 ) |
438 | role = KCal::Attendee::OptParticipant; | 438 | role = KCal::Attendee::OptParticipant; |
439 | else | 439 | else |
440 | role = KCal::Attendee::NonParticipant; | 440 | role = KCal::Attendee::NonParticipant; |
441 | QString mail = QString::fromUcs2(pItem->GetAddress().GetBuffer()); | 441 | QString mail = QString::fromUcs2(pItem->GetAddress().GetBuffer()); |
442 | if( mail.isEmpty() && name.find("@") > 0 ) | 442 | if( mail.isEmpty() && name.find("@") > 0 ) { |
443 | mail = name; | 443 | int kl = name.find("<"); |
444 | int gr = name.find(">"); | ||
445 | if ( kl >= 0 && gr >= 0) { | ||
446 | mail = name.mid (kl+1, gr - kl -1); | ||
447 | name = name.left( kl ); | ||
448 | } | ||
449 | else | ||
450 | mail = name; | ||
451 | } | ||
444 | mail = mail.stripWhiteSpace(); | 452 | mail = mail.stripWhiteSpace(); |
445 | 453 | ||
446 | QString uid = getUidByEmail( mail ); | 454 | QString uid = getUidByEmail( mail ); |
447 | //uid = QString::fromUcs2( pItem->GetEntryID().GetBuffer()); | 455 | //uid = QString::fromUcs2( pItem->GetEntryID().GetBuffer()); |
448 | KCal::Attendee * a = new KCal::Attendee( name, mail,rsvp,stat,role,uid) ; | 456 | KCal::Attendee * a = new KCal::Attendee( name, mail,rsvp,stat,role,uid) ; |
449 | event->addAttendee( a , false ); | 457 | event->addAttendee( a , false ); |
450 | itm->Release(); | 458 | itm->Release(); |
451 | } | 459 | } |
452 | 460 | ||
453 | 461 | ||
454 | if ( !mCalendar->addEventNoDup( event )) | 462 | if ( !mCalendar->addEventNoDup( event )) |
455 | delete event; | 463 | delete event; |
456 | else { | 464 | else { |
457 | // QString mes = i18n("Importing %1.\n date: %2 date: %3").arg( event->summary()).arg( event->dtStart().toString()).arg( event->dtEnd().toString()); | 465 | // QString mes = i18n("Importing %1.\n date: %2 date: %3").arg( event->summary()).arg( event->dtStart().toString()).arg( event->dtEnd().toString()); |
458 | //KMessageBox::information(this,mes); | 466 | //KMessageBox::information(this,mes); |
459 | ++importedItems; | 467 | ++importedItems; |
460 | } | 468 | } |
461 | } | 469 | } |
462 | void KOImportOLdialog::slotCancel() | 470 | void KOImportOLdialog::slotCancel() |
463 | { | 471 | { |
464 | reject(); | 472 | reject(); |
465 | } | 473 | } |
466 | 474 | ||
467 | QString KOImportOLdialog::getUidByEmail( QString email ) | 475 | QString KOImportOLdialog::getUidByEmail( QString email ) |
468 | { | 476 | { |
469 | KABC::StdAddressBook* AddressBook = KABC::StdAddressBook::self( true ); | 477 | KABC::StdAddressBook* AddressBook = KABC::StdAddressBook::self( true ); |
470 | KABC::AddressBook::Iterator it; | 478 | KABC::AddressBook::Iterator it; |
471 | for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { | 479 | for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { |
472 | QStringList em = (*it).emails(); | 480 | QStringList em = (*it).emails(); |
473 | if ( em.contains( email )) | 481 | if ( em.contains( email )) |
474 | return (*it).uid(); | 482 | return (*it).uid(); |
475 | } | 483 | } |
476 | return ""; | 484 | return ""; |
477 | } | 485 | } |