1 package net.pterodactylus.sone.core;
3 import net.pterodactylus.sone.fcp.FcpInterface.FullAccessRequired;
4 import net.pterodactylus.util.config.Configuration;
5 import net.pterodactylus.util.config.ConfigurationException;
8 * Loads preferences stored in a {@link Configuration} into a {@link
11 public class PreferencesLoader {
13 private final Preferences preferences;
15 public PreferencesLoader(Preferences preferences) {
16 this.preferences = preferences;
19 public void loadFrom(Configuration configuration) {
20 loadInsertionDelay(configuration);
21 loadPostsPerPage(configuration);
22 loadImagesPerPage(configuration);
23 loadCharactersPerPost(configuration);
24 loadPostCutOffLength(configuration);
25 loadRequireFullAccess(configuration);
26 loadPositiveTrust(configuration);
27 loadNegativeTrust(configuration);
28 loadTrustComment(configuration);
29 loadFcpInterfaceActive(configuration);
30 loadFcpFullAccessRequired(configuration);
33 private void loadInsertionDelay(Configuration configuration) {
34 preferences.setInsertionDelay(configuration.getIntValue(
35 "Option/InsertionDelay").getValue(null));
38 private void loadPostsPerPage(Configuration configuration) {
39 preferences.setPostsPerPage(
40 configuration.getIntValue("Option/PostsPerPage")
44 private void loadImagesPerPage(Configuration configuration) {
45 preferences.setImagesPerPage(
46 configuration.getIntValue("Option/ImagesPerPage")
50 private void loadCharactersPerPost(Configuration configuration) {
51 preferences.setCharactersPerPost(
52 configuration.getIntValue("Option/CharactersPerPost")
56 private void loadPostCutOffLength(Configuration configuration) {
58 preferences.setPostCutOffLength(
59 configuration.getIntValue("Option/PostCutOffLength")
61 } catch (IllegalArgumentException iae1) {
62 /* previous versions allowed -1, ignore and use default. */
66 private void loadRequireFullAccess(Configuration configuration) {
67 preferences.setRequireFullAccess(
68 configuration.getBooleanValue("Option/RequireFullAccess")
72 private void loadPositiveTrust(Configuration configuration) {
73 preferences.setPositiveTrust(
74 configuration.getIntValue("Option/PositiveTrust")
78 private void loadNegativeTrust(Configuration configuration) {
79 preferences.setNegativeTrust(
80 configuration.getIntValue("Option/NegativeTrust")
84 private void loadTrustComment(Configuration configuration) {
85 preferences.setTrustComment(
86 configuration.getStringValue("Option/TrustComment")
90 private void loadFcpInterfaceActive(Configuration configuration) {
91 preferences.setFcpInterfaceActive(configuration.getBooleanValue(
92 "Option/ActivateFcpInterface").getValue(null));
95 private void loadFcpFullAccessRequired(Configuration configuration) {
96 Integer fullAccessRequiredInteger = configuration
97 .getIntValue("Option/FcpFullAccessRequired").getValue(null);
98 preferences.setFcpFullAccessRequired(
99 (fullAccessRequiredInteger == null) ? null :
100 FullAccessRequired.values()[fullAccessRequiredInteger]);