Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
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
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056 REGISTER_DIALOG(addon_uninstall_list)
00057
00058 void taddon_uninstall_list::pre_show(CVideo& , 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 }