use of com.biglybt.pif.ui.tables.TableRow in project BiglyBT by BiglySoftware.
the class DeviceManagerUI method setupTranscodeMenus.
private void setupTranscodeMenus() {
if (DISABLED_TRANSCODING) {
return;
}
// top level menus
final String[] tables = { TableManager.TABLE_MYTORRENTS_INCOMPLETE, TableManager.TABLE_MYTORRENTS_INCOMPLETE_BIG, TableManager.TABLE_MYTORRENTS_COMPLETE, TableManager.TABLE_MYTORRENTS_COMPLETE_BIG, TableManager.TABLE_TORRENT_FILES, TableManager.TABLE_MYTORRENTS_UNOPENED, TableManager.TABLE_MYTORRENTS_UNOPENED_BIG, TableManager.TABLE_MYTORRENTS_ALL_BIG };
TableManager table_manager = plugin_interface.getUIManager().getTableManager();
MenuItemFillListener menu_fill_listener = new MenuItemFillListener() {
@Override
public void menuWillBeShown(MenuItem menu, Object _target) {
final TableRow[] target;
if (_target instanceof TableRow) {
target = new TableRow[] { (TableRow) _target };
} else {
target = (TableRow[]) _target;
}
boolean enabled = target.length > 0;
for (TableRow row : target) {
Object obj = row.getDataSource();
if (obj instanceof Download) {
Download download = (Download) obj;
if (download.getState() == Download.ST_ERROR) {
enabled = false;
}
} else {
DiskManagerFileInfo file = (DiskManagerFileInfo) obj;
try {
if (file.getIndex() < 0 || file.getDownload().getState() == Download.ST_ERROR) {
enabled = false;
}
} catch (Throwable e) {
enabled = false;
}
}
}
menu.setEnabled(enabled);
menu.removeAllChildItems();
if (enabled) {
Device[] devices = device_manager.getDevices();
int devices_added = 0;
for (Device device : devices) {
if (device.isHidden()) {
continue;
}
if (device instanceof TranscodeTarget) {
devices_added++;
final TranscodeTarget renderer = (TranscodeTarget) device;
TranscodeProfile[] profiles = renderer.getTranscodeProfiles();
TableContextMenuItem device_item = plugin_interface.getUIManager().getTableManager().addContextMenuItem((TableContextMenuItem) menu, "!" + device.getName() + (profiles.length == 0 ? " (No Profiles)" : "") + "!");
device_item.setStyle(MenuItem.STYLE_MENU);
if (profiles.length == 0) {
device_item.setEnabled(false);
} else {
Arrays.sort(profiles, new Comparator<TranscodeProfile>() {
@Override
public int compare(TranscodeProfile o1, TranscodeProfile o2) {
int i1 = o1.getIconIndex();
int i2 = o2.getIconIndex();
if (i1 == i2) {
return o1.getName().compareToIgnoreCase(o2.getName());
} else {
return (i1 - i2);
}
}
});
for (final TranscodeProfile profile : profiles) {
TableContextMenuItem profile_item = plugin_interface.getUIManager().getTableManager().addContextMenuItem(device_item, "!" + profile.getName() + "!");
profile_item.addMultiListener(new MenuItemListener() {
@Override
public void selected(MenuItem menu, Object x) {
for (TableRow row : target) {
Object obj = row.getDataSource();
try {
if (obj instanceof Download) {
Download download = (Download) obj;
addDownload(renderer, profile, -1, download);
} else {
DiskManagerFileInfo file = (DiskManagerFileInfo) obj;
addFile(renderer, profile, -1, file);
}
} catch (Throwable e) {
Debug.out(e);
}
}
}
});
}
}
}
}
if (devices_added == 0) {
TableContextMenuItem device_item = plugin_interface.getUIManager().getTableManager().addContextMenuItem((TableContextMenuItem) menu, "!(No Devices)!");
device_item.setEnabled(false);
}
}
}
};
// instead of forcing a loop like this
for (String table : tables) {
TableContextMenuItem menu = table_manager.addContextMenuItem(table, "devices.contextmenu.xcode");
menu.setStyle(TableContextMenuItem.STYLE_MENU);
menu.setHeaderCategory(MenuItem.HEADER_CONTENT);
menu.addFillListener(menu_fill_listener);
menu.setDisposeWithUIDetach(UIInstance.UIT_SWT);
}
}
use of com.biglybt.pif.ui.tables.TableRow in project BiglyBT by BiglySoftware.
the class MagnetPlugin method initialize.
@Override
public void initialize(PluginInterface _plugin_interface) {
plugin_interface = _plugin_interface;
MagnetURIHandler uri_handler = MagnetURIHandler.getSingleton();
final LocaleUtilities lu = plugin_interface.getUtilities().getLocaleUtilities();
lu.addListener(new LocaleListener() {
@Override
public void localeChanged(Locale l) {
updateLocale(lu);
}
});
updateLocale(lu);
BasicPluginConfigModel config = plugin_interface.getUIManager().createBasicPluginConfigModel(ConfigSection.SECTION_PLUGINS, PLUGIN_CONFIGSECTION_ID);
config.addInfoParameter2("MagnetPlugin.current.port", String.valueOf(uri_handler.getPort()));
secondary_lookup = config.addBooleanParameter2("MagnetPlugin.use.lookup.service", "MagnetPlugin.use.lookup.service", true);
md_lookup = config.addBooleanParameter2("MagnetPlugin.use.md.download", "MagnetPlugin.use.md.download", true);
md_lookup_delay = config.addIntParameter2("MagnetPlugin.use.md.download.delay", "MagnetPlugin.use.md.download.delay", MD_LOOKUP_DELAY_SECS_DEFAULT);
md_lookup.addEnabledOnSelection(md_lookup_delay);
timeout_param = config.addIntParameter2("MagnetPlugin.timeout.secs", "MagnetPlugin.timeout.secs", PLUGIN_DOWNLOAD_TIMEOUT_SECS_DEFAULT);
sources_param = config.addStringListParameter2("MagnetPlugin.add.sources", "MagnetPlugin.add.sources", SOURCE_VALUES, SOURCE_STRINGS, SOURCE_VALUES[1]);
sources_extra_param = config.addIntParameter2("MagnetPlugin.add.sources.extra", "MagnetPlugin.add.sources.extra", 0);
magnet_recovery = config.addBooleanParameter2("MagnetPlugin.recover.magnets", "MagnetPlugin.recover.magnets", true);
Parameter[] nps = new Parameter[AENetworkClassifier.AT_NETWORKS.length];
for (int i = 0; i < nps.length; i++) {
String nn = AENetworkClassifier.AT_NETWORKS[i];
String config_name = "Network Selection Default." + nn;
String msg_text = "ConfigView.section.connection.networks." + nn;
final BooleanParameter param = config.addBooleanParameter2(config_name, msg_text, COConfigurationManager.getBooleanParameter(config_name));
COConfigurationManager.addParameterListener(config_name, new com.biglybt.core.config.ParameterListener() {
@Override
public void parameterChanged(String name) {
param.setDefaultValue(COConfigurationManager.getBooleanParameter(name));
}
});
nps[i] = param;
net_params.put(nn, param);
}
config.createGroup("label.default.nets", nps);
MenuItemListener listener = new MenuItemListener() {
@Override
public void selected(MenuItem _menu, Object _target) {
TableRow[] rows = (TableRow[]) _target;
String cb_all_data = "";
for (TableRow row : rows) {
Torrent torrent;
String name;
Object ds = row.getDataSource();
Download download = null;
ShareResource share = null;
if (ds instanceof ShareResourceFile) {
ShareResourceFile sf = (ShareResourceFile) ds;
try {
torrent = sf.getItem().getTorrent();
} catch (ShareException e) {
continue;
}
name = sf.getName();
share = sf;
} else if (ds instanceof ShareResourceDir) {
ShareResourceDir sd = (ShareResourceDir) ds;
try {
torrent = sd.getItem().getTorrent();
} catch (ShareException e) {
continue;
}
name = sd.getName();
share = sd;
} else if (ds instanceof Download) {
download = (Download) ds;
torrent = download.getTorrent();
name = download.getName();
} else {
continue;
}
boolean is_share = false;
Set<String> networks = new HashSet<>();
if (share != null) {
is_share = true;
Map<String, String> properties = share.getProperties();
if (properties != null) {
String nets = properties.get(ShareManager.PR_NETWORKS);
if (nets != null) {
String[] bits = nets.split(",");
for (String bit : bits) {
bit = AENetworkClassifier.internalise(bit.trim());
if (bit != null) {
networks.add(bit);
}
}
}
}
}
if (download != null) {
TorrentAttribute ta = plugin_interface.getTorrentManager().getAttribute(TorrentAttribute.TA_NETWORKS);
String[] nets = download.getListAttribute(ta);
networks.addAll(Arrays.asList(nets));
try {
byte[] hash = download.getTorrentHash();
if (plugin_interface.getShareManager().lookupShare(hash) != null) {
is_share = true;
}
} catch (Throwable e) {
}
}
String cb_data = download == null ? UrlUtils.getMagnetURI(name, torrent) : UrlUtils.getMagnetURI(download);
if (download != null) {
List<Tag> tags = TagManagerFactory.getTagManager().getTagsForTaggable(TagType.TT_DOWNLOAD_MANUAL, PluginCoreUtils.unwrap(download));
for (Tag tag : tags) {
if (tag.isPublic()) {
cb_data += "&tag=" + UrlUtils.encode(tag.getTagName(true));
}
}
}
String sources = sources_param.getValue();
boolean add_sources = sources.equals("2") || (sources.equals("1") && is_share);
if (add_sources) {
if (networks.isEmpty()) {
for (String net : AENetworkClassifier.AT_NETWORKS) {
if (isNetworkEnabled(net)) {
networks.add(net);
}
}
}
if (networks.contains(AENetworkClassifier.AT_PUBLIC) && !cb_data.contains("xsource=")) {
InetAddress ip = NetworkAdmin.getSingleton().getDefaultPublicAddress();
InetAddress ip_v6 = NetworkAdmin.getSingleton().getDefaultPublicAddressV6();
int port = TCPNetworkManager.getSingleton().getTCPListeningPortNumber();
if (ip != null && port > 0) {
cb_data += "&xsource=" + UrlUtils.encode(ip.getHostAddress() + ":" + port);
}
if (ip_v6 != null && port > 0) {
cb_data += "&xsource=" + UrlUtils.encode(ip_v6.getHostAddress() + ":" + port);
}
int extra = sources_extra_param.getValue();
if (extra > 0) {
if (download == null) {
if (torrent != null) {
download = plugin_interface.getDownloadManager().getDownload(torrent);
}
}
if (download != null) {
Set<String> added = new HashSet<>();
DownloadManager dm = PluginCoreUtils.unwrap(download);
PEPeerManager pm = dm.getPeerManager();
if (pm != null) {
List<PEPeer> peers = pm.getPeers();
for (PEPeer peer : peers) {
String peer_ip = peer.getIp();
if (AENetworkClassifier.categoriseAddress(peer_ip) == AENetworkClassifier.AT_PUBLIC) {
int peer_port = peer.getTCPListenPort();
if (peer_port > 0) {
cb_data += "&xsource=" + UrlUtils.encode(peer_ip + ":" + peer_port);
added.add(peer_ip);
extra--;
if (extra == 0) {
break;
}
}
}
}
}
if (extra > 0) {
Map response_cache = dm.getDownloadState().getTrackerResponseCache();
if (response_cache != null) {
List<TRTrackerAnnouncerResponsePeer> peers = TRTrackerAnnouncerFactory.getCachedPeers(response_cache);
for (TRTrackerAnnouncerResponsePeer peer : peers) {
String peer_ip = peer.getAddress();
if (AENetworkClassifier.categoriseAddress(peer_ip) == AENetworkClassifier.AT_PUBLIC) {
if (!added.contains(peer_ip)) {
int peer_port = peer.getPort();
if (peer_port > 0) {
cb_data += "&xsource=" + UrlUtils.encode(peer_ip + ":" + peer_port);
added.add(peer_ip);
extra--;
if (extra == 0) {
break;
}
}
}
}
}
}
}
}
}
}
}
// removed this as well - nothing wrong with allowing magnet copy
// for private torrents - they still can't be tracked if you don't
// have permission
/*if ( torrent.isPrivate()){
cb_data = getMessageText( "private_torrent" );
}else if ( torrent.isDecentralised()){
*/
// ok
/* relaxed this as we allow such torrents to be downloaded via magnet links
* (as opposed to tracked in the DHT)
}else if ( torrent.isDecentralisedBackupEnabled()){
TorrentAttribute ta_peer_sources = plugin_interface.getTorrentManager().getAttribute( TorrentAttribute.TA_PEER_SOURCES );
String[] sources = download.getListAttribute( ta_peer_sources );
boolean ok = false;
for (int i=0;i<sources.length;i++){
if ( sources[i].equalsIgnoreCase( "DHT")){
ok = true;
break;
}
}
if ( !ok ){
cb_data = getMessageText( "decentral_disabled" );
}
}else{
cb_data = getMessageText( "decentral_backup_disabled" );
*/
// }
// System.out.println( "MagnetPlugin: export = " + url );
cb_all_data += (cb_all_data.length() == 0 ? "" : "\n") + cb_data;
}
try {
plugin_interface.getUIManager().copyToClipBoard(cb_all_data);
} catch (Throwable e) {
e.printStackTrace();
}
}
};
List<TableContextMenuItem> menus = new ArrayList<>();
for (String table : TableManager.TABLE_MYTORRENTS_ALL) {
TableContextMenuItem menu = plugin_interface.getUIManager().getTableManager().addContextMenuItem(table, "MagnetPlugin.contextmenu.exporturi");
menu.addMultiListener(listener);
menu.setHeaderCategory(MenuItem.HEADER_SOCIAL);
menus.add(menu);
}
uri_handler.addListener(new MagnetURIHandlerListener() {
@Override
public byte[] badge() {
InputStream is = getClass().getClassLoader().getResourceAsStream("com/biglybt/plugin/magnet/Magnet.gif");
if (is == null) {
return (null);
}
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
byte[] buffer = new byte[8192];
while (true) {
int len = is.read(buffer);
if (len <= 0) {
break;
}
baos.write(buffer, 0, len);
}
} finally {
is.close();
}
return (baos.toByteArray());
} catch (Throwable e) {
Debug.printStackTrace(e);
return (null);
}
}
@Override
public byte[] download(MagnetURIHandlerProgressListener muh_listener, byte[] hash, String args, InetSocketAddress[] sources, long timeout) throws MagnetURIHandlerException {
try {
Download dl = plugin_interface.getDownloadManager().getDownload(hash);
if (dl != null) {
Torrent torrent = dl.getTorrent();
if (torrent != null) {
byte[] torrent_data = torrent.writeToBEncodedData();
torrent_data = addTrackersAndWebSeedsEtc(torrent_data, args, new HashSet<String>());
return (torrent_data);
}
}
} catch (Throwable e) {
Debug.printStackTrace(e);
}
return (recoverableDownload(muh_listener, hash, args, sources, timeout, false));
}
@Override
public boolean download(URL url) throws MagnetURIHandlerException {
try {
plugin_interface.getDownloadManager().addDownload(url, false);
return (true);
} catch (DownloadException e) {
throw (new MagnetURIHandlerException("Operation failed", e));
}
}
@Override
public boolean set(String name, Map values) {
List l = listeners.getList();
for (int i = 0; i < l.size(); i++) {
if (((MagnetPluginListener) l.get(i)).set(name, values)) {
return (true);
}
}
return (false);
}
@Override
public int get(String name, Map values) {
List l = listeners.getList();
for (int i = 0; i < l.size(); i++) {
int res = ((MagnetPluginListener) l.get(i)).get(name, values);
if (res != Integer.MIN_VALUE) {
return (res);
}
}
return (Integer.MIN_VALUE);
}
});
plugin_interface.getUIManager().addUIListener(new UIManagerListener() {
@Override
public void UIAttached(UIInstance instance) {
if (instance.getUIType().equals(UIInstance.UIT_SWT)) {
try {
Class.forName("com.biglybt.plugin.magnet.swt.MagnetPluginUISWT").getConstructor(new Class[] { UIInstance.class, TableContextMenuItem[].class }).newInstance(new Object[] { instance, menus.toArray(new TableContextMenuItem[menus.size()]) });
} catch (Throwable e) {
e.printStackTrace();
}
}
}
@Override
public void UIDetached(UIInstance instance) {
}
});
final List<Download> to_delete = new ArrayList<>();
Download[] downloads = plugin_interface.getDownloadManager().getDownloads();
for (Download download : downloads) {
if (download.getFlag(Download.FLAG_METADATA_DOWNLOAD)) {
to_delete.add(download);
}
}
final AESemaphore delete_done = new AESemaphore("delete waiter");
if (to_delete.size() > 0) {
AEThread2 t = new AEThread2("MagnetPlugin:delmds", true) {
@Override
public void run() {
try {
for (Download download : to_delete) {
try {
download.stop();
} catch (Throwable e) {
}
try {
download.remove(true, true);
} catch (Throwable e) {
Debug.out(e);
}
}
} finally {
delete_done.release();
}
}
};
t.start();
} else {
delete_done.release();
}
plugin_interface.addListener(new PluginListener() {
@Override
public void initializationComplete() {
// make sure DDB is initialised as we need it to register its
// transfer types
AEThread2 t = new AEThread2("MagnetPlugin:init", true) {
@Override
public void run() {
delete_done.reserve();
recoverDownloads();
plugin_interface.getDistributedDatabase();
}
};
t.start();
}
@Override
public void closedownInitiated() {
}
@Override
public void closedownComplete() {
}
});
}
use of com.biglybt.pif.ui.tables.TableRow in project BiglyBT by BiglySoftware.
the class FilesView method initYourTableView.
@Override
public TableViewSWT<DiskManagerFileInfo> initYourTableView() {
tv = TableViewFactory.createTableViewSWT(com.biglybt.pif.disk.DiskManagerFileInfo.class, TableManager.TABLE_TORRENT_FILES, getPropertiesPrefix(), basicItems, "firstpiece", SWT.MULTI | SWT.FULL_SELECTION | SWT.VIRTUAL);
if (allowTabViews) {
tv.setEnableTabViews(enable_tabs, true, null);
}
basicItems = new TableColumnCore[0];
UIFunctionsSWT uiFunctions = UIFunctionsManagerSWT.getUIFunctionsSWT();
if (uiFunctions != null) {
UISWTInstance pluginUI = uiFunctions.getUISWTInstance();
registerPluginViews(pluginUI);
}
tv.addTableDataSourceChangedListener(this, true);
tv.addRefreshListener(this, true);
tv.addSelectionListener(this, false);
tv.addMenuFillListener(this);
tv.addLifeCycleListener(this);
tv.addKeyListener(this);
tv.addRefreshListener(new TableRowRefreshListener() {
@Override
public void rowRefresh(TableRow row) {
if (row instanceof TableRowSWT) {
Object ds = ((TableRowSWT) row).getDataSource(true);
if (ds instanceof FilesViewNodeInner) {
((TableRowSWT) row).setFontStyle(SWT.ITALIC);
((TableRowSWT) row).setAlpha(220);
}
}
}
});
return tv;
}
use of com.biglybt.pif.ui.tables.TableRow 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);
az2_handler = new BuddyPluginAZ2(this);
sec_man = plugin_interface.getUtilities().getSecurityManager();
logger = plugin_interface.getLogger().getChannel("Friends");
logger.setDiagnostic();
final LocaleUtilities lu = plugin_interface.getUtilities().getLocaleUtilities();
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);
// nickname
nick_name_param = config.addStringParameter2("azbuddy.nickname", "azbuddy.nickname", "");
nick_name_param.setGenerateIntermediateEvents(false);
nick_name_param.addListener(new ParameterListener() {
@Override
public void parameterChanged(Parameter param) {
updateNickName(nick_name_param.getValue());
}
});
// online status
String[] os_values = STATUS_VALUES;
String[] os_labels = STATUS_STRINGS;
online_status_param = config.addStringListParameter2("azbuddy.online_status", "azbuddy.online_status", os_values, os_labels, os_values[0]);
online_status_param.addListener(new ParameterListener() {
@Override
public void parameterChanged(Parameter param) {
int status = Integer.parseInt(online_status_param.getValue());
updateOnlineStatus(status);
}
});
// If we add this then use proper message texts in the STATUS_STRINGS
online_status_param.setVisible(SUPPORT_ONLINE_STATUS);
// 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);
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();
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, nick_name_param, online_status_param, protocol_speed, enable_chat_notifications, cat_pub, tracker_enable, tracker_so_enable, buddies_lan_local });
// 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 end
beta_plugin = new BuddyPluginBeta(plugin_interface, this, beta_enabled_param);
final TableContextMenuItem menu_item_itorrents = plugin_interface.getUIManager().getTableManager().addContextMenuItem(TableManager.TABLE_MYTORRENTS_INCOMPLETE, "azbuddy.contextmenu");
final TableContextMenuItem menu_item_ctorrents = plugin_interface.getUIManager().getTableManager().addContextMenuItem(TableManager.TABLE_MYTORRENTS_COMPLETE, "azbuddy.contextmenu");
menu_item_itorrents.setStyle(TableContextMenuItem.STYLE_MENU);
menu_item_itorrents.setHeaderCategory(MenuItem.HEADER_SOCIAL);
menu_item_ctorrents.setStyle(TableContextMenuItem.STYLE_MENU);
menu_item_ctorrents.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();
boolean incomplete = ((TableContextMenuItem) menu).getTableID() == TableManager.TABLE_MYTORRENTS_INCOMPLETE;
TableContextMenuItem parent = incomplete ? menu_item_itorrents : menu_item_ctorrents;
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(parent, "!" + buddy.getName() + (online ? "" : (" - " + MessageText.getString("label.disconnected"))) + "!");
item.addMultiListener(new MenuItemListener() {
@Override
public void selected(MenuItem menu, Object target) {
for (Torrent torrent : torrents) {
az2_handler.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_itorrents.addFillListener(menu_fill_listener);
menu_item_ctorrents.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, String.class }).newInstance(new Object[] { BuddyPlugin.this, instance, VIEW_ID });
for (Runnable r : swt_ui_waiters) {
try {
r.run();
} catch (Throwable e) {
Debug.out(e);
}
}
swt_ui_waiters.clear();
}
} catch (Throwable e) {
e.printStackTrace();
}
}
setupDisablePrompt(instance);
}
@Override
public void UIDetached(UIInstance instance) {
if (instance.getUIType().equals(UIInstance.UIT_SWT) && swt_ui != null) {
swt_ui.destroy();
swt_ui = null;
}
}
});
ParameterListener enabled_listener = new ParameterListener() {
@Override
public void parameterChanged(Parameter param) {
boolean classic_enabled = classic_enabled_param.getValue();
nick_name_param.setEnabled(classic_enabled);
online_status_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(tracker_enable.getValue());
if (param != null) {
setClassicEnabledInternal(classic_enabled);
fireEnabledStateChanged();
}
}
};
enabled_listener.parameterChanged(null);
classic_enabled_param.addListener(enabled_listener);
beta_enabled_param.addListener(enabled_listener);
tracker_enable.addListener(enabled_listener);
loadConfig();
registerMessageHandler();
plugin_interface.addListener(new PluginListener() {
@Override
public void initializationComplete() {
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() {
saveConfig(true);
closedown();
beta_plugin.closedown();
}
@Override
public void closedownComplete() {
}
});
}
use of com.biglybt.pif.ui.tables.TableRow in project BiglyBT by BiglySoftware.
the class SBC_LibraryTableView method initShow.
public void initShow(Core core) {
Object data = soParent.getControl().getData("TorrentFilterMode");
if (data instanceof Long) {
torrentFilterMode = (int) ((Long) data).longValue();
}
data = soParent.getControl().getData("DataSource");
boolean useBigTable = useBigTable();
SWTSkinObjectTextbox soFilter = (SWTSkinObjectTextbox) skin.getSkinObject("library-filter", soParent.getParent());
Text txtFilter = soFilter == null ? null : soFilter.getTextControl();
SWTSkinObjectContainer soCats = (SWTSkinObjectContainer) skin.getSkinObject("library-categories", soParent.getParent());
Composite cCats = soCats == null ? null : soCats.getComposite();
// columns not needed for small mode, all torrents
TableColumnCore[] columns = useBigTable || torrentFilterMode != SBC_LibraryView.TORRENTS_ALL ? getColumns() : null;
if (null != columns) {
TableColumnManager tcManager = TableColumnManager.getInstance();
tcManager.addColumns(columns);
}
if (useBigTable) {
if (torrentFilterMode == SBC_LibraryView.TORRENTS_COMPLETE || torrentFilterMode == SBC_LibraryView.TORRENTS_INCOMPLETE || torrentFilterMode == SBC_LibraryView.TORRENTS_UNOPENED) {
swtViewListener = torrentView = new MyTorrentsView_Big(core, torrentFilterMode, columns, txtFilter, cCats);
} else {
swtViewListener = torrentView = new MyTorrentsView_Big(core, torrentFilterMode, columns, txtFilter, cCats);
}
} else {
String tableID = SB_Transfers.getTableIdFromFilterMode(torrentFilterMode, false);
if (torrentFilterMode == SBC_LibraryView.TORRENTS_COMPLETE) {
swtViewListener = torrentView = new MyTorrentsView(core, tableID, true, columns, txtFilter, cCats, true);
} else if (torrentFilterMode == SBC_LibraryView.TORRENTS_INCOMPLETE) {
swtViewListener = torrentView = new MyTorrentsView(core, tableID, false, columns, txtFilter, cCats, true);
} else if (torrentFilterMode == SBC_LibraryView.TORRENTS_UNOPENED) {
swtViewListener = torrentView = new MyTorrentsView(core, tableID, true, columns, txtFilter, cCats, true) {
@Override
public boolean isOurDownloadManager(DownloadManager dm) {
if (PlatformTorrentUtils.getHasBeenOpened(dm)) {
return false;
}
return super.isOurDownloadManager(dm);
}
};
} else {
swtViewListener = new MyTorrentsSuperView(txtFilter, cCats) {
@Override
public void initializeDone() {
MyTorrentsView seedingview = getSeedingview();
if (seedingview != null) {
seedingview.overrideDefaultSelected(new TableSelectionAdapter() {
@Override
public void defaultSelected(TableRowCore[] rows, int stateMask, int origin) {
doDefaultClick(rows, stateMask, false, origin);
}
});
MyTorrentsView torrentview = getTorrentview();
if (torrentview != null) {
torrentview.overrideDefaultSelected(new TableSelectionAdapter() {
@Override
public void defaultSelected(TableRowCore[] rows, int stateMask, int origin) {
doDefaultClick(rows, stateMask, false, origin);
}
});
}
}
}
};
}
if (torrentView != null) {
torrentView.overrideDefaultSelected(new TableSelectionAdapter() {
@Override
public void defaultSelected(TableRowCore[] rows, int stateMask, int origin) {
doDefaultClick(rows, stateMask, false, origin);
}
});
}
}
if (torrentView != null) {
tv = torrentView.getTableView();
if (torrentFilterMode == SBC_LibraryView.TORRENTS_UNOPENED) {
torrentView.setRebuildListOnFocusGain(true);
}
}
try {
view = new UISWTViewImpl(ID + torrentFilterMode, UISWTInstance.VIEW_MAIN, false);
view.setDatasource(data);
view.setEventListener(swtViewListener, true);
} catch (Exception e) {
Debug.out(e);
}
SWTSkinObjectContainer soContents = new SWTSkinObjectContainer(skin, skin.getSkinProperties(), getUpdateUIName(), "", soMain);
skin.layout();
viewComposite = soContents.getComposite();
viewComposite.setLayoutData(Utils.getFilledFormData());
GridLayout gridLayout = new GridLayout();
gridLayout.horizontalSpacing = gridLayout.verticalSpacing = gridLayout.marginHeight = gridLayout.marginWidth = 0;
viewComposite.setLayout(gridLayout);
view.initialize(viewComposite);
SWTSkinObject soSizeSlider = skin.getSkinObject("table-size-slider", soParent.getParent());
if (soSizeSlider instanceof SWTSkinObjectContainer) {
SWTSkinObjectContainer so = (SWTSkinObjectContainer) soSizeSlider;
if (tv != null && !tv.enableSizeSlider(so.getComposite(), 16, 100)) {
so.setVisible(false);
}
}
if (torrentFilterMode == SBC_LibraryView.TORRENTS_ALL && tv != null) {
tv.addRefreshListener(new TableRowRefreshListener() {
@Override
public void rowRefresh(TableRow row) {
TableRowSWT rowCore = (TableRowSWT) row;
Object ds = rowCore.getDataSource(true);
if (!(ds instanceof DownloadManager)) {
return;
}
DownloadManager dm = (DownloadManager) ds;
boolean changed = false;
boolean assumedComplete = dm.getAssumedComplete();
if (!assumedComplete) {
changed |= rowCore.setAlpha(160);
} else if (!PlatformTorrentUtils.getHasBeenOpened(dm)) {
changed |= rowCore.setAlpha(255);
} else {
changed |= rowCore.setAlpha(255);
}
}
});
}
viewComposite.getParent().layout(true);
}
Aggregations