use of com.biglybt.ui.swt.shells.MessageBoxShell in project BiglyBT by BiglySoftware.
the class DonationWindow method _open.
public static void _open(final boolean showNoLoad, final String sourceRef) {
if (shell != null && !shell.isDisposed()) {
return;
}
final Shell parentShell = Utils.findAnyShell();
shell = ShellFactory.createShell(parentShell, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
shell.setLayout(new FillLayout());
if (parentShell != null) {
parentShell.setCursor(shell.getDisplay().getSystemCursor(SWT.CURSOR_WAIT));
}
shell.addTraverseListener(new TraverseListener() {
@Override
public void keyTraversed(TraverseEvent e) {
if (e.detail == SWT.TRAVERSE_ESCAPE) {
e.widget.dispose();
e.doit = false;
}
}
});
shell.addDisposeListener(new DisposeListener() {
@Override
public void widgetDisposed(DisposeEvent e) {
if (parentShell != null) {
parentShell.setCursor(e.display.getSystemCursor(SWT.CURSOR_ARROW));
}
if (browserFunction != null && !browserFunction.isDisposed()) {
browserFunction.dispose();
}
shell = null;
}
});
BrowserWrapper browser = Utils.createSafeBrowser(shell, SWT.NONE);
if (browser == null) {
shell.dispose();
return;
}
browser.addTitleListener(new TitleListener() {
@Override
public void changed(TitleEvent event) {
if (shell == null || shell.isDisposed()) {
return;
}
shell.setText(event.title);
}
});
browserFunction = browser.addBrowserFunction("sendDonationEvent", new BrowserWrapper.BrowserFunction() {
@Override
public Object function(Object[] arguments) {
if (shell == null || shell.isDisposed()) {
return null;
}
if (arguments == null) {
Debug.out("Invalid sendDonationEvent null ");
return null;
}
if (arguments.length < 1) {
Debug.out("Invalid sendDonationEvent length " + arguments.length + " not 1");
return null;
}
if (!(arguments[0] instanceof String)) {
Debug.out("Invalid sendDonationEvent " + (arguments[0] == null ? "NULL" : arguments.getClass().getSimpleName()) + " not String");
return null;
}
String text = (String) arguments[0];
if (text.contains("page-loaded")) {
pageLoadedOk = true;
COConfigurationManager.setParameter("donations.count", COConfigurationManager.getLongParameter("donations.count", 1) + 1);
Utils.centreWindow(shell);
if (parentShell != null) {
parentShell.setCursor(shell.getDisplay().getSystemCursor(SWT.CURSOR_ARROW));
}
shell.open();
} else if (text.contains("reset-ask-time")) {
int time = reAskEveryHours;
String[] strings = text.split(" ");
if (strings.length > 1) {
try {
time = Integer.parseInt(strings[1]);
} catch (Throwable ignore) {
}
}
resetAskTime(time);
} else if (text.contains("never-ask-again")) {
neverAskAgain();
} else if (text.contains("close")) {
Utils.execSWTThreadLater(0, new AERunnable() {
@Override
public void runSupport() {
if (shell != null && !shell.isDisposed()) {
shell.dispose();
}
}
});
} else if (text.startsWith("open-url")) {
String url = text.substring(9);
Utils.launch(url);
} else if (text.startsWith("set-size")) {
String[] strings = text.split(" ");
if (strings.length > 2) {
try {
int w = Integer.parseInt(strings[1]);
int h = Integer.parseInt(strings[2]);
Rectangle computeTrim = shell.computeTrim(0, 0, w, h);
shell.setSize(computeTrim.width, computeTrim.height);
} catch (Exception ignore) {
}
}
}
return null;
}
});
browser.addLocationListener(new LocationListener() {
@Override
public void changing(LocationEvent event) {
}
@Override
public void changed(LocationEvent event) {
}
});
long upTime = StatsFactory.getStats().getTotalUpTime();
// secs * mins
int upHours = (int) (upTime / (60 * 60));
final String url = Constants.URL_DONATION + "?locale=" + MessageText.getCurrentLocale().toString() + "&azv=" + Constants.AZUREUS_VERSION + "&count=" + COConfigurationManager.getLongParameter("donations.count", 1) + "&uphours=" + upHours + "&sourceref=" + UrlUtils.encode(sourceRef);
if (!browser.isFake()) {
SimpleTimer.addEvent("donation.pageload", SystemTime.getOffsetTime(6000), new TimerEventPerformer() {
@Override
public void perform(TimerEvent event) {
if (!pageLoadedOk) {
Utils.execSWTThread(new AERunnable() {
@Override
public void runSupport() {
Debug.out("Page Didn't Load:" + url);
shell.dispose();
if (showNoLoad) {
new MessageBoxShell(SWT.OK, MessageText.getString("DonationWindow.noload.title"), MessageText.getString("DonationWindow.noload.text", new String[] { url })).open(null);
}
}
});
}
}
});
}
browser.setUrl(url);
if (browser.isFake()) {
browser.setUrl(Constants.URL_DONATION);
browser.setText("Please follow the link to donate via an external browser");
shell.setSize(400, 500);
Utils.centreWindow(shell);
if (parentShell != null) {
parentShell.setCursor(shell.getDisplay().getSystemCursor(SWT.CURSOR_ARROW));
}
shell.open();
}
}
use of com.biglybt.ui.swt.shells.MessageBoxShell in project BiglyBT by BiglySoftware.
the class DonationWindow method checkForDonationPopup.
public static void checkForDonationPopup() {
if (shell != null) {
if (DEBUG) {
new MessageBoxShell(SWT.OK, "Donations Test", "Already Open").open(null);
}
return;
}
long maxDate = COConfigurationManager.getLongParameter("donations.maxDate", 0);
boolean force = maxDate > 0 && SystemTime.getCurrentTime() > maxDate;
// Check if user has already donated first
boolean alreadyDonated = COConfigurationManager.getBooleanParameter("donations.donated", false);
if (alreadyDonated && !force) {
if (DEBUG) {
new MessageBoxShell(SWT.OK, "Donations Test", "Already Donated! I like you.").open(null);
}
return;
}
OverallStats stats = StatsFactory.getStats();
if (stats == null) {
return;
}
long upTime = stats.getTotalUpTime();
// secs * mins
int hours = (int) (upTime / (60 * 60));
// Ask every DONATIONS_ASK_AFTER hours.
int nextAsk = COConfigurationManager.getIntParameter("donations.nextAskHours", 0);
if (nextAsk == 0) {
// First Time
COConfigurationManager.setParameter("donations.nextAskHours", hours + initialAskHours);
COConfigurationManager.save();
if (DEBUG) {
new MessageBoxShell(SWT.OK, "Donations Test", "Newbie. You're active for " + hours + ".").open(null);
}
return;
}
if (hours < nextAsk && !force) {
if (DEBUG) {
new MessageBoxShell(SWT.OK, "Donations Test", "Wait " + (nextAsk - hours) + ".").open(null);
}
return;
}
long minDate = COConfigurationManager.getLongParameter("donations.minDate", 0);
if (minDate > 0 && minDate > SystemTime.getCurrentTime()) {
if (DEBUG) {
new MessageBoxShell(SWT.OK, "Donation Test", "Wait " + ((SystemTime.getCurrentTime() - minDate) / 1000 / 3600 / 24) + " days").open(null);
}
return;
}
COConfigurationManager.setParameter("donations.nextAskHours", hours + reAskEveryHours);
COConfigurationManager.save();
Utils.execSWTThread(new AERunnable() {
@Override
public void runSupport() {
open(false, "check");
}
});
}
use of com.biglybt.ui.swt.shells.MessageBoxShell in project BiglyBT by BiglySoftware.
the class MainWindowImpl method initSkinListeners.
/**
* Associates every view ID that we use to a class, and creates the class
* on first EVENT_SHOW.
*/
private void initSkinListeners() {
uiSkinnableSWTListener = new UISkinnableSWTListener() {
@Override
public void skinBeforeComponents(Composite composite, Object skinnableObject, Object[] relatedObjects) {
MessageBoxShell shell = (MessageBoxShell) skinnableObject;
TOTorrent torrent = null;
DownloadManager dm = (DownloadManager) LogRelationUtils.queryForClass(relatedObjects, DownloadManager.class);
if (dm != null) {
torrent = dm.getTorrent();
} else {
torrent = (TOTorrent) LogRelationUtils.queryForClass(relatedObjects, TOTorrent.class);
}
if (torrent != null && shell.getLeftImage() == null) {
byte[] contentThumbnail = PlatformTorrentUtils.getContentThumbnail(torrent);
if (contentThumbnail != null) {
try {
ByteArrayInputStream bis = new ByteArrayInputStream(contentThumbnail);
final Image img = new Image(Display.getDefault(), bis);
shell.setLeftImage(img);
composite.addDisposeListener(new DisposeListener() {
@Override
public void widgetDisposed(DisposeEvent e) {
if (!img.isDisposed()) {
img.dispose();
}
}
});
} catch (Exception ignored) {
}
}
}
}
@Override
public void skinAfterComponents(Composite composite, Object skinnableObject, Object[] relatedObjects) {
}
};
UISkinnableManagerSWT skinnableManagerSWT = UISkinnableManagerSWT.getInstance();
skinnableManagerSWT.addSkinnableListener(MessageBoxShell.class.toString(), uiSkinnableSWTListener);
}
use of com.biglybt.ui.swt.shells.MessageBoxShell in project BiglyBT by BiglySoftware.
the class DebugMenuHelper method createDebugMenuItem.
/**
* Creates the Debug menu and its children
* NOTE: This is a development only menu and so it's not modularized into separate menu items
* because this menu is always rendered in its entirety
* @param menu
* @param mainWindow
* @return
*/
public static MenuItem createDebugMenuItem(final Menu menuDebug) {
MenuItem item;
final UIFunctionsSWT uiFunctions = UIFunctionsManagerSWT.getUIFunctionsSWT();
if (null == uiFunctions) {
throw new IllegalStateException("UIFunctionsManagerSWT.getUIFunctionsSWT() is returning null");
}
item = new MenuItem(menuDebug, SWT.CASCADE);
item.setText("Run GC");
item.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
System.gc();
}
});
item = new MenuItem(menuDebug, SWT.PUSH);
item.setText("&CoreReq");
item.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
CoreWaiterSWT.waitForCoreRunning(new CoreRunningListener() {
@Override
public void coreRunning(Core core) {
new MessageBoxShell(0, "Done", "Core Now Avail").open(null);
}
});
}
});
/*
item = new MenuItem(menuDebug, SWT.CASCADE);
item.setText("Subscriptions");
Menu menuSubscriptions = new Menu(menuDebug.getParent(), SWT.DROP_DOWN);
item.setMenu(menuSubscriptions);
item = new MenuItem(menuSubscriptions, SWT.NONE);
item.setText("Create RSS Feed");
item.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
final Shell shell = new Shell(uiFunctions.getMainShell());
shell.setLayout(new FormLayout());
Label label = new Label(shell,SWT.NONE);
label.setText("RSS Feed URL :");
final Text urlText = new Text(shell,SWT.BORDER);
urlText.setText(Utils.getLinkFromClipboard(shell.getDisplay(),false));
Label separator = new Label(shell,SWT.SEPARATOR | SWT.HORIZONTAL);
Button cancel = new Button(shell,SWT.PUSH);
cancel.setText("Cancel");
Button ok = new Button(shell,SWT.PUSH);
ok.setText("Ok");
FormData data;
data = new FormData();
data.left = new FormAttachment(0,5);
data.right = new FormAttachment(100,-5);
data.top = new FormAttachment(0,5);
label.setLayoutData(data);
data = new FormData();
data.left = new FormAttachment(0,5);
data.right = new FormAttachment(100,-5);
data.top = new FormAttachment(label);
data.width = 400;
urlText.setLayoutData(data);
data = new FormData();
data.left = new FormAttachment(0,5);
data.right = new FormAttachment(100,-5);
data.top = new FormAttachment(urlText);
separator.setLayoutData(data);
data = new FormData();
data.right = new FormAttachment(ok);
data.width = 100;
data.top = new FormAttachment(separator);
cancel.setLayoutData(data);
data = new FormData();
data.right = new FormAttachment(100,-5);
data.width = 100;
data.top = new FormAttachment(separator);
ok.setLayoutData(data);
cancel.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event arg0) {
shell.dispose();
}
});
ok.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event arg0) {
String url_str = urlText.getText();
shell.dispose();
try{
URL url = new URL( url_str );
SubscriptionManagerFactory.getSingleton().createSingletonRSS( url_str, url, 120, true );
}catch( Throwable e ){
Debug.printStackTrace(e);
}
}
});
shell.pack();
Utils.centerWindowRelativeTo(shell, uiFunctions.getMainShell());
shell.open();
shell.setFocus();
urlText.setFocus();
}
});
*/
item = new MenuItem(menuDebug, SWT.CASCADE);
item.setText("DW");
Menu menuBrowserTB = new Menu(menuDebug.getParent(), SWT.DROP_DOWN);
item.setMenu(menuBrowserTB);
item = new MenuItem(menuBrowserTB, SWT.NONE);
item.setText("popup check");
item.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
boolean oldDebug = DonationWindow.DEBUG;
DonationWindow.DEBUG = true;
DonationWindow.checkForDonationPopup();
DonationWindow.DEBUG = oldDebug;
}
});
item = new MenuItem(menuBrowserTB, SWT.NONE);
item.setText("show");
item.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
boolean oldDebug = DonationWindow.DEBUG;
DonationWindow.DEBUG = true;
DonationWindow.open(true, "debug");
DonationWindow.DEBUG = oldDebug;
}
});
item = new MenuItem(menuDebug, SWT.NONE);
item.setText("Alerts");
item.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
String text = "This is a long message with lots of information and " + "stuff you really should read. Are you still reading? Good, because " + "reading <a href=\"http://moo.com\">stimulates</a> the mind.\n\nYeah Baby.";
LogAlert logAlert = new LogAlert(true, LogAlert.AT_INFORMATION, "Simple");
Logger.log(logAlert);
logAlert = new LogAlert(true, LogAlert.AT_WARNING, text);
logAlert.details = "Details: \n\n" + text;
Logger.log(logAlert);
logAlert = new LogAlert(true, LogAlert.AT_ERROR, "ShortText");
logAlert.details = "Details";
Logger.log(logAlert);
}
});
item = new MenuItem(menuDebug, SWT.NONE);
item.setText("MsgBox");
item.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
VuzeMessageBox box = new VuzeMessageBox("Title", "Text", new String[] { "Ok", "Cancel" }, 0);
box.setListener(new VuzeMessageBoxListener() {
@Override
public void shellReady(Shell shell, SWTSkinObjectContainer soExtra) {
SWTSkin skin = soExtra.getSkin();
skin.createSkinObject("dlg.generic.test", "dlg.generic.test", soExtra);
skin.layout(soExtra);
shell.layout(true, true);
}
});
box.open(null);
}
});
item = new MenuItem(menuDebug, SWT.CASCADE);
item.setText("Size");
Menu menuSize = new Menu(menuDebug.getParent(), SWT.DROP_DOWN);
item.setMenu(menuSize);
int[] sizes = { 640, 430, 800, 550, 1024, 718, 1280, 700, 1440, 850, 1600, 1050, 1920, 1150 };
for (int i = 0; i < sizes.length; i += 2) {
final int x = sizes[i];
final int y = sizes[i + 1];
item = new MenuItem(menuSize, SWT.NONE);
item.setText("" + x + "," + y);
item.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
UIFunctionsManagerSWT.getUIFunctionsSWT().getMainShell().setSize(x, y);
}
});
}
item = new MenuItem(menuDebug, SWT.NONE);
item.setText("Obfuscated Shell Image");
item.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent ev) {
Display display = Display.getCurrent();
java.util.List<Image> shell_images = UIDebugGenerator.getShellImages();
Image biggest_image = null;
long biggest_area = 0;
for (Image image : shell_images) {
Shell shell2 = new Shell(display);
Rectangle bounds = image.getBounds();
long area = bounds.width * bounds.height;
if (area > biggest_area) {
biggest_image = image;
}
Point size = shell2.computeSize(bounds.width, bounds.height);
shell2.setSize(size);
shell2.setBackgroundImage(image);
shell2.open();
}
if (biggest_image != null) {
new Clipboard(display).setContents(new Object[] { biggest_image.getImageData() }, new Transfer[] { ImageTransfer.getInstance() });
}
}
});
return item;
}
use of com.biglybt.ui.swt.shells.MessageBoxShell in project BiglyBT by BiglySoftware.
the class TorrentUtil method removeDownloadsSupport.
private static void removeDownloadsSupport(final DownloadManager[] dms, final AERunnable deleteFailed, final boolean forcePrompt) {
if (dms == null) {
return;
}
// confusing code:
// for loop goes through erasing published and low noise torrents until
// it reaches a normal one. We then prompt the user, and stop the loop.
// When the user finally chooses an option, we act on it. If the user
// chose to act on all, we do immediately all and quit.
// If the user chose an action just for the one torrent, we do that action,
// remove that item from the array (by nulling it), and then call
// removeDownloads again so we can prompt again (or erase more published/low noise torrents)
boolean can_archive = false;
for (int i = 0; i < dms.length; i++) {
DownloadManager dm = dms[i];
if (dm == null) {
continue;
}
if (PluginCoreUtils.wrap(dm).canStubbify()) {
can_archive = true;
}
}
for (int i = 0; i < dms.length; i++) {
DownloadManager dm = dms[i];
if (dm == null) {
continue;
}
boolean deleteTorrent = COConfigurationManager.getBooleanParameter("def.deletetorrent");
int confirm = COConfigurationManager.getIntParameter("tb.confirm.delete.content");
boolean doPrompt = confirm == 0 | forcePrompt;
if (doPrompt) {
String title = MessageText.getString("deletedata.title");
String text = MessageText.getString("v3.deleteContent.message", new String[] { dm.getDisplayName() });
if (can_archive) {
text += "\n\n" + MessageText.getString("v3.deleteContent.or.archive");
}
String[] buttons;
int defaultButtonPos;
buttons = new String[] { MessageText.getString("Button.cancel"), MessageText.getString("Button.deleteContent.fromComputer"), MessageText.getString("Button.deleteContent.fromLibrary") };
/*
int[] buttonVals = new int[] {
SWT.CANCEL,
1,
2
};
*/
defaultButtonPos = 2;
final MessageBoxShell mb = new MessageBoxShell(title, text, buttons, defaultButtonPos);
int numLeft = (dms.length - i);
if (numLeft > 1) {
mb.setRemember("na", false, MessageText.getString("v3.deleteContent.applyToAll", new String[] { "" + numLeft }));
// never store remember state
mb.setRememberOnlyIfButton(-3);
}
mb.setRelatedObject(dm);
mb.setLeftImage("image.trash");
mb.addCheckBox("deletecontent.also.deletetorrent", 2, deleteTorrent);
final int index = i;
TorrentUtils.startTorrentDelete();
final boolean[] endDone = { false };
try {
mb.open(new UserPrompterResultListener() {
@Override
public void prompterClosed(int result) {
try {
ImageLoader.getInstance().releaseImage("image.trash");
removeDownloadsPrompterClosed(dms, index, deleteFailed, result, mb.isRemembered(), mb.getCheckBoxEnabled());
} finally {
synchronized (endDone) {
if (!endDone[0]) {
TorrentUtils.endTorrentDelete();
endDone[0] = true;
}
}
}
}
});
} catch (Throwable e) {
Debug.out(e);
synchronized (endDone) {
if (!endDone[0]) {
TorrentUtils.endTorrentDelete();
endDone[0] = true;
}
}
}
return;
} else {
boolean deleteData = confirm == 1;
removeDownloadsPrompterClosed(dms, i, deleteFailed, deleteData ? 1 : 2, true, deleteTorrent);
}
}
}
Aggregations