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 Qt library by Trolltech AS, Norway (or with modified versions
00023  *  of Qt that use the same license as Qt), 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  *  Qt.  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 <kio/job.h>
00036 #include <qvaluevector.h>
00037 
00038 namespace KMail {
00039 
00041   struct ACLListEntry {
00042     ACLListEntry() {} // for QValueVector
00043     ACLListEntry( const QString& u, const QString& irl, int p )
00044       : userId( u ), internalRightsList( irl ), permissions( p ), changed( false ) {}
00045     QString userId;
00046     QString internalRightsList; 
00047     int permissions; 
00048     bool changed; 
00049   };
00050 
00051   typedef QValueVector<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   KIO::SimpleJob* setACL( KIO::Slave* slave, const KURL& url, const QString& user, unsigned int permissions );
00090 
00091   class DeleteACLJob;
00093   DeleteACLJob* deleteACL( KIO::Slave* slave, const KURL& url, const QString& user );
00094 
00095   class GetACLJob;
00097   GetACLJob* getACL( KIO::Slave* slave, const KURL& url );
00098 
00099   class GetUserRightsJob;
00101   GetUserRightsJob* getUserRights( KIO::Slave* slave, const KURL& url );
00102 
00103   class MultiSetACLJob;
00105   MultiSetACLJob* multiSetACL( KIO::Slave* slave, const KURL& url, const ACLList& acl );
00106 
00108   class GetACLJob : public KIO::SimpleJob
00109   {
00110     Q_OBJECT
00111   public:
00112     GetACLJob( const KURL& url, const QByteArray &packedArgs,
00113                bool showProgressInfo );
00114 
00115     const ACLList& entries() const { return m_entries; }
00116 
00117   protected slots:
00118     void slotInfoMessage( KIO::Job*, const QString& );
00119   private:
00120     ACLList m_entries;
00121   };
00122 
00124   class GetUserRightsJob : public KIO::SimpleJob
00125   {
00126     Q_OBJECT
00127   public:
00128     GetUserRightsJob( const KURL& url, const QByteArray &packedArgs,
00129                       bool showProgressInfo );
00130     unsigned int permissions() const { return m_permissions; }
00131 
00132   protected slots:
00133     void slotInfoMessage( KIO::Job*, const QString& );
00134   private:
00135     unsigned int m_permissions;
00136   };
00137 
00140   class DeleteACLJob : public KIO::SimpleJob
00141   {
00142     Q_OBJECT
00143   public:
00144     DeleteACLJob( const KURL& url, const QString& userId,
00145                   const QByteArray &packedArgs,
00146                   bool showProgressInfo );
00147 
00148     QString userId() const { return mUserId; }
00149 
00150   private:
00151     QString mUserId;
00152   };
00153 
00155   class MultiSetACLJob : public KIO::Job {
00156     Q_OBJECT
00157 
00158   public:
00159     MultiSetACLJob( KIO::Slave* slave, const KURL& url, const ACLList& acl, bool showProgressInfo );
00160 
00161   signals:
00162     // Emitted when a given user's permissions were successfully changed.
00163     // This allows the caller to keep track of what exactly was done (and handle errors better)
00164     void aclChanged( const QString& userId, int permissions );
00165 
00166   protected slots:
00167     virtual void slotStart();
00168     virtual void slotResult( KIO::Job *job );
00169 
00170   private:
00171     KIO::Slave* mSlave;
00172     const KURL mUrl;
00173     const ACLList mACLList;
00174     ACLList::const_iterator mACLListIterator;
00175   };
00176 
00177 
00178 #ifndef NDEBUG
00179   QString permissionsToString( unsigned int permissions );
00180 #endif
00181 }
00182 
00183 } // namespace
00184 
00185 #endif /* KMACLJOBS_H */
KDE Home | KDE Accessibility Home | Description of Access Keys