Commit 9f3e8511 authored by Elvis Angelaccio's avatar Elvis Angelaccio
Browse files

Simplify Query usage in CLI plugins

The Query was still assuming that all plugins run from a secondary
thread.
Since CliInterface-based plugins run from the main thread, there is no need to
emit the `userQuery` signal and then call `Query::waitForResponse()`.
They can directly call `Query::execute()` instead.

Differential Revision: D3217
parent 1b5af864
......@@ -166,10 +166,14 @@ signals:
void progress(double progress);
void info(const QString &info);
void finished(bool result);
void userQuery(Query *query);
void testSuccess();
void compressionMethodFound(const QStringList);
/**
* Emitted when @p query needs to be executed on the GUI thread.
*/
void userQuery(Query *query);
protected:
/**
......
......@@ -354,8 +354,7 @@ void CliInterface::processFinished(int exitCode, QProcess::ExitStatus exitStatus
list();
} else if (m_operationMode == List && isCorrupt()) {
Kerfuffle::LoadCorruptQuery query(filename());
emit userQuery(&query);
query.waitForResponse();
query.execute();
if (!query.responseYes()) {
emit cancelled();
emit finished(false);
......@@ -495,8 +494,7 @@ bool CliInterface::moveDroppedFilesToDest(const QVector<Archive::Entry*> &files,
Kerfuffle::OverwriteQuery query(absDestEntry.absoluteFilePath());
query.setNoRenameMode(true);
emit userQuery(&query);
query.waitForResponse();
query.execute();
if (query.responseOverwrite() || query.responseOverwriteAll()) {
if (query.responseOverwriteAll()) {
......@@ -604,8 +602,7 @@ bool CliInterface::moveToDestination(const QDir &tempDir, const QDir &destDir, b
Kerfuffle::OverwriteQuery query(absDestEntry.absoluteFilePath());
query.setNoRenameMode(true);
emit userQuery(&query);
query.waitForResponse();
query.execute();
if (query.responseOverwrite() || query.responseOverwriteAll()) {
if (query.responseOverwriteAll()) {
......@@ -727,8 +724,7 @@ void CliInterface::killProcess(bool emitFinished)
bool CliInterface::passwordQuery()
{
Kerfuffle::PasswordNeededQuery query(filename());
emit userQuery(&query);
query.waitForResponse();
query.execute();
if (query.responseCancelled()) {
emit cancelled();
......@@ -866,8 +862,7 @@ bool CliInterface::handleLine(const QString& line)
qCDebug(ARK) << "Found a password prompt";
Kerfuffle::PasswordNeededQuery query(filename());
emit userQuery(&query);
query.waitForResponse();
query.execute();
if (query.responseCancelled()) {
emit cancelled();
......@@ -911,8 +906,7 @@ bool CliInterface::handleLine(const QString& line)
qCDebug(ARK) << "Found a password prompt";
Kerfuffle::PasswordNeededQuery query(filename());
emit userQuery(&query);
query.waitForResponse();
query.execute();
if (query.responseCancelled()) {
emit cancelled();
......@@ -992,11 +986,7 @@ bool CliInterface::handleFileExistsMessage(const QString& line)
Kerfuffle::OverwriteQuery query(QDir::current().path() + QLatin1Char( '/' ) + m_storedFileName);
query.setNoRenameMode(true);
emit userQuery(&query);
qCDebug(ARK) << "Waiting response";
query.waitForResponse();
qCDebug(ARK) << "Finished response";
query.execute();
QString responseToProcess;
const QStringList choices = m_cliProps->property("fileExistsInput").toStringList();
......
......@@ -215,6 +215,10 @@ void Job::onFinished(bool result)
void Job::onUserQuery(Query *query)
{
if (archiveInterface()->waitForFinishedSignal()) {
qCWarning(ARK) << "Plugins run from the main thread should call directly query->execute()";
}
emit userQuery(query);
}
......
......@@ -44,7 +44,6 @@ namespace Kerfuffle
{
Query::Query()
{
m_responseMutex.lock();
}
QVariant Query::response() const
......@@ -54,11 +53,11 @@ QVariant Query::response() const
void Query::waitForResponse()
{
QMutexLocker locker(&m_responseMutex);
//if there is no response set yet, wait
if (!m_data.contains(QStringLiteral("response"))) {
m_responseCondition.wait(&m_responseMutex);
}
m_responseMutex.unlock();
}
void Query::setResponse(const QVariant &response)
......
......@@ -46,14 +46,13 @@ class KERFUFFLE_EXPORT Query
{
public:
/**
* Execute the response. Will happen in the GUI thread, so it's
* safe to use widgets/gui elements here. Must call setResponse
* when done.
* Execute the response. It needs to be called from the GUI thread.
*/
virtual void execute() = 0;
/**
* Will block until the response have been set
* Will block until the response have been set.
* Useful for worker threads that need to show a dialog.
*/
void waitForResponse();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment