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 loadFcpInterfaceActive(configuration);
27 loadFcpFullAccessRequired(configuration);
30 private void loadInsertionDelay(Configuration configuration) {
31 preferences.setNewInsertionDelay(configuration.getIntValue(
32 "Option/InsertionDelay").getValue(null));
35 private void loadPostsPerPage(Configuration configuration) {
36 preferences.setNewPostsPerPage(
37 configuration.getIntValue("Option/PostsPerPage")
41 private void loadImagesPerPage(Configuration configuration) {
42 preferences.setNewImagesPerPage(
43 configuration.getIntValue("Option/ImagesPerPage")
47 private void loadCharactersPerPost(Configuration configuration) {
48 preferences.setNewCharactersPerPost(
49 configuration.getIntValue("Option/CharactersPerPost")
53 private void loadPostCutOffLength(Configuration configuration) {
55 preferences.setNewPostCutOffLength(
56 configuration.getIntValue("Option/PostCutOffLength")
58 } catch (IllegalArgumentException iae1) {
59 /* previous versions allowed -1, ignore and use default. */
63 private void loadRequireFullAccess(Configuration configuration) {
64 preferences.setNewRequireFullAccess(
65 configuration.getBooleanValue("Option/RequireFullAccess")
69 private void loadFcpInterfaceActive(Configuration configuration) {
70 preferences.setNewFcpInterfaceActive(configuration.getBooleanValue(
71 "Option/ActivateFcpInterface").getValue(null));
74 private void loadFcpFullAccessRequired(Configuration configuration) {
75 Integer fullAccessRequiredInteger = configuration
76 .getIntValue("Option/FcpFullAccessRequired").getValue(null);
77 preferences.setNewFcpFullAccessRequired(
78 (fullAccessRequiredInteger == null) ? null :
79 FullAccessRequired.values()[fullAccessRequiredInteger]);