summaryrefslogtreecommitdiffstats
path: root/application/dialogs
diff options
context:
space:
mode:
authorPetr Mrázek <peterix@gmail.com>2015-05-02 23:42:33 +0200
committerPetr Mrázek <peterix@gmail.com>2015-05-02 23:42:33 +0200
commit5779ffd6645ba3fae5abe068d456fc1ee9dd91ff (patch)
treebe5d81b6132b63db368e7061d766f70250fa222c /application/dialogs
parent4fc4a172562a76091721b8c488aafbd6ed2b01ed (diff)
downloadMultiMC-5779ffd6645ba3fae5abe068d456fc1ee9dd91ff.tar
MultiMC-5779ffd6645ba3fae5abe068d456fc1ee9dd91ff.tar.gz
MultiMC-5779ffd6645ba3fae5abe068d456fc1ee9dd91ff.tar.lz
MultiMC-5779ffd6645ba3fae5abe068d456fc1ee9dd91ff.tar.xz
MultiMC-5779ffd6645ba3fae5abe068d456fc1ee9dd91ff.zip
GH-922 improve version select dialogs
Diffstat (limited to 'application/dialogs')
-rw-r--r--application/dialogs/CopyInstanceDialog.cpp2
-rw-r--r--application/dialogs/VersionSelectDialog.cpp88
-rw-r--r--application/dialogs/VersionSelectDialog.h21
-rw-r--r--application/dialogs/VersionSelectDialog.ui10
4 files changed, 107 insertions, 14 deletions
diff --git a/application/dialogs/CopyInstanceDialog.cpp b/application/dialogs/CopyInstanceDialog.cpp
index 7c98978b..5b8e3096 100644
--- a/application/dialogs/CopyInstanceDialog.cpp
+++ b/application/dialogs/CopyInstanceDialog.cpp
@@ -21,8 +21,6 @@
#include "ui_CopyInstanceDialog.h"
#include "Platform.h"
-#include "dialogs/VersionSelectDialog.h"
-#include "dialogs/ProgressDialog.h"
#include "dialogs/IconPickerDialog.h"
#include "BaseVersion.h"
diff --git a/application/dialogs/VersionSelectDialog.cpp b/application/dialogs/VersionSelectDialog.cpp
index 354857e7..57514fe7 100644
--- a/application/dialogs/VersionSelectDialog.cpp
+++ b/application/dialogs/VersionSelectDialog.cpp
@@ -19,6 +19,7 @@
#include <QHeaderView>
#include <dialogs/ProgressDialog.h>
+#include "CustomMessageBox.h"
#include "Platform.h"
#include <BaseVersion.h>
@@ -46,6 +47,7 @@ VersionSelectDialog::VersionSelectDialog(BaseVersionList *vlist, QString title,
ui->listView->setModel(m_proxyModel);
ui->listView->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
ui->listView->header()->setSectionResizeMode(resizeOnColumn, QHeaderView::Stretch);
+ ui->sneakyProgressBar->setHidden(true);
if (!cancelable)
{
@@ -58,6 +60,11 @@ void VersionSelectDialog::setEmptyString(QString emptyString)
ui->listView->setEmptyString(emptyString);
}
+void VersionSelectDialog::setEmptyErrorString(QString emptyErrorString)
+{
+ ui->listView->setEmptyErrorString(emptyErrorString);
+}
+
VersionSelectDialog::~VersionSelectDialog()
{
delete ui;
@@ -77,26 +84,89 @@ int VersionSelectDialog::exec()
{
loadList();
}
- auto idx = m_proxyModel->getRecommended();
- if(idx.isValid())
+ else
{
- ui->listView->selectionModel()->setCurrentIndex(idx,QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows);
- ui->listView->scrollTo(idx, QAbstractItemView::PositionAtCenter);
+ if (m_proxyModel->rowCount() == 0)
+ {
+ ui->listView->setEmptyMode(VersionListView::String);
+ }
+ preselect();
}
return QDialog::exec();
}
+void VersionSelectDialog::closeEvent(QCloseEvent * event)
+{
+ if(loadTask)
+ {
+ loadTask->abort();
+ loadTask->deleteLater();
+ loadTask = nullptr;
+ }
+ QDialog::closeEvent(event);
+}
+
void VersionSelectDialog::loadList()
{
- Task *loadTask = m_vlist->getLoadTask();
+ if(loadTask)
+ {
+ return;
+ }
+ loadTask = m_vlist->getLoadTask();
if (!loadTask)
{
return;
}
- ProgressDialog *taskDlg = new ProgressDialog(this);
- loadTask->setParent(taskDlg);
- taskDlg->exec(loadTask);
- delete taskDlg;
+ connect(loadTask, &Task::finished, this, &VersionSelectDialog::onTaskFinished);
+ connect(loadTask, &Task::progress, this, &VersionSelectDialog::changeProgress);
+ loadTask->start();
+ ui->sneakyProgressBar->setHidden(false);
+}
+
+void VersionSelectDialog::onTaskFinished()
+{
+ if (!loadTask->successful())
+ {
+ CustomMessageBox::selectable(this, tr("Error"),
+ tr("List update failed:\n%1").arg(loadTask->failReason()),
+ QMessageBox::Warning)->show();
+ if (m_proxyModel->rowCount() == 0)
+ {
+ ui->listView->setEmptyMode(VersionListView::ErrorString);
+ }
+ }
+ else if (m_proxyModel->rowCount() == 0)
+ {
+ ui->listView->setEmptyMode(VersionListView::String);
+ }
+ ui->sneakyProgressBar->setHidden(true);
+ loadTask->deleteLater();
+ loadTask = nullptr;
+ preselect();
+}
+
+void VersionSelectDialog::changeProgress(qint64 current, qint64 total)
+{
+ ui->sneakyProgressBar->setMaximum(total);
+ ui->sneakyProgressBar->setValue(current);
+}
+
+void VersionSelectDialog::preselect()
+{
+ if(preselectedAlready)
+ return;
+ preselectedAlready = true;
+ selectRecommended();
+}
+
+void VersionSelectDialog::selectRecommended()
+{
+ auto idx = m_proxyModel->getRecommended();
+ if(idx.isValid())
+ {
+ ui->listView->selectionModel()->setCurrentIndex(idx,QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows);
+ ui->listView->scrollTo(idx, QAbstractItemView::PositionAtCenter);
+ }
}
BaseVersionPtr VersionSelectDialog::selectedVersion() const
diff --git a/application/dialogs/VersionSelectDialog.h b/application/dialogs/VersionSelectDialog.h
index 23bd158a..6b83535e 100644
--- a/application/dialogs/VersionSelectDialog.h
+++ b/application/dialogs/VersionSelectDialog.h
@@ -46,19 +46,34 @@ public:
void setFuzzyFilter(BaseVersionList::ModelRoles role, QString filter);
void setExactFilter(BaseVersionList::ModelRoles role, QString filter);
void setEmptyString(QString emptyString);
+ void setEmptyErrorString(QString emptyErrorString);
void setResizeOn(int column);
void setUseLatest(const bool useLatest);
+protected:
+ virtual void closeEvent ( QCloseEvent* );
+
private
slots:
void on_refreshButton_clicked();
+ void onTaskFinished();
+ void changeProgress(qint64 current, qint64 total);
+
+private:
+ void preselect();
+ void selectRecommended();
+
private:
- Ui::VersionSelectDialog *ui;
+ Ui::VersionSelectDialog *ui = nullptr;
- BaseVersionList *m_vlist;
+ BaseVersionList *m_vlist = nullptr;
- VersionProxyModel *m_proxyModel;
+ VersionProxyModel *m_proxyModel = nullptr;
int resizeOnColumn = 0;
+
+ Task * loadTask = nullptr;
+
+ bool preselectedAlready = false;
};
diff --git a/application/dialogs/VersionSelectDialog.ui b/application/dialogs/VersionSelectDialog.ui
index e4014e11..420e853d 100644
--- a/application/dialogs/VersionSelectDialog.ui
+++ b/application/dialogs/VersionSelectDialog.ui
@@ -40,6 +40,16 @@
</widget>
</item>
<item>
+ <widget class="QProgressBar" name="sneakyProgressBar">
+ <property name="value">
+ <number>24</number>
+ </property>
+ <property name="format">
+ <string notr="true">%p%</string>
+ </property>
+ </widget>
+ </item>
+ <item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QPushButton" name="refreshButton">