File indexing completed on 2024-05-12 03:54:23
0001 /* This file is part of the KDE libraries 0002 SPDX-FileCopyrightText: 1997 Matthias Kalle Dalheimer <kalle@kde.org> 0003 SPDX-FileCopyrightText: 1998, 1999 Waldo Bastian <bastian@kde.org> 0004 0005 SPDX-License-Identifier: LGPL-2.0-or-later 0006 */ 0007 0008 #ifndef KAUTHORIZED_H 0009 #define KAUTHORIZED_H 0010 0011 #include <kconfigcore_export.h> 0012 0013 #include <QMetaEnum> 0014 #include <QObject> 0015 #include <QStringList> 0016 #include <QVariant> 0017 0018 class QUrl; 0019 class QString; 0020 class QQmlEngine; 0021 class QJSEngine; 0022 0023 /** 0024 * The functions in this namespace provide the core of the Kiosk action 0025 * restriction system; the KIO and KXMLGui frameworks build on this. 0026 * 0027 * The relevant settings are read from the application's KSharedConfig 0028 * instance, so actions can be disabled on a per-application or global 0029 * basis (by using the kdeglobals file). 0030 */ 0031 class KCONFIGCORE_EXPORT KAuthorized : public QObject 0032 { 0033 Q_OBJECT 0034 public: 0035 /** 0036 * The enum values lower cased represent the action that is authorized 0037 * For example the SHELL_ACCESS value is converted to the "shell_access" string. 0038 * 0039 * @since 5.88 0040 */ 0041 enum GenericRestriction { 0042 SHELL_ACCESS = 1, // if the user is authorized to open a shell or execute shell commands 0043 GHNS, /// if the collaborative data sharing framework KNewStuff is authorized 0044 // GUI behavior 0045 LINEEDIT_REVEAL_PASSWORD, /// if typed characters in password fields can be made visible 0046 LINEEDIT_TEXT_COMPLETION, /// if line edits should be allowed to display completions 0047 MOVABLE_TOOLBARS, /// if toolbars of apps should be movable 0048 RUN_DESKTOP_FILES, /// if .desktop files should be run as executables when clicked 0049 }; 0050 Q_ENUM(GenericRestriction) 0051 0052 /** 0053 * 0054 * @since 5.88 0055 */ 0056 enum GenericAction { 0057 OPEN_WITH = 1, /// if the open-with menu should be shown for files etc. 0058 EDITFILETYPE, /// if mime-type accociations are allowed to be configured 0059 0060 OPTIONS_SHOW_TOOLBAR, /// if the toolbar should be displayed in apps 0061 SWITCH_APPLICATION_LANGUAGE, /// if an action to switch the app language should be shown 0062 BOOKMARKS, /// saving bookmarks is allowed 0063 }; 0064 Q_ENUM(GenericAction) 0065 0066 /** 0067 * Returns whether the user is permitted to perform a certain action. 0068 * 0069 * All settings are read from the "[KDE Action Restrictions]" group. 0070 * For example, if kdeglobals contains 0071 * @verbatim 0072 [KDE Action Restrictions][$i] 0073 shell_access=false 0074 @endverbatim 0075 * then 0076 * @code 0077 * KAuthorized::authorize("shell_access"); 0078 * @endcode 0079 * will return @c false. 0080 * 0081 * This method is intended for actions that do not necessarily have a 0082 * one-to-one correspondence with a menu or toolbar item (ie: a QAction 0083 * in a KXMLGui application). "shell_access" is an example of such a 0084 * "generic" action. 0085 * 0086 * The convention for actions like "File->New" is to prepend the action 0087 * name with "action/", for example "action/file_new". This is what 0088 * authorizeAction() does. 0089 * 0090 * @param action The name of the action. 0091 * @return @c true if the action is authorized, @c false 0092 * otherwise. 0093 * 0094 * @see authorizeAction() 0095 */ 0096 Q_INVOKABLE static bool authorize(const QString &action); 0097 0098 /** 0099 * Returns whether the user is permitted to perform a common action. 0100 * The enum values lower cased represent the action that is 0101 * passed in to @p authorize(QString) 0102 * 0103 * @overload 0104 * @since 5.88 0105 */ 0106 Q_INVOKABLE static bool authorize(GenericRestriction action); 0107 0108 /** 0109 * Returns whether the user is permitted to perform a certain action. 0110 * 0111 * This behaves like authorize(), except that "action/" is prepended to 0112 * @p action. So if kdeglobals contains 0113 * @verbatim 0114 [KDE Action Restrictions][$i] 0115 action/file_new=false 0116 @endverbatim 0117 * then 0118 * @code 0119 * KAuthorized::authorizeAction("file_new"); 0120 * @endcode 0121 * will return @c false. 0122 * 0123 * KXMLGui-based applications should not normally need to call this 0124 * function, as KActionCollection will do it automatically. 0125 * 0126 * @param action The name of a QAction action. 0127 * @return @c true if the QAction is authorized, @c false 0128 * otherwise. 0129 * @since 5.24 0130 * 0131 * @see authorize() 0132 */ 0133 Q_INVOKABLE static bool authorizeAction(const QString &action); 0134 0135 /** 0136 * Overload to authorize common actions. 0137 * 0138 * @overload 0139 * @since 5.88 0140 */ 0141 Q_INVOKABLE static bool authorizeAction(GenericAction action); 0142 0143 /** 0144 * Returns whether the user is permitted to use a certain control module. 0145 * 0146 * All settings are read from the "[KDE Control Module Restrictions]" 0147 * group. For example, if kdeglobals contains 0148 * @verbatim 0149 [KDE Control Module Restrictions][$i] 0150 kcm_desktop-settings=false 0151 @endverbatim 0152 * then 0153 * @code 0154 * KAuthorized::authorizeControlModule("kcm_desktop-settings"); 0155 * @endcode 0156 * will return @c false. 0157 * 0158 * @param pluginId The desktop menu ID for the control module. 0159 * @return @c true if access to the module is authorized, @c false otherwise. 0160 * 0161 */ 0162 Q_INVOKABLE static bool authorizeControlModule(const QString &pluginId); 0163 0164 static KAuthorized *create(QQmlEngine *, QJSEngine *) 0165 { 0166 return new KAuthorized; 0167 } 0168 0169 private: 0170 friend class KConfigQmlPlugin; 0171 explicit KAuthorized(); 0172 }; 0173 0174 #endif