From 6a848d4bbc4fa90f0ba3376d29a2d88a973979d9 Mon Sep 17 00:00:00 2001 From: Bo Thorsen Date: Fri, 14 May 2004 14:53:52 +0000 Subject: [PATCH] Support fetching multiple IMAP resource folders svn path=/trunk/kdepim/; revision=311401 --- kmailicalIface.h | 1 + kmailicalifaceimpl.cpp | 68 +++++++++++++++++++++++++++++++++++------- kmailicalifaceimpl.h | 7 ++--- 3 files changed, 62 insertions(+), 14 deletions(-) diff --git a/kmailicalIface.h b/kmailicalIface.h index 4c5bde548..9a375d659 100644 --- a/kmailicalIface.h +++ b/kmailicalIface.h @@ -45,6 +45,7 @@ k_dcop: const QString& uid ) = 0; virtual QStringList incidences( const QString& type, const QString& folder ) = 0; + virtual QStringList subresources( const QString& type ) = 0; // This saves the iCals/vCards in the entries in the folder. // The format in the string list is uid, entry, uid, entry... diff --git a/kmailicalifaceimpl.cpp b/kmailicalifaceimpl.cpp index 430001de8..87f7f4eec 100644 --- a/kmailicalifaceimpl.cpp +++ b/kmailicalifaceimpl.cpp @@ -152,7 +152,7 @@ bool KMailICalIfaceImpl::addIncidence( const QString& type, rc = true; } else - kdError() << "Not an IMAP resource folder" << endl; + kdError(5006) << "Not an IMAP resource folder" << endl; mResourceQuiet = quiet; return rc; @@ -184,7 +184,7 @@ bool KMailICalIfaceImpl::deleteIncidence( const QString& type, } else kdDebug(5006) << type << " not found, cannot remove uid " << uid << endl; } else - kdError() << "Not an IMAP resource folder" << endl; + kdError(5006) << "Not an IMAP resource folder" << endl; mResourceQuiet = quiet; return rc; @@ -197,11 +197,18 @@ QStringList KMailICalIfaceImpl::incidences( const QString& type, if( !mUseResourceIMAP ) return QStringList(); - kdDebug(5006) << "KMailICalIfaceImpl::incidences( " << type << " )" << endl; + kdDebug(5006) << "KMailICalIfaceImpl::incidences( " << type << ", " + << folder << " )" << endl; QStringList ilist; - KMFolder* f = folderFromType( type ); + KMFolder* f; + if ( folder.isEmpty() || ( folderFromType( type ) && + folderFromType( type )->location() == folder ) ) + f = folderFromType( type ); + else + f = extraFolder( type, folder ); if( f ) { + f->open(); QString s; for( int i=0; icount(); ++i ) { bool unget = !f->isMessage(i); @@ -213,12 +220,34 @@ QStringList KMailICalIfaceImpl::incidences( const QString& type, } if( unget ) f->unGetMsg(i); } - } else - kdError() << "Not an IMAP resource folder" << endl; + } else { + // Check if it's an error or just something with another type + if ( mExtraFolders.find( folder ) == 0 ) + kdError(5006) << "Not an IMAP resource folder" << endl; + } return ilist; } +QStringList KMailICalIfaceImpl::subresources( const QString& type ) +{ + QStringList lst; + + // Add the default one + KMFolder* f = folderFromType( type ); + if ( f ) + lst << f->location(); + + // Add the extra folders + int t = folderContentsType( type ); + QDictIterator it( mExtraFolders ); + for ( ; it.current(); ++it ) + if ( it.current()->type == t ) + lst << it.current()->folder->location(); + + return lst; +} + bool KMailICalIfaceImpl::update( const QString& type, const QString& folder, const QStringList& entries ) { @@ -275,7 +304,7 @@ bool KMailICalIfaceImpl::update( const QString& type, const QString& folder, addIncidence( type, folder, uid, entry ); } } else { - kdError() << "Not an IMAP resource folder" << endl; + kdError(5006) << "Not an IMAP resource folder" << endl; rc = false; } @@ -308,7 +337,7 @@ void KMailICalIfaceImpl::slotIncidenceAdded( KMFolder* folder, } if( unget ) folder->unGetMsg(i); } else - kdError() << "Not an IMAP resource folder" << endl; + kdError(5006) << "Not an IMAP resource folder" << endl; } // KMail deleted a file @@ -339,7 +368,7 @@ void KMailICalIfaceImpl::slotIncidenceDeleted( KMFolder* folder, } if( unget ) folder->unGetMsg(i); } else - kdError() << "Not a groupware folder" << endl; + kdError(5006) << "Not a groupware folder" << endl; } // KMail orders a refresh @@ -365,7 +394,7 @@ KMFolder* KMailICalIfaceImpl::folderFromType( const QString& type ) else if( type == "Task" || type == "Todo" ) return mTasks; else if( type == "Journal" ) return mJournals; - kdError() << "No folder type \"" << type << "\"" << endl; + kdError(5006) << "No folder type \"" << type << "\"" << endl; } return 0; @@ -549,6 +578,25 @@ void KMailICalIfaceImpl::folderContentsTypeChanged( KMFolder* folder, subresourceAdded( folderContentsType( contentsType ), folder->location() ); } +KMFolder* KMailICalIfaceImpl::extraFolder( const QString& type, + const QString& folder ) +{ + // If an extra folder exists that match the type and folder location, + // use that + int t = folderContentsType( type ); + if ( t < 1 || t > 5 ) + return 0; + + QDictIterator it( mExtraFolders ); + for ( ; it.current(); ++it ) + if ( it.current()->type == t && + it.current()->folder->location() == folder ) + return it.current()->folder; + + return 0; +} + + /**************************** * The config stuff */ diff --git a/kmailicalifaceimpl.h b/kmailicalifaceimpl.h index c81d9ad33..79956d4c0 100644 --- a/kmailicalifaceimpl.h +++ b/kmailicalifaceimpl.h @@ -58,6 +58,8 @@ public: const QString& uid ); virtual QStringList incidences( const QString& type, const QString& folder ); + virtual QStringList subresources( const QString& type ); + // This saves the iCals/vCards in the entries in the folder. // The format in the string list is uid, entry, uid, entry... virtual bool update( const QString& type, const QString& folder, @@ -140,10 +142,7 @@ private: /** Helper function for initFolders. Initializes a single folder. */ KMFolder* initFolder( KFolderTreeItem::Type itemType, const char* typeString ); - /** Emit a dcop signal */ - void dcopEmit( const QCString& signal, const QString& arg0, - const QString& arg1 = QString::null, - const QString& arg2 = QString::null ); + KMFolder* extraFolder( const QString& type, const QString& folder ); void loadPixmaps() const;