From 976e164e2cf8ec579b7b5620155c86577882b669 Mon Sep 17 00:00:00 2001 From: yukihane Date: Mon, 29 Aug 2011 16:46:01 +0900 Subject: [PATCH] =?utf8?q?=E9=80=B2=E6=8D=97=E5=A0=B1=E5=91=8A=E5=AE=9F?= =?utf8?q?=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- frontend/src/saccubus/worker/impl/PercentageReportable.java | 9 +++++++++ frontend/src/saccubus/worker/impl/convert/Convert.java | 12 +++++++----- .../src/saccubus/worker/impl/convert/ConvertProgress.java | 13 +++++++++++-- frontend/src/saccubus/worker/impl/download/Download.java | 4 ++-- .../src/saccubus/worker/impl/download/DownloadProgress.java | 13 +++++++++++-- frontend/src/yukihane/inqubus/manager/TaskManage.java | 8 +++++--- 6 files changed, 45 insertions(+), 14 deletions(-) create mode 100644 frontend/src/saccubus/worker/impl/PercentageReportable.java diff --git a/frontend/src/saccubus/worker/impl/PercentageReportable.java b/frontend/src/saccubus/worker/impl/PercentageReportable.java new file mode 100644 index 0000000..24960ae --- /dev/null +++ b/frontend/src/saccubus/worker/impl/PercentageReportable.java @@ -0,0 +1,9 @@ +package saccubus.worker.impl; + +/** + * + * @author yuki + */ +public interface PercentageReportable { + double getPercentage(); +} diff --git a/frontend/src/saccubus/worker/impl/convert/Convert.java b/frontend/src/saccubus/worker/impl/convert/Convert.java index 3f581f3..3aca88f 100644 --- a/frontend/src/saccubus/worker/impl/convert/Convert.java +++ b/frontend/src/saccubus/worker/impl/convert/Convert.java @@ -52,7 +52,8 @@ public class Convert extends Worker { * @param output 変換後出力動画. * @throws IOException 変換失敗. */ - public Convert(ConvertProfile profile, File video, File comment, WorkerListener listener) { + public Convert(ConvertProfile profile, File video, File comment, + WorkerListener listener) { super(listener); this.profile = profile; this.videoFile = video; @@ -84,18 +85,18 @@ public class Convert extends Worker { if (profile.isCommentOverlay()) { transformedComment = File.createTempFile("vhk", ".tmp", profile.getTempDir()); final HideCondition hide = profile.getNgSetting(); - publish(new ConvertProgress(PROCESS, "コメントの中間ファイルへの変換中")); + publish(new ConvertProgress(PROCESS, 0.0, "コメントの中間ファイルへの変換中")); ConvertToVideoHook.convert(commentFile, transformedComment, hide.getId(), hide.getWord()); } checkStop(); - publish(new ConvertProgress(PROCESS, "動画の変換を開始")); + publish(new ConvertProgress(PROCESS, 0.0, "動画の変換を開始")); final int code = convert(transformedComment, outputFile); if (code != 0) { throw new IOException("ffmpeg実行失敗: " + outputFile.getPath()); } - publish(new ConvertProgress(PROCESS, "変換が正常に終了しました。")); + publish(new ConvertProgress(PROCESS, 100.0, "変換が正常に終了しました。")); return new ConvertResult(true, outputFile.getName()); } finally { if (transformedComment != null && transformedComment.exists()) { @@ -191,7 +192,8 @@ public class Convert extends Worker { String msg; while ((msg = ebr.readLine()) != null) { if (msg.startsWith("frame=")) { - publish(new ConvertProgress(PROCESS, msg)); + // TODO パーセンテージ計算、出力 + publish(new ConvertProgress(PROCESS, 0.0, msg)); } else if (!msg.endsWith("No accelerated colorspace conversion found")) { logger.log(Level.INFO, msg); } diff --git a/frontend/src/saccubus/worker/impl/convert/ConvertProgress.java b/frontend/src/saccubus/worker/impl/convert/ConvertProgress.java index 44b9527..79df46c 100644 --- a/frontend/src/saccubus/worker/impl/convert/ConvertProgress.java +++ b/frontend/src/saccubus/worker/impl/convert/ConvertProgress.java @@ -1,18 +1,22 @@ package saccubus.worker.impl.convert; import org.apache.commons.lang.builder.ToStringBuilder; +import saccubus.worker.impl.MessageReportable; +import saccubus.worker.impl.PercentageReportable; /** * * @author yuki */ -public class ConvertProgress { +public class ConvertProgress implements PercentageReportable, MessageReportable { private final ConvertStatus status; + private final double percentage; private final String message; - ConvertProgress(ConvertStatus status, String message) { + ConvertProgress(ConvertStatus status, double percentage, String message) { this.status = status; + this.percentage = percentage; this.message = message; } @@ -25,6 +29,11 @@ public class ConvertProgress { } @Override + public double getPercentage() { + return percentage; + } + + @Override public String toString() { return ToStringBuilder.reflectionToString(this); } diff --git a/frontend/src/saccubus/worker/impl/download/Download.java b/frontend/src/saccubus/worker/impl/download/Download.java index 51810e1..eb5b166 100644 --- a/frontend/src/saccubus/worker/impl/download/Download.java +++ b/frontend/src/saccubus/worker/impl/download/Download.java @@ -80,7 +80,7 @@ public class Download extends Worker { @Override public DownloadResult work() throws Exception { - publish(new DownloadProgress(PROCESS, "ログイン中")); + publish(new DownloadProgress(PROCESS, 0.0, "ログイン中")); NicoHttpClient client = null; nicobrowser.VideoInfo vi = null; @@ -132,7 +132,7 @@ public class Download extends Worker { @Override public void progress(long fileSize, long downloadSize) { final double vol = (double) downloadSize / (double) fileSize * 100.0; - publish(new DownloadProgress(PROCESS, String.format("ダウンロード%.2f%%", vol))); + publish(new DownloadProgress(PROCESS, vol, String.format("ダウンロード%.2f%%", vol))); } }); diff --git a/frontend/src/saccubus/worker/impl/download/DownloadProgress.java b/frontend/src/saccubus/worker/impl/download/DownloadProgress.java index 62a265d..1ef07f8 100644 --- a/frontend/src/saccubus/worker/impl/download/DownloadProgress.java +++ b/frontend/src/saccubus/worker/impl/download/DownloadProgress.java @@ -1,18 +1,22 @@ package saccubus.worker.impl.download; import org.apache.commons.lang.builder.ToStringBuilder; +import saccubus.worker.impl.MessageReportable; +import saccubus.worker.impl.PercentageReportable; /** * * @author yuki */ -public class DownloadProgress { +public class DownloadProgress implements PercentageReportable, MessageReportable { private final DownloadStatus status; + private final double percentage; private final String message; - DownloadProgress(DownloadStatus status, String message) { + DownloadProgress(DownloadStatus status, double percentage, String message) { this.status = status; + this.percentage = percentage; this.message = message; } @@ -25,6 +29,11 @@ public class DownloadProgress { } @Override + public double getPercentage() { + return percentage; + } + + @Override public String toString() { return ToStringBuilder.reflectionToString(this); } diff --git a/frontend/src/yukihane/inqubus/manager/TaskManage.java b/frontend/src/yukihane/inqubus/manager/TaskManage.java index 47d4f10..ab37bbe 100644 --- a/frontend/src/yukihane/inqubus/manager/TaskManage.java +++ b/frontend/src/yukihane/inqubus/manager/TaskManage.java @@ -8,6 +8,8 @@ import java.util.concurrent.Future; import java.util.logging.Level; import java.util.logging.Logger; import saccubus.worker.WorkerListener; +import saccubus.worker.impl.MessageReportable; +import saccubus.worker.impl.PercentageReportable; import saccubus.worker.impl.convert.Convert; import saccubus.worker.impl.convert.ConvertProgress; import saccubus.worker.impl.convert.ConvertResult; @@ -22,6 +24,7 @@ import saccubus.worker.profile.DownloadProfile; * @author yuki */ public class TaskManage { + private static final Logger logger = Logger.getLogger(TaskManage.class.getName()); private final ExecutorService downloadExecutorService; private final ExecutorService convertExecutorService; @@ -94,7 +97,7 @@ public class TaskManage { } } - abstract class TaskManageInnerListener implements WorkerListener { + abstract class TaskManageInnerListener implements WorkerListener { private final int rowId; @@ -122,8 +125,7 @@ public class TaskManage { @Override public void process(V progress) { logger.log(Level.FINEST, "process: {0}", progress); - // TOOD - notify(TaskStatus.DOING, 0.0, ""); + notify(TaskStatus.DOING, progress.getPercentage(), progress.getMessage()); } @Override -- 2.11.0