use of com.biglybt.core.tag.TagDownload in project BiglyBT by BiglySoftware.
the class SystemTraySWT method updateUI.
// @see UIUpdatable#updateUI()
@Override
public void updateUI(boolean is_visible) {
if (interval++ % 10 > 0) {
return;
}
if (trayItem.isDisposed()) {
uiFunctions.getUIUpdater().removeUpdater(this);
return;
}
if (core == null || !core.isStarted()) {
return;
}
if (enableTooltip) {
GlobalManagerStats stats = gm.getStats();
StringBuilder toolTip = new StringBuilder();
int seeding = 0;
int downloading = 0;
DownloadManager next_download = null;
long next_download_eta = Long.MAX_VALUE;
TagManager tm = TagManagerFactory.getTagManager();
if (tm != null && tm.isEnabled()) {
TagType tt = tm.getTagType(TagType.TT_DOWNLOAD_STATE);
if (tt != null) {
TagDownload dl_tag = (TagDownload) tt.getTag(1);
downloading = dl_tag.getTaggedCount();
seeding = tt.getTag(2).getTaggedCount();
if (enableTooltipNextETA && downloading > 0) {
for (DownloadManager dl : dl_tag.getTaggedDownloads()) {
DownloadManagerStats dl_stats = dl.getStats();
long eta = dl_stats.getSmoothedETA();
if (eta < next_download_eta) {
next_download_eta = eta;
next_download = dl;
}
}
}
}
} else {
// OMG this must be slow on 10k lists
/*
List<?> managers = gm.getDownloadManagers();
for (int i = 0; i < managers.size(); i++) {
DownloadManager manager = (DownloadManager) managers.get(i);
int state = manager.getState();
if (state == DownloadManager.STATE_DOWNLOADING)
downloading++;
if (state == DownloadManager.STATE_SEEDING)
seeding++;
}
*/
}
String seeding_text = seedingKeyVal.replaceAll("%1", "" + seeding);
String downloading_text = downloadingKeyVal.replaceAll("%1", "" + downloading);
toolTip.append(seeding_text).append(downloading_text).append("\n");
if (next_download != null) {
String dl_name = next_download.getDisplayName();
if (dl_name.length() > 80) {
dl_name = dl_name.substring(0, 77) + "...";
}
dl_name = dl_name.replaceAll("&", "&&");
toolTip.append(" ");
toolTip.append(dl_name);
toolTip.append(": ");
toolTip.append(etaKeyVal);
toolTip.append("=");
toolTip.append(DisplayFormatters.formatETA(next_download_eta));
toolTip.append("\n");
}
toolTip.append(dlAbbrKeyVal).append(" ");
toolTip.append(DisplayFormatters.formatDataProtByteCountToKiBEtcPerSec(stats.getDataReceiveRate(), stats.getProtocolReceiveRate()));
toolTip.append(", ").append(ulAbbrKeyVal).append(" ");
toolTip.append(DisplayFormatters.formatDataProtByteCountToKiBEtcPerSec(stats.getDataSendRate(), stats.getProtocolSendRate()));
int alerts = Alerts.getUnviewedLogAlertCount();
if (alerts > 0) {
toolTip.append("\n");
toolTip.append(alertsKeyVal.replaceAll("%1", "" + alerts));
}
trayItem.setToolTipText(toolTip.toString());
}
if (Constants.isUnix && gm != null) {
GlobalManagerStats stats = gm.getStats();
long l = (stats.getDataReceiveRate() + stats.getDataSendRate()) / 1024;
if (l != lastUnixVal) {
lastUnixVal = l;
trayItem.setMenu(menu, menuBuilder);
}
}
// Why should we refresh the image? it never changes ...
// and is a memory bottleneck for some non-obvious reasons.
// trayItem.setImage(ImageLoader.getInstance().getImage("logo16"));
trayItem.setVisible(true);
}
Aggregations