gui/dialogs/addon/description.cpp

Go to the documentation of this file.
00001 /* $Id: description.cpp 54278 2012-05-21 04:06:46Z 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 #define GETTEXT_DOMAIN "wesnoth-lib"
00017 
00018 #include "gui/dialogs/addon/description.hpp"
00019 
00020 #include "foreach.hpp"
00021 #include "formula_string_utils.hpp"
00022 #include "gettext.hpp"
00023 #include "gui/widgets/settings.hpp"
00024 #include "language.hpp"
00025 
00026 namespace {
00027     std::string langcode_to_string(const std::string& lcode)
00028     {
00029         foreach(const language_def& ld, get_languages()) {
00030             if(ld.localename == lcode || ld.localename.substr(0, 2) == lcode) {
00031                 return ld.language;
00032             }
00033         }
00034 
00035         return "";
00036     }
00037 
00038     std::string describe_addon_state_info(const addon_tracking_info& state)
00039     {
00040         std::string s;
00041 
00042         utils::string_map i18n_symbols;
00043         i18n_symbols["local_version"] = state.installed_version.str();
00044 
00045         switch(state.state) {
00046         case ADDON_NONE:
00047             if(!state.can_publish) {
00048                 s += _("addon_state^Not installed");
00049             } else {
00050                 s += _("addon_state^Published, not installed");
00051             }
00052             break;
00053         case ADDON_INSTALLED:
00054             s += "<span color='green'>";
00055             if(!state.can_publish) {
00056                 s += _("addon_state^Installed");
00057             } else {
00058                 s += _("addon_state^Published");
00059             }
00060             s += "</span>";
00061             break;
00062         case ADDON_NOT_TRACKED:
00063             s += "<span color='green'>";
00064             if(!state.can_publish) {
00065                 s += _("addon_state^Installed, not tracking local version");
00066             } else {
00067                 // Published add-ons often don't have local status information,
00068                 // hence untracked. This should be considered normal.
00069                 s += _("addon_state^Published, not tracking local version");
00070             }
00071             s += "</span>";
00072             break;
00073         case ADDON_INSTALLED_UPGRADABLE:
00074             s += "<span color='yellow'>";
00075             {
00076                 const char* const vstr = !state.can_publish
00077                     ? _("addon_state^Installed ($local_version|), upgradable")
00078                     : _("addon_state^Published ($local_version| installed), upgradable");
00079                 s += utils::interpolate_variables_into_string(vstr, &i18n_symbols);
00080             }
00081             s += "</span>";
00082             break;
00083         case ADDON_INSTALLED_OUTDATED:
00084             s += "<span color='orange'>";
00085             {
00086                 const char* const vstr = !state.can_publish
00087                     ? _("addon_state^Installed ($local_version|), outdated on server")
00088                     : _("addon_state^Published ($local_version| installed), outdated on server");
00089                 s += utils::interpolate_variables_into_string(vstr, &i18n_symbols);
00090             }
00091             s += "</span>";
00092             break;
00093         case ADDON_INSTALLED_BROKEN:
00094             s += "<span color='red'>";
00095             if(!state.can_publish) {
00096                 s += _("addon_state^Installed, broken");
00097             } else {
00098                 s += _("addon_state^Published, broken");
00099             }
00100             s += "</span>";
00101             break;
00102         default:
00103             s += "<span color='gray'>";
00104             s += _("addon_state^Unknown");
00105             s += "</span>";
00106         }
00107 
00108         return s;
00109     }
00110 }
00111 
00112 namespace gui2 {
00113 
00114 /*WIKI
00115  * @page = GUIWindowDefinitionWML
00116  * @order = 2_addon_description
00117  *
00118  * == Add-on description ==
00119  *
00120  * Add-on description and details for the add-ons manager interface.
00121  *
00122  * @begin{table}{dialog_widgets}
00123  *
00124  * image & & control & m &
00125  *         Label for displaying the add-on icon, in a 72x72 area. $
00126  *
00127  * title & & control & m &
00128  *         Dialog title label, corresponding to the add-on name. $
00129  *
00130  * type & & control & m &
00131  *         Label for displaying the add-on's type. $
00132  *
00133  * version & & control & m &
00134  *         Label for displaying the add-on version number. $
00135  *
00136  * status & & control & m &
00137  *         Label for displaying the current installation/upgradability status. $
00138  *
00139  * author & & control & m &
00140  *         Label for displaying the add-on author/maintainer name. $
00141  *
00142  * size & & control & m &
00143  *         Label for displaying the add-on package size. $
00144  *
00145  * downloads & & control & m &
00146  *         Label for displaying the add-on's download count. $
00147  *
00148  * description & & control & m &
00149  *         Text label for displaying the add-on's description. The control can
00150  *         be given a text, this text is shown when the addon has no
00151  *         description. If the addon has a description this field shows the
00152  *         description of the addon. $
00153  *
00154  * translations & & control & m &
00155  *         Label for displaying a list of translations provided by the add-on.
00156  *         Like the ''description'' it can also show a default text if no
00157  *         translations are available. $
00158  *
00159  * @end{table}
00160  */
00161 
00162 REGISTER_DIALOG(addon_description)
00163 
00164 taddon_description::taddon_description(const addon_info& addon, const addon_tracking_info& state)
00165 {
00166     register_label("image", true, addon.display_icon());
00167     register_label("title", true, addon.title);
00168     register_label("version", true, addon.version);
00169     register_label("status", true, describe_addon_state_info(state), true);
00170     register_label("author", true, addon.author);
00171     register_label("type", true, addon.display_type());
00172     register_label("size", true, size_display_string(addon.size));
00173     register_label("downloads", true, str_cast(addon.downloads));
00174     if(!addon.description.empty()) {
00175         register_label("description", true, addon.description);
00176     }
00177 
00178     std::string languages;
00179 
00180     foreach(const std::string& lc, addon.locales) {
00181         const std::string& langlabel = langcode_to_string(lc);
00182         if(!langlabel.empty()) {
00183             if(!languages.empty()) {
00184                 languages += ", ";
00185             }
00186             languages += langlabel;
00187         }
00188     }
00189 
00190     if(!languages.empty()) {
00191         register_label("translations", true, languages);
00192     }
00193 }
00194 
00195 } // namespace  gui2
00196 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated by doxygen 1.7.1 on Thu May 24 2012 01:02:42 for The Battle for Wesnoth
Gna! | Forum | Wiki | CIA | devdocs