libzypp 17.37.10

userrequest.h
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8\---------------------------------------------------------------------*/
9#ifndef ZYPP_CORE_ZYPPNG_USERREQUEST_H
10#define ZYPP_CORE_ZYPPNG_USERREQUEST_H
11
12#include <zypp-core/zyppng/base/Base>
13#include <zypp-core/zyppng/base/Signals>
14#include <zypp-core/UserData.h>
15#include <vector>
16 namespace zyppng {
17
18 using UserData = zypp::callback::UserData;
19 using ContentType = zypp::ContentType;
20
21
22 ZYPP_FWD_DECL_TYPE_WITH_REFS( UserRequest );
23 ZYPP_FWD_DECL_TYPE_WITH_REFS( ShowMessageRequest );
24 ZYPP_FWD_DECL_TYPE_WITH_REFS( ListChoiceRequest );
25 ZYPP_FWD_DECL_TYPE_WITH_REFS( BooleanChoiceRequest );
26
27 /*
28 constexpr std::string_view CTYPE_SHOW_MESSAGE_REQUEST ("userreq/show-message");
29 constexpr std::string_view CTYPE_LIST_CHOICE_REQUEST ("userreq/list-choice");
30 constexpr std::string_view CTYPE_BOOLEAN_COICE_REQUEST("userreq/boolean-choice");
31 */
32
33
34 enum class UserRequestType : uint {
35 Message, // simple message to the user, no input or predefined like y/n
36 ListChoice, // request to select from a list of options
37 BooleanChoice, // request user to say yes or no
38 KeyTrust, // request to the user to trust a key
39 Custom = 512
40 };
41
48 class UserRequest : public Base
49 {
50 public:
51 UserRequest( UserData userData = {} );
52 ~UserRequest() override;
53 virtual UserRequestType type() const = 0;
54 const UserData &userData() const;
55 UserData &userData();
56
57 private:
58 UserData _userData;
59 };
60
61
62
71 class ShowMessageRequest : public UserRequest
72 {
73 ZYPP_ADD_CREATE_FUNC(ShowMessageRequest)
74 public:
75
76 enum class MType {
77 Debug, Info, Warning, Error, Important, Data
78 };
79
80 ZYPP_DECL_PRIVATE_CONSTR_ARGS(ShowMessageRequest, std::string message, MType mType = MType::Info, UserData data = {} );
81 UserRequestType type() const override;
82
83 MType messageType();
84 const std::string &message() const;
85
86 private:
87 MType _type = MType::Info;
88 std::string _message;
89 };
90
91
92
120 class ListChoiceRequest : public UserRequest
121 {
122 ZYPP_ADD_CREATE_FUNC(ListChoiceRequest)
123 public:
124
125 struct Choice {
126 std::string opt;
127 std::string detail;
128 };
129
130 using index_type = std::vector<Choice>::size_type;
131
132 ZYPP_DECL_PRIVATE_CONSTR_ARGS(ListChoiceRequest, std::string label, std::vector<Choice> answers, index_type defaultAnswer, UserData userData = {} );
133 UserRequestType type() const override;
134
135 const std::string &label() const;
136
137 void setChoice ( const index_type sel );
138 index_type choice() const;
139
140 index_type defaultAnswer() const;
141
142 const std::vector<Choice> &answers() const;
143
144
145 private:
146 std::string _label;
147 std::vector<Choice> _answers;
148 index_type _answer = 0;
149 index_type _default = 0;
150 };
151
152
153 class BooleanChoiceRequest : public UserRequest
154 {
155 ZYPP_ADD_CREATE_FUNC(BooleanChoiceRequest)
156
157 public:
158 ZYPP_DECL_PRIVATE_CONSTR_ARGS(BooleanChoiceRequest, std::string label, const bool defaultAnswer = false, UserData userData = {} );
159 UserRequestType type() const override;
160
161 const std::string &label() const;
162
163 void setChoice ( const bool sel );
164 bool choice() const;
165
166 private:
167 std::string _label;
168 bool _answer = false;
169
170 };
171
172}
173
174
175#endif
zypp::ContentType
Mime type like 'type/subtype' classification of content.
Definition ContentType.h:30
zypp::callback::UserData
Typesafe passing of user data via callbacks.
Definition UserData.h:40
zyppng::Base::Base
Base()
Definition base.cc:20
zyppng::BooleanChoiceRequest
Definition userrequest.h:154
zyppng::BooleanChoiceRequest::_answer
bool _answer
Definition userrequest.h:168
zyppng::BooleanChoiceRequest::ZYPP_DECL_PRIVATE_CONSTR_ARGS
ZYPP_DECL_PRIVATE_CONSTR_ARGS(BooleanChoiceRequest, std::string label, const bool defaultAnswer=false, UserData userData={})
zyppng::BooleanChoiceRequest::type
UserRequestType type() const override
Definition userrequest.cc:99
zyppng::BooleanChoiceRequest::setChoice
void setChoice(const bool sel)
Definition userrequest.cc:109
zyppng::BooleanChoiceRequest::_label
std::string _label
Definition userrequest.h:167
zyppng::BooleanChoiceRequest::choice
bool choice() const
Definition userrequest.cc:114
zyppng::BooleanChoiceRequest::label
const std::string & label() const
Definition userrequest.cc:104
zyppng::ListChoiceRequest
Definition userrequest.h:121
zyppng::ListChoiceRequest::index_type
std::vector< Choice >::size_type index_type
Definition userrequest.h:130
zyppng::ListChoiceRequest::choice
index_type choice() const
Definition userrequest.cc:78
zyppng::ListChoiceRequest::setChoice
void setChoice(const index_type sel)
Definition userrequest.cc:71
zyppng::ListChoiceRequest::_answer
index_type _answer
Definition userrequest.h:148
zyppng::ListChoiceRequest::_answers
std::vector< Choice > _answers
Definition userrequest.h:147
zyppng::ListChoiceRequest::ZYPP_DECL_PRIVATE_CONSTR_ARGS
ZYPP_DECL_PRIVATE_CONSTR_ARGS(ListChoiceRequest, std::string label, std::vector< Choice > answers, index_type defaultAnswer, UserData userData={})
zyppng::ListChoiceRequest::label
const std::string & label() const
Definition userrequest.cc:66
zyppng::ListChoiceRequest::_label
std::string _label
Definition userrequest.h:146
zyppng::ListChoiceRequest::type
UserRequestType type() const override
Definition userrequest.cc:61
zyppng::ListChoiceRequest::defaultAnswer
index_type defaultAnswer() const
Definition userrequest.cc:83
zyppng::ListChoiceRequest::answers
const std::vector< Choice > & answers() const
Definition userrequest.cc:88
zyppng::ListChoiceRequest::_default
index_type _default
Definition userrequest.h:149
zyppng::ShowMessageRequest
Definition userrequest.h:72
zyppng::ShowMessageRequest::MType
MType
Definition userrequest.h:76
zyppng::ShowMessageRequest::MType::Important
@ Important
Definition userrequest.h:77
zyppng::ShowMessageRequest::MType::Warning
@ Warning
Definition userrequest.h:77
zyppng::ShowMessageRequest::MType::Info
@ Info
Definition userrequest.h:77
zyppng::ShowMessageRequest::MType::Error
@ Error
Definition userrequest.h:77
zyppng::ShowMessageRequest::MType::Debug
@ Debug
Definition userrequest.h:77
zyppng::ShowMessageRequest::MType::Data
@ Data
Definition userrequest.h:77
zyppng::ShowMessageRequest::ZYPP_DECL_PRIVATE_CONSTR_ARGS
ZYPP_DECL_PRIVATE_CONSTR_ARGS(ShowMessageRequest, std::string message, MType mType=MType::Info, UserData data={})
zyppng::ShowMessageRequest::_type
MType _type
Definition userrequest.h:87
zyppng::ShowMessageRequest::message
const std::string & message() const
Definition userrequest.cc:48
zyppng::ShowMessageRequest::_message
std::string _message
Definition userrequest.h:88
zyppng::ShowMessageRequest::type
UserRequestType type() const override
Definition userrequest.cc:38
zyppng::ShowMessageRequest::messageType
MType messageType()
Definition userrequest.cc:43
zyppng::UserRequest
Definition userrequest.h:49
zyppng::UserRequest::userData
const UserData & userData() const
Definition userrequest.cc:22
zyppng::UserRequest::UserRequest
UserRequest(UserData userData={})
Definition userrequest.cc:15
zyppng::UserRequest::~UserRequest
~UserRequest() override
Definition userrequest.cc:19
zyppng::UserRequest::type
virtual UserRequestType type() const =0
zyppng::UserRequest::_userData
UserData _userData
Definition userrequest.h:58
zyppng
Definition MediaNetworkRequestExecutor.h:16
zyppng::UserRequestType
UserRequestType
Definition userrequest.h:34
zyppng::UserRequestType::BooleanChoice
@ BooleanChoice
Definition userrequest.h:37
zyppng::UserRequestType::Message
@ Message
Definition userrequest.h:35
zyppng::UserRequestType::ListChoice
@ ListChoice
Definition userrequest.h:36
zyppng::UserRequestType::Custom
@ Custom
Definition userrequest.h:39
zyppng::UserRequestType::KeyTrust
@ KeyTrust
Definition userrequest.h:38
zyppng::UserData
zypp::callback::UserData UserData
Definition userrequest.h:18
zyppng::ListChoiceRequest::Choice
Definition userrequest.h:125
zyppng::ListChoiceRequest::Choice::opt
std::string opt
Definition userrequest.h:126
zyppng::ListChoiceRequest::Choice::detail
std::string detail
Definition userrequest.h:127
UserData.h
ZYPP_ADD_CREATE_FUNC
#define ZYPP_ADD_CREATE_FUNC(Class)
Definition zyppglobal.h:205
ZYPP_FWD_DECL_TYPE_WITH_REFS
#define ZYPP_FWD_DECL_TYPE_WITH_REFS(T)
Definition zyppglobal.h:126