22 #include <tdeapplication.h>
23 #include <tdeconfig.h>
24 #include <kstandarddirs.h>
29 #include <tdemessagebox.h>
30 #include <tdelocale.h>
31 #include <tdeaction.h>
32 #include <tdeglobal.h>
34 #include "korganizer/korganizer.h"
35 #include "korganizer/calendarview.h"
37 #include <exchangeclient.h>
38 #include <exchangeaccount.h>
41 #include "exchangedialog.h"
42 #include "exchangeconfig.h"
47 class ExchangeFactory :
public KOrg::PartFactory {
51 kdDebug(5850) <<
"Registering Exchange Plugin...\n";
52 TDEGlobal::locale()->insertCatalogue(
"libkpimexchange");
53 return new Exchange(parent,name);
57 K_EXPORT_COMPONENT_FACTORY( libkorg_exchange, ExchangeFactory )
60 KOrg::Part(parent,name)
62 setInstance(
new TDEInstance(
"korganizer" ) );
64 kdDebug(5850) <<
"Creating Exchange Plugin...\n";
66 mAccount =
new KPIM::ExchangeAccount(
"Calendar/Exchange Plugin" );
67 mClient =
new KPIM::ExchangeClient( mAccount );
70 setXMLFile(
"plugins/exchangeui.rc");
72 new TDEAction(i18n(
"&Download..."), 0,
this, TQ_SLOT(download()),
73 actionCollection(),
"exchange_download");
75 TDEAction *action =
new TDEAction(i18n(
"&Upload Event..."), 0,
this, TQ_SLOT(upload()),
76 actionCollection(),
"exchange_upload");
77 TQObject::connect(mainWindow()->
view(),TQ_SIGNAL(incidenceSelected(
Incidence *)),
78 this, TQ_SLOT(slotIncidenceSelected(
Incidence *)));
79 action->setEnabled(
false );
80 TQObject::connect(
this,TQ_SIGNAL(enableIncidenceActions(
bool)),
81 action,TQ_SLOT(setEnabled(
bool)));
83 action =
new TDEAction(i18n(
"De&lete Event"), 0,
this, TQ_SLOT(remove()),
84 actionCollection(),
"exchange_delete");
85 TQObject::connect(
this,TQ_SIGNAL(enableIncidenceActions(
bool)),
86 action,TQ_SLOT(setEnabled(
bool)));
87 action->setEnabled(
false );
89 new TDEAction(i18n(
"&Configure..."), 0,
this, TQ_SLOT(configure()),
90 actionCollection(),
"exchange_configure");
92 connect(
this, TQ_SIGNAL( calendarChanged() ), mainWindow()->
view(), TQ_SLOT( updateView() ) );
93 connect(
this, TQ_SIGNAL( calendarChanged(
const TQDate &,
const TQDate &)),
94 mainWindow()->
view(), TQ_SLOT(updateView(
const TQDate &,
const TQDate &)) );
99 kdDebug(5850) <<
"Exchange Plugin destructor" << endl;
102 TQString Exchange::info()
104 return i18n(
"This plugin imports and export calendar events from/to a Microsoft Exchange 2000 Server.");
107 TQString Exchange::shortInfo()
109 return i18n(
"Exchange Plugin");
112 void Exchange::slotIncidenceSelected(
Incidence *incidence )
114 emit enableIncidenceActions( incidence != 0 );
117 void Exchange::download()
119 ExchangeDialog dialog( mainWindow()->
view()->startDate(), mainWindow()->
view()->endDate() );
121 if (dialog.exec() != TQDialog::Accepted )
124 TQDate start = dialog.m_start->date();
125 TQDate end = dialog.m_end->date();
129 int result = mClient->downloadSynchronous(calendar, start, end,
true );
131 if ( result == KPIM::ExchangeClient::ResultOK )
132 emit calendarChanged();
134 showError( result, mClient->detailedErrorString() );
138 void Exchange::upload()
140 kdDebug(5850) <<
"Called Exchange::upload()" << endl;
142 Event*
event =
dynamic_cast<Event *
> ( mainWindow()->view()->currentSelection() );
145 KMessageBox::information( 0L, i18n(
"Please select an appointment."), i18n(
"Exchange Plugin") );
148 if ( KMessageBox::warningContinueCancel( 0L, i18n(
"Exchange Upload is EXPERIMENTAL, you may lose data on this appointment!"), i18n(
"Exchange Plugin"), i18n(
"&Upload") )
149 == KMessageBox::Continue ) {
150 kdDebug(5850) <<
"Trying to add appointment " <<
event->summary() << endl;
151 int result = mClient->uploadSynchronous( event );
152 if ( result != KPIM::ExchangeClient::ResultOK )
153 showError( result, mClient->detailedErrorString() );
157 void Exchange::remove()
159 kdDebug(5850) <<
"Called Exchange::remove()" << endl;
161 Event*
event =
dynamic_cast<Event *
> ( mainWindow()->view()->currentSelection() );
164 KMessageBox::information( 0L, i18n(
"Please select an appointment."), i18n(
"Exchange Plugin") );
168 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"),
"edit-delete") )
169 == KMessageBox::Continue ) {
170 kdDebug(5850) <<
"Trying to delete appointment " <<
event->summary() << endl;
171 int result = mClient->removeSynchronous( event );
173 if ( result == KPIM::ExchangeClient::ResultOK ) {
174 mainWindow()->view()->calendar()->deleteEvent( event );
175 emit calendarChanged();
177 showError( result, mClient->detailedErrorString() );
181 void Exchange::configure()
183 kdDebug(5850) <<
"Exchange::configure" << endl;
184 ExchangeConfig dialog( mAccount );
186 if (dialog.exec() == TQDialog::Accepted )
187 mAccount->save(
"Calendar/Exchange Plugin" );
190 void Exchange::showError(
int error,
const TQString& moreInfo )
194 case KPIM::ExchangeClient::ResultOK:
195 errorText = i18n(
"No Error" );
197 case KPIM::ExchangeClient::CommunicationError:
198 errorText = i18n(
"The Exchange server could not be reached or returned an error." );
200 case KPIM::ExchangeClient::ServerResponseError:
201 errorText = i18n(
"Server response could not be interpreted." );
203 case KPIM::ExchangeClient::IllegalAppointmentError:
204 errorText = i18n(
"Appointment data could not be interpreted." );
206 case KPIM::ExchangeClient::NonEventError:
207 errorText = i18n(
"This should not happen: trying to upload wrong type of event." );
209 case KPIM::ExchangeClient::EventWriteError:
210 errorText = i18n(
"An error occurred trying to write an appointment to the server." );
212 case KPIM::ExchangeClient::DeleteUnknownEventError:
213 errorText = i18n(
"Trying to delete an event that is not present on the server." );
215 case KPIM::ExchangeClient::UnknownError:
217 errorText = i18n(
"Unknown Error" );
220 if ( error != KPIM::ExchangeClient::ResultOK ) {
221 if ( moreInfo.isNull() )
222 KMessageBox::error( mainWindow()->topLevelWidget(), errorText, i18n(
"Exchange Plugin" ) );
224 KMessageBox::detailedError( mainWindow()->topLevelWidget(), errorText, moreInfo, i18n(
"Exchange Plugin" ) );
228 void Exchange::test()
230 kdDebug(5850) <<
"Entering test()" << endl;
234 void Exchange::test2()
236 kdDebug(5850) <<
"Entering test2()" << endl;
238 #include "exchange.moc"
interface for korganizer main window
virtual TQWidget * topLevelWidget()=0
Return widget whcih represents this main window.
bool view(TQWidget *parent, Attachment *attachment)