use of com.biglybt.pif.download.Download.SeedingRank in project BiglyBT by BiglySoftware.
the class StatusItem method refresh.
@Override
public void refresh(TableCell cell) {
DownloadManager dm = (DownloadManager) cell.getDataSource();
if (dm == null) {
return;
}
Integer sort_order = sort_orders.get(getTableID());
if (sort_order == null) {
sort_order = sort_orders.get("other");
}
int state = dm.getState();
String tooltip;
if (state == DownloadManager.STATE_QUEUED && Utils.getUserMode() == 0) {
tooltip = MessageText.getString("ManagerItem.queued.tooltip");
} else {
tooltip = null;
}
if (state != DownloadManager.STATE_STOPPED && state != DownloadManager.STATE_ERROR && dm.isDownloadComplete(false)) {
SeedingRank sr = dm.getSeedingRank();
String[] status = sr.getStatus(true);
tooltip = tooltip == null ? status[0] : (tooltip + "\n\n" + status[0]);
if (status[1] != null) {
tooltip += "\n\n" + status[1];
}
}
long sort_value;
String text;
if (showTrackerErrors && dm.isUnauthorisedOnTracker() && state != DownloadManager.STATE_ERROR) {
text = dm.getTrackerStatus();
sort_value = 1100;
} else {
text = DisplayFormatters.formatDownloadStatus(dm);
boolean forced = dm.isForceStart() && (state == DownloadManager.STATE_DOWNLOADING || state == DownloadManager.STATE_SEEDING);
if (sort_order == 1) {
if (forced) {
sort_value = 1000;
} else {
switch(state) {
case DownloadManager.STATE_SEEDING:
{
sort_value = 900;
break;
}
case DownloadManager.STATE_DOWNLOADING:
{
sort_value = 800;
break;
}
case DownloadManager.STATE_QUEUED:
{
if (dm.getSubState() == DownloadManager.STATE_SEEDING) {
// light seeding
sort_value = 750;
} else {
sort_value = 700;
}
break;
}
case DownloadManager.STATE_STOPPED:
{
if (dm.isPaused()) {
sort_value = 600;
} else {
sort_value = 500;
}
break;
}
default:
{
sort_value = 0;
}
}
}
} else if (sort_order == 2) {
PEPeerManager pm = dm.getPeerManager();
boolean super_seeding = pm != null && pm.isSuperSeedMode();
if (forced) {
sort_value = 800;
} else if (dm.isPaused()) {
sort_value = 600;
} else if (super_seeding) {
sort_value = 825;
} else {
switch(state) {
case DownloadManager.STATE_WAITING:
{
sort_value = 100;
break;
}
case DownloadManager.STATE_INITIALIZING:
{
sort_value = 100;
break;
}
case DownloadManager.STATE_INITIALIZED:
{
sort_value = 100;
break;
}
case DownloadManager.STATE_ALLOCATING:
{
sort_value = 200;
break;
}
case DownloadManager.STATE_CHECKING:
{
sort_value = 900;
break;
}
case DownloadManager.STATE_READY:
{
sort_value = 300;
break;
}
case DownloadManager.STATE_DOWNLOADING:
{
sort_value = 400;
break;
}
case DownloadManager.STATE_FINISHING:
{
sort_value = 400;
break;
}
case DownloadManager.STATE_SEEDING:
{
DiskManager diskManager = dm.getDiskManager();
if (diskManager != null && diskManager.getCompleteRecheckStatus() != -1) {
sort_value = 900;
} else {
sort_value = 850;
}
break;
}
case DownloadManager.STATE_STOPPING:
{
sort_value = 500;
break;
}
case DownloadManager.STATE_STOPPED:
{
sort_value = 500;
break;
}
case DownloadManager.STATE_QUEUED:
{
if (dm.getSubState() == DownloadManager.STATE_SEEDING) {
sort_value = 810;
} else {
sort_value = 700;
}
break;
}
case DownloadManager.STATE_ERROR:
{
sort_value = 1000;
break;
}
default:
{
sort_value = 999;
break;
}
}
}
} else {
// not used
sort_value = 0;
}
}
if (tooltip != null) {
tooltip = text + "\n\n" + tooltip;
}
if (sort_order == 1) {
// priority based - mix in actual state and priority
sort_value += state;
sort_value <<= 32;
if (dm.isDownloadComplete(false)) {
Download dl = PluginCoreUtils.wrap(dm);
if (dl != null) {
sort_value += dl.getSeedingRank().getRank();
}
} else {
sort_value -= dm.getPosition();
}
}
boolean update;
if (sort_order == 0) {
update = cell.setSortValue(text);
} else {
update = cell.setSortValue(sort_value);
if (!update) {
if (!cell.getText().equals(text)) {
update = true;
}
}
}
if (update || !cell.isValid()) {
cell.setText(text);
cell.setToolTip(tooltip);
boolean clickable = false;
if (cell instanceof TableCellSWT) {
int cursor_id;
if (!text.contains("http://")) {
dm.setUserData(CLICK_KEY, null);
cursor_id = SWT.CURSOR_ARROW;
} else {
dm.setUserData(CLICK_KEY, text);
cursor_id = SWT.CURSOR_HAND;
clickable = true;
}
((TableCellSWT) cell).setCursorID(cursor_id);
}
if (!changeCellFG && !changeRowFG) {
// clickable, make it blue whatever
cell.setForeground(clickable ? BLUE : null);
return;
}
TableRow row = cell.getTableRow();
if (row != null) {
Color color = null;
if (state == DownloadManager.STATE_SEEDING) {
color = Colors.blues[Colors.BLUES_MIDDARK];
} else if (state == DownloadManager.STATE_ERROR) {
color = Colors.colorError;
} else {
color = null;
}
if (changeRowFG) {
if (row instanceof TableRowSWT) {
((TableRowSWT) row).requestForegroundColor(color_requester, overall_change_fg ? color : null);
}
// row.setForeground( overall_change_fg?Utils.colorToIntArray(color):null);
} else if (changeCellFG) {
cell.setForeground(Utils.colorToIntArray(color));
}
if (clickable) {
cell.setForeground(Utils.colorToIntArray(Colors.blue));
}
}
} else {
String old_tt = (String) cell.getToolTip();
if (old_tt != tooltip) {
if (old_tt == null || tooltip == null || !old_tt.equals(tooltip)) {
cell.setToolTip(tooltip);
}
}
}
}
use of com.biglybt.pif.download.Download.SeedingRank in project BiglyBT by BiglySoftware.
the class SeedingRankColumnListener method refresh.
@Override
public void refresh(TableCell cell) {
Download dl = (Download) cell.getDataSource();
if (dl == null)
return;
DefaultRankCalculator dlData;
Object o = cell.getSortValue();
if (o instanceof DefaultRankCalculator)
dlData = (DefaultRankCalculator) o;
else {
dlData = StartStopRulesDefaultPlugin.getRankCalculator(dl);
}
if (dlData == null) {
cell.setSortValue(-1);
return;
}
Sorter comp = (Sorter) dlData.getUserData(KEY);
if (comp == null) {
comp = new Sorter(dlData);
dlData.setUserData(KEY, comp);
}
cell.setSortValue(comp);
SeedingRank sr = dl.getSeedingRank();
String[] status = sr.getStatus(false);
cell.setText(status[0]);
/*
int state = dlData.getState();
if ( state == Download.ST_STOPPED || state == Download.ST_ERROR ){
cell.setText( "" );
}else{
cell.setText(status[0]);
}
*/
cell.setToolTip(status[1]);
}
Aggregations