use of com.biglybt.core.metasearch.impl.plugin.PluginEngine in project BiglyBT by BiglySoftware.
the class MetaSearchImpl method resolveProvider.
public SearchProvider resolveProvider(PluginEngine for_engine) {
List<EngineImpl> l = engines.getList();
for (EngineImpl e : l) {
if (e instanceof PluginEngine) {
PluginEngine pe = (PluginEngine) e;
SearchProvider provider = pe.getProvider();
if (provider != null) {
if (pe.getName().equals(for_engine.getName())) {
return (provider);
}
}
}
}
return (null);
}
use of com.biglybt.core.metasearch.impl.plugin.PluginEngine in project BiglyBT by BiglySoftware.
the class MetaSearchImpl method importFromPlugin.
public EngineImpl importFromPlugin(String _pid, SearchProvider provider) throws IOException {
synchronized (this) {
// unfortunately pid can be internationalised and thus musn't be used as a key to
// a bencoded-map as it can lead of nastyness. Delete any existing entries that have
// got out of control
Iterator<String> it = plugin_map.keySet().iterator();
while (it.hasNext()) {
if (it.next().length() > 1024) {
Debug.out("plugin_map corrupted, resetting");
plugin_map.clear();
break;
}
}
String pid = Base32.encode(_pid.getBytes("UTF-8"));
Long l_id = plugin_map.get(pid);
long id;
if (l_id == null) {
id = manager.getLocalTemplateID();
plugin_map.put(pid, new Long(id));
configDirty();
} else {
id = l_id.longValue();
}
EngineImpl engine = (EngineImpl) getEngine(id);
if (engine == null) {
engine = new PluginEngine(this, id, provider);
engine.setSource(Engine.ENGINE_SOURCE_LOCAL);
engine.setSelectionState(Engine.SEL_STATE_MANUAL_SELECTED);
addEngine(engine);
} else {
if (engine instanceof PluginEngine) {
((PluginEngine) engine).setProvider(provider);
} else {
Debug.out("Inconsistent: plugin must be a PluginEngine!");
plugin_map.remove(pid);
removeEngine(engine);
throw (new IOException("Inconsistent"));
}
}
return (engine);
}
}
use of com.biglybt.core.metasearch.impl.plugin.PluginEngine in project BiglyBT by BiglySoftware.
the class SearchUtils method addMenus.
public static void addMenus(Menu engine_menu, final Engine engine, boolean separator_required) {
if (separator_required) {
new MenuItem(engine_menu, SWT.SEPARATOR);
separator_required = false;
}
if (!(engine instanceof PluginEngine)) {
MenuItem export_json = new MenuItem(engine_menu, SWT.PUSH);
Messages.setLanguageText(export_json, "menu.export.json.to.clipboard");
export_json.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
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) {
MenuItem export_uri = new MenuItem(engine_menu, SWT.PUSH);
Messages.setLanguageText(export_uri, "label.copy.uri.to.clip");
export_uri.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
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);
}
}
});
}
});
}
new MenuItem(engine_menu, SWT.SEPARATOR);
MenuItem remove_item = new MenuItem(engine_menu, SWT.PUSH);
Messages.setLanguageText(remove_item, "Button.remove");
Utils.setMenuItemImage(remove_item, "delete");
remove_item.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
engine.setSelectionState(Engine.SEL_STATE_FORCE_DESELECTED);
}
});
separator_required = true;
}
if (separator_required) {
new MenuItem(engine_menu, SWT.SEPARATOR);
separator_required = false;
}
MenuItem show_props = new MenuItem(engine_menu, SWT.PUSH);
Messages.setLanguageText(show_props, "Subscription.menu.properties");
show_props.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
showProperties(engine);
}
});
}
use of com.biglybt.core.metasearch.impl.plugin.PluginEngine 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();
}
});
}
Aggregations