File indexing completed on 2024-11-24 04:44:28

0001 /*
0002     This file is part of oxaccess.
0003 
0004     SPDX-FileCopyrightText: 2009 Tobias Koenig <tokoe@kde.org>
0005 
0006     SPDX-License-Identifier: LGPL-2.0-or-later
0007 */
0008 
0009 #pragma once
0010 
0011 #include <QList>
0012 #include <QMap>
0013 #include <QString>
0014 
0015 namespace OXA
0016 {
0017 /**
0018  * @short A class that contains information about folders on the OX server.
0019  *
0020  * @author Tobias Koenig <tokoe@kde.org>
0021  */
0022 class Folder
0023 {
0024 public:
0025     /**
0026      * Describes a list of folders.
0027      */
0028     using List = QList<Folder>;
0029 
0030     /**
0031      * Describes the status of the folder.
0032      */
0033     enum ObjectStatus {
0034         Created, ///< The folder has been created or modified.
0035         Deleted ///< The folder has been deleted.
0036     };
0037 
0038     /**
0039      * Describes the visibility type of the folder.
0040      */
0041     enum Type {
0042         Public, ///< The folder is visible for all users.
0043         Private ///< The folder is only visible for the owner.
0044     };
0045 
0046     /**
0047      * Describes the module the folder belongs to.
0048      */
0049     enum Module {
0050         Unbound, ///< The folder is only a structural folder.
0051         Calendar, ///< The folder contains events.
0052         Contacts, ///< The folder contains contacts.
0053         Tasks ///< The folder contains tasks.
0054     };
0055 
0056     /**
0057      * Describes the permissions a user or group can have on
0058      * a folder.
0059      */
0060     class Permissions
0061     {
0062     public:
0063         /**
0064          * Describes the permissions on folder objects.
0065          */
0066         enum FolderPermission {
0067             NoPermission = 0, ///< No permissions.
0068             FolderIsVisible = 2, ///< The folder can be read.
0069             CreateObjects = 4, ///< Objects can be created in the folder.
0070             CreateSubfolders = 8, ///< Subfolders can be created in the folder.
0071             AdminPermission = 128 ///< Permissions can be changed.
0072         };
0073 
0074         /**
0075          * Describes the read permissions on other objects.
0076          */
0077         enum ObjectReadPermission {
0078             NoReadPermission = 0, ///< The objects can not be read.
0079             ReadOwnObjects = 2, ///< Only own objects can be read.
0080             ReadAllObjects = 4, ///< All objects can be read.
0081             AdminReadPermission = 128
0082         };
0083 
0084         /**
0085          * Describes the write permissions on other objects.
0086          */
0087         enum ObjectWritePermission {
0088             NoWritePermission = 0, ///< The objects can not be written.
0089             WriteOwnObjects = 2, ///< Only own objects can be written.
0090             WriteAllObjects = 4, ///< All objects can be written.
0091             AdminWritePermission = 128
0092         };
0093 
0094         /**
0095          * Describes the delete permissions on other objects.
0096          */
0097         enum ObjectDeletePermission {
0098             NoDeletePermission = 0, ///< The objects can not be deleted.
0099             DeleteOwnObjects = 2, ///< Only own objects can be deleted.
0100             DeleteAllObjects = 4, ///< All objects can be deleted.
0101             AdminDeletePermission = 128
0102         };
0103 
0104         Permissions();
0105 
0106         void setFolderPermission(FolderPermission permission);
0107         FolderPermission folderPermission() const;
0108 
0109         void setObjectReadPermission(ObjectReadPermission permission);
0110         ObjectReadPermission objectReadPermission() const;
0111 
0112         void setObjectWritePermission(ObjectWritePermission permission);
0113         ObjectWritePermission objectWritePermission() const;
0114 
0115         void setObjectDeletePermission(ObjectDeletePermission permission);
0116         ObjectDeletePermission objectDeletePermission() const;
0117 
0118         void setAdminFlag(bool value);
0119         bool adminFlag() const;
0120 
0121     private:
0122         FolderPermission mFolderPermission;
0123         ObjectReadPermission mObjectReadPermission;
0124         ObjectWritePermission mObjectWritePermission;
0125         ObjectDeletePermission mObjectDeletePermission;
0126         bool mAdminFlag = false;
0127     };
0128 
0129     using UserPermissions = QMap<qlonglong, Permissions>;
0130     using GroupPermissions = QMap<qlonglong, Permissions>;
0131 
0132     Folder();
0133 
0134     void setObjectStatus(ObjectStatus status);
0135     [[nodiscard]] ObjectStatus objectStatus() const;
0136 
0137     void setTitle(const QString &title);
0138     [[nodiscard]] QString title() const;
0139 
0140     void setType(Type type);
0141     [[nodiscard]] Type type() const;
0142 
0143     void setModule(Module module);
0144     [[nodiscard]] Module module() const;
0145 
0146     void setObjectId(qlonglong id);
0147     [[nodiscard]] qlonglong objectId() const;
0148 
0149     void setFolderId(qlonglong id);
0150     [[nodiscard]] qlonglong folderId() const;
0151 
0152     void setIsDefaultFolder(bool value);
0153     [[nodiscard]] bool isDefaultFolder() const;
0154 
0155     void setOwner(qlonglong id);
0156     [[nodiscard]] qlonglong owner() const;
0157 
0158     void setLastModified(const QString &timeStamp);
0159     [[nodiscard]] QString lastModified() const;
0160 
0161     void setUserPermissions(const UserPermissions &permissions);
0162     [[nodiscard]] UserPermissions userPermissions() const;
0163 
0164     void setGroupPermissions(const GroupPermissions &permissions);
0165     [[nodiscard]] GroupPermissions groupPermissions() const;
0166 
0167 private:
0168     ObjectStatus mObjectStatus;
0169     QString mTitle;
0170     Type mType;
0171     Module mModule;
0172     qlonglong mObjectId;
0173     qlonglong mFolderId;
0174     bool mIsDefaultFolder;
0175     qlonglong mOwner;
0176     QString mLastModified;
0177     UserPermissions mUserPermissions;
0178     GroupPermissions mGroupPermissions;
0179 };
0180 }
0181 Q_DECLARE_TYPEINFO(OXA::Folder, Q_RELOCATABLE_TYPE);