use of com.biglybt.core.subs.Subscription in project BiglyBT by BiglySoftware.
the class ColumnSubscriptionTag method refresh.
@Override
public void refresh(TableCell cell) {
Subscription sub = (Subscription) cell.getDataSource();
Tag tag = tag_manager.lookupTagByUID(sub.getTagID());
String tag_str = tag == null ? "" : tag.getTagName(true);
if (!cell.setSortValue(tag_str) && cell.isValid()) {
return;
}
if (!cell.isShown()) {
return;
}
cell.setText(tag_str);
return;
}
use of com.biglybt.core.subs.Subscription 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.subs.Subscription 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.subs.Subscription in project BiglyBT by BiglySoftware.
the class SubscriptionListWindow method complete.
@Override
public void complete(final byte[] hash, final Subscription[] subscriptions) {
if (!(subscriptions.length > 0)) {
failed(hash, null);
} else {
if (display != null && !display.isDisposed()) {
display.asyncExec(new Runnable() {
@Override
public void run() {
if (mainComposite.isDisposed()) {
return;
}
subscriptionItems = new SubscriptionItemModel[subscriptions.length];
for (int i = 0; i < subscriptions.length; i++) {
final SubscriptionItemModel subscriptionItem = new SubscriptionItemModel();
subscriptionItems[i] = subscriptionItem;
subscriptionItem.name = subscriptions[i].getName();
subscriptionItem.popularity = -1;
subscriptionItem.popularityDisplay = MessageText.getString("subscriptions.listwindow.popularity.reading");
subscriptionItem.subscription = subscriptions[i];
try {
subscriptions[i].getPopularity(new SubscriptionPopularityListener() {
@Override
public void gotPopularity(long popularity) {
update(subscriptionItem, popularity, popularity + "");
}
@Override
public void failed(SubscriptionException error) {
update(subscriptionItem, -2, MessageText.getString("subscriptions.listwindow.popularity.unknown"));
}
});
} catch (SubscriptionException e) {
update(subscriptionItem, -2, MessageText.getString("subscriptions.listwindow.popularity.unknown"));
}
}
animatedImage.stop();
mainLayout.topControl = listPanel;
mainComposite.layout();
sortAndRefresh();
subscriptionsList.setSelection(0);
action.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event arg0) {
if (subscriptionsList != null && !subscriptionsList.isDisposed()) {
int selectedIndex = subscriptionsList.getSelectionIndex();
if (selectedIndex >= 0 && selectedIndex < subscriptionItems.length) {
Subscription subscription = (Subscription) subscriptionItems[selectedIndex].subscription;
if (subscription != null) {
subscription.setSubscribed(true);
subscription.requestAttention();
}
}
}
}
});
}
});
}
}
}
use of com.biglybt.core.subs.Subscription in project BiglyBT by BiglySoftware.
the class SubscriptionWizard method createAvailableSubscriptionComposite.
private Composite createAvailableSubscriptionComposite(Composite parent) {
Composite composite = new Composite(parent, SWT.NONE);
Label hsep1 = new Label(composite, SWT.SEPARATOR | SWT.HORIZONTAL);
Label hsep2 = new Label(composite, SWT.SEPARATOR | SWT.HORIZONTAL);
Label vsep = new Label(composite, SWT.SEPARATOR | SWT.VERTICAL);
Label subtitle1 = new Label(composite, SWT.NONE);
Label subtitle2 = new Label(composite, SWT.NONE);
subtitle1.setFont(subTitleFont);
subtitle2.setFont(subTitleFont);
subtitle1.setText(MessageText.getString("Wizard.Subscription.subscribe.library"));
subtitle2.setText(MessageText.getString("Wizard.Subscription.subscribe.subscriptions"));
libraryTable = new Table(composite, SWT.FULL_SELECTION | SWT.VIRTUAL | SWT.V_SCROLL | SWT.SINGLE);
final TableColumn torrentColumn = new TableColumn(libraryTable, SWT.NONE);
torrentColumn.setWidth(Utils.adjustPXForDPI(50));
final Composite compEmpty = new Composite(composite, SWT.NONE);
compEmpty.setBackground(Colors.getSystemColor(display, SWT.COLOR_WHITE));
compEmpty.setBackgroundMode(SWT.INHERIT_DEFAULT);
FillLayout fl = new FillLayout();
fl.marginHeight = 15;
fl.marginWidth = 15;
compEmpty.setLayout(fl);
compEmpty.setVisible(false);
final Link labelEmpty = new Link(compEmpty, SWT.WRAP);
labelEmpty.setText(MessageText.getString("Wizard.Subscription.subscribe.library.empty"));
labelEmpty.setFont(subTitleFont);
labelEmpty.setForeground(ColorCache.getColor(composite.getDisplay(), "#6D6F6E"));
labelEmpty.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);
}
}
});
initColumns();
final Composite cTV = new Composite(composite, SWT.NONE);
cTV.setLayoutData(Utils.getFilledFormData());
GridLayout layout = new GridLayout();
layout.marginHeight = layout.marginWidth = layout.verticalSpacing = layout.horizontalSpacing = 0;
cTV.setLayout(layout);
tvSubscriptions = TableViewFactory.createTableViewSWT(Subscription.class, TABLE_SUB_WIZ, TABLE_SUB_WIZ, new TableColumnCore[0], "SubWizRank", SWT.FULL_SELECTION | SWT.VIRTUAL | SWT.V_SCROLL | SWT.SINGLE);
tvSubscriptions.setMenuEnabled(false);
tvSubscriptions.setHeaderVisible(false);
tvSubscriptions.setRowDefaultHeightEM(1.4f);
tvSubscriptions.initialize(cTV);
tvSubscriptions.getComposite().addListener(SWT.Resize, new Listener() {
@Override
public void handleEvent(Event event) {
com.biglybt.pif.ui.tables.TableColumn tcName = tvSubscriptions.getTableColumn("SubWizName");
com.biglybt.pif.ui.tables.TableColumn tcRank = tvSubscriptions.getTableColumn("SubWizRank");
Rectangle clientArea = ((Composite) event.widget).getClientArea();
tcName.setWidthPX(clientArea.width - tcRank.getWidth() - 1);
}
});
tvSubscriptions.addSelectionListener(new TableSelectionListener() {
@Override
public void selected(TableRowCore[] row) {
Utils.execSWTThread(new AERunnable() {
@Override
public void runSupport() {
if (tvSubscriptions.getSelectedRowsSize() == 0) {
addButton.setEnabled(false);
} else {
addButton.setEnabled(true);
TableRowCore[] rows = tvSubscriptions.getSelectedRows();
Subscription subscription = (Subscription) rows[0].getDataSource();
if (subscription.isSubscribed()) {
addButton.setEnabled(false);
} else {
addButton.setEnabled(true);
}
addButton.setData("subscription", subscription);
}
}
});
}
@Override
public void mouseExit(TableRowCore row) {
}
@Override
public void mouseEnter(TableRowCore row) {
}
@Override
public void focusChanged(TableRowCore focus) {
}
@Override
public void deselected(TableRowCore[] rows) {
Utils.execSWTThread(new AERunnable() {
@Override
public void runSupport() {
if (tvSubscriptions.getSelectedRowsSize() == 0) {
addButton.setEnabled(false);
}
}
});
}
@Override
public void defaultSelected(TableRowCore[] rows, int stateMask) {
}
}, false);
UIUpdaterSWT.getInstance().addUpdater(new UIUpdatable() {
@Override
public void updateUI() {
if (tvSubscriptions != null) {
tvSubscriptions.refreshTable(false);
}
}
@Override
public String getUpdateUIName() {
return "SubWiz";
}
});
Listener resizeListener = new Listener() {
int last_width;
@Override
public void handleEvent(Event event) {
Table table = (Table) event.widget;
Rectangle rect = table.getClientArea();
int width = rect.width - 3;
if (width == last_width) {
return;
}
last_width = width;
int nbColumns = table.getColumnCount();
if (nbColumns == 1) {
table.getColumns()[0].setWidth(width);
}
((Table) event.widget).update();
}
};
// subscriptionTable.addListener(SWT.Resize , resizeListener);
libraryTable.addListener(SWT.Resize, resizeListener);
final Listener selectionListener = new Listener() {
@Override
public void handleEvent(Event event) {
TableItem item = (TableItem) event.item;
subscriptions = (Subscription[]) item.getData("subscriptions");
tvSubscriptions.removeDataSources(tvSubscriptions.getDataSources().toArray(new Subscription[0]));
if (subscriptions != null) {
tvSubscriptions.addDataSources(subscriptions);
}
tvSubscriptions.processDataSourceQueueSync();
addButton.setEnabled(false);
addButton.setData("subscription", null);
tvSubscriptions.setSelectedRows(new TableRowCore[0]);
if (subscriptions != null && subscriptions.length > 0) {
TableRowCore row = tvSubscriptions.getRow(subscriptions[0]);
if (row != null) {
row.setSelected(true);
}
}
}
};
libraryTable.addListener(SWT.Selection, selectionListener);
if (availableSubscriptions != null) {
libraryTable.addListener(SWT.SetData, new Listener() {
@Override
public void handleEvent(Event event) {
TableItem item = (TableItem) event.item;
int index = libraryTable.indexOf(item);
SubscriptionDownloadDetails subInfo = availableSubscriptions[index];
item.setText(subInfo.getDownload().getDisplayName());
item.setData("subscriptions", subInfo.getSubscriptions());
boolean isSubscribed = false;
Subscription[] subs = subInfo.getSubscriptions();
for (int i = 0; i < subs.length; i++) {
if (subs[i].isSubscribed())
isSubscribed = true;
}
if (isSubscribed) {
item.setForeground(Colors.getSystemColor(display, SWT.COLOR_GRAY));
}
if (subInfo.getDownload() == download) {
libraryTable.setSelection(item);
selectionListener.handleEvent(event);
}
if (index == 0 && download == null) {
libraryTable.setSelection(item);
selectionListener.handleEvent(event);
}
if (libraryTable.getSelectionIndex() == index) {
// If the item was already selected and we got the SetData afterwards, then let's populate the
// subscriptionsTable
selectionListener.handleEvent(event);
}
}
});
libraryTable.setItemCount(availableSubscriptions.length);
if (availableSubscriptions.length == 0) {
libraryTable.setVisible(false);
compEmpty.setVisible(true);
}
} else {
// Test code
libraryTable.addListener(SWT.SetData, new Listener() {
@Override
public void handleEvent(Event event) {
TableItem item = (TableItem) event.item;
int index = libraryTable.indexOf(item);
item.setText("test " + index);
}
});
libraryTable.setItemCount(20);
}
addButton.setEnabled(false);
addButton.setData("subscription", null);
// final Image rssIcon = imageLoader.getImage("icon_rss");
libraryTable.addListener(SWT.MeasureItem, new Listener() {
@Override
public void handleEvent(Event event) {
event.height = 20;
}
});
FormLayout formLayout = new FormLayout();
composite.setLayout(formLayout);
FormData data;
data = new FormData();
data.top = new FormAttachment(0, 0);
data.left = new FormAttachment(40, 0);
data.bottom = new FormAttachment(100, 0);
vsep.setLayoutData(data);
data = new FormData();
data.top = new FormAttachment(0, 5);
data.right = new FormAttachment(vsep, 0);
data.left = new FormAttachment(0, 5);
subtitle1.setLayoutData(data);
data = new FormData();
data.top = new FormAttachment(0, 5);
data.left = new FormAttachment(vsep, 5);
data.right = new FormAttachment(100, 0);
subtitle2.setLayoutData(data);
data = new FormData();
data.top = new FormAttachment(subtitle1, 5);
data.right = new FormAttachment(vsep, 0);
data.left = new FormAttachment(0, 0);
hsep1.setLayoutData(data);
data = new FormData();
data.top = new FormAttachment(subtitle2, 5);
data.left = new FormAttachment(vsep, -1);
data.right = new FormAttachment(100, 0);
hsep2.setLayoutData(data);
data = new FormData();
data.top = new FormAttachment(hsep1, 0);
data.right = new FormAttachment(vsep, 0);
data.left = new FormAttachment(0, 0);
data.bottom = new FormAttachment(100, 0);
if (availableSubscriptions != null && availableSubscriptions.length > 0) {
libraryTable.setLayoutData(data);
} else {
// hack: dispose libraryTable as it's not needed and draws over controls
// (makes a white box covering text). Would be smarter to not
// create the libraryTable at all..
libraryTable.dispose();
cancelButton.setFocus();
shell.setDefaultButton(cancelButton);
compEmpty.setLayoutData(data);
}
data = new FormData();
data.top = new FormAttachment(hsep2, 0);
data.left = new FormAttachment(vsep, 0);
data.right = new FormAttachment(100, 0);
data.bottom = new FormAttachment(100, 0);
cTV.setLayoutData(data);
return composite;
}
Aggregations