/*
- * Sone - OptionsPage.java - Copyright © 2010 David Roden
+ * Sone - OptionsPage.java - Copyright © 2010–2013 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
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;
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);
- String avatarId =request.getHttpRequest().getPartAsStringFailsafe("avatar-image", 36);
- currentSone.setAvatar(webInterface.getCore().getImage(avatarId, false));
+ currentSone.getOptions().setShowNewReplyNotifications(showNotificationNewReplies);
+ String showCustomAvatars = request.getHttpRequest().getPartAsStringFailsafe("show-custom-avatars", 32);
+ currentSone.getOptions().setShowCustomAvatars(ShowCustomAvatars.valueOf(showCustomAvatars));
webInterface.getCore().touchConfiguration();
}
Integer insertionDelay = Numbers.safeParseInteger(request.getHttpRequest().getPartAsStringFailsafe("insertion-delay", 16));
} else {
preferences.setPostsPerPage(postsPerPage);
}
+ Integer imagesPerPage = Numbers.safeParseInteger(request.getHttpRequest().getPartAsStringFailsafe("images-per-page", 4), null);
+ if (!preferences.validateImagesPerPage(imagesPerPage)) {
+ fieldErrors.add("images-per-page");
+ } else {
+ preferences.setImagesPerPage(imagesPerPage);
+ }
Integer charactersPerPost = Numbers.safeParseInteger(request.getHttpRequest().getPartAsStringFailsafe("characters-per-post", 10), null);
if (!preferences.validateCharactersPerPost(charactersPerPost)) {
fieldErrors.add("characters-per-post");
Integer fcpFullAccessRequiredInteger = Numbers.safeParseInteger(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("avatar-image", currentSone.getAvatar());
+ 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());
}
}