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
38 namespace KIO
{ class Slave
; }
42 /// One entry in the ACL list: user and permissions
44 ACLListEntry() {} // for QValueVector
45 ACLListEntry( const QString
& u
, const QString
& irl
, int p
)
46 : userId( u
), internalRightsList( irl
), permissions( p
), changed( false ) {}
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
;
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.
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.
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
);
86 /// Delete the permissions for a given user on a given url
87 DeleteACLJob
* deleteACL( KIO::Slave
* slave
, const KUrl
& url
, const QString
& user
);
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
);
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
106 GetACLJob( const KUrl
& url
, const QByteArray
&packedArgs
);
108 const ACLList
& entries() const { return m_entries
; }
111 void slotInfoMessage( KJob
*, const QString
&, const QString
& );
116 /// Get the users' rights for a given url
117 class GetUserRightsJob
: public KIO::SpecialJob
121 GetUserRightsJob( const KUrl
& url
, const QByteArray
&packedArgs
);
122 unsigned int permissions() const { return m_permissions
; }
125 void slotInfoMessage( KJob
*, const QString
&,const QString
& );
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
136 DeleteACLJob( const KUrl
& url
, const QString
& userId
,
137 const QByteArray
&packedArgs
);
139 QString
userId() const { return mUserId
; }
145 /// Set and delete a list of permissions for different users on a given url
146 class MultiSetACLJob
: public KIO::Job
{
150 MultiSetACLJob( KIO::Slave
* slave
, const KUrl
& url
, const ACLList
& acl
);
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
);
158 virtual void slotStart();
159 virtual void slotResult( KJob
*job
);
164 const ACLList mACLList
;
165 ACLList::const_iterator mACLListIterator
;
170 QString
permissionsToString( unsigned int permissions
);
176 #endif /* KMACLJOBS_H */