Diffstat (limited to 'korganizer/koimportoldialog.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | korganizer/koimportoldialog.cpp | 30 |
1 files changed, 15 insertions, 15 deletions
diff --git a/korganizer/koimportoldialog.cpp b/korganizer/koimportoldialog.cpp index 79b97e8..63d044c 100644 --- a/korganizer/koimportoldialog.cpp +++ b/korganizer/koimportoldialog.cpp | |||
@@ -1,142 +1,142 @@ | |||
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 <q3frame.h> |
26 | #include <qpixmap.h> | 26 | #include <qpixmap.h> |
27 | #include <qlayout.h> | 27 | #include <qlayout.h> |
28 | #include <qprogressbar.h> | 28 | #include <q3progressbar.h> |
29 | #include <qprogressdialog.h> | 29 | #include <q3progressdialog.h> |
30 | #include <qwidgetstack.h> | 30 | #include <q3widgetstack.h> |
31 | #include <qdatetime.h> | 31 | #include <qdatetime.h> |
32 | #include <qdir.h> | 32 | #include <qdir.h> |
33 | #include <qapplication.h> | 33 | #include <qapplication.h> |
34 | #include <qhbox.h> | 34 | #include <q3hbox.h> |
35 | #include <qregexp.h> | 35 | #include <qregexp.h> |
36 | #include <qheader.h> | 36 | #include <q3header.h> |
37 | #include <qdatetime.h> | 37 | #include <qdatetime.h> |
38 | #include <qlistview.h> | 38 | #include <q3listview.h> |
39 | 39 | ||
40 | #include <kdebug.h> | 40 | #include <kdebug.h> |
41 | #include <klocale.h> | 41 | #include <klocale.h> |
42 | #include <kstandarddirs.h> | 42 | #include <kstandarddirs.h> |
43 | #include <kmessagebox.h> | 43 | #include <kmessagebox.h> |
44 | #include <kfiledialog.h> | 44 | #include <kfiledialog.h> |
45 | 45 | ||
46 | #include <libkdepim/categoryselectdialog.h> | 46 | #include <libkdepim/categoryselectdialog.h> |
47 | #include <libkdepim/kinputdialog.h> | 47 | #include <libkdepim/kinputdialog.h> |
48 | 48 | ||
49 | #include <libkcal/calendarlocal.h> | 49 | #include <libkcal/calendarlocal.h> |
50 | #include <libkcal/icalformat.h> | 50 | #include <libkcal/icalformat.h> |
51 | #include <kabc/stdaddressbook.h> | 51 | #include <kabc/stdaddressbook.h> |
52 | 52 | ||
53 | #include "koprefs.h" | 53 | #include "koprefs.h" |
54 | #include "koglobals.h" | 54 | #include "koglobals.h" |
55 | 55 | ||
56 | #include "koimportoldialog.h" | 56 | #include "koimportoldialog.h" |
57 | 57 | ||
58 | #include "../outport/msoutl9.h" | 58 | #include "../outport/msoutl9.h" |
59 | #include <ole2.h> | 59 | #include <ole2.h> |
60 | #include <comutil.h> | 60 | #include <comutil.h> |
61 | _Application gOlApp; | 61 | _Application gOlApp; |
62 | 62 | ||
63 | QDateTime mDdate2Qdtr( DATE dt) | 63 | QDateTime mDdate2Qdtr( DATE dt) |
64 | { | 64 | { |
65 | COleDateTime odt; | 65 | COleDateTime odt; |
66 | SYSTEMTIME st; | 66 | SYSTEMTIME st; |
67 | odt = dt; | 67 | odt = dt; |
68 | odt.GetAsSystemTime(st); | 68 | odt.GetAsSystemTime(st); |
69 | QDateTime qdt (QDate(st.wYear, st.wMonth,st.wDay ),QTime( st.wHour, st.wMinute,st.wSecond ) ); | 69 | QDateTime qdt (QDate(st.wYear, st.wMonth,st.wDay ),QTime( st.wHour, st.wMinute,st.wSecond ) ); |
70 | return qdt; | 70 | return qdt; |
71 | } | 71 | } |
72 | 72 | ||
73 | class OLEListViewItem : public QCheckListItem | 73 | class OLEListViewItem : public Q3CheckListItem |
74 | { | 74 | { |
75 | public: | 75 | public: |
76 | OLEListViewItem( QListView *parent, QString text ) : | 76 | OLEListViewItem( Q3ListView *parent, QString text ) : |
77 | QCheckListItem( parent, text, QCheckListItem::CheckBox ) { mData = 0; }; | 77 | Q3CheckListItem( parent, text, Q3CheckListItem::CheckBox ) { mData = 0; }; |
78 | OLEListViewItem( QListViewItem *after, QString text ) : | 78 | OLEListViewItem( Q3ListViewItem *after, QString text ) : |
79 | QCheckListItem( after, text, QCheckListItem::CheckBox ) { mData = 0; }; | 79 | Q3CheckListItem( after, text, Q3CheckListItem::CheckBox ) { mData = 0; }; |
80 | ~OLEListViewItem() {}; | 80 | ~OLEListViewItem() {}; |
81 | void setData( DWORD data ) {mData= data; }; | 81 | void setData( DWORD data ) {mData= data; }; |
82 | DWORD data() { return mData ;}; | 82 | DWORD data() { return mData ;}; |
83 | private: | 83 | private: |
84 | DWORD mData; | 84 | DWORD mData; |
85 | }; | 85 | }; |
86 | 86 | ||
87 | KOImportOLdialog::KOImportOLdialog( const QString &caption, | 87 | KOImportOLdialog::KOImportOLdialog( const QString &caption, |
88 | Calendar *calendar, QWidget *parent ) : | 88 | Calendar *calendar, QWidget *parent ) : |
89 | KDialogBase( Plain, caption, User1 | Close, Ok, | 89 | KDialogBase( Plain, caption, User1 | Close, Ok, |
90 | parent, caption, true, false, i18n("Import!") ) | 90 | parent, caption, true, false, i18n("Import!") ) |
91 | { | 91 | { |
92 | QHBox * mw = new QHBox( this ); | 92 | Q3HBox * mw = new Q3HBox( this ); |
93 | setMainWidget( mw ); | 93 | setMainWidget( mw ); |
94 | mListView = new QListView( mw ); | 94 | mListView = new Q3ListView( mw ); |
95 | mListView->addColumn(i18n("Select Folder to import")); | 95 | mListView->addColumn(i18n("Select Folder to import")); |
96 | mListView->addColumn(i18n("Content Type")); | 96 | mListView->addColumn(i18n("Content Type")); |
97 | mCalendar = calendar; | 97 | mCalendar = calendar; |
98 | connect( this, SIGNAL( user1Clicked() ),SLOT ( slotApply())); | 98 | connect( this, SIGNAL( user1Clicked() ),SLOT ( slotApply())); |
99 | setupFolderView(); | 99 | setupFolderView(); |
100 | resize( sizeHint().width()+50, sizeHint().height()+50 ); | 100 | resize( sizeHint().width()+50, sizeHint().height()+50 ); |
101 | } | 101 | } |
102 | 102 | ||
103 | KOImportOLdialog::~KOImportOLdialog() | 103 | KOImportOLdialog::~KOImportOLdialog() |
104 | { | 104 | { |
105 | 105 | ||
106 | } | 106 | } |
107 | 107 | ||
108 | 108 | ||
109 | void KOImportOLdialog::setupFolderView() | 109 | void KOImportOLdialog::setupFolderView() |
110 | { | 110 | { |
111 | SCODE sc = ::OleInitialize(NULL); | 111 | SCODE sc = ::OleInitialize(NULL); |
112 | if ( FAILED ( sc ) ) { | 112 | if ( FAILED ( sc ) ) { |
113 | KMessageBox::information(this,"OLE initialisation failed"); | 113 | KMessageBox::information(this,"OLE initialisation failed"); |
114 | return; | 114 | return; |
115 | } | 115 | } |
116 | 116 | ||
117 | if(!gOlApp.CreateDispatch(_T("Outlook.Application"),NULL)){ | 117 | if(!gOlApp.CreateDispatch(_T("Outlook.Application"),NULL)){ |
118 | KMessageBox::information(this,"Sorry, cannot access Outlook"); | 118 | KMessageBox::information(this,"Sorry, cannot access Outlook"); |
119 | return ; | 119 | return ; |
120 | } | 120 | } |
121 | MAPIFolder mfInbox; | 121 | MAPIFolder mfInbox; |
122 | MAPIFolder mfRoot; | 122 | MAPIFolder mfRoot; |
123 | CString szName; | 123 | CString szName; |
124 | _NameSpace olNS; | 124 | _NameSpace olNS; |
125 | olNS = gOlApp.GetNamespace(_T("MAPI")); | 125 | olNS = gOlApp.GetNamespace(_T("MAPI")); |
126 | mfInbox = olNS.GetDefaultFolder(6); | 126 | mfInbox = olNS.GetDefaultFolder(6); |
127 | mfRoot = mfInbox.GetParent(); | 127 | mfRoot = mfInbox.GetParent(); |
128 | szName = mfRoot.GetName(); | 128 | szName = mfRoot.GetName(); |
129 | long iType = mfRoot.GetDefaultItemType(); | 129 | long iType = mfRoot.GetDefaultItemType(); |
130 | QString mes; | 130 | QString mes; |
131 | mes = QString::fromUcs2( szName.GetBuffer() ); | 131 | mes = QString::fromUcs2( szName.GetBuffer() ); |
132 | OLEListViewItem * root = new OLEListViewItem( mListView, mes ); | 132 | OLEListViewItem * root = new OLEListViewItem( mListView, mes ); |
133 | mfRoot.m_lpDispatch->AddRef(); | 133 | mfRoot.m_lpDispatch->AddRef(); |
134 | addFolder( root, mfRoot.m_lpDispatch ); | 134 | addFolder( root, mfRoot.m_lpDispatch ); |
135 | root->setOpen( true ); | 135 | root->setOpen( true ); |
136 | mListView->setSortColumn( 0 ); | 136 | mListView->setSortColumn( 0 ); |
137 | mListView->sort( ); | 137 | mListView->sort( ); |
138 | } | 138 | } |
139 | 139 | ||
140 | 140 | ||
141 | void KOImportOLdialog::addFolder(OLEListViewItem* iParent, LPDISPATCH dispParent) | 141 | void KOImportOLdialog::addFolder(OLEListViewItem* iParent, LPDISPATCH dispParent) |
142 | { | 142 | { |
@@ -167,97 +167,97 @@ void KOImportOLdialog::addFolder(OLEListViewItem* iParent, LPDISPATCH dispParent | |||
167 | ts = i18n("Calendar"); | 167 | ts = i18n("Calendar"); |
168 | break; | 168 | break; |
169 | case 2: | 169 | case 2: |
170 | ts = i18n("Contacts"); | 170 | ts = i18n("Contacts"); |
171 | break; | 171 | break; |
172 | case 3: | 172 | case 3: |
173 | ts = i18n("Todos"); | 173 | ts = i18n("Todos"); |
174 | break; | 174 | break; |
175 | case 4: | 175 | case 4: |
176 | ts = i18n("Journals"); | 176 | ts = i18n("Journals"); |
177 | break; | 177 | break; |
178 | case 5: | 178 | case 5: |
179 | ts = i18n("Notes"); | 179 | ts = i18n("Notes"); |
180 | break; | 180 | break; |
181 | default: | 181 | default: |
182 | ts = i18n("Unknown"); | 182 | ts = i18n("Unknown"); |
183 | } | 183 | } |
184 | hChild->setText( 1,ts); | 184 | hChild->setText( 1,ts); |
185 | hChild->setData( (DWORD) mfChild.m_lpDispatch ); | 185 | hChild->setData( (DWORD) mfChild.m_lpDispatch ); |
186 | mfChild.m_lpDispatch->AddRef(); | 186 | mfChild.m_lpDispatch->AddRef(); |
187 | addFolder(hChild, mfChild.m_lpDispatch); | 187 | addFolder(hChild, mfChild.m_lpDispatch); |
188 | } | 188 | } |
189 | } | 189 | } |
190 | 190 | ||
191 | void KOImportOLdialog::slotApply() | 191 | void KOImportOLdialog::slotApply() |
192 | { | 192 | { |
193 | importedItems = 0; | 193 | importedItems = 0; |
194 | OLEListViewItem* child = (OLEListViewItem*) mListView->firstChild(); | 194 | OLEListViewItem* child = (OLEListViewItem*) mListView->firstChild(); |
195 | while ( child ) { | 195 | while ( child ) { |
196 | if ( child->isOn()&& child->data() ) | 196 | if ( child->isOn()&& child->data() ) |
197 | readCalendarData( child->data() ); | 197 | readCalendarData( child->data() ); |
198 | child = (OLEListViewItem*) child->itemBelow(); | 198 | child = (OLEListViewItem*) child->itemBelow(); |
199 | } | 199 | } |
200 | QString mes = i18n("Importing complete.\n\n%1 items imported.").arg( importedItems); | 200 | QString mes = i18n("Importing complete.\n\n%1 items imported.").arg( importedItems); |
201 | KMessageBox::information(this,mes); | 201 | KMessageBox::information(this,mes); |
202 | } | 202 | } |
203 | void KOImportOLdialog::readCalendarData( DWORD folder ) | 203 | void KOImportOLdialog::readCalendarData( DWORD folder ) |
204 | { | 204 | { |
205 | 205 | ||
206 | LPDISPATCH dispItem = (LPDISPATCH)folder; | 206 | LPDISPATCH dispItem = (LPDISPATCH)folder; |
207 | dispItem->AddRef(); | 207 | dispItem->AddRef(); |
208 | MAPIFolder mf(dispItem); | 208 | MAPIFolder mf(dispItem); |
209 | mf.m_lpDispatch->AddRef(); | 209 | mf.m_lpDispatch->AddRef(); |
210 | _Items folderItems; | 210 | _Items folderItems; |
211 | _variant_t indx((long)0); | 211 | _variant_t indx((long)0); |
212 | LPDISPATCH itm; | 212 | LPDISPATCH itm; |
213 | int i; | 213 | int i; |
214 | folderItems = mf.GetItems(); | 214 | folderItems = mf.GetItems(); |
215 | QProgressDialog bar( i18n("Importing calendar data"),i18n("Abort"), folderItems.GetCount(),this ); | 215 | Q3ProgressDialog bar( i18n("Importing calendar data"),i18n("Abort"), folderItems.GetCount(),this ); |
216 | bar.setCaption (i18n("Importing!") ); | 216 | bar.setCaption (i18n("Importing!") ); |
217 | int h = bar.sizeHint().height() ; | 217 | int h = bar.sizeHint().height() ; |
218 | int w = 300; | 218 | int w = 300; |
219 | int dw = QApplication::desktop()->width(); | 219 | int dw = QApplication::desktop()->width(); |
220 | int dh = QApplication::desktop()->height(); | 220 | int dh = QApplication::desktop()->height(); |
221 | //bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); | 221 | //bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); |
222 | bar.show(); | 222 | bar.show(); |
223 | for(i=1; i <= folderItems.GetCount(); ++i) | 223 | for(i=1; i <= folderItems.GetCount(); ++i) |
224 | { | 224 | { |
225 | qApp->processEvents(); | 225 | qApp->processEvents(); |
226 | if ( ! bar.isVisible() ) | 226 | if ( ! bar.isVisible() ) |
227 | return ; | 227 | return ; |
228 | bar.setProgress( i ); | 228 | bar.setProgress( i ); |
229 | bar.raise(); | 229 | bar.raise(); |
230 | indx = (long)i; | 230 | indx = (long)i; |
231 | itm = folderItems.Item(indx.Detach()); | 231 | itm = folderItems.Item(indx.Detach()); |
232 | _AppointmentItem * pItem = (_AppointmentItem *)&itm; | 232 | _AppointmentItem * pItem = (_AppointmentItem *)&itm; |
233 | ol2kopiCalendar( pItem ); | 233 | ol2kopiCalendar( pItem ); |
234 | itm->Release(); | 234 | itm->Release(); |
235 | } | 235 | } |
236 | } | 236 | } |
237 | void KOImportOLdialog::slotOk() | 237 | void KOImportOLdialog::slotOk() |
238 | { | 238 | { |
239 | QDialog::accept(); | 239 | QDialog::accept(); |
240 | } | 240 | } |
241 | 241 | ||
242 | void KOImportOLdialog::ol2kopiCalendar( _AppointmentItem * aItem, bool computeRecurrence ) | 242 | void KOImportOLdialog::ol2kopiCalendar( _AppointmentItem * aItem, bool computeRecurrence ) |
243 | { | 243 | { |
244 | KCal::Event* event = new KCal::Event(); | 244 | KCal::Event* event = new KCal::Event(); |
245 | if ( aItem->GetAllDayEvent() ){ | 245 | if ( aItem->GetAllDayEvent() ){ |
246 | event->setDtStart( QDateTime( mDdate2Qdtr( aItem->GetStart()).date(),QTime(0,0,0 ) )); | 246 | event->setDtStart( QDateTime( mDdate2Qdtr( aItem->GetStart()).date(),QTime(0,0,0 ) )); |
247 | event->setDtEnd( QDateTime( mDdate2Qdtr( aItem->GetEnd()) .date(),QTime(0,0,0 )).addDays(-1)); | 247 | event->setDtEnd( QDateTime( mDdate2Qdtr( aItem->GetEnd()) .date(),QTime(0,0,0 )).addDays(-1)); |
248 | event->setFloats( true ); | 248 | event->setFloats( true ); |
249 | } else { | 249 | } else { |
250 | event->setDtStart( mDdate2Qdtr( aItem->GetStart()) ); | 250 | event->setDtStart( mDdate2Qdtr( aItem->GetStart()) ); |
251 | event->setDtEnd( mDdate2Qdtr( aItem->GetEnd()) ); | 251 | event->setDtEnd( mDdate2Qdtr( aItem->GetEnd()) ); |
252 | event->setFloats( false ); | 252 | event->setFloats( false ); |
253 | } | 253 | } |
254 | event->setSummary( QString::fromUcs2( aItem->GetSubject().GetBuffer()).stripWhiteSpace() ); | 254 | event->setSummary( QString::fromUcs2( aItem->GetSubject().GetBuffer()).stripWhiteSpace() ); |
255 | event->setLocation( QString::fromUcs2( aItem->GetLocation().GetBuffer()).stripWhiteSpace() ); | 255 | event->setLocation( QString::fromUcs2( aItem->GetLocation().GetBuffer()).stripWhiteSpace() ); |
256 | event->setDescription( QString::fromUcs2( aItem->GetBody().GetBuffer()).replace( QRegExp("\\r"), "").stripWhiteSpace() ); | 256 | event->setDescription( QString::fromUcs2( aItem->GetBody().GetBuffer()).replace( QRegExp("\\r"), "").stripWhiteSpace() ); |
257 | QString cat = QString::fromUcs2( aItem->GetCategories().GetBuffer()).replace( QRegExp("; "), ";"); | 257 | QString cat = QString::fromUcs2( aItem->GetCategories().GetBuffer()).replace( QRegExp("; "), ";"); |
258 | event->setCategories( QStringList::split( ";", cat ) ); | 258 | event->setCategories( QStringList::split( ";", cat ) ); |
259 | if ( aItem->GetReminderSet() ) { | 259 | if ( aItem->GetReminderSet() ) { |
260 | event->clearAlarms(); | 260 | event->clearAlarms(); |
261 | Alarm* alarm = event->newAlarm(); | 261 | Alarm* alarm = event->newAlarm(); |
262 | alarm->setStartOffset( -aItem->GetReminderMinutesBeforeStart()*60 ); | 262 | alarm->setStartOffset( -aItem->GetReminderMinutesBeforeStart()*60 ); |
263 | alarm->setEnabled( true ); | 263 | alarm->setEnabled( true ); |