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.
305 lines
7.2 KiB
305 lines
7.2 KiB
15 years ago
|
/*
|
||
13 years ago
|
This file is part of tdepim.
|
||
15 years ago
|
|
||
|
Copyright (c) 2004 Cornelius Schumacher <schumacher@kde.org>
|
||
|
|
||
|
This library is free software; you can redistribute it and/or
|
||
|
modify it under the terms of the GNU Library General Public
|
||
|
License as published by the Free Software Foundation; either
|
||
|
version 2 of the License, or (at your option) any later version.
|
||
|
|
||
|
This library 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
|
||
|
Library General Public License for more details.
|
||
|
|
||
|
You should have received a copy of the GNU Library General Public License
|
||
|
along with this library; see the file COPYING.LIB. If not, write to
|
||
|
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||
|
Boston, MA 02110-1301, USA.
|
||
|
*/
|
||
|
|
||
|
#include "kcal_resourcegroupware.h"
|
||
|
|
||
|
#include "kcal_groupwareprefsbase.h"
|
||
|
#include "kcal_resourcegroupwareconfig.h"
|
||
|
|
||
|
#include <libkcal/confirmsavedialog.h>
|
||
|
#include <libkcal/icalformat.h>
|
||
|
#include <libkcal/calendarlocal.h>
|
||
|
|
||
15 years ago
|
#include <tqapplication.h>
|
||
|
#include <tqdatetime.h>
|
||
|
#include <tqptrlist.h>
|
||
|
#include <tqstringlist.h>
|
||
|
#include <tqtimer.h>
|
||
15 years ago
|
|
||
|
#include <kabc/locknull.h>
|
||
|
#include <kdebug.h>
|
||
|
#include <klocale.h>
|
||
12 years ago
|
#include <tderesources/configwidget.h>
|
||
15 years ago
|
#include <kstandarddirs.h>
|
||
|
#include <kstringhandler.h>
|
||
|
#include <kurl.h>
|
||
13 years ago
|
#include <libtdepim/kpimprefs.h>
|
||
|
#include <libtdepim/groupwarejob.h>
|
||
15 years ago
|
|
||
|
using namespace KCal;
|
||
|
|
||
|
ResourceGroupware::ResourceGroupware()
|
||
|
: ResourceCached( 0 ), mLock( true ),
|
||
|
mProgress( 0 )
|
||
|
{
|
||
|
init();
|
||
|
|
||
|
mPrefs->addGroupPrefix( identifier() );
|
||
|
}
|
||
|
|
||
12 years ago
|
ResourceGroupware::ResourceGroupware( const TDEConfig *config )
|
||
15 years ago
|
: ResourceCached( config ), mLock( true )
|
||
|
{
|
||
|
init();
|
||
|
|
||
|
mPrefs->addGroupPrefix( identifier() );
|
||
|
|
||
14 years ago
|
if ( config ) {
|
||
|
readConfig( config );
|
||
|
} else {
|
||
|
setResourceName( i18n( "Groupware Server" ) );
|
||
|
}
|
||
15 years ago
|
}
|
||
|
|
||
|
ResourceGroupware::~ResourceGroupware()
|
||
|
{
|
||
|
disableChangeNotification();
|
||
|
|
||
|
delete mPrefs;
|
||
|
mPrefs = 0;
|
||
|
}
|
||
|
|
||
|
void ResourceGroupware::init()
|
||
|
{
|
||
|
mDownloadJob = 0;
|
||
|
mProgress = 0;
|
||
|
|
||
|
mIsShowingError = false;
|
||
|
|
||
|
mPrefs = new GroupwarePrefsBase();
|
||
|
|
||
|
setType( "groupware" );
|
||
|
|
||
|
enableChangeNotification();
|
||
|
}
|
||
|
|
||
|
GroupwarePrefsBase *ResourceGroupware::prefs()
|
||
|
{
|
||
|
return mPrefs;
|
||
|
}
|
||
|
|
||
12 years ago
|
void ResourceGroupware::readConfig( const TDEConfig *config )
|
||
15 years ago
|
{
|
||
|
kdDebug() << "KCal::ResourceGroupware::readConfig()" << endl;
|
||
|
|
||
|
mPrefs->readConfig();
|
||
|
|
||
|
ResourceCached::readConfig( config );
|
||
|
}
|
||
|
|
||
12 years ago
|
void ResourceGroupware::writeConfig( TDEConfig *config )
|
||
15 years ago
|
{
|
||
|
kdDebug() << "KCal::ResourceGroupware::writeConfig()" << endl;
|
||
|
|
||
|
ResourceCalendar::writeConfig( config );
|
||
|
|
||
|
mPrefs->writeConfig();
|
||
|
|
||
|
ResourceCached::writeConfig( config );
|
||
|
}
|
||
|
|
||
|
bool ResourceGroupware::doOpen()
|
||
|
{
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
void ResourceGroupware::doClose()
|
||
|
{
|
||
|
ResourceCached::doClose();
|
||
|
}
|
||
|
|
||
|
bool ResourceGroupware::doLoad()
|
||
|
{
|
||
|
kdDebug() << "ResourceGroupware::load()" << endl;
|
||
|
|
||
|
if ( mIsShowingError ) {
|
||
|
kdDebug() << "Still showing error" << endl;
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
if ( mDownloadJob ) {
|
||
|
kdWarning() << "Download still in progress" << endl;
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
mCalendar.close();
|
||
|
|
||
|
disableChangeNotification();
|
||
|
loadCache();
|
||
|
enableChangeNotification();
|
||
|
|
||
|
emit resourceChanged( this );
|
||
|
|
||
|
clearChanges();
|
||
|
|
||
|
KURL url( prefs()->url() );
|
||
|
url.setUser( prefs()->user() );
|
||
|
url.setPass( prefs()->password() );
|
||
|
|
||
|
kdDebug() << "Download URL: " << url << endl;
|
||
|
|
||
14 years ago
|
mJobData = TQString();
|
||
15 years ago
|
|
||
|
mDownloadJob = KPIM::GroupwareJob::getCalendar( url );
|
||
12 years ago
|
connect( mDownloadJob, TQT_SIGNAL( result( TDEIO::Job * ) ),
|
||
|
TQT_SLOT( slotJobResult( TDEIO::Job * ) ) );
|
||
|
connect( mDownloadJob, TQT_SIGNAL( data( TDEIO::Job *, const TQByteArray & ) ),
|
||
|
TQT_SLOT( slotJobData( TDEIO::Job *, const TQByteArray & ) ) );
|
||
15 years ago
|
|
||
|
mProgress = KPIM::ProgressManager::instance()->createProgressItem(
|
||
|
KPIM::ProgressManager::getUniqueID(), i18n("Downloading calendar") );
|
||
|
connect( mProgress,
|
||
15 years ago
|
TQT_SIGNAL( progressItemCanceled( KPIM::ProgressItem * ) ),
|
||
|
TQT_SLOT( cancelLoad() ) );
|
||
15 years ago
|
|
||
|
return true;
|
||
|
}
|
||
|
|
||
12 years ago
|
void ResourceGroupware::slotJobResult( TDEIO::Job *job )
|
||
15 years ago
|
{
|
||
|
kdDebug() << "ResourceGroupware::slotJobResult(): " << endl;
|
||
|
|
||
|
if ( job->error() ) {
|
||
|
mIsShowingError = true;
|
||
|
loadError( job->errorString() );
|
||
|
mIsShowingError = false;
|
||
|
} else {
|
||
|
disableChangeNotification();
|
||
|
|
||
|
clearCache();
|
||
|
|
||
|
// FIXME: This does not take into account the time zone!
|
||
|
CalendarLocal calendar;
|
||
|
ICalFormat ical;
|
||
|
if ( !ical.fromString( &calendar, mJobData ) ) {
|
||
|
loadError( i18n("Error parsing calendar data.") );
|
||
|
} else {
|
||
|
Incidence::List incidences = calendar.incidences();
|
||
|
Incidence::List::ConstIterator it;
|
||
|
for( it = incidences.begin(); it != incidences.end(); ++it ) {
|
||
|
// kdDebug() << "INCIDENCE: " << (*it)->summary() << endl;
|
||
|
Incidence *i = (*it)->clone();
|
||
15 years ago
|
TQString remote = (*it)->customProperty( "GWRESOURCE", "UID" );
|
||
|
TQString local = idMapper().localId( remote );
|
||
15 years ago
|
if ( local.isEmpty() ) {
|
||
|
idMapper().setRemoteId( i->uid(), remote );
|
||
|
} else {
|
||
|
i->setUid( local );
|
||
|
}
|
||
|
addIncidence( i );
|
||
|
}
|
||
|
}
|
||
|
saveCache();
|
||
|
enableChangeNotification();
|
||
|
|
||
|
clearChanges();
|
||
|
|
||
|
emit resourceChanged( this );
|
||
|
emit resourceLoaded( this );
|
||
|
}
|
||
|
|
||
|
mDownloadJob = 0;
|
||
|
if ( mProgress ) mProgress->setComplete();
|
||
|
mProgress = 0;
|
||
|
}
|
||
|
|
||
12 years ago
|
void ResourceGroupware::slotJobData( TDEIO::Job *, const TQByteArray &data )
|
||
15 years ago
|
{
|
||
|
// kdDebug() << "ResourceGroupware::slotJobData()" << endl;
|
||
|
|
||
|
mJobData.append( data.data() );
|
||
|
}
|
||
|
|
||
|
void ResourceGroupware::loadFinished()
|
||
|
{
|
||
|
saveCache();
|
||
|
enableChangeNotification();
|
||
|
|
||
|
emit resourceChanged( this );
|
||
|
emit resourceLoaded( this );
|
||
|
}
|
||
|
|
||
|
bool ResourceGroupware::doSave()
|
||
|
{
|
||
|
kdDebug() << "KCal::ResourceGroupware::doSave()" << endl;
|
||
|
|
||
|
saveCache();
|
||
|
|
||
|
if ( !hasChanges() ) {
|
||
|
kdDebug() << "No changes" << endl;
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
if ( !confirmSave() ) return false;
|
||
|
|
||
|
#if 0
|
||
|
Incidence::List::ConstIterator it;
|
||
|
|
||
|
Incidence::List added = addedIncidences();
|
||
|
for( it = added.begin(); it != added.end(); ++it ) {
|
||
|
if ( mServer->addIncidence( *it, this ) ) {
|
||
|
clearChange( *it );
|
||
|
saveCache();
|
||
|
}
|
||
|
}
|
||
|
Incidence::List changed = changedIncidences();
|
||
|
for( it = changed.begin(); it != changed.end(); ++it ) {
|
||
|
if ( mServer->changeIncidence( *it ) ) clearChange( *it );
|
||
|
}
|
||
|
Incidence::List deleted = deletedIncidences();
|
||
|
for( it = deleted.begin(); it != deleted.end(); ++it ) {
|
||
|
if ( mServer->deleteIncidence( *it ) ) clearChange( *it );
|
||
|
}
|
||
|
#endif
|
||
|
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
// FIXME: Put this into ResourceCached
|
||
|
bool ResourceGroupware::confirmSave()
|
||
|
{
|
||
|
if ( !hasChanges() ) return true;
|
||
|
|
||
|
ConfirmSaveDialog dlg( resourceName(), 0 );
|
||
|
|
||
|
dlg.addIncidences( addedIncidences(), i18n("Added") );
|
||
|
dlg.addIncidences( changedIncidences(), i18n("Changed") );
|
||
|
dlg.addIncidences( deletedIncidences(), i18n("Deleted") );
|
||
|
|
||
|
int result = dlg.exec();
|
||
15 years ago
|
return result == TQDialog::Accepted;
|
||
15 years ago
|
}
|
||
|
|
||
|
KABC::Lock *ResourceGroupware::lock()
|
||
|
{
|
||
|
return &mLock;
|
||
|
}
|
||
|
|
||
|
void ResourceGroupware::cancelLoad()
|
||
|
{
|
||
|
if ( mDownloadJob ) mDownloadJob->kill();
|
||
|
mDownloadJob = 0;
|
||
|
if ( mProgress ) mProgress->setComplete();
|
||
|
mProgress = 0;
|
||
|
}
|
||
|
|
||
|
#include "kcal_resourcegroupware.moc"
|