libzypp: zypp-core/ng/ui/userrequest.cc Source File

libzypp 17.38.14

userrequest.cc
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8\---------------------------------------------------------------------*/
9#include "userrequest.h"
10#include <string>
11#include <utility>
12
13namespace zyppng
14{
15 UserRequest::UserRequest( UserData userData )
16 : _userData( std::move(userData) )
17 { }
18
19 UserRequest::~UserRequest()
20 { }
21
22 const UserData &UserRequest::userData() const
23 {
24 return _userData;
25 }
26
27 UserData &UserRequest::userData()
28 {
29 return _userData;
30 }
31
32 ZYPP_IMPL_PRIVATE_CONSTR_ARGS(ShowMessageRequest, std::string message, MType mType, UserData data )
33 : UserRequest( std::move(data) )
34 , _type( mType )
35 , _message( std::move(message) )
36 { }
37
38 UserRequestType ShowMessageRequest::type() const
39 {
40 return UserRequestType::Message;
41 }
42
43 ShowMessageRequest::MType ShowMessageRequest::messageType()
44 {
45 return _type;
46 }
47
48 const std::string &ShowMessageRequest::message() const
49 {
50 return _message;
51 }
52
53 ZYPP_IMPL_PRIVATE_CONSTR_ARGS(ListChoiceRequest, std::string label, std::vector<Choice> answers, index_type defaultAnswer, UserData userData )
54 : UserRequest( std::move(userData) )
55 , _label( std::move(label) )
56 , _answers( std::move(answers) )
57 , _answer( std::move(defaultAnswer) )
58 , _default( std::move(defaultAnswer) )
59 { }
60
61 UserRequestType ListChoiceRequest::type() const
62 {
63 return UserRequestType::ListChoice;
64 }
65
66 const std::string &ListChoiceRequest::label() const
67 {
68 return _label;
69 }
70
71 void ListChoiceRequest::setChoice(const index_type sel )
72 {
73 if ( sel >= _answers.size() )
74 ZYPP_THROW( std::logic_error("Selection index is out of range") );
75 _answer = sel;
76 }
77
78 ListChoiceRequest::index_type ListChoiceRequest::choice() const
79 {
80 return _answer;
81 }
82
83 ListChoiceRequest::index_type ListChoiceRequest::defaultAnswer() const
84 {
85 return _default;
86 }
87
88 const std::vector<ListChoiceRequest::Choice> &ListChoiceRequest::answers() const
89 {
90 return _answers;
91 }
92
93 ZYPP_IMPL_PRIVATE_CONSTR_ARGS(BooleanChoiceRequest, std::string label, const bool defaultAnswer, UserData userData )
94 : UserRequest( std::move(userData) )
95 , _label( std::move(label) )
96 , _answer( defaultAnswer )
97 { }
98
99 UserRequestType BooleanChoiceRequest::type() const
100 {
101 return UserRequestType::BooleanChoice;
102 }
103
104 const std::string &BooleanChoiceRequest::label() const
105 {
106 return _label;
107 }
108
109 void BooleanChoiceRequest::setChoice(const bool sel)
110 {
111 _answer = sel;
112 }
113
114 bool BooleanChoiceRequest::choice() const
115 {
116 return _answer;
117 }
118
119}
ZYPP_THROW
#define ZYPP_THROW(EXCPT)
Drops a logline and throws the Exception.
Definition Exception.h:459
zyppng::BooleanChoiceRequest
Definition userrequest.h:154
zyppng::BooleanChoiceRequest::_answer
bool _answer
Definition userrequest.h:168
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::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::_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::_userData
UserData _userData
Definition userrequest.h:58
std
Definition ansi.h:855
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::UserData
zypp::callback::UserData UserData
Definition userrequest.h:18
zyppng::ZYPP_IMPL_PRIVATE_CONSTR_ARGS
ZYPP_IMPL_PRIVATE_CONSTR_ARGS(TrustKeyRequest, std::string label, KeyTrust trust, UserData userData)
Definition userrequest.cc:34
userrequest.h