The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
uninstall_list.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2011 - 2016 by Ignacio Riquelme Morelle <[email protected]>
3  Part of the Battle for Wesnoth Project http://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
16 
18 #include "gui/widgets/grid.hpp"
19 #ifdef GUI2_EXPERIMENTAL_LISTBOX
20 #include "gui/widgets/list.hpp"
21 #else
22 #include "gui/widgets/listbox.hpp"
23 #endif
24 #include "gui/widgets/settings.hpp"
26 #include "gui/widgets/window.hpp"
27 
28 #include <algorithm>
29 
30 namespace gui2
31 {
32 
33 /*WIKI
34  * @page = GUIWindowDefinitionWML
35  * @order = 2_addon_uninstall_list
36  *
37  * == Add-on uninstall list ==
38  *
39  * Dialog with a checkbox list for choosing installed add-ons to remove.
40  *
41  * @begin{table}{dialog_widgets}
42  *
43  * addons_list & & listbox & m &
44  * A listbox containing add-on selection entries. $
45  *
46  * -checkbox & & toggle_button & m &
47  * A toggle button allowing the user to mark/unmark the add-on. $
48  *
49  * -name & & control & o &
50  * The name of the add-on. $
51  *
52  * @end{table}
53  */
54 
55 REGISTER_DIALOG(addon_uninstall_list)
56 
58 {
59  tlistbox& list = find_widget<tlistbox>(&window, "addons_list", false);
60  window.keyboard_capture(&list);
61 
62  this->selections_.clear();
63 
64  for(const auto & entry : titles_map_)
65  {
66  const std::string& id = entry.first;
67  const std::string& title = entry.second;
68 
69  this->ids_.push_back(id);
70  this->selections_[id] = false;
71 
72  std::map<std::string, string_map> data;
74 
75  column["label"] = title;
76  data.insert(std::make_pair("name", column));
77  list.add_row(data);
78  }
79 }
80 
82 {
83  const tlistbox& list = find_widget<tlistbox>(&window, "addons_list", false);
84  const unsigned rows = list.get_item_count();
85 
86  assert(rows == this->ids_.size() && rows == this->titles_map_.size());
87 
88  if(!rows || get_retval() != twindow::OK) {
89  return;
90  }
91 
92  for(unsigned k = 0; k < rows; ++k) {
93  tgrid const* g = list.get_row_grid(k);
94  const ttoggle_button& checkbox
95  = find_widget<const ttoggle_button>(g, "checkbox", false);
96  this->selections_[this->ids_[k]] = checkbox.get_value_bool();
97  }
98 }
99 
100 std::vector<std::string> taddon_uninstall_list::selected_addons() const
101 {
102  std::vector<std::string> retv;
103 
104  for(const auto & entry : selections_)
105  {
106  if(entry.second) {
107  retv.push_back(entry.first);
108  }
109  }
110 
111  return retv;
112 }
113 
114 
115 } // namespace gui2
GLvoid **typedef void(GLAPIENTRY *PFNGLGETVERTEXATTRIBDVPROC)(GLuint
Definition: glew.h:1806
int get_retval() const
Definition: dialog.hpp:161
Base container class.
Definition: grid.hpp:29
This file contains the window object, this object is a top level container which has the event manage...
REGISTER_DIALOG(label_settings)
std::vector< std::string > ids_
GLboolean GLboolean g
Definition: glew.h:7319
void post_show(twindow &window)
Inherited from tdialog.
GLint GLenum GLsizei GLint GLsizei const GLvoid * data
Definition: glew.h:1347
base class of top level items, the only item which needs to store the final canvases to draw on ...
Definition: window.hpp:62
Class for a toggle button.
A class inherited from ttext_box that displays its input as stars.
Definition: field-fwd.hpp:23
Dialog is closed with ok button.
Definition: window.hpp:125
This file contains the settings handling of the widget library.
unsigned get_item_count() const
Returns the number of items in the listbox.
Definition: listbox.cpp:138
void add_row(const string_map &item, const int index=-1)
When an item in the list is selected by the user we need to update the state.
Definition: listbox.cpp:74
bool get_value_bool() const
Definition: selectable.hpp:48
static size_t id
Ids for the timers.
Definition: timer.cpp:39
std::map< std::string, t_string > string_map
Definition: generator.hpp:23
GLenum GLenum GLvoid GLvoid * column
Definition: glew.h:3805
The listbox class.
Definition: listbox.hpp:39
#define g
Definition: glew.h:12730
std::map< std::string, bool > selections_
GLsizei const GLcharARB ** string
Definition: glew.h:4503
void clear()
Removes all the rows in the listbox, clearing it.
Definition: listbox.cpp:131
const tgrid * get_row_grid(const unsigned row) const
Returns the grid of the wanted row.
Definition: listbox.cpp:215
std::vector< std::string > selected_addons() const
std::map< std::string, std::string > titles_map_