From 04ce71a9f32e8837d2904d0892d18dcb95fda5d3 Mon Sep 17 00:00:00 2001 From: codestation Date: Thu, 16 Jan 2014 21:38:05 -0430 Subject: [PATCH] Delay the progress dialog by one second so it doesn't show on quick scans. Do not show the disconnect message if no connection is established. Show correct directory separators on Windows. --- src/clientmanager.cpp | 3 ++- src/cmaclient.cpp | 12 ++++++++++++ src/cmaclient.h | 1 + src/forms/configwidget.cpp | 14 +++++++------- src/forms/progressform.cpp | 13 +++++++++++++ src/forms/progressform.h | 6 ++++++ src/mainwidget.cpp | 4 +++- 7 files changed, 44 insertions(+), 9 deletions(-) diff --git a/src/clientmanager.cpp b/src/clientmanager.cpp index 2e42396..3b2e6b5 100644 --- a/src/clientmanager.cpp +++ b/src/clientmanager.cpp @@ -38,6 +38,7 @@ ClientManager::~ClientManager() void ClientManager::databaseUpdated(int count) { + progress.interruptShow(); progress.hide(); if(count >= 0) { emit messageSent(tr("Added %1 items to the database").arg(count)); @@ -130,7 +131,7 @@ void ClientManager::refreshDatabase() emit messageSent(tr("No PS Vita system has been registered")); } } else { - progress.show(); + progress.showDelayed(1000); } } diff --git a/src/cmaclient.cpp b/src/cmaclient.cpp index 2f966a2..daa3efd 100644 --- a/src/cmaclient.cpp +++ b/src/cmaclient.cpp @@ -251,3 +251,15 @@ void CmaClient::setActive(bool state) is_active = state; } +bool CmaClient::isRunning() +{ + bool ret; + if(mutex.tryLock()) { + ret = in_progress; + mutex.unlock(); + } else { + ret = true; + } + return ret; +} + diff --git a/src/cmaclient.h b/src/cmaclient.h index 6d1c195..d2023f8 100644 --- a/src/cmaclient.h +++ b/src/cmaclient.h @@ -38,6 +38,7 @@ class CmaClient : public QObject public: explicit CmaClient(QObject *parent = 0); + static bool isRunning(); void launch(); private: diff --git a/src/forms/configwidget.cpp b/src/forms/configwidget.cpp index ed8dc3e..f7ebf24 100644 --- a/src/forms/configwidget.cpp +++ b/src/forms/configwidget.cpp @@ -67,17 +67,17 @@ void ConfigWidget::setDefaultData() QString defaultdir; QSettings settings; defaultdir = QStandardPaths::writableLocation(QStandardPaths::PicturesLocation); - ui->photoPath->setText(settings.value("photoPath", defaultdir).toString()); + ui->photoPath->setText(QDir::toNativeSeparators(settings.value("photoPath", defaultdir).toString())); defaultdir = QStandardPaths::writableLocation(QStandardPaths::MusicLocation); - ui->musicPath->setText(settings.value("musicPath", defaultdir).toString()); + ui->musicPath->setText(QDir::toNativeSeparators(settings.value("musicPath", defaultdir).toString())); defaultdir = QStandardPaths::writableLocation(QStandardPaths::MoviesLocation); - ui->videoPath->setText(settings.value("videoPath", defaultdir).toString()); + ui->videoPath->setText(QDir::toNativeSeparators(settings.value("videoPath", defaultdir).toString())); defaultdir = QStandardPaths::writableLocation(QStandardPaths::HomeLocation); defaultdir.append(QDir::separator()).append("PS Vita"); - ui->appPath->setText(settings.value("appsPath", defaultdir).toString()); + ui->appPath->setText(QDir::toNativeSeparators(settings.value("appsPath", defaultdir).toString())); defaultdir = QStandardPaths::writableLocation(QStandardPaths::HomeLocation); defaultdir.append(QDir::separator()).append("PSV Updates"); - ui->urlPath->setText(settings.value("urlPath", defaultdir).toString()); + ui->urlPath->setText(QDir::toNativeSeparators(settings.value("urlPath", defaultdir).toString())); ui->offlineCheck->setChecked(settings.value("offlineMode", true).toBool()); ui->metadataCheck->setChecked(settings.value("skipMetadata", false).toBool()); @@ -128,7 +128,7 @@ void ConfigWidget::browseBtnPressed(int btn) QString selected = QFileDialog::getExistingDirectory(this, msg, lineedit->text(), QFileDialog::ShowDirsOnly); if(!selected.isEmpty()) { - lineedit->setText(selected); + lineedit->setText(QDir::toNativeSeparators((selected))); } } @@ -138,7 +138,7 @@ void ConfigWidget::savePath(QSettings &settings, const QLineEdit *edit, const QS if(path.endsWith(QDir::separator())) { path.chop(1); } - settings.setValue(key, path); + settings.setValue(key, QDir::fromNativeSeparators(path)); QDir(QDir::root()).mkpath(path); } diff --git a/src/forms/progressform.cpp b/src/forms/progressform.cpp index aa0160d..746aade 100644 --- a/src/forms/progressform.cpp +++ b/src/forms/progressform.cpp @@ -62,3 +62,16 @@ void ProgressForm::setDirectoryName(QString dir) QString elided = ui->directoryLabel->fontMetrics().elidedText(dir, Qt::ElideMiddle, ui->directoryLabel->width(), 0); ui->directoryLabel->setText(elided); } + +void ProgressForm::showDelayed(int msec) +{ + timer.setSingleShot(true); + timer.setInterval(msec); + connect(&timer, SIGNAL(timeout()), this, SLOT(show())); + timer.start(); +} + +void ProgressForm::interruptShow() +{ + timer.stop(); +} diff --git a/src/forms/progressform.h b/src/forms/progressform.h index 4c0a4b3..12fc292 100644 --- a/src/forms/progressform.h +++ b/src/forms/progressform.h @@ -20,6 +20,7 @@ #ifndef PROGRESSFORM_H #define PROGRESSFORM_H +#include #include namespace Ui { @@ -34,9 +35,14 @@ public: explicit ProgressForm(QWidget *parent = 0); ~ProgressForm(); + void showDelayed(int msec = 1000); + void interruptShow(); + private: Ui::ProgressForm *ui; + QTimer timer; + signals: void canceled(); diff --git a/src/mainwidget.cpp b/src/mainwidget.cpp index c1f296e..35d8088 100644 --- a/src/mainwidget.cpp +++ b/src/mainwidget.cpp @@ -77,7 +77,9 @@ void MainWidget::dialogResult(int result) void MainWidget::stopServer() { setTrayTooltip(tr("Shutting down...")); - receiveMessage(tr("Stopping QCMA (disconnect your PS Vita)")); + if(CmaClient::isRunning()) { + receiveMessage(tr("Stopping QCMA (disconnect your PS Vita)")); + } manager.stop(); }