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