Author: mordante
Date: Sun Mar 13 20:18:34 2011
New Revision: 48899
URL: http://svn.gna.org/viewcvs/wesnoth?rev=48899&view=rev
Log:
Polish the taddon_connect class.
Modified:
trunk/src/addon/manager.cpp
trunk/src/gui/dialogs/addon_connect.cpp
trunk/src/gui/dialogs/addon_connect.hpp
trunk/src/tests/gui/test_gui2.cpp
Modified: trunk/src/addon/manager.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/addon/manager.cpp?rev=48899&r1=48898&r2=48899&view=diff
==============================================================================
--- trunk/src/addon/manager.cpp (original)
+++ trunk/src/addon/manager.cpp Sun Mar 13 20:18:34 2011
@@ -1427,19 +1427,14 @@
{
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;
-
- addon_dlg.set_host_name(default_host);
- addon_dlg.set_allow_remove(have_addons);
- addon_dlg.set_allow_updates(have_addons);
+ gui2::taddon_connect addon_dlg(host_name, have_addons, 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 @@
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);
Modified: trunk/src/gui/dialogs/addon_connect.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/dialogs/addon_connect.cpp?rev=48899&r1=48898&r2=48899&view=diff
==============================================================================
--- trunk/src/gui/dialogs/addon_connect.cpp (original)
+++ trunk/src/gui/dialogs/addon_connect.cpp Sun Mar 13 20:18:34 2011
@@ -47,29 +47,31 @@
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();
}
}
Modified: trunk/src/gui/dialogs/addon_connect.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/dialogs/addon_connect.hpp?rev=48899&r1=48898&r2=48899&view=diff
==============================================================================
--- trunk/src/gui/dialogs/addon_connect.hpp (original)
+++ trunk/src/gui/dialogs/addon_connect.hpp Sun Mar 13 20:18:34 2011
@@ -25,38 +25,26 @@
: 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. */
Modified: trunk/src/tests/gui/test_gui2.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/tests/gui/test_gui2.cpp?rev=48899&r1=48898&r2=48899&view=diff
==============================================================================
--- trunk/src/tests/gui/test_gui2.cpp (original)
+++ trunk/src/tests/gui/test_gui2.cpp Sun Mar 13 20:18:34 2011
@@ -426,6 +426,16 @@
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>
{
static gui2::taddon_list* create()
_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits