[education/rkward] rkward/agents: More RCommandReceiver cleanups
Thomas Friedrichsmeier
null at kde.org
Sat May 21 22:42:42 BST 2022
Git commit 30c65108e2d29b858ce225cfc73c97411d212c0f by Thomas Friedrichsmeier.
Committed on 21/05/2022 at 21:42.
Pushed by tfry into branch 'master'.
More RCommandReceiver cleanups
M +10 -19 rkward/agents/rkeditobjectagent.cpp
M +1 -4 rkward/agents/rkeditobjectagent.h
M +7 -9 rkward/agents/rkquitagent.cpp
M +1 -3 rkward/agents/rkquitagent.h
https://invent.kde.org/education/rkward/commit/30c65108e2d29b858ce225cfc73c97411d212c0f
diff --git a/rkward/agents/rkeditobjectagent.cpp b/rkward/agents/rkeditobjectagent.cpp
index 908ae723..52bb873b 100644
--- a/rkward/agents/rkeditobjectagent.cpp
+++ b/rkward/agents/rkeditobjectagent.cpp
@@ -1,6 +1,6 @@
/*
rkeditobjectagent - This file is part of RKWard (https://rkward.kde.org). Created: Fri Feb 16 2007
-SPDX-FileCopyrightText: 2007 by Thomas Friedrichsmeier <thomas.friedrichsmeier at kdemail.net>
+SPDX-FileCopyrightText: 2007-2022 by Thomas Friedrichsmeier <thomas.friedrichsmeier at kdemail.net>
SPDX-FileContributor: The RKWard Team <rkward-devel at kde.org>
SPDX-License-Identifier: GPL-2.0-or-later
*/
@@ -16,28 +16,16 @@ SPDX-License-Identifier: GPL-2.0-or-later
#include "../debug.h"
-RKEditObjectAgent::RKEditObjectAgent (const QStringList &object_names, RCommandChain *chain) {
+RKEditObjectAgent::RKEditObjectAgent (const QStringList &_object_names, RCommandChain *chain) {
RK_TRACE (APP);
- RKEditObjectAgent::object_names = object_names;
+ RKEditObjectAgent::object_names = _object_names;
// first issue an empty command to trigger an update of the object list
RInterface::issueCommand (new RCommand (QString (), RCommand::EmptyCommand | RCommand::ObjectListUpdate, QString (), this), chain);
- // now add another empty command to find out, when the update is complete
- RCommand *command = new RCommand (QString (), RCommand::EmptyCommand, QString (), this);
- done_command_id = command->id ();
- RInterface::issueCommand (command, chain);
-}
-
-RKEditObjectAgent::~RKEditObjectAgent () {
- RK_TRACE (APP);
-}
-
-void RKEditObjectAgent::rCommandDone (RCommand *command) {
- RK_TRACE (APP);
-
- if (command->id () == done_command_id) {
+ // now add another empty command to find out, when the update has completed
+ RInterface::whenAllFinished(this, [this]() {
for (QStringList::const_iterator it = object_names.constBegin (); it != object_names.constEnd (); ++it) {
QString object_name = *it;
RObject *obj = RObjectList::getObjectList ()->findObject (object_name);
@@ -45,9 +33,12 @@ void RKEditObjectAgent::rCommandDone (RCommand *command) {
KMessageBox::information (0, i18n ("The object '%1', could not be opened for editing. Either it does not exist, or RKWard does not support editing this type of object, yet.", object_name), i18n ("Cannot edit '%1'", object_name));
}
}
-
+
// we're done
deleteLater ();
- }
+ }, chain);
}
+RKEditObjectAgent::~RKEditObjectAgent () {
+ RK_TRACE (APP);
+}
diff --git a/rkward/agents/rkeditobjectagent.h b/rkward/agents/rkeditobjectagent.h
index f0bf24a9..84514c3b 100644
--- a/rkward/agents/rkeditobjectagent.h
+++ b/rkward/agents/rkeditobjectagent.h
@@ -1,6 +1,6 @@
/*
rkeditobjectagent - This file is part of the RKWard project. Created: Fri Feb 16 2007
-SPDX-FileCopyrightText: 2007 by Thomas Friedrichsmeier <thomas.friedrichsmeier at kdemail.net>
+SPDX-FileCopyrightText: 2007-2022 by Thomas Friedrichsmeier <thomas.friedrichsmeier at kdemail.net>
SPDX-FileContributor: The RKWard Team <rkward-devel at kde.org>
SPDX-License-Identifier: GPL-2.0-or-later
*/
@@ -23,11 +23,8 @@ public:
RKEditObjectAgent (const QStringList &object_names, RCommandChain *chain);
~RKEditObjectAgent ();
-protected:
- void rCommandDone (RCommand *command) override;
private:
QStringList object_names;
- int done_command_id;
};
#endif
diff --git a/rkward/agents/rkquitagent.cpp b/rkward/agents/rkquitagent.cpp
index 9aa29d67..739a3d57 100644
--- a/rkward/agents/rkquitagent.cpp
+++ b/rkward/agents/rkquitagent.cpp
@@ -24,7 +24,7 @@ RKQuitAgent::RKQuitAgent (QObject *parent) : QObject (parent) {
RK_TRACE (APP);
quitting = true;
- RCommand *command = new RCommand (QString (), RCommand::EmptyCommand | RCommand::QuitCommand, QString (), this);
+ RCommand *command = new RCommand (QString (), RCommand::EmptyCommand | RCommand::QuitCommand);
RKWardMainWindow::getMain ()->hide ();
cancel_dialog = new RKProgressControl (this, i18n ("Waiting for remaining R commands to finish. To quit immediately, press Cancel (WARNING: This may result in loss of data)"), i18n ("Waiting for R to finish"), RKProgressControl::AllowCancel | RKProgressControl::ShowAtOnce);
@@ -32,15 +32,19 @@ RKQuitAgent::RKQuitAgent (QObject *parent) : QObject (parent) {
connect (cancel_dialog, &RKProgressControl::cancelled, this, &RKQuitAgent::doQuitNow);
if (RInterface::instance()->backendIsDead()) { // nothing to loose
- QTimer::singleShot (0, this, SLOT (doQuitNow()));
+ QTimer::singleShot(0, this, &RKQuitAgent::doQuitNow);
return;
} else if (RInterface::instance()->backendIsIdle()) {
// there should be no problem while quitting. If there is, show the dialog after 300 msec
- QTimer::singleShot (300, this, SLOT (showWaitDialog()));
+ QTimer::singleShot(300, this, &RKQuitAgent::showWaitDialog);
} else {
showWaitDialog ();
}
+ command->whenFinished(this, [this]() {
+ RK_TRACE(APP);
+ QTimer::singleShot(0, this, &RKQuitAgent::doQuitNow);
+ });
RInterface::issueCommand (command);
}
@@ -60,10 +64,4 @@ void RKQuitAgent::doQuitNow () {
RKWardMainWindow::getMain ()->close (); // this will kill the agent as well.
}
-void RKQuitAgent::rCommandDone (RCommand *) {
- RK_TRACE (APP);
-
- QTimer::singleShot (0, this, SLOT (doQuitNow()));
-}
-
diff --git a/rkward/agents/rkquitagent.h b/rkward/agents/rkquitagent.h
index 0aca80a5..72c56fa1 100644
--- a/rkward/agents/rkquitagent.h
+++ b/rkward/agents/rkquitagent.h
@@ -15,7 +15,7 @@ class RKProgressControl;
/** The purpose of RKQuitAgent is to delay the actual destruction of the app until all commands have finished in the backend. The quit agent can NOT handle queries for saving some more data, or similar things. Do not call before you really want to quit the application.
@author Thomas Friedrichsmeier
*/
-class RKQuitAgent : public QObject, public RCommandReceiver {
+class RKQuitAgent : public QObject {
Q_OBJECT
public:
/** Constructor. As soon as you construct an object of this type, the RKWard application *will* quit (but maybe with a short delay)! */
@@ -26,8 +26,6 @@ public:
public slots:
void doQuitNow ();
void showWaitDialog ();
-protected:
- void rCommandDone (RCommand *command) override;
private:
RKProgressControl *cancel_dialog;
static bool quitting;
More information about the rkward-tracker
mailing list