libzypp 17.37.17
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>
16namespace zyppng {
17
20
21
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:
52 ~UserRequest() override;
53 virtual UserRequestType type() const = 0;
54 const UserData &userData() const;
56
57 private:
59 };
60
61
62
72 {
74 public:
75
76 enum class MType {
78 };
79
81 UserRequestType type() const override;
82
83 MType messageType();
84 const std::string &message() const;
85
86 private:
88 std::string _message;
89 };
90
91
92
121 {
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
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
141
142 const std::vector<Choice> &answers() const;
143
144
145 private:
146 std::string _label;
147 std::vector<Choice> _answers;
150 };
151
152
154 {
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
Mime type like 'type/subtype' classification of content.
Definition ContentType.h:30
Typesafe passing of user data via callbacks.
Definition UserData.h:40
ZYPP_DECL_PRIVATE_CONSTR_ARGS(BooleanChoiceRequest, std::string label, const bool defaultAnswer=false, UserData userData={})
UserRequestType type() const override
void setChoice(const bool sel)
const std::string & label() const
std::vector< Choice >::size_type index_type
index_type choice() const
void setChoice(const index_type sel)
std::vector< Choice > _answers
ZYPP_DECL_PRIVATE_CONSTR_ARGS(ListChoiceRequest, std::string label, std::vector< Choice > answers, index_type defaultAnswer, UserData userData={})
const std::string & label() const
UserRequestType type() const override
index_type defaultAnswer() const
const std::vector< Choice > & answers() const
ZYPP_DECL_PRIVATE_CONSTR_ARGS(ShowMessageRequest, std::string message, MType mType=MType::Info, UserData data={})
const std::string & message() const
UserRequestType type() const override
const UserData & userData() const
UserRequest(UserData userData={})
~UserRequest() override
virtual UserRequestType type() const =0
UserRequestType
Definition userrequest.h:34
zypp::callback::UserData UserData
Definition userrequest.h:18
#define ZYPP_ADD_CREATE_FUNC(Class)
Definition zyppglobal.h:205
#define ZYPP_FWD_DECL_TYPE_WITH_REFS(T)
Definition zyppglobal.h:126