summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTannin <sherb@gmx.net>2015-10-10 19:35:18 +0200
committerTannin <sherb@gmx.net>2015-10-10 19:35:18 +0200
commit90d87a0cf75be44da34c3c3282f82e5b3a399168 (patch)
tree8fd5a7c6fa519d2b40e66bcddde747f72b920d70
parent115315df2809fb66eb5b18b85f089da457ccc19b (diff)
fixed progress dialogs appearing on startup
Appears to be a new bug in qt or maybe incompatibility with Windows 10: All Progress dialogs were made visibly automatically a few seconds after application startup. This was "fixed" by creating the dialog dynamically on demand
-rw-r--r--src/installationmanager.cpp83
-rw-r--r--src/installationmanager.h2
-rw-r--r--src/nxmaccessmanager.cpp18
-rw-r--r--src/nxmaccessmanager.h2
-rw-r--r--src/selfupdater.cpp40
-rw-r--r--src/selfupdater.h8
6 files changed, 90 insertions, 63 deletions
diff --git a/src/installationmanager.cpp b/src/installationmanager.cpp
index 75abd750..a6af1a7f 100644
--- a/src/installationmanager.cpp
+++ b/src/installationmanager.cpp
@@ -34,6 +34,7 @@ along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>.
#include <installationtester.h>
#include <gameinfo.h>
#include <utility.h>
+#include <scopeguard.h>
#include <QFileInfo>
#include <QLibrary>
#include <QInputDialog>
@@ -71,7 +72,6 @@ static T resolveFunction(QLibrary &lib, const char *name)
InstallationManager::InstallationManager()
: m_ParentWidget(nullptr)
- , m_InstallationProgress(nullptr)
, m_SupportedExtensions({ "zip", "rar", "7z", "fomod", "001" })
{
QLibrary archiveLib("dlls\\archive.dll");
@@ -85,8 +85,6 @@ InstallationManager::InstallationManager()
if (!m_CurrentArchive->isValid()) {
throw MyException(getErrorString(m_CurrentArchive->getLastError()));
}
-
- m_InstallationProgress.setWindowFlags(m_InstallationProgress.windowFlags() & (~Qt::WindowContextHelpButtonHint));
}
@@ -97,7 +95,6 @@ InstallationManager::~InstallationManager()
void InstallationManager::setParentWidget(QWidget *widget)
{
- m_InstallationProgress.setParent(widget, Qt::Dialog);
for (IPluginInstaller *installer : m_Installers) {
installer->setParentWidget(widget);
}
@@ -171,19 +168,24 @@ bool InstallationManager::unpackSingleFile(const QString &fileName)
return false;
}
- m_InstallationProgress.setWindowTitle(tr("Extracting files"));
- m_InstallationProgress.setLabelText(QString());
- m_InstallationProgress.setValue(0);
- m_InstallationProgress.setWindowModality(Qt::WindowModal);
- m_InstallationProgress.show();
+ m_InstallationProgress = new QProgressDialog(m_ParentWidget);
+ ON_BLOCK_EXIT([this] () {
+ m_InstallationProgress->hide();
+ m_InstallationProgress->deleteLater();
+ m_InstallationProgress = nullptr;
+ });
+ m_InstallationProgress->setWindowFlags(
+ m_InstallationProgress->windowFlags() & ~Qt::WindowContextHelpButtonHint);
+
+ m_InstallationProgress->setWindowTitle(tr("Extracting files"));
+ m_InstallationProgress->setWindowModality(Qt::WindowModal);
+ m_InstallationProgress->show();
bool res = m_CurrentArchive->extract(ToWString(QDir::toNativeSeparators(QDir::tempPath())).c_str(),
new MethodCallback<InstallationManager, void, float>(this, &InstallationManager::updateProgress),
new MethodCallback<InstallationManager, void, LPCWSTR>(this, &InstallationManager::dummyProgressFile),
new MethodCallback<InstallationManager, void, LPCWSTR>(this, &InstallationManager::report7ZipError));
- m_InstallationProgress.hide();
-
return res;
}
@@ -191,7 +193,7 @@ bool InstallationManager::unpackSingleFile(const QString &fileName)
QString InstallationManager::extractFile(const QString &fileName)
{
if (unpackSingleFile(fileName)) {
- return QDir::tempPath().append("/").append(QFileInfo(fileName).fileName());
+ return QDir::tempPath() + "/" + QFileInfo(fileName).fileName();
} else {
return QString();
}
@@ -215,7 +217,7 @@ QStringList InstallationManager::extractFiles(const QStringList &filesOrig, bool
{
QStringList files;
- foreach (const QString &file, filesOrig) {
+ for (const QString &file : filesOrig) {
files.append(canonicalize(file));
}
@@ -249,22 +251,26 @@ QStringList InstallationManager::extractFiles(const QStringList &filesOrig, bool
}
}
- m_InstallationProgress.setWindowTitle(tr("Extracting files"));
- m_InstallationProgress.setLabelText(QString());
- m_InstallationProgress.setValue(0);
- m_InstallationProgress.setWindowModality(Qt::WindowModal);
- m_InstallationProgress.show();
+ m_InstallationProgress = new QProgressDialog(m_ParentWidget);
+ ON_BLOCK_EXIT([this] () {
+ m_InstallationProgress->hide();
+ m_InstallationProgress->deleteLater();
+ m_InstallationProgress = nullptr;
+ });
+ m_InstallationProgress->setWindowFlags(
+ m_InstallationProgress->windowFlags() & (~Qt::WindowContextHelpButtonHint));
+ m_InstallationProgress->setWindowTitle(tr("Extracting files"));
+ m_InstallationProgress->setWindowModality(Qt::WindowModal);
+ m_InstallationProgress->show();
// unpack only the files we need for the installer
if (!m_CurrentArchive->extract(ToWString(QDir::toNativeSeparators(QDir::tempPath())).c_str(),
new MethodCallback<InstallationManager, void, float>(this, &InstallationManager::updateProgress),
new MethodCallback<InstallationManager, void, LPCWSTR>(this, &InstallationManager::dummyProgressFile),
new MethodCallback<InstallationManager, void, LPCWSTR>(this, &InstallationManager::report7ZipError))) {
- m_InstallationProgress.hide();
throw MyException(QString("extracting failed (%1)").arg(m_CurrentArchive->getLastError()));
}
- m_InstallationProgress.hide();
return result;
}
@@ -387,21 +393,21 @@ DirectoryTree::Node *InstallationManager::getSimpleArchiveBase(DirectoryTree *da
void InstallationManager::updateProgress(float percentage)
{
- m_InstallationProgress.setValue(static_cast<int>(percentage * 100.0));
- if (m_InstallationProgress.wasCanceled()) {
- m_CurrentArchive->cancel();
- m_InstallationProgress.reset();
+ if (m_InstallationProgress != nullptr) {
+ m_InstallationProgress->setValue(static_cast<int>(percentage * 100.0));
+ if (m_InstallationProgress->wasCanceled()) {
+ m_CurrentArchive->cancel();
+ m_InstallationProgress->reset();
+ }
}
}
void InstallationManager::updateProgressFile(LPCWSTR fileName)
{
-#if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
- m_InstallationProgress.setLabelText(QString::fromWCharArray(fileName));
-#else
- m_InstallationProgress.setLabelText(QString::fromUtf16(fileName));
-#endif
+ if (m_InstallationProgress != nullptr) {
+ m_InstallationProgress->setLabelText(QString::fromWCharArray(fileName));
+ }
}
@@ -533,16 +539,21 @@ bool InstallationManager::doInstall(GuessedValue<QString> &modName, int modID,
qDebug("installing to \"%s\"", targetDirectoryNative.toUtf8().constData());
- m_InstallationProgress.setWindowTitle(tr("Extracting files"));
- m_InstallationProgress.setLabelText(QString());
- m_InstallationProgress.setValue(0);
- m_InstallationProgress.setWindowModality(Qt::WindowModal);
- m_InstallationProgress.show();
+ m_InstallationProgress = new QProgressDialog(m_ParentWidget);
+ ON_BLOCK_EXIT([this] () {
+ m_InstallationProgress->hide();
+ m_InstallationProgress->deleteLater();
+ m_InstallationProgress = nullptr;
+ });
+
+ m_InstallationProgress->setWindowFlags(
+ m_InstallationProgress->windowFlags() & (~Qt::WindowContextHelpButtonHint));
+ m_InstallationProgress->setWindowModality(Qt::WindowModal);
+ m_InstallationProgress->show();
if (!m_CurrentArchive->extract(ToWString("\\\\?\\" + targetDirectoryNative).c_str(),
new MethodCallback<InstallationManager, void, float>(this, &InstallationManager::updateProgress),
new MethodCallback<InstallationManager, void, LPCWSTR>(this, &InstallationManager::updateProgressFile),
new MethodCallback<InstallationManager, void, LPCWSTR>(this, &InstallationManager::report7ZipError))) {
- m_InstallationProgress.hide();
if (m_CurrentArchive->getLastError() == Archive::ERROR_EXTRACT_CANCELLED) {
return false;
} else {
@@ -550,8 +561,6 @@ bool InstallationManager::doInstall(GuessedValue<QString> &modName, int modID,
}
}
- m_InstallationProgress.hide();
-
QSettings settingsFile(targetDirectory + "/meta.ini", QSettings::IniFormat);
// overwrite settings only if they are actually are available or haven't been set before
diff --git a/src/installationmanager.h b/src/installationmanager.h
index d4b4f7dc..111b41f5 100644
--- a/src/installationmanager.h
+++ b/src/installationmanager.h
@@ -208,7 +208,7 @@ private:
Archive *m_CurrentArchive;
QString m_CurrentFile;
- QProgressDialog m_InstallationProgress;
+ QProgressDialog *m_InstallationProgress { nullptr };
std::set<QString> m_TempFilesToDelete;
diff --git a/src/nxmaccessmanager.cpp b/src/nxmaccessmanager.cpp
index 07a75910..0763bb71 100644
--- a/src/nxmaccessmanager.cpp
+++ b/src/nxmaccessmanager.cpp
@@ -52,7 +52,6 @@ const std::set<int> NXMAccessManager::s_PremiumAccountStates { 4, 6, 13, 27, 31,
NXMAccessManager::NXMAccessManager(QObject *parent, const QString &moVersion)
: QNetworkAccessManager(parent)
, m_LoginReply(nullptr)
- , m_ProgressDialog()
, m_MOVersion(moVersion)
{
m_LoginTimeout.setSingleShot(true);
@@ -239,10 +238,11 @@ void NXMAccessManager::pageLogin()
request.setRawHeader("User-Agent", userAgent().toUtf8());
- m_ProgressDialog.setLabelText(tr("Logging into Nexus"));
- QList<QPushButton*> buttons = m_ProgressDialog.findChildren<QPushButton*>();
+ m_ProgressDialog = new QProgressDialog(nullptr);
+ m_ProgressDialog->setLabelText(tr("Logging into Nexus"));
+ QList<QPushButton*> buttons = m_ProgressDialog->findChildren<QPushButton*>();
buttons.at(0)->setEnabled(false);
- m_ProgressDialog.show();
+ m_ProgressDialog->show();
QCoreApplication::processEvents(); // for some reason the whole app hangs during the login. This way the user has at least a little feedback
m_LoginReply = post(request, postDataQuery);
@@ -269,7 +269,10 @@ void NXMAccessManager::loginTimeout()
void NXMAccessManager::loginError(QNetworkReply::NetworkError)
{
qDebug("login error");
- m_ProgressDialog.hide();
+ if (m_ProgressDialog != nullptr) {
+ m_ProgressDialog->deleteLater();
+ m_ProgressDialog = nullptr;
+ }
m_Username.clear();
m_Password.clear();
m_LoginState = LOGIN_NOT_VALID;
@@ -300,7 +303,10 @@ bool NXMAccessManager::hasLoginCookies() const
void NXMAccessManager::loginFinished()
{
- m_ProgressDialog.hide();
+ if (m_ProgressDialog != nullptr) {
+ m_ProgressDialog->deleteLater();
+ m_ProgressDialog = nullptr;
+ }
m_LoginReply->deleteLater();
m_LoginReply = nullptr;
diff --git a/src/nxmaccessmanager.h b/src/nxmaccessmanager.h
index 2b615cdc..a03dbe36 100644
--- a/src/nxmaccessmanager.h
+++ b/src/nxmaccessmanager.h
@@ -109,7 +109,7 @@ private:
QTimer m_LoginTimeout;
QNetworkReply *m_LoginReply;
- QProgressDialog m_ProgressDialog;
+ QProgressDialog *m_ProgressDialog { nullptr };
QString m_MOVersion;
QString m_NMMVersion;
diff --git a/src/selfupdater.cpp b/src/selfupdater.cpp
index ed34bfc2..bcf81cfd 100644
--- a/src/selfupdater.cpp
+++ b/src/selfupdater.cpp
@@ -61,11 +61,8 @@ SelfUpdater::SelfUpdater(NexusInterface *nexusInterface)
, m_Interface(nexusInterface)
, m_UpdateRequestID(-1)
, m_Reply(nullptr)
- , m_Progress(nullptr)
, m_Attempts(3)
{
- m_Progress.setMaximum(100);
-
QLibrary archiveLib("dlls\\archive.dll");
if (!archiveLib.load()) {
throw MyException(tr("archive.dll not loaded: \"%1\"").arg(archiveLib.errorString()));
@@ -78,7 +75,7 @@ SelfUpdater::SelfUpdater(NexusInterface *nexusInterface)
throw MyException(InstallationManager::getErrorString(m_CurrentArchive->getLastError()));
}
- connect(&m_Progress, SIGNAL(canceled()), this, SLOT(downloadCancel()));
+ connect(m_Progress, SIGNAL(canceled()), this, SLOT(downloadCancel()));
VS_FIXEDFILEINFO version = GetFileVersion(ToWString(QApplication::applicationFilePath()));
@@ -136,12 +133,23 @@ void SelfUpdater::startUpdate()
void SelfUpdater::showProgress()
{
- m_Progress.setModal(true);
- m_Progress.setParent(m_Parent, Qt::Dialog);
- m_Progress.show();
- m_Progress.setValue(0);
- m_Progress.setWindowTitle(tr("Update"));
- m_Progress.setLabelText(tr("Download in progress"));
+ if (m_Progress == nullptr) {
+ m_Progress = new QProgressDialog(m_Parent, Qt::Dialog);
+ }
+ m_Progress->setModal(true);
+ m_Progress->show();
+ m_Progress->setValue(0);
+ m_Progress->setWindowTitle(tr("Update"));
+ m_Progress->setLabelText(tr("Download in progress"));
+}
+
+void SelfUpdater::closeProgress()
+{
+ if (m_Progress != nullptr) {
+ m_Progress->hide();
+ m_Progress->deleteLater();
+ m_Progress = nullptr;
+ }
}
void SelfUpdater::download(const QString &downloadLink, const QString &fileName)
@@ -168,7 +176,9 @@ void SelfUpdater::downloadProgress(qint64 bytesReceived, qint64 bytesTotal)
m_Reply->abort();
} else {
if (bytesTotal != 0) {
- m_Progress.setValue((bytesReceived * 100) / bytesTotal);
+ if (m_Progress != nullptr) {
+ m_Progress->setValue((bytesReceived * 100) / bytesTotal);
+ }
}
}
}
@@ -196,7 +206,8 @@ void SelfUpdater::downloadFinished()
m_Canceled = true;
}
- m_Progress.hide();
+ closeProgress();
+
m_Reply->close();
m_Reply->deleteLater();
m_Reply = nullptr;
@@ -439,7 +450,7 @@ void SelfUpdater::nxmFilesAvailable(int, QVariant userData, QVariant resultData,
} else {
qCritical("no file for update found");
MessageDialog::showMessage(tr("no file for update found. Please update manually."), m_Parent);
- m_Progress.hide();
+ closeProgress();
}
}
@@ -474,8 +485,7 @@ void SelfUpdater::nxmDownloadURLsAvailable(int, int, QVariant userData, QVariant
download(dlServer["URI"].toString(), userData.toString());
} else {
MessageDialog::showMessage(tr("No download server available. Please try again later."), m_Parent);
- m_Progress.hide();
+ closeProgress();
}
}
}
-
diff --git a/src/selfupdater.h b/src/selfupdater.h
index b5bbc406..143b05cb 100644
--- a/src/selfupdater.h
+++ b/src/selfupdater.h
@@ -32,6 +32,7 @@ along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>.
class NexusInterface;
+
/**
* @brief manages updates for Mod Organizer itself
* This class is used to update the Mod Organizer
@@ -39,7 +40,7 @@ class NexusInterface;
* 1. call testForUpdate() to determine is available
* 2. if the updateAvailable() signal is received, allow the user to start the update
* 3. if the user start the update, call startUpdate()
- * 4. startUpdate() will first query a list of files, try to determine if there is an
+ * 4. startUpdate() will first query a list of files, try to determine if there is an
* incremental update. If not, the user will have to confirm the download of a full download.
* Once the correct file is selected, it is downloaded.
* 5. before the downloaded file is extracted, existing files that are going to be replaced are
@@ -48,7 +49,7 @@ class NexusInterface;
* 7. finally, a restart is requested via signal.
* 8. at restart, Mod Organizer will remove the update_backup directory since none of the files
* should now be open
- *
+ *
* @todo use NexusBridge
**/
class SelfUpdater : public QObject
@@ -121,6 +122,7 @@ private:
void report7ZipError(LPCWSTR errorMessage);
QString retrieveNews(const QString &description);
void showProgress();
+ void closeProgress();
private slots:
@@ -138,7 +140,7 @@ private:
QString m_NewestVersion;
QFile m_UpdateFile;
QNetworkReply *m_Reply;
- QProgressDialog m_Progress;
+ QProgressDialog *m_Progress { nullptr };
bool m_Canceled;
int m_Attempts;