File indexing completed on 2024-05-12 15:34:08

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 
0021 /**
0022  * The functions in this namespace provide the core of the Kiosk action
0023  * restriction system; the KIO and KXMLGui frameworks build on this.
0024  *
0025  * The relevant settings are read from the application's KSharedConfig
0026  * instance, so actions can be disabled on a per-application or global
0027  * basis (by using the kdeglobals file).
0028  */
0029 namespace KAuthorized
0030 {
0031 Q_NAMESPACE_EXPORT(KCONFIGCORE_EXPORT)
0032 
0033 /**
0034  * The enum values lower cased represent the action that is authorized
0035  * For example the SHELL_ACCESS value is converted to the "shell_access" string.
0036  *
0037  * @since 5.88
0038  */
0039 enum GenericRestriction {
0040     SHELL_ACCESS = 1, // if the user is authorized to open a shell or execute shell commands
0041     GHNS, /// if the collaborative data sharing framework KNewStuff is authorized
0042     // GUI behavior
0043     LINEEDIT_REVEAL_PASSWORD, /// if typed characters in password fields can be made visible
0044     LINEEDIT_TEXT_COMPLETION, /// if line edits should be allowed to display completions
0045     MOVABLE_TOOLBARS, /// if toolbars of of apps should be movable
0046     RUN_DESKTOP_FILES, /// if .desktop files should be run as executables when clicked
0047 };
0048 Q_ENUM_NS(GenericRestriction)
0049 
0050 /**
0051  *
0052  * @since 5.88
0053  */
0054 enum GenericAction {
0055     OPEN_WITH = 1, /// if the open-with menu should be shown for files etc.
0056     EDITFILETYPE, /// if mime-type accociations are allowed to be configured
0057 
0058     OPTIONS_SHOW_TOOLBAR, /// if the toolbar should be displayed in apps
0059     SWITCH_APPLICATION_LANGUAGE, /// if an action to switch the app language should be shown
0060     BOOKMARKS, /// saving bookmarks is allowed
0061 };
0062 Q_ENUM_NS(GenericAction)
0063 
0064 /**
0065  * Returns whether the user is permitted to perform a certain action.
0066  *
0067  * All settings are read from the "[KDE Action Restrictions]" group.
0068  * For example, if kdeglobals contains
0069  * @verbatim
0070    [KDE Action Restrictions][$i]
0071    shell_access=false
0072    @endverbatim
0073  * then
0074  * @code
0075  * KAuthorized::authorize("shell_access");
0076  * @endcode
0077  * will return @c false.
0078  *
0079  * This method is intended for actions that do not necessarily have a
0080  * one-to-one correspondence with a menu or toolbar item (ie: a QAction
0081  * in a KXMLGui application).  "shell_access" is an example of such a
0082  * "generic" action.
0083  *
0084  * The convention for actions like "File->New" is to prepend the action
0085  * name with "action/", for example "action/file_new".  This is what
0086  * authorizeAction() does.
0087  *
0088  * @param action  The name of the action.
0089  * @return        @c true if the action is authorized, @c false
0090  *                otherwise.
0091  *
0092  * @see authorizeAction()
0093  */
0094 KCONFIGCORE_EXPORT bool authorize(const QString &action);
0095 
0096 /**
0097  * Returns whether the user is permitted to perform a common action.
0098  * The enum values lower cased represent the action that is
0099  * passed in to @p authorize(QString)
0100  *
0101  * @overload
0102  * @since 5.88
0103  */
0104 KCONFIGCORE_EXPORT bool authorize(GenericRestriction action);
0105 
0106 /**
0107  * Returns whether the user is permitted to perform a certain action.
0108  *
0109  * This behaves like authorize(), except that "action/" is prepended to
0110  * @p action.  So if kdeglobals contains
0111  * @verbatim
0112    [KDE Action Restrictions][$i]
0113    action/file_new=false
0114    @endverbatim
0115  * then
0116  * @code
0117  * KAuthorized::authorizeAction("file_new");
0118  * @endcode
0119  * will return @c false.
0120  *
0121  * KXMLGui-based applications should not normally need to call this
0122  * function, as KActionCollection will do it automatically.
0123  *
0124  * @param action  The name of a QAction action.
0125  * @return        @c true if the QAction is authorized, @c false
0126  *                otherwise.
0127  * @since 5.24
0128  *
0129  * @see authorize()
0130  */
0131 KCONFIGCORE_EXPORT bool authorizeAction(const QString &action);
0132 
0133 /**
0134  * Overload to authorize common actions.
0135  *
0136  * @overload
0137  * @since 5.88
0138  */
0139 KCONFIGCORE_EXPORT bool authorizeAction(GenericAction action);
0140 
0141 #if KCONFIGCORE_ENABLE_DEPRECATED_SINCE(5, 24)
0142 /**
0143  * Returns whether the user is permitted to perform a certain action.
0144  *
0145  * This behaves like authorize(), except that "action/" is prepended to
0146  * @p action.  So if kdeglobals contains
0147  * @verbatim
0148    [KDE Action Restrictions][$i]
0149    action/file_new=false
0150    @endverbatim
0151  * then
0152  * @code
0153  * KAuthorized::authorizeKAction("file_new");
0154  * @endcode
0155  * will return @c false.
0156  *
0157  * KXMLGui-based applications should not normally need to call this
0158  * function, as KActionCollection will do it automatically.
0159  *
0160  * @param action  The name of a KAction action.
0161  * @return        @c true if the KAction is authorized, @c false
0162  *                otherwise.
0163  *
0164  * @see authorize()
0165  * @deprecated since 5.24, use authorizeAction() instead.
0166  */
0167 KCONFIGCORE_EXPORT
0168 KCONFIGCORE_DEPRECATED_VERSION(5, 24, "Use KAuthorized::authorizeAction(const QString&)")
0169 bool authorizeKAction(const QString &action);
0170 #endif
0171 
0172 /**
0173  * Returns whether the user is permitted to use a certain control
0174  * module.
0175  *
0176  * All settings are read from the "[KDE Control Module Restrictions]"
0177  * group.  For example, if kdeglobals contains
0178  * @verbatim
0179    [KDE Control Module Restrictions][$i]
0180    desktop-settings.desktop=false
0181    @endverbatim
0182  * then
0183  * @code
0184  * KAuthorized::authorizeControlModule("desktop-settings.desktop");
0185  * @endcode
0186  * will return @c false.
0187  *
0188  * @param menuId  The desktop menu ID for the control module.
0189  * @return        @c true if access to the module is authorized,
0190  *                @c false otherwise.
0191  *
0192  * @see authorizeControlModules()
0193  */
0194 KCONFIGCORE_EXPORT bool authorizeControlModule(const QString &menuId);
0195 
0196 /**
0197  * Determines which control modules from a list the user is permitted to
0198  * use.
0199  *
0200  * @param menuIds  A list of desktop menu IDs for control modules.
0201  * @return         The entries in @p menuIds for which
0202  *                 authorizeControlModule() returns @c true.
0203  *
0204  * @see authorizeControlModule()
0205  */
0206 KCONFIGCORE_EXPORT QStringList authorizeControlModules(const QStringList &menuIds);
0207 
0208 }
0209 
0210 #endif