use of com.biglybt.ui.UIFunctions in project BiglyBT by BiglySoftware.
the class TagUIUtils method checkTagSharing.
public static void checkTagSharing(boolean start_of_day) {
UIFunctions uiFunctions = UIFunctionsManager.getUIFunctions();
if (uiFunctions != null) {
TagManager tm = TagManagerFactory.getTagManager();
if (start_of_day) {
if (COConfigurationManager.getBooleanParameter("tag.sharing.default.checked", false)) {
return;
}
COConfigurationManager.setParameter("tag.sharing.default.checked", true);
List<TagType> tag_types = tm.getTagTypes();
boolean prompt_required = false;
for (TagType tag_type : tag_types) {
List<Tag> tags = tag_type.getTags();
for (Tag tag : tags) {
if (tag.isPublic()) {
prompt_required = true;
}
}
}
if (!prompt_required) {
return;
}
}
String title = MessageText.getString("tag.sharing.enable.title");
String text = MessageText.getString("tag.sharing.enable.text");
UIFunctionsUserPrompter prompter = uiFunctions.getUserPrompter(title, text, new String[] { MessageText.getString("Button.yes"), MessageText.getString("Button.no") }, 0);
prompter.setRemember("tag.share.default", true, MessageText.getString("MessageBoxWindow.nomoreprompting"));
prompter.setAutoCloseInMS(0);
prompter.open(null);
boolean share = prompter.waitUntilClosed() == 0;
tm.setTagPublicDefault(share);
}
}
use of com.biglybt.ui.UIFunctions in project BiglyBT by BiglySoftware.
the class CategoryUIUtils method createMenuItems.
public static void createMenuItems(final Menu menu, final Category category) {
if (category.getType() == Category.TYPE_USER) {
final MenuItem itemDelete = new MenuItem(menu, SWT.PUSH);
Messages.setLanguageText(itemDelete, "MyTorrentsView.menu.category.delete");
itemDelete.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
GlobalManager gm = CoreFactory.getSingleton().getGlobalManager();
List<DownloadManager> managers = category.getDownloadManagers(gm.getDownloadManagers());
// move to array,since setCategory removed it from the category,
// which would mess up our loop
DownloadManager[] dms = managers.toArray(new DownloadManager[managers.size()]);
for (DownloadManager dm : dms) {
DownloadManagerState state = dm.getDownloadState();
if (state != null) {
state.setCategory(null);
}
}
CategoryManager.removeCategory(category);
}
});
}
if (category.getType() != Category.TYPE_ALL) {
long kInB = DisplayFormatters.getKinB();
long maxDownload = COConfigurationManager.getIntParameter("Max Download Speed KBs", 0) * kInB;
long maxUpload = COConfigurationManager.getIntParameter("Max Upload Speed KBs", 0) * kInB;
int down_speed = category.getDownloadSpeed();
int up_speed = category.getUploadSpeed();
ViewUtils.addSpeedMenu(menu.getShell(), menu, true, true, true, true, false, down_speed == 0, down_speed, down_speed, maxDownload, false, up_speed == 0, up_speed, up_speed, maxUpload, 1, null, new SpeedAdapter() {
@Override
public void setDownSpeed(int val) {
category.setDownloadSpeed(val);
}
@Override
public void setUpSpeed(int val) {
category.setUploadSpeed(val);
}
});
}
GlobalManager gm = CoreFactory.getSingleton().getGlobalManager();
List<DownloadManager> managers = category.getDownloadManagers(gm.getDownloadManagers());
final DownloadManager[] dms = managers.toArray(new DownloadManager[managers.size()]);
boolean start = false;
boolean stop = false;
for (DownloadManager dm : dms) {
stop = stop || ManagerUtils.isStopable(dm);
start = start || ManagerUtils.isStartable(dm);
}
// Queue
final MenuItem itemQueue = new MenuItem(menu, SWT.PUSH);
Messages.setLanguageText(itemQueue, "MyTorrentsView.menu.queue");
Utils.setMenuItemImage(itemQueue, "start");
itemQueue.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
GlobalManager gm = CoreFactory.getSingleton().getGlobalManager();
List<?> managers = category.getDownloadManagers(gm.getDownloadManagers());
Object[] dms = managers.toArray();
TorrentUtil.queueDataSources(dms, true);
}
});
itemQueue.setEnabled(start);
// Stop
final MenuItem itemStop = new MenuItem(menu, SWT.PUSH);
Messages.setLanguageText(itemStop, "MyTorrentsView.menu.stop");
Utils.setMenuItemImage(itemStop, "stop");
itemStop.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
GlobalManager gm = CoreFactory.getSingleton().getGlobalManager();
List<?> managers = category.getDownloadManagers(gm.getDownloadManagers());
Object[] dms = managers.toArray();
TorrentUtil.stopDataSources(dms);
}
});
itemStop.setEnabled(stop);
if (category.canBePublic()) {
new MenuItem(menu, SWT.SEPARATOR);
final MenuItem itemPublic = new MenuItem(menu, SWT.CHECK);
itemPublic.setSelection(category.isPublic());
Messages.setLanguageText(itemPublic, "cat.share");
itemPublic.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
category.setPublic(itemPublic.getSelection());
}
});
}
// share with friends
PluginInterface bpi = PluginInitializer.getDefaultInterface().getPluginManager().getPluginInterfaceByClass(BuddyPlugin.class);
int cat_type = category.getType();
if (bpi != null && cat_type != Category.TYPE_UNCATEGORIZED) {
final BuddyPlugin buddy_plugin = (BuddyPlugin) bpi.getPlugin();
if (buddy_plugin.isClassicEnabled()) {
final Menu share_menu = new Menu(menu.getShell(), SWT.DROP_DOWN);
final MenuItem share_item = new MenuItem(menu, SWT.CASCADE);
Messages.setLanguageText(share_item, "azbuddy.ui.menu.cat.share");
share_item.setMenu(share_menu);
List<BuddyPluginBuddy> buddies = buddy_plugin.getBuddies();
if (buddies.size() == 0) {
final MenuItem item = new MenuItem(share_menu, SWT.CHECK);
item.setText(MessageText.getString("general.add.friends"));
item.setEnabled(false);
} else {
final String cname;
if (cat_type == Category.TYPE_ALL) {
cname = "All";
} else {
cname = category.getName();
}
final boolean is_public = buddy_plugin.isPublicTagOrCategory(cname);
final MenuItem itemPubCat = new MenuItem(share_menu, SWT.CHECK);
Messages.setLanguageText(itemPubCat, "general.all.friends");
itemPubCat.setSelection(is_public);
itemPubCat.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
if (is_public) {
buddy_plugin.removePublicTagOrCategory(cname);
} else {
buddy_plugin.addPublicTagOrCategory(cname);
}
}
});
new MenuItem(share_menu, SWT.SEPARATOR);
for (final BuddyPluginBuddy buddy : buddies) {
if (buddy.getNickName() == null) {
continue;
}
final boolean auth = buddy.isLocalRSSTagOrCategoryAuthorised(cname);
final MenuItem itemShare = new MenuItem(share_menu, SWT.CHECK);
itemShare.setText(buddy.getName());
itemShare.setSelection(auth || is_public);
if (is_public) {
itemShare.setEnabled(false);
}
itemShare.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
if (auth) {
buddy.removeLocalAuthorisedRSSTagOrCategory(cname);
} else {
buddy.addLocalAuthorisedRSSTagOrCategory(cname);
}
}
});
}
}
}
}
if (category.getType() != Category.TYPE_ALL) {
TrancodeUIUtils.TranscodeTarget[] tts = TrancodeUIUtils.getTranscodeTargets();
if (tts.length > 0) {
final Menu t_menu = new Menu(menu.getShell(), SWT.DROP_DOWN);
final MenuItem t_item = new MenuItem(menu, SWT.CASCADE);
Messages.setLanguageText(t_item, "cat.autoxcode");
t_item.setMenu(t_menu);
String existing = category.getStringAttribute(Category.AT_AUTO_TRANSCODE_TARGET);
for (TrancodeUIUtils.TranscodeTarget tt : tts) {
TrancodeUIUtils.TranscodeProfile[] profiles = tt.getProfiles();
if (profiles.length > 0) {
final Menu tt_menu = new Menu(t_menu.getShell(), SWT.DROP_DOWN);
final MenuItem tt_item = new MenuItem(t_menu, SWT.CASCADE);
tt_item.setText(tt.getName());
tt_item.setMenu(tt_menu);
for (final TrancodeUIUtils.TranscodeProfile tp : profiles) {
final MenuItem p_item = new MenuItem(tt_menu, SWT.CHECK);
p_item.setText(tp.getName());
boolean selected = existing != null && existing.equals(tp.getUID());
if (selected) {
Utils.setMenuItemImage(tt_item, "blacktick");
}
p_item.setSelection(selected);
p_item.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
category.setStringAttribute(Category.AT_AUTO_TRANSCODE_TARGET, p_item.getSelection() ? tp.getUID() : null);
}
});
}
}
}
}
}
// rss feed
final MenuItem rssOption = new MenuItem(menu, SWT.CHECK);
rssOption.setSelection(category.getBooleanAttribute(Category.AT_RSS_GEN));
Messages.setLanguageText(rssOption, "cat.rss.gen");
rssOption.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
boolean set = rssOption.getSelection();
category.setBooleanAttribute(Category.AT_RSS_GEN, set);
}
});
if (cat_type != Category.TYPE_UNCATEGORIZED && cat_type != Category.TYPE_ALL) {
final MenuItem upPriority = new MenuItem(menu, SWT.CHECK);
upPriority.setSelection(category.getIntAttribute(Category.AT_UPLOAD_PRIORITY) > 0);
Messages.setLanguageText(upPriority, "cat.upload.priority");
upPriority.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
boolean set = upPriority.getSelection();
category.setIntAttribute(Category.AT_UPLOAD_PRIORITY, set ? 1 : 0);
}
});
}
// options
MenuItem itemOptions = new MenuItem(menu, SWT.PUSH);
Messages.setLanguageText(itemOptions, "cat.options");
itemOptions.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
UIFunctions uiFunctions = UIFunctionsManager.getUIFunctions();
if (uiFunctions != null) {
MultipleDocumentInterface mdi = uiFunctions.getMDI();
if (mdi != null) {
mdi.showEntryByID(MultipleDocumentInterface.SIDEBAR_SECTION_TORRENT_OPTIONS, dms);
}
}
}
});
if (dms.length == 0) {
itemOptions.setEnabled(false);
}
}
use of com.biglybt.ui.UIFunctions in project BiglyBT by BiglySoftware.
the class CoreImpl method checkRestartAction.
protected boolean checkRestartAction() {
if (ra_restarting) {
return (true);
}
int restart_after = COConfigurationManager.getIntParameter("Auto Restart When Idle");
if (restart_after > 0) {
List<DownloadManager> managers = getGlobalManager().getDownloadManagers();
boolean active = false;
for (DownloadManager manager : managers) {
int state = manager.getState();
if (state == DownloadManager.STATE_DOWNLOADING || state == DownloadManager.STATE_SEEDING) {
active = true;
break;
}
}
if (active) {
GlobalManagerStats stats = global_manager.getStats();
long totals = stats.getTotalDataBytesReceived() + stats.getTotalDataBytesSent();
long now = SystemTime.getMonotonousTime();
if (totals == ra_last_total_data) {
if (now - ra_last_data_time >= 60 * 1000 * restart_after) {
ra_restarting = true;
String message = MessageText.getString("core.restart.alert", new String[] { String.valueOf(restart_after) });
UIFunctions ui_functions = UIFunctionsManager.getUIFunctions();
if (ui_functions != null) {
ui_functions.forceNotify(UIFunctions.STATUSICON_NONE, null, message, null, new Object[0], -1);
}
Logger.log(new LogAlert(LogAlert.UNREPEATABLE, LogEvent.LT_INFORMATION, message));
new DelayedEvent("CoreRestart", 10 * 1000, new AERunnable() {
@Override
public void runSupport() {
requestRestart();
}
});
return (true);
}
} else {
ra_last_total_data = totals;
ra_last_data_time = now;
}
} else {
ra_last_total_data = -1;
}
} else {
ra_last_total_data = -1;
}
return (false);
}
use of com.biglybt.ui.UIFunctions in project BiglyBT by BiglySoftware.
the class CoreUpdateChecker method displayUserMessage.
/**
* Log and display a user message if contained within reply.
* @param reply from server
*/
private void displayUserMessage(Map reply) {
try {
Iterator it = reply.keySet().iterator();
while (it.hasNext()) {
String key = (String) it.next();
if (key.startsWith("message_sig") || !key.startsWith("message")) {
continue;
}
byte[] message_bytes = (byte[]) reply.get(key);
if (message_bytes != null && message_bytes.length > 0) {
String message;
try {
message = new String(message_bytes, "UTF-8");
} catch (Throwable e) {
message = new String(message_bytes);
}
String sig_key;
int pos = key.indexOf('_');
if (pos == -1) {
sig_key = "message_sig";
} else {
sig_key = "message_sig" + key.substring(pos);
}
String last_message_key = "CoreUpdateChecker.last" + key;
String last = COConfigurationManager.getStringParameter(last_message_key, "");
if (!message.equals(last)) {
boolean repeatable = false;
byte[] signature = (byte[]) reply.get(sig_key);
if (signature == null) {
Logger.log(new LogEvent(LogIDs.LOGGER, "Signature missing from message"));
return;
}
try {
AEVerifier.verifyData(message, signature);
} catch (Throwable e) {
Logger.log(new LogEvent(LogIDs.LOGGER, "Message signature check failed", e));
return;
}
boolean completed = false;
if (message.startsWith("x:") || message.startsWith("y:")) {
// emergency patch application
repeatable = message.startsWith("y:");
try {
URL jar_url = new URL(message.substring(2));
if (!repeatable) {
Logger.log(new LogEvent(LogIDs.LOGGER, "Patch application requsted: url=" + jar_url));
}
File temp_dir = AETemporaryFileHandler.createTempDir();
File jar_file = new File(temp_dir, "patch.jar");
InputStream is = rdf.create(jar_url).download();
try {
FileUtil.copyFile(is, jar_file);
is = null;
AEVerifier.verifyData(jar_file);
ClassLoader cl = CoreUpdateChecker.class.getClassLoader();
if (cl instanceof URLClassLoader) {
URL[] old = ((URLClassLoader) cl).getURLs();
URL[] new_urls = new URL[old.length + 1];
System.arraycopy(old, 0, new_urls, 1, old.length);
new_urls[0] = jar_file.toURL();
cl = new URLClassLoader(new_urls, cl);
} else {
cl = new URLClassLoader(new URL[] { jar_file.toURL() }, cl);
}
Class cla = cl.loadClass("com.biglybt.update.version.Patch");
cla.newInstance();
completed = true;
} finally {
if (is != null) {
is.close();
}
jar_file.delete();
temp_dir.delete();
}
} catch (Throwable e) {
if (!repeatable) {
Logger.log(new LogEvent(LogIDs.LOGGER, "Patch application failed", e));
}
}
} else if (message.startsWith("u:") && message.length() > 4) {
try {
String type = message.substring(2, 3);
String url = message.substring(4);
UIFunctions uif = UIFunctionsManager.getUIFunctions();
if (uif != null) {
uif.viewURL(url, null, 0.9, 0.9, true, type.equals("1"));
}
} catch (Throwable t) {
Logger.log(new LogEvent(LogIDs.LOGGER, "URL message failed", t));
}
// mark as complete even if errored
completed = true;
} else {
int alert_type = LogAlert.AT_WARNING;
String alert_text = message;
boolean force = false;
if (alert_text.startsWith("f:")) {
force = true;
alert_text = alert_text.substring(2);
}
if (alert_text.startsWith("i:")) {
alert_type = LogAlert.AT_INFORMATION;
alert_text = alert_text.substring(2);
}
plugin_interface.getPluginProperties().setProperty(MESSAGE_PROPERTY, alert_text);
if (force) {
UIFunctions uif = UIFunctionsManager.getUIFunctions();
if (uif != null) {
try {
uif.forceNotify(UIFunctions.STATUSICON_NONE, null, alert_text, null, null, 0);
completed = true;
} catch (Throwable e) {
}
}
}
if (!completed) {
Logger.log(new LogAlert(LogAlert.UNREPEATABLE, alert_type, alert_text, 0));
}
completed = true;
}
if (completed) {
if (!repeatable) {
COConfigurationManager.setParameter(last_message_key, message);
COConfigurationManager.save();
}
}
}
}
}
} catch (Throwable e) {
Debug.printStackTrace(e);
}
}
use of com.biglybt.ui.UIFunctions in project BiglyBT by BiglySoftware.
the class CoreUpdateChecker method handleZIPUpdate.
protected void handleZIPUpdate(UpdateChecker checker, InputStream data) throws Exception {
ZipInputStream zip = null;
Properties update_properties = new Properties();
File temp_dir = AETemporaryFileHandler.createTempDir();
File update_file = null;
try {
zip = new ZipInputStream(data);
ZipEntry entry = null;
while ((entry = zip.getNextEntry()) != null) {
String name = entry.getName().trim();
if (name.equals("azureus.sig") || name.endsWith("/") || name.length() == 0) {
continue;
}
if (name.equals("update.properties")) {
update_properties.load(zip);
} else {
if (update_file != null) {
throw (new Exception("Multiple update files are not supported"));
}
update_file = new File(temp_dir, name);
FileUtil.copyFile(zip, update_file, false);
}
}
} finally {
if (zip != null) {
try {
zip.close();
} catch (Throwable e) {
}
}
}
if (update_properties == null) {
throw (new Exception("Update properties missing"));
}
if (update_file == null) {
throw (new Exception("Update file missing"));
}
String info_url = update_properties.getProperty("info.url");
if (info_url == null) {
throw (new Exception("Update property 'info.url' missing"));
}
// update_properties.setProperty( "launch.args" , "-silent" );
// update_properties.setProperty( "launch.silent" , "true" );
String s_args = update_properties.getProperty("launch.args", "").trim();
final String[] args;
if (s_args.length() > 0) {
args = GeneralUtils.splitQuotedTokens(s_args);
} else {
args = new String[0];
}
UIFunctions uif = UIFunctionsManager.getUIFunctions();
if (uif == null) {
throw (new Exception("Update can't proceed - UI functions unavailable"));
}
checker.getCheckInstance().setProperty(UpdateCheckInstance.PT_CLOSE_OR_RESTART_ALREADY_IN_PROGRESS, true);
final File f_update_file = update_file;
boolean silent = update_properties.getProperty("launch.silent", "false").equals("true");
if (silent) {
if (Constants.isOSX) {
String app_name = SystemProperties.getApplicationName();
if (!(app_name.equals("Vuze") || app_name.equals("Azureus") || app_name.equals("BiglyBT") || app_name.equals(Constants.AZUREUS_NAME))) {
UIManager ui_manager = StaticUtilities.getUIManager(120 * 1000);
String details = MessageText.getString("update.fail.app.changed", new String[] { app_name });
ui_manager.showMessageBox("update.fail.app.changed.title", "!" + details + "!", UIManagerEvent.MT_OK);
return;
}
}
uif.performAction(UIFunctions.ACTION_UPDATE_RESTART_REQUEST, !FileUtil.canReallyWriteToAppDirectory(), new UIFunctions.actionListener() {
@Override
public void actionComplete(Object result) {
if ((Boolean) result) {
launchUpdate(f_update_file, args);
}
}
});
} else {
uif.performAction(UIFunctions.ACTION_FULL_UPDATE, info_url, new UIFunctions.actionListener() {
@Override
public void actionComplete(Object result) {
if ((Boolean) result) {
launchUpdate(f_update_file, args);
}
}
});
}
}
Aggregations