kioslaves
opengroupware.cppGo to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "opengroupware.h"
00022 #include "webdavhandler.h"
00023
00024 #include <kdebug.h>
00025 #include <kurl.h>
00026 #include <kio/job.h>
00027 #include <kio/davjob.h>
00028 #include <klocale.h>
00029
00030 #include <libkdepim/kabcresourcecached.h>
00031
00032 #include <libkcal/freebusy.h>
00033 #include <libkcal/icalformat.h>
00034 #include <libkcal/scheduler.h>
00035 #include <libkcal/calendarlocal.h>
00036
00037 #include <kabc/vcardconverter.h>
00038
00039 #include <kinstance.h>
00040 #include <kdebug.h>
00041 #include <klocale.h>
00042 #include <ktempfile.h>
00043
00044 #include <sys/types.h>
00045 #include <unistd.h>
00046 #include <stdlib.h>
00047
00048 #include <kdepimmacros.h>
00049
00050 namespace KABC {
00051
00052 class ResourceMemory : public ResourceCached
00053 {
00054 public:
00055 ResourceMemory() : ResourceCached( 0 ) {}
00056
00057 Ticket *requestSaveTicket() { return 0; }
00058 bool load() { return true; }
00059 bool save( Ticket * ) { return true; }
00060 void releaseSaveTicket( Ticket * ) {}
00061 };
00062
00063 }
00064
00065
00066 extern "C" {
00067 KDE_EXPORT int kdemain( int argc, char **argv );
00068 }
00069
00070 int kdemain( int argc, char **argv )
00071 {
00072 KInstance instance( "kio_OpenGroupware" );
00073
00074 kdDebug(7000) << "Starting kio_OpenGroupware(pid: " << getpid() << ")" << endl;
00075
00076 if (argc != 4) {
00077 fprintf( stderr, "Usage: kio_OpenGroupware protocol domain-socket1 domain-socket2\n");
00078 exit( -1 );
00079 }
00080
00081 OpenGroupware slave( argv[1], argv[2], argv[3] );
00082 slave.dispatchLoop();
00083
00084 return 0;
00085 }
00086
00087 OpenGroupware::OpenGroupware( const QCString &protocol, const QCString &pool,
00088 const QCString &app )
00089 : SlaveBase( protocol, pool, app )
00090 {
00091 }
00092
00093 void OpenGroupware::get( const KURL &url )
00094 {
00095 kdDebug(7000) << "OpenGroupware::get()" << endl;
00096 kdDebug(7000) << " URL: " << url.url() << endl;
00097 #if 1
00098 kdDebug(7000) << " Path: " << url.path() << endl;
00099 kdDebug(7000) << " Query: " << url.query() << endl;
00100 kdDebug(7000) << " Protocol: " << url.protocol() << endl;
00101 kdDebug(7000) << " Filename: " << url.filename() << endl;
00102 #endif
00103
00104 mimeType( "text/plain" );
00105
00106 QString path = url.path();
00107 debugMessage( "Path: " + path );
00108
00109 if ( path.startsWith( "/freebusy/" ) ) {
00110 getFreeBusy( url );
00111 } else if ( path.startsWith( "/calendar/" ) ) {
00112 getCalendar( url );
00113 } else if ( path.startsWith( "/addressbook/" ) ) {
00114 getAddressbook( url );
00115 } else {
00116 QString error = i18n("Unknown path. Known paths are '/freebusy/', "
00117 "'/calendar/' and '/addressbook/'.");
00118 errorMessage( error );
00119 }
00120
00121 kdDebug(7000) << "OpenGroupwareCgiProtocol::get() done" << endl;
00122 }
00123
00124 void OpenGroupware::getFreeBusy( const KURL &url )
00125 {
00126 QString file = url.filename();
00127 if ( file.right( 4 ) != ".ifb" ) {
00128 QString error = i18n("Illegal filename. File has to have '.ifb' suffix.");
00129 errorMessage( error );
00130 } else {
00131 QString email = file.left( file.length() - 4 );
00132 debugMessage( "Email: " + email );
00133
00134 QString user = url.user();
00135 QString pass = url.pass();
00136
00137 debugMessage( "URL: " );
00138 debugMessage( "User: " + user );
00139 debugMessage( "Password: " + pass );
00140
00141 KCal::FreeBusy *fb = new KCal::FreeBusy;
00142
00143 if ( user.isEmpty() || pass.isEmpty() ) {
00144 errorMessage( i18n("Need username and password.") );
00145 } else {
00146
00147
00148
00149 QDate start = QDate::currentDate().addDays( -3 );
00150 QDate end = QDate::currentDate().addDays( 60 );
00151
00152 fb->setDtStart( start );
00153 fb->setDtEnd( end );
00154
00155 kdDebug() << "Login" << endl;
00156
00157 }
00158
00159 #if 0
00160 QDateTime s = QDateTime( QDate( 2004, 9, 27 ), QTime( 10, 0 ) );
00161 QDateTime e = QDateTime( QDate( 2004, 9, 27 ), QTime( 11, 0 ) );
00162
00163 fb->addPeriod( s, e );
00164 #endif
00165
00166 KCal::ICalFormat format;
00167
00168 QString ical = format.createScheduleMessage( fb, KCal::Scheduler::Publish );
00169
00170 data( ical.utf8() );
00171
00172 finished();
00173 }
00174 }
00175
00176
00177 void OpenGroupware::getCalendar( const KURL &_url )
00178 {
00179
00180 KURL url( _url );
00181 QString user = url.user();
00182 QString pass = url.pass();
00183
00184 QDomDocument props = WebdavHandler::createAllPropsRequest();
00185
00186 debugMessage( "URL: " );
00187 debugMessage( "User: " + user );
00188 debugMessage( "Password: " + pass );
00189
00190 url.setProtocol( "webdav" );
00191 url.setPath ( "/zidestore/dav/till/" );
00192
00193 kdDebug(7000) << "getCalendar: " << url.prettyURL() << endl;
00194
00195
00196 mListEventsJob = KIO::davPropFind( url, props, "0", false );
00197 connect( mListEventsJob, SIGNAL( result( KIO::Job * ) ),
00198 SLOT( slotGetCalendarListingResult( KIO::Job * ) ) );
00199 }
00200
00201 void OpenGroupware::getAddressbook( const KURL &url )
00202 {
00203
00204 }
00205
00206 void OpenGroupware::errorMessage( const QString &msg )
00207 {
00208 error( KIO::ERR_SLAVE_DEFINED, msg );
00209 }
00210
00211 void OpenGroupware::debugMessage( const QString &msg )
00212 {
00213 #if 0
00214 data( ( msg + "\n" ).utf8() );
00215 #else
00216 Q_UNUSED( msg );
00217 #endif
00218 }
00219
00220
00221 void OpenGroupware::slotGetCalendarListingResult( KIO::Job *job )
00222 {
00223
00224 kdDebug(7000) << k_funcinfo << endl;
00225
00226 if ( job->error() ) {
00227 job->showErrorDialog( 0 );
00228 } else {
00229 kdDebug() << "ResourceSlox::slotResult() success" << endl;
00230
00231 QDomDocument doc = mListEventsJob->response();
00232
00233 }
00234 KCal::ICalFormat format;
00235 KCal::CalendarLocal calendar;
00236
00237 QString ical = format.toString( &calendar );
00238
00239 data( ical.utf8() );
00240
00241 finished();
00242 }
00243
00244
00245 void OpenGroupware::slotGetCalendarResult( KIO::Job *job )
00246 {
00247 Q_UNUSED( job );
00248 }
00249 #include "opengroupware.moc"
00250
|