Changeset 6349 in josm


Ignore:
Timestamp:
2013-10-31T22:52:58+01:00 (10 years ago)
Author:
Don-vip
Message:

fix #9234 - For identified users, notifies periodically (every 5 minutes by default) of new OSM messages he/she has received. All of this is configurable in server access preferences.

Location:
trunk/src/org/openstreetmap/josm
Files:
2 added
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/osm/UserInfo.java

    r3083 r6349  
    2222    /** the list of preferred languages */
    2323    private List<String> languages;
     24    /** the number of unread messages */
     25    private int unreadMessages;
    2426
     27    /**
     28     * Constructs a new {@code UserInfo}.
     29     */
    2530    public UserInfo() {
    2631        id = 0;
     
    7176        this.homeZoom = homeZoom;
    7277    }
     78
     79    /**
     80     * Replies the number of unread messages
     81     * @return the number of unread messages
     82     * @since 6349
     83     */
     84    public final int getUnreadMessages() {
     85        return unreadMessages;
     86    }
     87
     88    /**
     89     * Sets the number of unread messages
     90     * @param unreadMessages the number of unread messages
     91     * @since 6349
     92     */
     93    public final void setUnreadMessages(int unreadMessages) {
     94        this.unreadMessages = unreadMessages;
     95    }
    7396}
  • trunk/src/org/openstreetmap/josm/gui/ExceptionDialogUtil.java

    r6070 r6349  
    2020import org.openstreetmap.josm.io.IllegalDataException;
    2121import org.openstreetmap.josm.io.MissingOAuthAccessTokenException;
     22import org.openstreetmap.josm.io.OsmApi;
    2223import org.openstreetmap.josm.io.OsmApiException;
    2324import org.openstreetmap.josm.io.OsmApiInitializationException;
     
    244245    }
    245246
    246     private static boolean isOAuth() {
    247         return Main.pref.get("osm-server.auth-method", "basic").equals("oauth");
    248     }
    249 
    250247    /**
    251248     * Explains a {@link OsmApiException} which was thrown because the authentication at
     
    256253    public static void explainAuthenticationFailed(OsmApiException e) {
    257254        String msg;
    258         if (isOAuth()) {
     255        if (OsmApi.isUsingOAuth()) {
    259256            msg = ExceptionUtil.explainFailedOAuthAuthentication(e);
    260257        } else {
     
    293290            msg = tr("Access to redacted version ''{0}'' of {1} {2} is forbidden.",
    294291                    version, tr(type), id);
    295         } else if (isOAuth()) {
     292        } else if (OsmApi.isUsingOAuth()) {
    296293            msg = ExceptionUtil.explainFailedOAuthAuthorisation(e);
    297294        } else {
  • trunk/src/org/openstreetmap/josm/gui/JosmUserIdentityManager.java

    r6296 r6349  
    1414import org.openstreetmap.josm.gui.preferences.server.OAuthAccessTokenHolder;
    1515import org.openstreetmap.josm.gui.progress.NullProgressMonitor;
     16import org.openstreetmap.josm.io.OsmApi;
    1617import org.openstreetmap.josm.io.OsmServerUserInfoReader;
    1718import org.openstreetmap.josm.io.OsmTransferException;
     
    6061        if (instance == null) {
    6162            instance = new JosmUserIdentityManager();
    62             if (Main.pref.get("osm-server.auth-method").equals("oauth") && OAuthAccessTokenHolder.getInstance().containsAccessToken()) {
     63            if (OsmApi.isUsingOAuth() && OAuthAccessTokenHolder.getInstance().containsAccessToken()) {
    6364                try {
    6465                    instance.initFromOAuth(Main.parent);
     
    272273            accessTokenKeyChanged = false;
    273274            accessTokenSecretChanged = false;
    274             if (Main.pref.get("osm-server.auth-method").equals("oauth")) {
     275            if (OsmApi.isUsingOAuth()) {
    275276                try {
    276277                    instance.initFromOAuth(Main.parent);
  • trunk/src/org/openstreetmap/josm/gui/MainApplication.java

    r6248 r6349  
    4242import org.openstreetmap.josm.gui.util.GuiHelper;
    4343import org.openstreetmap.josm.io.DefaultProxySelector;
     44import org.openstreetmap.josm.io.MessageNotifier;
    4445import org.openstreetmap.josm.io.auth.CredentialsManager;
    4546import org.openstreetmap.josm.io.auth.DefaultAuthenticator;
     
    443444            RemoteControl.start();
    444445        }
     446       
     447        if (MessageNotifier.PROP_NOTIFIER_ENABLED.get()) {
     448            MessageNotifier.start();
     449        }
    445450
    446451        if (Main.pref.getBoolean("debug.edt-checker.enable", Version.getInstance().isLocalBuild())) {
  • trunk/src/org/openstreetmap/josm/gui/preferences/server/AuthenticationPreferencesPanel.java

    r6248 r6349  
    4141    /** the panel for the OAuth authentication parameters */
    4242    private OAuthAuthenticationPreferencesPanel pnlOAuthPreferences;
     43    /** the panel for messages notifier preferences */
     44    private MessagesNotifierPanel pnlMessagesPreferences;
    4345
    4446    /**
     
    7476        bg.add(rbOAuth);
    7577
    76         //-- add the panel which will hld the authentication parameters
     78        //-- add the panel which will hold the authentication parameters
    7779        gc.gridx = 0;
    7880        gc.gridy = 1;
     
    8486        pnlAuthenticationParameteters.setLayout(new BorderLayout());
    8587
    86         //-- the two panel for authentication parameters
     88        //-- the two panels for authentication parameters
    8789        pnlBasicAuthPreferences = new BasicAuthenticationPreferencesPanel();
    8890        pnlOAuthPreferences = new OAuthAuthenticationPreferencesPanel();
     
    9092        rbBasicAuthentication.setSelected(true);
    9193        pnlAuthenticationParameteters.add(pnlBasicAuthPreferences, BorderLayout.CENTER);
     94       
     95        //-- the panel for messages preferences
     96        gc.gridy = 2;
     97        gc.fill = GridBagConstraints.NONE;
     98        add(pnlMessagesPreferences = new MessagesNotifierPanel(), gc);
    9299    }
    93100
     101    /**
     102     * Constructs a new {@code AuthenticationPreferencesPanel}.
     103     */
    94104    public AuthenticationPreferencesPanel() {
    95105        build();
     
    97107    }
    98108
     109    /**
     110     * Initializes the panel from preferences
     111     */
    99112    public void initFromPreferences() {
    100113        String authMethod = Main.pref.get("osm-server.auth-method", "basic");
     
    109122        pnlBasicAuthPreferences.initFromPreferences();
    110123        pnlOAuthPreferences.initFromPreferences();
     124        pnlMessagesPreferences.initFromPreferences();
    111125    }
    112126
     127    /**
     128     * Saves the current values to preferences
     129     */
    113130    public void saveToPreferences() {
    114131        // save the authentication method
     
    131148            pnlOAuthPreferences.saveToPreferences();
    132149        }
     150        // save message notifications preferences. To be done after authentication preferences.
     151        pnlMessagesPreferences.saveToPreferences();
    133152    }
    134153
  • trunk/src/org/openstreetmap/josm/io/OsmApi.java

    r6317 r6349  
    564564    }
    565565
    566     protected boolean isUsingOAuth() {
    567         String authMethod = Main.pref.get("osm-server.auth-method", "basic");
    568         return authMethod.equals("oauth");
     566    /**
     567     * Determines if JOSM is configured to access OSM API via OAuth
     568     * @return {@code true} if JOSM is configured to access OSM API via OAuth, {@code false} otherwise
     569     * @since 6349
     570     */
     571    public static final boolean isUsingOAuth() {
     572        return "oauth".equals(Main.pref.get("osm-server.auth-method", "basic"));
    569573    }
    570574
  • trunk/src/org/openstreetmap/josm/io/OsmServerUserInfoReader.java

    r5434 r6349  
    2929    }
    3030
    31     static public  UserInfo buildFromXML(Document document) throws OsmDataParsingException{
     31    /**
     32     * Parses the given XML data and returns the associated user info.
     33     * @param document The XML contents
     34     * @return The user info
     35     * @throws OsmDataParsingException if parsing goes wrong
     36     */
     37    static public UserInfo buildFromXML(Document document) throws OsmDataParsingException {
    3238        try {
    3339            XPathFactory factory = XPathFactory.newInstance();
     
    105111                userInfo.setLanguages(languages);
    106112            }
     113           
     114            // -- messages
     115            xmlNode = (Node)xpath.compile("/osm/user[1]/messages/received").evaluate(document, XPathConstants.NODE);
     116            if (xmlNode != null) {
     117                v = getAttribute(xmlNode, "unread");
     118                if (v == null)
     119                    throw new OsmDataParsingException(tr("Missing attribute ''{0}'' on XML tag ''{1}''.", "unread", "received"));
     120                try {
     121                    userInfo.setUnreadMessages(Integer.parseInt(v));
     122                } catch(NumberFormatException e) {
     123                    throw new OsmDataParsingException(tr("Illegal value for attribute ''{0}'' on XML tag ''{1}''. Got {2}.", "unread", "received", v));
     124                }
     125            }
     126           
    107127            return userInfo;
    108128        } catch(XPathException e) {
     
    111131    }
    112132
     133    /**
     134     * Constructs a new {@code OsmServerUserInfoReader}.
     135     */
    113136    public OsmServerUserInfoReader() {
    114137        setDoAuthenticate(true);
  • trunk/src/org/openstreetmap/josm/io/auth/CredentialsManager.java

    r6070 r6349  
    99import org.openstreetmap.josm.gui.JosmUserIdentityManager;
    1010import org.openstreetmap.josm.io.OsmApi;
     11import org.openstreetmap.josm.tools.CheckParameterUtil;
    1112import org.openstreetmap.josm.tools.Utils;
    1213
     
    1516 *
    1617 * Currently, it defaults to replying an instance of {@link JosmPreferencesCredentialAgent}.
    17  *
     18 * @since 2641
    1819 */
    1920public class CredentialsManager implements CredentialsAgent {
     
    5657    }
    5758
    58     /*****
    59      * non-static fields and methods
     59    /* non-static fields and methods */
     60
     61    /**
     62     * The credentials agent doing the real stuff
    6063     */
    61 
    6264    private CredentialsAgent delegate;
    6365
     66    /**
     67     * Constructs a new {@code CredentialsManager}.
     68     * @param delegate The credentials agent backing this credential manager. Must not be {@code null}
     69     */
    6470    public CredentialsManager(CredentialsAgent delegate) {
     71        CheckParameterUtil.ensureParameterNotNull(delegate, "delegate");
    6572        this.delegate = delegate;
    6673    }
     74   
     75    /**
     76     * Returns type of credentials agent backing this credentials manager.
     77     * @return The type of credentials agent
     78     */
     79    public final Class<? extends CredentialsAgent> getCredentialsAgentClass () {
     80        return delegate.getClass();
     81    }
    6782
     83    /**
     84     * Returns the username for OSM API
     85     * @return the username for OSM API
     86     */
    6887    public String getUsername() {
    6988        return getUsername(OsmApi.getOsmApi().getHost());
    7089    }
    7190
     91    /**
     92     * Returns the username for a given host
     93     * @param host The host for which username is wanted
     94     * @return The username for {@code host}
     95     */
    7296    public String getUsername(String host) {
    7397        String username = null;
  • trunk/src/org/openstreetmap/josm/io/auth/DefaultAuthenticator.java

    r5266 r6349  
    77import java.util.Map;
    88
    9 import org.openstreetmap.josm.Main;
     9import org.openstreetmap.josm.io.OsmApi;
    1010
    1111/**
     
    4343            if (getRequestorType().equals(Authenticator.RequestorType.SERVER)) {
    4444                // if we are working with OAuth we don't prompt for a password
    45                 //
    46                 String authMethod = Main.pref.get("osm-server.auth-method", "basic");
    47                 if (authMethod.equals("oauth"))
     45                if (OsmApi.isUsingOAuth())
    4846                    return null;
    4947            }
Note: See TracChangeset for help on using the changeset viewer.