| 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 | |
| 15 | using namespace KNewStuffQuick; |
| 16 | |
| 17 | Q_GLOBAL_STATIC(QuickQuestionListener, s_quickQuestionListener) |
| 18 | QuickQuestionListener *QuickQuestionListener::instance() |
| 19 | { |
| 20 | return s_quickQuestionListener; |
| 21 | } |
| 22 | |
| 23 | QuickQuestionListener::~QuickQuestionListener() |
| 24 | { |
| 25 | if (m_question) { |
| 26 | m_question->setResponse(KNSCore::Question::CancelResponse); |
| 27 | } |
| 28 | } |
| 29 | |
| 30 | void QuickQuestionListener::askQuestion(KNSCore::Question *question) |
| 31 | { |
| 32 | switch (question->questionType()) { |
| 33 | case KNSCore::Question::SelectFromListQuestion: |
| 34 | Q_EMIT askListQuestion(title: question->title(), question: question->question(), list: question->list()); |
| 35 | break; |
| 36 | case KNSCore::Question::ContinueCancelQuestion: |
| 37 | Q_EMIT askContinueCancelQuestion(title: question->title(), question: question->question()); |
| 38 | break; |
| 39 | case KNSCore::Question::InputTextQuestion: |
| 40 | Q_EMIT askTextInputQuestion(title: question->title(), question: question->question()); |
| 41 | break; |
| 42 | case KNSCore::Question::PasswordQuestion: |
| 43 | Q_EMIT askPasswordQuestion(title: question->title(), question: question->question()); |
| 44 | break; |
| 45 | case KNSCore::Question::YesNoQuestion: |
| 46 | default: |
| 47 | Q_EMIT askYesNoQuestion(title: question->title(), question: question->question()); |
| 48 | break; |
| 49 | } |
| 50 | m_question = question; |
| 51 | } |
| 52 | |
| 53 | void 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" |
| 91 |
