mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
fix DownloadDialog behavior
The DownloadDialog behavior was broken in a way it allows the user to make changes on the dialog while the download is happening. Also, clicking on "Cancel" breaks/hangs the UI sometimes, as libdivingcomputer doesn't always cancels the download right away. That's a bug that still needs to be fixed. Signed-off-by: Danilo Cesar Lemes de Paula <danilo.eu@gmail.com>
This commit is contained in:
parent
db44045cfe
commit
ab649e21ba
2 changed files with 49 additions and 2 deletions
|
@ -65,7 +65,11 @@ DownloadFromDCWidget::DownloadFromDCWidget(QWidget* parent, Qt::WindowFlags f) :
|
||||||
|
|
||||||
void DownloadFromDCWidget::runDialog()
|
void DownloadFromDCWidget::runDialog()
|
||||||
{
|
{
|
||||||
|
// Since the DownloadDialog is only
|
||||||
|
// created once, we need to do put some starting code here
|
||||||
ui->progressBar->hide();
|
ui->progressBar->hide();
|
||||||
|
markChildrenAsEnabled();
|
||||||
|
|
||||||
exec();
|
exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -138,7 +142,11 @@ void DownloadFromDCWidget::on_cancel_clicked()
|
||||||
thread->deleteLater();
|
thread->deleteLater();
|
||||||
thread = 0;
|
thread = 0;
|
||||||
}
|
}
|
||||||
close();
|
|
||||||
|
// Confusing, but if the user press cancel during a download
|
||||||
|
// he probably want to cancel the download, not to close the window.
|
||||||
|
if (!downloading)
|
||||||
|
close();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DownloadFromDCWidget::on_ok_clicked()
|
void DownloadFromDCWidget::on_ok_clicked()
|
||||||
|
@ -146,6 +154,7 @@ void DownloadFromDCWidget::on_ok_clicked()
|
||||||
if (downloading)
|
if (downloading)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
markChildrenAsDisabled();
|
||||||
ui->progressBar->setValue(0);
|
ui->progressBar->setValue(0);
|
||||||
ui->progressBar->show();
|
ui->progressBar->show();
|
||||||
|
|
||||||
|
@ -156,6 +165,7 @@ void DownloadFromDCWidget::on_ok_clicked()
|
||||||
data.devname = strdup(ui->device->text().toUtf8().data());
|
data.devname = strdup(ui->device->text().toUtf8().data());
|
||||||
data.vendor = strdup(ui->vendor->currentText().toUtf8().data());
|
data.vendor = strdup(ui->vendor->currentText().toUtf8().data());
|
||||||
data.product = strdup(ui->product->currentText().toUtf8().data());
|
data.product = strdup(ui->product->currentText().toUtf8().data());
|
||||||
|
|
||||||
data.descriptor = descriptorLookup[ui->vendor->currentText() + ui->product->currentText()];
|
data.descriptor = descriptorLookup[ui->vendor->currentText() + ui->product->currentText()];
|
||||||
data.force_download = ui->forceDownload->isChecked();
|
data.force_download = ui->forceDownload->isChecked();
|
||||||
data.deviceid = data.diveid = 0;
|
data.deviceid = data.diveid = 0;
|
||||||
|
@ -177,6 +187,36 @@ bool DownloadFromDCWidget::preferDownloaded()
|
||||||
return ui->preferDownloaded->isChecked();
|
return ui->preferDownloaded->isChecked();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DownloadFromDCWidget::reject()
|
||||||
|
{
|
||||||
|
// we don't want the download window being able to close
|
||||||
|
// while we're still downloading.
|
||||||
|
if (!downloading)
|
||||||
|
QDialog::reject();
|
||||||
|
}
|
||||||
|
|
||||||
|
void DownloadFromDCWidget::markChildrenAsDisabled()
|
||||||
|
{
|
||||||
|
ui->device->setDisabled(true);
|
||||||
|
ui->vendor->setDisabled(true);
|
||||||
|
ui->product->setDisabled(true);
|
||||||
|
ui->forceDownload->setDisabled(true);
|
||||||
|
ui->preferDownloaded->setDisabled(true);
|
||||||
|
ui->ok->setDisabled(true);
|
||||||
|
ui->search->setDisabled(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DownloadFromDCWidget::markChildrenAsEnabled()
|
||||||
|
{
|
||||||
|
ui->device->setDisabled(false);
|
||||||
|
ui->vendor->setDisabled(false);
|
||||||
|
ui->product->setDisabled(false);
|
||||||
|
ui->forceDownload->setDisabled(false);
|
||||||
|
ui->preferDownloaded->setDisabled(false);
|
||||||
|
ui->ok->setDisabled(false);
|
||||||
|
ui->search->setDisabled(false);
|
||||||
|
}
|
||||||
|
|
||||||
DownloadThread::DownloadThread(device_data_t* data): data(data)
|
DownloadThread::DownloadThread(device_data_t* data): data(data)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,7 @@ private:
|
||||||
class InterfaceThread : public QThread{
|
class InterfaceThread : public QThread{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
InterfaceThread(QObject *parent, device_data_t *data) ;
|
InterfaceThread(QObject *parent, device_data_t *data);
|
||||||
virtual void run();
|
virtual void run();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
@ -39,13 +39,19 @@ class DownloadFromDCWidget : public QDialog{
|
||||||
public:
|
public:
|
||||||
explicit DownloadFromDCWidget(QWidget* parent = 0, Qt::WindowFlags f = 0);
|
explicit DownloadFromDCWidget(QWidget* parent = 0, Qt::WindowFlags f = 0);
|
||||||
static DownloadFromDCWidget *instance();
|
static DownloadFromDCWidget *instance();
|
||||||
|
void reject();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void on_ok_clicked();
|
void on_ok_clicked();
|
||||||
void on_cancel_clicked();
|
void on_cancel_clicked();
|
||||||
void runDialog();
|
void runDialog();
|
||||||
void stoppedDownloading();
|
void stoppedDownloading();
|
||||||
void on_vendor_currentIndexChanged(const QString& vendor);
|
void on_vendor_currentIndexChanged(const QString& vendor);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void markChildrenAsDisabled();
|
||||||
|
void markChildrenAsEnabled();
|
||||||
|
|
||||||
Ui::DownloadFromDiveComputer *ui;
|
Ui::DownloadFromDiveComputer *ui;
|
||||||
InterfaceThread *thread;
|
InterfaceThread *thread;
|
||||||
bool downloading;
|
bool downloading;
|
||||||
|
@ -58,6 +64,7 @@ private:
|
||||||
QStringListModel *vendorModel;
|
QStringListModel *vendorModel;
|
||||||
QStringListModel *productModel;
|
QStringListModel *productModel;
|
||||||
void fill_computer_list();
|
void fill_computer_list();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
bool preferDownloaded();
|
bool preferDownloaded();
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Reference in a new issue