use of com.biglybt.plugin.net.buddy.BuddyPluginBuddy in project BiglyBT by BiglySoftware.
the class TagUIUtils method addShareWithFriendsMenuItems.
private static void addShareWithFriendsMenuItems(Menu menu, Tag tag, TagType tag_type) {
PluginInterface bpi = PluginInitializer.getDefaultInterface().getPluginManager().getPluginInterfaceByClass(BuddyPlugin.class);
if (tag_type.getTagType() == TagType.TT_DOWNLOAD_MANUAL && bpi != null) {
TagFeatureProperties props = (TagFeatureProperties) tag;
TagProperty tp = props.getProperty(TagFeatureProperties.PR_UNTAGGED);
Boolean is_ut = tp == null ? null : tp.getBoolean();
if (is_ut == null || !is_ut) {
final BuddyPlugin buddy_plugin = (BuddyPlugin) bpi.getPlugin();
if (buddy_plugin.isClassicEnabled()) {
final Menu share_menu = new Menu(menu.getShell(), SWT.DROP_DOWN);
final MenuItem share_item = new MenuItem(menu, SWT.CASCADE);
Messages.setLanguageText(share_item, "azbuddy.ui.menu.cat.share");
// nasty hack to fix nastyness on windows
share_item.setText(share_item.getText() + " ");
share_item.setMenu(share_menu);
List<BuddyPluginBuddy> buddies = buddy_plugin.getBuddies();
if (buddies.size() == 0) {
final MenuItem item = new MenuItem(share_menu, SWT.CHECK);
item.setText(MessageText.getString("general.add.friends"));
item.setEnabled(false);
} else {
final String tag_name = tag.getTagName(true);
final boolean is_public = buddy_plugin.isPublicTagOrCategory(tag_name);
final MenuItem itemPubCat = new MenuItem(share_menu, SWT.CHECK);
Messages.setLanguageText(itemPubCat, "general.all.friends");
itemPubCat.setSelection(is_public);
itemPubCat.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
if (is_public) {
buddy_plugin.removePublicTagOrCategory(tag_name);
} else {
buddy_plugin.addPublicTagOrCategory(tag_name);
}
}
});
new MenuItem(share_menu, SWT.SEPARATOR);
for (final BuddyPluginBuddy buddy : buddies) {
if (buddy.getNickName() == null) {
continue;
}
final boolean auth = buddy.isLocalRSSTagOrCategoryAuthorised(tag_name);
final MenuItem itemShare = new MenuItem(share_menu, SWT.CHECK);
itemShare.setText(buddy.getName());
itemShare.setSelection(auth || is_public);
if (is_public) {
itemShare.setEnabled(false);
}
itemShare.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
if (auth) {
buddy.removeLocalAuthorisedRSSTagOrCategory(tag_name);
} else {
buddy.addLocalAuthorisedRSSTagOrCategory(tag_name);
}
}
});
}
}
}
}
}
}
use of com.biglybt.plugin.net.buddy.BuddyPluginBuddy in project BiglyBT by BiglySoftware.
the class CategoryUIUtils method createMenuItems.
public static void createMenuItems(final Menu menu, final Category category) {
if (category.getType() == Category.TYPE_USER) {
final MenuItem itemDelete = new MenuItem(menu, SWT.PUSH);
Messages.setLanguageText(itemDelete, "MyTorrentsView.menu.category.delete");
itemDelete.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
GlobalManager gm = CoreFactory.getSingleton().getGlobalManager();
List<DownloadManager> managers = category.getDownloadManagers(gm.getDownloadManagers());
// move to array,since setCategory removed it from the category,
// which would mess up our loop
DownloadManager[] dms = managers.toArray(new DownloadManager[managers.size()]);
for (DownloadManager dm : dms) {
DownloadManagerState state = dm.getDownloadState();
if (state != null) {
state.setCategory(null);
}
}
CategoryManager.removeCategory(category);
}
});
}
if (category.getType() != Category.TYPE_ALL) {
long kInB = DisplayFormatters.getKinB();
long maxDownload = COConfigurationManager.getIntParameter("Max Download Speed KBs", 0) * kInB;
long maxUpload = COConfigurationManager.getIntParameter("Max Upload Speed KBs", 0) * kInB;
int down_speed = category.getDownloadSpeed();
int up_speed = category.getUploadSpeed();
ViewUtils.addSpeedMenu(menu.getShell(), menu, true, true, true, true, false, down_speed == 0, down_speed, down_speed, maxDownload, false, up_speed == 0, up_speed, up_speed, maxUpload, 1, null, new SpeedAdapter() {
@Override
public void setDownSpeed(int val) {
category.setDownloadSpeed(val);
}
@Override
public void setUpSpeed(int val) {
category.setUploadSpeed(val);
}
});
}
GlobalManager gm = CoreFactory.getSingleton().getGlobalManager();
List<DownloadManager> managers = category.getDownloadManagers(gm.getDownloadManagers());
final DownloadManager[] dms = managers.toArray(new DownloadManager[managers.size()]);
boolean start = false;
boolean stop = false;
for (DownloadManager dm : dms) {
stop = stop || ManagerUtils.isStopable(dm);
start = start || ManagerUtils.isStartable(dm);
}
// Queue
final MenuItem itemQueue = new MenuItem(menu, SWT.PUSH);
Messages.setLanguageText(itemQueue, "MyTorrentsView.menu.queue");
Utils.setMenuItemImage(itemQueue, "start");
itemQueue.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
GlobalManager gm = CoreFactory.getSingleton().getGlobalManager();
List<?> managers = category.getDownloadManagers(gm.getDownloadManagers());
Object[] dms = managers.toArray();
TorrentUtil.queueDataSources(dms, true);
}
});
itemQueue.setEnabled(start);
// Stop
final MenuItem itemStop = new MenuItem(menu, SWT.PUSH);
Messages.setLanguageText(itemStop, "MyTorrentsView.menu.stop");
Utils.setMenuItemImage(itemStop, "stop");
itemStop.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
GlobalManager gm = CoreFactory.getSingleton().getGlobalManager();
List<?> managers = category.getDownloadManagers(gm.getDownloadManagers());
Object[] dms = managers.toArray();
TorrentUtil.stopDataSources(dms);
}
});
itemStop.setEnabled(stop);
if (category.canBePublic()) {
new MenuItem(menu, SWT.SEPARATOR);
final MenuItem itemPublic = new MenuItem(menu, SWT.CHECK);
itemPublic.setSelection(category.isPublic());
Messages.setLanguageText(itemPublic, "cat.share");
itemPublic.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
category.setPublic(itemPublic.getSelection());
}
});
}
// share with friends
PluginInterface bpi = PluginInitializer.getDefaultInterface().getPluginManager().getPluginInterfaceByClass(BuddyPlugin.class);
int cat_type = category.getType();
if (bpi != null && cat_type != Category.TYPE_UNCATEGORIZED) {
final BuddyPlugin buddy_plugin = (BuddyPlugin) bpi.getPlugin();
if (buddy_plugin.isClassicEnabled()) {
final Menu share_menu = new Menu(menu.getShell(), SWT.DROP_DOWN);
final MenuItem share_item = new MenuItem(menu, SWT.CASCADE);
Messages.setLanguageText(share_item, "azbuddy.ui.menu.cat.share");
share_item.setMenu(share_menu);
List<BuddyPluginBuddy> buddies = buddy_plugin.getBuddies();
if (buddies.size() == 0) {
final MenuItem item = new MenuItem(share_menu, SWT.CHECK);
item.setText(MessageText.getString("general.add.friends"));
item.setEnabled(false);
} else {
final String cname;
if (cat_type == Category.TYPE_ALL) {
cname = "All";
} else {
cname = category.getName();
}
final boolean is_public = buddy_plugin.isPublicTagOrCategory(cname);
final MenuItem itemPubCat = new MenuItem(share_menu, SWT.CHECK);
Messages.setLanguageText(itemPubCat, "general.all.friends");
itemPubCat.setSelection(is_public);
itemPubCat.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
if (is_public) {
buddy_plugin.removePublicTagOrCategory(cname);
} else {
buddy_plugin.addPublicTagOrCategory(cname);
}
}
});
new MenuItem(share_menu, SWT.SEPARATOR);
for (final BuddyPluginBuddy buddy : buddies) {
if (buddy.getNickName() == null) {
continue;
}
final boolean auth = buddy.isLocalRSSTagOrCategoryAuthorised(cname);
final MenuItem itemShare = new MenuItem(share_menu, SWT.CHECK);
itemShare.setText(buddy.getName());
itemShare.setSelection(auth || is_public);
if (is_public) {
itemShare.setEnabled(false);
}
itemShare.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
if (auth) {
buddy.removeLocalAuthorisedRSSTagOrCategory(cname);
} else {
buddy.addLocalAuthorisedRSSTagOrCategory(cname);
}
}
});
}
}
}
}
if (category.getType() != Category.TYPE_ALL) {
TrancodeUIUtils.TranscodeTarget[] tts = TrancodeUIUtils.getTranscodeTargets();
if (tts.length > 0) {
final Menu t_menu = new Menu(menu.getShell(), SWT.DROP_DOWN);
final MenuItem t_item = new MenuItem(menu, SWT.CASCADE);
Messages.setLanguageText(t_item, "cat.autoxcode");
t_item.setMenu(t_menu);
String existing = category.getStringAttribute(Category.AT_AUTO_TRANSCODE_TARGET);
for (TrancodeUIUtils.TranscodeTarget tt : tts) {
TrancodeUIUtils.TranscodeProfile[] profiles = tt.getProfiles();
if (profiles.length > 0) {
final Menu tt_menu = new Menu(t_menu.getShell(), SWT.DROP_DOWN);
final MenuItem tt_item = new MenuItem(t_menu, SWT.CASCADE);
tt_item.setText(tt.getName());
tt_item.setMenu(tt_menu);
for (final TrancodeUIUtils.TranscodeProfile tp : profiles) {
final MenuItem p_item = new MenuItem(tt_menu, SWT.CHECK);
p_item.setText(tp.getName());
boolean selected = existing != null && existing.equals(tp.getUID());
if (selected) {
Utils.setMenuItemImage(tt_item, "blacktick");
}
p_item.setSelection(selected);
p_item.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
category.setStringAttribute(Category.AT_AUTO_TRANSCODE_TARGET, p_item.getSelection() ? tp.getUID() : null);
}
});
}
}
}
}
}
// rss feed
final MenuItem rssOption = new MenuItem(menu, SWT.CHECK);
rssOption.setSelection(category.getBooleanAttribute(Category.AT_RSS_GEN));
Messages.setLanguageText(rssOption, "cat.rss.gen");
rssOption.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
boolean set = rssOption.getSelection();
category.setBooleanAttribute(Category.AT_RSS_GEN, set);
}
});
if (cat_type != Category.TYPE_UNCATEGORIZED && cat_type != Category.TYPE_ALL) {
final MenuItem upPriority = new MenuItem(menu, SWT.CHECK);
upPriority.setSelection(category.getIntAttribute(Category.AT_UPLOAD_PRIORITY) > 0);
Messages.setLanguageText(upPriority, "cat.upload.priority");
upPriority.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
boolean set = upPriority.getSelection();
category.setIntAttribute(Category.AT_UPLOAD_PRIORITY, set ? 1 : 0);
}
});
}
// options
MenuItem itemOptions = new MenuItem(menu, SWT.PUSH);
Messages.setLanguageText(itemOptions, "cat.options");
itemOptions.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
UIFunctions uiFunctions = UIFunctionsManager.getUIFunctions();
if (uiFunctions != null) {
MultipleDocumentInterface mdi = uiFunctions.getMDI();
if (mdi != null) {
mdi.showEntryByID(MultipleDocumentInterface.SIDEBAR_SECTION_TORRENT_OPTIONS, dms);
}
}
}
});
if (dms.length == 0) {
itemOptions.setEnabled(false);
}
}
use of com.biglybt.plugin.net.buddy.BuddyPluginBuddy in project BiglyBT by BiglySoftware.
the class BuddyPluginTracker method doTracking.
protected void doTracking() {
if (!(plugin_enabled && tracker_enabled)) {
return;
}
Map<BuddyPluginBuddy, List<Download>> peers_to_check = new HashMap<>();
Map<PartialBuddy, List<Download>> partials_to_check = new HashMap<>();
Set<Download> active_set = new HashSet<>();
synchronized (online_buddies) {
Iterator<BuddyPluginBuddy> it = online_buddies.iterator();
while (it.hasNext()) {
BuddyPluginBuddy buddy = it.next();
BuddyTrackingData buddy_data = getBuddyData(buddy);
Map<Download, Boolean> active = buddy_data.getDownloadsToTrack();
if (active.size() > 0) {
Iterator<Map.Entry<Download, Boolean>> it2 = active.entrySet().iterator();
List<Download> check_peers = new ArrayList<>();
while (it2.hasNext()) {
Map.Entry<Download, Boolean> entry = it2.next();
Download dl = entry.getKey();
boolean check_peer = entry.getValue();
if (check_peer) {
check_peers.add(dl);
}
active_set.add(dl);
}
if (check_peers.size() > 0) {
peers_to_check.put(buddy, check_peers);
}
}
}
for (PartialBuddyData pbd : partial_buddies.values()) {
active_set.addAll(pbd.downloads);
}
}
synchronized (actively_tracking) {
Iterator<Download> it = active_set.iterator();
while (it.hasNext()) {
Download dl = it.next();
if (!actively_tracking.contains(dl)) {
actively_tracking.add(dl);
trackPeers(dl);
}
}
it = actively_tracking.iterator();
while (it.hasNext()) {
Download dl = (Download) it.next();
if (!active_set.contains(dl)) {
it.remove();
untrackPeers(dl);
}
}
}
// check peer connections
Iterator<Map.Entry<BuddyPluginBuddy, List<Download>>> it = peers_to_check.entrySet().iterator();
boolean lan = plugin.getPeersAreLANLocal();
while (it.hasNext()) {
Map.Entry<BuddyPluginBuddy, List<Download>> entry = it.next();
BuddyPluginBuddy buddy = entry.getKey();
if (!buddy.isOnline(false)) {
continue;
}
InetAddress ip = buddy.getAdjustedIP();
if (ip == null) {
continue;
}
int tcp_port = buddy.getTCPPort();
int udp_port = buddy.getUDPPort();
List<Download> downloads = (List<Download>) entry.getValue();
for (int i = 0; i < downloads.size(); i++) {
Download download = downloads.get(i);
PeerManager pm = download.getPeerManager();
if (pm == null) {
continue;
}
Peer[] existing_peers = pm.getPeers(ip.getHostAddress());
boolean connected = false;
for (int j = 0; j < existing_peers.length; j++) {
Peer peer = existing_peers[j];
if (peer.getTCPListenPort() == tcp_port || peer.getUDPListenPort() == udp_port) {
if (lan && !peer.isLANLocal()) {
AddressUtils.addLANRateLimitAddress(ip);
peer.resetLANLocalStatus();
}
connected = true;
break;
}
}
if (connected) {
log(download.getName() + " - peer " + ip.getHostAddress() + " already connected");
continue;
}
log(download.getName() + " - connecting to peer " + ip.getHostAddress());
PEPeerManager c_pm = PluginCoreUtils.unwrap(pm);
Map user_data = new LightHashMap();
user_data.put(PEER_KEY, download);
user_data.put(Peer.PR_PRIORITY_CONNECTION, Boolean.TRUE);
c_pm.addPeer(ip.getHostAddress(), tcp_port, udp_port, true, user_data);
}
}
}
use of com.biglybt.plugin.net.buddy.BuddyPluginBuddy in project BiglyBT by BiglySoftware.
the class BuddyPluginTracker method isBuddy.
protected int isBuddy(Peer peer) {
PartialBuddy pb = new PartialBuddy(this, peer);
String peer_ip = peer.getIp();
List<String> ips = AddressUtils.getLANAddresses(peer_ip);
synchronized (online_buddies) {
if (partial_buddies.containsKey(pb)) {
return (BUDDY_YES);
}
int result = BUDDY_NO;
outer: for (int i = 0; i < ips.size(); i++) {
String ip = ips.get(i);
List<BuddyPluginBuddy> buddies = online_buddy_ips.get(ip);
if (buddies != null) {
if (peer.getTCPListenPort() == 0 && peer.getUDPListenPort() == 0) {
result = BUDDY_MAYBE;
} else {
for (int j = 0; j < buddies.size(); j++) {
BuddyPluginBuddy buddy = (BuddyPluginBuddy) buddies.get(j);
if (buddy.getTCPPort() == peer.getTCPListenPort() && buddy.getTCPPort() != 0) {
result = BUDDY_YES;
break outer;
}
if (buddy.getUDPPort() == peer.getUDPListenPort() && buddy.getUDPPort() != 0) {
result = BUDDY_YES;
break outer;
}
}
}
}
}
return (result);
}
}
use of com.biglybt.plugin.net.buddy.BuddyPluginBuddy in project BiglyBT by BiglySoftware.
the class BuddyPluginTracker method untrackDownload.
protected void untrackDownload(Download download) {
synchronized (tracked_downloads) {
if (tracked_downloads.remove(download)) {
download_set_id++;
downloadData download_data = (downloadData) download.getUserData(BuddyPluginTracker.class);
download.setUserData(BuddyPluginTracker.class, null);
HashWrapper full_id = download_data.getID();
full_id_map.remove(full_id);
HashWrapper short_id = new HashWrapper(full_id.getHash(), 0, SHORT_ID_SIZE);
List dls = (List) short_id_map.get(short_id);
if (dls != null) {
dls.remove(download);
if (dls.size() == 0) {
short_id_map.remove(short_id);
}
}
}
}
synchronized (online_buddies) {
Iterator<BuddyPluginBuddy> it = online_buddies.iterator();
while (it.hasNext()) {
BuddyPluginBuddy buddy = it.next();
BuddyTrackingData buddy_data = getBuddyData(buddy);
buddy_data.removeDownload(download);
}
}
synchronized (actively_tracking) {
actively_tracking.remove(download);
}
}
Aggregations