use of com.biglybt.pif.download.Download in project BiglyBT by BiglySoftware.
the class BuddyPlugin method initialize.
@Override
public void initialize(final PluginInterface _plugin_interface) {
plugin_interface = _plugin_interface;
ta_category = plugin_interface.getTorrentManager().getAttribute(TorrentAttribute.TA_CATEGORY);
logger = plugin_interface.getLogger().getChannel("Friends");
logger.setDiagnostic();
plugin_networks = new BuddyPluginNetwork[] { new BuddyPluginNetwork(plugin_interface, this, AENetworkClassifier.AT_PUBLIC), new BuddyPluginNetwork(plugin_interface, this, AENetworkClassifier.AT_I2P) };
final LocaleUtilities lu = plugin_interface.getUtilities().getLocaleUtilities();
Properties l10n_constants = new Properties();
l10n_constants.put("azbuddy.classic.link.url", Wiki.FRIENDS);
l10n_constants.put("azbuddy.dchat.link.url", Wiki.DECENTRALIZED_CHAT);
l10n_constants.put("azbuddy.profile.info.url", Wiki.FRIENDS_PUBLIC_PROFILE);
lu.integrateLocalisedMessageBundle(l10n_constants);
lu.addListener(new LocaleListener() {
@Override
public void localeChanged(Locale l) {
updateLocale(lu);
}
});
updateLocale(lu);
BasicPluginConfigModel config = plugin_interface.getUIManager().createBasicPluginConfigModel("Views.plugins." + VIEW_ID + ".title");
// enabled
classic_enabled_param = config.addBooleanParameter2("azbuddy.enabled", "azbuddy.enabled", false);
ParameterTabFolder network_tab = config.createTabFolder();
ParameterGroup network_anon_item = null;
for (int i = 0; i < 2; i++) {
boolean is_pub_tab = i == 0;
String suffix = is_pub_tab ? "" : ".anon";
// nickname
StringParameter nick_param = config.addStringParameter2("azbuddy.nickname" + suffix, "azbuddy.nickname", "");
nick_param.setGenerateIntermediateEvents(false);
nick_param.addListener(new ParameterListener() {
@Override
public void parameterChanged(Parameter param) {
updateNickName(is_pub_tab, nick_param.getValue());
}
});
// online status
String[] os_values = STATUS_VALUES;
String[] os_labels = STATUS_STRINGS;
StringListParameter os_param = config.addStringListParameter2("azbuddy.online_status" + suffix, "azbuddy.online_status", os_values, os_labels, os_values[0]);
os_param.addListener(new ParameterListener() {
@Override
public void parameterChanged(Parameter param) {
updateOnlineStatus(is_pub_tab, Integer.parseInt(os_param.getValue()));
}
});
// If we add this then use proper message texts in the STATUS_STRINGS
os_param.setVisible(SUPPORT_ONLINE_STATUS);
StringParameter profile_param = config.addStringParameter2("azbuddy.profile.info" + suffix, "", "");
profile_param.setLabelText("<a href=\"" + MessageText.getString("azbuddy.profile.info.url") + "\">" + MessageText.getString("azbuddy.profile.info") + "</a>");
profile_param.setMultiLine(5);
profile_param.setGenerateIntermediateEvents(false);
profile_param.addListener(new ParameterListener() {
@Override
public void parameterChanged(Parameter param) {
updateProfiles();
}
});
ParameterGroup profile_group = config.createGroup(is_pub_tab ? "azbuddy.public.profile" : "azbuddy.anon.profile", new Parameter[] { profile_param });
ParameterGroup network_item = config.createGroup(is_pub_tab ? "label.public" : "label.anon", new Parameter[] { nick_param, os_param, profile_group });
if (is_pub_tab) {
nick_name_public_param = nick_param;
online_status_public_param = os_param;
profile_public_param = profile_param;
} else {
nick_name_anon_param = nick_param;
online_status_anon_param = os_param;
profile_anon_param = profile_param;
network_anon_item = network_item;
}
network_tab.addTab(network_item);
}
updateProfiles();
// protocol speed
final IntParameter protocol_speed = config.addIntParameter2("azbuddy.protocolspeed", "azbuddy.protocolspeed", 32);
protocol_speed.setMinimumRequiredUserMode(Parameter.MODE_ADVANCED);
ConnectionManager cman = plugin_interface.getConnectionManager();
int inbound_limit = protocol_speed.getValue() * 1024;
inbound_limiter = cman.createRateLimiter("buddy_up", inbound_limit);
outbound_limiter = cman.createRateLimiter("buddy_down", 0);
protocol_speed.addListener(new ParameterListener() {
@Override
public void parameterChanged(Parameter param) {
inbound_limiter.setRateLimitBytesPerSecond(protocol_speed.getValue() * 1024);
}
});
// chat notifications
enable_chat_notifications = config.addBooleanParameter2("azbuddy.enable_chat_notif", "azbuddy.enable_chat_notif", true);
// default published tags or cats
cat_pub = config.addStringParameter2("azbuddy.enable_cat_pub", "azbuddy.enable_cat_pub", "");
cat_pub.setGenerateIntermediateEvents(false);
setPublicTagsOrCategories(cat_pub.getValue(), false);
final BooleanParameter tracker_enable = config.addBooleanParameter2("azbuddy.tracker.enabled", "azbuddy.tracker.enabled", true);
final BooleanParameter tracker_so_enable = config.addBooleanParameter2("azbuddy.tracker.seeding.only.enabled", "azbuddy.tracker.seeding.only.enabled", false);
// nasty hack but the existing text has a \t prefix that causes UI weirdness but I don't want to change it and
// end up with missing translations...
tracker_so_enable.setLabelText(MessageText.getString("azbuddy.tracker.seeding.only.enabled").trim());
tracker_so_enable.setIndent(1, true);
final BooleanParameter buddies_lan_local = config.addBooleanParameter2("azbuddy.tracker.con.lan.local", "azbuddy.tracker.con.lan.local", true);
buddies_lan_local.addListener(new ParameterListener() {
@Override
public void parameterChanged(Parameter param) {
lan_local_peers = buddies_lan_local.getValue();
}
});
lan_local_peers = buddies_lan_local.getValue();
final BooleanParameter buddies_fp_enable = config.addBooleanParameter2("azbuddy.tracker.fp.enable", "azbuddy.tracker.fp.enable", true);
buddies_fp_enable.addListener(new ParameterListener() {
@Override
public void parameterChanged(Parameter param) {
fp_enable = buddies_fp_enable.getValue();
}
});
fp_enable = buddies_fp_enable.getValue();
cat_pub.addListener(new ParameterListener() {
@Override
public void parameterChanged(Parameter param) {
setPublicTagsOrCategories(cat_pub.getValue(), false);
}
});
config.createGroup("label.friends", new Parameter[] { classic_enabled_param, network_tab, protocol_speed, enable_chat_notifications, cat_pub, tracker_enable, tracker_so_enable, buddies_lan_local, buddies_fp_enable });
// decentralised stuff
beta_enabled_param = config.addBooleanParameter2("azbuddy.dchat.decentralized.enabled", "azbuddy.dchat.decentralized.enabled", true);
config.createGroup("azbuddy.dchat.decentralized", new Parameter[] { beta_enabled_param });
config.addLabelParameter2("azbuddy.dchat.more.settings");
// config end
beta_plugin = new BuddyPluginBeta(plugin_interface, this, beta_enabled_param);
for (String table_id : TableManager.TABLE_MYTORRENTS_ALL) {
TableContextMenuItem menu_item = plugin_interface.getUIManager().getTableManager().addContextMenuItem(table_id, "azbuddy.contextmenu");
menu_item.setStyle(TableContextMenuItem.STYLE_MENU);
menu_item.setHeaderCategory(MenuItem.HEADER_SOCIAL);
MenuItemFillListener menu_fill_listener = new MenuItemFillListener() {
@Override
public void menuWillBeShown(MenuItem menu, Object _target) {
menu.removeAllChildItems();
if (!(isClassicEnabled() && isAvailable())) {
menu.setEnabled(false);
return;
}
final List<Torrent> torrents = new ArrayList<>();
if (_target instanceof TableRow) {
addDownload(torrents, (TableRow) _target);
} else {
TableRow[] rows = (TableRow[]) _target;
for (TableRow row : rows) {
addDownload(torrents, row);
}
}
if (torrents.size() == 0) {
menu.setEnabled(false);
} else {
List<BuddyPluginBuddy> buddies = getBuddies();
for (int i = 0; i < buddies.size(); i++) {
final BuddyPluginBuddy buddy = (BuddyPluginBuddy) buddies.get(i);
boolean online = buddy.isOnline(true);
TableContextMenuItem item = plugin_interface.getUIManager().getTableManager().addContextMenuItem(menu_item, "!" + (buddy.getName() + (buddy.isPublicNetwork() ? "" : (" (" + MessageText.getString("label.anon.medium") + ")"))) + (online ? "" : (" - " + MessageText.getString("label.disconnected"))) + "!");
item.addMultiListener(new MenuItemListener() {
@Override
public void selected(MenuItem menu, Object target) {
for (Torrent torrent : torrents) {
buddy.getPluginNetwork().getAZ2Handler().sendAZ2Torrent(torrent, buddy);
}
}
});
item.setEnabled(online);
}
menu.setEnabled(true);
}
}
protected void addDownload(List<Torrent> torrents, TableRow row) {
Object obj = row.getDataSource();
Download download;
if (obj instanceof Download) {
download = (Download) obj;
} else {
DiskManagerFileInfo file = (DiskManagerFileInfo) obj;
try {
download = file.getDownload();
} catch (DownloadException e) {
Debug.printStackTrace(e);
return;
}
}
Torrent torrent = download.getTorrent();
if (torrent != null && !TorrentUtils.isReallyPrivate(PluginCoreUtils.unwrap(torrent))) {
torrents.add(torrent);
}
}
};
menu_item.addFillListener(menu_fill_listener);
}
buddy_tracker = new BuddyPluginTracker(this, tracker_enable, tracker_so_enable);
plugin_interface.getUIManager().addUIListener(new UIManagerListener() {
@Override
public void UIAttached(final UIInstance instance) {
if (instance.getUIType().equals(UIInstance.UIT_SWT)) {
try {
synchronized (swt_ui_waiters) {
swt_ui = (BuddyPluginViewInterface) Class.forName("com.biglybt.plugin.net.buddy.swt.BuddyPluginView").getConstructor(new Class[] { BuddyPlugin.class, UIInstance.class }).newInstance(new Object[] { BuddyPlugin.this, instance });
for (Runnable r : swt_ui_waiters) {
try {
r.run();
} catch (Throwable e) {
Debug.out(e);
}
}
swt_ui_waiters.clear();
}
} catch (Throwable e) {
Debug.out(e);
}
}
setupDisablePrompt(instance);
}
@Override
public void UIDetached(UIInstance instance) {
if (instance.getUIType().equals(UIInstance.UIT_SWT) && swt_ui != null) {
swt_ui.destroy();
swt_ui = null;
}
}
});
final ParameterGroup f_network_anon_item = network_anon_item;
ParameterListener enabled_listener = new ParameterListener() {
@Override
public void parameterChanged(Parameter param) {
boolean classic_enabled = classic_enabled_param.getValue();
nick_name_public_param.setEnabled(classic_enabled);
online_status_public_param.setEnabled(classic_enabled);
nick_name_anon_param.setEnabled(classic_enabled);
online_status_anon_param.setEnabled(classic_enabled);
protocol_speed.setEnabled(classic_enabled);
enable_chat_notifications.setEnabled(classic_enabled);
cat_pub.setEnabled(classic_enabled);
tracker_enable.setEnabled(classic_enabled);
tracker_so_enable.setEnabled(classic_enabled && tracker_enable.getValue());
buddies_lan_local.setEnabled(classic_enabled);
buddies_fp_enable.setEnabled(classic_enabled);
network_tab.setEnabled(classic_enabled);
f_network_anon_item.setEnabled(classic_enabled && I2PHelpers.isI2PInstalled());
if (param != null) {
for (BuddyPluginNetwork pn : plugin_networks) {
pn.setClassicEnabledInternal(classic_enabled);
}
fireEnabledStateChanged();
}
}
};
classic_enabled_param.addListener(enabled_listener);
beta_enabled_param.addListener(enabled_listener);
tracker_enable.addListener(enabled_listener);
for (BuddyPluginNetwork pn : plugin_networks) {
pn.loadConfig();
pn.registerMessageHandler();
}
plugin_interface.addListener(new PluginListener() {
@Override
public void initializationComplete() {
enabled_listener.parameterChanged(null);
final DelayedTask dt = plugin_interface.getUtilities().createDelayedTask(new Runnable() {
@Override
public void run() {
new AEThread2("BuddyPlugin:init", true) {
@Override
public void run() {
startup();
beta_plugin.startup();
initialization_complete.set(true);
}
}.start();
}
});
dt.queue();
}
@Override
public void closedownInitiated() {
// meh, moved this to core listener below as we need to closedown before
// i2p plugin so connections aren't torn down before we can tidily close
}
@Override
public void closedownComplete() {
}
});
CoreFactory.getSingleton().addLifecycleListener(new CoreLifecycleAdapter() {
@Override
public boolean syncInvokeRequired() {
return (true);
}
@Override
public void stopping(Core core) {
for (BuddyPluginNetwork pn : plugin_networks) {
pn.saveConfig(true);
pn.closedown();
}
beta_plugin.closedown();
}
});
}
use of com.biglybt.pif.download.Download in project BiglyBT by BiglySoftware.
the class BuddyPlugin method getRSS.
public FeedDetails getRSS(BuddyPluginBuddy buddy, String tag_or_category, String if_mod) throws BuddyPluginException {
if (!buddy.isLocalRSSTagOrCategoryAuthorised(tag_or_category)) {
throw (new BuddyPluginException("Unauthorised tag/category '" + tag_or_category + "'"));
}
buddy.localRSSTagOrCategoryRead(tag_or_category);
Download[] downloads = plugin_interface.getDownloadManager().getDownloads();
List<Download> selected_dls = new ArrayList<>();
long fingerprint = 0;
for (int i = 0; i < downloads.length; i++) {
Download download = downloads[i];
Torrent torrent = download.getTorrent();
if (torrent == null) {
continue;
}
boolean match = tag_or_category.equalsIgnoreCase("all");
if (!match) {
String dl_cat = download.getAttribute(ta_category);
match = dl_cat != null && dl_cat.equals(tag_or_category);
}
if (!match) {
try {
List<Tag> tags = TagManagerFactory.getTagManager().getTagsForTaggable(TagType.TT_DOWNLOAD_MANUAL, PluginCoreUtils.unwrap(download));
for (Tag tag : tags) {
if (tag.getTagName(true).equals(tag_or_category)) {
match = true;
break;
}
}
} catch (Throwable e) {
}
}
if (match) {
if (!TorrentUtils.isReallyPrivate(PluginCoreUtils.unwrap(torrent))) {
selected_dls.add(download);
byte[] hash = torrent.getHash();
int num = (hash[0] << 24) & 0xff000000 | (hash[1] << 16) & 0x00ff0000 | (hash[2] << 8) & 0x0000ff00 | hash[3] & 0x000000ff;
fingerprint += num;
}
}
}
PluginConfig pc = plugin_interface.getPluginconfig();
String feed_finger_key = "feed_finger.category." + tag_or_category;
String feed_date_key = "feed_date.category." + tag_or_category;
long existing_fingerprint = pc.getPluginLongParameter(feed_finger_key, 0);
long feed_date = pc.getPluginLongParameter(feed_date_key, 0);
long now = SystemTime.getCurrentTime();
if (existing_fingerprint == fingerprint) {
if (selected_dls.size() > 0) {
if (now < feed_date || now - feed_date > FEED_UPDATE_MIN_MILLIS) {
feed_date = now;
pc.setPluginParameter(feed_date_key, feed_date);
}
}
} else {
pc.setPluginParameter(feed_finger_key, fingerprint);
if (now <= feed_date) {
feed_date++;
} else {
feed_date = now;
}
pc.setPluginParameter(feed_date_key, feed_date);
}
String last_modified = TimeFormatter.getHTTPDate(feed_date);
if (if_mod != null && if_mod.equals(last_modified)) {
return (new FeedDetails(new byte[0], last_modified));
}
ByteArrayOutputStream os = new ByteArrayOutputStream();
try {
PrintWriter pw = new PrintWriter(new OutputStreamWriter(os, "UTF-8"));
pw.println("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
pw.println("<rss version=\"2.0\" xmlns:vuze=\"http://www.vuze.com\">");
pw.println("<channel>");
pw.println("<title>" + escape(tag_or_category) + "</title>");
Collections.sort(selected_dls, new Comparator<Download>() {
@Override
public int compare(Download d1, Download d2) {
long added1 = getAddedTime(d1) / 1000;
long added2 = getAddedTime(d2) / 1000;
return ((int) (added2 - added1));
}
});
pw.println("<pubDate>" + last_modified + "</pubDate>");
for (int i = 0; i < selected_dls.size(); i++) {
Download download = (Download) selected_dls.get(i);
DownloadManager core_download = PluginCoreUtils.unwrap(download);
Torrent torrent = download.getTorrent();
String hash_str = Base32.encode(torrent.getHash());
pw.println("<item>");
pw.println("<title>" + escape(download.getName()) + "</title>");
pw.println("<guid>" + hash_str + "</guid>");
long added = core_download.getDownloadState().getLongParameter(DownloadManagerState.PARAM_DOWNLOAD_ADDED_TIME);
pw.println("<pubDate>" + TimeFormatter.getHTTPDate(added) + "</pubDate>");
pw.println("<vuze:size>" + torrent.getSize() + "</vuze:size>");
pw.println("<vuze:assethash>" + hash_str + "</vuze:assethash>");
String url = "azplug:?id=azbuddy&name=Friends&arg=";
String arg = "pk=" + buddy.getPluginNetwork().getPublicKey() + "&cat=" + tag_or_category + "&hash=" + Base32.encode(torrent.getHash());
url += URLEncoder.encode(arg, "UTF-8");
pw.println("<vuze:downloadurl>" + escape(url) + "</vuze:downloadurl>");
DownloadScrapeResult scrape = download.getLastScrapeResult();
if (scrape != null && scrape.getResponseType() == DownloadScrapeResult.RT_SUCCESS) {
pw.println("<vuze:seeds>" + scrape.getSeedCount() + "</vuze:seeds>");
pw.println("<vuze:peers>" + scrape.getNonSeedCount() + "</vuze:peers>");
}
pw.println("</item>");
}
pw.println("</channel>");
pw.println("</rss>");
pw.flush();
return (new FeedDetails(os.toByteArray(), last_modified));
} catch (IOException e) {
throw (new BuddyPluginException("", e));
}
}
use of com.biglybt.pif.download.Download in project BiglyBT by BiglySoftware.
the class ExternalSeedPlugin method addPeers.
protected void addPeers(final Download download, List _peers) {
final List peers = new ArrayList();
peers.addAll(_peers);
if (peers.size() > 0) {
boolean add_listener = false;
try {
download_mon.enter();
List existing_peers = (List) download_map.get(download);
if (existing_peers == null) {
add_listener = true;
existing_peers = new ArrayList();
download_map.put(download, existing_peers);
}
Iterator it = peers.iterator();
while (it.hasNext()) {
ExternalSeedPeer peer = (ExternalSeedPeer) it.next();
boolean skip = false;
for (int j = 0; j < existing_peers.size(); j++) {
ExternalSeedPeer existing_peer = (ExternalSeedPeer) existing_peers.get(j);
if (existing_peer.sameAs(peer)) {
skip = true;
break;
}
}
if (skip) {
it.remove();
} else {
log(download.getName() + " found seed " + peer.getName());
existing_peers.add(peer);
}
}
setStatus("Running: Downloads with external seeds = " + download_map.size());
} finally {
download_mon.exit();
}
if (add_listener) {
download.addPeerListener(new DownloadPeerListener() {
@Override
public void peerManagerAdded(Download download, PeerManager peer_manager) {
List existing_peers = getPeers();
if (existing_peers == null) {
return;
}
for (int i = 0; i < existing_peers.size(); i++) {
ExternalSeedPeer peer = (ExternalSeedPeer) existing_peers.get(i);
peer.setManager(peer_manager);
}
}
@Override
public void peerManagerRemoved(Download download, PeerManager peer_manager) {
List existing_peers = getPeers();
if (existing_peers == null) {
return;
}
for (int i = 0; i < existing_peers.size(); i++) {
ExternalSeedPeer peer = (ExternalSeedPeer) existing_peers.get(i);
peer.setManager(null);
}
}
protected List getPeers() {
List existing_peers = null;
try {
download_mon.enter();
List temp = (List) download_map.get(download);
if (temp != null) {
existing_peers = new ArrayList(temp.size());
existing_peers.addAll(temp);
}
} finally {
download_mon.exit();
}
return (existing_peers);
}
});
} else {
// fix up newly added peers to current peer manager
PeerManager existing_pm = download.getPeerManager();
if (existing_pm != null) {
for (int i = 0; i < peers.size(); i++) {
ExternalSeedPeer peer = (ExternalSeedPeer) peers.get(i);
if (peer.getManager() == null) {
peer.setManager(existing_pm);
}
}
}
}
}
}
use of com.biglybt.pif.download.Download in project BiglyBT by BiglySoftware.
the class SeedingRankColumnListener method refresh.
@Override
public void refresh(TableCell cell) {
Download dl = (Download) cell.getDataSource();
if (dl == null)
return;
DefaultRankCalculator dlData;
Object o = cell.getSortValue();
if (o instanceof DefaultRankCalculator)
dlData = (DefaultRankCalculator) o;
else {
dlData = StartStopRulesDefaultPlugin.getRankCalculator(dl);
}
if (dlData == null) {
cell.setSortValue(-1);
return;
}
Sorter comp = (Sorter) dlData.getUserData(KEY);
if (comp == null) {
comp = new Sorter(dlData);
dlData.setUserData(KEY, comp);
}
cell.setSortValue(comp);
SeedingRank sr = dl.getSeedingRank();
String[] status = sr.getStatus(false);
cell.setText(status[0]);
/*
int state = dlData.getState();
if ( state == Download.ST_STOPPED || state == Download.ST_ERROR ){
cell.setText( "" );
}else{
cell.setText(status[0]);
}
*/
cell.setToolTip(status[1]);
}
use of com.biglybt.pif.download.Download in project BiglyBT by BiglySoftware.
the class DownloadManagerMoveHandler method recalculatePath.
public static SaveLocationChange recalculatePath(DownloadManager dm) {
Download download = PluginCoreUtils.wrap(dm);
SaveLocationChange result = null;
if (canGoToCompleteDir(dm)) {
result = CURRENT_HANDLER.onCompletion(download, true, false);
}
if (result == null) {
result = CURRENT_HANDLER.onInitialization(download, true, false);
}
return result;
}
Aggregations