Polish the taddon_connect class.

This commit is contained in:
Mark de Wever 2011-03-13 19:18:34 +00:00
parent 642ae5ecb5
commit 2bc198b8fd
4 changed files with 43 additions and 48 deletions

View file

@ -1427,19 +1427,14 @@ void manage_addons(game_display& disp)
{
int res;
bool do_refresh = false;
std::string remote_host;
const std::string default_host = preferences::campaign_server();
std::string host_name = preferences::campaign_server();
const bool have_addons = !installed_addons().empty();
gui2::taddon_connect addon_dlg;
gui2::taddon_connect addon_dlg(host_name, have_addons, have_addons);
addon_dlg.set_host_name(default_host);
addon_dlg.set_allow_remove(have_addons);
addon_dlg.set_allow_updates(have_addons);
addon_dlg.show(disp.video());
res = addon_dlg.get_retval();
remote_host = addon_dlg.host_name();
if(res == gui2::twindow::OK) {
res = addon_download;
@ -1448,7 +1443,7 @@ void manage_addons(game_display& disp)
switch(res) {
case addon_update:
case addon_download:
download_addons(disp, remote_host, res==addon_update, &do_refresh);
download_addons(disp, host_name, res==addon_update, &do_refresh);
break;
case addon_uninstall:
uninstall_local_addons(disp, &do_refresh);

View file

@ -47,29 +47,31 @@ namespace gui2 {
REGISTER_DIALOG(addon_connect)
taddon_connect::taddon_connect(std::string& host_name
, const bool allow_updates
, const bool allow_remove)
: allow_updates_(allow_updates)
, allow_remove_(allow_remove)
{
register_text2("host_name", false, host_name, true);
}
void taddon_connect::pre_show(CVideo& /*video*/, twindow& window)
{
ttext_box& host_widget =
find_widget<ttext_box>(&window, "host_name", false);
tbutton& update_cmd =
find_widget<tbutton>(&window, "update_addons", false);
update_cmd.set_active(allow_updates_);
tbutton& remove_cmd =
find_widget<tbutton>(&window, "remove_addons", false);
remove_cmd.set_active(allow_remove_);
find_widget<tbutton>(&window, "update_addons", false)
.set_active(allow_updates_);
host_widget.set_value(host_name_);
window.keyboard_capture(&host_widget);
find_widget<tbutton>(&window, "remove_addons", false)
.set_active(allow_remove_);
}
void taddon_connect::post_show(twindow& window)
{
if(get_retval() == twindow::OK) {
if(get_retval() == twindow::OK || get_retval() == 3) {
ttext_box& host_widget =
find_widget<ttext_box>(&window, "host_name", false);
host_widget.save_to_history();
host_name_= host_widget.get_value();
}
}

View file

@ -25,38 +25,26 @@ class taddon_connect
: public tdialog
{
public:
taddon_connect()
: host_name_()
, allow_updates_()
, allow_remove_()
{
}
bool allow_updates() const { return allow_updates_; }
void set_allow_updates(bool allow_updates)
{
allow_updates_ = allow_updates;
}
bool allow_remove() const { return allow_remove_; }
void set_allow_remove(bool allow_remove)
{
allow_remove_ = allow_remove;
}
const std::string& host_name() const { return host_name_; }
void set_host_name(const std::string& host_name)
{
host_name_ = host_name;
}
/**
* Constructor.
*
* @param host_name [in] The initial value for the host_name.
* @param host_name [out] The final value of the host_name if the
* dialog returns @ref twindow::OK or 3
* undefined otherwise.
* @param allow_updates Sets @ref allow_updates_.
* @param allow_remove Sets @ref allow_remove_.
*/
taddon_connect(std::string& host_name
, const bool allow_updates
, const bool allow_remove);
private:
std::string host_name_;
/** Enable the update addon button? */
bool allow_updates_;
/** Enable the addon remove button? */
bool allow_remove_;
/** Inherited from tdialog, implemented by REGISTER_DIALOG. */

View file

@ -425,6 +425,16 @@ BOOST_AUTO_TEST_CASE(test_make_test_fake)
namespace {
template<>
struct twrapper<gui2::taddon_connect>
{
static gui2::taddon_connect* create()
{
static std::string host_name = "host_name";
return new gui2::taddon_connect(host_name, true, true);
}
};
template<>
struct twrapper<gui2::taddon_list>
{