use of com.biglybt.ui.swt.shells.MessageBoxShell in project BiglyBT by BiglySoftware.
the class FilesViewMenuUtil method setSkipped.
// Returns true if it was paused here.
private static boolean setSkipped(DownloadManager manager, DiskManagerFileInfo[] infos, boolean skipped, boolean delete_action) {
if (!manager.isPersistent()) {
for (int i = 0; i < infos.length; i++) {
infos[i].setSkipped(skipped);
}
return false;
}
int[] existing_storage_types = manager.getStorageType(infos);
int nbFiles = manager.getDiskManagerFileInfoSet().nbFiles();
boolean[] setLinear = new boolean[nbFiles];
boolean[] setCompact = new boolean[nbFiles];
boolean[] setReorder = new boolean[nbFiles];
boolean[] setReorderCompact = new boolean[nbFiles];
int compactCount = 0;
int linearCount = 0;
int reorderCount = 0;
int reorderCompactCount = 0;
if (infos.length > 1) {
}
// This should hopefully reduce the number of "exists" checks.
File save_location = manager.getAbsoluteSaveLocation();
boolean root_exists = save_location.isDirectory() || (infos.length <= 1 && save_location.exists());
boolean type_has_been_changed = false;
boolean requires_pausing = false;
for (int i = 0; i < infos.length; i++) {
int existing_storage_type = existing_storage_types[i];
int compact_target;
int non_compact_target;
if (existing_storage_type == DiskManagerFileInfo.ST_COMPACT || existing_storage_type == DiskManagerFileInfo.ST_LINEAR) {
compact_target = DiskManagerFileInfo.ST_COMPACT;
non_compact_target = DiskManagerFileInfo.ST_LINEAR;
} else {
compact_target = DiskManagerFileInfo.ST_REORDER_COMPACT;
non_compact_target = DiskManagerFileInfo.ST_REORDER;
}
int new_storage_type;
if (skipped) {
// Check to see if the file exists, but try to avoid doing an
// actual disk check if possible.
File existing_file = infos[i].getFile(true);
// Avoid performing existing_file.exists if we know that it is meant
// to reside in the default save location and that location does not
// exist.
boolean perform_check;
if (root_exists) {
perform_check = true;
} else if (FileUtil.isAncestorOf(save_location, existing_file)) {
perform_check = false;
} else {
perform_check = true;
}
if (perform_check && existing_file.exists()) {
if (delete_action) {
MessageBoxShell mb = new MessageBoxShell(SWT.OK | SWT.CANCEL, MessageText.getString("FilesView.rename.confirm.delete.title"), MessageText.getString("FilesView.rename.confirm.delete.text", new String[] { existing_file.toString() }));
mb.setDefaultButtonUsingStyle(SWT.OK);
mb.setRememberOnlyIfButton(0);
mb.setRemember("FilesView.messagebox.delete.id", false, null);
mb.setLeftImage(SWT.ICON_WARNING);
mb.open(null);
boolean wants_to_delete = mb.waitUntilClosed() == SWT.OK;
if (wants_to_delete) {
new_storage_type = compact_target;
} else {
new_storage_type = non_compact_target;
}
} else {
// compact only currently supports first+last piece and therefore is not
// good for handling partial DND files (as other partial pieces will be discarded....)
new_storage_type = non_compact_target;
}
} else // File does not exist.
{
new_storage_type = compact_target;
}
} else {
new_storage_type = non_compact_target;
}
boolean has_changed = existing_storage_type != new_storage_type;
type_has_been_changed |= has_changed;
if (has_changed) {
requires_pausing |= (new_storage_type == DiskManagerFileInfo.ST_COMPACT || new_storage_type == DiskManagerFileInfo.ST_REORDER_COMPACT);
if (new_storage_type == DiskManagerFileInfo.ST_COMPACT) {
setCompact[infos[i].getIndex()] = true;
compactCount++;
} else if (new_storage_type == DiskManagerFileInfo.ST_LINEAR) {
setLinear[infos[i].getIndex()] = true;
linearCount++;
} else if (new_storage_type == DiskManagerFileInfo.ST_REORDER) {
setReorder[infos[i].getIndex()] = true;
reorderCount++;
} else if (new_storage_type == DiskManagerFileInfo.ST_REORDER_COMPACT) {
setReorderCompact[infos[i].getIndex()] = true;
reorderCompactCount++;
}
}
}
boolean ok = true;
boolean paused = false;
if (type_has_been_changed) {
if (requires_pausing)
paused = manager.pause();
if (linearCount > 0)
ok &= Arrays.equals(setLinear, manager.getDiskManagerFileInfoSet().setStorageTypes(setLinear, DiskManagerFileInfo.ST_LINEAR));
if (compactCount > 0)
ok &= Arrays.equals(setCompact, manager.getDiskManagerFileInfoSet().setStorageTypes(setCompact, DiskManagerFileInfo.ST_COMPACT));
if (reorderCount > 0)
ok &= Arrays.equals(setReorder, manager.getDiskManagerFileInfoSet().setStorageTypes(setReorder, DiskManagerFileInfo.ST_REORDER));
if (reorderCompactCount > 0)
ok &= Arrays.equals(setReorderCompact, manager.getDiskManagerFileInfoSet().setStorageTypes(setReorderCompact, DiskManagerFileInfo.ST_REORDER_COMPACT));
}
if (ok) {
for (int i = 0; i < infos.length; i++) {
infos[i].setSkipped(skipped);
}
}
return paused;
}
use of com.biglybt.ui.swt.shells.MessageBoxShell in project BiglyBT by BiglySoftware.
the class TrackerView method initYourTableView.
@Override
public TableViewSWT<TrackerPeerSource> initYourTableView() {
tv = TableViewFactory.createTableViewSWT(TrackerPeerSource.class, TableManager.TABLE_TORRENT_TRACKERS, getPropertiesPrefix(), basicItems, basicItems[0].getName(), SWT.MULTI | SWT.FULL_SELECTION | SWT.VIRTUAL);
tv.addLifeCycleListener(this);
tv.addMenuFillListener(this);
tv.addTableDataSourceChangedListener(this, true);
tv.addSelectionListener(this, false);
tv.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
if (e.stateMask == 0 && e.keyCode == SWT.DEL) {
Object[] datasources = tv.getSelectedDataSources().toArray();
List<TrackerPeerSource> pss = new ArrayList<>();
String str = "";
for (Object object : datasources) {
TrackerPeerSource ps = (TrackerPeerSource) object;
if (ps.canDelete()) {
pss.add(ps);
str += (str.isEmpty() ? "" : ", ") + ps.getName();
}
}
if (!pss.isEmpty()) {
MessageBoxShell mb = new MessageBoxShell(MessageText.getString("message.confirm.delete.title"), MessageText.getString("message.confirm.delete.text", new String[] { str }), new String[] { MessageText.getString("Button.yes"), MessageText.getString("Button.no") }, 1);
mb.open(new UserPrompterResultListener() {
@Override
public void prompterClosed(int result) {
if (result == 0) {
for (TrackerPeerSource ps : pss) {
ps.delete();
}
}
}
});
}
e.doit = false;
}
}
});
tv.setEnableTabViews(enable_tabs, true, null);
UIFunctionsSWT uiFunctions = UIFunctionsManagerSWT.getUIFunctionsSWT();
if (uiFunctions != null) {
UISWTInstance pluginUI = uiFunctions.getUISWTInstance();
registerPluginViews(pluginUI);
}
return tv;
}
use of com.biglybt.ui.swt.shells.MessageBoxShell in project BiglyBT by BiglySoftware.
the class SBC_DevicesView method deleteFiles.
protected void deleteFiles(final TranscodeFile[] toRemove, final int startIndex) {
if (toRemove[startIndex] == null) {
int nextIndex = startIndex + 1;
if (nextIndex < toRemove.length) {
deleteFiles(toRemove, nextIndex);
}
return;
}
final TranscodeFile file = toRemove[startIndex];
try {
File cache_file = file.getCacheFileIfExists();
if (cache_file != null && cache_file.exists() && file.isComplete()) {
String path = cache_file.toString();
String title = MessageText.getString("xcode.deletedata.title");
String copy_text = "";
Device device = file.getDevice();
if (device instanceof DeviceMediaRenderer) {
DeviceMediaRenderer dmr = (DeviceMediaRenderer) device;
File copy_to = dmr.getCopyToFolder();
if (dmr.canCopyToDevice() || (dmr.canCopyToFolder() && copy_to != null && copy_to.exists())) {
copy_text = MessageText.getString("xcode.deletedata.message.2", new String[] { device.getName() });
}
}
String text = MessageText.getString("xcode.deletedata.message", new String[] { file.getName(), file.getProfileName(), copy_text });
MessageBoxShell mb = new MessageBoxShell(title, text);
mb.setRemember("xcode.deletedata.noconfirm.key", false, MessageText.getString("deletedata.noprompt"));
if (startIndex == toRemove.length - 1) {
mb.setButtons(0, new String[] { MessageText.getString("Button.yes"), MessageText.getString("Button.no") }, new Integer[] { 0, 1 });
mb.setRememberOnlyIfButton(0);
} else {
mb.setButtons(1, new String[] { MessageText.getString("Button.removeAll"), MessageText.getString("Button.yes"), MessageText.getString("Button.no") }, new Integer[] { 2, 0, 1 });
mb.setRememberOnlyIfButton(1);
}
DownloadManager dm = null;
if (dm != null) {
mb.setRelatedObject(dm);
}
mb.setLeftImage(SWT.ICON_WARNING);
mb.open(new UserPrompterResultListener() {
@Override
public void prompterClosed(int result) {
if (result == -1) {
return;
} else if (result == 0) {
deleteNoCheck(file);
} else if (result == 2) {
for (int i = startIndex; i < toRemove.length; i++) {
if (toRemove[i] != null) {
deleteNoCheck(toRemove[i]);
}
}
return;
}
int nextIndex = startIndex + 1;
if (nextIndex < toRemove.length) {
deleteFiles(toRemove, nextIndex);
}
}
});
} else {
deleteNoCheck(file);
int nextIndex = startIndex + 1;
if (nextIndex < toRemove.length) {
deleteFiles(toRemove, nextIndex);
}
}
} catch (Throwable e) {
Debug.out(e);
}
}
use of com.biglybt.ui.swt.shells.MessageBoxShell in project BiglyBT by BiglySoftware.
the class TranscodeChooser method createProfileList.
/**
* @param soList
*
* @since 4.1.0.5
*/
private void createProfileList(SWTSkinObjectContainer soList) {
if (selectedTranscodeTarget == null && selectedDeviceTemplate == null) {
new MessageBoxShell(SWT.OK, "No Device", "No Device Selected!?").open(null);
shell.dispose();
return;
}
if (selectedTranscodeTarget != null) {
try {
TranscodeProfile defaultProfile = selectedTranscodeTarget.getDefaultTranscodeProfile();
if (defaultProfile != null) {
if (selectedTranscodeTarget.getTranscodeRequirement() == TranscodeTarget.TRANSCODE_NEVER) {
// take note of never-xcode override
selectedProfile = selectedTranscodeTarget.getBlankProfile();
} else {
selectedProfile = defaultProfile;
}
shell.dispose();
return;
}
} catch (TranscodeException e) {
}
}
if (transcodeProfiles.length == 0 || (selectedTranscodeTarget != null && selectedTranscodeTarget.getTranscodeRequirement() == TranscodeTarget.TRANSCODE_NEVER)) {
if (selectedTranscodeTarget != null) {
selectedProfile = selectedTranscodeTarget.getBlankProfile();
shell.dispose();
return;
}
new MessageBoxShell(SWT.OK, "No Profiles", "No Profiles for device!").open(null);
shell.dispose();
return;
}
if (transcodeProfiles.length == 1) {
selectedProfile = transcodeProfiles[0];
shell.dispose();
return;
}
Arrays.sort(transcodeProfiles, new Comparator<TranscodeProfile>() {
@Override
public int compare(TranscodeProfile o1, TranscodeProfile o2) {
int i1 = o1.getIconIndex();
int i2 = o2.getIconIndex();
if (i1 == i2) {
return o1.getName().compareToIgnoreCase(o2.getName());
} else {
return (i1 - i2);
}
}
});
Composite parent = soList.getComposite();
if (parent.getChildren().length > 0) {
Utils.disposeComposite(parent, false);
}
soInfoTitle = (SWTSkinObjectText) skin.getSkinObject("info-title");
soInfoText = (SWTSkinObjectText) skin.getSkinObject("info-text");
resetProfileInfoBox(false);
RowLayout layout = new RowLayout(SWT.HORIZONTAL);
layout.spacing = 0;
layout.marginLeft = layout.marginRight = 0;
layout.wrap = true;
layout.justify = true;
layout.fill = true;
parent.setLayout(layout);
Listener listenerMouseInout = new Listener() {
@Override
public void handleEvent(Event event) {
Widget widget = (event.widget instanceof Canvas) ? ((Canvas) event.widget).getParent() : event.widget;
Composite c = TranscodeChooser.this.soList.getComposite();
Rectangle bounds = c.getClientArea();
c.redraw(bounds.x, bounds.y, bounds.width, bounds.height, true);
TranscodeProfile profile = (TranscodeProfile) widget.getData("obj");
if (profile == null) {
return;
}
if (event.type == SWT.MouseEnter) {
String description = profile.getDescription();
if (selectedTranscodeTarget != null) {
if (profile == selectedTranscodeTarget.getBlankProfile()) {
description = null;
}
}
if (description == null || description.length() == 0) {
resetProfileInfoBox(true);
} else {
if (soInfoTitle != null) {
soInfoTitle.setTextID("devices.choose.profile.info.title.selected", new String[] { profile.getName() });
}
if (soInfoText != null) {
soInfoText.setText(description);
Point computeSize = shell.computeSize(shell.getClientArea().width, SWT.DEFAULT, true);
if (computeSize.y > shell.getSize().y) {
shell.setSize(computeSize);
}
}
}
}
}
};
parent.addListener(SWT.MouseEnter, new Listener() {
@Override
public void handleEvent(Event event) {
resetProfileInfoBox(true);
}
});
Listener clickListener = new Listener() {
boolean down = false;
@Override
public void handleEvent(Event event) {
if (event.type == SWT.MouseDown) {
down = true;
} else if (event.type == SWT.MouseUp && down) {
Widget widget = (event.widget instanceof Label) ? ((Label) event.widget).getParent() : event.widget;
selectedProfile = (TranscodeProfile) widget.getData("obj");
if (selectedTranscodeTarget != null && selectedProfile == selectedTranscodeTarget.getBlankProfile()) {
transcodeRequirement = TranscodeTarget.TRANSCODE_NEVER;
}
if (selectedProfile == null) {
Debug.out("profile is null!");
} else {
if (btnNoPrompt != null) {
if (btnNoPrompt.getSelection()) {
if (transcodeRequirement == TranscodeTarget.TRANSCODE_NEVER) {
selectedTranscodeTarget.setTranscodeRequirement(transcodeRequirement);
} else {
selectedTranscodeTarget.setDefaultTranscodeProfile(selectedProfile);
selectedTranscodeTarget.setTranscodeRequirement(transcodeRequirement);
}
}
}
}
shell.dispose();
down = false;
}
}
};
int total_images = 0;
for (TranscodeProfile profile : transcodeProfiles) {
addImageBox(parent, clickListener, listenerMouseInout, profile, profile.getIconURL(), profile.getName());
total_images++;
}
if (selectedTranscodeTarget != null) {
addImageBox(parent, clickListener, listenerMouseInout, selectedTranscodeTarget.getBlankProfile(), "", "Do not transcode");
total_images++;
}
SWTSkinObjectText soTitle = (SWTSkinObjectText) skin.getSkinObject("title");
if (soTitle != null) {
soTitle.setTextID("devices.choose.profile.title");
}
SWTSkinObjectText soSubTitle = (SWTSkinObjectText) skin.getSkinObject("subtitle");
if (soSubTitle != null) {
soSubTitle.setTextID("label.clickone");
}
if (soBottomContainer != null) {
soBottomContainer.setVisible(true);
}
SWTSkinObjectContainer soButtonBottomArea = (SWTSkinObjectContainer) skin.getSkinObject("button-bottom");
if (soButtonBottomArea != null) {
soButtonBottomArea.setVisible(false);
}
// once we get to 13 icons (e.g. for iTunes now we have ipad4/ipad mini we increase the width)
// to ensure the dialog doesn't get too long
Point computeSize = shell.computeSize(total_images > 12 ? 800 : 600, SWT.DEFAULT, true);
shell.setSize(computeSize);
Utils.centerWindowRelativeTo(shell, mainShell);
}
use of com.biglybt.ui.swt.shells.MessageBoxShell in project BiglyBT by BiglySoftware.
the class DeviceTemplateChooser method noDevices.
/**
* @since 4.1.0.5
*/
private void noDevices() {
new MessageBoxShell(SWT.OK, "No Devices Found", "We couldn't find any devices. Maybe you didn't install the Vuze Transcoder Plugin?").open(null);
skinnedDialog.close();
}
Aggregations