package edu.azureus.example; import org.gudy.azureus2.plugins.*; import org.gudy.azureus2.plugins.download.*; import org.gudy.azureus2.plugins.logging.*; import org.gudy.azureus2.plugins.ui.config.*; import org.gudy.azureus2.plugins.ui.model.*; import org.gudy.azureus2.plugins.utils.*; public class plugin implements Plugin, DownloadManagerListener, DownloadListener { private static final String BASENAME = "example."; private static final String CONFIG_ENABLED = "enabled"; private static final boolean CONFIG_ENABLED_DEFAULT = false; private static final String CONFIG_PREFIX = "prefix"; private static final String CONFIG_DEFAULT = "defaultPrefix"; private DownloadManager dm; private BooleanParameter enabled; private StringParameter prefix; private LoggerChannel log; private PluginInterface pluginInterface; private LocaleUtilities lu; public void downloadAdded(Download download) { download.addListener(this); } public void downloadRemoved(Download download) { download.removeListener(this); } public void initialize(PluginInterface pluginInterface) { this.pluginInterface = pluginInterface; this.lu = pluginInterface.getUtilities().getLocaleUtilities(); log = pluginInterface.getLogger().getChannel("ExampleLogger"); final BasicPluginViewModel vm = pluginInterface.getUIManager() .createBasicPluginViewModel( lu.getLocalisedMessageText(BASENAME + "name")); vm.getActivity().setVisible(false); vm.getProgress().setVisible(false); log.addListener(new LoggerChannelListener() { public void messageLogged(int type, String content) { vm.getLogArea().appendText(content + "\n"); } public void messageLogged(String str, Throwable error) { vm.getLogArea().appendText(str + "\n"); vm.getLogArea().appendText(error.getLocalizedMessage() + "\n"); } }); BasicPluginConfigModel cfg = this.pluginInterface.getUIManager() .createBasicPluginConfigModel("plugins", BASENAME + "name"); enabled = cfg.addBooleanParameter2(CONFIG_ENABLED, BASENAME + CONFIG_ENABLED, CONFIG_ENABLED_DEFAULT); prefix = cfg.addStringParameter2(CONFIG_PREFIX, BASENAME + CONFIG_PREFIX, lu.getLocalisedMessageText(CONFIG_DEFAULT)); enabled.addEnabledOnSelection(prefix); this.pluginInterface.getDownloadManager().addListener(this); } public void positionChanged(Download download, int oldPosition, int newPosition) { // If you want to keep track of the queue position // do it here } public void stateChanged(Download download, int old_state, int new_state) { if (enabled.getValue()) { log.log("[" + prefix.getValue() + "] Torrent '" + download.getName() + "' changed status from " + Download.ST_NAMES[old_state] + " to " + Download.ST_NAMES[new_state]); } } }