add_button.setFont(skin.getButtonFont());
add_button.setImage(SWTImageRepository.getImage("add.png"));
add_button.setText(_._("mainwindow.sharedtab.button.add"));
add_button.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
add_button.setAlignment(SWT.LEFT);
add_button.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
DirectoryDialog dir_dialog = new DirectoryDialog (getShell(),SWT.MULTI | SWT.OPEN);
String directory = dir_dialog.open();
if (directory == null) return ;
java.util.List<File> shared_dirs = null;
try {
shared_dirs = config_manager.getSharedFolders();
} catch (ConfigurationManagerException e) {
e.printStackTrace();
}
java.util.List<File> newDirs = new LinkedList<File>();
if (shared_dirs == null)
shared_dirs = new CopyOnWriteArrayList<File>();
else
shared_dirs = new CopyOnWriteArrayList<File>(shared_dirs);
java.util.List<File> already_exist_list = org.jmule.core.utils.FileUtils.extractNewFolders(new File[]{new File(directory)},shared_dirs,newDirs);
if (already_exist_list.size()!=0) {
AlreadyExistDirsWindow window = new AlreadyExistDirsWindow(already_exist_list);
window.getCoreComponents();
window.initUIComponents();
}
shared_dirs.addAll(newDirs);
try {
config_manager.setSharedFolders(shared_dirs);
} catch (ConfigurationManagerException e) {
e.printStackTrace();
}
} });
remove_button = new Button(control_block,SWT.NONE);
remove_button.setFont(skin.getButtonFont());
remove_button.setText(_._("mainwindow.sharedtab.button.remove"));
remove_button.setImage(SWTImageRepository.getImage("remove.png"));
remove_button.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
remove_button.setAlignment(SWT.LEFT);
remove_button.setEnabled(false);
remove_button.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
removeSelectedDir();
} });
clear_button = new Button(control_block,SWT.NONE);
clear_button.setFont(skin.getButtonFont());
clear_button.setText(_._("mainwindow.sharedtab.button.clear"));
clear_button.setImage(SWTImageRepository.getImage("remove_all.png"));
clear_button.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
clear_button.setAlignment(SWT.LEFT);
clear_button.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
clearDirList();
} });
Button reload_button = new Button(control_block,SWT.NONE);
reload_button.setFont(skin.getButtonFont());
reload_button.setText(_._("mainwindow.sharedtab.button.reload"));
reload_button.setImage(SWTImageRepository.getImage("refresh.png"));
reload_button.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
sharing_manager.loadCompletedFiles();
}
});
shared_dir_list = new List (dir_list_content, SWT.BORDER | SWT.SINGLE | SWT.V_SCROLL | SWT.H_SCROLL);
shared_dir_list.setLayoutData(new GridData(GridData.FILL_BOTH));
shared_dir_list.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
String selected_dir = shared_dir_list.getSelection()[0];
if (selected_dir.equals(last_selection)) return ;
last_selection = selected_dir;
updateFileList(selected_dir);
int selection_id = shared_dir_list.getSelectionIndex();
if ((selection_id>=no_remove_id_start)&&(selection_id<=no_remove_id_end)) {
remove_button.setEnabled(false);
return;
}
remove_button.setEnabled(true);
}
});
shared_files.setLayout(new FillLayout());
shared_files_group = new Group(shared_files,SWT.NONE);
shared_files_group.setText(_._("mainwindow.sharedtab.group.shared_files"));
shared_files_group.setLayout(new FillLayout());
shared_files_table = new JMTable<SharedFile>(shared_files_group, SWT.NONE){
protected int compareObjects(SharedFile object1, SharedFile object2,
int columnID, boolean order) {
if (columnID == SWTConstants.SHARED_LIST_FILE_NAME_COLUMN_ID) {
return Misc.compareAllObjects(object1, object2, "getSharingName", order);
}
if (columnID == SWTConstants.SHARED_LIST_FILE_SIZE_COLUMN_ID) {
return Misc.compareAllObjects(object1, object2, "length", order);
}
if (columnID == SWTConstants.SHARED_LIST_FILE_TYPE_COLUMN_ID) {
String type1 = FileFormatter.formatMimeType(object1.getMimeType());
String type2 = FileFormatter.formatMimeType(object2.getMimeType());
int result = type1.compareTo(type2);
if (order)
return result;
else
return Misc.reverse(result);
}
if (columnID == SWTConstants.SHARED_LIST_COMPLETED_COLUMN_ID) {
double value1 = 100;
double value2 = 100;
if (object1 instanceof PartialFile)
value1 = ((PartialFile)object1).getPercentCompleted();
if (object2 instanceof PartialFile)
value2 = ((PartialFile)object2).getPercentCompleted();
int result = 0;
if (value1>value2)
result = 1;
if (value2>value1)
result = -1;
if (order)
return result;
else
return Misc.reverse(result);
}
if (columnID == SWTConstants.SHARED_LIST_FILE_ID_COLUMN_ID) {
String hash1 = object1.getFileHash().getAsString();
String hash2 = object2.getFileHash().getAsString();
int result = hash1.compareTo(hash2);
if (order)
return result;
else
return Misc.reverse(result);
}
return 0;
}
protected Menu getPopUpMenu() {
if (getSelectionCount()<1)
return no_items_menu;
SharedFile shared_file = shared_files_table.getSelectedObject();
if (shared_file.isCompleted()) {
rating_menu.setEnabled(true);
rating_menu.setVisible(true);
file_not_rated.setSelection(false);
file_fake.setSelection(false);
file_poor.setSelection(false);
file_fair.setSelection(false);
file_good.setSelection(false);
file_excellent.setSelection(false);
switch (shared_file.getFileQuality()) {
case FAKE : file_fake.setSelection(true); break;
case POOR : file_poor.setSelection(true); break;
case FAIR : file_fair.setSelection(true); break;
case GOOD : file_good.setSelection(true); break;
case EXCELLENT : file_excellent.setSelection(true); break;
default : file_not_rated.setSelection(true); break;
}
} else { rating_menu.setEnabled(false); }
properties_menu_item.setEnabled(true);
copy_ed2k_link_menu_item.setEnabled(true);
remove_from_disk_menu_item.setEnabled(true);
if (getSelectedObject().getHashSet() == null) {
properties_menu_item.setEnabled(false);
copy_ed2k_link_menu_item.setEnabled(false);
remove_from_disk_menu_item.setEnabled(false);
}
if (getSelectionCount()>1)
properties_menu_item.setEnabled(false);
open_selected_menu_item.setEnabled(false);
if (selectedRunnableFiles())
open_selected_menu_item.setEnabled(true);
return select_completed_file_menu;
}
int HASHED = 0x01;
int UNHASHED = 0x02;
int HASHING = 0x03;
public void updateRow(SharedFile object) {
int status = HASHED;
java.util.List<CompletedFile> file_list = sharing_manager.getUnhashedFiles();
if (file_list != null) {
for(CompletedFile unhashed_file : file_list) {
if (unhashed_file.getFile().equals(object.getFile())) {
status = UNHASHED;
break;
}
}
}
SharedFile hashing_file = sharing_manager.getCurrentHashingFile();
if (hashing_file != null)
if (object.getFile().equals(hashing_file.getFile()))
status = HASHING;
Image icon = SWTImageRepository.getIconByExtension(object.getSharingName());
setRowImage(object, SWTConstants.SHARED_LIST_FILE_NAME_COLUMN_ID, icon);
String text = object.getSharingName();
setRowText(object, SWTConstants.SHARED_LIST_FILE_NAME_COLUMN_ID, text);
long file_size = object.getFile().length();
setRowText(object, SWTConstants.SHARED_LIST_FILE_SIZE_COLUMN_ID, FileFormatter.formatFileSize(file_size));
String mime_type = FileFormatter.formatMimeType(object.getMimeType());
setRowText(object,SWTConstants.SHARED_LIST_FILE_TYPE_COLUMN_ID,mime_type);
double percent_completed = 100d;
if (object instanceof PartialFile) {
PartialFile partial_file = (PartialFile)object;
percent_completed = partial_file.getPercentCompleted();
}
if (status == HASHED) {
setRowText(object,SWTConstants.SHARED_LIST_COMPLETED_COLUMN_ID,FileFormatter.formatProgress(percent_completed));
setRowText(object,SWTConstants.SHARED_LIST_FILE_ID_COLUMN_ID, object.getFileHash().getAsString());
} else
if (status == HASHING)
setRowText(object,SWTConstants.SHARED_LIST_FILE_ID_COLUMN_ID, _._("mainwindow.sharedtab.label.hashing"));
else
setRowText(object,SWTConstants.SHARED_LIST_FILE_ID_COLUMN_ID, _._("mainwindow.sharedtab.label.waiting_to_hash"));
}
};
int width;
width = SWTPreferences.getInstance().getColumnWidth(SWTConstants.SHARED_LIST_FILE_NAME_COLUMN_ID);
shared_files_table.addColumn(SWT.LEFT, SWTConstants.SHARED_LIST_FILE_NAME_COLUMN_ID, _._("mainwindow.sharedtab.column.filename"), "", width);
width = SWTPreferences.getInstance().getColumnWidth(SWTConstants.SHARED_LIST_FILE_SIZE_COLUMN_ID);
shared_files_table.addColumn(SWT.RIGHT, SWTConstants.SHARED_LIST_FILE_SIZE_COLUMN_ID, _._("mainwindow.sharedtab.column.filesize"), "", width);
width = SWTPreferences.getInstance().getColumnWidth(SWTConstants.SHARED_LIST_FILE_TYPE_COLUMN_ID);
shared_files_table.addColumn(SWT.LEFT, SWTConstants.SHARED_LIST_FILE_TYPE_COLUMN_ID, _._("mainwindow.sharedtab.column.filetype"), "",width);
width = SWTPreferences.getInstance().getColumnWidth(SWTConstants.SHARED_LIST_FILE_ID_COLUMN_ID);
shared_files_table.addColumn(SWT.LEFT, SWTConstants.SHARED_LIST_FILE_ID_COLUMN_ID, _._("mainwindow.sharedtab.column.fileid"), "", width);
width = SWTPreferences.getInstance().getColumnWidth(SWTConstants.SHARED_LIST_COMPLETED_COLUMN_ID);
shared_files_table.addColumn(SWT.RIGHT, SWTConstants.SHARED_LIST_COMPLETED_COLUMN_ID, _._("mainwindow.sharedtab.column.completed"), "", width);
shared_files_table.updateColumnSettings();
no_items_menu = new Menu(shared_files_table);
MenuItem column_setup_menu_item = new MenuItem(no_items_menu,SWT.PUSH);
column_setup_menu_item.setText(_._("mainwindow.sharedtab.popupmenu.column_setup"));
column_setup_menu_item.setImage(SWTImageRepository.getImage("columns_setup.png"));
column_setup_menu_item.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
shared_files_table.showColumnEditorWindow();
}});
select_completed_file_menu = new Menu(shared_files_table);
open_selected_menu_item = new MenuItem(select_completed_file_menu,SWT.PUSH);
open_selected_menu_item.setText(_._("mainwindow.sharedtab.popupmenu.open"));
open_selected_menu_item.setImage(SWTImageRepository.getImage("open_file.png"));
open_selected_menu_item.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
openSelected();
}});
copy_ed2k_link_menu_item = new MenuItem(select_completed_file_menu,SWT.PUSH);
copy_ed2k_link_menu_item.setText(_._("mainwindow.sharedtab.popupmenu.copy_ed2k_link"));
copy_ed2k_link_menu_item.setImage(SWTImageRepository.getImage("ed2k_link.png"));
copy_ed2k_link_menu_item.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
copyED2KLink();
}});
remove_from_disk_menu_item = new MenuItem(select_completed_file_menu,SWT.PUSH);
remove_from_disk_menu_item.setText(_._("mainwindow.sharedtab.popupmenu.remove_from_disk"));
remove_from_disk_menu_item.setImage(SWTImageRepository.getImage("cancel.png"));
remove_from_disk_menu_item.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
removeFromDisk();
}});
MenuItem selected_column_setup_menu_item = new MenuItem(select_completed_file_menu,SWT.PUSH);
selected_column_setup_menu_item.setText(_._("mainwindow.sharedtab.popupmenu.column_setup"));
selected_column_setup_menu_item.setImage(SWTImageRepository.getImage("columns_setup.png"));
selected_column_setup_menu_item.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
shared_files_table.showColumnEditorWindow();
}});
rating_menu_item = new MenuItem(select_completed_file_menu, SWT.CASCADE);
rating_menu_item.setText(_._("mainwindow.searchtab.popupmenu.rating_submenu"));
rating_menu = new Menu(select_completed_file_menu);
rating_menu_item.setMenu(rating_menu);
file_not_rated = new MenuItem(rating_menu, SWT.RADIO);
file_not_rated.setText(_._("mainwindow.searchtab.popupmenu.rating_submenu.not_rated"));
file_not_rated.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
SWTThread.getDisplay().asyncExec(new JMRunnable() {
public void JMRun() {
file_fake.setSelection(false);
file_poor.setSelection(false);
file_fair.setSelection(false);
file_good.setSelection(false);
file_excellent.setSelection(false);
SharedFile shared_file = shared_files_table.getSelectedObject();
shared_file.setFileQuality(FileQuality.NOTRATED);
}
});
}});
file_fake = new MenuItem(rating_menu, SWT.RADIO);
file_fake.setText(_._("mainwindow.searchtab.popupmenu.rating_submenu.fake"));
file_fake.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
SWTThread.getDisplay().asyncExec(new JMRunnable() {
public void JMRun() {
file_not_rated.setSelection(false);
file_poor.setSelection(false);
file_fair.setSelection(false);
file_good.setSelection(false);
file_excellent.setSelection(false);
SharedFile shared_file = shared_files_table.getSelectedObject();
shared_file.setFileQuality(FileQuality.FAKE);
}});
}});
file_poor = new MenuItem(rating_menu, SWT.RADIO);
file_poor.setText(_._("mainwindow.searchtab.popupmenu.rating_submenu.poor"));
file_poor.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
SWTThread.getDisplay().asyncExec(new JMRunnable() {
public void JMRun() {
file_not_rated.setSelection(false);
file_fake.setSelection(false);
file_fair.setSelection(false);
file_good.setSelection(false);
file_excellent.setSelection(false);
SharedFile shared_file = shared_files_table.getSelectedObject();
shared_file.setFileQuality(FileQuality.POOR);
}});
}});
file_fair = new MenuItem(rating_menu, SWT.RADIO);
file_fair.setText(_._("mainwindow.searchtab.popupmenu.rating_submenu.fair"));
file_fair.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
SWTThread.getDisplay().asyncExec(new JMRunnable() {
public void JMRun() {
file_not_rated.setSelection(false);
file_fake.setSelection(false);
file_poor.setSelection(false);
file_good.setSelection(false);
file_excellent.setSelection(false);
SharedFile shared_file = shared_files_table.getSelectedObject();
shared_file.setFileQuality(FileQuality.FAIR);
}});
}});
file_good = new MenuItem(rating_menu, SWT.RADIO);
file_good.setText(_._("mainwindow.searchtab.popupmenu.rating_submenu.good"));
file_good.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
SWTThread.getDisplay().asyncExec(new JMRunnable() {
public void JMRun() {
file_not_rated.setSelection(false);
file_fake.setSelection(false);
file_poor.setSelection(false);
file_fair.setSelection(false);
file_excellent.setSelection(false);
SharedFile shared_file = shared_files_table.getSelectedObject();
shared_file.setFileQuality(FileQuality.GOOD);
}});
}});
file_excellent = new MenuItem(rating_menu, SWT.RADIO);
file_excellent.setText(_._("mainwindow.searchtab.popupmenu.rating_submenu.excellent"));
file_excellent.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
SWTThread.getDisplay().asyncExec(new JMRunnable() {
public void JMRun() {
file_not_rated.setSelection(false);
file_fake.setSelection(false);
file_poor.setSelection(false);
file_fair.setSelection(false);
file_good.setSelection(false);
SharedFile shared_file = shared_files_table.getSelectedObject();
shared_file.setFileQuality(FileQuality.EXCELLENT);
}});
}});
new MenuItem(select_completed_file_menu,SWT.SEPARATOR);
properties_menu_item = new MenuItem(select_completed_file_menu,SWT.PUSH);
properties_menu_item.setText(_._("mainwindow.sharedtab.popupmenu.properties"));
properties_menu_item.setImage(SWTImageRepository.getImage("info.png"));
properties_menu_item.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
SharedFile shared_file = shared_files_table.getSelectedObject();
SharedFilePropertiesWindow window = new SharedFilePropertiesWindow(shared_file);
window.getCoreComponents();
window.initUIComponents();