/*
- * Sone - OptionsPage.java - Copyright © 2010 David Roden
+ * Sone - OptionsPage.java - Copyright © 2010–2016 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
package net.pterodactylus.sone.web;
+import static net.pterodactylus.sone.utils.NumberParsers.parseInt;
+
import java.util.ArrayList;
import java.util.List;
-import net.pterodactylus.sone.core.Core.Preferences;
+import net.pterodactylus.sone.core.Preferences;
import net.pterodactylus.sone.data.Sone;
import net.pterodactylus.sone.data.Sone.ShowCustomAvatars;
import net.pterodactylus.sone.fcp.FcpInterface.FullAccessRequired;
import net.pterodactylus.sone.web.page.FreenetRequest;
-import net.pterodactylus.util.number.Numbers;
import net.pterodactylus.util.template.Template;
import net.pterodactylus.util.template.TemplateContext;
import net.pterodactylus.util.web.Method;
List<String> fieldErrors = new ArrayList<String>();
if (currentSone != null) {
boolean autoFollow = request.getHttpRequest().isPartSet("auto-follow");
- currentSone.getOptions().getBooleanOption("AutoFollow").set(autoFollow);
+ currentSone.getOptions().setAutoFollow(autoFollow);
boolean enableSoneInsertNotifications = request.getHttpRequest().isPartSet("enable-sone-insert-notifications");
- currentSone.getOptions().getBooleanOption("EnableSoneInsertNotifications").set(enableSoneInsertNotifications);
+ currentSone.getOptions().setSoneInsertNotificationEnabled(enableSoneInsertNotifications);
boolean showNotificationNewSones = request.getHttpRequest().isPartSet("show-notification-new-sones");
- currentSone.getOptions().getBooleanOption("ShowNotification/NewSones").set(showNotificationNewSones);
+ currentSone.getOptions().setShowNewSoneNotifications(showNotificationNewSones);
boolean showNotificationNewPosts = request.getHttpRequest().isPartSet("show-notification-new-posts");
- currentSone.getOptions().getBooleanOption("ShowNotification/NewPosts").set(showNotificationNewPosts);
+ currentSone.getOptions().setShowNewPostNotifications(showNotificationNewPosts);
boolean showNotificationNewReplies = request.getHttpRequest().isPartSet("show-notification-new-replies");
- currentSone.getOptions().getBooleanOption("ShowNotification/NewReplies").set(showNotificationNewReplies);
+ currentSone.getOptions().setShowNewReplyNotifications(showNotificationNewReplies);
String showCustomAvatars = request.getHttpRequest().getPartAsStringFailsafe("show-custom-avatars", 32);
- currentSone.getOptions().<ShowCustomAvatars> getEnumOption("ShowCustomAvatars").set(ShowCustomAvatars.valueOf(showCustomAvatars));
+ currentSone.getOptions().setShowCustomAvatars(ShowCustomAvatars.valueOf(showCustomAvatars));
webInterface.getCore().touchConfiguration();
}
- Integer insertionDelay = Numbers.safeParseInteger(request.getHttpRequest().getPartAsStringFailsafe("insertion-delay", 16));
+ Integer insertionDelay = parseInt(request.getHttpRequest().getPartAsStringFailsafe("insertion-delay", 16), null);
if (!preferences.validateInsertionDelay(insertionDelay)) {
fieldErrors.add("insertion-delay");
} else {
preferences.setInsertionDelay(insertionDelay);
}
- Integer postsPerPage = Numbers.safeParseInteger(request.getHttpRequest().getPartAsStringFailsafe("posts-per-page", 4), null);
+ Integer postsPerPage = parseInt(request.getHttpRequest().getPartAsStringFailsafe("posts-per-page", 4), null);
if (!preferences.validatePostsPerPage(postsPerPage)) {
fieldErrors.add("posts-per-page");
} else {
preferences.setPostsPerPage(postsPerPage);
}
- Integer charactersPerPost = Numbers.safeParseInteger(request.getHttpRequest().getPartAsStringFailsafe("characters-per-post", 10), null);
+ Integer imagesPerPage = parseInt(request.getHttpRequest().getPartAsStringFailsafe("images-per-page", 4), null);
+ if (!preferences.validateImagesPerPage(imagesPerPage)) {
+ fieldErrors.add("images-per-page");
+ } else {
+ preferences.setImagesPerPage(imagesPerPage);
+ }
+ Integer charactersPerPost = parseInt(request.getHttpRequest().getPartAsStringFailsafe("characters-per-post", 10), null);
if (!preferences.validateCharactersPerPost(charactersPerPost)) {
fieldErrors.add("characters-per-post");
} else {
preferences.setCharactersPerPost(charactersPerPost);
}
- Integer postCutOffLength = Numbers.safeParseInteger(request.getHttpRequest().getPartAsStringFailsafe("post-cut-off-length", 10), null);
+ Integer postCutOffLength = parseInt(request.getHttpRequest().getPartAsStringFailsafe("post-cut-off-length", 10), null);
if (!preferences.validatePostCutOffLength(postCutOffLength)) {
fieldErrors.add("post-cut-off-length");
} else {
}
boolean requireFullAccess = request.getHttpRequest().isPartSet("require-full-access");
preferences.setRequireFullAccess(requireFullAccess);
- Integer positiveTrust = Numbers.safeParseInteger(request.getHttpRequest().getPartAsStringFailsafe("positive-trust", 3));
+ Integer positiveTrust = parseInt(request.getHttpRequest().getPartAsStringFailsafe("positive-trust", 3), null);
if (!preferences.validatePositiveTrust(positiveTrust)) {
fieldErrors.add("positive-trust");
} else {
preferences.setPositiveTrust(positiveTrust);
}
- Integer negativeTrust = Numbers.safeParseInteger(request.getHttpRequest().getPartAsStringFailsafe("negative-trust", 4));
+ Integer negativeTrust = parseInt(request.getHttpRequest().getPartAsStringFailsafe("negative-trust", 4), null);
if (!preferences.validateNegativeTrust(negativeTrust)) {
fieldErrors.add("negative-trust");
} else {
preferences.setTrustComment(trustComment);
boolean fcpInterfaceActive = request.getHttpRequest().isPartSet("fcp-interface-active");
preferences.setFcpInterfaceActive(fcpInterfaceActive);
- Integer fcpFullAccessRequiredInteger = Numbers.safeParseInteger(request.getHttpRequest().getPartAsStringFailsafe("fcp-full-access-required", 1), preferences.getFcpFullAccessRequired().ordinal());
+ Integer fcpFullAccessRequiredInteger = parseInt(request.getHttpRequest().getPartAsStringFailsafe("fcp-full-access-required", 1), preferences.getFcpFullAccessRequired().ordinal());
FullAccessRequired fcpFullAccessRequired = FullAccessRequired.values()[fcpFullAccessRequiredInteger];
preferences.setFcpFullAccessRequired(fcpFullAccessRequired);
- boolean clearOnNextRestart = Boolean.parseBoolean(request.getHttpRequest().getPartAsStringFailsafe("clear-on-next-restart", 5));
- preferences.setClearOnNextRestart(clearOnNextRestart);
- boolean reallyClearOnNextRestart = Boolean.parseBoolean(request.getHttpRequest().getPartAsStringFailsafe("really-clear-on-next-restart", 5));
- preferences.setReallyClearOnNextRestart(reallyClearOnNextRestart);
webInterface.getCore().touchConfiguration();
if (fieldErrors.isEmpty()) {
throw new RedirectException(getPath());
templateContext.set("fieldErrors", fieldErrors);
}
if (currentSone != null) {
- templateContext.set("auto-follow", currentSone.getOptions().getBooleanOption("AutoFollow").get());
- templateContext.set("enable-sone-insert-notifications", currentSone.getOptions().getBooleanOption("EnableSoneInsertNotifications").get());
- templateContext.set("show-notification-new-sones", currentSone.getOptions().getBooleanOption("ShowNotification/NewSones").get());
- templateContext.set("show-notification-new-posts", currentSone.getOptions().getBooleanOption("ShowNotification/NewPosts").get());
- templateContext.set("show-notification-new-replies", currentSone.getOptions().getBooleanOption("ShowNotification/NewReplies").get());
- templateContext.set("show-custom-avatars", currentSone.getOptions().<ShowCustomAvatars> getEnumOption("ShowCustomAvatars").get().name());
+ templateContext.set("auto-follow", currentSone.getOptions().isAutoFollow());
+ templateContext.set("enable-sone-insert-notifications", currentSone.getOptions().isSoneInsertNotificationEnabled());
+ templateContext.set("show-notification-new-sones", currentSone.getOptions().isShowNewSoneNotifications());
+ templateContext.set("show-notification-new-posts", currentSone.getOptions().isShowNewPostNotifications());
+ templateContext.set("show-notification-new-replies", currentSone.getOptions().isShowNewReplyNotifications());
+ templateContext.set("show-custom-avatars", currentSone.getOptions().getShowCustomAvatars().name());
}
templateContext.set("insertion-delay", preferences.getInsertionDelay());
templateContext.set("posts-per-page", preferences.getPostsPerPage());
+ templateContext.set("images-per-page", preferences.getImagesPerPage());
templateContext.set("characters-per-post", preferences.getCharactersPerPost());
templateContext.set("post-cut-off-length", preferences.getPostCutOffLength());
templateContext.set("require-full-access", preferences.isRequireFullAccess());
templateContext.set("trust-comment", preferences.getTrustComment());
templateContext.set("fcp-interface-active", preferences.isFcpInterfaceActive());
templateContext.set("fcp-full-access-required", preferences.getFcpFullAccessRequired().ordinal());
- templateContext.set("clear-on-next-restart", preferences.isClearOnNextRestart());
- templateContext.set("really-clear-on-next-restart", preferences.isReallyClearOnNextRestart());
}
}