use of com.biglybt.core.devices.DeviceManager.UnassociatedDevice in project BiglyBT by BiglySoftware.
the class DeviceManagerUPnPImpl method getUnassociatedDevices.
public UnassociatedDevice[] getUnassociatedDevices() {
List<UnassociatedDevice> result = new ArrayList<>();
Map<InetAddress, String> ud;
synchronized (unassociated_devices) {
ud = new HashMap<>(unassociated_devices);
}
DeviceImpl[] devices = manager.getDevices();
for (final Map.Entry<InetAddress, String> entry : ud.entrySet()) {
InetAddress address = entry.getKey();
boolean already_assoc = false;
for (DeviceImpl d : devices) {
if (d instanceof DeviceMediaRendererImpl) {
DeviceMediaRendererImpl r = (DeviceMediaRendererImpl) d;
InetAddress device_address = r.getAddress();
if (d.isAlive() && device_address != null && device_address.equals(address)) {
already_assoc = true;
break;
}
}
}
if (!already_assoc) {
result.add(new UnassociatedDevice() {
@Override
public InetAddress getAddress() {
return (entry.getKey());
}
@Override
public String getDescription() {
return (entry.getValue());
}
});
}
}
return (result.toArray(new UnassociatedDevice[result.size()]));
}
use of com.biglybt.core.devices.DeviceManager.UnassociatedDevice in project BiglyBT by BiglySoftware.
the class DeviceManagerUI method setupEntry.
private void setupEntry(deviceItem new_di, final Device device, String parent) {
synchronized (DeviceManagerUI.this) {
if (new_di.isDestroyed()) {
return;
}
deviceView view = new deviceView(parent, device);
new_di.setView(view);
String key = parent + "/" + device.getID() + ":" + nextSidebarID();
final MdiEntry entry;
int device_type = device.getType();
if (device_type == Device.DT_MEDIA_RENDERER) {
entry = mdi.createEntryFromSkinRef(parent, key, "devicerendererview", device.getName(), view, null, false, null);
} else {
entry = mdi.createEntryFromEventListener(parent, view, key, false, device, null);
entry.setExpanded(true);
}
entry.setDatasource(device);
entry.setLogID(parent + "-" + device.getName());
entry.addListener(new MdiCloseListener() {
@Override
public void mdiEntryClosed(MdiEntry entry, boolean userClosed) {
if (device != null) {
device.setTransientProperty(DEVICE_IVIEW_KEY, null);
}
}
});
new_di.setMdiEntry(entry);
setStatus(device, new_di);
if (device instanceof TranscodeTarget) {
entry.addListener(new MdiEntryDropListener() {
@Override
public boolean mdiEntryDrop(MdiEntry entry, Object payload) {
return handleDrop((TranscodeTarget) device, payload);
}
});
}
final MenuManager menu_manager = ui_manager.getMenuManager();
boolean need_sep = false;
if (device instanceof TranscodeTarget) {
need_sep = true;
MenuItem explore_menu_item = menu_manager.addMenuItem("sidebar." + key, "v3.menu.device.exploreTranscodes");
explore_menu_item.setDisposeWithUIDetach(UIInstance.UIT_SWT);
explore_menu_item.addListener(new MenuItemListener() {
@Override
public void selected(MenuItem menu, Object target) {
ManagerUtils.open(((TranscodeTarget) device).getWorkingDirectory());
}
});
}
if (device instanceof DeviceMediaRenderer) {
need_sep = true;
// filter view
final DeviceMediaRenderer renderer = (DeviceMediaRenderer) device;
if (renderer.canFilterFilesView()) {
MenuItem filterfiles_menu_item = menu_manager.addMenuItem("sidebar." + key, "devices.xcode.only.show");
filterfiles_menu_item.setDisposeWithUIDetach(UIInstance.UIT_SWT);
filterfiles_menu_item.setStyle(MenuItem.STYLE_CHECK);
filterfiles_menu_item.addFillListener(new MenuItemFillListener() {
@Override
public void menuWillBeShown(MenuItem menu, Object data) {
menu.setData(Boolean.valueOf(renderer.getFilterFilesView()));
}
});
filterfiles_menu_item.addListener(new MenuItemListener() {
@Override
public void selected(MenuItem menu, Object target) {
renderer.setFilterFilesView((Boolean) menu.getData());
}
});
}
if (renderer.canShowCategories()) {
MenuItem showcat_menu_item = menu_manager.addMenuItem("sidebar." + key, "devices.xcode.show.cat");
showcat_menu_item.setDisposeWithUIDetach(UIInstance.UIT_SWT);
showcat_menu_item.setStyle(MenuItem.STYLE_CHECK);
showcat_menu_item.addFillListener(new MenuItemFillListener() {
@Override
public void menuWillBeShown(MenuItem menu, Object data) {
menu.setData(Boolean.valueOf(renderer.getShowCategories()));
}
});
showcat_menu_item.addListener(new MenuItemListener() {
@Override
public void selected(MenuItem menu, Object target) {
renderer.setShowCategories((Boolean) menu.getData());
}
});
}
if (!DISABLED_TRANSCODING) {
MenuItem alwayscache_menu_item = menu_manager.addMenuItem("sidebar." + key, "devices.always.cache");
alwayscache_menu_item.setDisposeWithUIDetach(UIInstance.UIT_SWT);
alwayscache_menu_item.setStyle(MenuItem.STYLE_CHECK);
alwayscache_menu_item.addFillListener(new MenuItemFillListener() {
@Override
public void menuWillBeShown(MenuItem menu, Object data) {
menu.setData(Boolean.valueOf(renderer.getAlwaysCacheFiles()));
}
});
alwayscache_menu_item.addListener(new MenuItemListener() {
@Override
public void selected(MenuItem menu, Object target) {
renderer.setAlwaysCacheFiles((Boolean) menu.getData());
}
});
}
}
if (need_sep) {
MenuItem menu_item = menu_manager.addMenuItem("sidebar." + key, "1");
menu_item.setStyle(MenuItem.STYLE_SEPARATOR);
menu_item.setDisposeWithUIDetach(UIInstance.UIT_SWT);
}
need_sep = false;
if (device instanceof DeviceMediaRenderer) {
final DeviceMediaRenderer renderer = (DeviceMediaRenderer) device;
if (renderer.canCopyToFolder()) {
need_sep = true;
MenuItem autocopy_menu_item = menu_manager.addMenuItem("sidebar." + key, "devices.xcode.autoCopy");
autocopy_menu_item.setDisposeWithUIDetach(UIInstance.UIT_SWT);
autocopy_menu_item.setStyle(MenuItem.STYLE_CHECK);
autocopy_menu_item.addFillListener(new MenuItemFillListener() {
@Override
public void menuWillBeShown(MenuItem menu, Object data) {
menu.setData(Boolean.valueOf(renderer.getAutoCopyToFolder()));
}
});
autocopy_menu_item.addListener(new MenuItemListener() {
@Override
public void selected(MenuItem menu, Object target) {
renderer.setAutoCopyToFolder((Boolean) menu.getData());
}
});
final MenuItem mancopy_menu_item = menu_manager.addMenuItem("sidebar." + key, "devices.xcode.mancopy");
mancopy_menu_item.setDisposeWithUIDetach(UIInstance.UIT_SWT);
mancopy_menu_item.setStyle(MenuItem.STYLE_PUSH);
mancopy_menu_item.addListener(new MenuItemListener() {
@Override
public void selected(MenuItem menu, Object target) {
try {
renderer.manualCopy();
} catch (Throwable e) {
Debug.out(e);
}
}
});
mancopy_menu_item.addFillListener(new MenuItemFillListener() {
@Override
public void menuWillBeShown(MenuItem menu, Object data) {
boolean enabled = false;
if (!renderer.getAutoCopyToFolder()) {
File target = renderer.getCopyToFolder();
if (target != null && target.exists()) {
enabled = renderer.getCopyToFolderPending() > 0;
}
}
mancopy_menu_item.setEnabled(enabled);
}
});
MenuItem setcopyto_menu_item = menu_manager.addMenuItem("sidebar." + key, "devices.xcode.setcopyto");
setcopyto_menu_item.setDisposeWithUIDetach(UIInstance.UIT_SWT);
setcopyto_menu_item.setStyle(MenuItem.STYLE_PUSH);
setcopyto_menu_item.addListener(new MenuItemListener() {
@Override
public void selected(MenuItem menu, Object target) {
Shell shell = Utils.findAnyShell();
DirectoryDialog dd = new DirectoryDialog(shell);
File existing = renderer.getCopyToFolder();
if (existing != null) {
dd.setFilterPath(existing.getAbsolutePath());
}
dd.setText(MessageText.getString("devices.xcode.setcopyto.title"));
String path = dd.open();
if (path != null) {
renderer.setCopyToFolder(new File(path));
}
}
});
}
if (renderer.canCopyToDevice()) {
need_sep = true;
MenuItem autocopy_menu_item = menu_manager.addMenuItem("sidebar." + key, "devices.xcode.autoCopy.device");
autocopy_menu_item.setDisposeWithUIDetach(UIInstance.UIT_SWT);
autocopy_menu_item.setStyle(MenuItem.STYLE_CHECK);
autocopy_menu_item.addFillListener(new MenuItemFillListener() {
@Override
public void menuWillBeShown(MenuItem menu, Object data) {
menu.setData(Boolean.valueOf(renderer.getAutoCopyToDevice()));
}
});
autocopy_menu_item.addListener(new MenuItemListener() {
@Override
public void selected(MenuItem menu, Object target) {
renderer.setAutoCopyToDevice((Boolean) menu.getData());
}
});
final MenuItem mancopy_menu_item = menu_manager.addMenuItem("sidebar." + key, "devices.xcode.mancopy");
mancopy_menu_item.setDisposeWithUIDetach(UIInstance.UIT_SWT);
mancopy_menu_item.setStyle(MenuItem.STYLE_PUSH);
mancopy_menu_item.addListener(new MenuItemListener() {
@Override
public void selected(MenuItem menu, Object target) {
try {
renderer.manualCopy();
} catch (Throwable e) {
Debug.out(e);
}
}
});
mancopy_menu_item.addFillListener(new MenuItemFillListener() {
@Override
public void menuWillBeShown(MenuItem menu, Object data) {
boolean enabled = false;
if (!renderer.getAutoCopyToDevice()) {
enabled = renderer.getCopyToDevicePending() > 0;
}
mancopy_menu_item.setEnabled(enabled);
}
});
}
if (renderer.canAutoStartDevice()) {
need_sep = true;
MenuItem autostart_menu_item = menu_manager.addMenuItem("sidebar." + key, "devices.xcode.autoStart");
autostart_menu_item.setDisposeWithUIDetach(UIInstance.UIT_SWT);
autostart_menu_item.setStyle(MenuItem.STYLE_CHECK);
autostart_menu_item.addFillListener(new MenuItemFillListener() {
@Override
public void menuWillBeShown(MenuItem menu, Object data) {
menu.setData(Boolean.valueOf(renderer.getAutoStartDevice()));
}
});
autostart_menu_item.addListener(new MenuItemListener() {
@Override
public void selected(MenuItem menu, Object target) {
renderer.setAutoStartDevice((Boolean) menu.getData());
}
});
}
if (renderer.canAssociate()) {
need_sep = true;
final MenuItem menu_associate = menu_manager.addMenuItem("sidebar." + key, "devices.associate");
menu_associate.setDisposeWithUIDetach(UIInstance.UIT_SWT);
menu_associate.setStyle(MenuItem.STYLE_MENU);
menu_associate.addFillListener(new MenuItemFillListener() {
@Override
public void menuWillBeShown(MenuItem menu, Object data) {
menu_associate.removeAllChildItems();
if (renderer.isAlive()) {
InetAddress a = renderer.getAddress();
String address = a == null ? "" : a.getHostAddress();
MenuItem menu_none = menu_manager.addMenuItem(menu_associate, "!" + MessageText.getString("devices.associate.already") + ": " + address + "!");
menu_none.setEnabled(false);
menu_associate.setEnabled(true);
} else {
UnassociatedDevice[] unassoc = device_manager.getUnassociatedDevices();
if (unassoc.length == 0) {
menu_associate.setEnabled(false);
} else {
menu_associate.setEnabled(true);
for (final UnassociatedDevice un : unassoc) {
MenuItem menu_un = menu_manager.addMenuItem(menu_associate, "!" + un.getAddress().getHostAddress() + ": " + un.getDescription() + "!");
menu_un.addListener(new MenuItemListener() {
@Override
public void selected(MenuItem menu, Object target) {
renderer.associate(un);
}
});
}
}
}
}
});
}
if (renderer.canRestrictAccess()) {
need_sep = true;
final MenuItem menu_ra = menu_manager.addMenuItem("sidebar." + key, "devices.restrict_access");
menu_ra.setDisposeWithUIDetach(UIInstance.UIT_SWT);
menu_ra.addListener(new MenuItemListener() {
@Override
public void selected(MenuItem menu, Object target) {
if (target instanceof MdiEntry) {
UISWTInputReceiver entry = (UISWTInputReceiver) swt_ui.getInputReceiver();
entry.setMessage("devices.restrict_access.msg");
entry.setPreenteredText(renderer.getAccessRestriction(), false);
entry.maintainWhitespace(false);
entry.allowEmptyInput(true);
entry.setLocalisedTitle(MessageText.getString("devices.restrict_access.prompt", new String[] { device.getName() }));
entry.prompt(new UIInputReceiverListener() {
@Override
public void UIInputReceiverClosed(UIInputReceiver entry) {
if (!entry.hasSubmittedInput()) {
return;
}
String input = entry.getSubmittedInput().trim();
renderer.setAccessRestriction(input);
}
});
}
}
});
}
final TranscodeProfile[] transcodeProfiles = renderer.getTranscodeProfiles();
if (transcodeProfiles.length > 0) {
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);
}
}
});
need_sep = true;
MenuItem menu_default_profile = menu_manager.addMenuItem("sidebar." + key, "v3.menu.device.defaultprofile");
menu_default_profile.setDisposeWithUIDetach(UIInstance.UIT_SWT);
menu_default_profile.setStyle(MenuItem.STYLE_MENU);
MenuItem menu_profile_never = menu_manager.addMenuItem(menu_default_profile, "v3.menu.device.defaultprofile.never");
menu_profile_never.setStyle(MenuItem.STYLE_CHECK);
menu_profile_never.setData(Boolean.TRUE);
menu_profile_never.addListener(new MenuItemListener() {
@Override
public void selected(MenuItem menu, Object target) {
renderer.setTranscodeRequirement(((Boolean) menu.getData()) ? TranscodeTarget.TRANSCODE_NEVER : TranscodeTarget.TRANSCODE_WHEN_REQUIRED);
}
});
menu_profile_never.addFillListener(new MenuItemFillListener() {
@Override
public void menuWillBeShown(MenuItem menu, Object data) {
boolean never = renderer.getTranscodeRequirement() == TranscodeTarget.TRANSCODE_NEVER;
menu.setData(never);
}
});
MenuItem menu_profile_none = menu_manager.addMenuItem(menu_default_profile, "option.askeverytime");
menu_profile_none.setStyle(MenuItem.STYLE_RADIO);
menu_profile_none.setData(Boolean.FALSE);
menu_profile_none.addListener(new MenuItemListener() {
@Override
public void selected(MenuItem menu, Object target) {
renderer.setDefaultTranscodeProfile(null);
}
});
menu_profile_none.addFillListener(new MenuItemFillListener() {
@Override
public void menuWillBeShown(MenuItem menu, Object data) {
if (transcodeProfiles.length <= 1) {
menu.setData(Boolean.FALSE);
menu.setEnabled(false);
} else {
TranscodeProfile profile = null;
try {
profile = renderer.getDefaultTranscodeProfile();
} catch (TranscodeException e) {
}
menu.setData((profile == null) ? Boolean.TRUE : Boolean.FALSE);
menu.setEnabled(renderer.getTranscodeRequirement() != TranscodeTarget.TRANSCODE_NEVER);
}
}
});
for (final TranscodeProfile profile : transcodeProfiles) {
MenuItem menuItem = menu_manager.addMenuItem(menu_default_profile, "!" + profile.getName() + "!");
menuItem.setStyle(MenuItem.STYLE_RADIO);
menuItem.setData(Boolean.FALSE);
menuItem.addListener(new MenuItemListener() {
@Override
public void selected(MenuItem menu, Object target) {
renderer.setDefaultTranscodeProfile(profile);
}
});
menuItem.addFillListener(new MenuItemFillListener() {
@Override
public void menuWillBeShown(MenuItem menu, Object data) {
if (transcodeProfiles.length <= 1) {
menu.setData(Boolean.TRUE);
menu.setEnabled(false);
} else {
TranscodeProfile dprofile = null;
try {
dprofile = renderer.getDefaultTranscodeProfile();
} catch (TranscodeException e) {
}
menu.setData((profile.equals(dprofile)) ? Boolean.TRUE : Boolean.FALSE);
menu.setEnabled(renderer.getTranscodeRequirement() != TranscodeTarget.TRANSCODE_NEVER);
}
}
});
}
}
if (true) {
need_sep = true;
final MenuItem rss_menu_item = menu_manager.addMenuItem("sidebar." + key, "devices.xcode.rsspub");
rss_menu_item.setDisposeWithUIDetach(UIInstance.UIT_SWT);
rss_menu_item.setStyle(MenuItem.STYLE_CHECK);
rss_menu_item.addFillListener(new MenuItemFillListener() {
@Override
public void menuWillBeShown(MenuItem menu, Object data) {
rss_menu_item.setEnabled(device_manager.isRSSPublishEnabled());
menu.setData(Boolean.valueOf(device_manager.isRSSPublishEnabled() && renderer.isRSSPublishEnabled()));
}
});
rss_menu_item.addListener(new MenuItemListener() {
@Override
public void selected(MenuItem menu, Object target) {
renderer.setRSSPublishEnabled((Boolean) menu.getData());
}
});
rss_menu_item.setEnabled(device_manager.isRSSPublishEnabled());
}
if (true) {
need_sep = true;
final MenuItem aswt_menu_item = menu_manager.addMenuItem("sidebar." + key, "devices.xcode.tagshare");
aswt_menu_item.setDisposeWithUIDetach(UIInstance.UIT_SWT);
aswt_menu_item.setStyle(MenuItem.STYLE_MENU);
aswt_menu_item.addFillListener(new MenuItemFillListener() {
@Override
public void menuWillBeShown(MenuItem menu, Object data) {
addTagSubMenu(menu_manager, menu, renderer);
}
});
}
}
if (device.isBrowsable()) {
need_sep = true;
MenuItem browse_menu_item = menu_manager.addMenuItem("sidebar." + key, "device.browse");
browse_menu_item.setDisposeWithUIDetach(UIInstance.UIT_SWT);
browse_menu_item.setStyle(MenuItem.STYLE_MENU);
browse_menu_item.addFillListener(will_browse_listener);
}
if (need_sep) {
MenuItem menu_item = menu_manager.addMenuItem("sidebar." + key, "s2");
menu_item.setDisposeWithUIDetach(UIInstance.UIT_SWT);
menu_item.setStyle(MenuItem.STYLE_SEPARATOR);
}
// rename
MenuItem rename_menu_item = menu_manager.addMenuItem("sidebar." + key, "MyTorrentsView.menu.rename");
rename_menu_item.setDisposeWithUIDetach(UIInstance.UIT_SWT);
rename_menu_item.addListener(rename_listener);
if (device.isExportable()) {
MenuItem export_item = menu_manager.addMenuItem("sidebar." + key, "Subscription.menu.export");
export_item.setDisposeWithUIDetach(UIInstance.UIT_SWT);
export_item.addListener(export_listener);
}
// hide
MenuItem hide_menu_item = menu_manager.addMenuItem("sidebar." + key, "device.hide");
hide_menu_item.setDisposeWithUIDetach(UIInstance.UIT_SWT);
hide_menu_item.addListener(hide_listener);
// tag
MenuItem tag_menu_item = menu_manager.addMenuItem("sidebar." + key, "device.tag");
tag_menu_item.setDisposeWithUIDetach(UIInstance.UIT_SWT);
tag_menu_item.setStyle(MenuItem.STYLE_CHECK);
tag_menu_item.addFillListener(will_tag_listener);
tag_menu_item.addListener(tag_listener);
// remove
MenuItem remove_menu_item = menu_manager.addMenuItem("sidebar." + key, "MySharesView.menu.remove");
remove_menu_item.setDisposeWithUIDetach(UIInstance.UIT_SWT);
remove_menu_item.addFillListener(will_remove_listener);
remove_menu_item.addListener(remove_listener);
// sep
MenuItem menu_item_sep = menu_manager.addMenuItem("sidebar." + key, "s3");
menu_item_sep.setStyle(MenuItem.STYLE_SEPARATOR);
menu_item_sep.setDisposeWithUIDetach(UIInstance.UIT_SWT);
final URL wiki_url = device.getWikiURL();
if (wiki_url != null) {
MenuItem wiki_menu_item = menu_manager.addMenuItem("sidebar." + key, "device.wiki");
wiki_menu_item.setDisposeWithUIDetach(UIInstance.UIT_SWT);
wiki_menu_item.addListener(new MenuItemListener() {
@Override
public void selected(MenuItem menu, Object target) {
Utils.launch(wiki_url.toExternalForm());
}
});
}
// props
MenuItem menu_item = menu_manager.addMenuItem("sidebar." + key, "Subscription.menu.properties");
menu_item.setDisposeWithUIDetach(UIInstance.UIT_SWT);
menu_item.addListener(properties_listener);
}
}
Aggregations