mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-01-05 19:19:39 -06:00
Making SyncWidget and ShortcutWidget modal windows
Enable correct progress callback for DownloadManager
This commit is contained in:
@@ -24,6 +24,9 @@
|
||||
|
||||
#include "mainwindow.h"
|
||||
|
||||
#include "shortcutwidget.h"
|
||||
#include "syncwidget.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QComboBox>
|
||||
#include <QDir>
|
||||
@@ -141,8 +144,13 @@ void MainWindow::initialize() {
|
||||
this, SLOT(newsNetworkError())
|
||||
);
|
||||
|
||||
_shortcutWidget.hide();
|
||||
_syncWidget.hide();
|
||||
_shortcutWidget = new ShortcutWidget(this, Qt::Popup | Qt::Dialog);
|
||||
_shortcutWidget->setWindowModality(Qt::WindowModal);
|
||||
_shortcutWidget->hide();
|
||||
|
||||
_syncWidget = new SyncWidget(this, Qt::Popup | Qt::Dialog);
|
||||
_syncWidget->setWindowModality(Qt::WindowModal);
|
||||
_syncWidget->hide();
|
||||
|
||||
QDir d(ModulesDirectory);
|
||||
d.setFilter(QDir::Files);
|
||||
@@ -152,16 +160,16 @@ void MainWindow::initialize() {
|
||||
_sceneFiles.insert(i.fileName(), i.absoluteFilePath());
|
||||
_scenes->addItem(i.fileName());
|
||||
}
|
||||
_syncWidget.setSceneFiles(_sceneFiles);
|
||||
_syncWidget.setModulesDirectory(ModulesDirectory);
|
||||
_syncWidget->setSceneFiles(_sceneFiles);
|
||||
_syncWidget->setModulesDirectory(ModulesDirectory);
|
||||
}
|
||||
|
||||
void MainWindow::shortcutButtonPressed() {
|
||||
_shortcutWidget.show();
|
||||
_shortcutWidget->show();
|
||||
}
|
||||
|
||||
void MainWindow::syncButtonPressed() {
|
||||
_syncWidget.show();
|
||||
_syncWidget->show();
|
||||
}
|
||||
|
||||
void MainWindow::startButtonPressed() {
|
||||
|
||||
@@ -27,9 +27,6 @@
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
#include "shortcutwidget.h"
|
||||
#include "syncwidget.h"
|
||||
|
||||
#include <QMap>
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QNetworkReply>
|
||||
@@ -38,6 +35,9 @@
|
||||
class QComboBox;
|
||||
class QNetworkAccessManager;
|
||||
|
||||
class ShortcutWidget;
|
||||
class SyncWidget;
|
||||
|
||||
class MainWindow : public QWidget {
|
||||
Q_OBJECT
|
||||
public:
|
||||
@@ -62,8 +62,8 @@ private:
|
||||
QComboBox* _scenes;
|
||||
QMap<QString, QString> _sceneFiles;
|
||||
|
||||
ShortcutWidget _shortcutWidget;
|
||||
SyncWidget _syncWidget;
|
||||
ShortcutWidget* _shortcutWidget;
|
||||
SyncWidget* _syncWidget;
|
||||
|
||||
|
||||
QNetworkAccessManager _networkManager;
|
||||
|
||||
@@ -24,6 +24,6 @@
|
||||
|
||||
#include "shortcutwidget.h"
|
||||
|
||||
ShortcutWidget::ShortcutWidget(QWidget* parent)
|
||||
: QWidget(parent)
|
||||
ShortcutWidget::ShortcutWidget(QWidget* parent, Qt::WindowFlags f)
|
||||
: QWidget(parent, f)
|
||||
{}
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
class ShortcutWidget : public QWidget {
|
||||
Q_OBJECT
|
||||
public:
|
||||
ShortcutWidget(QWidget* parent);
|
||||
ShortcutWidget(QWidget* parent, Qt::WindowFlags f = 0);
|
||||
};
|
||||
|
||||
#endif // __SHORTCUTWIDGET_H__
|
||||
|
||||
@@ -64,10 +64,12 @@ namespace {
|
||||
const std::string DestinationKey = "Destination";
|
||||
const std::string IdentifierKey = "Identifier";
|
||||
const std::string VersionKey = "Version";
|
||||
|
||||
const QString DefaultSceneName = "default.scene";
|
||||
}
|
||||
|
||||
SyncWidget::SyncWidget(QWidget* parent)
|
||||
: QWidget(parent)
|
||||
SyncWidget::SyncWidget(QWidget* parent, Qt::WindowFlags f)
|
||||
: QWidget(parent, f)
|
||||
, _sceneLayout(nullptr)
|
||||
, _session(new libtorrent::session)
|
||||
{
|
||||
@@ -135,6 +137,9 @@ void SyncWidget::setSceneFiles(QMap<QString, QString> sceneFiles) {
|
||||
|
||||
QCheckBox* checkbox = new QCheckBox(sceneName);
|
||||
|
||||
if (sceneName == DefaultSceneName)
|
||||
checkbox->setChecked(true);
|
||||
|
||||
_sceneLayout->addWidget(checkbox, i / nColumns, i % nColumns);
|
||||
}
|
||||
}
|
||||
@@ -148,29 +153,44 @@ void SyncWidget::clear() {
|
||||
}
|
||||
|
||||
void SyncWidget::handleDirectFiles(QString module, DirectFiles files) {
|
||||
//return;
|
||||
qDebug() << "Direct Files";
|
||||
for (const DirectFile& f : files) {
|
||||
qDebug() << f.url << " -> " << f.destination;
|
||||
|
||||
auto finishedCallback =
|
||||
[](const ghoul::filesystem::File& f) {
|
||||
qDebug() << QString::fromStdString(f.filename()) << "finished";
|
||||
};
|
||||
auto progressCallback =
|
||||
[](const ghoul::filesystem::File& f, float progress) {
|
||||
qDebug() << QString::fromStdString(f.filename()) << ": " << progress;
|
||||
};
|
||||
|
||||
DlManager.downloadFile(
|
||||
f.url.toStdString(),
|
||||
fullPath(module, f.destination).toStdString(),
|
||||
[](const ghoul::filesystem::File& f) { qDebug() << QString::fromStdString(f.filename()) << "finished";}
|
||||
finishedCallback,
|
||||
progressCallback
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void SyncWidget::handleFileRequest(QString module, FileRequests files) {
|
||||
//return;
|
||||
return;
|
||||
qDebug() << "File Requests";
|
||||
for (const FileRequest& f : files) {
|
||||
auto progressCallback =
|
||||
[](const ghoul::filesystem::File& f, float progress) {
|
||||
qDebug() << QString::fromStdString(f.filename()) << ": " << progress;
|
||||
};
|
||||
|
||||
qDebug() << f.identifier << " (" << f.version << ")" << " -> " << f.destination;
|
||||
DlManager.downloadRequestFiles(
|
||||
f.identifier.toStdString(),
|
||||
fullPath(module, f.destination).toStdString(),
|
||||
f.version,
|
||||
[](const ghoul::filesystem::File& f) { qDebug() << "finished"; }
|
||||
[](const ghoul::filesystem::File& f) { qDebug() << "finished"; },
|
||||
progressCallback
|
||||
);
|
||||
|
||||
|
||||
@@ -255,8 +275,18 @@ void SyncWidget::syncButtonPressed() {
|
||||
if (found) {
|
||||
DirectFiles files;
|
||||
for (int i = 1; i <= directDownloadFiles.size(); ++i) {
|
||||
if (!directDownloadFiles.hasKeyAndValue<ghoul::Dictionary>(std::to_string(i))) {
|
||||
qDebug() << QString::fromStdString(FileDownloadKey) << " is not a dictionary";
|
||||
continue;
|
||||
}
|
||||
ghoul::Dictionary d = directDownloadFiles.value<ghoul::Dictionary>(std::to_string(i));
|
||||
if (!directDownloadFiles.hasKeyAndValue<std::string>(UrlKey)) {
|
||||
qDebug() << "No '" << QString::fromStdString(UrlKey);
|
||||
}
|
||||
std::string url = d.value<std::string>(UrlKey);
|
||||
if (!directDownloadFiles.hasKeyAndValue<std::string>(DestinationKey)) {
|
||||
qDebug() << "No '" << QString::fromStdString(DestinationKey);
|
||||
}
|
||||
std::string dest = d.value<std::string>(DestinationKey);
|
||||
|
||||
files.append({
|
||||
@@ -323,30 +353,30 @@ QString SyncWidget::fullPath(QString module, QString destination) const {
|
||||
void SyncWidget::handleTimer() {
|
||||
using namespace libtorrent;
|
||||
|
||||
_session->post_torrent_updates();
|
||||
libtorrent::session_settings settings = _session->settings();
|
||||
//_session->post_torrent_updates();
|
||||
//libtorrent::session_settings settings = _session->settings();
|
||||
|
||||
qDebug() << "Session";
|
||||
qDebug() << "nPeers: " << _session->status().num_peers;
|
||||
qDebug() << "DHT: " << _session->is_dht_running();
|
||||
qDebug() << "Incoming TCP" << settings.enable_incoming_tcp;
|
||||
qDebug() << "Outgoing TCP" << settings.enable_outgoing_tcp;
|
||||
qDebug() << "Incoming UTP" << settings.enable_incoming_utp;
|
||||
qDebug() << "Outgoing UTP" << settings.enable_outgoing_utp;
|
||||
qDebug() << "===";
|
||||
//qDebug() << "Session";
|
||||
//qDebug() << "nPeers: " << _session->status().num_peers;
|
||||
//qDebug() << "DHT: " << _session->is_dht_running();
|
||||
//qDebug() << "Incoming TCP" << settings.enable_incoming_tcp;
|
||||
//qDebug() << "Outgoing TCP" << settings.enable_outgoing_tcp;
|
||||
//qDebug() << "Incoming UTP" << settings.enable_incoming_utp;
|
||||
//qDebug() << "Outgoing UTP" << settings.enable_outgoing_utp;
|
||||
//qDebug() << "===";
|
||||
|
||||
qDebug() << "Alerts";
|
||||
std::deque<alert*> alerts;
|
||||
_session->pop_alerts(&alerts);
|
||||
for (alert* a : alerts) {
|
||||
qDebug() << QString::fromStdString(a->message());
|
||||
//qDebug() << "Alerts";
|
||||
//std::deque<alert*> alerts;
|
||||
//_session->pop_alerts(&alerts);
|
||||
//for (alert* a : alerts) {
|
||||
// qDebug() << QString::fromStdString(a->message());
|
||||
|
||||
//if (a->category() == alert::status_notification) {
|
||||
// state_update_alert* sua = static_cast<state_update_alert*>(a);
|
||||
// for (torrent_status s )
|
||||
//}
|
||||
}
|
||||
qDebug() << "===";
|
||||
// //if (a->category() == alert::status_notification) {
|
||||
// // state_update_alert* sua = static_cast<state_update_alert*>(a);
|
||||
// // for (torrent_status s )
|
||||
// //}
|
||||
//}
|
||||
//qDebug() << "===";
|
||||
|
||||
|
||||
std::vector<torrent_handle> handles = _session->get_torrents();
|
||||
@@ -356,24 +386,24 @@ void SyncWidget::handleTimer() {
|
||||
|
||||
w->update(s.total_wanted_done);
|
||||
|
||||
qDebug() << "Name: " << QString::fromStdString(h.name());
|
||||
//torrent_status s = h.status();
|
||||
// qDebug() << "Name: " << QString::fromStdString(h.name());
|
||||
// //torrent_status s = h.status();
|
||||
|
||||
qDebug() << "Error: " << QString::fromStdString(s.error);
|
||||
// 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() << "List Seeds: " << s.list_seeds;
|
||||
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() << "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() << "List Seeds: " << s.list_seeds;
|
||||
// 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() << "";
|
||||
// qDebug() << "";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ namespace libtorrent {
|
||||
class SyncWidget : public QWidget {
|
||||
Q_OBJECT
|
||||
public:
|
||||
SyncWidget(QWidget* parent);
|
||||
SyncWidget(QWidget* parent, Qt::WindowFlags f = 0);
|
||||
~SyncWidget();
|
||||
|
||||
void setSceneFiles(QMap<QString, QString> sceneFiles);
|
||||
|
||||
2
data
2
data
Submodule data updated: 3879f4b889...9de5bb5767
@@ -54,4 +54,5 @@ return {
|
||||
File = "${BASE_PATH}/Properties.txt"
|
||||
},
|
||||
DownloadRequestURL = "http://openspace.itn.liu.se/request.cgi",
|
||||
RenderingMethod = "ABufferFrameBuffer"
|
||||
}
|
||||
@@ -45,6 +45,51 @@ namespace {
|
||||
written = fwrite(ptr, size, nmemb, stream);
|
||||
return written;
|
||||
}
|
||||
|
||||
struct Progress {
|
||||
CURL* curl;
|
||||
const ghoul::filesystem::File* file;
|
||||
openspace::DownloadManager::DownloadProgressCallback* callback;
|
||||
};
|
||||
|
||||
int xferinfo(void *p,
|
||||
curl_off_t dltotal, curl_off_t dlnow,
|
||||
curl_off_t ultotal, curl_off_t ulnow)
|
||||
{
|
||||
Progress* myp = static_cast<Progress*>(p);
|
||||
|
||||
if (myp->callback && *(myp->callback)) {
|
||||
(*(myp->callback))(
|
||||
*(myp->file),
|
||||
static_cast<float>(dlnow) / static_cast<float>(dltotal)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
//if (*(myp->callback)) {
|
||||
// *(myp->callback)(
|
||||
// myp->file,
|
||||
// static_cast<float>(dlnow) / static_cast<float>(dltotal)
|
||||
// );
|
||||
//}
|
||||
//CURL* curl = myp->curl;
|
||||
|
||||
|
||||
|
||||
//double curtime = 0;
|
||||
|
||||
//curl_easy_getinfo(curl, CURLINFO_TOTAL_TIME, &curtime);
|
||||
|
||||
//fprintf(stderr, "UP: %" CURL_FORMAT_CURL_OFF_T " of %" CURL_FORMAT_CURL_OFF_T
|
||||
// " DOWN: %" CURL_FORMAT_CURL_OFF_T " of %" CURL_FORMAT_CURL_OFF_T
|
||||
// "\r\n",
|
||||
// ulnow, ultotal, dlnow, dltotal);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
namespace openspace {
|
||||
@@ -65,20 +110,26 @@ bool DownloadManager::downloadFile(
|
||||
{
|
||||
CURL* curl = curl_easy_init();
|
||||
if (curl) {
|
||||
|
||||
FILE* fp = fopen(file.path().c_str(), "wb");
|
||||
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
|
||||
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writeData);
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
|
||||
|
||||
if (progressCallback) {
|
||||
Progress p = { curl, &file, &progressCallback };
|
||||
curl_easy_setopt(curl, CURLOPT_XFERINFOFUNCTION, xferinfo);
|
||||
curl_easy_setopt(curl, CURLOPT_XFERINFODATA, &p);
|
||||
curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0L);
|
||||
}
|
||||
|
||||
LDEBUG("Starting download for file: '" << url <<
|
||||
"' into file '" << file.path() << "'");
|
||||
CURLcode res = curl_easy_perform(curl);
|
||||
curl_easy_cleanup(curl);
|
||||
fclose(fp);
|
||||
|
||||
// TODO: incorporate progressCallback ---abock
|
||||
// http://curl.haxx.se/libcurl/c/progressfunc.html
|
||||
|
||||
if (res != CURLE_OK) {
|
||||
LERROR("Error downloading file 'url': " << curl_easy_strerror(res));
|
||||
return false;
|
||||
@@ -112,7 +163,7 @@ bool DownloadManager::downloadRequestFiles(
|
||||
bool success = downloadFile(
|
||||
fullRequest,
|
||||
requestFile,
|
||||
[destination](const ghoul::filesystem::File& f) {
|
||||
[destination, &progressCallback](const ghoul::filesystem::File& f) {
|
||||
LDEBUG("Finished: " << f.path());
|
||||
std::ifstream temporary(f.path());
|
||||
std::string line;
|
||||
@@ -126,7 +177,8 @@ bool DownloadManager::downloadRequestFiles(
|
||||
bool success = DlManager.downloadFile(
|
||||
line,
|
||||
destination.path() + "/" + file,
|
||||
[&nFinished](const ghoul::filesystem::File& f) { ++nFinished; }
|
||||
[&nFinished](const ghoul::filesystem::File& f) { ++nFinished; },
|
||||
[&progressCallback](const ghoul::filesystem::File& f, float progress) { progressCallback(f, progress); }
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user