Ticket #12731: 12731-upload-block.patch

File 12731-upload-block.patch, 10.3 KB (added by bastiK, 4 years ago)
  • src/org/openstreetmap/josm/actions/ToggleUploadDiscouragedLayerAction.java

     
    3131    public ToggleUploadDiscouragedLayerAction(OsmDataLayer layer) {
    3232        super(tr("Discourage upload"), ImageProvider.get("no_upload"));
    3333        this.layer = layer;
     34        setEnabled(layer.isUploadable());
    3435    }
    3536
    3637    @Override
     
    4243    @Override
    4344    public Component createMenuComponent() {
    4445        JCheckBoxMenuItem item = new JCheckBoxMenuItem(this);
    45         item.setSelected(layer.isUploadDiscouraged());
     46        item.setSelected(layer.isUploadDiscouraged() || !layer.isUploadable());
    4647        return item;
    4748    }
    4849
  • src/org/openstreetmap/josm/actions/UploadAction.java

     
    140140     */
    141141    @Override
    142142    protected void updateEnabledState() {
    143         setEnabled(getLayerManager().getEditLayer() != null);
     143        OsmDataLayer editLayer = getLayerManager().getEditLayer();
     144        setEnabled(editLayer != null && editLayer.isUploadable());
    144145    }
    145146
    146147    public static boolean checkPreUploadConditions(AbstractModifiableLayer layer) {
  • src/org/openstreetmap/josm/data/osm/DataSet.java

     
    9898 */
    9999public final class DataSet implements Data, ProjectionChangeListener {
    100100
     101    public enum UploadPolicy {
     102        NORMAL("true"),
     103        DISCOURAGED("false"),
     104        BLOCKED("never");
     105
     106        String xml_flag;
     107
     108        private UploadPolicy(String xml_flag) {
     109            this.xml_flag = xml_flag;
     110        }
     111
     112        public String getXmlFlag() {
     113            return xml_flag;
     114        }
     115    };
     116
    101117    /**
    102118     * Maximum number of events that can be fired between beginUpdate/endUpdate to be send as single events (ie without DatasetChangedEvent)
    103119     */
     
    123139
    124140    private int highlightUpdateCount;
    125141
    126     private boolean uploadDiscouraged;
     142    private UploadPolicy uploadPolicy;
    127143
    128144    private final ReadWriteLock lock = new ReentrantReadWriteLock();
    129145    private final Object selectionLock = new Object();
     
    299315    }
    300316
    301317    /**
    302      * Determines if upload is being discouraged (i.e. this dataset contains private data which should not be uploaded)
     318     * Determines if upload is being discouraged.
     319     * (i.e. this dataset contains private data which should not be uploaded)
    303320     * @return {@code true} if upload is being discouraged, {@code false} otherwise
    304321     * @see #setUploadDiscouraged
    305322     */
     323    @Deprecated
    306324    public boolean isUploadDiscouraged() {
    307         return uploadDiscouraged;
     325        return uploadPolicy == UploadPolicy.DISCOURAGED || uploadPolicy == UploadPolicy.BLOCKED;
    308326    }
    309327
    310328    /**
     
    312330     * @param uploadDiscouraged {@code true} if this dataset contains private data which should not be uploaded
    313331     * @see #isUploadDiscouraged
    314332     */
     333    @Deprecated
    315334    public void setUploadDiscouraged(boolean uploadDiscouraged) {
    316         this.uploadDiscouraged = uploadDiscouraged;
     335        if (uploadPolicy != UploadPolicy.BLOCKED) {
     336            this.uploadPolicy = uploadDiscouraged ? UploadPolicy.DISCOURAGED : UploadPolicy.NORMAL;
     337        }
    317338    }
    318339
     340    public UploadPolicy getUploadPolicy() {
     341        return this.uploadPolicy;
     342    }
     343
     344    public void setUploadPolicy(UploadPolicy uploadPolicy) {
     345        this.uploadPolicy = uploadPolicy;
     346    }
     347
    319348    /**
    320349     * Holding bin for changeset tag information, to be applied when or if this is ever uploaded.
    321350     */
  • src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java

     
    6262import org.openstreetmap.josm.data.gpx.WayPoint;
    6363import org.openstreetmap.josm.data.osm.DataIntegrityProblemException;
    6464import org.openstreetmap.josm.data.osm.DataSet;
     65import org.openstreetmap.josm.data.osm.DataSet.UploadPolicy;
    6566import org.openstreetmap.josm.data.osm.DataSetMerger;
    6667import org.openstreetmap.josm.data.osm.DatasetConsistencyTest;
    6768import org.openstreetmap.josm.data.osm.IPrimitive;
     
    386387    @Override
    387388    public Icon getIcon() {
    388389        ImageProvider base = getBaseIconProvider().setMaxSize(ImageSizes.LAYER);
    389         if (isUploadDiscouraged()) {
     390        if (isUploadDiscouraged() || data.getUploadPolicy() == UploadPolicy.BLOCKED) {
    390391            base.addOverlay(new ImageOverlay(new ImageProvider("warning-small"), 0.5, 0.5, 1.0, 1.0));
    391392        }
    392393        return base.get();
     
    603604        if (isUploadDiscouraged()) {
    604605            p.add(new JLabel(tr("Upload is discouraged")), GBC.eop().insets(15, 0, 0, 0));
    605606        }
     607        if (data.getUploadPolicy() == UploadPolicy.BLOCKED) {
     608            p.add(new JLabel(tr("Upload is blocked")), GBC.eop().insets(15, 0, 0, 0));
     609        }
    606610
    607611        return p;
    608612    }
     
    873877
    874878    @Override
    875879    public boolean isUploadable() {
    876         return true;
     880        return data.getUploadPolicy() != UploadPolicy.BLOCKED;
    877881    }
    878882
    879883    @Override
    880884    public boolean requiresUploadToServer() {
    881         return requiresUploadToServer;
     885        return isUploadable() && requiresUploadToServer;
    882886    }
    883887
    884888    @Override
     
    967971         // change listener and already got notified.
    968972    }
    969973
     974    /**
     975     * Determines if upload is being discouraged.
     976     * (i.e. this dataset contains private data which should not be uploaded)
     977     * @return {@code true} if upload is being discouraged, {@code false} otherwise
     978     */
    970979    @Override
    971980    public final boolean isUploadDiscouraged() {
    972         return data.isUploadDiscouraged();
     981        return data.getUploadPolicy() == UploadPolicy.DISCOURAGED;
    973982    }
    974983
    975984    /**
     
    978987     * This feature allows to use "private" data layers.
    979988     */
    980989    public final void setUploadDiscouraged(boolean uploadDiscouraged) {
    981         if (uploadDiscouraged ^ isUploadDiscouraged()) {
    982             data.setUploadDiscouraged(uploadDiscouraged);
     990        if (data.getUploadPolicy() != UploadPolicy.BLOCKED &&
     991                uploadDiscouraged ^ isUploadDiscouraged()) {
     992            data.setUploadPolicy(uploadDiscouraged ? UploadPolicy.DISCOURAGED : UploadPolicy.NORMAL);
    983993            for (LayerStateChangeListener l : layerStateChangeListeners) {
    984994                l.uploadDiscouragedChanged(this, uploadDiscouraged);
    985995            }
  • src/org/openstreetmap/josm/io/OsmReader.java

     
    2727import org.openstreetmap.josm.data.osm.AbstractPrimitive;
    2828import org.openstreetmap.josm.data.osm.Changeset;
    2929import org.openstreetmap.josm.data.osm.DataSet;
     30import org.openstreetmap.josm.data.osm.DataSet.UploadPolicy;
    3031import org.openstreetmap.josm.data.osm.Node;
    3132import org.openstreetmap.josm.data.osm.NodeData;
    3233import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
     
    138139        ds.setVersion(v);
    139140        String upload = parser.getAttributeValue(null, "upload");
    140141        if (upload != null) {
    141             ds.setUploadDiscouraged(!Boolean.parseBoolean(upload));
     142            for (UploadPolicy policy : UploadPolicy.values()) {
     143                if (policy.getXmlFlag().equalsIgnoreCase(upload)) {
     144                    ds.setUploadPolicy(policy);
     145                    break;
     146                }
     147            }
    142148        }
    143149        String generator = parser.getAttributeValue(null, "generator");
    144150        Long uploadChangesetId = null;
  • src/org/openstreetmap/josm/io/OsmWriter.java

     
    1616import org.openstreetmap.josm.data.osm.AbstractPrimitive;
    1717import org.openstreetmap.josm.data.osm.Changeset;
    1818import org.openstreetmap.josm.data.osm.DataSet;
     19import org.openstreetmap.josm.data.osm.DataSet.UploadPolicy;
    1920import org.openstreetmap.josm.data.osm.INode;
    2021import org.openstreetmap.josm.data.osm.IPrimitive;
    2122import org.openstreetmap.josm.data.osm.IRelation;
     
    7778        header(null);
    7879    }
    7980
    80     public void header(Boolean upload) {
     81    public void header(UploadPolicy upload) {
    8182        out.println("<?xml version='1.0' encoding='UTF-8'?>");
    8283        out.print("<osm version='");
    8384        out.print(version);
    84         if (upload != null) {
     85        if (upload != UploadPolicy.NORMAL) {
    8586            out.print("' upload='");
    86             out.print(upload);
     87            out.print(upload.getXmlFlag());
    8788        }
    8889        out.println("' generator='JOSM'>");
    8990    }
     
    113114    }
    114115
    115116    public void writeLayer(OsmDataLayer layer) {
    116         header(!layer.isUploadDiscouraged());
     117        header(layer.data.getUploadPolicy());
    117118        writeDataSources(layer.data);
    118119        writeContent(layer.data);
    119120        footer();
  • src/org/openstreetmap/josm/tools/RightAndLefthandTraffic.java

     
    156156        try (Writer writer = new OutputStreamWriter(new FileOutputStream(file), StandardCharsets.UTF_8);
    157157             OsmWriter w = OsmWriterFactory.createOsmWriter(new PrintWriter(writer), false, ds.getVersion())
    158158            ) {
    159             w.header(Boolean.FALSE);
     159            w.header(DataSet.UploadPolicy.DISCOURAGED);
    160160            w.writeContent(ds);
    161161            w.footer();
    162162        } catch (IOException ex) {