Swap tool auto downloader finished, browse finished, and ui updates

This commit is contained in:
twiddle 2024-05-22 13:55:51 -04:00
parent 435a75d453
commit e6aac4eb25
3 changed files with 77 additions and 100 deletions

View file

@ -9,10 +9,10 @@
#include <stdio.h>
#include <archive.h>
#include <zip.h>
#include <zlib.h>
#include <archive_entry.h>
#include "utils/AppData.h"
#include <archive_entry.h>
#include <QFileDialog>
#include "utils/config.h"
#include "utils/Networking.h"
@ -22,10 +22,28 @@ AtomicConfigDialog::AtomicConfigDialog(QWidget *parent)
{
ui->setupUi(this);
this->fillListWidgets();
connect(ui->btn_autoInstall,&QPushButton::clicked, this, &AtomicConfigDialog::downloadBinary);
connect(ui->btn_selectFile,&QPushButton::clicked, this, &AtomicConfigDialog::selectBinary);
ui->downloadLabel->setVisible(false);
connect(ui->btn_autoInstall,&QPushButton::clicked, this, [this] {
/*
QMessageBox downloadPopup = QMessageBox(this);
qDebug() << "opening popup";
downloadPopup.setText("Downloading swap tool, this usually takes about a minute or two, please wait");
downloadPopup.setWindowTitle("Swap tool download");
downloadPopup.show();
qApp->processEvents();
*/
AtomicConfigDialog::downloadBinary();
});
connect(ui->btn_selectFile,&QPushButton::clicked, this, [this] {
QString path = QFileDialog::getOpenFileName(this, "Select swap binary file",
Config::defaultConfigDir().absolutePath(),
"Binary Executable (*)");
Config::instance()->set(Config::swapPath, path);
if(path.isEmpty()){
return;
}
close();
});
connect(ui->buttonBox, &QDialogButtonBox::accepted, [this]{
this->accept();
});
@ -33,56 +51,6 @@ AtomicConfigDialog::AtomicConfigDialog(QWidget *parent)
this->adjustSize();
}
void AtomicConfigDialog::setCheckState(QListWidget *widget, Qt::CheckState checkState) {
QListWidgetItem *item;
for (int i=0; i < widget->count(); i++) {
item = widget->item(i);
item->setCheckState(checkState);
}
}
QStringList AtomicConfigDialog::getChecked(QListWidget *widget) {
QStringList checked;
QListWidgetItem *item;
for (int i=0; i < widget->count(); i++) {
item = widget->item(i);
if (item->checkState() == Qt::Checked) {
checked.append(item->text());
}
}
return checked;
}
void AtomicConfigDialog::fillListWidgets() {
QStringList cryptoCurrencies = appData()->prices.markets.keys();
QStringList fiatCurrencies = appData()->prices.rates.keys();
QStringList checkedCryptoCurrencies = conf()->get(Config::cryptoSymbols).toStringList();
QStringList checkedFiatCurrencies = conf()->get(Config::fiatSymbols).toStringList();
auto setChecked = [](QListWidget *widget, const QStringList &checked){
QListWidgetItem *item;
for (int i=0; i < widget->count(); i++) {
item = widget->item(i);
item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
if (checked.contains(item->text())) {
item->setCheckState(Qt::Checked);
} else {
item->setCheckState(Qt::Unchecked);
}
}
};
}
void AtomicConfigDialog::downloadBinary() {
auto* network = new Networking(this);
download = new QTemporaryFile(this);
@ -98,9 +66,11 @@ void AtomicConfigDialog::downloadBinary() {
} else {
url = QString("https://github.com/comit-network/xmr-btc-swap/releases/download/0.12.3/swap_0.12.3_Darwin_x86_64.tar");
}
archive = network->get(this, url);
ui->downloadLabel->setVisible(true);
QStringList answer;
connect(archive,&QNetworkReply::readyRead, this, [&]{
connect(archive,&QNetworkReply::readyRead, this, [this]{
QByteArray data= archive->readAll();
qDebug() << "received data of size: " << data.size();
download->write(data.constData(), data.size());
@ -111,7 +81,7 @@ void AtomicConfigDialog::downloadBinary() {
void AtomicConfigDialog::extract() {
ui->downloadLabel->setText("Download Successful, extracting binary to final destination");
qDebug() << "extracting";
download->close();
archive->deleteLater();
@ -179,6 +149,8 @@ void AtomicConfigDialog::extract() {
}
qDebug() << "Finished";
binaryFile.close();
ui->downloadLabel->setText("Swap tool installation complete, Atomic swaps are ready !");
};
int
@ -205,7 +177,5 @@ AtomicConfigDialog::copy_data(struct archive *ar, struct archive *aw)
}
}
}
void AtomicConfigDialog::selectBinary() {
};
AtomicConfigDialog::~AtomicConfigDialog() = default;

View file

@ -28,11 +28,7 @@ public slots:
void extract();
private:
void setCheckState(QListWidget *widget, Qt::CheckState checkState);
QStringList getChecked(QListWidget *widget);
void fillListWidgets();
void downloadBinary();
void selectBinary();
int copy_data(struct archive *ar, struct archive *aw);
QScopedPointer<Ui::AtomicConfigDialog> ui;

View file

@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>509</width>
<width>514</width>
<height>574</height>
</rect>
</property>
@ -17,10 +17,12 @@
<item>
<widget class="Line" name="line">
<property name="orientation">
<enum>Qt::Vertical</enum>
<enum>Qt::Orientation::Vertical</enum>
</property>
</widget>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
@ -40,7 +42,7 @@
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<enum>Qt::Orientation::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
@ -53,10 +55,19 @@
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<enum>Qt::Orientation::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
<set>QDialogButtonBox::StandardButton::Close</set>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QLabel" name="downloadLabel">
<property name="text">
<string>Downloading swap tool ... this usually takes await cause of tor routing</string>
</property>
</widget>
</item>