kmail

acljobs.h

00001 /*
00002  * acljobs.h
00003  *
00004  * Copyright (c) 2004 David Faure <faure@kde.org>
00005  *
00006  *
00007  *  This program is free software; you can redistribute it and/or modify
00008  *  it under the terms of the GNU General Public License as published by
00009  *  the Free Software Foundation; version 2 of the License
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License
00017  *  along with this program; if not, write to the Free Software
00018  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00019  *
00020  *  In addition, as a special exception, the copyright holders give
00021  *  permission to link the code of this program with any edition of
00022  *  the TQt library by Trolltech AS, Norway (or with modified versions
00023  *  of TQt that use the same license as TQt), and distribute linked
00024  *  combinations including the two.  You must obey the GNU General
00025  *  Public License in all respects for all of the code used other than
00026  *  TQt.  If you modify this file, you may extend this exception to
00027  *  your version of the file, but you are not obligated to do so.  If
00028  *  you do not wish to do so, delete this exception statement from
00029  *  your version.
00030  */
00031 
00032 #ifndef KMACLJOBS_H
00033 #define KMACLJOBS_H
00034 
00035 #include <tdeio/job.h>
00036 #include <tqvaluevector.h>
00037 
00038 namespace KMail {
00039 
00041   struct ACLListEntry {
00042     ACLListEntry() {} // for TQValueVector
00043     ACLListEntry( const TQString& u, const TQString& irl, int p )
00044       : userId( u ), internalRightsList( irl ), permissions( p ), changed( false ) {}
00045     TQString userId;
00046     TQString internalRightsList; 
00047     int permissions; 
00048     bool changed; 
00049   };
00050 
00051   typedef TQValueVector<ACLListEntry> ACLList;
00052 
00060 namespace ACLJobs {
00061 
00062   // Used by KMFolderCachedImap and KMFolderImap, no better place for that yet, until we have a
00063   // common base class for both
00064   enum ACLFetchState {
00065     NotFetchedYet, 
00066     Ok,            
00067     FetchFailed    
00068   };
00069 
00073   enum ACLPermissions {
00074     List = 1,
00075     Read = 2,
00076     WriteFlags = 4,
00077     Insert = 8,
00078     Create = 16,
00079     Delete = 32,
00080     Administer = 64,
00081     Post = 128,
00082     WriteSeenFlag = 256,
00083     // alias for "all read/write permissions except admin"
00084     AllWrite = List | Read | WriteFlags | Insert | Post | Create | Delete | WriteSeenFlag,
00085     // alias for "all permissions"
00086     All = List | Read | WriteFlags | Insert | Post | Create | Delete | Administer | WriteSeenFlag
00087   };
00089   TDEIO::SimpleJob* setACL( TDEIO::Slave* slave, const KURL& url, const TQString& user, unsigned int permissions );
00090 
00091   class DeleteACLJob;
00093   DeleteACLJob* deleteACL( TDEIO::Slave* slave, const KURL& url, const TQString& user );
00094 
00095   class GetACLJob;
00097   GetACLJob* getACL( TDEIO::Slave* slave, const KURL& url );
00098 
00099   class GetUserRightsJob;
00101   GetUserRightsJob* getUserRights( TDEIO::Slave* slave, const KURL& url );
00102 
00103   class MultiSetACLJob;
00105   MultiSetACLJob* multiSetACL( TDEIO::Slave* slave, const KURL& url, const ACLList& acl );
00106 
00108   class GetACLJob : public TDEIO::SimpleJob
00109   {
00110     Q_OBJECT
00111   
00112   public:
00113     GetACLJob( const KURL& url, const TQByteArray &packedArgs,
00114                bool showProgressInfo );
00115 
00116     const ACLList& entries() const { return m_entries; }
00117 
00118   protected slots:
00119     void slotInfoMessage( TDEIO::Job*, const TQString& );
00120   private:
00121     ACLList m_entries;
00122   };
00123 
00125   class GetUserRightsJob : public TDEIO::SimpleJob
00126   {
00127     Q_OBJECT
00128   
00129   public:
00130     GetUserRightsJob( const KURL& url, const TQByteArray &packedArgs,
00131                       bool showProgressInfo );
00132     unsigned int permissions() const { return m_permissions; }
00133 
00134   protected slots:
00135     void slotInfoMessage( TDEIO::Job*, const TQString& );
00136   private:
00137     unsigned int m_permissions;
00138   };
00139 
00142   class DeleteACLJob : public TDEIO::SimpleJob
00143   {
00144     Q_OBJECT
00145   
00146   public:
00147     DeleteACLJob( const KURL& url, const TQString& userId,
00148                   const TQByteArray &packedArgs,
00149                   bool showProgressInfo );
00150 
00151     TQString userId() const { return mUserId; }
00152 
00153   private:
00154     TQString mUserId;
00155   };
00156 
00158   class MultiSetACLJob : public TDEIO::Job {
00159     Q_OBJECT
00160   
00161 
00162   public:
00163     MultiSetACLJob( TDEIO::Slave* slave, const KURL& url, const ACLList& acl, bool showProgressInfo );
00164 
00165   signals:
00166     // Emitted when a given user's permissions were successfully changed.
00167     // This allows the caller to keep track of what exactly was done (and handle errors better)
00168     void aclChanged( const TQString& userId, int permissions );
00169 
00170   protected slots:
00171     virtual void slotStart();
00172     virtual void slotResult( TDEIO::Job *job );
00173 
00174   private:
00175     TDEIO::Slave* mSlave;
00176     const KURL mUrl;
00177     const ACLList mACLList;
00178     ACLList::const_iterator mACLListIterator;
00179   };
00180 
00181 
00182 #ifndef NDEBUG
00183   TQString permissionsToString( unsigned int permissions );
00184 #endif
00185 }
00186 
00187 } // namespace
00188 
00189 #endif /* KMACLJOBS_H */