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.core.event.InsertionDelayChangedEvent;
21 import net.pterodactylus.sone.fcp.FcpInterface;
22 import net.pterodactylus.sone.fcp.FcpInterface.FullAccessRequired;
24 import com.google.common.eventbus.EventBus;
27 * Convenience interface for external classes that want to access the core’s
30 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
32 public class Preferences {
34 private final EventBus eventBus;
35 private final Options options;
37 public Preferences(EventBus eventBus, Options options) {
38 this.eventBus = eventBus;
39 this.options = options;
43 * Returns the insertion delay.
45 * @return The insertion delay
47 public int getInsertionDelay() {
48 return options.getIntegerOption("InsertionDelay").get();
52 * Validates the given insertion delay.
54 * @param insertionDelay
55 * The insertion delay to validate
56 * @return {@code true} if the given insertion delay was valid,
57 * {@code false} otherwise
59 public boolean validateInsertionDelay(Integer insertionDelay) {
60 return options.getIntegerOption("InsertionDelay").validate(insertionDelay);
64 * Sets the insertion delay
66 * @param insertionDelay
67 * The new insertion delay, or {@code null} to restore it to
69 * @return This preferences
71 public Preferences setInsertionDelay(Integer insertionDelay) {
72 options.getIntegerOption("InsertionDelay").set(insertionDelay);
73 eventBus.post(new InsertionDelayChangedEvent(getInsertionDelay()));
78 * Returns the number of posts to show per page.
80 * @return The number of posts to show per page
82 public int getPostsPerPage() {
83 return options.getIntegerOption("PostsPerPage").get();
87 * Validates the number of posts per page.
90 * The number of posts per page
91 * @return {@code true} if the number of posts per page was valid,
92 * {@code false} otherwise
94 public boolean validatePostsPerPage(Integer postsPerPage) {
95 return options.getIntegerOption("PostsPerPage").validate(postsPerPage);
99 * Sets the number of posts to show per page.
101 * @param postsPerPage
102 * The number of posts to show per page
103 * @return This preferences object
105 public Preferences setPostsPerPage(Integer postsPerPage) {
106 options.getIntegerOption("PostsPerPage").set(postsPerPage);
111 * Returns the number of images to show per page.
113 * @return The number of images to show per page
115 public int getImagesPerPage() {
116 return options.getIntegerOption("ImagesPerPage").get();
120 * Validates the number of images per page.
122 * @param imagesPerPage
123 * The number of images per page
124 * @return {@code true} if the number of images per page was valid,
125 * {@code false} otherwise
127 public boolean validateImagesPerPage(Integer imagesPerPage) {
128 return options.getIntegerOption("ImagesPerPage").validate(imagesPerPage);
132 * Sets the number of images per page.
134 * @param imagesPerPage
135 * The number of images per page
136 * @return This preferences object
138 public Preferences setImagesPerPage(Integer imagesPerPage) {
139 options.getIntegerOption("ImagesPerPage").set(imagesPerPage);
144 * Returns the number of characters per post, or <code>-1</code> if the
145 * posts should not be cut off.
147 * @return The numbers of characters per post
149 public int getCharactersPerPost() {
150 return options.getIntegerOption("CharactersPerPost").get();
154 * Validates the number of characters per post.
156 * @param charactersPerPost
157 * The number of characters per post
158 * @return {@code true} if the number of characters per post was valid,
159 * {@code false} otherwise
161 public boolean validateCharactersPerPost(Integer charactersPerPost) {
162 return options.getIntegerOption("CharactersPerPost").validate(charactersPerPost);
166 * Sets the number of characters per post.
168 * @param charactersPerPost
169 * The number of characters per post, or <code>-1</code> to
170 * not cut off the posts
171 * @return This preferences objects
173 public Preferences setCharactersPerPost(Integer charactersPerPost) {
174 options.getIntegerOption("CharactersPerPost").set(charactersPerPost);
179 * Returns the number of characters the shortened post should have.
181 * @return The number of characters of the snippet
183 public int getPostCutOffLength() {
184 return options.getIntegerOption("PostCutOffLength").get();
188 * Validates the number of characters after which to cut off the post.
190 * @param postCutOffLength
191 * The number of characters of the snippet
192 * @return {@code true} if the number of characters of the snippet is
193 * valid, {@code false} otherwise
195 public boolean validatePostCutOffLength(Integer postCutOffLength) {
196 return options.getIntegerOption("PostCutOffLength").validate(postCutOffLength);
200 * Sets the number of characters the shortened post should have.
202 * @param postCutOffLength
203 * The number of characters of the snippet
204 * @return This preferences
206 public Preferences setPostCutOffLength(Integer postCutOffLength) {
207 options.getIntegerOption("PostCutOffLength").set(postCutOffLength);
212 * Returns whether Sone requires full access to be even visible.
214 * @return {@code true} if Sone requires full access, {@code false}
217 public boolean isRequireFullAccess() {
218 return options.getBooleanOption("RequireFullAccess").get();
222 * Sets whether Sone requires full access to be even visible.
224 * @param requireFullAccess
225 * {@code true} if Sone requires full access, {@code false}
228 public void setRequireFullAccess(Boolean requireFullAccess) {
229 options.getBooleanOption("RequireFullAccess").set(requireFullAccess);
233 * Returns the positive trust.
235 * @return The positive trust
237 public int getPositiveTrust() {
238 return options.getIntegerOption("PositiveTrust").get();
242 * Validates the positive trust.
244 * @param positiveTrust
245 * The positive trust to validate
246 * @return {@code true} if the positive trust was valid, {@code false}
249 public boolean validatePositiveTrust(Integer positiveTrust) {
250 return options.getIntegerOption("PositiveTrust").validate(positiveTrust);
254 * Sets the positive trust.
256 * @param positiveTrust
257 * The new positive trust, or {@code null} to restore it to
259 * @return This preferences
261 public Preferences setPositiveTrust(Integer positiveTrust) {
262 options.getIntegerOption("PositiveTrust").set(positiveTrust);
267 * Returns the negative trust.
269 * @return The negative trust
271 public int getNegativeTrust() {
272 return options.getIntegerOption("NegativeTrust").get();
276 * Validates the negative trust.
278 * @param negativeTrust
279 * The negative trust to validate
280 * @return {@code true} if the negative trust was valid, {@code false}
283 public boolean validateNegativeTrust(Integer negativeTrust) {
284 return options.getIntegerOption("NegativeTrust").validate(negativeTrust);
288 * Sets the negative trust.
290 * @param negativeTrust
291 * The negative trust, or {@code null} to restore it to the
293 * @return The preferences
295 public Preferences setNegativeTrust(Integer negativeTrust) {
296 options.getIntegerOption("NegativeTrust").set(negativeTrust);
301 * Returns the trust comment. This is the comment that is set in the web
302 * of trust when a trust value is assigned to an identity.
304 * @return The trust comment
306 public String getTrustComment() {
307 return options.getStringOption("TrustComment").get();
311 * Sets the trust comment.
313 * @param trustComment
314 * The trust comment, or {@code null} to restore it to the
316 * @return This preferences
318 public Preferences setTrustComment(String trustComment) {
319 options.getStringOption("TrustComment").set(trustComment);
324 * Returns whether the {@link FcpInterface FCP interface} is currently
327 * @see FcpInterface#setActive(boolean)
328 * @return {@code true} if the FCP interface is currently active,
329 * {@code false} otherwise
331 public boolean isFcpInterfaceActive() {
332 return options.getBooleanOption("ActivateFcpInterface").get();
336 * Sets whether the {@link FcpInterface FCP interface} is currently
339 * @see FcpInterface#setActive(boolean)
340 * @param fcpInterfaceActive
341 * {@code true} to activate the FCP interface, {@code false}
342 * to deactivate the FCP interface
343 * @return This preferences object
345 public Preferences setFcpInterfaceActive(boolean fcpInterfaceActive) {
346 options.getBooleanOption("ActivateFcpInterface").set(fcpInterfaceActive);
351 * Returns the action level for which full access to the FCP interface
354 * @return The action level for which full access to the FCP interface
357 public FullAccessRequired getFcpFullAccessRequired() {
358 return FullAccessRequired.values()[options.getIntegerOption("FcpFullAccessRequired").get()];
362 * Sets the action level for which full access to the FCP interface is
365 * @param fcpFullAccessRequired
367 * @return This preferences
369 public Preferences setFcpFullAccessRequired(FullAccessRequired fcpFullAccessRequired) {
370 options.getIntegerOption("FcpFullAccessRequired").set((fcpFullAccessRequired != null) ? fcpFullAccessRequired.ordinal() : null);