summaryrefslogtreecommitdiffstats
path: root/korganizer/freebusymanager.cpp
diff options
context:
space:
mode:
authortpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-05-14 02:06:47 +0000
committertpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-05-14 02:06:47 +0000
commitacc2b77512ce0d8d708dda14dec1464f3eed830c (patch)
tree7917cc141e67ba40a4d4b06c752b66ede069b3da /korganizer/freebusymanager.cpp
parent54887c51b14c7707178d43d39413bf1bc7a17472 (diff)
downloadtdepim-acc2b77512ce0d8d708dda14dec1464f3eed830c.tar.gz
tdepim-acc2b77512ce0d8d708dda14dec1464f3eed830c.zip
Second batch of kdepim stability and functionality repairs
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdepim@1126473 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'korganizer/freebusymanager.cpp')
-rw-r--r--korganizer/freebusymanager.cpp99
1 files changed, 64 insertions, 35 deletions
diff --git a/korganizer/freebusymanager.cpp b/korganizer/freebusymanager.cpp
index 94fe320cf..fdb4f531b 100644
--- a/korganizer/freebusymanager.cpp
+++ b/korganizer/freebusymanager.cpp
@@ -66,6 +66,8 @@
#include <qregexp.h>
#include <qdir.h>
+#define DEBUG_5850 kdDebug(5850)
+
using namespace KCal;
FreeBusyDownloadJob::FreeBusyDownloadJob( const QString &email, const KURL &url,
@@ -96,10 +98,10 @@ void FreeBusyDownloadJob::slotData( KIO::Job *, const QByteArray &data )
void FreeBusyDownloadJob::slotResult( KIO::Job *job )
{
- kdDebug(5850) << "FreeBusyDownloadJob::slotResult() " << mEmail << endl;
+ DEBUG_5850 << "FreeBusyDownloadJob::slotResult() " << mEmail << endl;
if( job->error() ) {
- kdDebug(5850) << "FreeBusyDownloadJob::slotResult() job error for " << mEmail << endl;
+ DEBUG_5850 << "FreeBusyDownloadJob::slotResult() job error for " << mEmail << endl;
emit freeBusyDownloadError( mEmail );
} else {
FreeBusy *fb = mManager->iCalToFreeBusy( mFreeBusyData );
@@ -189,7 +191,7 @@ void FreeBusyManager::slotPerhapsUploadFB()
} else {
// We are currently uploading the FB list. Start the timer
if( eta <= 0 ) {
- kdDebug(5850) << "This shouldn't happen! eta <= 0\n";
+ DEBUG_5850 << "This shouldn't happen! eta <= 0\n";
eta = 10; // whatever
}
}
@@ -241,6 +243,16 @@ void FreeBusyManager::publishFreeBusy()
mBrokenUrl = true;
return;
}
+
+// // Substitute %u and %d [FIXME]
+// QString defaultEmail = KOCore()::self()->email();
+// int emailpos = defaultEmail.find( '@' );
+// if (emailpos != -1) {
+// const QString emailName = defaultEmail.left( emailpos );
+// const QString emailHost = defaultEmail.mid( emailpos + 1 );
+// targetURL = targetURL.url().replace("%25u", emailName, true);
+// targetURL = targetURL.url().replace("%25d", emailHost, true);
+// }
targetURL.setUser( KOPrefs::instance()->mFreeBusyPublishUser );
targetURL.setPass( KOPrefs::instance()->mFreeBusyPublishPassword );
@@ -311,7 +323,7 @@ void FreeBusyManager::publishFreeBusy()
KURL src;
src.setPath( tempFile.name() );
- kdDebug(5850) << "FreeBusyManager::publishFreeBusy(): " << targetURL << endl;
+ DEBUG_5850 << "FreeBusyManager::publishFreeBusy(): " << targetURL << endl;
KIO::Job * job = KIO::file_copy( src, targetURL, -1,
true /*overwrite*/,
@@ -343,7 +355,7 @@ void FreeBusyManager::slotUploadFreeBusyResult(KIO::Job *_job)
bool FreeBusyManager::retrieveFreeBusy( const QString &email, bool forceDownload )
{
- kdDebug(5850) << "FreeBusyManager::retrieveFreeBusy(): " << email << endl;
+ DEBUG_5850 << "FreeBusyManager::retrieveFreeBusy(): " << email << endl;
if ( email.isEmpty() ) return false;
// Check for cached copy of free/busy list
@@ -374,11 +386,11 @@ bool FreeBusyManager::processRetrieveQueue()
KURL sourceURL = freeBusyUrl( email );
- kdDebug(5850) << "FreeBusyManager::processRetrieveQueue(): url: " << sourceURL
+ DEBUG_5850 << "FreeBusyManager::processRetrieveQueue(): url: " << sourceURL
<< endl;
if ( !sourceURL.isValid() ) {
- kdDebug(5850) << "Invalid FB URL\n";
+ DEBUG_5850 << "Invalid FB URL\n";
slotFreeBusyDownloadError( email );
return false;
}
@@ -406,7 +418,7 @@ void FreeBusyManager::slotFreeBusyDownloadError( const QString& email )
// The reason we try to download even our own free-busy list is that
// this allows to avoid showing as busy the folders that are "fb relevant for nobody"
// like shared resources (meeting rooms etc.)
- kdDebug(5850) << "freebusy of owner, falling back to local list" << endl;
+ DEBUG_5850 << "freebusy of owner, falling back to local list" << endl;
emit freeBusyRetrieved( ownerFreeBusy(), email );
}
@@ -419,7 +431,7 @@ void FreeBusyManager::cancelRetrieval()
KURL FreeBusyManager::freeBusyUrl( const QString &email )
{
- kdDebug(5850) << "FreeBusyManager::freeBusyUrl(): " << email << endl;
+ DEBUG_5850 << "FreeBusyManager::freeBusyUrl(): " << email << endl;
// First check if there is a specific FB url for this email
QString configFile = locateLocal( "data", "korganizer/freebusyurls" );
@@ -428,7 +440,7 @@ KURL FreeBusyManager::freeBusyUrl( const QString &email )
cfg.setGroup( email );
QString url = cfg.readEntry( "url" );
if ( !url.isEmpty() ) {
- kdDebug(5850) << "found cached url: " << url << endl;
+ DEBUG_5850 << "found cached url: " << url << endl;
return KURL( url );
}
// Try with the url configurated by preferred email in kaddressbook
@@ -459,8 +471,9 @@ KURL FreeBusyManager::freeBusyUrl( const QString &email )
// Sanity check: Don't download if it's not a correct email
// address (this also avoids downloading for "(empty email)").
int emailpos = email.find( '@' );
- if( emailpos == -1 )
+ if( emailpos == -1 ) {
return KURL();
+ }
// Cut off everything left of the @ sign to get the user name.
const QString emailName = email.left( emailpos );
@@ -477,35 +490,51 @@ KURL FreeBusyManager::freeBusyUrl( const QString &email )
if ( hostDomain != emailHost && !hostDomain.endsWith( '.' + emailHost )
&& !emailHost.endsWith( '.' + hostDomain ) ) {
// Host names do not match
- kdDebug(5850) << "Host '" << sourceURL.host() << "' doesn't match email '"
+ DEBUG_5850 << "Host '" << sourceURL.host() << "' doesn't match email '"
<< email << '\'' << endl;
return KURL();
}
}
- kdDebug(5850) << "Server FreeBusy url: " << sourceURL << endl;
- if ( KOPrefs::instance()->mFreeBusyFullDomainRetrieval )
- sourceURL.setFileName( email + ".ifb" );
- else
- sourceURL.setFileName( emailName + ".ifb" );
- sourceURL.setUser( KOPrefs::instance()->mFreeBusyRetrieveUser );
- sourceURL.setPass( KOPrefs::instance()->mFreeBusyRetrievePassword );
-
- kdDebug(5850) << "Results in generated: " << sourceURL << endl;
- return sourceURL;
+ // This should work with anything thrown at it, not just Kolab
+ // Notice that Kolab URLs are just entered as the base address, e.g. http://server.com/mykolab/
+ // This means that if the trailing slash is not entered, we can treat this as a custom, non-Kolab URL!
+ // In that case, just pass it on through with substitution for %u and %d
+ // TODO: May want an explicit configuration option in kogroupwareprefspage.ui for this
+ if ((sourceURL.url().endsWith("/", true) == false) || (sourceURL.url().contains("%25u", true)) || (sourceURL.url().contains("%25d", true))) {
+ // A generic URL, substitute %u and %d
+ sourceURL = sourceURL.url().replace("%25u", emailName, true);
+ sourceURL = sourceURL.url().replace("%25d", emailHost, true);
+ sourceURL.setUser( KOPrefs::instance()->mFreeBusyRetrieveUser );
+ sourceURL.setPass( KOPrefs::instance()->mFreeBusyRetrievePassword );
+ return sourceURL;
+ }
+ else {
+ // This is (probably) a Kolab URL!
+ DEBUG_5850 << "Server FreeBusy url: " << sourceURL << endl;
+ if ( KOPrefs::instance()->mFreeBusyFullDomainRetrieval )
+ sourceURL.setFileName( email + ".ifb" );
+ else
+ sourceURL.setFileName( emailName + ".ifb" );
+ sourceURL.setUser( KOPrefs::instance()->mFreeBusyRetrieveUser );
+ sourceURL.setPass( KOPrefs::instance()->mFreeBusyRetrievePassword );
+
+ DEBUG_5850 << "Results in generated: " << sourceURL << endl;
+ return sourceURL;
+ }
}
KCal::FreeBusy *FreeBusyManager::iCalToFreeBusy( const QCString &data )
{
- kdDebug(5850) << "FreeBusyManager::iCalToFreeBusy()" << endl;
- kdDebug(5850) << data << endl;
+ DEBUG_5850 << "FreeBusyManager::iCalToFreeBusy()" << endl;
+ DEBUG_5850 << data << endl;
QString freeBusyVCal = QString::fromUtf8( data );
KCal::FreeBusy *fb = mFormat.parseFreeBusy( freeBusyVCal );
if ( !fb ) {
- kdDebug(5850) << "FreeBusyManager::iCalToFreeBusy(): Error parsing free/busy"
+ DEBUG_5850 << "FreeBusyManager::iCalToFreeBusy(): Error parsing free/busy"
<< endl;
- kdDebug(5850) << freeBusyVCal << endl;
+ DEBUG_5850 << freeBusyVCal << endl;
}
return fb;
}
@@ -517,19 +546,19 @@ QString FreeBusyManager::freeBusyDir()
FreeBusy *FreeBusyManager::loadFreeBusy( const QString &email )
{
- kdDebug(5850) << "FreeBusyManager::loadFreeBusy(): " << email << endl;
+ DEBUG_5850 << "FreeBusyManager::loadFreeBusy(): " << email << endl;
QString fbd = freeBusyDir();
QFile f( fbd + "/" + email + ".ifb" );
if ( !f.exists() ) {
- kdDebug(5850) << "FreeBusyManager::loadFreeBusy() " << f.name()
+ DEBUG_5850 << "FreeBusyManager::loadFreeBusy() " << f.name()
<< " doesn't exist." << endl;
return 0;
}
if ( !f.open( IO_ReadOnly ) ) {
- kdDebug(5850) << "FreeBusyManager::loadFreeBusy() Unable to open file "
+ DEBUG_5850 << "FreeBusyManager::loadFreeBusy() Unable to open file "
<< f.name() << endl;
return 0;
}
@@ -542,17 +571,17 @@ FreeBusy *FreeBusyManager::loadFreeBusy( const QString &email )
bool FreeBusyManager::saveFreeBusy( FreeBusy *freebusy, const Person &person )
{
- kdDebug(5850) << "FreeBusyManager::saveFreeBusy(): " << person.fullName() << endl;
+ DEBUG_5850 << "FreeBusyManager::saveFreeBusy(): " << person.fullName() << endl;
QString fbd = freeBusyDir();
QDir freeBusyDirectory( fbd );
if ( !freeBusyDirectory.exists() ) {
- kdDebug(5850) << "Directory " << fbd << " does not exist!" << endl;
- kdDebug(5850) << "Creating directory: " << fbd << endl;
+ DEBUG_5850 << "Directory " << fbd << " does not exist!" << endl;
+ DEBUG_5850 << "Creating directory: " << fbd << endl;
if( !freeBusyDirectory.mkdir( fbd, true ) ) {
- kdDebug(5850) << "Could not create directory: " << fbd << endl;
+ DEBUG_5850 << "Could not create directory: " << fbd << endl;
return false;
}
}
@@ -563,7 +592,7 @@ bool FreeBusyManager::saveFreeBusy( FreeBusy *freebusy, const Person &person )
filename += ".ifb";
QFile f( filename );
- kdDebug(5850) << "FreeBusyManager::saveFreeBusy(): filename: " << filename
+ DEBUG_5850 << "FreeBusyManager::saveFreeBusy(): filename: " << filename
<< endl;
freebusy->clearAttendees();
@@ -573,7 +602,7 @@ bool FreeBusyManager::saveFreeBusy( FreeBusy *freebusy, const Person &person )
Scheduler::Publish );
if ( !f.open( IO_ReadWrite ) ) {
- kdDebug(5850) << "acceptFreeBusy: Can't open:" << filename << " for writing"
+ DEBUG_5850 << "acceptFreeBusy: Can't open:" << filename << " for writing"
<< endl;
return false;
}