Search in sources :

Example 1 with TranscodeFile

use of com.biglybt.core.devices.TranscodeFile in project BiglyBT by BiglySoftware.

the class DataSourceUtils method getTorrent.

public static TOTorrent getTorrent(Object ds) {
    if (ds instanceof TOTorrent) {
        return (TOTorrent) ds;
    }
    if (ds instanceof DownloadManager) {
        TOTorrent torrent = ((DownloadManager) ds).getTorrent();
        if (torrent != null) {
            return torrent;
        }
    }
    if (ds instanceof ActivitiesEntry) {
        TOTorrent torrent = ((ActivitiesEntry) ds).getTorrent();
        if (torrent == null) {
            // getDM will check hash as well
            DownloadManager dm = getDM(ds);
            if (dm != null) {
                torrent = dm.getTorrent();
            }
        }
        return torrent;
    }
    if (ds instanceof TranscodeFile) {
        TranscodeFile tf = (TranscodeFile) ds;
        try {
            DiskManagerFileInfo file = tf.getSourceFile();
            if (file != null) {
                Download download = file.getDownload();
                if (download != null) {
                    Torrent torrent = download.getTorrent();
                    if (torrent != null) {
                        return PluginCoreUtils.unwrap(torrent);
                    }
                }
            }
        } catch (Throwable e) {
        }
    }
    if (ds instanceof TranscodeJob) {
        TranscodeJob tj = (TranscodeJob) ds;
        try {
            DiskManagerFileInfo file = tj.getFile();
            if (file != null) {
                Download download = tj.getFile().getDownload();
                if (download != null) {
                    Torrent torrent = download.getTorrent();
                    if (torrent != null) {
                        return PluginCoreUtils.unwrap(torrent);
                    }
                }
            }
        } catch (DownloadException e) {
        }
    }
    if (ds instanceof ISelectedContent) {
        return ((ISelectedContent) ds).getTorrent();
    }
    if (ds instanceof String) {
        String hash = (String) ds;
        try {
            GlobalManager gm = CoreFactory.getSingleton().getGlobalManager();
            DownloadManager dm = gm.getDownloadManager(new HashWrapper(Base32.decode(hash)));
            if (dm != null) {
                return dm.getTorrent();
            }
        } catch (Exception e) {
        // ignore
        }
    }
    DownloadManager dm = getDM(ds);
    if (dm != null) {
        return dm.getTorrent();
    }
    return null;
}
Also used : TOTorrent(com.biglybt.core.torrent.TOTorrent) Torrent(com.biglybt.pif.torrent.Torrent) DiskManagerFileInfo(com.biglybt.pif.disk.DiskManagerFileInfo) ISelectedContent(com.biglybt.ui.selectedcontent.ISelectedContent) DownloadManager(com.biglybt.core.download.DownloadManager) DownloadException(com.biglybt.pif.download.DownloadException) TranscodeJob(com.biglybt.core.devices.TranscodeJob) ActivitiesEntry(com.biglybt.activities.ActivitiesEntry) GlobalManager(com.biglybt.core.global.GlobalManager) HashWrapper(com.biglybt.core.util.HashWrapper) TOTorrent(com.biglybt.core.torrent.TOTorrent) DownloadException(com.biglybt.pif.download.DownloadException) TranscodeFile(com.biglybt.core.devices.TranscodeFile) Download(com.biglybt.pif.download.Download) TagDownload(com.biglybt.core.tag.TagDownload)

Example 2 with TranscodeFile

use of com.biglybt.core.devices.TranscodeFile in project BiglyBT by BiglySoftware.

the class ColumnTJ_Tags method refresh.

// @see com.biglybt.pif.ui.tables.TableCellRefreshListener#refresh(com.biglybt.pif.ui.tables.TableCell)
@Override
public void refresh(TableCell cell) {
    TranscodeFile tf = (TranscodeFile) cell.getDataSource();
    if (tf == null) {
        return;
    }
    String[] tags = tf.getTags(true);
    String str = "";
    for (String tag : tags) {
        str += (str.length() == 0 ? "" : ",") + tag;
    }
    cell.setText(str);
}
Also used : TranscodeFile(com.biglybt.core.devices.TranscodeFile)

Example 3 with TranscodeFile

use of com.biglybt.core.devices.TranscodeFile in project BiglyBT by BiglySoftware.

the class ColumnTJ_Completion method refresh.

@Override
public void refresh(TableCell cell) {
    TranscodeFile tf = (TranscodeFile) cell.getDataSource();
    int percentDone = getPerThouDone(tf);
    cell.setSortValue(percentDone);
}
Also used : TranscodeFile(com.biglybt.core.devices.TranscodeFile)

Example 4 with TranscodeFile

use of com.biglybt.core.devices.TranscodeFile in project BiglyBT by BiglySoftware.

the class ColumnTJ_Name method refresh.

@Override
public void refresh(TableCell cell) {
    TranscodeFile tf = (TranscodeFile) cell.getDataSource();
    if (tf == null) {
        return;
    }
    String text = tf.getName();
    if (text == null || text.length() == 0) {
        return;
    }
    cell.setText(text);
}
Also used : TranscodeFile(com.biglybt.core.devices.TranscodeFile)

Example 5 with TranscodeFile

use of com.biglybt.core.devices.TranscodeFile in project BiglyBT by BiglySoftware.

the class ColumnTJ_Status method refresh.

// @see com.biglybt.pif.ui.tables.TableCellRefreshListener#refresh(com.biglybt.pif.ui.tables.TableCell)
@Override
public void refresh(TableCell cell) {
    TranscodeFile tf = (TranscodeFile) cell.getDataSource();
    if (tf == null || tf.isDeleted()) {
        return;
    }
    TranscodeJob job = tf.getJob();
    String tooltip = null;
    String text = null;
    boolean error = false;
    if (job == null) {
        try {
            if (tf.isComplete() && !tf.getTargetFile().getFile(true).exists()) {
                tooltip = "File '" + tf.getTargetFile().getFile().getAbsolutePath() + "' not found";
                text = js_resources[5] + ": File not found";
                error = true;
            }
        } catch (Throwable e) {
        }
        if (text == null) {
            if (tf.isCopyingToDevice()) {
                text = js_resources[11];
            } else if (tf.getCopyToDeviceFails() > 0) {
                text = js_resources[7];
                error = true;
            } else if (tf.isTemplate() && !tf.isComplete()) {
                text = js_resources[8];
            } else {
                text = js_resources[9];
            }
        }
    } else {
        int state = job.getState();
        text = js_resources[state];
        if (state == TranscodeJob.ST_QUEUED) {
            long eta = job.getDownloadETA();
            if (eta > 0) {
                text = js_resources[10] + ": " + eta_text + " " + (eta == Long.MAX_VALUE ? Constants.INFINITY_STRING : TimeFormatter.format(eta));
            }
        } else {
            text = js_resources[state];
            if (state == TranscodeJob.ST_FAILED) {
                String error_msg = job.getError();
                if (error_msg != null) {
                    try {
                        int pos = error_msg.indexOf('\n');
                        if (pos >= 0) {
                            error_msg = error_msg.substring(0, pos);
                        }
                        pos = error_msg.indexOf(',');
                        if (pos >= 0) {
                            pos = error_msg.indexOf(',', pos + 1);
                            if (pos >= 0) {
                                error_msg = error_msg.substring(0, pos);
                            }
                        }
                        text += ": " + error_msg.trim();
                    } catch (Throwable e) {
                    }
                }
                tooltip = "See transcode log for more details";
                error = true;
            }
        }
    }
    cell.setText(text);
    cell.setToolTip(tooltip);
    if (error) {
        cell.setForegroundToErrorColor();
    } else {
        cell.setForeground(Utils.colorToIntArray(null));
    }
}
Also used : TranscodeFile(com.biglybt.core.devices.TranscodeFile) TranscodeJob(com.biglybt.core.devices.TranscodeJob)

Aggregations

TranscodeFile (com.biglybt.core.devices.TranscodeFile)14 TranscodeJob (com.biglybt.core.devices.TranscodeJob)4 DownloadManager (com.biglybt.core.download.DownloadManager)2 DiskManagerFileInfo (com.biglybt.pif.disk.DiskManagerFileInfo)2 DownloadException (com.biglybt.pif.download.DownloadException)2 ISelectedContent (com.biglybt.ui.selectedcontent.ISelectedContent)2 ActivitiesEntry (com.biglybt.activities.ActivitiesEntry)1 Device (com.biglybt.core.devices.Device)1 DeviceMediaRenderer (com.biglybt.core.devices.DeviceMediaRenderer)1 TranscodeTargetListener (com.biglybt.core.devices.TranscodeTargetListener)1 GlobalManager (com.biglybt.core.global.GlobalManager)1 TagDownload (com.biglybt.core.tag.TagDownload)1 TOTorrent (com.biglybt.core.torrent.TOTorrent)1 HashWrapper (com.biglybt.core.util.HashWrapper)1 Download (com.biglybt.pif.download.Download)1 Torrent (com.biglybt.pif.torrent.Torrent)1 ImageLoader (com.biglybt.ui.swt.imageloader.ImageLoader)1