mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-01-04 02:29:49 -06:00
Some more work on Launcher
This commit is contained in:
@@ -52,14 +52,17 @@ InfoWidget::InfoWidget(QString name, int totalBytes)
|
||||
|
||||
setLayout(layout);
|
||||
|
||||
update(0, 0.f);
|
||||
update(0);
|
||||
}
|
||||
|
||||
void InfoWidget::update(int currentBytes, float progress) {
|
||||
void InfoWidget::update(int currentBytes) {
|
||||
_bytes->setText(
|
||||
QString("%1 / %2").arg(currentBytes).arg(_totalBytes)
|
||||
QString("%1 / %2")
|
||||
.arg(currentBytes)
|
||||
.arg(_totalBytes)
|
||||
);
|
||||
|
||||
float progress = static_cast<float>(currentBytes) / static_cast<float>(_totalBytes);
|
||||
_progress->setValue(static_cast<int>(progress * 100));
|
||||
}
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ Q_OBJECT
|
||||
public:
|
||||
InfoWidget(QString name, int totalBytes);
|
||||
|
||||
void update(int currentBytes, float progress);
|
||||
void update(int currentBytes);
|
||||
void error(QString message);
|
||||
|
||||
private:
|
||||
|
||||
@@ -37,6 +37,7 @@
|
||||
#include <QCheckBox>
|
||||
#include <QDebug>
|
||||
#include <QDir>
|
||||
#include <QFileInfo>
|
||||
#include <QGridLayout>
|
||||
#include <QGroupBox>
|
||||
#include <QPushButton>
|
||||
@@ -110,6 +111,7 @@ SyncWidget::SyncWidget(QWidget* parent)
|
||||
return;
|
||||
}
|
||||
_session->start_upnp();
|
||||
_session->start_dht();
|
||||
|
||||
QTimer* timer = new QTimer(this);
|
||||
QObject::connect(timer, SIGNAL(timeout()), this, SLOT(handleTimer()));
|
||||
@@ -180,7 +182,10 @@ void SyncWidget::handleTorrentFiles(QString module, TorrentFiles files) {
|
||||
QString file = QString::fromStdString(absPath(fullPath(module, f.file).toStdString()));
|
||||
qDebug() << file;
|
||||
|
||||
//libtorrent::bdecode()
|
||||
if (!QFileInfo(file).exists()) {
|
||||
qDebug() << file << " does not exist";
|
||||
continue;
|
||||
}
|
||||
|
||||
libtorrent::error_code ec;
|
||||
libtorrent::add_torrent_params p;
|
||||
@@ -192,16 +197,18 @@ void SyncWidget::handleTorrentFiles(QString module, TorrentFiles files) {
|
||||
p.auto_managed = true;
|
||||
if (ec) {
|
||||
qDebug() << QString::fromStdString(ec.message());
|
||||
//return;
|
||||
continue;
|
||||
}
|
||||
libtorrent::torrent_handle h = _session->add_torrent(p, ec);
|
||||
if (ec) {
|
||||
qDebug() << QString::fromStdString(ec.message());
|
||||
//return;
|
||||
continue;
|
||||
}
|
||||
|
||||
InfoWidget* w = new InfoWidget(f.file, h.status().total_done);
|
||||
libtorrent::size_type s = h.status().total_wanted;
|
||||
InfoWidget* w = new InfoWidget(f.file, h.status().total_wanted);
|
||||
_downloadLayout->addWidget(w);
|
||||
_infoWidgetMap[h] = w;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -246,7 +253,6 @@ void SyncWidget::syncButtonPressed() {
|
||||
bool found = dataDictionary.getValue<ghoul::Dictionary>(FileDownloadKey, directDownloadFiles);
|
||||
if (found) {
|
||||
DirectFiles files;
|
||||
//QStringList files;
|
||||
for (int i = 1; i <= directDownloadFiles.size(); ++i) {
|
||||
ghoul::Dictionary d = directDownloadFiles.value<ghoul::Dictionary>(std::to_string(i));
|
||||
std::string url = d.value<std::string>(UrlKey);
|
||||
@@ -314,7 +320,7 @@ QString SyncWidget::fullPath(QString module, QString destination) const {
|
||||
}
|
||||
|
||||
void SyncWidget::handleTimer() {
|
||||
//using namespace libtorrent;
|
||||
using namespace libtorrent;
|
||||
|
||||
//_session->post_torrent_updates();
|
||||
|
||||
@@ -336,25 +342,30 @@ void SyncWidget::handleTimer() {
|
||||
//qDebug() << "===";
|
||||
|
||||
|
||||
//std::vector<torrent_handle> handles = _session->get_torrents();
|
||||
//for (torrent_handle h : handles) {
|
||||
// //qDebug() << "Name: " << QString::fromStdString(h.name());
|
||||
// //torrent_status s = h.status();
|
||||
std::vector<torrent_handle> handles = _session->get_torrents();
|
||||
for (torrent_handle h : handles) {
|
||||
torrent_status s = h.status();
|
||||
InfoWidget* w = _infoWidgetMap[h];
|
||||
|
||||
// //qDebug() << "Error: " << QString::fromStdString(s.error);
|
||||
w->update(s.total_wanted_done);
|
||||
|
||||
// //qDebug() << "Total Wanted: " << s.total_wanted;
|
||||
// //qDebug() << "Total Wanted Done: " << s.total_wanted_done;
|
||||
// //qDebug() << "Has Incoming: " << s.has_incoming;
|
||||
// //qDebug() << "Connect Candidates: " << s.connect_candidates;
|
||||
// //qDebug() << "Last Seen Complete: " << s.last_seen_complete;
|
||||
// //qDebug() << "List Peers: " << s.list_peers;
|
||||
// //qDebug() << "Num Pieces: " << s.num_pieces;
|
||||
// //qDebug() << "Download Rate: " << s.download_rate;
|
||||
// //qDebug() << "List Seeds: " << s.list_seeds;
|
||||
// //qDebug() << "Paused: " << s.paused;
|
||||
// //qDebug() << "Progress: " << s.progress;
|
||||
qDebug() << "Name: " << QString::fromStdString(h.name());
|
||||
//torrent_status s = h.status();
|
||||
|
||||
// qDebug() << "";
|
||||
//}
|
||||
qDebug() << "Error: " << QString::fromStdString(s.error);
|
||||
|
||||
qDebug() << "Total Wanted: " << s.total_wanted;
|
||||
qDebug() << "Total Wanted Done: " << s.total_wanted_done;
|
||||
qDebug() << "Has Incoming: " << s.has_incoming;
|
||||
qDebug() << "Connect Candidates: " << s.connect_candidates;
|
||||
qDebug() << "Last Seen Complete: " << s.last_seen_complete;
|
||||
qDebug() << "List Peers: " << s.list_peers;
|
||||
qDebug() << "Num Pieces: " << s.num_pieces;
|
||||
qDebug() << "Download Rate: " << s.download_rate;
|
||||
qDebug() << "List Seeds: " << s.list_seeds;
|
||||
qDebug() << "Paused: " << s.paused;
|
||||
qDebug() << "Progress: " << s.progress;
|
||||
|
||||
qDebug() << "";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ class InfoWidget;
|
||||
|
||||
namespace libtorrent {
|
||||
class session;
|
||||
class torrent_handle;
|
||||
struct torrent_handle;
|
||||
}
|
||||
|
||||
class SyncWidget : public QWidget {
|
||||
@@ -88,7 +88,6 @@ private:
|
||||
QBoxLayout* _downloadLayout;
|
||||
|
||||
libtorrent::session* _session;
|
||||
//QMap<QString, InfoWidget*> _infoWidgetMap;
|
||||
QMap<libtorrent::torrent_handle, InfoWidget*> _infoWidgetMap;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user