File indexing completed on 2024-04-14 15:51:35

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