gui/dialogs/addon/uninstall_list.cpp

Go to the documentation of this file.
00001 /* $Id: uninstall_list.cpp 53335 2012-02-29 20:41:19Z shadowmaster $ */
00002 /*
00003    Copyright (C) 2011 - 2012 by Ignacio Riquelme Morelle <shadowm2006@gmail.com>
00004    Part of the Battle for Wesnoth Project http://www.wesnoth.org/
00005 
00006    This program is free software; you can redistribute it and/or modify
00007    it under the terms of the GNU General Public License as published by
00008    the Free Software Foundation; either version 2 of the License, or
00009    (at your option) any later version.
00010    This program is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY.
00012 
00013    See the COPYING file for more details.
00014 */
00015 
00016 #include "gui/dialogs/addon/uninstall_list.hpp"
00017 
00018 #include "addon/info.hpp"
00019 #include "foreach.hpp"
00020 #include "gui/widgets/grid.hpp"
00021 #ifdef GUI2_EXPERIMENTAL_LISTBOX
00022     #include "gui/widgets/list.hpp"
00023 #else
00024     #include "gui/widgets/listbox.hpp"
00025 #endif
00026 #include "gui/widgets/settings.hpp"
00027 #include "gui/widgets/toggle_button.hpp"
00028 #include "gui/widgets/window.hpp"
00029 
00030 #include <algorithm>
00031 
00032 namespace gui2 {
00033 
00034 /*WIKI
00035  * @page = GUIWindowDefinitionWML
00036  * @order = 2_addon_uninstall_list
00037  *
00038  * == Add-on uninstall list ==
00039  *
00040  * Dialog with a checkbox list for choosing installed add-ons to remove.
00041  *
00042  * @begin{table}{dialog_widgets}
00043  *
00044  * addons_list & & listbox & m &
00045  *     A listbox containing add-on selection entries. $
00046  *
00047  * -checkbox & & toggle_button & m &
00048  *     A toggle button allowing the user to mark/unmark the add-on. $
00049  *
00050  * -name & & control & o &
00051  *     The name of the add-on. $
00052  *
00053  * @end{table}
00054  */
00055 
00056 REGISTER_DIALOG(addon_uninstall_list)
00057 
00058 void taddon_uninstall_list::pre_show(CVideo& /*video*/, twindow& window)
00059 {
00060     tlistbox& list = find_widget<tlistbox>(&window, "addons_list", false);
00061     window.keyboard_capture(&list);
00062 
00063     this->names_.clear();
00064     this->selections_.clear();
00065 
00066     foreach(const std::string& id, this->ids_) {
00067         this->names_.push_back(make_addon_title(id));
00068         this->selections_[id] = false;
00069 
00070         std::map<std::string, string_map> data;
00071         string_map column;
00072 
00073         column["label"] = this->names_.back();
00074         data.insert(std::make_pair("name", column));
00075         list.add_row(data);
00076     }
00077 }
00078 
00079 void taddon_uninstall_list::post_show(twindow& window)
00080 {
00081     const tlistbox& list = find_widget<tlistbox>(&window, "addons_list", false);
00082     const unsigned rows = list.get_item_count();
00083 
00084     assert(rows == this->ids_.size() && rows == this->names_.size());
00085 
00086     if(!rows || get_retval() != twindow::OK) {
00087         return;
00088     }
00089 
00090     for(unsigned k = 0; k < rows; ++k) {
00091         tgrid const* g = list.get_row_grid(k);
00092         const ttoggle_button& checkbox = find_widget<const ttoggle_button>(g, "checkbox", false);
00093         this->selections_[this->ids_[k]] = checkbox.get_value();
00094     }
00095 
00096 }
00097 
00098 std::vector<std::string> taddon_uninstall_list::selected_addons() const
00099 {
00100     std::vector<std::string> retv;
00101 
00102     typedef std::map<std::string, bool> selections_map_type;
00103     foreach(const selections_map_type::value_type& entry, this->selections_) {
00104         if(entry.second) {
00105             retv.push_back(entry.first);
00106         }
00107     }
00108 
00109     return retv;
00110 }
00111 
00112 
00113 } // namespace gui2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated by doxygen 1.7.1 on Fri May 25 2012 01:02:57 for The Battle for Wesnoth
Gna! | Forum | Wiki | CIA | devdocs