TDE personal information management applications
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

opengroupware.cpp 6.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. /*
  2. This file is part of KDE.
  3. Copyright (c) 2004 Cornelius Schumacher <schumacher@kde.org>
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  15. */
  16. #include "opengroupware.h"
  17. #include "webdavhandler.h"
  18. #include <kdebug.h>
  19. #include <kurl.h>
  20. #include <kio/job.h>
  21. #include <kio/davjob.h>
  22. #include <klocale.h>
  23. #include <libtdepim/kabcresourcecached.h>
  24. #include <libkcal/freebusy.h>
  25. #include <libkcal/icalformat.h>
  26. #include <libkcal/scheduler.h>
  27. #include <libkcal/calendarlocal.h>
  28. #include <kabc/vcardconverter.h>
  29. #include <kinstance.h>
  30. #include <kdebug.h>
  31. #include <klocale.h>
  32. #include <ktempfile.h>
  33. #include <sys/types.h>
  34. #include <unistd.h>
  35. #include <stdlib.h>
  36. #include <kdepimmacros.h>
  37. namespace KABC {
  38. class ResourceMemory : public ResourceCached
  39. {
  40. public:
  41. ResourceMemory() : ResourceCached( 0 ) {}
  42. Ticket *requestSaveTicket() { return 0; }
  43. bool load() { return true; }
  44. bool save( Ticket * ) { return true; }
  45. void releaseSaveTicket( Ticket * ) {}
  46. };
  47. }
  48. extern "C" {
  49. KDE_EXPORT int kdemain( int argc, char **argv );
  50. }
  51. int kdemain( int argc, char **argv )
  52. {
  53. KInstance instance( "kio_OpenGroupware" );
  54. kdDebug(7000) << "Starting kio_OpenGroupware(pid: " << getpid() << ")" << endl;
  55. if (argc != 4) {
  56. fprintf( stderr, "Usage: kio_OpenGroupware protocol domain-socket1 domain-socket2\n");
  57. exit( -1 );
  58. }
  59. OpenGroupware slave( argv[1], argv[2], argv[3] );
  60. slave.dispatchLoop();
  61. return 0;
  62. }
  63. OpenGroupware::OpenGroupware( const TQCString &protocol, const TQCString &pool,
  64. const TQCString &app )
  65. : SlaveBase( protocol, pool, app )
  66. {
  67. }
  68. void OpenGroupware::get( const KURL &url )
  69. {
  70. kdDebug(7000) << "OpenGroupware::get()" << endl;
  71. kdDebug(7000) << " URL: " << url.url() << endl;
  72. #if 1
  73. kdDebug(7000) << " Path: " << url.path() << endl;
  74. kdDebug(7000) << " Query: " << url.query() << endl;
  75. kdDebug(7000) << " Protocol: " << url.protocol() << endl;
  76. kdDebug(7000) << " Filename: " << url.filename() << endl;
  77. #endif
  78. mimeType( "text/plain" );
  79. TQString path = url.path();
  80. debugMessage( "Path: " + path );
  81. if ( path.startsWith( "/freebusy/" ) ) {
  82. getFreeBusy( url );
  83. } else if ( path.startsWith( "/calendar/" ) ) {
  84. getCalendar( url );
  85. } else if ( path.startsWith( "/addressbook/" ) ) {
  86. getAddressbook( url );
  87. } else {
  88. TQString error = i18n("Unknown path. Known paths are '/freebusy/', "
  89. "'/calendar/' and '/addressbook/'.");
  90. errorMessage( error );
  91. }
  92. kdDebug(7000) << "OpenGroupwareCgiProtocol::get() done" << endl;
  93. }
  94. void OpenGroupware::getFreeBusy( const KURL &url )
  95. {
  96. TQString file = url.filename();
  97. if ( file.right( 4 ) != ".ifb" ) {
  98. TQString error = i18n("Illegal filename. File has to have '.ifb' suffix.");
  99. errorMessage( error );
  100. } else {
  101. TQString email = file.left( file.length() - 4 );
  102. debugMessage( "Email: " + email );
  103. TQString user = url.user();
  104. TQString pass = url.pass();
  105. debugMessage( "URL: " );
  106. debugMessage( "User: " + user );
  107. debugMessage( "Password: " + pass );
  108. KCal::FreeBusy *fb = new KCal::FreeBusy;
  109. if ( user.isEmpty() || pass.isEmpty() ) {
  110. errorMessage( i18n("Need username and password.") );
  111. } else {
  112. // FIXME get from server
  113. // FIXME: Read range from configuration or URL parameters.
  114. TQDate start = TQDate::tqcurrentDate().addDays( -3 );
  115. TQDate end = TQDate::tqcurrentDate().addDays( 60 );
  116. fb->setDtStart( start );
  117. fb->setDtEnd( end );
  118. kdDebug() << "Login" << endl;
  119. }
  120. #if 0
  121. TQDateTime s = TQDateTime( TQDate( 2004, 9, 27 ), TQTime( 10, 0 ) );
  122. TQDateTime e = TQDateTime( TQDate( 2004, 9, 27 ), TQTime( 11, 0 ) );
  123. fb->addPeriod( s, e );
  124. #endif
  125. KCal::ICalFormat format;
  126. TQString ical = format.createScheduleMessage( fb, KCal::Scheduler::Publish );
  127. data( ical.utf8() );
  128. finished();
  129. }
  130. }
  131. void OpenGroupware::getCalendar( const KURL &_url )
  132. {
  133. KURL url( _url ); // we'll be changing it
  134. TQString user = url.user();
  135. TQString pass = url.pass();
  136. TQDomDocument props = WebdavHandler::createAllPropsRequest();
  137. debugMessage( "URL: " );
  138. debugMessage( "User: " + user );
  139. debugMessage( "Password: " + pass );
  140. url.setProtocol( "webdav" );
  141. url.setPath ( "/zidestore/dav/till/" );
  142. kdDebug(7000) << "getCalendar: " << url.prettyURL() << endl;
  143. // FIXME do progress handling
  144. mListEventsJob = KIO::davPropFind( url, props, "0", false );
  145. connect( mListEventsJob, TQT_SIGNAL( result( KIO::Job * ) ),
  146. TQT_SLOT( slotGetCalendarListingResult( KIO::Job * ) ) );
  147. }
  148. void OpenGroupware::getAddressbook( const KURL &url )
  149. {
  150. }
  151. void OpenGroupware::errorMessage( const TQString &msg )
  152. {
  153. error( KIO::ERR_SLAVE_DEFINED, msg );
  154. }
  155. void OpenGroupware::debugMessage( const TQString &msg )
  156. {
  157. #if 0
  158. data( ( msg + "\n" ).utf8() );
  159. #else
  160. Q_UNUSED( msg );
  161. #endif
  162. }
  163. void OpenGroupware::slotGetCalendarListingResult( KIO::Job *job )
  164. {
  165. kdDebug(7000) << k_funcinfo << endl;
  166. if ( job->error() ) {
  167. job->showErrorDialog( 0 );
  168. } else {
  169. kdDebug() << "ResourceSlox::slotResult() success" << endl;
  170. TQDomDocument doc = mListEventsJob->response();
  171. }
  172. KCal::ICalFormat format;
  173. KCal::CalendarLocal calendar;
  174. TQString ical = format.toString( &calendar );
  175. data( ical.utf8() );
  176. finished();
  177. }
  178. void OpenGroupware::slotGetCalendarResult( KIO::Job *job )
  179. {
  180. Q_UNUSED( job );
  181. }
  182. #include "opengroupware.moc"