addon/info.hpp

Go to the documentation of this file.
00001 /* $Id: info.hpp 54222 2012-05-19 09:13:28Z shadowmaster $ */
00002 /*
00003    Copyright (C) 2010 - 2012 by Ignacio R. 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 #ifndef ADDON_INFO_HPP_INCLUDED
00017 #define ADDON_INFO_HPP_INCLUDED
00018 
00019 #include "config.hpp"
00020 #include "version.hpp"
00021 
00022 #include "addon/validation.hpp"
00023 
00024 #include <set>
00025 
00026 struct addon_info;
00027 typedef std::map<std::string, addon_info> addons_list;
00028 
00029 struct addon_info
00030 {
00031     std::string id;
00032     std::string title;
00033     std::string description;
00034 
00035     std::string icon;
00036 
00037     version_info version;
00038 
00039     std::string author;
00040 
00041     int size;
00042     int downloads;
00043     int uploads;
00044 
00045     ADDON_TYPE type;
00046 
00047     std::vector<std::string> locales;
00048 
00049     std::vector<std::string> depends;
00050     // std::vector<addon_dependency> conflicts, recommends, replaces;
00051 
00052     addon_info()
00053         : id(), title(), description(), icon()
00054         , version(), author(), size(), downloads()
00055         , uploads(), type(), locales()
00056         , depends()
00057     {}
00058 
00059     explicit addon_info(const config& cfg)
00060         : id(), title(), description(), icon()
00061         , version(), author(), size(), downloads()
00062         , uploads(), type(), locales()
00063         , depends()
00064     {
00065         this->read(cfg);
00066     }
00067 
00068     addon_info& operator=(const addon_info& o) {
00069         if(this != &o) {
00070             this->id = o.id;
00071             this->title = o.title;
00072             this->description = o.description;
00073             this->icon = o.icon;
00074             this->version = o.version;
00075             this->author = o.author;
00076             this->size = o.size;
00077             this->downloads = o.downloads;
00078             this->uploads = o.uploads;
00079             this->type = o.type;
00080             this->locales = o.locales;
00081             this->depends = o.depends;
00082         }
00083         return *this;
00084     }
00085 
00086     void read(const config& cfg);
00087 
00088     void write(config& cfg) const;
00089 
00090     /**
00091      * Write only minimal WML used for state tracking (_info.cfg) files.
00092      *
00093      * This currently only includes the add-on type, upload count,
00094      * and version number.
00095      *
00096      * @param cfg Target WML config object.
00097      */
00098     void write_minimal(config& cfg) const;
00099 
00100     /**
00101      * Get a title or automatic title for display.
00102      *
00103      * If the real @a title is empty, the returned value is the @a id with
00104      * underscores replaced with blanks.
00105      *
00106      * @todo FIXME: Is it even possible for the add-ons server to provide untitled
00107      *       add-ons in its reply anymore? Titles seem to be required at upload time.
00108      */
00109     std::string display_title() const;
00110 
00111     /** Get an icon path fixed for display (e.g. when TC is missing, or the image doesn't exist). */
00112     std::string display_icon() const;
00113 
00114     /** Get an add-on type identifier for display in the user's language. */
00115     std::string display_type() const;
00116 
00117     /**
00118      * Resolve an add-on's dependency tree in a recursive fashion.
00119      *
00120      * The returned vector contains the list of resolved dependencies for this
00121      * and any other add-ons upon which it depends.
00122      *
00123      * @param addons     The add-ons list.
00124      *
00125      * @todo Tag resolved dependencies with information about where they come from,
00126      *       and implement more dependency tiers.
00127      */
00128     std::set<std::string> resolve_dependencies(const addons_list& addons) const;
00129 };
00130 
00131 /**
00132  * Parse the specified add-ons list WML into an actual addons_list object.
00133  *
00134  * @param cfg  Add-ons list WML, currently a [campaigns] node from a server response.
00135  * @param dest Target addons_list object. It will be cleared first.
00136  */
00137 void read_addons_list(const config& cfg, addons_list& dest);
00138 
00139 /**
00140  * Get a human-readable representation of the specified byte count.
00141  *
00142  * The result includes the size unit, which is the largest byte multiply
00143  * that makes sense. (e.g. 1 MiB for 1048576 bytes.)
00144  */
00145 std::string size_display_string(double size);
00146 
00147 /**
00148  * Replaces underscores to dress up file or dirnames as add-on titles.
00149  *
00150  * @todo In the future we should store more local information about add-ons and use
00151  *       this only as a fallback; it could be desirable to fetch translated names as well
00152  *       somehow.
00153  */
00154 std::string make_addon_title(const std::string& id);
00155 
00156 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

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