The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
info.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2010 - 2016 by Ignacio R. 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 
15 #ifndef ADDON_INFO_HPP_INCLUDED
16 #define ADDON_INFO_HPP_INCLUDED
17 
18 #include "version.hpp"
19 
20 #include "addon/validation.hpp"
21 
22 #include <set>
23 #include <map>
24 
25 struct addon_info;
26 class config;
27 typedef std::map<std::string, addon_info> addons_list;
28 
29 struct addon_info
30 {
34 
36 
38 
40 
41  int size;
42  int downloads;
43  int uploads;
44 
46 
47  std::vector<std::string> locales;
48 
50 
51  std::vector<std::string> depends;
52  // std::vector<addon_dependency> conflicts, recommends, replaces;
53 
55 
56  time_t updated;
57  time_t created;
58 
59  // Artificial upload order index used to preserve add-ons upload order
60  // until we have actual first-upload timestamps implemented. This index
61  // is not serialized anywhere.
62  unsigned order;
63 
65  : id(), title(), description(), icon()
66  , version(), author(), size(), downloads()
67  , uploads(), type(), locales()
68  , core()
69  , depends()
70  , feedback_url()
71  , updated()
72  , created()
73  , order()
74  {}
75 
76  explicit addon_info(const config& cfg)
77  : id(), title(), description(), icon()
78  , version(), author(), size(), downloads()
79  , uploads(), type(), locales()
80  , core()
81  , depends()
82  , feedback_url()
83  , updated()
84  , created()
85  , order()
86  {
87  this->read(cfg);
88  }
89 
91  if(this != &o) {
92  this->id = o.id;
93  this->title = o.title;
94  this->description = o.description;
95  this->icon = o.icon;
96  this->version = o.version;
97  this->author = o.author;
98  this->size = o.size;
99  this->downloads = o.downloads;
100  this->uploads = o.uploads;
101  this->type = o.type;
102  this->locales = o.locales;
103  this->core = o.core;
104  this->depends = o.depends;
105  this->feedback_url = o.feedback_url;
106  this->updated = o.updated;
107  this->created = o.created;
108  this->order = o.order;
109  }
110  return *this;
111  }
112 
113  void read(const config& cfg);
114 
115  void write(config& cfg) const;
116 
117  /**
118  * Write only minimal WML used for state tracking (_info.cfg) files.
119  *
120  * This currently only includes the add-on type, upload count,
121  * title, and version number.
122  *
123  * @param cfg Target WML config object.
124  */
125  void write_minimal(config& cfg) const;
126 
127  /**
128  * Get a title or automatic title for display.
129  *
130  * If the real @a title is empty, the returned value is the @a id with
131  * underscores replaced with blanks.
132  *
133  * @todo FIXME: Is it even possible for the add-ons server to provide untitled
134  * add-ons in its reply anymore? Titles seem to be required at upload time.
135  */
136  std::string display_title() const;
137 
138  /** Get an icon path fixed for display (e.g. when TC is missing, or the image doesn't exist). */
139  std::string display_icon() const;
140 
141  /** Get an add-on type identifier for display in the user's language. */
142  std::string display_type() const;
143 
144  /**
145  * Resolve an add-on's dependency tree in a recursive fashion.
146  *
147  * The returned vector contains the list of resolved dependencies for this
148  * and any other add-ons upon which it depends.
149  *
150  * @param addons The add-ons list.
151  *
152  * @todo Tag resolved dependencies with information about where they come from,
153  * and implement more dependency tiers.
154  */
155  std::set<std::string> resolve_dependencies(const addons_list& addons) const;
156 };
157 
158 /**
159  * Parse the specified add-ons list WML into an actual addons_list object.
160  *
161  * @param cfg Add-ons list WML, currently a [campaigns] node from a server response.
162  * @param dest Target addons_list object. It will be cleared first.
163  */
164 void read_addons_list(const config& cfg, addons_list& dest);
165 
166 /**
167  * Get a human-readable representation of the specified byte count.
168  *
169  * The result includes the size unit, which is the largest byte multiply
170  * that makes sense. (e.g. 1 MiB for 1048576 bytes.)
171  */
173 
174 /**
175  * Replaces underscores to dress up file or dirnames as add-on titles.
176  *
177  * @todo In the future we should store more local information about add-ons and use
178  * this only as a fallback; it could be desirable to fetch translated names as well
179  * somehow.
180  */
182 
183 #endif
int size
Definition: info.hpp:41
ADDON_TYPE
Values used for add-on classification; UI-only at the moment, in the future it could be used for dire...
Definition: validation.hpp:41
addon_info & operator=(const addon_info &o)
Definition: info.hpp:90
std::string description
Definition: info.hpp:33
addon_info(const config &cfg)
Definition: info.hpp:76
std::string feedback_url
Definition: info.hpp:54
time_t created
Definition: info.hpp:57
unsigned order
Definition: info.hpp:62
void write_minimal(config &cfg) const
Write only minimal WML used for state tracking (_info.cfg) files.
Definition: info.cpp:114
std::string make_addon_title(const std::string &id)
Replaces underscores to dress up file or dirnames as add-on titles.
Definition: info.cpp:228
std::string display_title() const
Get a title or automatic title for display.
Definition: info.cpp:124
std::map< std::string, addon_info > addons_list
Definition: info.hpp:26
std::string id
Definition: info.hpp:31
addon_info()
Definition: info.hpp:64
ADDON_TYPE type
Definition: info.hpp:45
std::string display_icon() const
Get an icon path fixed for display (e.g.
Definition: info.cpp:133
void read(const config &cfg)
Definition: info.cpp:62
std::vector< std::string > locales
Definition: info.hpp:47
std::string icon
Definition: info.hpp:35
std::string display_type() const
Get an add-on type identifier for display in the user's language.
Definition: info.cpp:154
int uploads
Definition: info.hpp:43
std::string size_display_string(double size)
Get a human-readable representation of the specified byte count.
Definition: info.cpp:219
Represents version numbers.
Definition: version.hpp:44
void write(config &cfg) const
Definition: info.cpp:89
GLsizeiptr size
Definition: glew.h:1649
std::vector< std::string > depends
Definition: info.hpp:51
std::string title
Definition: info.hpp:32
version_info version
Definition: info.hpp:37
int downloads
Definition: info.hpp:42
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:83
Interfaces for manipulating version numbers of engine, add-ons, etc.
GLsizei const GLcharARB ** string
Definition: glew.h:4503
std::set< std::string > resolve_dependencies(const addons_list &addons) const
Resolve an add-on's dependency tree in a recursive fashion.
Definition: info.cpp:186
std::string author
Definition: info.hpp:39
time_t updated
Definition: info.hpp:56
void read_addons_list(const config &cfg, addons_list &dest)
Parse the specified add-ons list WML into an actual addons_list object.
std::string core
Definition: info.hpp:49