[education/rkward] /: Progress indication (busy / done / error) using icons
Thomas Friedrichsmeier
null at kde.org
Sun May 1 21:37:49 BST 2022
Git commit 8fcbd36e1b5cf7565da24eb51d96df743b7a4b83 by Thomas Friedrichsmeier.
Committed on 01/05/2022 at 16:17.
Pushed by tfry into branch 'master'.
Progress indication (busy / done / error) using icons
M +1 -2 ChangeLog
M +2 -2 rkward/dialogs/rkloadlibsdialog.cpp
M +1 -1 rkward/dialogs/rkloadlibsdialog.h
M +29 -3 rkward/misc/rkprogresscontrol.cpp
M +4 -1 rkward/misc/rkprogresscontrol.h
https://invent.kde.org/education/rkward/commit/8fcbd36e1b5cf7565da24eb51d96df743b7a4b83
diff --git a/ChangeLog b/ChangeLog
index 26af6786..51c9d03e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -4,8 +4,7 @@ TODOs:
- Fixed some problems with cancelling running commands
- Package installation uses inline widget to provide progress feedback, instead of separate dialogs
- TODO: Finding package from require() fails, because list is not yet loaded
- - TODO: Remove "Ok" button from dialog
- - TODO: Provide separate message texts (and icons?) for running, finished successfully, finished with error
+ - TODO: Remove "Ok" button from dialog, rename "Cancel" to "Close"
- TODO: Remove current repositories from .rk.get.package.installation.status() (no longer needed)
- Package installation no longer uses an external process, unless required for root permissions
- TODO: swallow installation output in require()
diff --git a/rkward/dialogs/rkloadlibsdialog.cpp b/rkward/dialogs/rkloadlibsdialog.cpp
index 6d6c3642..b6f502d0 100644
--- a/rkward/dialogs/rkloadlibsdialog.cpp
+++ b/rkward/dialogs/rkloadlibsdialog.cpp
@@ -292,7 +292,7 @@ void RKLoadLibsDialog::runInstallationCommand (const QString& command, bool as_r
RK_TRACE (DIALOGS);
auto control = new RKInlineProgressControl(install_packages_widget, true);
- control->messageWidget()->setText(QString("<b>%1</b><p>%2</p>").arg(title, message));
+ control->setText(QString("<b>%1</b><br/>%2...").arg(title, message));
control->show();
RCommand *rcommand;
@@ -887,7 +887,7 @@ void RKRPackageInstallationStatus::initialize (RCommandChain *chain) {
RCommand *command = new RCommand (".rk.get.package.installation.state ()", RCommand::App | RCommand::GetStructuredData);
connect(command->notifier(), &RCommandNotifier::commandFinished, this, &RKRPackageInstallationStatus::statusCommandFinished);
RKInlineProgressControl *control = new RKInlineProgressControl(display_area, true);
- control->messageWidget()->setText(i18n("<p>Please stand by while searching for installed and available packages.</p><p><strong>Note:</strong> This requires a working internet connection, and may take some time, esp. if one or more repositories are temporarily unavailable.</p>"));
+ control->setText(i18n("<p>Please stand by while searching for installed and available packages.</p><p><strong>Note:</strong> This requires a working internet connection, and may take some time, esp. if one or more repositories are temporarily unavailable.</p>"));
control->addRCommand(command);
control->setAutoCloseWhenCommandsDone(true);
RInterface::issueCommand(command, chain);
diff --git a/rkward/dialogs/rkloadlibsdialog.h b/rkward/dialogs/rkloadlibsdialog.h
index 9577cd9b..2996dc70 100644
--- a/rkward/dialogs/rkloadlibsdialog.h
+++ b/rkward/dialogs/rkloadlibsdialog.h
@@ -242,7 +242,7 @@ private:
RKDynamicSearchLine *filter_edit;
QCheckBox *rkward_packages_only;
PackageInstallParamsWidget *install_params;
-
+
RKLoadLibsDialog *parent;
};
diff --git a/rkward/misc/rkprogresscontrol.cpp b/rkward/misc/rkprogresscontrol.cpp
index ce6dd3ff..e7331a05 100644
--- a/rkward/misc/rkprogresscontrol.cpp
+++ b/rkward/misc/rkprogresscontrol.cpp
@@ -379,10 +379,13 @@ void RKProgressControlDialog::closeEvent (QCloseEvent *e) {
#include <KMessageBox>
#include <KStandardAction>
+#include "rkstandardicons.h"
+
RKInlineProgressControl::RKInlineProgressControl(QWidget *display_area, bool allow_cancel) : QObject(display_area),
autoclose(false),
allow_cancel(allow_cancel),
is_done(false),
+ any_failed(false),
display_area(display_area),
prevent_close_message(nullptr),
close_action(nullptr) {
@@ -438,8 +441,7 @@ void RKInlineProgressControl::addRCommand(RCommand *command) {
connect(command->notifier(), &RCommandNotifier::commandFinished, this, [this](RCommand *c) {
unfinished_commands.removeAll(c);
if (c->failed()) {
- autoclose = false;
- message_widget->setMessageType(KMessageWidget::Error);
+ any_failed = true;
}
if (unfinished_commands.isEmpty()) {
done();
@@ -462,14 +464,24 @@ void RKInlineProgressControl::addOutput(const QString& output, bool is_error_war
void RKInlineProgressControl::done() {
RK_TRACE(MISC);
- if (autoclose) {
+ if (autoclose && !any_failed) {
deleteLater();
} else {
+ message_widget->setMessageType(any_failed ? KMessageWidget::Error : KMessageWidget::Positive);
+ message_widget->setText(text + ' ' + (any_failed ? i18n("<b>An error occurred</b> (see below for details)") : i18n("<b>Done</b>")));
+ message_widget->setIcon(QIcon::fromTheme(any_failed ? "emblem-error" : "emblem-success"));
+ message_widget->animatedShow(); // to force an update of geometry
setCloseAction(i18n("Close"));
}
is_done = true;
}
+void RKInlineProgressControl::setText(const QString& _text){
+ RK_TRACE(MISC);
+ text = _text;
+ message_widget->setText(text);
+}
+
void RKInlineProgressControl::show(int delay_ms) {
RK_TRACE(MISC);
if (delay_ms > 0) {
@@ -477,6 +489,20 @@ void RKInlineProgressControl::show(int delay_ms) {
} else {
wrapper->show();
}
+ animation_step = 0;
+ message_widget->setIcon(RKStandardIcons::getIcon(RKStandardIcons::RKWardIcon));
+ auto t = new QTimer(this);
+ t->setInterval(750);
+ connect(t, &QTimer::timeout, this, [this]() {
+ if (is_done) return;
+ animation_step = (animation_step + 1) % 2;
+ if (animation_step) {
+ message_widget->setIcon(QIcon::fromTheme("computer-symbolic"));
+ } else {
+ message_widget->setIcon(RKStandardIcons::getIcon(RKStandardIcons::RKWardIcon));
+ }
+ });
+ t->start();
}
bool RKInlineProgressControl::eventFilter(QObject *, QEvent *e) {
diff --git a/rkward/misc/rkprogresscontrol.h b/rkward/misc/rkprogresscontrol.h
index 4dfab752..53592664 100644
--- a/rkward/misc/rkprogresscontrol.h
+++ b/rkward/misc/rkprogresscontrol.h
@@ -108,7 +108,7 @@ public:
void addRCommand(RCommand *command);
void setAutoCloseWhenCommandsDone(bool _autoclose) { autoclose = _autoclose; };
void show(int delay_ms=0);
- KMessageWidget *messageWidget() { return message_widget; };
+ void setText(const QString &text);
private:
void addOutput(const QString &output, bool is_error_warning);
void done();
@@ -118,6 +118,8 @@ private:
bool autoclose;
bool allow_cancel;
bool is_done;
+ bool any_failed;
+ int animation_step;
QWidget* wrapper;
QWidget* display_area;
KMessageWidget *message_widget;
@@ -125,6 +127,7 @@ private:
QTextEdit *output_display;
QList<RCommand*> unfinished_commands;
QAction* close_action;
+ QString text;
};
#endif
More information about the rkward-tracker
mailing list