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