File indexing completed on 2024-04-21 05:51:46

0001 // SPDX-License-Identifier: GPL-2.0-or-later
0002 // SPDX-FileCopyrightText: 2002 Dominik Seichter <domseichter@web.de>
0003 
0004 #ifndef PERMISSIONS_PLUGIN_H
0005 #define PERMISSIONS_PLUGIN_H
0006 
0007 #include <QtGlobal>
0008 
0009 #ifndef Q_OS_WIN
0010 
0011 #include "plugin.h"
0012 
0013 #include <QObject>
0014 
0015 namespace Ui
0016 {
0017 class PermissionsPluginWidget;
0018 };
0019 
0020 /** This is the abstract interface that has to be implemented
0021  *  by all KRename plugins.
0022  */
0023 class PermissionsPlugin : public QObject, public Plugin
0024 {
0025 
0026     Q_OBJECT
0027 
0028 public:
0029     explicit PermissionsPlugin(PluginLoader *loader);
0030     ~PermissionsPlugin() override;
0031 
0032     /**
0033      * @returns a name of the plugin that can be displayed
0034      *          to the user. This name should be internationalized.
0035      */
0036     const QString name() const override;
0037 
0038     /**
0039      * Determines the type of the plugin.
0040      * Different enum values may be or'ed together.
0041      *
0042      * @returns the type of the plugin.
0043      */
0044     inline int type() const override;
0045 
0046     /**
0047      * @returns an icon for this plugin.
0048      */
0049     const QIcon icon() const override;
0050 
0051     /**
0052      * @returns true if this plugins is always enabled
0053      *
0054      * Warning: If you return true here, the user has no possibility to
0055      *          disable this plugin.
0056      */
0057     inline bool enabledByDefault() const override;
0058 
0059     /**
0060      * This function is the core of your plugin.
0061      *
0062      * It does the actual processing of a file, filename or token depending of the type
0063      * of your plugin.
0064      *
0065      * \see type()
0066      *
0067      * @param b the parent BatchRenamer instance calling this plugin
0068      * @param index the index of the current file (i.e. the first file has index 0,
0069      *              the second file to be renamed has index 1 ....)
0070      * @param filenameOrToken this parameter depends on the type of your plugin.
0071      *                        If type is ePluginType_File, this is the absolute path
0072      *                        or URL to the renamed file.
0073      *                        If type is ePluginType_Filename, this is the filename
0074      *                        (without path) as created by KRename.
0075      *                        If type is ePluginType_Token, this is the contents of a token
0076      *                        in brackets. If your plugin supports the token [example],
0077      *                        KRename will pass the strign "example" to your method.
0078      * @param eCurrentType the current type of plugin that is requested (for plugins that support more than one type)
0079      *
0080      * @returns the result of the function, depending on type().
0081      * @returns an empty QString if this plugin has nothing to do.
0082      * @returns A new filename if type is ePluginType_Filename
0083      * @returns the value of the token if type is ePluginType_Token
0084      * @returns an error message or an empty QString if type is ePluginType_File
0085      */
0086     QString processFile(BatchRenamer *b, int index, const QString &filenameOrToken, EPluginType eCurrentType) override;
0087 
0088     /** Get a list of all tokens supported by this plugin.
0089      *
0090      *  If the token type != ePluginType_Token you have to return an empty list
0091      *
0092      *  @returns a list of all supported tokens. The returned strings will be treated
0093      *           as regular expressions to find a plugin which supports a token.
0094      */
0095     inline const QStringList &supportedTokens() const override;
0096 
0097     /** Returns help descriptions for the supported tokens
0098      *
0099      *  The returned stringlist contains strings that are the tokens
0100      *  and the description separated by ;;
0101      *
0102      *  @returns a stringlist containing help on the supported tokens
0103      */
0104     inline const QStringList &help() const override;
0105 
0106     /** Create a user interface for this plugin
0107      *
0108      *  @param parent the parent widget of this plugin
0109      */
0110     void createUI(QWidget *parent) const override;
0111 
0112 private Q_SLOTS:
0113     void slotEnableControls();
0114     void slotAdvancedPermissions();
0115     void slotUpdatePermissions();
0116 
0117 private:
0118 
0119     int getGid(const QString &group) const;
0120     int getUid(const QString &owner) const;
0121 
0122     //void setCurrentPermissions( int perm );
0123 
0124 private:
0125     Ui::PermissionsPluginWidget *m_widget;
0126 
0127     int m_curPermission;  ///< The current permissions
0128 
0129     QStringList m_tmp;    ///< Dummy empty list so that we can return a reference for supported tokens and help
0130     QStringList m_users;  ///< List of all usernames on the system
0131     QStringList m_groups; ///< List of all groups on the system
0132 };
0133 
0134 inline int PermissionsPlugin::type() const
0135 {
0136     return ePluginType_File;
0137 }
0138 
0139 inline bool PermissionsPlugin::enabledByDefault() const
0140 {
0141     return false;
0142 }
0143 
0144 inline const QStringList &PermissionsPlugin::supportedTokens() const
0145 {
0146     return m_tmp;
0147 }
0148 
0149 inline const QStringList &PermissionsPlugin::help() const
0150 {
0151     return m_tmp;
0152 }
0153 
0154 #endif // Q_OS_WIN
0155 
0156 #endif /* PERMISSIONS_PLUGIN_H */