Search in sources :

Example 1 with SubscriptionResultFilterable

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);
                }
            }
        }
    });
}
Also used : UserPrompterResultListener(com.biglybt.ui.UserPrompterResultListener) SubscriptionResultFilterable(com.biglybt.core.subs.util.SubscriptionResultFilterable) Subscription(com.biglybt.core.subs.Subscription) WebEngine(com.biglybt.core.metasearch.impl.web.WebEngine) Engine(com.biglybt.core.metasearch.Engine) WebEngine(com.biglybt.core.metasearch.impl.web.WebEngine) URL(java.net.URL)

Example 2 with SubscriptionResultFilterable

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 });
    }
}
Also used : List(java.util.List) SubscriptionResultFilterable(com.biglybt.core.subs.util.SubscriptionResultFilterable) Subscription(com.biglybt.core.subs.Subscription)

Example 3 with SubscriptionResultFilterable

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()]));
        }
    }
}
Also used : SubscriptionResult(com.biglybt.core.subs.SubscriptionResult) SubscriptionResultFilterable(com.biglybt.core.subs.util.SubscriptionResultFilterable)

Example 4 with SubscriptionResultFilterable

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);
}
Also used : DownloadUrlInfo(com.biglybt.ui.selectedcontent.DownloadUrlInfo) TableViewSWTMenuFillListener(com.biglybt.ui.swt.views.table.TableViewSWTMenuFillListener) TableColumnManager(com.biglybt.ui.common.table.impl.TableColumnManager) UIFunctions(com.biglybt.ui.UIFunctions) SelectedContent(com.biglybt.ui.selectedcontent.SelectedContent) ISelectedContent(com.biglybt.ui.selectedcontent.ISelectedContent) ISelectedContent(com.biglybt.ui.selectedcontent.ISelectedContent) Color(org.eclipse.swt.graphics.Color) SubscriptionResultFilterable(com.biglybt.core.subs.util.SubscriptionResultFilterable)

Example 5 with SubscriptionResultFilterable

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));
    }
}
Also used : Rectangle(org.eclipse.swt.graphics.Rectangle) SubscriptionResultFilterable(com.biglybt.core.subs.util.SubscriptionResultFilterable) Image(org.eclipse.swt.graphics.Image)

Aggregations

SubscriptionResultFilterable (com.biglybt.core.subs.util.SubscriptionResultFilterable)9 Subscription (com.biglybt.core.subs.Subscription)2 UserPrompterResultListener (com.biglybt.ui.UserPrompterResultListener)2 Engine (com.biglybt.core.metasearch.Engine)1 WebEngine (com.biglybt.core.metasearch.impl.web.WebEngine)1 SubscriptionResult (com.biglybt.core.subs.SubscriptionResult)1 SubscriptionResultFilter (com.biglybt.core.subs.SubscriptionResultFilter)1 UIFunctions (com.biglybt.ui.UIFunctions)1 TableColumnManager (com.biglybt.ui.common.table.impl.TableColumnManager)1 DownloadUrlInfo (com.biglybt.ui.selectedcontent.DownloadUrlInfo)1 ISelectedContent (com.biglybt.ui.selectedcontent.ISelectedContent)1 SelectedContent (com.biglybt.ui.selectedcontent.SelectedContent)1 SWTSkin (com.biglybt.ui.swt.skin.SWTSkin)1 SWTSkinCheckboxListener (com.biglybt.ui.swt.skin.SWTSkinCheckboxListener)1 SWTSkinObjectCheckbox (com.biglybt.ui.swt.skin.SWTSkinObjectCheckbox)1 SWTSkinObjectContainer (com.biglybt.ui.swt.skin.SWTSkinObjectContainer)1 VuzeMessageBox (com.biglybt.ui.swt.views.skin.VuzeMessageBox)1 VuzeMessageBoxListener (com.biglybt.ui.swt.views.skin.VuzeMessageBoxListener)1 TableViewSWTMenuFillListener (com.biglybt.ui.swt.views.table.TableViewSWTMenuFillListener)1 URL (java.net.URL)1