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.
260 lines
7.7 KiB
260 lines
7.7 KiB
15 years ago
|
/*
|
||
13 years ago
|
This file is part of tdepim.
|
||
15 years ago
|
|
||
|
Copyright (c) 2005 Reinhold Kainhofer <reinhold@kainhofer.com>
|
||
|
|
||
|
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 "bloggingcalendaradaptor.h"
|
||
|
#include "bloggingglobals.h"
|
||
|
#include <libemailfunctions/idmapper.h>
|
||
|
#include <folderlister.h>
|
||
|
|
||
|
#include <libkcal/calendarlocal.h>
|
||
|
#include <libkcal/icalformat.h>
|
||
|
#include <libkcal/resourcecached.h>
|
||
|
|
||
|
#include <kdebug.h>
|
||
|
|
||
|
using namespace KCal;
|
||
|
|
||
|
// That terribly long app key was generated at
|
||
|
// http://www.blogger.com/developers/api/1_docs/register.html
|
||
|
// for the "KDE-Pim libkcal blogging resource".
|
||
|
// TODO:
|
||
15 years ago
|
/*TQString BloggingCalendarAdaptor::mAppID =
|
||
|
TQString("20ffffffd7ffffffc5ffffffbdffffff87ffffffb72d39fffffffe5c4bfffff"
|
||
15 years ago
|
"fcfffffff80ffffffd4665cfffffff375ffffff88ffffff871a0cffffff8029");
|
||
|
*/
|
||
|
|
||
|
|
||
|
BloggingUploadItem::BloggingUploadItem( KBlog::APIBlog *api, CalendarAdaptor *adaptor, KCal::Incidence *incidence, KPIM::GroupwareUploadItem::UploadType type )
|
||
|
: GroupwareUploadItem( type ), mPosting( 0 ), mAPI( 0 )
|
||
|
{
|
||
|
Journal* j = dynamic_cast<Journal*>( incidence );
|
||
|
if ( api && j && adaptor ) {
|
||
|
mItemType = KPIM::FolderLister::Journal;
|
||
|
|
||
|
setUrl( j->customProperty( adaptor->identifier(), "storagelocation" ) );
|
||
|
setUid( j->uid() );
|
||
|
|
||
|
mPosting = api->postingFromJournal( j );
|
||
|
mAPI = api;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
BloggingUploadItem::~BloggingUploadItem()
|
||
|
{
|
||
|
delete mPosting;
|
||
|
}
|
||
|
|
||
12 years ago
|
TDEIO::TransferJob *BloggingUploadItem::createUploadJob( KPIM::GroupwareDataAdaptor *adaptor, const KURL &baseurl )
|
||
15 years ago
|
{
|
||
|
kdDebug()<<"BloggingUploadItem::createUploadJob, adaptor="<<adaptor<<", URL="<<baseurl.url()<<endl;
|
||
|
Q_ASSERT( adaptor );
|
||
|
if ( !adaptor || !mAPI ) return 0;
|
||
|
kdDebug() << "Uploading to: " << url().prettyURL() << endl;
|
||
|
mAPI->setURL( baseurl );
|
||
|
return mAPI->createUploadJob( url(), mPosting );
|
||
|
}
|
||
|
|
||
12 years ago
|
TDEIO::TransferJob *BloggingUploadItem::createUploadNewJob( KPIM::GroupwareDataAdaptor *adaptor, const KURL &baseurl )
|
||
15 years ago
|
{
|
||
|
kdDebug()<<"BloggingUploadItem::createUploadNewJob"<<endl;
|
||
|
Q_ASSERT( adaptor );
|
||
|
if ( !adaptor || !mAPI ) return 0;
|
||
|
kdDebug() << "Uploading new item to: " << baseurl.prettyURL() << endl;
|
||
|
mAPI->setURL( baseurl );
|
||
|
return mAPI->createUploadNewJob( mPosting );
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
BloggingCalendarAdaptor::BloggingCalendarAdaptor() : mAPI( 0 ), mAuthenticated( false )
|
||
|
{
|
||
|
}
|
||
|
|
||
|
|
||
|
KBlog::APIBlog *BloggingCalendarAdaptor::api() const
|
||
|
{
|
||
|
return mAPI;
|
||
|
}
|
||
|
|
||
|
void BloggingCalendarAdaptor::setAPI( KBlog::APIBlog *api )
|
||
|
{
|
||
|
delete mAPI;
|
||
|
mAPI = api;
|
||
|
mAuthenticated = false;
|
||
15 years ago
|
connect( api, TQT_SIGNAL( userInfoRetrieved( const TQString &, const TQString &,
|
||
|
const TQString & ) ),
|
||
|
TQT_SLOT( slotUserInfoRetrieved( const TQString &, const TQString &,
|
||
|
const TQString & ) ) );
|
||
|
connect( api, TQT_SIGNAL( folderInfoRetrieved( const TQString &, const TQString & ) ),
|
||
|
TQT_SLOT( slotFolderInfoRetrieved( const TQString&, const TQString & ) ) );
|
||
|
connect( api, TQT_SIGNAL( itemOnServer( const KURL & ) ),
|
||
|
TQT_SIGNAL( itemOnServer( const KURL & ) ) );
|
||
|
connect( api, TQT_SIGNAL( itemDownloaded( KCal::Incidence *, const TQString &,
|
||
|
const KURL &, const TQString &, const TQString & ) ),
|
||
|
TQT_SLOT( calendarItemDownloaded( KCal::Incidence *, const TQString &,
|
||
|
const KURL &, const TQString &, const TQString & ) ) );
|
||
15 years ago
|
|
||
|
}
|
||
|
|
||
|
KPIM::GroupwareUploadItem *BloggingCalendarAdaptor::newUploadItem( KCal::Incidence*it,
|
||
|
KPIM::GroupwareUploadItem::UploadType type )
|
||
|
{
|
||
|
return new BloggingUploadItem( mAPI, this, it, type );
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
15 years ago
|
void BloggingCalendarAdaptor::slotFolderInfoRetrieved( const TQString &id, const TQString &name )
|
||
15 years ago
|
{
|
||
|
emit folderInfoRetrieved( KURL(id), name, KPIM::FolderLister::Journal );
|
||
|
}
|
||
|
|
||
15 years ago
|
void BloggingCalendarAdaptor::slotUserInfoRetrieved( const TQString &/*nick*/,
|
||
|
const TQString &/*user*/, const TQString &/*email*/ )
|
||
15 years ago
|
{
|
||
|
kdDebug() << "BloggingCalendarAdaptor::slotUserInfoRetrieved"<<endl;
|
||
|
mAuthenticated = true;
|
||
|
}
|
||
|
|
||
|
void BloggingCalendarAdaptor::setBaseURL( const KURL &url )
|
||
|
{
|
||
|
if ( mAPI ) {
|
||
|
mAPI->setURL( url );
|
||
|
}
|
||
|
}
|
||
|
|
||
15 years ago
|
void BloggingCalendarAdaptor::setUser( const TQString &user )
|
||
15 years ago
|
{
|
||
|
CalendarAdaptor::setUser( user );
|
||
|
if ( mAPI ) {
|
||
|
mAPI->setUsername( user );
|
||
|
}
|
||
|
}
|
||
|
|
||
15 years ago
|
void BloggingCalendarAdaptor::setPassword( const TQString &password )
|
||
15 years ago
|
{
|
||
|
CalendarAdaptor::setPassword( password );
|
||
|
if ( mAPI ) {
|
||
|
mAPI->setPassword( password );
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void BloggingCalendarAdaptor::setUserPassword( KURL & )
|
||
|
{
|
||
|
kdDebug(5800) << "BloggingCalendarAdaptor::setUserPassword" << endl;
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
12 years ago
|
TDEIO::Job *BloggingCalendarAdaptor::createLoginJob( const KURL &url,
|
||
15 years ago
|
const TQString &user,
|
||
|
const TQString &password )
|
||
15 years ago
|
{
|
||
|
if ( mAPI ) {
|
||
|
mAPI->setURL( url );
|
||
|
mAPI->setUsername( user );
|
||
|
mAPI->setPassword( password );
|
||
|
return mAPI->createUserInfoJob();
|
||
|
} else return 0;
|
||
|
}
|
||
|
|
||
12 years ago
|
TDEIO::Job *BloggingCalendarAdaptor::createListFoldersJob( const KURL &/*url*/ )
|
||
15 years ago
|
{
|
||
|
if ( mAPI ) {
|
||
|
return mAPI->createListFoldersJob();
|
||
|
} else return 0;
|
||
|
}
|
||
|
|
||
12 years ago
|
TDEIO::TransferJob *BloggingCalendarAdaptor::createListItemsJob( const KURL &url )
|
||
15 years ago
|
{
|
||
|
if ( mAPI ) {
|
||
|
return mAPI->createListItemsJob( url );
|
||
|
} else return 0;
|
||
|
}
|
||
|
|
||
12 years ago
|
TDEIO::TransferJob *BloggingCalendarAdaptor::createDownloadJob( const KURL &url,
|
||
15 years ago
|
KPIM::FolderLister::ContentType ctype )
|
||
|
{
|
||
|
if ( mAPI && (ctype & KPIM::FolderLister::Journal) ) {
|
||
|
return mAPI->createDownloadJob( url );
|
||
|
} else return 0;
|
||
|
}
|
||
|
|
||
12 years ago
|
TDEIO::Job *BloggingCalendarAdaptor::createRemoveJob( const KURL &url,
|
||
15 years ago
|
KPIM::GroupwareUploadItem *deleteItem )
|
||
|
{
|
||
|
kdDebug()<<"BloggingCalendarAdaptor::createRemoveJob( " << url.url() << ", ..)" << endl;
|
||
|
if ( mAPI && deleteItem ) {
|
||
|
return mAPI->createRemoveJob( url, deleteItem->url().url() );
|
||
|
} else return 0;
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
|
||
12 years ago
|
bool BloggingCalendarAdaptor::interpretLoginJob( TDEIO::Job *job )
|
||
15 years ago
|
{
|
||
|
kdDebug()<<"BloggingCalendarAdaptor::interpretLoginJob"<<endl;
|
||
|
if ( mAPI && job ) {
|
||
|
kdDebug()<<"We have an API and a job"<<endl;
|
||
|
mAuthenticated = false;
|
||
|
mAPI->interpretUserInfoJob( job );
|
||
|
kdDebug() << "authenticated=" << mAuthenticated << endl;
|
||
|
return mAuthenticated;
|
||
|
} else return false;
|
||
|
}
|
||
|
|
||
|
|
||
12 years ago
|
void BloggingCalendarAdaptor::interpretListFoldersJob( TDEIO::Job *job, KPIM::FolderLister * )
|
||
15 years ago
|
{
|
||
|
kdDebug() << "BloggingCalendarAdaptor::interpretListFoldersJob" << endl;
|
||
|
if ( mAPI && job ) {
|
||
|
mAPI->interpretListFoldersJob( job );
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
12 years ago
|
bool BloggingCalendarAdaptor::interpretListItemsJob( TDEIO::Job *job,
|
||
15 years ago
|
const TQString &/*jobData*/ )
|
||
15 years ago
|
{
|
||
|
if ( mAPI ) {
|
||
|
return mAPI->interpretListItemsJob( job );
|
||
|
} else {
|
||
|
return false;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
12 years ago
|
bool BloggingCalendarAdaptor::interpretDownloadItemsJob( TDEIO::Job *job,
|
||
15 years ago
|
const TQString &/*jobData*/ )
|
||
15 years ago
|
{
|
||
|
if ( mAPI ) {
|
||
|
return mAPI->interpretDownloadItemsJob( job );
|
||
|
} else {
|
||
|
return false;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
#include "bloggingcalendaradaptor.moc"
|