Search in sources :

Example 21 with Subscription

use of com.biglybt.core.subs.Subscription in project BiglyBT by BiglySoftware.

the class MetaSearchListener method search.

protected void search(Map decodedMap, Engine target) {
    String searchText = (String) decodedMap.get("searchText");
    String headers = (String) decodedMap.get("headers");
    final Long sid = (Long) decodedMap.get("sid");
    Boolean mature = (Boolean) decodedMap.get("mature");
    Long l_max_per_engine = (Long) decodedMap.get("maxResultsPerEngine");
    int max_per_engine = l_max_per_engine == null ? 100 : l_max_per_engine.intValue();
    if (max_per_engine < 1) {
        max_per_engine = 1;
    }
    if (target == null) {
        // override engine selection for subscriptions
        String subscriptionId = ((String) decodedMap.get("subs_id"));
        if (subscriptionId != null) {
            Subscription subs = SubscriptionManagerFactory.getSingleton().getSubscriptionByID(subscriptionId);
            if (subs != null) {
                try {
                    Engine engine = subs.getEngine();
                    if (engine != null) {
                        target = engine;
                    }
                } catch (Throwable e) {
                    Debug.out(e);
                }
            }
        }
    }
    ResultListener listener = new ResultListener() {

        @Override
        public void contentReceived(Engine engine, String content) {
        }

        @Override
        public void matchFound(Engine engine, String[] fields) {
        }

        @Override
        public void engineFailed(Engine engine, Throwable e) {
            Debug.out(e);
            Map params = getParams(engine);
            params.put("error", Debug.getNestedExceptionMessage(e));
            sendBrowserMessage("metasearch", "engineFailed", params);
        }

        @Override
        public void engineRequiresLogin(Engine engine, Throwable e) {
            Map params = getParams(engine);
            params.put("error", Debug.getNestedExceptionMessage(e));
            sendBrowserMessage("metasearch", "engineRequiresLogin", params);
        }

        @Override
        public void resultsComplete(Engine engine) {
            sendBrowserMessage("metasearch", "engineCompleted", getParams(engine));
        }

        @Override
        public void resultsReceived(Engine engine, Result[] results) {
            Map params = getParams(engine);
            List resultsList = new ArrayList(results.length);
            for (int i = 0; i < results.length; i++) {
                Result result = results[i];
                resultsList.add(result.toJSONMap());
            }
            params.put("results", resultsList);
            sendBrowserMessage("metasearch", "resultsReceived", params);
        }

        protected Map getParams(Engine engine) {
            Map<String, Object> params = new HashMap<>();
            params.put("id", new Long(engine.getId()));
            params.put("name", engine.getName());
            params.put("favicon", engine.getIcon());
            params.put("dl_link_css", engine.getDownloadLinkCSS());
            params.put("shareable", Boolean.valueOf(engine.isShareable()));
            if (sid != null) {
                params.put("sid", sid);
            }
            return (params);
        }
    };
    List<SearchParameter> sps = new ArrayList<>();
    sps.add(new SearchParameter("s", searchText));
    if (mature != null) {
        sps.add(new SearchParameter("m", mature.toString()));
    }
    SearchParameter[] parameters = (SearchParameter[]) sps.toArray(new SearchParameter[sps.size()]);
    MetaSearchManager metaSearchManager = MetaSearchManagerFactory.getSingleton();
    Map<String, String> context = new HashMap<>();
    context.put(Engine.SC_FORCE_FULL, "true");
    context.put(Engine.SC_BATCH_PERIOD, "1000");
    context.put(Engine.SC_REMOVE_DUP_HASH, "true");
    if (target == null) {
        metaSearchManager.getMetaSearch().search(listener, parameters, headers, context, max_per_engine);
    } else {
        metaSearchManager.getMetaSearch().search(new Engine[] { target }, listener, parameters, headers, context, max_per_engine);
    }
}
Also used : SubscriptionResult(com.biglybt.core.subs.SubscriptionResult) JSONObject(org.json.simple.JSONObject) Subscription(com.biglybt.core.subs.Subscription) WebEngine(com.biglybt.core.metasearch.impl.web.WebEngine)

Example 22 with Subscription

use of com.biglybt.core.subs.Subscription in project BiglyBT by BiglySoftware.

the class ColumnSubscriptionAutoDownload method refresh.

@Override
public void refresh(TableCell cell) {
    boolean autoDownload = false;
    Subscription sub = (Subscription) cell.getDataSource();
    if (sub != null) {
        SubscriptionHistory history = sub.getHistory();
        if (history != null) {
            autoDownload = history.isAutoDownload();
        }
    }
    if (!cell.setSortValue(autoDownload ? 1 : 0) && cell.isValid()) {
        return;
    }
    if (!cell.isShown()) {
        return;
    }
    if (sub.isAutoDownloadSupported()) {
        cell.setText(DisplayFormatters.getYesNo(autoDownload));
    } else {
        if (!cell.setSortValue(-1) && cell.isValid()) {
            return;
        }
        cell.setText("");
    }
    return;
}
Also used : SubscriptionHistory(com.biglybt.core.subs.SubscriptionHistory) Subscription(com.biglybt.core.subs.Subscription)

Example 23 with Subscription

use of com.biglybt.core.subs.Subscription in project BiglyBT by BiglySoftware.

the class ColumnSubscriptionCategory method refresh.

@Override
public void refresh(TableCell cell) {
    Subscription sub = (Subscription) cell.getDataSource();
    String category = null;
    if (sub != null) {
        category = sub.getCategory();
    }
    if (category == null) {
        category = "";
    }
    if (!cell.setSortValue(category) && cell.isValid()) {
        return;
    }
    if (!cell.isShown()) {
        return;
    }
    cell.setText(category);
    return;
}
Also used : Subscription(com.biglybt.core.subs.Subscription)

Example 24 with Subscription

use of com.biglybt.core.subs.Subscription in project BiglyBT by BiglySoftware.

the class ColumnSubscriptionError method refresh.

@Override
public void refresh(TableCell cell) {
    String error = "";
    Subscription sub = (Subscription) cell.getDataSource();
    if (sub != null) {
        error = sub.getHistory().getLastError();
    }
    if (!cell.setSortValue(error) && cell.isValid()) {
        return;
    }
    if (!cell.isShown()) {
        return;
    }
    cell.setText(error);
}
Also used : Subscription(com.biglybt.core.subs.Subscription)

Example 25 with Subscription

use of com.biglybt.core.subs.Subscription in project BiglyBT by BiglySoftware.

the class ColumnSubscriptionName method refresh.

@Override
public void refresh(TableCell cell) {
    String name = null;
    Subscription sub = (Subscription) cell.getDataSource();
    if (sub != null) {
        name = sub.getName();
    }
    if (name == null) {
        name = "";
    }
    if (!cell.setSortValue(name) && cell.isValid()) {
        return;
    }
}
Also used : Subscription(com.biglybt.core.subs.Subscription)

Aggregations

Subscription (com.biglybt.core.subs.Subscription)34 WebEngine (com.biglybt.core.metasearch.impl.web.WebEngine)7 Engine (com.biglybt.core.metasearch.Engine)5 SubscriptionException (com.biglybt.core.subs.SubscriptionException)5 VuzeFile (com.biglybt.core.vuzefile.VuzeFile)4 URL (java.net.URL)4 Rectangle (org.eclipse.swt.graphics.Rectangle)4 PluginEngine (com.biglybt.core.metasearch.impl.plugin.PluginEngine)3 SubscriptionHistory (com.biglybt.core.subs.SubscriptionHistory)3 SubscriptionResult (com.biglybt.core.subs.SubscriptionResult)3 AERunnable (com.biglybt.core.util.AERunnable)3 TableCellAddedListener (com.biglybt.pif.ui.tables.TableCellAddedListener)3 TableCellRefreshListener (com.biglybt.pif.ui.tables.TableCellRefreshListener)3 TableColumnCreationListener (com.biglybt.pif.ui.tables.TableColumnCreationListener)3 MultipleDocumentInterface (com.biglybt.ui.mdi.MultipleDocumentInterface)3 TableCellSWTPaintListener (com.biglybt.ui.swt.views.table.TableCellSWTPaintListener)3 FormAttachment (org.eclipse.swt.layout.FormAttachment)3 FormData (org.eclipse.swt.layout.FormData)3 FormLayout (org.eclipse.swt.layout.FormLayout)3 Event (org.eclipse.swt.widgets.Event)3