2 * Sone - Preferences.java - Copyright © 2013 David Roden
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 package net.pterodactylus.sone.core;
20 import net.pterodactylus.sone.fcp.FcpInterface;
21 import net.pterodactylus.sone.fcp.FcpInterface.FullAccessRequired;
24 * Convenience interface for external classes that want to access the core’s
27 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
29 public class Preferences {
31 /** The wrapped options. */
32 private final Options options;
35 * Creates a new preferences object wrapped around the given options.
40 public Preferences(Options options) {
41 this.options = options;
45 * Returns the insertion delay.
47 * @return The insertion delay
49 public int getInsertionDelay() {
50 return options.getIntegerOption("InsertionDelay").get();
54 * Validates the given insertion delay.
56 * @param insertionDelay
57 * The insertion delay to validate
58 * @return {@code true} if the given insertion delay was valid,
59 * {@code false} otherwise
61 public boolean validateInsertionDelay(Integer insertionDelay) {
62 return options.getIntegerOption("InsertionDelay").validate(insertionDelay);
66 * Sets the insertion delay
68 * @param insertionDelay
69 * The new insertion delay, or {@code null} to restore it to
71 * @return This preferences
73 public Preferences setInsertionDelay(Integer insertionDelay) {
74 options.getIntegerOption("InsertionDelay").set(insertionDelay);
79 * Returns the number of posts to show per page.
81 * @return The number of posts to show per page
83 public int getPostsPerPage() {
84 return options.getIntegerOption("PostsPerPage").get();
88 * Validates the number of posts per page.
91 * The number of posts per page
92 * @return {@code true} if the number of posts per page was valid,
93 * {@code false} otherwise
95 public boolean validatePostsPerPage(Integer postsPerPage) {
96 return options.getIntegerOption("PostsPerPage").validate(postsPerPage);
100 * Sets the number of posts to show per page.
102 * @param postsPerPage
103 * The number of posts to show per page
104 * @return This preferences object
106 public Preferences setPostsPerPage(Integer postsPerPage) {
107 options.getIntegerOption("PostsPerPage").set(postsPerPage);
112 * Returns the number of images to show per page.
114 * @return The number of images to show per page
116 public int getImagesPerPage() {
117 return options.getIntegerOption("ImagesPerPage").get();
121 * Validates the number of images per page.
123 * @param imagesPerPage
124 * The number of images per page
125 * @return {@code true} if the number of images per page was valid,
126 * {@code false} otherwise
128 public boolean validateImagesPerPage(Integer imagesPerPage) {
129 return options.getIntegerOption("ImagesPerPage").validate(imagesPerPage);
133 * Sets the number of images per page.
135 * @param imagesPerPage
136 * The number of images per page
137 * @return This preferences object
139 public Preferences setImagesPerPage(Integer imagesPerPage) {
140 options.getIntegerOption("ImagesPerPage").set(imagesPerPage);
145 * Returns the number of characters per post, or <code>-1</code> if the
146 * posts should not be cut off.
148 * @return The numbers of characters per post
150 public int getCharactersPerPost() {
151 return options.getIntegerOption("CharactersPerPost").get();
155 * Validates the number of characters per post.
157 * @param charactersPerPost
158 * The number of characters per post
159 * @return {@code true} if the number of characters per post was valid,
160 * {@code false} otherwise
162 public boolean validateCharactersPerPost(Integer charactersPerPost) {
163 return options.getIntegerOption("CharactersPerPost").validate(charactersPerPost);
167 * Sets the number of characters per post.
169 * @param charactersPerPost
170 * The number of characters per post, or <code>-1</code> to
171 * not cut off the posts
172 * @return This preferences objects
174 public Preferences setCharactersPerPost(Integer charactersPerPost) {
175 options.getIntegerOption("CharactersPerPost").set(charactersPerPost);
180 * Returns the number of characters the shortened post should have.
182 * @return The number of characters of the snippet
184 public int getPostCutOffLength() {
185 return options.getIntegerOption("PostCutOffLength").get();
189 * Validates the number of characters after which to cut off the post.
191 * @param postCutOffLength
192 * The number of characters of the snippet
193 * @return {@code true} if the number of characters of the snippet is
194 * valid, {@code false} otherwise
196 public boolean validatePostCutOffLength(Integer postCutOffLength) {
197 return options.getIntegerOption("PostCutOffLength").validate(postCutOffLength);
201 * Sets the number of characters the shortened post should have.
203 * @param postCutOffLength
204 * The number of characters of the snippet
205 * @return This preferences
207 public Preferences setPostCutOffLength(Integer postCutOffLength) {
208 options.getIntegerOption("PostCutOffLength").set(postCutOffLength);
213 * Returns whether Sone requires full access to be even visible.
215 * @return {@code true} if Sone requires full access, {@code false}
218 public boolean isRequireFullAccess() {
219 return options.getBooleanOption("RequireFullAccess").get();
223 * Sets whether Sone requires full access to be even visible.
225 * @param requireFullAccess
226 * {@code true} if Sone requires full access, {@code false}
229 public void setRequireFullAccess(Boolean requireFullAccess) {
230 options.getBooleanOption("RequireFullAccess").set(requireFullAccess);
234 * Returns the positive trust.
236 * @return The positive trust
238 public int getPositiveTrust() {
239 return options.getIntegerOption("PositiveTrust").get();
243 * Validates the positive trust.
245 * @param positiveTrust
246 * The positive trust to validate
247 * @return {@code true} if the positive trust was valid, {@code false}
250 public boolean validatePositiveTrust(Integer positiveTrust) {
251 return options.getIntegerOption("PositiveTrust").validate(positiveTrust);
255 * Sets the positive trust.
257 * @param positiveTrust
258 * The new positive trust, or {@code null} to restore it to
260 * @return This preferences
262 public Preferences setPositiveTrust(Integer positiveTrust) {
263 options.getIntegerOption("PositiveTrust").set(positiveTrust);
268 * Returns the negative trust.
270 * @return The negative trust
272 public int getNegativeTrust() {
273 return options.getIntegerOption("NegativeTrust").get();
277 * Validates the negative trust.
279 * @param negativeTrust
280 * The negative trust to validate
281 * @return {@code true} if the negative trust was valid, {@code false}
284 public boolean validateNegativeTrust(Integer negativeTrust) {
285 return options.getIntegerOption("NegativeTrust").validate(negativeTrust);
289 * Sets the negative trust.
291 * @param negativeTrust
292 * The negative trust, or {@code null} to restore it to the
294 * @return The preferences
296 public Preferences setNegativeTrust(Integer negativeTrust) {
297 options.getIntegerOption("NegativeTrust").set(negativeTrust);
302 * Returns the trust comment. This is the comment that is set in the web
303 * of trust when a trust value is assigned to an identity.
305 * @return The trust comment
307 public String getTrustComment() {
308 return options.getStringOption("TrustComment").get();
312 * Sets the trust comment.
314 * @param trustComment
315 * The trust comment, or {@code null} to restore it to the
317 * @return This preferences
319 public Preferences setTrustComment(String trustComment) {
320 options.getStringOption("TrustComment").set(trustComment);
325 * Returns whether the {@link FcpInterface FCP interface} is currently
328 * @see FcpInterface#setActive(boolean)
329 * @return {@code true} if the FCP interface is currently active,
330 * {@code false} otherwise
332 public boolean isFcpInterfaceActive() {
333 return options.getBooleanOption("ActivateFcpInterface").get();
337 * Sets whether the {@link FcpInterface FCP interface} is currently
340 * @see FcpInterface#setActive(boolean)
341 * @param fcpInterfaceActive
342 * {@code true} to activate the FCP interface, {@code false}
343 * to deactivate the FCP interface
344 * @return This preferences object
346 public Preferences setFcpInterfaceActive(boolean fcpInterfaceActive) {
347 options.getBooleanOption("ActivateFcpInterface").set(fcpInterfaceActive);
352 * Returns the action level for which full access to the FCP interface
355 * @return The action level for which full access to the FCP interface
358 public FullAccessRequired getFcpFullAccessRequired() {
359 return FullAccessRequired.values()[options.getIntegerOption("FcpFullAccessRequired").get()];
363 * Sets the action level for which full access to the FCP interface is
366 * @param fcpFullAccessRequired
368 * @return This preferences
370 public Preferences setFcpFullAccessRequired(FullAccessRequired fcpFullAccessRequired) {
371 options.getIntegerOption("FcpFullAccessRequired").set((fcpFullAccessRequired != null) ? fcpFullAccessRequired.ordinal() : null);