From: David ‘Bombe’ Roden Date: Tue, 19 Oct 2010 07:01:17 +0000 (+0200) Subject: Add status fields to Sone accessor. X-Git-Tag: 0.1-RC1~201 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=b1660609f6574ed43afd61d332be9f3764900405;p=Sone.git Add status fields to Sone accessor. --- diff --git a/src/main/java/net/pterodactylus/sone/template/SoneAccessor.java b/src/main/java/net/pterodactylus/sone/template/SoneAccessor.java index d0a287f..e22738a 100644 --- a/src/main/java/net/pterodactylus/sone/template/SoneAccessor.java +++ b/src/main/java/net/pterodactylus/sone/template/SoneAccessor.java @@ -17,6 +17,8 @@ package net.pterodactylus.sone.template; +import net.pterodactylus.sone.core.Core; +import net.pterodactylus.sone.core.Core.SoneStatus; import net.pterodactylus.sone.data.Profile; import net.pterodactylus.sone.data.Sone; import net.pterodactylus.util.template.Accessor; @@ -42,6 +44,19 @@ import net.pterodactylus.util.template.ReflectionAccessor; */ public class SoneAccessor extends ReflectionAccessor { + /** The core. */ + private final Core core; + + /** + * Creates a new Sone accessor. + * + * @param core + * The Sone core + */ + public SoneAccessor(Core core) { + this.core = core; + } + /** * {@inheritDoc} */ @@ -61,6 +76,14 @@ public class SoneAccessor extends ReflectionAccessor { return currentSone.isSoneBlocked(sone.getId()); } else if (member.equals("modified")) { return sone.getModificationCounter() > 0; + } else if (member.equals("status")) { + return core.getSoneStatus(sone).toString(); + } else if (member.equals("idle")) { + return core.getSoneStatus(sone) == SoneStatus.idle; + } else if (member.equals("inserting")) { + return core.getSoneStatus(sone) == SoneStatus.inserting; + } else if (member.equals("downloading")) { + return core.getSoneStatus(sone) == SoneStatus.downloading; } return super.get(dataProvider, object, member); } diff --git a/src/main/java/net/pterodactylus/sone/web/WebInterface.java b/src/main/java/net/pterodactylus/sone/web/WebInterface.java index 5a404f2..2177aab 100644 --- a/src/main/java/net/pterodactylus/sone/web/WebInterface.java +++ b/src/main/java/net/pterodactylus/sone/web/WebInterface.java @@ -148,7 +148,7 @@ public class WebInterface extends AbstractService { private void registerToadlets() { DefaultTemplateFactory templateFactory = new DefaultTemplateFactory(); templateFactory.addAccessor(Object.class, new ReflectionAccessor()); - templateFactory.addAccessor(Sone.class, new SoneAccessor()); + templateFactory.addAccessor(Sone.class, new SoneAccessor(core())); templateFactory.addAccessor(Post.class, new PostAccessor(core())); templateFactory.addFilter("date", new DateFilter()); templateFactory.addFilter("l10n", new L10nFilter(l10n()));