use of com.biglybt.core.metasearch.Engine in project BiglyBT by BiglySoftware.
the class SubscriptionSchedulerImpl method download.
@Override
public boolean download(Subscription subs, boolean is_auto) throws SubscriptionException {
SubscriptionDownloader downloader;
AESemaphore sem = null;
String rate_limits = manager.getRateLimits().trim();
synchronized (active_subscription_downloaders) {
if (rate_limits.length() > 0) {
try {
Engine engine = subs.getEngine();
if (engine instanceof WebEngine) {
String url_str = ((WebEngine) engine).getSearchUrl(true);
String host = new URL(url_str).getHost();
String[] bits = rate_limits.split(",");
for (String bit : bits) {
String[] temp = bit.trim().split("=");
if (temp.length == 2) {
String lhs = temp[0].trim();
if (lhs.equals(host)) {
int mins = Integer.parseInt(temp[1].trim());
if (mins > 0) {
long now = SystemTime.getMonotonousTime();
Long last = rate_limit_map.get(host);
if (last != null && now - last < mins * 60 * 1000) {
if (is_auto) {
return (false);
} else {
throw (new SubscriptionException("Rate limiting prevents download from " + host));
}
}
rate_limit_map.put(host, now);
}
}
}
}
}
} catch (SubscriptionException e) {
throw (e);
} catch (Throwable e) {
Debug.out(e);
}
}
List waiting = (List) active_subscription_downloaders.get(subs);
if (waiting != null) {
sem = new AESemaphore("SS:waiter");
waiting.add(sem);
if (!is_auto) {
active_subs_download_is_auto = false;
}
} else {
active_subscription_downloaders.put(subs, new ArrayList());
active_subs_download_is_auto = is_auto;
}
downloader = new SubscriptionDownloader(manager, (SubscriptionImpl) subs);
}
try {
if (sem == null) {
downloader.download();
} else {
sem.reserve();
}
return (true);
} finally {
boolean was_auto;
synchronized (active_subscription_downloaders) {
List waiting = (List) active_subscription_downloaders.remove(subs);
if (waiting != null) {
for (int i = 0; i < waiting.size(); i++) {
((AESemaphore) waiting.get(i)).release();
}
}
was_auto = active_subs_download_is_auto;
}
((SubscriptionImpl) subs).fireDownloaded(was_auto);
}
}
use of com.biglybt.core.metasearch.Engine in project BiglyBT by BiglySoftware.
the class SearchUtils method addMenus.
public static void addMenus(final MenuManager menuManager) {
final com.biglybt.pif.ui.menus.MenuItem template_menu = menuManager.addMenuItem("sidebar.Search", "Search.menu.engines");
template_menu.setDisposeWithUIDetach(UIInstance.UIT_SWT);
template_menu.setStyle(com.biglybt.pif.ui.menus.MenuItem.STYLE_MENU);
template_menu.addFillListener(new MenuItemFillListener() {
@Override
public void menuWillBeShown(com.biglybt.pif.ui.menus.MenuItem menu, Object data) {
template_menu.removeAllChildItems();
Engine[] engines = MetaSearchManagerFactory.getSingleton().getMetaSearch().getEngines(true, false);
Arrays.sort(engines, new Comparator<Engine>() {
@Override
public int compare(Engine o1, Engine o2) {
return (o1.getName().compareToIgnoreCase(o2.getName()));
}
});
com.biglybt.pif.ui.menus.MenuItem import_menu = menuManager.addMenuItem(template_menu, "menu.import.json.from.clipboard");
import_menu.addListener(new MenuItemListener() {
@Override
public void selected(com.biglybt.pif.ui.menus.MenuItem menu, Object target) {
importFromClipboard();
}
});
com.biglybt.pif.ui.menus.MenuItem sep = menuManager.addMenuItem(template_menu, "!sep!");
sep.setStyle(com.biglybt.pif.ui.menus.MenuItem.STYLE_SEPARATOR);
for (int i = 0; i < engines.length; i++) {
final Engine engine = engines[i];
com.biglybt.pif.ui.menus.MenuItem engine_menu = menuManager.addMenuItem(template_menu, "!" + engine.getName() + "!");
engine_menu.setStyle(com.biglybt.pif.ui.menus.MenuItem.STYLE_MENU);
if (!(engine instanceof PluginEngine)) {
com.biglybt.pif.ui.menus.MenuItem mi = menuManager.addMenuItem(engine_menu, "MyTorrentsView.menu.exportmenu");
mi.addListener(new MenuItemListener() {
@Override
public void selected(com.biglybt.pif.ui.menus.MenuItem menu, Object target) {
final Shell shell = Utils.findAnyShell();
shell.getDisplay().asyncExec(new AERunnable() {
@Override
public void runSupport() {
FileDialog dialog = new FileDialog(shell, SWT.SYSTEM_MODAL | SWT.SAVE);
dialog.setFilterPath(TorrentOpener.getFilterPathData());
dialog.setText(MessageText.getString("metasearch.export.select.template.file"));
dialog.setFilterExtensions(VuzeFileHandler.getVuzeFileFilterExtensions());
dialog.setFilterNames(VuzeFileHandler.getVuzeFileFilterExtensions());
String path = TorrentOpener.setFilterPathData(dialog.open());
if (path != null) {
if (!VuzeFileHandler.isAcceptedVuzeFileName(path)) {
path = VuzeFileHandler.getVuzeFileName(path);
}
try {
engine.exportToVuzeFile(new File(path));
} catch (Throwable e) {
Debug.out(e);
}
}
}
});
}
});
com.biglybt.pif.ui.menus.MenuItem copy_mi = menuManager.addMenuItem(engine_menu, "menu.export.json.to.clipboard");
copy_mi.addListener(new MenuItemListener() {
@Override
public void selected(com.biglybt.pif.ui.menus.MenuItem menu, Object target) {
final Shell shell = Utils.findAnyShell();
shell.getDisplay().asyncExec(new AERunnable() {
@Override
public void runSupport() {
try {
ClipboardCopy.copyToClipBoard(engine.exportToVuzeFile().exportToJSON());
} catch (Throwable e) {
Debug.out(e);
}
}
});
}
});
final Subscription subs = engine.getSubscription();
if (subs != null) {
com.biglybt.pif.ui.menus.MenuItem copy_uri = menuManager.addMenuItem(engine_menu, "label.copy.uri.to.clip");
copy_uri.addListener(new MenuItemListener() {
@Override
public void selected(com.biglybt.pif.ui.menus.MenuItem menu, Object target) {
final Shell shell = Utils.findAnyShell();
shell.getDisplay().asyncExec(new AERunnable() {
@Override
public void runSupport() {
try {
ClipboardCopy.copyToClipBoard(subs.getURI());
} catch (Throwable e) {
Debug.out(e);
}
}
});
}
});
}
if (engine instanceof WebEngine) {
final WebEngine we = (WebEngine) engine;
if (we.isNeedsAuth()) {
String cookies = we.getCookies();
if (cookies != null && cookies.length() > 0) {
mi = menuManager.addMenuItem(engine_menu, "Subscription.menu.resetauth");
mi.addListener(new MenuItemListener() {
@Override
public void selected(com.biglybt.pif.ui.menus.MenuItem menu, Object target) {
we.setCookies(null);
}
});
}
}
}
}
if (!(engine instanceof PluginEngine)) {
if (engine_menu.getItems().length > 0) {
com.biglybt.pif.ui.menus.MenuItem mi = menuManager.addMenuItem(engine_menu, "Subscription.menu.sep");
mi.setStyle(com.biglybt.pif.ui.menus.MenuItem.STYLE_SEPARATOR);
}
com.biglybt.pif.ui.menus.MenuItem mi = menuManager.addMenuItem(engine_menu, "Button.remove");
mi.addListener(new MenuItemListener() {
@Override
public void selected(com.biglybt.pif.ui.menus.MenuItem menu, Object target) {
engine.setSelectionState(Engine.SEL_STATE_FORCE_DESELECTED);
}
});
mi = menuManager.addMenuItem(engine_menu, "Subscription.menu.sep2");
mi.setStyle(com.biglybt.pif.ui.menus.MenuItem.STYLE_SEPARATOR);
}
if (engine_menu.getItems().length > 0) {
com.biglybt.pif.ui.menus.MenuItem mi = menuManager.addMenuItem(engine_menu, "Subscription.menu.sep2");
mi.setStyle(com.biglybt.pif.ui.menus.MenuItem.STYLE_SEPARATOR);
}
com.biglybt.pif.ui.menus.MenuItem mi = menuManager.addMenuItem(engine_menu, "Subscription.menu.properties");
mi.addListener(new MenuItemListener() {
@Override
public void selected(com.biglybt.pif.ui.menus.MenuItem menu, Object target) {
showProperties(engine);
}
});
}
}
});
com.biglybt.pif.ui.menus.MenuItem chat_menu = menuManager.addMenuItem("sidebar.Search", "label.chat");
chat_menu.setDisposeWithUIDetach(UIInstance.UIT_SWT);
MenuBuildUtils.addChatMenu(menuManager, chat_menu, new MenuBuildUtils.ChatKeyResolver() {
@Override
public String getChatKey(Object object) {
return ("Search Templates");
}
});
com.biglybt.pif.ui.menus.MenuItem export_menu = menuManager.addMenuItem("sidebar.Search", "search.export.all");
export_menu.setDisposeWithUIDetach(UIInstance.UIT_SWT);
export_menu.setStyle(com.biglybt.pif.ui.menus.MenuItem.STYLE_PUSH);
export_menu.addListener(new MenuItemListener() {
@Override
public void selected(com.biglybt.pif.ui.menus.MenuItem menu, Object target) {
exportAll();
}
});
}
use of com.biglybt.core.metasearch.Engine in project BiglyBT by BiglySoftware.
the class SubscriptionManagerUI method showProperties.
protected static void showProperties(Subscription subs) {
SubscriptionHistory history = subs.getHistory();
SimpleDateFormat df = new SimpleDateFormat();
String last_error = history.getLastError();
if (last_error == null) {
last_error = "";
}
String engine_str;
String auth_str = String.valueOf(false);
try {
Engine engine = subs.getEngine();
engine_str = engine.getNameEx();
if (engine instanceof WebEngine) {
WebEngine web_engine = (WebEngine) engine;
if (web_engine.isNeedsAuth()) {
auth_str = String.valueOf(true) + ": cookies=" + toString(web_engine.getRequiredCookies());
}
}
engine_str += ", eid=" + engine.getId();
} catch (Throwable e) {
engine_str = "Unknown";
auth_str = "";
}
String[] keys = { "subs.prop.enabled", "subs.prop.is_public", "subs.prop.is_auto", "subs.prop.is_auto_ok", "subs.prop.is_dl_anon", "subs.prop.update_period", "subs.prop.last_scan", "subs.prop.last_result", "subs.prop.next_scan", "subs.prop.last_error", "subs.prop.num_read", "subs.prop.num_unread", "label.max.results", "subs.prop.assoc", "subs.prop.version", "subs.prop.high_version", "subscriptions.listwindow.popularity", "subs.prop.template", "subs.prop.auth", "TableColumn.header.category", "TableColumn.header.tag.name", "subs.prop.query" };
String category_str;
String category = subs.getCategory();
if (category == null) {
category_str = MessageText.getString("Categories.uncategorized");
} else {
category_str = category;
}
Tag tag = TagManagerFactory.getTagManager().lookupTagByUID(subs.getTagID());
String tag_str = tag == null ? "" : tag.getTagName(true);
int check_freq = history.getCheckFrequencyMins();
long last_new_result = history.getLastNewResultTime();
long next_scan = history.getNextScanTime();
int max_results = history.getMaxNonDeletedResults();
if (max_results < 0) {
SubscriptionManager subs_man = SubscriptionManagerFactory.getSingleton();
max_results = subs_man.getMaxNonDeletedResults();
}
String max_results_str = (max_results == 0 ? MessageText.getString("ConfigView.unlimited") : String.valueOf(max_results));
String[] values = { String.valueOf(history.isEnabled()), String.valueOf(subs.isPublic()) + "/" + (!subs.isAnonymous()), String.valueOf(history.isAutoDownload()), String.valueOf(subs.isAutoDownloadSupported()), String.valueOf(history.getDownloadNetworks() != null), (check_freq == Integer.MAX_VALUE ? "" : (String.valueOf(history.getCheckFrequencyMins() + " " + MessageText.getString("ConfigView.text.minutes")))), df.format(new Date(history.getLastScanTime())), (last_new_result == 0 ? "" : df.format(new Date(last_new_result))), (next_scan == Long.MAX_VALUE ? "" : df.format(new Date(next_scan))), (last_error.length() == 0 ? MessageText.getString("label.none") : last_error), String.valueOf(history.getNumRead()), String.valueOf(history.getNumUnread()), max_results_str, String.valueOf(subs.getAssociationCount()), String.valueOf(subs.getVersion()), subs.getHighestVersion() > subs.getVersion() ? String.valueOf(subs.getHighestVersion()) : null, subs.getCachedPopularity() <= 1 ? "-" : String.valueOf(subs.getCachedPopularity()), engine_str + ", sid=" + subs.getID(), auth_str, category_str, tag_str, subs.getQueryKey() };
final PropertiesWindow pw = new PropertiesWindow(subs.getName(), keys, values);
try {
// kick off a popularity update
subs.getPopularity(new SubscriptionPopularityListener() {
@Override
public void gotPopularity(long popularity) {
pw.updateProperty("subscriptions.listwindow.popularity", String.valueOf(popularity));
}
@Override
public void failed(SubscriptionException error) {
}
});
} catch (Throwable e) {
}
}
use of com.biglybt.core.metasearch.Engine in project BiglyBT by BiglySoftware.
the class SubscriptionsView method initialize.
private void initialize(Composite parent) {
viewComposite = new Composite(parent, SWT.NONE);
viewComposite.setLayout(new FormLayout());
TableColumnCore[] columns = new TableColumnCore[] { new ColumnSubscriptionNew(TABLE_ID), new ColumnSubscriptionName(TABLE_ID), new ColumnSubscriptionNbNewResults(TABLE_ID), new ColumnSubscriptionNbResults(TABLE_ID), new ColumnSubscriptionMaxResults(TABLE_ID), new ColumnSubscriptionLastChecked(TABLE_ID), new ColumnSubscriptionSubscribers(TABLE_ID), new ColumnSubscriptionEnabled(TABLE_ID), new ColumnSubscriptionAutoDownload(TABLE_ID), new ColumnSubscriptionCategory(TABLE_ID), new ColumnSubscriptionTag(TABLE_ID), new ColumnSubscriptionParent(TABLE_ID), new ColumnSubscriptionError(TABLE_ID) };
TableColumnManager tcm = TableColumnManager.getInstance();
tcm.setDefaultColumnNames(TABLE_ID, new String[] { ColumnSubscriptionNew.COLUMN_ID, ColumnSubscriptionName.COLUMN_ID, ColumnSubscriptionNbNewResults.COLUMN_ID, ColumnSubscriptionNbResults.COLUMN_ID, ColumnSubscriptionAutoDownload.COLUMN_ID });
view = TableViewFactory.createTableViewSWT(Subscription.class, TABLE_ID, TABLE_ID, columns, "name", SWT.MULTI | SWT.FULL_SELECTION | SWT.VIRTUAL);
view.addLifeCycleListener(new TableLifeCycleListener() {
@Override
public void tableLifeCycleEventOccurred(TableView tv, int eventType, Map<String, Object> data) {
switch(eventType) {
case EVENT_TABLELIFECYCLE_INITIALIZED:
SubscriptionManagerFactory.getSingleton().addListener(SubscriptionsView.this);
view.addDataSources(SubscriptionManagerFactory.getSingleton().getSubscriptions(true));
break;
case EVENT_TABLELIFECYCLE_DESTROYED:
SubscriptionManagerFactory.getSingleton().removeListener(SubscriptionsView.this);
break;
}
}
});
view.addSelectionListener(new TableSelectionAdapter() {
PluginInterface pi = PluginInitializer.getDefaultInterface();
UIManager uim = pi.getUIManager();
MenuManager menu_manager = uim.getMenuManager();
TableManager table_manager = uim.getTableManager();
ArrayList<TableContextMenuItem> menu_items = new ArrayList<>();
SubscriptionManagerUI.MenuCreator menu_creator = new SubscriptionManagerUI.MenuCreator() {
@Override
public com.biglybt.pif.ui.menus.MenuItem createMenu(String resource_id) {
TableContextMenuItem menu = table_manager.addContextMenuItem(TABLE_ID, resource_id);
menu.setDisposeWithUIDetach(UIInstance.UIT_SWT);
menu_items.add(menu);
return (menu);
}
@Override
public void refreshView() {
}
};
@Override
public void defaultSelected(TableRowCore[] rows, int stateMask) {
if (rows.length == 1) {
TableRowCore row = rows[0];
Subscription sub = (Subscription) row.getDataSource();
if (sub == null) {
return;
}
if (sub.isSearchTemplate()) {
try {
VuzeFile vf = sub.getSearchTemplateVuzeFile();
if (vf != null) {
sub.setSubscribed(true);
VuzeFileHandler.getSingleton().handleFiles(new VuzeFile[] { vf }, VuzeFileComponent.COMP_TYPE_NONE);
for (VuzeFileComponent comp : vf.getComponents()) {
Engine engine = (Engine) comp.getData(Engine.VUZE_FILE_COMPONENT_ENGINE_KEY);
if (engine != null && (engine.getSelectionState() == Engine.SEL_STATE_DESELECTED || engine.getSelectionState() == Engine.SEL_STATE_FORCE_DESELECTED)) {
engine.setSelectionState(Engine.SEL_STATE_MANUAL_SELECTED);
}
}
}
} catch (Throwable e) {
Debug.out(e);
}
} else {
String key = "Subscription_" + ByteFormatter.encodeString(sub.getPublicKey());
MultipleDocumentInterface mdi = UIFunctionsManager.getUIFunctions().getMDI();
if (mdi != null) {
mdi.showEntryByID(key);
}
}
}
}
@Override
public void selected(TableRowCore[] rows) {
rows = view.getSelectedRows();
ISelectedContent[] sels = new ISelectedContent[rows.length];
java.util.List<Subscription> subs = new ArrayList<>();
for (int i = 0; i < rows.length; i++) {
Subscription sub = (Subscription) rows[i].getDataSource();
sels[i] = new SubscriptionSelectedContent(sub);
if (sub != null) {
subs.add(sub);
}
}
SelectedContentManager.changeCurrentlySelectedContent(view.getTableID(), sels, view);
for (TableContextMenuItem mi : menu_items) {
mi.remove();
}
if (subs.size() > 0) {
SubscriptionManagerUI.createMenus(menu_manager, menu_creator, subs.toArray(new Subscription[0]));
}
}
}, false);
view.addKeyListener(new KeyListener() {
@Override
public void keyPressed(KeyEvent event) {
}
@Override
public void keyReleased(KeyEvent event) {
if (event.keyCode == SWT.DEL) {
removeSelected();
}
}
});
view.setRowDefaultHeightEM(1.4f);
view.initialize(viewComposite);
final Composite composite = new Composite(viewComposite, SWT.BORDER);
composite.setBackgroundMode(SWT.INHERIT_DEFAULT);
composite.setBackground(ColorCache.getColor(composite.getDisplay(), "#F1F9F8"));
Font font = composite.getFont();
FontData[] fDatas = font.getFontData();
for (int i = 0; i < fDatas.length; i++) {
fDatas[i].setHeight(150 * fDatas[i].getHeight() / 100);
if (Constants.isWindows) {
fDatas[i].setStyle(SWT.BOLD);
}
}
textFont1 = new Font(composite.getDisplay(), fDatas);
fDatas = font.getFontData();
for (int i = 0; i < fDatas.length; i++) {
fDatas[i].setHeight(120 * fDatas[i].getHeight() / 100);
}
textFont2 = new Font(composite.getDisplay(), fDatas);
Label preText = new Label(composite, SWT.NONE);
preText.setForeground(ColorCache.getColor(composite.getDisplay(), "#6D6F6E"));
preText.setFont(textFont1);
preText.setText(MessageText.getString("subscriptions.view.help.1"));
Label image = new Label(composite, SWT.NONE);
ImageLoader.getInstance().setLabelImage(image, "btn_rss_add");
Link postText = new Link(composite, SWT.NONE);
postText.setForeground(ColorCache.getColor(composite.getDisplay(), "#6D6F6E"));
postText.setFont(textFont2);
postText.setText(MessageText.getString("subscriptions.view.help.2"));
postText.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
if (event.text != null && (event.text.startsWith("http://") || event.text.startsWith("https://"))) {
Utils.launch(event.text);
}
}
});
Label close = new Label(composite, SWT.NONE);
ImageLoader.getInstance().setLabelImage(close, "image.dismissX");
close.setCursor(composite.getDisplay().getSystemCursor(SWT.CURSOR_HAND));
close.addListener(SWT.MouseUp, new Listener() {
@Override
public void handleEvent(Event arg0) {
COConfigurationManager.setParameter("subscriptions.view.showhelp", false);
composite.setVisible(false);
FormData data = (FormData) view.getComposite().getLayoutData();
data.bottom = new FormAttachment(100, 0);
viewComposite.layout(true);
}
});
FormLayout layout = new FormLayout();
composite.setLayout(layout);
FormData data;
data = new FormData();
data.left = new FormAttachment(0, 15);
data.top = new FormAttachment(0, 20);
data.bottom = new FormAttachment(postText, -5);
preText.setLayoutData(data);
data = new FormData();
data.left = new FormAttachment(preText, 5);
data.top = new FormAttachment(preText, 0, SWT.CENTER);
image.setLayoutData(data);
data = new FormData();
data.left = new FormAttachment(preText, 0, SWT.LEFT);
// data.top = new FormAttachment(preText,5);
data.bottom = new FormAttachment(100, -20);
postText.setLayoutData(data);
data = new FormData();
data.right = new FormAttachment(100, -10);
data.top = new FormAttachment(0, 10);
close.setLayoutData(data);
data = new FormData();
data.left = new FormAttachment(0, 0);
data.right = new FormAttachment(100, 0);
data.top = new FormAttachment(0, 0);
data.bottom = new FormAttachment(composite, 0);
viewComposite.setLayoutData(data);
data = new FormData();
data.left = new FormAttachment(0, 0);
data.right = new FormAttachment(100, 0);
data.bottom = new FormAttachment(100, 0);
composite.setLayoutData(data);
COConfigurationManager.setBooleanDefault("subscriptions.view.showhelp", true);
if (!COConfigurationManager.getBooleanParameter("subscriptions.view.showhelp")) {
composite.setVisible(false);
data = (FormData) viewComposite.getLayoutData();
data.bottom = new FormAttachment(100, 0);
viewComposite.layout(true);
}
}
Aggregations