korganizer Library API Documentation

exchange.cpp

00001 /* 00002 This file is part of KOrganizer. 00003 Copyright (c) 2002 Jan-Pascal van Best <janpascal@vanbest.org> 00004 00005 This program is free software; you can redistribute it and/or modify 00006 it under the terms of the GNU General Public License as published by 00007 the Free Software Foundation; either version 2 of the License, or 00008 (at your option) any later version. 00009 00010 This program is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 GNU General Public License for more details. 00014 00015 You should have received a copy of the GNU General Public License 00016 along with this program; if not, write to the Free Software 00017 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00018 */ 00019 00020 #include <qfile.h> 00021 00022 #include <kapplication.h> 00023 #include <kconfig.h> 00024 #include <kstandarddirs.h> 00025 00026 #include <kurl.h> 00027 #include <kdebug.h> 00028 00029 #include <kmessagebox.h> 00030 #include <klocale.h> 00031 #include <kaction.h> 00032 #include <kglobal.h> 00033 00034 #include "korganizer/korganizer.h" 00035 #include "korganizer/calendarview.h" 00036 00037 #include <exchangeclient.h> 00038 #include <exchangeaccount.h> 00039 00040 #include "exchange.h" 00041 #include "exchangedialog.h" 00042 #include "exchangeconfig.h" 00043 00044 00045 using namespace KCal; // Needed for connecting slots 00046 00047 class ExchangeFactory : public KOrg::PartFactory { 00048 public: 00049 KOrg::Part *create(KOrg::MainWindow *parent, const char *name) 00050 { 00051 return new Exchange(parent,name); 00052 } 00053 }; 00054 00055 extern "C" { 00056 void *init_libkorg_exchange() 00057 { 00058 kdDebug(5850) << "Registering Exchange Plugin...\n"; 00059 KGlobal::locale()->insertCatalogue("libkpimexchange"); 00060 return (new ExchangeFactory); 00061 } 00062 } 00063 00064 Exchange::Exchange(KOrg::MainWindow *parent, const char *name) : 00065 KOrg::Part(parent,name) 00066 { 00067 setInstance( new KInstance( "korganizer" ) ); 00068 00069 kdDebug(5850) << "Creating Exchange Plugin...\n"; 00070 00071 mAccount = new KPIM::ExchangeAccount( "Calendar/Exchange Plugin" ); 00072 mClient = new KPIM::ExchangeClient( mAccount ); 00073 mClient->setWindow( parent->topLevelWidget() ); 00074 00075 setXMLFile("plugins/exchangeui.rc"); 00076 00077 new KAction(i18n("Download..."), 0, this, SLOT(download()), 00078 actionCollection(), "exchange_download"); 00079 00080 KAction *action = new KAction(i18n("Upload Event..."), 0, this, SLOT(upload()), 00081 actionCollection(), "exchange_upload"); 00082 QObject::connect(mainWindow()->view(),SIGNAL(incidenceSelected(Incidence *)), 00083 this, SLOT(slotIncidenceSelected(Incidence *))); 00084 action->setEnabled( false ); 00085 QObject::connect(this,SIGNAL(enableIncidenceActions(bool)), 00086 action,SLOT(setEnabled(bool))); 00087 00088 action = new KAction(i18n("Delete Event"), 0, this, SLOT(remove()), 00089 actionCollection(), "exchange_delete"); 00090 QObject::connect(this,SIGNAL(enableIncidenceActions(bool)), 00091 action,SLOT(setEnabled(bool))); 00092 action->setEnabled( false ); 00093 00094 new KAction(i18n("Configure..."), 0, this, SLOT(configure()), 00095 actionCollection(), "exchange_configure"); 00096 00097 connect( this, SIGNAL( calendarChanged() ), mainWindow()->view(), SLOT( updateView() ) ); 00098 connect( this, SIGNAL( calendarChanged(const QDate &, const QDate &)), 00099 mainWindow()->view(), SLOT(updateView(const QDate &, const QDate &)) ); 00100 } 00101 00102 Exchange::~Exchange() 00103 { 00104 kdDebug(5850) << "Exchange Plugin destructor" << endl; 00105 } 00106 00107 QString Exchange::info() 00108 { 00109 return i18n("This plugin imports and export calendar events from/to a Microsoft Exchange 2000 Server."); 00110 } 00111 00112 void Exchange::slotIncidenceSelected( Incidence *incidence ) 00113 { 00114 emit enableIncidenceActions( incidence != 0 ); 00115 } 00116 00117 void Exchange::download() 00118 { 00119 ExchangeDialog dialog( mainWindow()->view()->startDate(), mainWindow()->view()->endDate() ); 00120 00121 if (dialog.exec() != QDialog::Accepted ) 00122 return; 00123 00124 QDate start = dialog.m_start->date(); 00125 QDate end = dialog.m_end->date(); 00126 00127 KCal::Calendar* calendar = mainWindow()->view()->calendar(); 00128 00129 int result = mClient->downloadSynchronous(calendar, start, end, true ); 00130 00131 if ( result == KPIM::ExchangeClient::ResultOK ) 00132 emit calendarChanged(); 00133 else 00134 showError( result, mClient->detailedErrorString() ); 00135 00136 } 00137 00138 void Exchange::upload() 00139 { 00140 kdDebug(5850) << "Called Exchange::upload()" << endl; 00141 00142 Event* event = static_cast<Event *> ( mainWindow()->view()->currentSelection() ); 00143 if ( ! event ) 00144 { 00145 KMessageBox::information( 0L, i18n("Please select an appointment."), i18n("Exchange Plugin") ); 00146 return; 00147 } 00148 if ( KMessageBox::warningContinueCancel( 0L, i18n("Exchange Upload is EXPERIMENTAL, you may lose data on this appointment!"), i18n("Exchange Plugin"), i18n("&Upload") ) 00149 == KMessageBox::Continue ) { 00150 kdDebug(5850) << "Trying to add appointment " << event->summary() << endl; 00151 int result = mClient->uploadSynchronous( event ); 00152 if ( result != KPIM::ExchangeClient::ResultOK ) 00153 showError( result, mClient->detailedErrorString() ); 00154 } 00155 } 00156 00157 void Exchange::remove() 00158 { 00159 kdDebug(5850) << "Called Exchange::remove()" << endl; 00160 00161 Event* event = static_cast<Event *> ( mainWindow()->view()->currentSelection() ); 00162 if ( ! event ) 00163 { 00164 KMessageBox::information( 0L, i18n("Please select an appointment."), i18n("Exchange Plugin") ); 00165 return; 00166 } 00167 00168 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") ) 00169 == KMessageBox::Continue ) { 00170 kdDebug(5850) << "Trying to delete appointment " << event->summary() << endl; 00171 int result = mClient->removeSynchronous( event ); 00172 00173 if ( result == KPIM::ExchangeClient::ResultOK ) { 00174 mainWindow()->view()->calendar()->deleteEvent( event ); 00175 emit calendarChanged(); 00176 } else 00177 showError( result, mClient->detailedErrorString() ); 00178 } 00179 } 00180 00181 void Exchange::configure() 00182 { 00183 kdDebug(5850) << "Exchange::configure" << endl; 00184 ExchangeConfig dialog( mAccount ); 00185 00186 if (dialog.exec() == QDialog::Accepted ) 00187 mAccount->save( "Calendar/Exchange Plugin" ); 00188 } 00189 00190 void Exchange::showError( int error, const QString& moreInfo /* = QString::null */ ) 00191 { 00192 QString errorText; 00193 switch( error ) { 00194 case KPIM::ExchangeClient::ResultOK: 00195 errorText = i18n( "No Error" ); 00196 break; 00197 case KPIM::ExchangeClient::CommunicationError: 00198 errorText = i18n( "The Exchange server could not be reached or returned an error." ); 00199 break; 00200 case KPIM::ExchangeClient::ServerResponseError: 00201 errorText = i18n( "Server response could not be interpreted." ); 00202 break; 00203 case KPIM::ExchangeClient::IllegalAppointmentError: 00204 errorText = i18n( "Appointment data could not be interpreted." ); 00205 break; 00206 case KPIM::ExchangeClient::NonEventError: 00207 errorText = i18n( "This should not happen: trying to upload wrong type of event." ); 00208 break; 00209 case KPIM::ExchangeClient::EventWriteError: 00210 errorText = i18n( "An error occurred trying to write an appointment to the server." ); 00211 break; 00212 case KPIM::ExchangeClient::DeleteUnknownEventError: 00213 errorText = i18n( "Trying to delete an event that is not present on the server." ); 00214 break; 00215 case KPIM::ExchangeClient::UnknownError: 00216 default: 00217 errorText = i18n( "Unknown Error" ); 00218 } 00219 00220 if ( error != KPIM::ExchangeClient::ResultOK ) { 00221 if ( moreInfo.isNull() ) 00222 KMessageBox::error( mainWindow()->topLevelWidget(), errorText, i18n( "Exchange Plugin" ) ); 00223 else 00224 KMessageBox::detailedError( mainWindow()->topLevelWidget(), errorText, moreInfo, i18n( "Exchange Plugin" ) ); 00225 } 00226 } 00227 00228 void Exchange::test() 00229 { 00230 kdDebug(5850) << "Entering test()" << endl; 00231 mClient->test(); 00232 } 00233 00234 void Exchange::test2() 00235 { 00236 kdDebug(5850) << "Entering test2()" << endl; 00237 } 00238 #include "exchange.moc"
KDE Logo
This file is part of the documentation for korganizer Library Version 3.3.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Fri Oct 1 15:19:30 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003