Ignore:
Timestamp:
2010-02-02T18:54:51+01:00 (15 years ago)
Author:
Gubaer
Message:

Fixed automatic update policy for plugins.
new: policy for version and time based automatic update can be configured in the preferences, see help

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/plugins/PluginHandler.java

    r2866 r2924  
    170170                )
    171171                + "</html>";
    172             togglePreferenceKey = "pluginmanager.dontshowagain.version";
     172            togglePreferenceKey = "pluginmanager.version-based-update.policy";
    173173        }  else {
    174174            long tim = System.currentTimeMillis();
    175175            long last = Main.pref.getLong("pluginmanager.lastupdate", 0);
    176             Integer maxTime = Main.pref.getInteger("pluginmanager.warntime", 60);
     176            Integer maxTime = Main.pref.getInteger("pluginmanager.time-based-update.interval", 60);
    177177            long d = (tim - last) / (24 * 60 * 60 * 1000l);
    178178            if ((last <= 0) || (maxTime <= 0)) {
     
    183183                    + tr("Last plugin update more than {0} days ago.", d)
    184184                    + "</html>";
    185                 togglePreferenceKey = "pluginmanager.dontshowagain.time";
     185                togglePreferenceKey = "pluginmanager.time-based-update.policy";
    186186            }
    187187        }
     
    209209        // check whether automatic update at startup was disabled
    210210        //
    211         boolean doAsk = !Main.pref.getBoolean(togglePreferenceKey, false);
    212         if (! doAsk) return false;
    213 
     211        String policy = Main.pref.get(togglePreferenceKey, "ask");
     212        policy = policy.trim().toLowerCase();
     213        if (policy.equals("never")) {
     214            if (togglePreferenceKey.equals("pluginmanager.version-based-update.policy")) {
     215                System.out.println(tr("Skipping plugin update after JOSM upgrade. Automatic update at startup is disabled."));
     216            } else if (togglePreferenceKey.equals("pluginmanager.time-based-update.policy")) {
     217                System.out.println(tr("Skipping plugin update after elapsed update interval. Automatic update at startup is disabled."));
     218            }
     219            return false;
     220        }
     221
     222        if (policy.equals("always")) {
     223            if (togglePreferenceKey.equals("pluginmanager.time-based-update.policy")) {
     224                System.out.println(tr("Running plugin update after JOSM upgrade. Automatic update at startup is enabled."));
     225            } else if (togglePreferenceKey.equals("pluginmanager.time-based-update.policy")) {
     226                System.out.println(tr("Running plugin update after elapsed update interval. Automatic update at startup is disabled."));
     227            }
     228            return true;
     229        }
     230
     231        if (!policy.equals("ask")) {
     232            System.err.println(tr("Unexpected value ''{0}'' for preference ''{1}''. Assuming value ''ask''.", policy, togglePreferenceKey));
     233        }
    214234        int ret = HelpAwareOptionPane.showOptionDialog(
    215235                parent,
     
    220240                options,
    221241                options[0],
    222                 ht("/Plugin/AutomaticUpdate")
    223         );
    224 
    225         pnlMessage.rememberDontShowAgain(togglePreferenceKey);
     242                ht("/Preferences/Plugins#AutomaticUpdate")
     243        );
     244
     245        if (pnlMessage.isRememberDecision()) {
     246            switch(ret) {
     247            case 0:
     248                Main.pref.put(togglePreferenceKey, "always");
     249                break;
     250            case JOptionPane.CLOSED_OPTION:
     251            case 1:
     252                Main.pref.put(togglePreferenceKey, "never");
     253                break;
     254            }
     255        } else {
     256            Main.pref.put(togglePreferenceKey, "ask");
     257        }
    226258        return ret == 0;
    227259    }
     
    888920            gc.fill = GridBagConstraints.HORIZONTAL;
    889921            gc.weighty = 0.0;
    890             add(cbDontShowAgain = new JCheckBox(tr("Do not check and ask again at startup (remembers choice)")), gc);
     922            add(cbDontShowAgain = new JCheckBox(tr("Do not ask again and remember my decision (go to Preferences->Plugins to change it later)")), gc);
    891923            cbDontShowAgain.setFont(cbDontShowAgain.getFont().deriveFont(Font.PLAIN));
    892924        }
     
    901933
    902934        public void initDontShowAgain(String preferencesKey) {
    903             cbDontShowAgain.setSelected(Main.pref.getBoolean(preferencesKey, false));
    904         }
    905 
    906         public void rememberDontShowAgain(String preferenceKey) {
    907             Main.pref.put(preferenceKey, cbDontShowAgain.isSelected());
     935            String policy = Main.pref.get(preferencesKey, "ask");
     936            policy = policy.trim().toLowerCase();
     937            cbDontShowAgain.setSelected(! policy.equals("ask"));
     938        }
     939
     940        public boolean isRememberDecision() {
     941            return cbDontShowAgain.isSelected();
    908942        }
    909943    }
Note: See TracChangeset for help on using the changeset viewer.