kmail

acljobs.h

Go to the documentation of this file.
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 
00065   enum ACLPermissions {
00066     List = 1,
00067     Read = 2,
00068     WriteFlags = 4,
00069     Insert = 8,
00070     Create = 16,
00071     Delete = 32,
00072     Administer = 64,
00073     Post = 128,
00074     WriteSeenFlag = 256,
00075     // alias for "all read/write permissions except admin"
00076     AllWrite = List | Read | WriteFlags | Insert | Post | Create | Delete | WriteSeenFlag,
00077     // alias for "all permissions"
00078     All = List | Read | WriteFlags | Insert | Post | Create | Delete | Administer | WriteSeenFlag
00079   };
00081   KIO::SimpleJob* setACL( KIO::Slave* slave, const KURL& url, const QString& user, unsigned int permissions );
00082 
00083   class DeleteACLJob;
00085   DeleteACLJob* deleteACL( KIO::Slave* slave, const KURL& url, const QString& user );
00086 
00087   class GetACLJob;
00089   GetACLJob* getACL( KIO::Slave* slave, const KURL& url );
00090 
00091   class GetUserRightsJob;
00093   GetUserRightsJob* getUserRights( KIO::Slave* slave, const KURL& url );
00094 
00095   class MultiSetACLJob;
00097   MultiSetACLJob* multiSetACL( KIO::Slave* slave, const KURL& url, const ACLList& acl );
00098 
00100   class GetACLJob : public KIO::SimpleJob
00101   {
00102     Q_OBJECT
00103   public:
00104     GetACLJob( const KURL& url, const QByteArray &packedArgs,
00105                bool showProgressInfo );
00106 
00107     const ACLList& entries() const { return m_entries; }
00108 
00109   protected slots:
00110     void slotInfoMessage( KIO::Job*, const QString& );
00111   private:
00112     ACLList m_entries;
00113   };
00114 
00116   class GetUserRightsJob : public KIO::SimpleJob
00117   {
00118     Q_OBJECT
00119   public:
00120     GetUserRightsJob( const KURL& url, const QByteArray &packedArgs,
00121                       bool showProgressInfo );
00122     unsigned int permissions() const { return m_permissions; }
00123 
00124   protected slots:
00125     void slotInfoMessage( KIO::Job*, const QString& );
00126   private:
00127     unsigned int m_permissions;
00128   };
00129 
00132   class DeleteACLJob : public KIO::SimpleJob
00133   {
00134     Q_OBJECT
00135   public:
00136     DeleteACLJob( const KURL& url, const QString& userId,
00137                   const QByteArray &packedArgs,
00138                   bool showProgressInfo );
00139 
00140     QString userId() const { return mUserId; }
00141 
00142   private:
00143     QString mUserId;
00144   };
00145 
00147   class MultiSetACLJob : public KIO::Job {
00148     Q_OBJECT
00149 
00150   public:
00151     MultiSetACLJob( KIO::Slave* slave, const KURL& url, const ACLList& acl, bool showProgressInfo );
00152 
00153   signals:
00154     // Emitted when a given user's permissions were successfully changed.
00155     // This allows the caller to keep track of what exactly was done (and handle errors better)
00156     void aclChanged( const QString& userId, int permissions );
00157 
00158   protected slots:
00159     virtual void slotStart();
00160     virtual void slotResult( KIO::Job *job );
00161 
00162   private:
00163     KIO::Slave* mSlave;
00164     const KURL mUrl;
00165     const ACLList mACLList;
00166     ACLList::const_iterator mACLListIterator;
00167   };
00168 
00169 
00170 #ifndef NDEBUG
00171   QString permissionsToString( unsigned int permissions );
00172 #endif
00173 }
00174 
00175 } // namespace
00176 
00177 #endif /* KMACLJOBS_H */