use of com.biglybt.ui.selectedcontent.DownloadUrlInfo in project BiglyBT by BiglySoftware.
the class TorrentListViewsUtils method downloadDataSource.
public static void downloadDataSource(Object ds, boolean playNow, String referal) {
TOTorrent torrent = DataSourceUtils.getTorrent(ds);
if (torrent != null) {
// handle encapsulated vuze file
try {
Map torrent_map = torrent.serialiseToMap();
torrent_map.remove("info");
VuzeFile vf = VuzeFileHandler.getSingleton().loadVuzeFile(torrent_map);
if (vf != null) {
VuzeFileHandler.getSingleton().handleFiles(new VuzeFile[] { vf }, VuzeFileComponent.COMP_TYPE_NONE);
return;
}
} catch (Throwable e) {
}
}
// one is likely stale
if (torrent != null) {
TorrentUIUtilsV3.addTorrentToGM(torrent);
} else {
DownloadUrlInfo dlInfo = DataSourceUtils.getDownloadInfo(ds);
if (dlInfo != null) {
TorrentUIUtilsV3.loadTorrent(dlInfo, playNow, false, true);
return;
}
String hash = DataSourceUtils.getHash(ds);
if (hash != null) {
dlInfo = new DownloadUrlInfo(UrlUtils.parseTextForMagnets(hash));
dlInfo.setReferer(referal);
TorrentUIUtilsV3.loadTorrent(dlInfo, playNow, false, true);
return;
}
}
}
use of com.biglybt.ui.selectedcontent.DownloadUrlInfo in project BiglyBT by BiglySoftware.
the class SBC_SubscriptionResultsView method initTable.
private void initTable(Composite control) {
tv_subs_results = TableViewFactory.createTableViewSWT(SBC_SubscriptionResult.class, TABLE_SR, TABLE_SR, new TableColumnCore[0], ColumnSearchSubResultAge.COLUMN_ID, SWT.MULTI | SWT.FULL_SELECTION | SWT.VIRTUAL);
TableColumnManager tableManager = TableColumnManager.getInstance();
tableManager.setDefaultColumnNames(TABLE_SR, new String[] { ColumnSubResultNew.COLUMN_ID, ColumnSearchSubResultType.COLUMN_ID, ColumnSearchSubResultName.COLUMN_ID, ColumnSearchSubResultActions.COLUMN_ID, ColumnSearchSubResultSize.COLUMN_ID, ColumnSearchSubResultSeedsPeers.COLUMN_ID, ColumnSearchSubResultRatings.COLUMN_ID, ColumnSearchSubResultAge.COLUMN_ID, ColumnSearchSubResultRank.COLUMN_ID, ColumnSearchSubResultCategory.COLUMN_ID });
tableManager.setDefaultSortColumnName(TABLE_SR, ColumnSearchSubResultAge.COLUMN_ID);
TableColumnCore tcc = tableManager.getTableColumnCore(TABLE_SR, ColumnSearchSubResultAge.COLUMN_ID);
if (tcc != null) {
tcc.setDefaultSortAscending(true);
}
if (txtFilter != null) {
tv_subs_results.enableFilterCheck(txtFilter, this);
}
tv_subs_results.setRowDefaultHeight(COConfigurationManager.getIntParameter("Search Subs Row Height"));
SWTSkinObject soSizeSlider = getSkinObject("table-size-slider");
if (soSizeSlider instanceof SWTSkinObjectContainer) {
SWTSkinObjectContainer so = (SWTSkinObjectContainer) soSizeSlider;
if (!tv_subs_results.enableSizeSlider(so.getComposite(), 16, 100)) {
so.setVisible(false);
}
}
table_parent = new Composite(control, SWT.NONE);
table_parent.setLayoutData(Utils.getFilledFormData());
GridLayout layout = new GridLayout();
layout.marginHeight = layout.marginWidth = layout.verticalSpacing = layout.horizontalSpacing = 0;
table_parent.setLayout(layout);
tv_subs_results.addSelectionListener(new TableSelectionListener() {
@Override
public void selected(TableRowCore[] _rows) {
updateSelectedContent();
}
@Override
public void mouseExit(TableRowCore row) {
}
@Override
public void mouseEnter(TableRowCore row) {
}
@Override
public void focusChanged(TableRowCore focus) {
UIFunctions uiFunctions = UIFunctionsManager.getUIFunctions();
if (uiFunctions != null) {
uiFunctions.refreshIconBar();
}
}
@Override
public void deselected(TableRowCore[] rows) {
updateSelectedContent();
}
@Override
public void defaultSelected(TableRowCore[] rows, int stateMask) {
if (rows.length == 1) {
SBC_SubscriptionResult rc = (SBC_SubscriptionResult) rows[0].getDataSource();
SBC_SearchResultsView.downloadAction(rc);
}
}
private void updateSelectedContent() {
TableRowCore[] rows = tv_subs_results.getSelectedRows();
ArrayList<ISelectedContent> valid = new ArrayList<>();
last_selected_content.clear();
for (int i = 0; i < rows.length; i++) {
SBC_SubscriptionResult rc = (SBC_SubscriptionResult) rows[i].getDataSource();
last_selected_content.add(rc);
byte[] hash = rc.getHash();
if (hash != null && hash.length > 0) {
SelectedContent sc = new SelectedContent(Base32.encode(hash), rc.getName());
sc.setDownloadInfo(new DownloadUrlInfo(getDownloadURI(rc)));
valid.add(sc);
}
}
ISelectedContent[] sels = valid.toArray(new ISelectedContent[valid.size()]);
SelectedContentManager.changeCurrentlySelectedContent("IconBarEnabler", sels, tv_subs_results);
UIFunctions uiFunctions = UIFunctionsManager.getUIFunctions();
if (uiFunctions != null) {
uiFunctions.refreshIconBar();
}
}
}, false);
tv_subs_results.addLifeCycleListener(new TableLifeCycleListener() {
@Override
public void tableLifeCycleEventOccurred(TableView tv, int eventType, Map<String, Object> data) {
if (eventType == TableLifeCycleListener.EVENT_TABLELIFECYCLE_INITIALIZED) {
reconcileResults(ds);
}
}
});
tv_subs_results.addMenuFillListener(new TableViewSWTMenuFillListener() {
@Override
public void fillMenu(String sColumnName, Menu menu) {
Object[] _related_content = tv_subs_results.getSelectedDataSources().toArray();
final SBC_SubscriptionResult[] results = new SBC_SubscriptionResult[_related_content.length];
System.arraycopy(_related_content, 0, results, 0, results.length);
MenuItem item = new MenuItem(menu, SWT.PUSH);
item.setText(MessageText.getString("label.copy.url.to.clip"));
item.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
StringBuffer buffer = new StringBuffer(1024);
for (SBC_SubscriptionResult result : results) {
if (buffer.length() > 0) {
buffer.append("\r\n");
}
buffer.append(getDownloadURI(result));
}
ClipboardCopy.copyToClipBoard(buffer.toString());
}
});
item.setEnabled(results.length > 0);
SearchSubsUtils.addMenu(results, menu);
new MenuItem(menu, SWT.SEPARATOR);
if (results.length == 1) {
if (SearchSubsUtils.addMenu(results[0], menu)) {
new MenuItem(menu, SWT.SEPARATOR);
}
}
final MenuItem remove_item = new MenuItem(menu, SWT.PUSH);
remove_item.setText(MessageText.getString("azbuddy.ui.menu.remove"));
Utils.setMenuItemImage(remove_item, "delete");
remove_item.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
userDelete(results);
}
});
remove_item.setEnabled(results.length > 0);
new MenuItem(menu, SWT.SEPARATOR);
}
@Override
public void addThisColumnSubMenu(String columnName, Menu menuThisColumn) {
}
});
tv_subs_results.addKeyListener(new KeyListener() {
@Override
public void keyPressed(KeyEvent e) {
if (e.stateMask == 0 && e.keyCode == SWT.DEL) {
Object[] selected;
synchronized (this) {
if (tv_subs_results == null) {
selected = new Object[0];
} else {
selected = tv_subs_results.getSelectedDataSources().toArray();
}
}
SBC_SubscriptionResult[] content = new SBC_SubscriptionResult[selected.length];
for (int i = 0; i < content.length; i++) {
content[i] = (SBC_SubscriptionResult) selected[i];
}
userDelete(content);
e.doit = false;
}
}
@Override
public void keyReleased(KeyEvent arg0) {
}
});
/*
if (ds instanceof RCMItemSubView) {
tv_related_content.addCountChangeListener(new TableCountChangeListener() {
public void rowRemoved(TableRowCore row) {
updateCount();
}
public void rowAdded(TableRowCore row) {
updateCount();
}
private void updateCount() {
int size = tv_related_content == null ? 0 : tv_related_content.size(false);
((RCMItemSubView) ds).setCount(size);
}
});
((RCMItemSubView) ds).setCount(0);
}
*/
tv_subs_results.initialize(table_parent);
control.layout(true);
}
use of com.biglybt.ui.selectedcontent.DownloadUrlInfo in project BiglyBT by BiglySoftware.
the class TorrentListener method handleMessage.
@Override
public void handleMessage(final BrowserMessage message) {
String opid = message.getOperationId();
if (OP_LOAD_TORRENT.equals(opid) || OP_LOAD_TORRENT_OLD.equals(opid)) {
final Map decodedMap = message.getDecodedMap();
String url = MapUtils.getMapString(decodedMap, "url", null);
final boolean playNow = MapUtils.getMapBoolean(decodedMap, "play-now", false);
final boolean playPrepare = MapUtils.getMapBoolean(decodedMap, "play-prepare", false);
final boolean bringToFront = MapUtils.getMapBoolean(decodedMap, "bring-to-front", true);
if (url != null) {
if (torrentURLHandler != null) {
try {
torrentURLHandler.handleTorrentURL(url);
} catch (Throwable e) {
Debug.printStackTrace(e);
}
}
final DownloadUrlInfo dlInfo = new DownloadUrlInfo(url);
dlInfo.setReferer(message.getReferer());
CoreFactory.addCoreRunningListener(new CoreRunningListener() {
@Override
public void coreRunning(Core core) {
TorrentUIUtilsV3.loadTorrent(dlInfo, playNow, playPrepare, bringToFront);
}
});
} else {
CoreFactory.addCoreRunningListener(new CoreRunningListener() {
@Override
public void coreRunning(Core core) {
loadTorrentByB64(core, message, MapUtils.getMapString(decodedMap, "b64", null));
}
});
}
} else {
throw new IllegalArgumentException("Unknown operation: " + opid);
}
}
use of com.biglybt.ui.selectedcontent.DownloadUrlInfo in project BiglyBT by BiglySoftware.
the class SBC_SearchResultsView method initTable.
private void initTable(Composite control) {
tv_subs_results = TableViewFactory.createTableViewSWT(SBC_SearchResult.class, TABLE_SR, TABLE_SR, new TableColumnCore[0], ColumnSearchSubResultName.COLUMN_ID, SWT.MULTI | SWT.FULL_SELECTION | SWT.VIRTUAL);
TableColumnManager tableManager = TableColumnManager.getInstance();
tableManager.setDefaultColumnNames(TABLE_SR, new String[] { ColumnSearchSubResultType.COLUMN_ID, ColumnSearchSubResultName.COLUMN_ID, ColumnSearchSubResultActions.COLUMN_ID, ColumnSearchSubResultSize.COLUMN_ID, ColumnSearchSubResultSeedsPeers.COLUMN_ID, ColumnSearchSubResultRatings.COLUMN_ID, ColumnSearchSubResultAge.COLUMN_ID, ColumnSearchSubResultRank.COLUMN_ID, ColumnSearchSubResultCategory.COLUMN_ID, ColumnSearchResultSite.COLUMN_ID });
tableManager.setDefaultSortColumnName(TABLE_SR, ColumnSearchSubResultRank.COLUMN_ID);
if (txtFilter != null) {
tv_subs_results.enableFilterCheck(txtFilter, this);
}
tv_subs_results.setRowDefaultHeight(COConfigurationManager.getIntParameter("Search Subs Row Height"));
SWTSkinObject soSizeSlider = getSkinObject("table-size-slider");
if (soSizeSlider instanceof SWTSkinObjectContainer) {
SWTSkinObjectContainer so = (SWTSkinObjectContainer) soSizeSlider;
if (!tv_subs_results.enableSizeSlider(so.getComposite(), 16, 100)) {
so.setVisible(false);
}
}
table_parent = new Composite(control, SWT.NONE);
table_parent.setLayoutData(Utils.getFilledFormData());
GridLayout layout = new GridLayout();
layout.marginHeight = layout.marginWidth = layout.verticalSpacing = layout.horizontalSpacing = 0;
table_parent.setLayout(layout);
tv_subs_results.addSelectionListener(new TableSelectionListener() {
@Override
public void selected(TableRowCore[] _rows) {
updateSelectedContent();
}
@Override
public void mouseExit(TableRowCore row) {
}
@Override
public void mouseEnter(TableRowCore row) {
}
@Override
public void focusChanged(TableRowCore focus) {
UIFunctions uiFunctions = UIFunctionsManager.getUIFunctions();
if (uiFunctions != null) {
uiFunctions.refreshIconBar();
}
}
@Override
public void deselected(TableRowCore[] rows) {
updateSelectedContent();
}
@Override
public void defaultSelected(TableRowCore[] rows, int stateMask) {
if (rows.length == 1) {
SBC_SearchResult rc = (SBC_SearchResult) rows[0].getDataSource();
downloadAction(rc);
}
}
private void updateSelectedContent() {
TableRowCore[] rows = tv_subs_results.getSelectedRows();
ArrayList<ISelectedContent> valid = new ArrayList<>();
last_selected_content.clear();
for (int i = 0; i < rows.length; i++) {
SBC_SearchResult rc = (SBC_SearchResult) rows[i].getDataSource();
last_selected_content.add(rc);
byte[] hash = rc.getHash();
if (hash != null && hash.length > 0) {
SelectedContent sc = new SelectedContent(Base32.encode(hash), rc.getName());
sc.setDownloadInfo(new DownloadUrlInfo(getDownloadURI(rc)));
valid.add(sc);
}
}
ISelectedContent[] sels = valid.toArray(new ISelectedContent[valid.size()]);
SelectedContentManager.changeCurrentlySelectedContent("IconBarEnabler", sels, tv_subs_results);
UIFunctions uiFunctions = UIFunctionsManager.getUIFunctions();
if (uiFunctions != null) {
uiFunctions.refreshIconBar();
}
}
}, false);
tv_subs_results.addMenuFillListener(new TableViewSWTMenuFillListener() {
@Override
public void fillMenu(String sColumnName, Menu menu) {
Object[] _related_content = tv_subs_results.getSelectedDataSources().toArray();
final SBC_SearchResult[] results = new SBC_SearchResult[_related_content.length];
System.arraycopy(_related_content, 0, results, 0, results.length);
MenuItem item = new MenuItem(menu, SWT.PUSH);
item.setText(MessageText.getString("label.copy.url.to.clip"));
item.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
StringBuffer buffer = new StringBuffer(1024);
for (SBC_SearchResult result : results) {
if (buffer.length() > 0) {
buffer.append("\r\n");
}
buffer.append(getDownloadURI(result));
}
ClipboardCopy.copyToClipBoard(buffer.toString());
}
});
item.setEnabled(results.length > 0);
SearchSubsUtils.addMenu(results, menu);
new MenuItem(menu, SWT.SEPARATOR);
if (results.length == 1) {
if (SearchSubsUtils.addMenu(results[0], menu)) {
new MenuItem(menu, SWT.SEPARATOR);
}
}
}
@Override
public void addThisColumnSubMenu(String columnName, Menu menuThisColumn) {
}
});
tv_subs_results.initialize(table_parent);
control.layout(true);
}
Aggregations