use of com.biglybt.ui.UIFunctions in project BiglyBT by BiglySoftware.
the class SBC_SearchResultsView method initTable.
private void initTable(Composite control) {
tv_subs_results = TableViewFactory.createTableViewSWT(SBC_SearchResult.class, TABLE_SR, TABLE_SR, new TableColumnCore[0], ColumnSearchSubResultName.COLUMN_ID, SWT.MULTI | SWT.FULL_SELECTION | SWT.VIRTUAL);
TableColumnManager tableManager = TableColumnManager.getInstance();
tableManager.setDefaultColumnNames(TABLE_SR, new String[] { ColumnSearchSubResultType.COLUMN_ID, ColumnSearchSubResultName.COLUMN_ID, ColumnSearchSubResultActions.COLUMN_ID, ColumnSearchSubResultSize.COLUMN_ID, ColumnSearchSubResultSeedsPeers.COLUMN_ID, ColumnSearchSubResultRatings.COLUMN_ID, ColumnSearchSubResultAge.COLUMN_ID, ColumnSearchSubResultRank.COLUMN_ID, ColumnSearchSubResultCategory.COLUMN_ID, ColumnSearchResultSite.COLUMN_ID });
tableManager.setDefaultSortColumnName(TABLE_SR, ColumnSearchSubResultRank.COLUMN_ID);
if (txtFilter != null) {
tv_subs_results.enableFilterCheck(txtFilter, this);
}
tv_subs_results.setRowDefaultHeight(COConfigurationManager.getIntParameter("Search Subs Row Height"));
SWTSkinObject soSizeSlider = getSkinObject("table-size-slider");
if (soSizeSlider instanceof SWTSkinObjectContainer) {
SWTSkinObjectContainer so = (SWTSkinObjectContainer) soSizeSlider;
if (!tv_subs_results.enableSizeSlider(so.getComposite(), 16, 100)) {
so.setVisible(false);
}
}
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) {
SBC_SearchResult rc = (SBC_SearchResult) rows[0].getDataSource();
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++) {
SBC_SearchResult rc = (SBC_SearchResult) 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);
}
}
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.addMenuFillListener(new TableViewSWTMenuFillListener() {
@Override
public void fillMenu(String sColumnName, Menu menu) {
Object[] _related_content = tv_subs_results.getSelectedDataSources().toArray();
final SBC_SearchResult[] results = new SBC_SearchResult[_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 (SBC_SearchResult 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);
}
}
}
@Override
public void addThisColumnSubMenu(String columnName, Menu menuThisColumn) {
}
});
tv_subs_results.initialize(table_parent);
control.layout(true);
}
use of com.biglybt.ui.UIFunctions in project BiglyBT by BiglySoftware.
the class BasicPluginViewImpl method initialize.
private void initialize(Composite composite) {
GridData gridData;
GridLayout gridLayout;
String sConfigSectionID = model.getConfigSectionID();
this.display = composite.getDisplay();
panel = new Composite(composite, SWT.NULL);
gridLayout = new GridLayout();
gridLayout.numColumns = 2;
panel.setLayout(gridLayout);
gridData = new GridData(GridData.FILL_BOTH);
Utils.setLayoutData(panel, gridData);
/*
* Status : [Status Text]
* Current Task : [Task Text]
* Progress : [||||||||||----------]
* Log :
* [
*
*
* ]
*/
Composite topSection = new Composite(panel, SWT.NONE);
gridLayout = new GridLayout();
gridLayout.numColumns = 2;
gridLayout.marginHeight = 0;
gridLayout.marginWidth = 0;
topSection.setLayout(gridLayout);
gridData = new GridData(GridData.FILL_HORIZONTAL);
if (sConfigSectionID == null) {
gridData.horizontalSpan = 2;
}
Utils.setLayoutData(topSection, gridData);
if (model.getStatus().getVisible()) {
Label statusTitle = new Label(topSection, SWT.NULL);
Messages.setLanguageText(statusTitle, "plugins.basicview.status");
status = new BufferedLabel(topSection, SWT.NULL);
gridData = new GridData(GridData.FILL_HORIZONTAL);
Utils.setLayoutData(status, gridData);
}
if (model.getActivity().getVisible()) {
Label activityTitle = new Label(topSection, SWT.NULL);
Messages.setLanguageText(activityTitle, "plugins.basicview.activity");
task = new BufferedLabel(topSection, SWT.NULL);
gridData = new GridData(GridData.FILL_HORIZONTAL);
Utils.setLayoutData(task, gridData);
}
if (model.getProgress().getVisible()) {
Label progressTitle = new Label(topSection, SWT.NULL);
Messages.setLanguageText(progressTitle, "plugins.basicview.progress");
progress = new ProgressBar(topSection, SWT.NULL);
progress.setMaximum(100);
progress.setMinimum(0);
gridData = new GridData(GridData.FILL_HORIZONTAL);
Utils.setLayoutData(progress, gridData);
}
if (sConfigSectionID != null) {
Composite configSection = new Composite(panel, SWT.NONE);
gridLayout = new GridLayout();
gridLayout.numColumns = 1;
gridLayout.marginHeight = 0;
gridLayout.marginWidth = 2;
configSection.setLayout(gridLayout);
gridData = new GridData(GridData.END | GridData.VERTICAL_ALIGN_END);
Utils.setLayoutData(configSection, gridData);
// Label padding = new Label(configSection,SWT.NULL);
// gridData = new GridData(GridData.FILL_HORIZONTAL);
// Utils.setLayoutData(padding, gridData);
Button btnConfig = new Button(configSection, SWT.PUSH);
Messages.setLanguageText(btnConfig, "plugins.basicview.config");
btnConfig.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
UIFunctions uiFunctions = UIFunctionsManager.getUIFunctions();
if (uiFunctions != null) {
uiFunctions.getMDI().showEntryByID(MultipleDocumentInterface.SIDEBAR_SECTION_CONFIG, model.getConfigSectionID());
}
}
});
Utils.setLayoutData(btnConfig, new GridData());
}
if (model.getLogArea().getVisible()) {
Label logTitle = new Label(topSection, SWT.NULL);
Messages.setLanguageText(logTitle, "plugins.basicview.log");
// gridData = new GridData(GridData.FILL_HORIZONTAL);
// gridData.horizontalSpan = 1;
// Utils.setLayoutData(logTitle, gridData);
Button button = new Button(topSection, SWT.PUSH);
Messages.setLanguageText(button, "plugins.basicview.clear");
button.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
model.getLogArea().setText("");
}
});
log = new StyledText(panel, SWT.READ_ONLY | SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER);
gridData = new GridData(GridData.FILL_BOTH);
gridData.horizontalSpan = 2;
Utils.setLayoutData(log, gridData);
ClipboardCopy.addCopyToClipMenu(log, new ClipboardCopy.copyToClipProvider() {
@Override
public String getText() {
return (log.getText().trim());
}
});
log.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent event) {
int key = event.character;
if (key <= 26 && key > 0) {
key += 'a' - 1;
}
if (key == 'a' && event.stateMask == SWT.MOD1) {
event.doit = false;
log.selectAll();
}
}
});
// String text = model.getLogArea().getText().trim();
// log.setText( text);
// log.setTopIndex(log.getLineCount());
model.getLogArea().addPropertyChangeListener(this);
Composite bottomSection = new Composite(panel, SWT.NONE);
gridLayout = new GridLayout();
gridLayout.numColumns = 3;
gridLayout.marginHeight = 0;
gridLayout.marginWidth = 0;
bottomSection.setLayout(gridLayout);
gridData = new GridData(GridData.FILL_HORIZONTAL);
gridData.horizontalSpan = 2;
Utils.setLayoutData(bottomSection, gridData);
// include
Label label = new Label(bottomSection, SWT.NONE);
Utils.setLayoutData(label, new GridData());
Messages.setLanguageText(label, "LoggerView.includeOnly");
final Text inclText = new Text(bottomSection, SWT.BORDER);
gridData = new GridData();
gridData.widthHint = 200;
Utils.setLayoutData(inclText, gridData);
inclText.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
String newExpression = inclText.getText();
if (newExpression.length() == 0)
inclusionFilter = null;
else {
try {
inclusionFilter = Pattern.compile(newExpression, Pattern.CASE_INSENSITIVE);
inclText.setBackground(null);
} catch (PatternSyntaxException e1) {
inclText.setBackground(Colors.colorErrorBG);
}
}
}
});
label = new Label(bottomSection, SWT.NONE);
// exclude
label = new Label(bottomSection, SWT.NONE);
Utils.setLayoutData(label, new GridData());
Messages.setLanguageText(label, "LoggerView.excludeAll");
final Text exclText = new Text(bottomSection, SWT.BORDER);
gridData = new GridData();
gridData.widthHint = 200;
Utils.setLayoutData(exclText, gridData);
exclText.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
String newExpression = exclText.getText();
if (newExpression.length() == 0)
exclusionFilter = null;
else {
try {
exclusionFilter = Pattern.compile(newExpression, Pattern.CASE_INSENSITIVE);
exclText.setBackground(null);
} catch (PatternSyntaxException e1) {
exclText.setBackground(Colors.colorErrorBG);
}
}
}
});
label = new Label(bottomSection, SWT.NONE);
// pause
Button buttonPause = new Button(bottomSection, SWT.CHECK);
Messages.setLanguageText(buttonPause, "LoggerView.pause");
gridData = new GridData();
Utils.setLayoutData(buttonPause, gridData);
buttonPause.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
if (e.widget == null || !(e.widget instanceof Button))
return;
Button btn = (Button) e.widget;
paused = btn.getSelection();
}
});
}
}
use of com.biglybt.ui.UIFunctions in project BiglyBT by BiglySoftware.
the class CocoaUIEnhancer method initialize.
private void initialize() throws Exception {
// Get the Mac OS X Application menu.
Object sharedApplication = invoke(nsapplicationCls, "sharedApplication");
Object mainMenu = invoke(sharedApplication, "mainMenu");
Object mainMenuItem = invoke(nsmenuCls, mainMenu, "itemAtIndex", new Object[] { wrapPointer(0) });
Object appMenu = invoke(mainMenuItem, "submenu");
// disable services menu
Object servicesMenuItem = invoke(nsmenuCls, appMenu, "itemAtIndex", new Object[] { wrapPointer(kServicesMenuItem) });
invoke(nsmenuitemCls, servicesMenuItem, "setEnabled", new Object[] { false });
Menu systemMenu = Display.getCurrent().getSystemMenu();
if (systemMenu != null) {
MenuItem sysItem = getItem(systemMenu, SWT.ID_ABOUT);
if (sysItem != null) {
sysItem.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
AboutWindow.show();
}
});
}
sysItem = getItem(systemMenu, SWT.ID_PREFERENCES);
if (sysItem != null) {
sysItem.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
UIFunctions uiFunctions = UIFunctionsManager.getUIFunctions();
if (uiFunctions != null) {
uiFunctions.getMDI().showEntryByID(MultipleDocumentInterface.SIDEBAR_SECTION_CONFIG);
}
}
});
}
int quitIndex = systemMenu.indexOf(getItem(systemMenu, SWT.ID_QUIT));
MenuItem restartItem = new MenuItem(systemMenu, SWT.CASCADE, quitIndex);
Messages.setLanguageText(restartItem, "MainWindow.menu.file.restart");
restartItem.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
UIFunctions uiFunctions = UIFunctionsManager.getUIFunctions();
if (uiFunctions != null) {
uiFunctions.dispose(true, false);
}
}
});
// Add other menus
boolean isAZ3 = "az3".equalsIgnoreCase(COConfigurationManager.getStringParameter("ui"));
if (!isAZ3) {
// add Wizard, NAT Test, Speed Test
int prefIndex = systemMenu.indexOf(getItem(systemMenu, SWT.ID_PREFERENCES)) + 1;
MenuItem wizItem = new MenuItem(systemMenu, SWT.CASCADE, prefIndex);
Messages.setLanguageText(wizItem, "MainWindow.menu.file.configure");
wizItem.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
new ConfigureWizard(false, ConfigureWizard.WIZARD_MODE_FULL);
}
});
MenuItem natMenu = new MenuItem(systemMenu, SWT.CASCADE, prefIndex);
Messages.setLanguageText(natMenu, "MainWindow.menu.tools.nattest");
natMenu.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
new NatTestWindow();
}
});
MenuItem netstatMenu = new MenuItem(systemMenu, SWT.CASCADE, prefIndex);
Messages.setLanguageText(netstatMenu, "MainWindow.menu.tools.netstat");
netstatMenu.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
UIFunctionsSWT uiFunctions = UIFunctionsManagerSWT.getUIFunctionsSWT();
if (uiFunctions != null) {
PluginsMenuHelper.IViewInfo[] views = PluginsMenuHelper.getInstance().getPluginViewsInfo();
for (PluginsMenuHelper.IViewInfo view : views) {
String viewID = view.viewID;
if (viewID != null && viewID.equals("aznetstatus")) {
view.openView(uiFunctions);
}
}
}
}
});
MenuItem speedMenu = new MenuItem(systemMenu, SWT.CASCADE, prefIndex);
Messages.setLanguageText(speedMenu, "MainWindow.menu.tools.speedtest");
speedMenu.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
new SpeedTestWizard();
}
});
}
}
// Register names in objective-c.
if (sel_applicationShouldHandleReopen_ == 0) {
sel_applicationShouldHandleReopen_ = registerName(osCls, "applicationShouldHandleReopen:hasVisibleWindows:");
}
// Add the action callbacks for menu items.
invoke(osCls, "class_addMethod", new Object[] { wrapPointer(delegateIdSWTApplication), wrapPointer(sel_applicationShouldHandleReopen_), wrapPointer(callBack4Addr), "@:@c" });
initialized = true;
}
use of com.biglybt.ui.UIFunctions in project BiglyBT by BiglySoftware.
the class TorrentMenuFancy method buildTorrentCustomMenu_Control.
public void buildTorrentCustomMenu_Control(final Composite cParent, final DownloadManager[] dms) {
final int userMode = COConfigurationManager.getIntParameter("User Mode");
boolean start = false;
boolean stop = false;
boolean pause = false;
boolean recheck = false;
boolean barsOpened = true;
boolean bChangeDir = hasSelection;
for (int i = 0; i < dms.length; i++) {
DownloadManager dm = dms[i];
if (barsOpened && !DownloadBar.getManager().isOpen(dm)) {
barsOpened = false;
}
stop = stop || ManagerUtils.isStopable(dm);
start = start || ManagerUtils.isStartable(dm);
pause = pause || ManagerUtils.isPauseable(dm);
recheck = recheck || dm.canForceRecheck();
boolean stopped = ManagerUtils.isStopped(dm);
int state = dm.getState();
bChangeDir &= (state == DownloadManager.STATE_ERROR || state == DownloadManager.STATE_STOPPED || state == DownloadManager.STATE_QUEUED);
/**
* Only perform a test on disk if:
* 1) We are currently set to allow the "Change Data Directory" option, and
* 2) We've only got one item selected - otherwise, we may potentially end up checking massive
* amounts of files across multiple torrents before we generate a menu.
*/
if (bChangeDir && dms.length == 1) {
bChangeDir = dm.isDataAlreadyAllocated();
if (bChangeDir && state == DownloadManager.STATE_ERROR) {
// filesExist is way too slow!
bChangeDir = !dm.filesExist(true);
} else {
DiskManagerFileInfo[] files = dm.getDiskManagerFileInfoSet().getFiles();
bChangeDir = false;
for (DiskManagerFileInfo info : files) {
if (info.isSkipped()) {
continue;
}
bChangeDir = !info.getFile(true).exists();
break;
}
}
}
}
Composite cQuickCommands = new Composite(cParent, SWT.NONE);
// cQuickCommands.setBackground(ColorCache.getRandomColor());
RowLayout rowLayout = new RowLayout(SWT.HORIZONTAL);
rowLayout.justify = true;
rowLayout.marginLeft = 0;
rowLayout.marginRight = 0;
cQuickCommands.setLayout(rowLayout);
GridData gd = new GridData();
gd.grabExcessHorizontalSpace = true;
gd.horizontalAlignment = SWT.FILL;
Utils.setLayoutData(cQuickCommands, gd);
// Queue
createActionButton(dms, cQuickCommands, "MyTorrentsView.menu.queue", "start", start, new ListenerGetOffSWT() {
@Override
void handleEventOffSWT(Event event) {
TorrentUtil.queueDataSources(dms, true);
}
});
// Force Start
if (userMode > 0) {
boolean forceStart = false;
boolean forceStartEnabled = false;
for (int i = 0; i < dms.length; i++) {
DownloadManager dm = dms[i];
forceStartEnabled = forceStartEnabled || ManagerUtils.isForceStartable(dm);
forceStart = forceStart || dm.isForceStart();
}
final boolean newForceStart = !forceStart;
createActionButton(dms, cQuickCommands, "MyTorrentsView.menu.forceStart", "forcestart", forceStartEnabled, forceStart ? SWT.BORDER : SWT.PUSH, new ListenerDMTask(dms) {
@Override
public void run(DownloadManager dm) {
if (ManagerUtils.isForceStartable(dm)) {
dm.setForceStart(newForceStart);
}
}
});
}
// Pause
if (userMode > 0) {
createActionButton(dms, cQuickCommands, "v3.MainWindow.button.pause", "pause", pause, new ListenerGetOffSWT() {
@Override
public void handleEventOffSWT(Event event) {
TorrentUtil.pauseDataSources(dms);
}
});
}
// Stop
createActionButton(dms, cQuickCommands, "MyTorrentsView.menu.stop", "stop", stop, new ListenerGetOffSWT() {
@Override
public void handleEventOffSWT(Event event) {
TorrentUtil.stopDataSources(dms);
}
});
// Force Recheck
createActionButton(dms, cQuickCommands, "MyTorrentsView.menu.recheck", "recheck", recheck, new ListenerDMTask(dms) {
@Override
public void run(DownloadManager dm) {
if (dm.canForceRecheck()) {
dm.forceRecheck();
}
}
});
// Delete
createActionButton(dms, cQuickCommands, "menu.delete.options", "delete", hasSelection, new Listener() {
@Override
public void handleEvent(Event event) {
TorrentUtil.removeDownloads(dms, null, true);
}
});
if (bChangeDir) {
createRow(cParent, "MyTorrentsView.menu.changeDirectory", null, new Listener() {
@Override
public void handleEvent(Event e) {
TorrentUtil.changeDirSelectedTorrents(dms, parentShell);
}
});
}
// Open Details
if (hasSelection) {
createRow(cParent, "MyTorrentsView.menu.showdetails", "details", new ListenerDMTask(dms) {
@Override
public void run(DownloadManager dm) {
UIFunctions uiFunctions = UIFunctionsManager.getUIFunctions();
if (uiFunctions != null) {
uiFunctions.getMDI().showEntryByID(MultipleDocumentInterface.SIDEBAR_SECTION_TORRENT_DETAILS, dm);
}
}
});
}
// Open Bar
if (hasSelection) {
FancyRowInfo row = createRow(cParent, "MyTorrentsView.menu.showdownloadbar", "downloadBar", new ListenerDMTask(dms) {
@Override
public void run(DownloadManager dm) {
if (DownloadBar.getManager().isOpen(dm)) {
DownloadBar.close(dm);
} else {
DownloadBar.open(dm, parentShell);
}
}
});
row.setSelection(barsOpened);
}
if (hasSelection) {
FancyRowInfo rowSpeedDL = createRow(cParent, "MyTorrentsView.menu.downSpeedLimit", "image.torrentspeed.down", false, new Listener() {
@Override
public void handleEvent(Event e) {
Event event = new Event();
event.type = SWT.MouseUp;
event.widget = e.widget;
event.stateMask = e.stateMask;
event.button = e.button;
e.display.post(event);
Core core = CoreFactory.getSingleton();
SelectableSpeedMenu.invokeSlider((Control) event.widget, core, dms, false, shell);
if (e.display.getActiveShell() != shell) {
if (!shell.isDisposed()) {
shell.dispose();
}
return;
}
FancyRowInfo rowInfo = findRowInfo(event.widget);
if (rowInfo != null) {
updateRowSpeed(rowInfo, false);
}
}
});
rowSpeedDL.keepMenu = true;
updateRowSpeed(rowSpeedDL, false);
}
if (hasSelection) {
FancyRowInfo rowSpeedUL = createRow(cParent, "MyTorrentsView.menu.upSpeedLimit", "image.torrentspeed.up", false, new Listener() {
@Override
public void handleEvent(Event e) {
Event event = new Event();
event.type = SWT.MouseUp;
event.widget = e.widget;
event.stateMask = e.stateMask;
event.button = e.button;
e.display.post(event);
Core core = CoreFactory.getSingleton();
SelectableSpeedMenu.invokeSlider((Control) e.widget, core, dms, true, shell);
if (e.display.getActiveShell() != shell) {
if (!shell.isDisposed()) {
shell.dispose();
}
return;
}
FancyRowInfo rowInfo = findRowInfo(event.widget);
if (rowInfo != null) {
updateRowSpeed(rowInfo, true);
}
}
});
rowSpeedUL.keepMenu = true;
updateRowSpeed(rowSpeedUL, true);
}
if (hasSelection && userMode > 0) {
createMenuRow(cParent, "MyTorrentsView.menu.tracker", null, new FancyMenuRowInfoListener() {
@Override
public void buildMenu(Menu menu) {
boolean changeUrl = hasSelection;
boolean manualUpdate = true;
boolean allStopped = true;
boolean canMove = true;
int userMode = COConfigurationManager.getIntParameter("User Mode");
final boolean use_open_containing_folder = COConfigurationManager.getBooleanParameter("MyTorrentsView.menu.show_parent_folder_enabled");
for (DownloadManager dm : dms) {
boolean stopped = ManagerUtils.isStopped(dm);
allStopped &= stopped;
canMove = canMove && dm.canMoveDataFiles();
if (userMode < 2) {
TRTrackerAnnouncer trackerClient = dm.getTrackerClient();
if (trackerClient != null) {
boolean update_state = ((SystemTime.getCurrentTime() / 1000 - trackerClient.getLastUpdateTime() >= TRTrackerAnnouncer.REFRESH_MINIMUM_SECS));
manualUpdate = manualUpdate & update_state;
}
}
}
TorrentUtil.addTrackerTorrentMenu(menu, dms, changeUrl, manualUpdate, allStopped, use_open_containing_folder, canMove);
}
});
}
if (hasSelection) {
Core core = CoreFactory.getSingleton();
SpeedLimitHandler slh = SpeedLimitHandler.getSingleton(core);
if (slh.hasAnyProfiles()) {
createMenuRow(cParent, IMenuConstants.MENU_ID_SPEED_LIMITS, null, new FancyMenuRowInfoListener() {
@Override
public void buildMenu(Menu menu) {
TorrentUtil.addSpeedLimitsMenu(dms, menu);
}
});
}
}
if (userMode > 0 && hasSelection) {
boolean can_pause = false;
for (int i = 0; i < dms.length; i++) {
DownloadManager dm = dms[i];
if (ManagerUtils.isPauseable(dm)) {
can_pause = true;
break;
}
}
if (can_pause) {
createRow(detailArea, "MainWindow.menu.transfers.pausetransfersfor", null, new Listener() {
@Override
public void handleEvent(Event event) {
TorrentUtil.pauseDownloadsFor(dms);
}
});
}
}
if (userMode > 0 && dms.length > 1) {
createRow(cParent, "label.options.and.info", null, new ListenerDMTask(dms) {
@Override
public void run(DownloadManager[] dms) {
UIFunctions uiFunctions = UIFunctionsManager.getUIFunctions();
if (uiFunctions != null) {
uiFunctions.getMDI().showEntryByID(MultipleDocumentInterface.SIDEBAR_SECTION_TORRENT_OPTIONS, dms);
}
}
});
}
if (userMode > 0) {
createMenuRow(cParent, "MyTorrentsView.menu.peersource", null, new FancyMenuRowInfoListener() {
@Override
public void buildMenu(Menu menu) {
TorrentUtil.addPeerSourceSubMenu(dms, menu);
}
});
}
// Sequential download
{
boolean allSeq = true;
boolean AllNonSeq = true;
for (int j = 0; j < dms.length; j++) {
DownloadManager dm = dms[j];
boolean seq = dm.getDownloadState().getFlag(DownloadManagerState.FLAG_SEQUENTIAL_DOWNLOAD);
if (seq) {
AllNonSeq = false;
} else {
allSeq = false;
}
}
boolean bChecked;
if (allSeq) {
bChecked = true;
} else if (AllNonSeq) {
bChecked = false;
} else {
bChecked = false;
}
final boolean newSeq = !bChecked;
FancyRowInfo row = createRow(cParent, "menu.sequential.download", null, new ListenerDMTask(dms) {
@Override
public void run(DownloadManager dm) {
dm.getDownloadState().setFlag(DownloadManagerState.FLAG_SEQUENTIAL_DOWNLOAD, newSeq);
}
});
row.setSelection(bChecked);
}
// IP Filter Enable
if (userMode > 0 && IpFilterManagerFactory.getSingleton().getIPFilter().isEnabled()) {
boolean allEnabled = true;
boolean allDisabled = true;
for (int j = 0; j < dms.length; j++) {
DownloadManager dm = dms[j];
boolean filterDisabled = dm.getDownloadState().getFlag(DownloadManagerState.FLAG_DISABLE_IP_FILTER);
if (filterDisabled) {
allEnabled = false;
} else {
allDisabled = false;
}
}
boolean bChecked;
if (allEnabled) {
bChecked = true;
} else if (allDisabled) {
bChecked = false;
} else {
bChecked = false;
}
final boolean newDisable = bChecked;
FancyRowInfo row = createRow(cParent, "MyTorrentsView.menu.ipf_enable", null, new ListenerDMTask(dms) {
@Override
public void run(DownloadManager dm) {
dm.getDownloadState().setFlag(DownloadManagerState.FLAG_DISABLE_IP_FILTER, newDisable);
}
});
row.setSelection(bChecked);
}
if (userMode > 1) {
createMenuRow(cParent, "MyTorrentsView.menu.networks", null, new FancyMenuRowInfoListener() {
@Override
public void buildMenu(Menu menu) {
TorrentUtil.addNetworksSubMenu(dms, menu);
}
});
}
// Advanced menu with stuff I don't know where to put
if (userMode > 0) {
createMenuRow(cParent, "MyTorrentsView.menu.advancedmenu", null, new FancyMenuRowInfoListener() {
@Override
public void buildMenu(Menu menu) {
boolean allStopped = true;
boolean allScanSelected = true;
boolean allScanNotSelected = true;
boolean fileMove = true;
boolean allResumeIncomplete = true;
boolean hasClearableLinks = false;
boolean hasRevertableFiles = false;
for (DownloadManager dm : dms) {
boolean stopped = ManagerUtils.isStopped(dm);
allStopped &= stopped;
fileMove = fileMove && dm.canMoveDataFiles();
boolean scan = dm.getDownloadState().getFlag(DownloadManagerState.FLAG_SCAN_INCOMPLETE_PIECES);
// include DND files in incomplete stat, since a recheck may
// find those files have been completed
boolean incomplete = !dm.isDownloadComplete(true);
allScanSelected = incomplete && allScanSelected && scan;
allScanNotSelected = incomplete && allScanNotSelected && !scan;
DownloadManagerState dms = dm.getDownloadState();
if (dms.isResumeDataComplete()) {
allResumeIncomplete = false;
}
if (stopped && !hasClearableLinks) {
if (dm.getDiskManagerFileInfoSet().nbFiles() > 1) {
if (dms.getFileLinks().hasLinks()) {
hasClearableLinks = true;
}
}
}
if (dm.getDownloadState().getFileLinks().size() > 0) {
hasRevertableFiles = true;
}
}
boolean fileRescan = allScanSelected || allScanNotSelected;
final MenuItem itemFileRescan = new MenuItem(menu, SWT.CHECK);
Messages.setLanguageText(itemFileRescan, "MyTorrentsView.menu.rescanfile");
itemFileRescan.addListener(SWT.Selection, new ListenerDMTask(dms) {
@Override
public void run(DownloadManager dm) {
dm.getDownloadState().setFlag(DownloadManagerState.FLAG_SCAN_INCOMPLETE_PIECES, itemFileRescan.getSelection());
}
});
itemFileRescan.setSelection(allScanSelected);
itemFileRescan.setEnabled(fileRescan);
// revert
final MenuItem itemRevertFiles = new MenuItem(menu, SWT.PUSH);
Messages.setLanguageText(itemRevertFiles, "MyTorrentsView.menu.revertfiles");
itemRevertFiles.addListener(SWT.Selection, new ListenerDMTask(dms) {
@Override
public void run(DownloadManager[] dms) {
FilesViewMenuUtil.revertFiles(tv, dms);
}
});
itemRevertFiles.setEnabled(hasRevertableFiles);
// clear links
final MenuItem itemClearLinks = new MenuItem(menu, SWT.PUSH);
Messages.setLanguageText(itemClearLinks, "FilesView.menu.clear.links");
itemClearLinks.addListener(SWT.Selection, new ListenerDMTask(dms) {
@Override
public void run(DownloadManager dm) {
if (ManagerUtils.isStopped(dm) && dm.getDownloadState().getFileLinks().hasLinks()) {
DiskManagerFileInfoSet fis = dm.getDiskManagerFileInfoSet();
if (fis.nbFiles() > 1) {
DiskManagerFileInfo[] files = fis.getFiles();
for (DiskManagerFileInfo file_info : files) {
File file_link = file_info.getFile(true);
File file_nolink = file_info.getFile(false);
if (!file_nolink.getAbsolutePath().equals(file_link.getAbsolutePath())) {
file_info.setLink(null);
}
}
}
}
}
});
itemClearLinks.setEnabled(hasClearableLinks);
// clear allocation
MenuItem itemFileClearAlloc = new MenuItem(menu, SWT.PUSH);
Messages.setLanguageText(itemFileClearAlloc, "MyTorrentsView.menu.clear_alloc_data");
itemFileClearAlloc.addListener(SWT.Selection, new ListenerDMTask(dms) {
@Override
public void run(DownloadManager dm) {
dm.setDataAlreadyAllocated(false);
}
});
itemFileClearAlloc.setEnabled(allStopped);
// clear resume
MenuItem itemFileClearResume = new MenuItem(menu, SWT.PUSH);
Messages.setLanguageText(itemFileClearResume, "MyTorrentsView.menu.clear_resume_data");
itemFileClearResume.addListener(SWT.Selection, new ListenerDMTask(dms) {
@Override
public void run(DownloadManager dm) {
dm.getDownloadState().clearResumeData();
}
});
itemFileClearResume.setEnabled(allStopped);
// set resume complete
MenuItem itemFileSetResumeComplete = new MenuItem(menu, SWT.PUSH);
Messages.setLanguageText(itemFileSetResumeComplete, "MyTorrentsView.menu.set.resume.complete");
itemFileSetResumeComplete.addListener(SWT.Selection, new ListenerDMTask(dms) {
@Override
public void run(DownloadManager dm) {
TorrentUtils.setResumeDataCompletelyValid(dm.getDownloadState());
}
});
itemFileSetResumeComplete.setEnabled(allStopped && allResumeIncomplete);
if (userMode > 1 && isSeedingView) {
boolean canSetSuperSeed = false;
boolean superSeedAllYes = true;
boolean superSeedAllNo = true;
for (DownloadManager dm : dms) {
PEPeerManager pm = dm.getPeerManager();
if (pm != null) {
if (pm.canToggleSuperSeedMode()) {
canSetSuperSeed = true;
}
if (pm.isSuperSeedMode()) {
superSeedAllYes = false;
} else {
superSeedAllNo = false;
}
} else {
superSeedAllYes = false;
superSeedAllNo = false;
}
}
final MenuItem itemSuperSeed = new MenuItem(menu, SWT.CHECK);
Messages.setLanguageText(itemSuperSeed, "ManagerItem.superseeding");
boolean enabled = canSetSuperSeed && (superSeedAllNo || superSeedAllYes);
itemSuperSeed.setEnabled(enabled);
final boolean selected = superSeedAllNo;
if (enabled) {
itemSuperSeed.setSelection(selected);
itemSuperSeed.addListener(SWT.Selection, new ListenerDMTask(dms) {
@Override
public void run(DownloadManager dm) {
PEPeerManager pm = dm.getPeerManager();
if (pm != null) {
if (pm.isSuperSeedMode() == selected && pm.canToggleSuperSeedMode()) {
pm.setSuperSeedMode(!selected);
}
}
}
});
}
}
}
});
}
}
use of com.biglybt.ui.UIFunctions in project BiglyBT by BiglySoftware.
the class TorrentUtil method hostTorrents.
public static void hostTorrents(final Object[] download_managers) {
ListenerDMTask task = new ListenerDMTask(toDMS(download_managers), true, true) {
@Override
public void run(DownloadManager dm) {
ManagerUtils.host(CoreFactory.getSingleton(), dm);
}
};
task.go();
UIFunctions uiFunctions = UIFunctionsManager.getUIFunctions();
if (uiFunctions != null) {
uiFunctions.getMDI().showEntryByID(MultipleDocumentInterface.SIDEBAR_SECTION_MY_TRACKER);
}
}
Aggregations