shellForChildren = shell;
shell.setText(MessageText.getString("OpenTorrentWindow.title"));
Utils.setShellIcon(shell);
GridLayout layout = FixupLayout(new GridLayout(), false);
shell.setLayout(layout);
shell.addListener(SWT.Resize, new Listener() {
public void handleEvent(Event e) {
resizeTables(3);
}
});
Clipboard clipboard = new Clipboard(shell.getDisplay());
String sClipText = (String) clipboard.getContents(TextTransfer.getInstance());
if (sClipText != null)
bTorrentInClipboard = addTorrentsFromTextList(sClipText, true) > 0;
// label = new Label(shell, SWT.BORDER | SWT.WRAP);
// Messages.setLanguageText(label, "OpenTorrentWindow.message");
// gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
// label.setLayoutData(gridData);
// Torrents
// ========
Composite cButtons = new Composite(shell, SWT.NONE);
RowLayout rLayout = new RowLayout(SWT.HORIZONTAL);
rLayout.marginBottom = 0;
rLayout.marginLeft = 0;
rLayout.marginRight = 0;
rLayout.marginTop = 0;
cButtons.setLayout(rLayout);
// Buttons for tableTorrents
Button browseTorrent = new Button(cButtons, SWT.PUSH);
Messages.setLanguageText(browseTorrent, "OpenTorrentWindow.addFiles");
browseTorrent.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event event) {
FileDialog fDialog = new FileDialog(shell, SWT.OPEN | SWT.MULTI);
fDialog.setFilterExtensions(new String[] {
"*.torrent",
"*.tor",
Constants.FILE_WILDCARD
});
fDialog.setFilterNames(new String[] {
"*.torrent",
"*.tor",
Constants.FILE_WILDCARD
});
fDialog.setFilterPath(TorrentOpener.getFilterPathTorrent());
fDialog.setText(MessageText.getString("MainWindow.dialog.choose.file"));
String fileName = TorrentOpener.setFilterPathTorrent(fDialog.open());
if (fileName != null) {
addTorrents(fDialog.getFilterPath(), fDialog.getFileNames());
}
}
});
Utils.setGridData(cButtons, GridData.FILL_HORIZONTAL, browseTorrent,
MIN_BUTTON_HEIGHT);
Button browseURL = new Button(cButtons, SWT.PUSH);
Messages.setLanguageText(browseURL, "OpenTorrentWindow.addFiles.URL");
browseURL.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event event) {
browseURL();
}
});
Button browseFolder = new Button(cButtons, SWT.PUSH);
Messages.setLanguageText(browseFolder, "OpenTorrentWindow.addFiles.Folder");
browseFolder.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event event) {
DirectoryDialog fDialog = new DirectoryDialog(shell, SWT.NULL);
fDialog.setFilterPath(TorrentOpener.getFilterPathTorrent());
fDialog.setMessage(MessageText.getString("MainWindow.dialog.choose.folder"));
String path = TorrentOpener.setFilterPathTorrent(fDialog.open());
if (path != null) {
addTorrents(path, null);
}
}
});
if (bTorrentInClipboard) {
Button pasteOpen = new Button(cButtons, SWT.PUSH);
Messages.setLanguageText(pasteOpen,
"OpenTorrentWindow.addFiles.Clipboard");
pasteOpen.setToolTipText(sClipText);
pasteOpen.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event event) {
Clipboard clipboard = new Clipboard(shell.getDisplay());
String sClipText = (String) clipboard.getContents(TextTransfer.getInstance());
if (sClipText != null) {
addTorrentsFromTextList(sClipText.trim(), false);
}
}
});
}
Group gTorrentsArea = new Group(shell, SWT.NONE);
gridData = new GridData(GridData.FILL_HORIZONTAL);
gTorrentsArea.setLayoutData(gridData);
layout = FixupLayout(new GridLayout(), true);
gTorrentsArea.setLayout(layout);
Messages.setLanguageText(gTorrentsArea, "OpenTorrentWindow.torrentLocation");
Composite cTorrentList = new Composite(gTorrentsArea, SWT.NONE);
gridData = new GridData(GridData.FILL_HORIZONTAL);
cTorrentList.setLayoutData(gridData);
createTorrentListArea(cTorrentList);
Composite cTorrentOptions = new Composite(gTorrentsArea, SWT.NONE);
gridData = new GridData(GridData.FILL_HORIZONTAL);
cTorrentOptions.setLayoutData(gridData);
layout = FixupLayout(new GridLayout(), true);
layout.marginHeight = 0;
layout.marginWidth = 0;
cTorrentOptions.setLayout(layout);
label = new Label(cTorrentOptions, SWT.NONE);
gridData = new GridData(GridData.FILL_HORIZONTAL);
label.setLayoutData(gridData);
Messages.setLanguageText(label, "OpenTorrentWindow.torrent.options");
int userMode = COConfigurationManager.getIntParameter("User Mode");
if (userMode > 0) {
Composite cTorrentModes = new Composite(cTorrentOptions, SWT.NONE);
gridData = new GridData(GridData.FILL_HORIZONTAL);
cTorrentModes.setLayoutData(gridData);
layout = new GridLayout();
layout.numColumns = 4;
layout.marginWidth = 0;
layout.marginHeight = 0;
cTorrentModes.setLayout(layout);
label = new Label(cTorrentModes, SWT.NONE);
gridData = new GridData(GridData.VERTICAL_ALIGN_CENTER);
label.setLayoutData(gridData);
Messages.setLanguageText(label, "OpenTorrentWindow.startMode");
cmbStartMode = new Combo(cTorrentModes, SWT.BORDER | SWT.READ_ONLY);
gridData = new GridData(GridData.FILL_HORIZONTAL);
cmbStartMode.setLayoutData(gridData);
updateStartModeCombo();
cmbStartMode.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
setSelectedStartMode(cmbStartMode.getSelectionIndex());
}
});
label = new Label(cTorrentModes, SWT.NONE);
gridData = new GridData(GridData.VERTICAL_ALIGN_CENTER);
label.setLayoutData(gridData);
Messages.setLanguageText(label, "OpenTorrentWindow.addPosition");
cmbQueueLocation = new Combo(cTorrentModes, SWT.BORDER | SWT.READ_ONLY);
gridData = new GridData(GridData.FILL_HORIZONTAL);
cmbQueueLocation.setLayoutData(gridData);
updateQueueLocationCombo();
cmbQueueLocation.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
setSelectedQueueLocation(cmbQueueLocation.getSelectionIndex());
}
});
}
// Save To..
// =========
cSaveTo = new Composite(cTorrentOptions, SWT.NONE);
layout = FixupLayout(new GridLayout(), false);
layout.marginHeight = 0;
layout.marginWidth = 0;
layout.verticalSpacing = 0;
layout.numColumns = 2;
cSaveTo.setLayout(layout);
Label lblDataDir = new Label(cSaveTo, SWT.NONE);
gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
gridData.horizontalSpan = 2;
lblDataDir.setLayoutData(gridData);
Messages.setLanguageText(lblDataDir, "OpenTorrentWindow.dataLocation");
cmbDataDir = new Combo(cSaveTo, SWT.BORDER);
gridData = new GridData(GridData.FILL_HORIZONTAL);
cmbDataDir.setLayoutData(gridData);
cmbDataDir.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent e) {
cmbDataDirChanged();
}
});
cmbDataDir.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event event) {
cmbDataDirChanged();
}
});
updateDataDirCombo();
dirList = COConfigurationManager.getStringListParameter("saveTo_list");
StringIterator iter = dirList.iterator();
while (iter.hasNext()) {
String s = iter.next();
if (!s.equals(sDestDir)) {
cmbDataDir.add(s);
}
}
Button browseData = new Button(cSaveTo, SWT.PUSH);
Messages.setLanguageText(browseData, "ConfigView.button.browse");
browseData.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event event) {
String sSavePath;
String sDefPath = cmbDataDir.getText();
File f = new File(sDefPath);
if (sDefPath.length() > 0) {
while (!f.exists()) {
f = f.getParentFile();
if (f == null) {
f = new File(sDefPath);
break;
}
}
}
DirectoryDialog dDialog = new DirectoryDialog(shell, SWT.SYSTEM_MODAL);
dDialog.setFilterPath(f.getAbsolutePath());
dDialog.setMessage(MessageText.getString("MainWindow.dialog.choose.savepath_forallfiles"));
sSavePath = dDialog.open();
if (sSavePath != null) {
cmbDataDir.setText(sSavePath);
}
}
});
gridData = new GridData(GridData.FILL_HORIZONTAL);
cSaveTo.setLayoutData(gridData);
// File List
// =========
Group gFilesArea = new Group(shell, SWT.NONE);
gridData = new GridData(GridData.FILL_BOTH);
gFilesArea.setLayoutData(gridData);
layout = FixupLayout(new GridLayout(), true);
gFilesArea.setLayout(layout);
Messages.setLanguageText(gFilesArea, "OpenTorrentWindow.fileList");
createTableDataFiles(gFilesArea);
// Ok, cancel
cArea = new Composite(shell, SWT.NULL);
layout = new GridLayout();
layout.marginHeight = 0;
layout.numColumns = 2;
cArea.setLayout(layout);
ok = new Button(cArea, SWT.PUSH);