diff --git a/platform-independent/java/gui/src/main/java/com/lyndir/masterpassword/gui/view/UserContentPanel.java b/platform-independent/java/gui/src/main/java/com/lyndir/masterpassword/gui/view/UserContentPanel.java index 25bb3b2b..8ba63405 100644 --- a/platform-independent/java/gui/src/main/java/com/lyndir/masterpassword/gui/view/UserContentPanel.java +++ b/platform-independent/java/gui/src/main/java/com/lyndir/masterpassword/gui/view/UserContentPanel.java @@ -604,6 +604,11 @@ public class UserContentPanel extends JPanel implements MasterPassword.Listener, user.getPreferences().getDefaultType(), user.getPreferences()::setDefaultType ), Components.strut() ); + components.add( Components.label( "Default Login Type:" ), + Components.comboBox( MPResultType.values(), MPResultType::getLongName, + user.getPreferences().getDefaultLoginType(), user.getPreferences()::setDefaultLoginType), + Components.strut() ); + components.add( Components.checkBox( "Hide Passwords", user.getPreferences().isHidePasswords(), user.getPreferences()::setHidePasswords ) ); @@ -639,7 +644,7 @@ public class UserContentPanel extends JPanel implements MasterPassword.Listener, components.add( Components.label( "Login Type:" ), Components.comboBox( MPResultType.values(), type -> - getTypeDescription( type, user.getAlgorithm().mpw_default_login_type() ), + getTypeDescription( type, user.getPreferences().getDefaultLoginType() ), site.getLoginType(), site::setLoginType ), Components.strut() ); diff --git a/platform-independent/java/model/src/main/java/com/lyndir/masterpassword/model/MPUserPreferences.java b/platform-independent/java/model/src/main/java/com/lyndir/masterpassword/model/MPUserPreferences.java index d7bab23f..5749335c 100644 --- a/platform-independent/java/model/src/main/java/com/lyndir/masterpassword/model/MPUserPreferences.java +++ b/platform-independent/java/model/src/main/java/com/lyndir/masterpassword/model/MPUserPreferences.java @@ -13,6 +13,10 @@ public interface MPUserPreferences { void setDefaultType(@Nullable MPResultType defaultType); + MPResultType getDefaultLoginType(); + + void setDefaultLoginType(@Nullable MPResultType defaultLoginType); + boolean isHidePasswords(); void setHidePasswords(boolean hidePasswords); diff --git a/platform-independent/java/model/src/main/java/com/lyndir/masterpassword/model/impl/MPBasicSite.java b/platform-independent/java/model/src/main/java/com/lyndir/masterpassword/model/impl/MPBasicSite.java index 9b646d15..e4e177c4 100644 --- a/platform-independent/java/model/src/main/java/com/lyndir/masterpassword/model/impl/MPBasicSite.java +++ b/platform-independent/java/model/src/main/java/com/lyndir/masterpassword/model/impl/MPBasicSite.java @@ -56,7 +56,7 @@ public abstract class MPBasicSite, Q extends MPQuestion> ext this.algorithm = (algorithm != null)? algorithm: this.user.getAlgorithm(); this.counter = (counter != null)? counter: this.algorithm.mpw_default_counter(); this.resultType = (resultType != null)? resultType: this.user.getPreferences().getDefaultType(); - this.loginType = (loginType != null)? loginType: this.algorithm.mpw_default_login_type(); + this.loginType = (loginType != null)? loginType: this.user.getPreferences().getDefaultLoginType(); } // - Meta @@ -125,7 +125,7 @@ public abstract class MPBasicSite, Q extends MPQuestion> ext if (this.loginType == loginType) return; - this.loginType = ifNotNullElse( loginType, getAlgorithm().mpw_default_login_type() ); + this.loginType = ifNotNullElse( loginType, this.user.getPreferences().getDefaultLoginType() ); setChanged(); } diff --git a/platform-independent/java/model/src/main/java/com/lyndir/masterpassword/model/impl/MPBasicUserPreferences.java b/platform-independent/java/model/src/main/java/com/lyndir/masterpassword/model/impl/MPBasicUserPreferences.java index a32363f7..b69d3410 100644 --- a/platform-independent/java/model/src/main/java/com/lyndir/masterpassword/model/impl/MPBasicUserPreferences.java +++ b/platform-independent/java/model/src/main/java/com/lyndir/masterpassword/model/impl/MPBasicUserPreferences.java @@ -14,6 +14,8 @@ public class MPBasicUserPreferences> implements MPUserP @Nullable private MPResultType defaultType; + @Nullable + private MPResultType defaultLoginType; private boolean hidePasswords; public MPBasicUserPreferences(final U user) { @@ -34,6 +36,16 @@ public class MPBasicUserPreferences> implements MPUserP this.defaultType = defaultType; } + @Override + public MPResultType getDefaultLoginType() { + return (defaultLoginType != null) ? defaultLoginType : user.getAlgorithm().mpw_default_login_type(); + } + + @Override + public void setDefaultLoginType(@Nullable final MPResultType defaultLoginType) { + this.defaultLoginType = defaultLoginType; + } + @Override public boolean isHidePasswords() { return hidePasswords; diff --git a/platform-independent/java/model/src/main/java/com/lyndir/masterpassword/model/impl/MPFileUser.java b/platform-independent/java/model/src/main/java/com/lyndir/masterpassword/model/impl/MPFileUser.java index d05ece6d..57081991 100755 --- a/platform-independent/java/model/src/main/java/com/lyndir/masterpassword/model/impl/MPFileUser.java +++ b/platform-independent/java/model/src/main/java/com/lyndir/masterpassword/model/impl/MPFileUser.java @@ -62,18 +62,19 @@ public class MPFileUser extends MPBasicUser { } public MPFileUser(final String fullName, @Nullable final byte[] keyID, final MPAlgorithm algorithm, final File location) { - this( fullName, keyID, algorithm, 0, null, new Instant(), false, + this( fullName, keyID, algorithm, 0, null, null, new Instant(), false, MPMarshaller.ContentMode.PROTECTED, MPMarshalFormat.DEFAULT, location ); } public MPFileUser(final String fullName, @Nullable final byte[] keyID, final MPAlgorithm algorithm, final int avatar, - @Nullable final MPResultType defaultType, final ReadableInstant lastUsed, final boolean hidePasswords, - final MPMarshaller.ContentMode contentMode, final MPMarshalFormat format, final File location) { + @Nullable final MPResultType defaultType, @Nullable final MPResultType defaultLoginType, + final ReadableInstant lastUsed, final boolean hidePasswords, final MPMarshaller.ContentMode contentMode, + final MPMarshalFormat format, final File location) { super( avatar, fullName, algorithm ); this.keyID = (keyID != null)? keyID.clone(): null; this.lastUsed = lastUsed; - this.preferences = new MPFileUserPreferences( this, defaultType, hidePasswords ); + this.preferences = new MPFileUserPreferences( this, defaultType, defaultLoginType, hidePasswords); this.format = format; this.contentMode = contentMode; diff --git a/platform-independent/java/model/src/main/java/com/lyndir/masterpassword/model/impl/MPFileUserPreferences.java b/platform-independent/java/model/src/main/java/com/lyndir/masterpassword/model/impl/MPFileUserPreferences.java index b800f0c6..acf1a666 100644 --- a/platform-independent/java/model/src/main/java/com/lyndir/masterpassword/model/impl/MPFileUserPreferences.java +++ b/platform-independent/java/model/src/main/java/com/lyndir/masterpassword/model/impl/MPFileUserPreferences.java @@ -10,10 +10,11 @@ import javax.annotation.Nullable; */ public class MPFileUserPreferences extends MPBasicUserPreferences { - public MPFileUserPreferences(final MPFileUser user, @Nullable final MPResultType defaultType, final boolean hidePasswords) { + public MPFileUserPreferences(final MPFileUser user, @Nullable final MPResultType defaultType, @Nullable final MPResultType defaultLoginType, final boolean hidePasswords) { super( user ); setDefaultType( defaultType ); + setDefaultLoginType(defaultLoginType); setHidePasswords( hidePasswords ); } @@ -26,6 +27,15 @@ public class MPFileUserPreferences extends MPBasicUserPreferences { getUser().setChanged(); } + @Override + public void setDefaultLoginType(@Nullable final MPResultType defaultLoginType) { + if (getDefaultLoginType() == defaultLoginType) + return; + + super.setDefaultLoginType(defaultLoginType); + getUser().setChanged(); + } + @Override public void setHidePasswords(final boolean hidePasswords) { if (Objects.equals( isHidePasswords(), hidePasswords )) diff --git a/platform-independent/java/model/src/main/java/com/lyndir/masterpassword/model/impl/MPFlatMarshaller.java b/platform-independent/java/model/src/main/java/com/lyndir/masterpassword/model/impl/MPFlatMarshaller.java index b3cca47c..aac53f3b 100644 --- a/platform-independent/java/model/src/main/java/com/lyndir/masterpassword/model/impl/MPFlatMarshaller.java +++ b/platform-independent/java/model/src/main/java/com/lyndir/masterpassword/model/impl/MPFlatMarshaller.java @@ -57,6 +57,7 @@ public class MPFlatMarshaller implements MPMarshaller { content.append( "# Key ID: " ).append( user.exportKeyID() ).append( '\n' ); content.append( "# Algorithm: " ).append( user.getAlgorithm().version().toInt() ).append( '\n' ); content.append( "# Default Type: " ).append( user.getPreferences().getDefaultType().getType() ).append( '\n' ); + content.append( "# Default Login Type: " ).append( user.getPreferences().getDefaultLoginType().getType() ).append( '\n' ); content.append( "# Passwords: " ).append( user.getContentMode().name() ).append( '\n' ); content.append( "##\n" ); content.append( "#\n" ); diff --git a/platform-independent/java/model/src/main/java/com/lyndir/masterpassword/model/impl/MPFlatUnmarshaller.java b/platform-independent/java/model/src/main/java/com/lyndir/masterpassword/model/impl/MPFlatUnmarshaller.java index 9d6e290f..8a6e0bc9 100644 --- a/platform-independent/java/model/src/main/java/com/lyndir/masterpassword/model/impl/MPFlatUnmarshaller.java +++ b/platform-independent/java/model/src/main/java/com/lyndir/masterpassword/model/impl/MPFlatUnmarshaller.java @@ -56,11 +56,12 @@ public class MPFlatUnmarshaller implements MPUnmarshaller { int mpVersion = 0, avatar = 0; boolean clearContent = false, headerStarted = false; MPResultType defaultType = null; + MPResultType defaultLoginType = null; Instant date = null; //noinspection HardcodedLineSeparator for (final String line : CharStreams.readLines( reader )) - // Header delimitor. + // Header delimiter. if (line.startsWith( "##" )) { if (!headerStarted) // Starts the header. @@ -68,7 +69,7 @@ public class MPFlatUnmarshaller implements MPUnmarshaller { else if ((fullName != null) && (keyID != null)) // Ends the header. return new MPFileUser( - fullName, keyID, MPAlgorithm.Version.fromInt( mpVersion ).getAlgorithm(), avatar, defaultType, + fullName, keyID, MPAlgorithm.Version.fromInt( mpVersion ).getAlgorithm(), avatar, defaultType, defaultLoginType, date, false, clearContent? MPMarshaller.ContentMode.VISIBLE: MPMarshaller.ContentMode.PROTECTED, MPMarshalFormat.Flat, file ); @@ -93,6 +94,8 @@ public class MPFlatUnmarshaller implements MPUnmarshaller { clearContent = "visible".equalsIgnoreCase( value ); else if ("Default Type".equalsIgnoreCase( name )) defaultType = MPResultType.forType( ConversionUtils.toIntegerNN( value ) ); + else if ("Default Login Type".equalsIgnoreCase( name )) + defaultLoginType = MPResultType.forType( ConversionUtils.toIntegerNN( value ) ); else if ("Date".equalsIgnoreCase( name )) date = MPModelConstants.dateTimeFormatter.parseDateTime( value ).toInstant(); } diff --git a/platform-independent/java/model/src/main/java/com/lyndir/masterpassword/model/impl/MPJSONFile.java b/platform-independent/java/model/src/main/java/com/lyndir/masterpassword/model/impl/MPJSONFile.java index 5cb3b85a..0a1eee23 100644 --- a/platform-independent/java/model/src/main/java/com/lyndir/masterpassword/model/impl/MPJSONFile.java +++ b/platform-independent/java/model/src/main/java/com/lyndir/masterpassword/model/impl/MPJSONFile.java @@ -20,11 +20,6 @@ package com.lyndir.masterpassword.model.impl; import static com.lyndir.lhunath.opal.system.util.ObjectUtils.*; -import com.fasterxml.jackson.annotation.JsonAutoDetect; -import com.fasterxml.jackson.annotation.PropertyAccessor; -import com.fasterxml.jackson.core.util.DefaultPrettyPrinter; -import com.fasterxml.jackson.core.util.Separators; -import com.fasterxml.jackson.databind.ObjectMapper; import com.google.common.primitives.UnsignedInteger; import com.lyndir.lhunath.opal.system.CodeUtils; import com.lyndir.masterpassword.*; @@ -66,6 +61,7 @@ public class MPJSONFile extends MPJSONAnyObject { user._ext_mpw = new User.Ext() { { default_type = modelUser.getPreferences().getDefaultType(); + default_login_type = modelUser.getPreferences().getDefaultLoginType(); hide_passwords = modelUser.getPreferences().isHidePasswords(); } }; @@ -133,6 +129,7 @@ public class MPJSONFile extends MPJSONAnyObject { return new MPFileUser( user.full_name, CodeUtils.decodeHex( user.key_id ), algorithm, user.avatar, (user._ext_mpw != null)? user._ext_mpw.default_type: null, + (user._ext_mpw != null)? user._ext_mpw.default_login_type : null, (user.last_used != null)? MPModelConstants.dateTimeFormatter.parseDateTime( user.last_used ): new Instant(), (user._ext_mpw != null) && user._ext_mpw.hide_passwords, export.redacted? MPMarshaller.ContentMode.PROTECTED: MPMarshaller.ContentMode.VISIBLE, @@ -211,6 +208,8 @@ public class MPJSONFile extends MPJSONAnyObject { @Nullable MPResultType default_type; + @Nullable + MPResultType default_login_type; boolean hide_passwords; } }