001    // License: GPL. For details, see LICENSE file.
002    package org.openstreetmap.josm.io.remotecontrol;
003    
004    import java.util.Arrays;
005    import java.util.List;
006    import org.openstreetmap.josm.Main;
007    import static org.openstreetmap.josm.tools.I18n.tr;
008    
009    /**
010     * Contains a preference name to control permission for the operation
011     * implemented by the RequestHandler, and an error message to be displayed if
012     * not permitted.
013     *
014     * @author Bodo Meissner
015     */
016    public class PermissionPrefWithDefault {
017    
018        public static final PermissionPrefWithDefault LOAD_DATA =
019                new PermissionPrefWithDefault("remotecontrol.permission.load-data", true, tr("Load data from API"));
020        public static final PermissionPrefWithDefault IMPORT_DATA =
021                new PermissionPrefWithDefault("remotecontrol.permission.import", true, tr("Import data from URL"));
022        public static final PermissionPrefWithDefault OPEN_FILES =
023                new PermissionPrefWithDefault("remotecontrol.permission.open-files", false, tr("Open local files"));
024        public static final PermissionPrefWithDefault LOAD_IMAGERY =
025                new PermissionPrefWithDefault("remotecontrol.permission.imagery", true, tr("Load imagery layers"));
026        public static final PermissionPrefWithDefault CHANGE_SELECTION =
027                new PermissionPrefWithDefault("remotecontrol.permission.change-selection", true, tr("Change the selection"));
028        public static final PermissionPrefWithDefault CHANGE_VIEWPORT =
029                new PermissionPrefWithDefault("remotecontrol.permission.change-viewport", true, tr("Change the viewport"));
030        public static final PermissionPrefWithDefault CREATE_OBJECTS =
031                new PermissionPrefWithDefault("remotecontrol.permission.create-objects", true, tr("Create new objects"));
032        public static final PermissionPrefWithDefault READ_PROTOCOL_VERSION =
033                new PermissionPrefWithDefault("remotecontrol.permission.read-protocolversion", true, tr("Read protocol version"));
034        /**
035         * name of the preference setting to permit the remote operation
036         */
037        public final String pref;
038        /**
039         * default preference setting
040         */
041        public final boolean defaultVal;
042        /**
043         * text for the preference dialog checkbox
044         */
045        public final String preferenceText;
046    
047        public PermissionPrefWithDefault(String pref, boolean defaultVal, String preferenceText) {
048            this.pref = pref;
049            this.defaultVal = defaultVal;
050            this.preferenceText = preferenceText;
051        }
052    
053        public boolean isAllowed() {
054            return Main.pref.getBoolean(pref, defaultVal);
055        }
056    
057        public static List<PermissionPrefWithDefault> getPermissionPrefs() {
058            return Arrays.asList(
059                    LOAD_DATA, IMPORT_DATA, OPEN_FILES, LOAD_IMAGERY,
060                    CHANGE_SELECTION, CHANGE_VIEWPORT,
061                    CREATE_OBJECTS, READ_PROTOCOL_VERSION);
062        }
063    }