/* ********************************************************************** **
** Copyright notice **
** **
** (c) 2005-2006 RSSOwl Development Team **
** http://www.rssowl.org/ **
** **
** All rights reserved **
** **
** This program and the accompanying materials are made available under **
** the terms of the Eclipse Public License v1.0 which accompanies this **
** distribution, and is available at: **
** http://www.rssowl.org/legal/epl-v10.html **
** **
** A copy is found in the file epl-v10.html and important notices to the **
** license from the team is found in the textfile LICENSE.txt distributed **
** in this package. **
** **
** This copyright notice MUST APPEAR in all copies of the file! **
** **
** Contributors: **
** RSSOwl Development Team - initial API and implementation **
** **
** ********************************************************************** */
package org.rssowl.contrib.podcast.core.codelets;
import java.util.List;
import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.swt.widgets.Shell;
import org.rssowl.contrib.podcast.core.process.InstructionService;
import org.rssowl.contrib.podcast.core.process.strategy.AbstractSequence;
import org.rssowl.contrib.podcast.core.process.strategy.IStep;
import org.rssowl.contrib.podcast.model.IPersonalAttachment;
import org.rssowl.contrib.podcast.model.IPersonalBookMark;
import org.rssowl.contrib.podcast.model.IXFile;
import org.rssowl.contrib.podcast.model.PersonalFiles;
import org.rssowl.contrib.podcast.model.XLocalFile;
import org.rssowl.core.util.ITask;
/**
*
*/
public class InspectABookMark extends AbstractSequence implements IStep<IPersonalBookMark> {
// private InstructionNotifier mNotifier;
// public InspectABookMark(InstructionNotifier pNotifier){
// mNotifier = pNotifier;
// }
public InspectABookMark() {
add("File Inspector", new InspectAFile());
add("File Marker", new MarkAnAttachment());
}
public Class<IPersonalBookMark> getTargetClass(){
return IPersonalBookMark.class;
}
/**
*/
public Object execute(IPersonalBookMark pPBookMark) {
InspectInstruction lInspect = new InspectInstruction(pPBookMark,
null, ITask.Priority.DEFAULT);
InstructionService.getInstance().schedule(lInspect);
return null; // TODO Implement.
}
public boolean ifso(IPersonalBookMark t) {
return true; // TODO Implement
}
/**
* Instruction to be executed in the background.
*
* @author christophe.bouhier
*
*/
class InspectInstruction implements ITask {
private final Long mId;
private final IPersonalBookMark mBookMark;
private final Priority fPriority;
InspectInstruction(IPersonalBookMark pBookMark, Shell shell,
ITask.Priority priority) {
Assert.isNotNull(pBookMark);
Assert.isNotNull(pBookMark.getId());
mBookMark = pBookMark;
mId = pBookMark.getId();
fPriority = priority;
}
public IStatus run(IProgressMonitor monitor) {
inspectBookMark(mBookMark);
return Status.OK_STATUS;
}
public String getName() {
return mBookMark.getName();
}
public Priority getPriority() {
return fPriority;
}
@Override
public int hashCode() {
return mId.hashCode();
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (this.getClass() != obj.getClass())
return false;
final InspectInstruction other = (InspectInstruction) obj;
return mId.equals(other.mId);
}
}
private void inspectBookMark(IPersonalBookMark pPBookMark) {
List<IXFile> lFiles = PersonalFiles.getInstance().getMerged(pPBookMark,
true);
if (lFiles != null) {
// Report the action.
// CB TODO reporting an instruction will be handled by the specific instruction
// handler.
// if (pPBookMark.getInstruction().isInspect()) {
// String lInfo = new String();
// if (lFiles.size() > 0) {
// lInfo = Messages.getString("tasks.inspecting.content")
// + lFiles.size() + " "
// + Messages.getString("tasks.inspecting.file");
// lInfo = lInfo.trim();
// } else {
// lInfo = Messages.getString("tasks.inspecting.noFiles");
// }
// mNotifier.notifyInstuctionInfo(new InstructionEvent(pPBookMark
// .getInstruction().getSource(),
// InstructionEvent.INSTRUCTION_INFO, pPBookMark, lInfo));
//
// }
// We have to reset the candidate count, as the count
// is regenerated here.
pPBookMark.setCandidateCount(0);
for (IXFile lFile : lFiles) {
if (lFile instanceof IPersonalAttachment) {
IPersonalAttachment lPAttachment = (IPersonalAttachment) lFile;
if (!lPAttachment.isInspected()) {
if (lPAttachment.getFile() != null) {
// TODO Linked STEP. if (pPBookMark.getInstruction().isInspect()) {
// inspectAttachment(lPAttachment);
// mNotifier
// .notifyInstructionSucceeded(new InstructionEvent(
// pPBookMark.getInstruction()
// .getSource(),
// InstructionEvent.INSTRUCTION_INSPECT,
// lPAttachment, (Exception) null));
}
// }
// CB TODO, migrate linked step.
// if (pPBookMark.getInstruction().isMark()) {
// markSingleAttachment(pPBookMark, lPAttachment);
// }
}
// CB TODO Preference access.
// IMPORTANT !!!!!!!
// pFeed.updateSingleCandidate(lEnclosure, Configuration
// .getInstance().getMarkMax());
// CB TODO, migrate notifier.
// mNotifier.notifyInstructionSucceeded(new InstructionEvent(
// pPBookMark.getInstruction().getSource(),
// InstructionEvent.INSTRUCTION_MARK, lPAttachment,
// (Exception) null));
// if (pPBookMark.getInstruction().isDownload()) {
// if (lPAttachment.isCandidate()) {
// downloadAttachment(lPAttachment);
// }
// }
} else {
if (lFile instanceof XLocalFile) {
// CB TODO, migrate log.
// mLog.info("inspect(), local file" + lFile.getName());
// TODO Linked STEP. if (pPBookMark.getInstruction().isInspect()) {
// inspectAttachment(lFile);
// }
// // Always mark delete for local files.
// TODO Linked STEP. markDeleteAttachment(lFile);
// TODO migrate the notifier.
// mNotifier
// .notifyInstructionSucceeded(new InstructionEvent(
// pPBookMark.getInstruction().getSource(),
// InstructionEvent.INSTRUCTION_INSPECT,
// lFile, (Exception) null));
}
}
}
}
}
}