kcmshell renamed to kcmshell4 to fix co-installability between kdelibs3 and kdebase4...
[kdepim.git] / kmail / acljobs.h
blob19db56720d09f89e789c877d2054b60437e5b6b7
1 /*
2 * acljobs.h
4 * Copyright (c) 2004 David Faure <faure@kde.org>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 2 of the License
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 * In addition, as a special exception, the copyright holders give
21 * permission to link the code of this program with any edition of
22 * the Qt library by Trolltech AS, Norway (or with modified versions
23 * of Qt that use the same license as Qt), and distribute linked
24 * combinations including the two. You must obey the GNU General
25 * Public License in all respects for all of the code used other than
26 * Qt. If you modify this file, you may extend this exception to
27 * your version of the file, but you are not obligated to do so. If
28 * you do not wish to do so, delete this exception statement from
29 * your version.
32 #ifndef KMACLJOBS_H
33 #define KMACLJOBS_H
35 #include <kio/job.h>
36 #include <QVector>
38 namespace KIO { class Slave; }
40 namespace KMail {
42 /// One entry in the ACL list: user and permissions
43 struct ACLListEntry {
44 ACLListEntry() {} // for QValueVector
45 ACLListEntry( const QString& u, const QString& irl, int p )
46 : userId( u ), internalRightsList( irl ), permissions( p ), changed( false ) {}
47 QString userId;
48 QString internalRightsList; ///< protocol-dependent string (e.g. IMAP rights list)
49 int permissions; ///< based on the ACLPermissions enum
50 bool changed; ///< special flag for KMFolderCachedImap
53 typedef QVector<ACLListEntry> ACLList;
55 /**
56 * This namespace contains functions that return jobs for ACL operations.
58 * The current implementation is tied to IMAP.
59 * If someone wants to extend this to other protocols, turn the class into a namespace
60 * and use virtual methods.
62 namespace ACLJobs {
64 /// Bitfield modelling the possible permissions.
65 /// This is modelled after the imap4 permissions except that Read is "rs".
66 /// The semantics of the bits is protocol-dependent.
67 enum ACLPermissions {
68 List = 1,
69 Read = 2,
70 WriteFlags = 4,
71 Insert = 8,
72 Create = 16,
73 Delete = 32,
74 Administer = 64,
75 Post = 128,
76 WriteSeenFlag = 256,
77 // alias for "all read/write permissions except admin"
78 AllWrite = List | Read | WriteFlags | Insert | Post | Create | Delete | WriteSeenFlag,
79 // alias for "all permissions"
80 All = List | Read | WriteFlags | Insert | Post | Create | Delete | Administer | WriteSeenFlag
82 /// Set the permissions for a given user on a given url
83 KIO::SimpleJob* setACL( KIO::Slave* slave, const KUrl& url, const QString& user, unsigned int permissions );
85 class DeleteACLJob;
86 /// Delete the permissions for a given user on a given url
87 DeleteACLJob* deleteACL( KIO::Slave* slave, const KUrl& url, const QString& user );
89 class GetACLJob;
90 /// List all ACLs for a given url
91 GetACLJob* getACL( KIO::Slave* slave, const KUrl& url );
93 class GetUserRightsJob;
94 /// Get the users' rights for a given url
95 GetUserRightsJob* getUserRights( KIO::Slave* slave, const KUrl& url );
97 class MultiSetACLJob;
98 /// Set and delete a list of permissions for different users on a given url
99 MultiSetACLJob* multiSetACL( KIO::Slave* slave, const KUrl& url, const ACLList& acl );
101 /// List all ACLs for a given url
102 class GetACLJob : public KIO::SpecialJob
104 Q_OBJECT
105 public:
106 GetACLJob( const KUrl& url, const QByteArray &packedArgs);
108 const ACLList& entries() const { return m_entries; }
110 protected slots:
111 void slotInfoMessage( KJob*, const QString&, const QString& );
112 private:
113 ACLList m_entries;
116 /// Get the users' rights for a given url
117 class GetUserRightsJob : public KIO::SpecialJob
119 Q_OBJECT
120 public:
121 GetUserRightsJob( const KUrl& url, const QByteArray &packedArgs);
122 unsigned int permissions() const { return m_permissions; }
124 protected slots:
125 void slotInfoMessage( KJob*, const QString&,const QString& );
126 private:
127 unsigned int m_permissions;
130 /// Delete the permissions for a given user on a given url
131 /// This class only exists to store the userid in the job
132 class DeleteACLJob : public KIO::SpecialJob
134 Q_OBJECT
135 public:
136 DeleteACLJob( const KUrl& url, const QString& userId,
137 const QByteArray &packedArgs);
139 QString userId() const { return mUserId; }
141 private:
142 QString mUserId;
145 /// Set and delete a list of permissions for different users on a given url
146 class MultiSetACLJob : public KIO::Job {
147 Q_OBJECT
149 public:
150 MultiSetACLJob( KIO::Slave* slave, const KUrl& url, const ACLList& acl);
152 signals:
153 // Emitted when a given user's permissions were successfully changed.
154 // This allows the caller to keep track of what exactly was done (and handle errors better)
155 void aclChanged( const QString& userId, int permissions );
157 protected slots:
158 virtual void slotStart();
159 virtual void slotResult( KJob *job );
161 private:
162 KIO::Slave* mSlave;
163 const KUrl mUrl;
164 const ACLList mACLList;
165 ACLList::const_iterator mACLListIterator;
169 #ifndef NDEBUG
170 QString permissionsToString( unsigned int permissions );
171 #endif
174 } // namespace
176 #endif /* KMACLJOBS_H */