use of com.biglybt.core.subs.util.SubscriptionResultFilterable in project BiglyBT by BiglySoftware.
the class SBC_SearchResultsView method downloadAction.
public static void downloadAction(final SearchSubsResultBase entry) {
String link = entry.getTorrentLink();
if (link.startsWith("chat:")) {
Utils.launch(link);
return;
}
showDownloadFTUX(entry, new UserPrompterResultListener() {
@Override
public void prompterClosed(int result) {
if (result == 0) {
String referer_str = null;
String torrentUrl = entry.getTorrentLink();
try {
Map headers = UrlUtils.getBrowserHeaders(referer_str);
if (entry instanceof SubscriptionResultFilterable) {
SubscriptionResultFilterable sub_entry = (SubscriptionResultFilterable) entry;
Subscription subs = sub_entry.getSubscription();
try {
Engine engine = subs.getEngine();
if (engine != null && engine instanceof WebEngine) {
WebEngine webEngine = (WebEngine) engine;
if (webEngine.isNeedsAuth()) {
headers.put("Cookie", webEngine.getCookies());
}
}
} catch (Throwable e) {
Debug.out(e);
}
subs.addPotentialAssociation(sub_entry.getID(), torrentUrl);
} else {
SBC_SearchResult search_entry = (SBC_SearchResult) entry;
Engine engine = search_entry.getEngine();
if (engine != null) {
engine.addPotentialAssociation(torrentUrl);
if (engine instanceof WebEngine) {
WebEngine webEngine = (WebEngine) engine;
if (webEngine.isNeedsAuth()) {
headers.put("Cookie", webEngine.getCookies());
}
}
}
}
byte[] torrent_hash = entry.getHash();
if (torrent_hash != null) {
if (torrent_hash != null && !torrentUrl.toLowerCase().startsWith("magnet")) {
String title = entry.getName();
String magnet = UrlUtils.getMagnetURI(torrent_hash, title, null);
headers.put("X-Alternative-URI-1", magnet);
}
}
PluginInitializer.getDefaultInterface().getDownloadManager().addDownload(new URL(torrentUrl), headers);
} catch (Throwable e) {
Debug.out(e);
}
}
}
});
}
use of com.biglybt.core.subs.util.SubscriptionResultFilterable in project BiglyBT by BiglySoftware.
the class SBC_SubscriptionResultsView method userDelete.
private void userDelete(SubscriptionResultFilterable[] results) {
TableRowCore focusedRow = tv_subs_results.getFocusedRow();
TableRowCore focusRow = null;
if (focusedRow != null) {
int i = tv_subs_results.indexOf(focusedRow);
int size = tv_subs_results.size(false);
if (i < size - 1) {
focusRow = tv_subs_results.getRow(i + 1);
} else if (i > 0) {
focusRow = tv_subs_results.getRow(i - 1);
}
}
Map<Subscription, List<String>> result_map = new HashMap<>();
for (SubscriptionResultFilterable result : results) {
Subscription subs = result.getSubscription();
List<String> ids = result_map.get(subs);
if (ids == null) {
ids = new ArrayList<>();
result_map.put(subs, ids);
}
ids.add(result.getID());
}
for (Map.Entry<Subscription, List<String>> entry : result_map.entrySet()) {
List<String> ids = entry.getValue();
entry.getKey().getHistory().deleteResults(ids.toArray(new String[ids.size()]));
}
if (focusRow != null) {
tv_subs_results.setSelectedRows(new TableRowCore[] { focusRow });
}
}
use of com.biglybt.core.subs.util.SubscriptionResultFilterable in project BiglyBT by BiglySoftware.
the class SBC_SubscriptionResultsView method reconcileResults.
private void reconcileResults(Subscription subs) {
synchronized (this) {
if (subs != ds || ds == null || subs == null || tv_subs_results == null) {
return;
}
tv_subs_results.processDataSourceQueueSync();
Collection<SubscriptionResultFilterable> existing_results = tv_subs_results.getDataSources(true);
Map<String, SubscriptionResultFilterable> existing_map = new HashMap<>();
for (SubscriptionResultFilterable result : existing_results) {
existing_map.put(result.getID(), result);
}
SubscriptionResult[] current_results = ds.getResults(false);
List<SubscriptionResultFilterable> new_results = new ArrayList<>(current_results.length);
for (SubscriptionResult result : current_results) {
SubscriptionResultFilterable existing = existing_map.remove(result.getID());
if (existing == null) {
new_results.add(new SubscriptionResultFilterable(ds, result));
} else {
existing.updateFrom(result);
}
}
if (new_results.size() > 0) {
tv_subs_results.addDataSources(new_results.toArray(new SubscriptionResultFilterable[new_results.size()]));
}
if (existing_map.size() > 0) {
Collection<SubscriptionResultFilterable> to_remove = existing_map.values();
tv_subs_results.removeDataSources(to_remove.toArray(new SubscriptionResultFilterable[to_remove.size()]));
}
}
}
use of com.biglybt.core.subs.util.SubscriptionResultFilterable in project BiglyBT by BiglySoftware.
the class SBC_SubscriptionResultsView method initTable.
private void initTable(Composite control) {
tv_subs_results = TableViewFactory.createTableViewSWT(SubscriptionResultFilterable.class, TABLE_SR, TABLE_SR, new TableColumnCore[0], ColumnSearchSubResultAge.COLUMN_ID, SWT.MULTI | SWT.FULL_SELECTION | SWT.VIRTUAL);
TableColumnManager tcm = TableColumnManager.getInstance();
tcm.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, ColumnSearchSubResultAssetDate.COLUMN_ID, ColumnSearchSubResultRank.COLUMN_ID, ColumnSearchSubResultCategory.COLUMN_ID });
if (!tcm.hasTableColumnSettings(TABLE_SR)) {
tcm.setDefaultSortColumnName(TABLE_SR, ColumnSearchSubResultAge.COLUMN_ID);
TableColumnCore tcc = tcm.getTableColumnCore(TABLE_SR, ColumnSearchSubResultAge.COLUMN_ID);
if (tcc != null) {
tcc.setDefaultSortAscending(true);
}
}
SWTSkinObjectTextbox soFilterBox = (SWTSkinObjectTextbox) getSkinObject("filterbox");
if (soFilterBox != null) {
tv_subs_results.enableFilterCheck(soFilterBox.getBubbleTextBox(), this);
}
tv_subs_results.setRowDefaultHeight(COConfigurationManager.getIntParameter("Search Subs Row Height"));
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) {
SubscriptionResultFilterable rc = (SubscriptionResultFilterable) 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++) {
SubscriptionResultFilterable rc = (SubscriptionResultFilterable) 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);
}
}
TableRowCore hash_row = null;
byte[] hash = null;
if (rows.length == 1) {
hash_row = rows[0];
SubscriptionResultFilterable rc = (SubscriptionResultFilterable) hash_row.getDataSource();
hash = rc.getHash();
}
for (TableRowCore row : tv_subs_results.getRows()) {
Color target = null;
if (row != hash_row && hash != null) {
if (Arrays.equals(((SubscriptionResultFilterable) row.getDataSource()).getHash(), hash)) {
target = Colors.blues[Colors.BLUES_MIDLIGHT];
}
}
((TableRowSWT) row).requestBackgroundColor(colour_requester, target);
}
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 SubscriptionResultFilterable[] results = new SubscriptionResultFilterable[_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 (SubscriptionResultFilterable 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();
}
}
SubscriptionResultFilterable[] content = new SubscriptionResultFilterable[selected.length];
for (int i = 0; i < content.length; i++) {
content[i] = (SubscriptionResultFilterable) 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.core.subs.util.SubscriptionResultFilterable in project BiglyBT by BiglySoftware.
the class ColumnSubResultNew method cellPaint.
@Override
public void cellPaint(GC gc, TableCellSWT cell) {
SubscriptionResultFilterable entry = (SubscriptionResultFilterable) cell.getDataSource();
Rectangle cellBounds = cell.getBounds();
Image img = entry == null || entry.getRead() ? imgOld : imgNew;
if (img != null && !img.isDisposed()) {
Rectangle imgBounds = img.getBounds();
gc.drawImage(img, cellBounds.x + ((cellBounds.width - imgBounds.width) / 2), cellBounds.y + ((cellBounds.height - imgBounds.height) / 2));
}
}
Aggregations