From b1660609f6574ed43afd61d332be9f3764900405 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Tue, 19 Oct 2010 09:01:17 +0200 Subject: [PATCH] Add status fields to Sone accessor. --- .../pterodactylus/sone/template/SoneAccessor.java | 23 ++++++++++++++++++++++ .../net/pterodactylus/sone/web/WebInterface.java | 2 +- 2 files changed, 24 insertions(+), 1 deletion(-) 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())); -- 2.7.4