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.
251 lines
6.0 KiB
251 lines
6.0 KiB
15 years ago
|
/*
|
||
|
This file is part of KDE.
|
||
|
|
||
|
Copyright (c) 2004 Cornelius Schumacher <schumacher@kde.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 "opengroupware.h"
|
||
|
#include "webdavhandler.h"
|
||
|
|
||
|
#include <kdebug.h>
|
||
|
#include <kurl.h>
|
||
12 years ago
|
#include <tdeio/job.h>
|
||
|
#include <tdeio/davjob.h>
|
||
12 years ago
|
#include <tdelocale.h>
|
||
15 years ago
|
|
||
12 years ago
|
#include <libtdepim/tdeabcresourcecached.h>
|
||
15 years ago
|
|
||
|
#include <libkcal/freebusy.h>
|
||
|
#include <libkcal/icalformat.h>
|
||
|
#include <libkcal/scheduler.h>
|
||
|
#include <libkcal/calendarlocal.h>
|
||
|
|
||
12 years ago
|
#include <tdeabc/vcardconverter.h>
|
||
15 years ago
|
|
||
|
#include <kinstance.h>
|
||
|
#include <kdebug.h>
|
||
12 years ago
|
#include <tdelocale.h>
|
||
|
#include <tdetempfile.h>
|
||
15 years ago
|
|
||
|
#include <sys/types.h>
|
||
|
#include <unistd.h>
|
||
|
#include <stdlib.h>
|
||
|
|
||
13 years ago
|
#include <tdepimmacros.h>
|
||
15 years ago
|
|
||
12 years ago
|
namespace TDEABC {
|
||
15 years ago
|
|
||
|
class ResourceMemory : public ResourceCached
|
||
|
{
|
||
|
public:
|
||
|
ResourceMemory() : ResourceCached( 0 ) {}
|
||
|
|
||
|
Ticket *requestSaveTicket() { return 0; }
|
||
|
bool load() { return true; }
|
||
|
bool save( Ticket * ) { return true; }
|
||
|
void releaseSaveTicket( Ticket * ) {}
|
||
|
};
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
extern "C" {
|
||
|
KDE_EXPORT int kdemain( int argc, char **argv );
|
||
|
}
|
||
|
|
||
|
int kdemain( int argc, char **argv )
|
||
|
{
|
||
12 years ago
|
TDEInstance instance( "tdeio_OpenGroupware" );
|
||
15 years ago
|
|
||
12 years ago
|
kdDebug(7000) << "Starting tdeio_OpenGroupware(pid: " << getpid() << ")" << endl;
|
||
15 years ago
|
|
||
|
if (argc != 4) {
|
||
12 years ago
|
fprintf( stderr, "Usage: tdeio_OpenGroupware protocol domain-socket1 domain-socket2\n");
|
||
15 years ago
|
exit( -1 );
|
||
|
}
|
||
|
|
||
|
OpenGroupware slave( argv[1], argv[2], argv[3] );
|
||
|
slave.dispatchLoop();
|
||
|
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
14 years ago
|
OpenGroupware::OpenGroupware( const TQCString &protocol, const TQCString &pool,
|
||
|
const TQCString &app )
|
||
15 years ago
|
: SlaveBase( protocol, pool, app )
|
||
|
{
|
||
|
}
|
||
|
|
||
|
void OpenGroupware::get( const KURL &url )
|
||
|
{
|
||
|
kdDebug(7000) << "OpenGroupware::get()" << endl;
|
||
|
kdDebug(7000) << " URL: " << url.url() << endl;
|
||
|
#if 1
|
||
|
kdDebug(7000) << " Path: " << url.path() << endl;
|
||
|
kdDebug(7000) << " Query: " << url.query() << endl;
|
||
|
kdDebug(7000) << " Protocol: " << url.protocol() << endl;
|
||
|
kdDebug(7000) << " Filename: " << url.filename() << endl;
|
||
|
#endif
|
||
|
|
||
|
mimeType( "text/plain" );
|
||
|
|
||
14 years ago
|
TQString path = url.path();
|
||
15 years ago
|
debugMessage( "Path: " + path );
|
||
|
|
||
|
if ( path.startsWith( "/freebusy/" ) ) {
|
||
|
getFreeBusy( url );
|
||
|
} else if ( path.startsWith( "/calendar/" ) ) {
|
||
|
getCalendar( url );
|
||
|
} else if ( path.startsWith( "/addressbook/" ) ) {
|
||
|
getAddressbook( url );
|
||
|
} else {
|
||
14 years ago
|
TQString error = i18n("Unknown path. Known paths are '/freebusy/', "
|
||
15 years ago
|
"'/calendar/' and '/addressbook/'.");
|
||
|
errorMessage( error );
|
||
|
}
|
||
|
|
||
|
kdDebug(7000) << "OpenGroupwareCgiProtocol::get() done" << endl;
|
||
|
}
|
||
|
|
||
|
void OpenGroupware::getFreeBusy( const KURL &url )
|
||
|
{
|
||
14 years ago
|
TQString file = url.filename();
|
||
15 years ago
|
if ( file.right( 4 ) != ".ifb" ) {
|
||
14 years ago
|
TQString error = i18n("Illegal filename. File has to have '.ifb' suffix.");
|
||
15 years ago
|
errorMessage( error );
|
||
|
} else {
|
||
14 years ago
|
TQString email = file.left( file.length() - 4 );
|
||
15 years ago
|
debugMessage( "Email: " + email );
|
||
|
|
||
14 years ago
|
TQString user = url.user();
|
||
|
TQString pass = url.pass();
|
||
15 years ago
|
|
||
|
debugMessage( "URL: " );
|
||
|
debugMessage( "User: " + user );
|
||
|
debugMessage( "Password: " + pass );
|
||
|
|
||
|
KCal::FreeBusy *fb = new KCal::FreeBusy;
|
||
|
|
||
|
if ( user.isEmpty() || pass.isEmpty() ) {
|
||
|
errorMessage( i18n("Need username and password.") );
|
||
|
} else {
|
||
|
// FIXME get from server
|
||
|
|
||
|
// FIXME: Read range from configuration or URL parameters.
|
||
13 years ago
|
TQDate start = TQDate::currentDate().addDays( -3 );
|
||
|
TQDate end = TQDate::currentDate().addDays( 60 );
|
||
15 years ago
|
|
||
|
fb->setDtStart( start );
|
||
|
fb->setDtEnd( end );
|
||
|
|
||
|
kdDebug() << "Login" << endl;
|
||
|
|
||
|
}
|
||
|
|
||
|
#if 0
|
||
14 years ago
|
TQDateTime s = TQDateTime( TQDate( 2004, 9, 27 ), TQTime( 10, 0 ) );
|
||
|
TQDateTime e = TQDateTime( TQDate( 2004, 9, 27 ), TQTime( 11, 0 ) );
|
||
15 years ago
|
|
||
|
fb->addPeriod( s, e );
|
||
|
#endif
|
||
|
|
||
|
KCal::ICalFormat format;
|
||
|
|
||
14 years ago
|
TQString ical = format.createScheduleMessage( fb, KCal::Scheduler::Publish );
|
||
15 years ago
|
|
||
|
data( ical.utf8() );
|
||
|
|
||
|
finished();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
void OpenGroupware::getCalendar( const KURL &_url )
|
||
|
{
|
||
|
|
||
|
KURL url( _url ); // we'll be changing it
|
||
14 years ago
|
TQString user = url.user();
|
||
|
TQString pass = url.pass();
|
||
15 years ago
|
|
||
14 years ago
|
TQDomDocument props = WebdavHandler::createAllPropsRequest();
|
||
15 years ago
|
|
||
|
debugMessage( "URL: " );
|
||
|
debugMessage( "User: " + user );
|
||
|
debugMessage( "Password: " + pass );
|
||
|
|
||
|
url.setProtocol( "webdav" );
|
||
|
url.setPath ( "/zidestore/dav/till/" );
|
||
|
|
||
|
kdDebug(7000) << "getCalendar: " << url.prettyURL() << endl;
|
||
|
|
||
|
// FIXME do progress handling
|
||
12 years ago
|
mListEventsJob = TDEIO::davPropFind( url, props, "0", false );
|
||
|
connect( mListEventsJob, TQT_SIGNAL( result( TDEIO::Job * ) ),
|
||
|
TQT_SLOT( slotGetCalendarListingResult( TDEIO::Job * ) ) );
|
||
15 years ago
|
}
|
||
|
|
||
|
void OpenGroupware::getAddressbook( const KURL &url )
|
||
|
{
|
||
|
|
||
|
}
|
||
|
|
||
14 years ago
|
void OpenGroupware::errorMessage( const TQString &msg )
|
||
15 years ago
|
{
|
||
12 years ago
|
error( TDEIO::ERR_SLAVE_DEFINED, msg );
|
||
15 years ago
|
}
|
||
|
|
||
14 years ago
|
void OpenGroupware::debugMessage( const TQString &msg )
|
||
15 years ago
|
{
|
||
|
#if 0
|
||
|
data( ( msg + "\n" ).utf8() );
|
||
|
#else
|
||
|
Q_UNUSED( msg );
|
||
|
#endif
|
||
|
}
|
||
|
|
||
|
|
||
12 years ago
|
void OpenGroupware::slotGetCalendarListingResult( TDEIO::Job *job )
|
||
15 years ago
|
{
|
||
|
|
||
|
kdDebug(7000) << k_funcinfo << endl;
|
||
|
|
||
|
if ( job->error() ) {
|
||
|
job->showErrorDialog( 0 );
|
||
|
} else {
|
||
|
kdDebug() << "ResourceSlox::slotResult() success" << endl;
|
||
|
|
||
14 years ago
|
TQDomDocument doc = mListEventsJob->response();
|
||
15 years ago
|
|
||
|
}
|
||
|
KCal::ICalFormat format;
|
||
|
KCal::CalendarLocal calendar;
|
||
|
|
||
14 years ago
|
TQString ical = format.toString( &calendar );
|
||
15 years ago
|
|
||
|
data( ical.utf8() );
|
||
|
|
||
|
finished();
|
||
|
}
|
||
|
|
||
|
|
||
12 years ago
|
void OpenGroupware::slotGetCalendarResult( TDEIO::Job *job )
|
||
15 years ago
|
{
|
||
|
Q_UNUSED( job );
|
||
|
}
|
||
|
#include "opengroupware.moc"
|
||
|
|