summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleix Pol <[email protected]>2016-11-14 19:53:29 +0100
committerAleix Pol <[email protected]>2016-11-14 19:53:29 +0100
commit53042cfafb32de7c9268303e304bc0d5d60ff1c4 (patch)
tree3b6ddb220d977f2ba4e6eb5e29af507b9f654cc9
parent75dca3dc92303ef66b5d9e556e2c7128db41b033 (diff)
Don't close if the input is wrong
Display a visual error message instead, users expect the feedback on the GUI. BUG: 372277
-rw-r--r--discover/DiscoverMainWindow.cpp8
-rw-r--r--discover/DiscoverMainWindow.h1
-rw-r--r--discover/autotests/CMakeLists.txt1
-rw-r--r--discover/main.cpp11
4 files changed, 15 insertions, 6 deletions
diff --git a/discover/DiscoverMainWindow.cpp b/discover/DiscoverMainWindow.cpp
index 0b3ca10..cf1d071 100644
--- a/discover/DiscoverMainWindow.cpp
+++ b/discover/DiscoverMainWindow.cpp
@@ -34,6 +34,7 @@
#include <qqml.h>
#include <QPointer>
#include <QGuiApplication>
+#include <QTimer>
// KDE includes
#include <KAboutApplicationDialog>
@@ -367,3 +368,10 @@ QWindow* DiscoverMainWindow::rootObject() const
{
return qobject_cast<QWindow*>(m_engine->rootObjects().at(0));
}
+
+void DiscoverMainWindow::showPassiveNotification(const QString& msg)
+{
+ QTimer::singleShot(100, this, [this, msg](){
+ QMetaObject::invokeMethod(rootObject(), "showPassiveNotification", Qt::QueuedConnection, Q_ARG(QVariant, msg), Q_ARG(QVariant, {}), Q_ARG(QVariant, {}), Q_ARG(QVariant, {}));
+ });
+}
diff --git a/discover/DiscoverMainWindow.h b/discover/DiscoverMainWindow.h
index 34b85ff..f259b6d 100644
--- a/discover/DiscoverMainWindow.h
+++ b/discover/DiscoverMainWindow.h
@@ -62,6 +62,7 @@ class DiscoverMainWindow : public QObject
static bool isRoot();
QWindow* rootObject() const;
+ void showPassiveNotification(const QString &msg);
public Q_SLOTS:
void openApplication(const QString& app);
diff --git a/discover/autotests/CMakeLists.txt b/discover/autotests/CMakeLists.txt
index f54b321..6f44168 100644
--- a/discover/autotests/CMakeLists.txt
+++ b/discover/autotests/CMakeLists.txt
@@ -10,4 +10,5 @@ if(BUILD_DummyBackend)
add_test(NAME missingResource COMMAND Plasma::Discover --test "${CMAKE_CURRENT_SOURCE_DIR}/missingResource.qml" "appstream://caca")
add_test(NAME apparg COMMAND Plasma::Discover --test "${CMAKE_CURRENT_SOURCE_DIR}/appstreamUrl.qml" --application techie1)
add_test(NAME categoryarg COMMAND Plasma::Discover --test "${CMAKE_CURRENT_SOURCE_DIR}/categoryArg.qml" --category "dummy 2.1")
+ add_test(NAME wrongInput COMMAND Plasma::Discover --test "${CMAKE_CURRENT_SOURCE_DIR}/wrongInput.qml" "CMakeLists.txt")
endif()
diff --git a/discover/main.cpp b/discover/main.cpp
index d1946f5..3e92348 100644
--- a/discover/main.cpp
+++ b/discover/main.cpp
@@ -61,7 +61,7 @@ QCommandLineParser* createParser()
return parser;
}
-bool processArgs(QCommandLineParser* parser, DiscoverMainWindow* mainWindow)
+void processArgs(QCommandLineParser* parser, DiscoverMainWindow* mainWindow)
{
if(parser->isSet(QStringLiteral("application")))
mainWindow->openApplication(parser->value(QStringLiteral("application")));
@@ -79,11 +79,11 @@ bool processArgs(QCommandLineParser* parser, DiscoverMainWindow* mainWindow)
QTextStream(stdout) << "opening appstream resource" << url.host() << '\n';
mainWindow->openApplication(url.host());
} else {
- QTextStream(stdout) << "unrecognized url" << url.toDisplayString() << '\n';
- return true;
+ const QString msg = i18n("Unrecognized url: %1", url.toDisplayString());
+ QTextStream(stdout) << msg << '\n';
+ mainWindow->showPassiveNotification(msg);
}
}
- return false;
}
int main(int argc, char** argv)
@@ -125,8 +125,7 @@ int main(int argc, char** argv)
processArgs(parser.data(), mainWindow);
});
- if (processArgs(parser.data(), mainWindow))
- return 1;
+ processArgs(parser.data(), mainWindow);
if(parser->isSet(QStringLiteral("listmodes"))) {
QTextStream(stdout) << i18n("Available modes:\n");