-
Notifications
You must be signed in to change notification settings - Fork 3
/
Settings.cpp
executable file
·84 lines (68 loc) · 2.32 KB
/
Settings.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
//
// Copyright 2015 CutePoisonX ([email protected])
//
// This file is part of PoisonConvert.
//
// PoisonConvert is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// PoisonConvert is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with PoisonConvert. If not, see <http://www.gnu.org/licenses/>.
//
#include "Settings.h"
#include "UserInterface.h"
Settings::Settings(UserInterface ui, string name, string description,
string settings_change_prompt, string default_param)
: ui_(ui), settings_name_(name), settings_description_(description),
settings_change_prompt_(settings_change_prompt), settings_param_(default_param), settings_default_param_(default_param)
{
}
Settings::Settings(const Settings& orig)
: ui_(orig.ui_), settings_name_(orig.settings_name_), settings_description_(orig.settings_description_),
settings_change_prompt_(orig.settings_change_prompt_), settings_param_(orig.settings_param_)
{
}
Settings::~Settings()
{
}
string const Settings::setParam()
{
string new_param;
ui_.writeString(settings_change_prompt_, true, "green");
do
{
new_param = ui_.readString();
if (new_param == "exit")
{
return settings_param_;
}
} while (checkParam(new_param, true) == PARAM_CHANGE_ERROR);
attemptToChangeParam(new_param);
ui_.writeString("Saved.", true, "green");
ui_.readString(false);
return settings_param_;
}
Settings::PARAM_CHANGE_RETURN Settings::setParamSilent(string const& new_param, bool force_change)
{
PARAM_CHANGE_RETURN param_change_ret = checkParam(new_param, false);
if (param_change_ret == PARAM_CHANGE_SUCCESS || force_change)
{
attemptToChangeParam(new_param);
}
return param_change_ret;
}
void Settings::attemptToChangeParam(string new_param)
{
changeParam(new_param);
}
void Settings::changeParam(string const& new_param)
{
settings_param_ = new_param;
}