KNewStuff

quickquestionlistener.cpp
1/*
2 This file is part of KNewStuffQuick.
3 SPDX-FileCopyrightText: 2016 Dan Leinir Turthra Jensen <admin@leinir.dk>
4
5 SPDX-License-Identifier: LGPL-2.1-or-later
6*/
7
8#include "quickquestionlistener.h"
9
10#include "core/question.h"
11
12#include <QCoreApplication>
13#include <QPointer>
14
15using namespace KNewStuffQuick;
16
17Q_GLOBAL_STATIC(QuickQuestionListener, s_quickQuestionListener)
18QuickQuestionListener *QuickQuestionListener::instance()
19{
20 return s_quickQuestionListener;
21}
22
23QuickQuestionListener::~QuickQuestionListener()
24{
25 if (m_question) {
26 m_question->setResponse(KNSCore::Question::CancelResponse);
27 }
28}
29
30void QuickQuestionListener::askQuestion(KNSCore::Question *question)
31{
32 switch (question->questionType()) {
33 case KNSCore::Question::SelectFromListQuestion:
34 Q_EMIT askListQuestion(question->title(), question->question(), question->list());
35 break;
36 case KNSCore::Question::ContinueCancelQuestion:
37 Q_EMIT askContinueCancelQuestion(question->title(), question->question());
38 break;
39 case KNSCore::Question::InputTextQuestion:
40 Q_EMIT askTextInputQuestion(question->title(), question->question());
41 break;
42 case KNSCore::Question::PasswordQuestion:
43 Q_EMIT askPasswordQuestion(question->title(), question->question());
44 break;
45 case KNSCore::Question::YesNoQuestion:
46 default:
47 Q_EMIT askYesNoQuestion(question->title(), question->question());
48 break;
49 }
50 m_question = question;
51}
52
53void KNewStuffQuick::QuickQuestionListener::passResponse(bool responseIsContinue, QString input)
54{
55 if (m_question) {
56 if (responseIsContinue) {
57 m_question->setResponse(input);
58 switch (m_question->questionType()) {
59 case KNSCore::Question::ContinueCancelQuestion:
60 m_question->setResponse(KNSCore::Question::ContinueResponse);
61 break;
62 case KNSCore::Question::YesNoQuestion:
63 m_question->setResponse(KNSCore::Question::YesResponse);
64 break;
65 case KNSCore::Question::SelectFromListQuestion:
66 case KNSCore::Question::InputTextQuestion:
67 case KNSCore::Question::PasswordQuestion:
68 default:
69 m_question->setResponse(KNSCore::Question::OKResponse);
70 break;
71 }
72 } else {
73 switch (m_question->questionType()) {
74 case KNSCore::Question::YesNoQuestion:
75 m_question->setResponse(KNSCore::Question::NoResponse);
76 break;
77 case KNSCore::Question::SelectFromListQuestion:
78 case KNSCore::Question::InputTextQuestion:
79 case KNSCore::Question::PasswordQuestion:
80 case KNSCore::Question::ContinueCancelQuestion:
81 default:
82 m_question->setResponse(KNSCore::Question::CancelResponse);
83 break;
84 }
85 }
86 m_question.clear();
87 }
88}
89
90#include "moc_quickquestionlistener.cpp"
A way to ask a user a question from inside a GUI-less library (like KNewStuffCore)
Definition question.h:47
Q_EMITQ_EMIT
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:20:03 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.