1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
|
/*
This file is part of KOrganizer.
Copyright (c) 2002 Jan-Pascal van Best <janpascal@vanbest.org>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include <tqfile.h>
#include <kapplication.h>
#include <kconfig.h>
#include <kstandarddirs.h>
#include <kurl.h>
#include <kdebug.h>
#include <kmessagebox.h>
#include <klocale.h>
#include <kaction.h>
#include <kglobal.h>
#include "korganizer/korganizer.h"
#include "korganizer/calendarview.h"
#include <exchangeclient.h>
#include <exchangeaccount.h>
#include "exchange.h"
#include "exchangedialog.h"
#include "exchangeconfig.h"
using namespace KCal; // Needed for connecting slots
class ExchangeFactory : public KOrg::PartFactory {
public:
KOrg::Part *create(KOrg::MainWindow *parent, const char *name)
{
kdDebug(5850) << "Registering Exchange Plugin...\n";
TDEGlobal::locale()->insertCatalogue("libkpimexchange");
return new Exchange(parent,name);
}
};
K_EXPORT_COMPONENT_FACTORY( libkorg_exchange, ExchangeFactory )
Exchange::Exchange(KOrg::MainWindow *parent, const char *name) :
KOrg::Part(parent,name)
{
setInstance( new TDEInstance( "korganizer" ) );
kdDebug(5850) << "Creating Exchange Plugin...\n";
mAccount = new KPIM::ExchangeAccount( "Calendar/Exchange Plugin" );
mClient = new KPIM::ExchangeClient( mAccount );
mClient->setWindow( parent->topLevelWidget() );
setXMLFile("plugins/exchangeui.rc");
new KAction(i18n("&Download..."), 0, this, TQT_SLOT(download()),
actionCollection(), "exchange_download");
KAction *action = new KAction(i18n("&Upload Event..."), 0, this, TQT_SLOT(upload()),
actionCollection(), "exchange_upload");
TQObject::connect(mainWindow()->view(),TQT_SIGNAL(incidenceSelected(Incidence *)),
this, TQT_SLOT(slotIncidenceSelected(Incidence *)));
action->setEnabled( false );
TQObject::connect(this,TQT_SIGNAL(enableIncidenceActions(bool)),
action,TQT_SLOT(setEnabled(bool)));
action = new KAction(i18n("De&lete Event"), 0, this, TQT_SLOT(remove()),
actionCollection(), "exchange_delete");
TQObject::connect(this,TQT_SIGNAL(enableIncidenceActions(bool)),
action,TQT_SLOT(setEnabled(bool)));
action->setEnabled( false );
new KAction(i18n("&Configure..."), 0, this, TQT_SLOT(configure()),
actionCollection(), "exchange_configure");
connect( this, TQT_SIGNAL( calendarChanged() ), mainWindow()->view(), TQT_SLOT( updateView() ) );
connect( this, TQT_SIGNAL( calendarChanged(const TQDate &, const TQDate &)),
mainWindow()->view(), TQT_SLOT(updateView(const TQDate &, const TQDate &)) );
}
Exchange::~Exchange()
{
kdDebug(5850) << "Exchange Plugin destructor" << endl;
}
TQString Exchange::info()
{
return i18n("This plugin imports and export calendar events from/to a Microsoft Exchange 2000 Server.");
}
TQString Exchange::shortInfo()
{
return i18n("Exchange Plugin");
}
void Exchange::slotIncidenceSelected( Incidence *incidence )
{
emit enableIncidenceActions( incidence != 0 );
}
void Exchange::download()
{
ExchangeDialog dialog( mainWindow()->view()->startDate(), mainWindow()->view()->endDate() );
if (dialog.exec() != TQDialog::Accepted )
return;
TQDate start = dialog.m_start->date();
TQDate end = dialog.m_end->date();
KCal::Calendar* calendar = mainWindow()->view()->calendar();
int result = mClient->downloadSynchronous(calendar, start, end, true );
if ( result == KPIM::ExchangeClient::ResultOK )
emit calendarChanged();
else
showError( result, mClient->detailedErrorString() );
}
void Exchange::upload()
{
kdDebug(5850) << "Called Exchange::upload()" << endl;
Event* event = dynamic_cast<Event *> ( mainWindow()->view()->currentSelection() );
if ( ! event )
{
KMessageBox::information( 0L, i18n("Please select an appointment."), i18n("Exchange Plugin") );
return;
}
if ( KMessageBox::warningContinueCancel( 0L, i18n("Exchange Upload is EXPERIMENTAL, you may lose data on this appointment!"), i18n("Exchange Plugin"), i18n("&Upload") )
== KMessageBox::Continue ) {
kdDebug(5850) << "Trying to add appointment " << event->summary() << endl;
int result = mClient->uploadSynchronous( event );
if ( result != KPIM::ExchangeClient::ResultOK )
showError( result, mClient->detailedErrorString() );
}
}
void Exchange::remove()
{
kdDebug(5850) << "Called Exchange::remove()" << endl;
Event* event = dynamic_cast<Event *> ( mainWindow()->view()->currentSelection() );
if ( ! event )
{
KMessageBox::information( 0L, i18n("Please select an appointment."), i18n("Exchange Plugin") );
return;
}
if ( KMessageBox::warningContinueCancel( 0L, i18n("Exchange Delete is EXPERIMENTAL, if this is a recurring event it will delete all instances!"), i18n("Exchange Plugin"), KGuiItem(i18n("&Delete"),"editdelete") )
== KMessageBox::Continue ) {
kdDebug(5850) << "Trying to delete appointment " << event->summary() << endl;
int result = mClient->removeSynchronous( event );
if ( result == KPIM::ExchangeClient::ResultOK ) {
mainWindow()->view()->calendar()->deleteEvent( event );
emit calendarChanged();
} else
showError( result, mClient->detailedErrorString() );
}
}
void Exchange::configure()
{
kdDebug(5850) << "Exchange::configure" << endl;
ExchangeConfig dialog( mAccount );
if (dialog.exec() == TQDialog::Accepted )
mAccount->save( "Calendar/Exchange Plugin" );
}
void Exchange::showError( int error, const TQString& moreInfo /* = TQString() */ )
{
TQString errorText;
switch( error ) {
case KPIM::ExchangeClient::ResultOK:
errorText = i18n( "No Error" );
break;
case KPIM::ExchangeClient::CommunicationError:
errorText = i18n( "The Exchange server could not be reached or returned an error." );
break;
case KPIM::ExchangeClient::ServerResponseError:
errorText = i18n( "Server response could not be interpreted." );
break;
case KPIM::ExchangeClient::IllegalAppointmentError:
errorText = i18n( "Appointment data could not be interpreted." );
break;
case KPIM::ExchangeClient::NonEventError:
errorText = i18n( "This should not happen: trying to upload wrong type of event." );
break;
case KPIM::ExchangeClient::EventWriteError:
errorText = i18n( "An error occurred trying to write an appointment to the server." );
break;
case KPIM::ExchangeClient::DeleteUnknownEventError:
errorText = i18n( "Trying to delete an event that is not present on the server." );
break;
case KPIM::ExchangeClient::UnknownError:
default:
errorText = i18n( "Unknown Error" );
}
if ( error != KPIM::ExchangeClient::ResultOK ) {
if ( moreInfo.isNull() )
KMessageBox::error( mainWindow()->topLevelWidget(), errorText, i18n( "Exchange Plugin" ) );
else
KMessageBox::detailedError( mainWindow()->topLevelWidget(), errorText, moreInfo, i18n( "Exchange Plugin" ) );
}
}
void Exchange::test()
{
kdDebug(5850) << "Entering test()" << endl;
mClient->test();
}
void Exchange::test2()
{
kdDebug(5850) << "Entering test2()" << endl;
}
#include "exchange.moc"
|