From c7ad8d093591214a32cacc79fa25d8e118493093 Mon Sep 17 00:00:00 2001
From: Andrei Karas <akaras@inbox.ru>
Date: Thu, 18 Oct 2012 19:02:04 +0300
Subject: Add button in themes to show additional theme info.

---
 data/graphics/gui/CMakeLists.txt       |  1 +
 data/graphics/gui/Makefile.am          |  1 +
 data/graphics/gui/info.xml             |  4 ++++
 data/themes/blacknblack/CMakeLists.txt |  1 +
 data/themes/blacknblack/Makefile.am    |  1 +
 data/themes/blacknblack/info.xml       |  4 ++++
 data/themes/blackwood/CMakeLists.txt   |  1 +
 data/themes/blackwood/Makefile.am      |  1 +
 data/themes/blackwood/info.xml         |  4 ++++
 data/themes/enchilado/CMakeLists.txt   |  1 +
 data/themes/enchilado/Makefile.am      |  1 +
 data/themes/enchilado/info.xml         |  4 ++++
 data/themes/jewelry/CMakeLists.txt     |  1 +
 data/themes/jewelry/Makefile.am        |  1 +
 data/themes/jewelry/info.xml           |  4 ++++
 data/themes/mana/CMakeLists.txt        |  1 +
 data/themes/mana/Makefile.am           |  1 +
 data/themes/mana/info.xml              |  4 ++++
 data/themes/pink/CMakeLists.txt        |  1 +
 data/themes/pink/Makefile.am           |  1 +
 data/themes/pink/info.xml              |  4 ++++
 data/themes/unity/CMakeLists.txt       |  1 +
 data/themes/unity/Makefile.am          |  1 +
 data/themes/unity/info.xml             |  4 ++++
 data/themes/wood/CMakeLists.txt        |  1 +
 data/themes/wood/Makefile.am           |  1 +
 data/themes/wood/info.xml              |  4 ++++
 src/gui/setup_theme.cpp                | 32 +++++++++++++++++++++++++++++---
 src/gui/setup_theme.h                  | 10 +++++-----
 src/gui/theme.cpp                      | 32 ++++++++++++++++++++++++++++++++
 src/gui/theme.h                        |  8 ++++++++
 31 files changed, 128 insertions(+), 8 deletions(-)
 create mode 100644 data/graphics/gui/info.xml
 create mode 100644 data/themes/blacknblack/info.xml
 create mode 100644 data/themes/blackwood/info.xml
 create mode 100644 data/themes/enchilado/info.xml
 create mode 100644 data/themes/jewelry/info.xml
 create mode 100644 data/themes/mana/info.xml
 create mode 100644 data/themes/pink/info.xml
 create mode 100644 data/themes/unity/info.xml
 create mode 100644 data/themes/wood/info.xml

diff --git a/data/graphics/gui/CMakeLists.txt b/data/graphics/gui/CMakeLists.txt
index bc5cd64c6..985a6224c 100644
--- a/data/graphics/gui/CMakeLists.txt
+++ b/data/graphics/gui/CMakeLists.txt
@@ -22,6 +22,7 @@ SET (FILES
     equipment_playerbox.xml
     equipmentbox.png
     incomplete_icon.xml
+    info.xml
     inventory.xml
     item_selection.xml
     item_shortcut_background.xml
diff --git a/data/graphics/gui/Makefile.am b/data/graphics/gui/Makefile.am
index eaa53b58b..7120f40c7 100644
--- a/data/graphics/gui/Makefile.am
+++ b/data/graphics/gui/Makefile.am
@@ -25,6 +25,7 @@ gui_DATA =				\
 	equipment_playerbox.xml	\
 	equipmentbox.png	\
 	incomplete_icon.xml	\
+	info.xml	\
 	inventory.xml	\
 	item_selection.xml	\
 	item_shortcut_background.xml	\
diff --git a/data/graphics/gui/info.xml b/data/graphics/gui/info.xml
new file mode 100644
index 000000000..e427444ea
--- /dev/null
+++ b/data/graphics/gui/info.xml
@@ -0,0 +1,4 @@
+<info>
+    <name>(default)</name>
+    <copyright>2004-2009 The Mana World Development Team\n2009-2010 The Mana Developers\n2011-2012 ManaPlus Developers</copyright>
+</info>
diff --git a/data/themes/blacknblack/CMakeLists.txt b/data/themes/blacknblack/CMakeLists.txt
index f280b3e9c..5f345280a 100644
--- a/data/themes/blacknblack/CMakeLists.txt
+++ b/data/themes/blacknblack/CMakeLists.txt
@@ -1,6 +1,7 @@
 SET (FILES
     bubble.png
     colors.xml
+    info.xml
     mouse.png
     window.png
     )
diff --git a/data/themes/blacknblack/Makefile.am b/data/themes/blacknblack/Makefile.am
index 62f943081..92a81142a 100644
--- a/data/themes/blacknblack/Makefile.am
+++ b/data/themes/blacknblack/Makefile.am
@@ -4,6 +4,7 @@ guidir = $(pkgdatadir)/data/themes/blacknblack
 gui_DATA =				\
 	bubble.png			\
 	colors.xml		\
+	info.xml		\
 	mouse.png			\
 	window.png
 
diff --git a/data/themes/blacknblack/info.xml b/data/themes/blacknblack/info.xml
new file mode 100644
index 000000000..6857485f7
--- /dev/null
+++ b/data/themes/blacknblack/info.xml
@@ -0,0 +1,4 @@
+<info>
+    <name>Black & black</name>
+    <copyright>2012 ManaPlus developers</copyright>
+</info>
diff --git a/data/themes/blackwood/CMakeLists.txt b/data/themes/blackwood/CMakeLists.txt
index 954bfb3d9..d68aa12d3 100644
--- a/data/themes/blackwood/CMakeLists.txt
+++ b/data/themes/blackwood/CMakeLists.txt
@@ -1,5 +1,6 @@
 SET (FILES
     colors.xml
+    info.xml
     mouse.png
     progress-indicator.png
     speech_bubble.png
diff --git a/data/themes/blackwood/Makefile.am b/data/themes/blackwood/Makefile.am
index d1e33f1af..1ea0272bc 100644
--- a/data/themes/blackwood/Makefile.am
+++ b/data/themes/blackwood/Makefile.am
@@ -3,6 +3,7 @@ guidir = $(pkgdatadir)/data/themes/blackwood
 
 gui_DATA =				\
 	colors.xml			\
+	info.xml			\
 	mouse.png			\
 	progress-indicator.png		\
 	speechbubble.xml		\
diff --git a/data/themes/blackwood/info.xml b/data/themes/blackwood/info.xml
new file mode 100644
index 000000000..25d3b6b3a
--- /dev/null
+++ b/data/themes/blackwood/info.xml
@@ -0,0 +1,4 @@
+<info>
+    <name>Black wood</name>
+    <copyright>2010-2011 Felix Jely\n2011-2012  The ManaPlus Developers</copyright>
+</info>
diff --git a/data/themes/enchilado/CMakeLists.txt b/data/themes/enchilado/CMakeLists.txt
index f853912d8..97dca0a2f 100644
--- a/data/themes/enchilado/CMakeLists.txt
+++ b/data/themes/enchilado/CMakeLists.txt
@@ -2,6 +2,7 @@ SET (FILES
     buy.xml
     colors.xml
     equipment.xml
+    info.xml
     inventory.xml
     popup.xml
     progressbar.xml
diff --git a/data/themes/enchilado/Makefile.am b/data/themes/enchilado/Makefile.am
index d3b517c9e..5eb839b18 100644
--- a/data/themes/enchilado/Makefile.am
+++ b/data/themes/enchilado/Makefile.am
@@ -5,6 +5,7 @@ gui_DATA =				\
 	buy.xml		\
 	colors.xml		\
 	equipment.xml		\
+	info.xml		\
 	inventory.xml		\
 	popup.xml		\
 	progressbar.xml		\
diff --git a/data/themes/enchilado/info.xml b/data/themes/enchilado/info.xml
new file mode 100644
index 000000000..edadfcd49
--- /dev/null
+++ b/data/themes/enchilado/info.xml
@@ -0,0 +1,4 @@
+<info>
+    <name>Enchilado</name>
+    <copyright>2010-2011 R W E Sayers\n2010-2012 ManaPlus developers</copyright>
+</info>
diff --git a/data/themes/jewelry/CMakeLists.txt b/data/themes/jewelry/CMakeLists.txt
index 2adbfedbd..e1cd1fb19 100644
--- a/data/themes/jewelry/CMakeLists.txt
+++ b/data/themes/jewelry/CMakeLists.txt
@@ -19,6 +19,7 @@ SET (FILES
     equipment_background.xml
     equipmentbox.png
     incomplete_icon.xml
+    info.xml
     inventory.xml
     itempopup.xml
     items.xml
diff --git a/data/themes/jewelry/Makefile.am b/data/themes/jewelry/Makefile.am
index b7246984a..f86c44649 100644
--- a/data/themes/jewelry/Makefile.am
+++ b/data/themes/jewelry/Makefile.am
@@ -22,6 +22,7 @@ gui_DATA =				\
 	equipment_background.xml		\
 	equipmentbox.png		\
 	incomplete_icon.xml		\
+	info.xml		\
 	inventory.xml		\
 	itempopup.xml		\
 	items.xml		\
diff --git a/data/themes/jewelry/info.xml b/data/themes/jewelry/info.xml
new file mode 100644
index 000000000..d62b32fbb
--- /dev/null
+++ b/data/themes/jewelry/info.xml
@@ -0,0 +1,4 @@
+<info>
+    <name>Jewelry</name>
+    <copyright>2012 Hal9000\n2012 ManaPlus developers</copyright>
+</info>
diff --git a/data/themes/mana/CMakeLists.txt b/data/themes/mana/CMakeLists.txt
index 0f2ecac98..6547c1609 100644
--- a/data/themes/mana/CMakeLists.txt
+++ b/data/themes/mana/CMakeLists.txt
@@ -1,5 +1,6 @@
 SET (FILES
     colors.xml
+    info.xml
     npc.xml
     quests.xml
     social.xml
diff --git a/data/themes/mana/Makefile.am b/data/themes/mana/Makefile.am
index 192410a0e..828de323b 100644
--- a/data/themes/mana/Makefile.am
+++ b/data/themes/mana/Makefile.am
@@ -3,6 +3,7 @@ guidir = $(pkgdatadir)/data/themes/mana
 
 gui_DATA =				\
 	colors.xml		\
+	info.xml		\
 	npc.xml		\
 	quests.xml		\
 	social.xml
diff --git a/data/themes/mana/info.xml b/data/themes/mana/info.xml
new file mode 100644
index 000000000..994939d00
--- /dev/null
+++ b/data/themes/mana/info.xml
@@ -0,0 +1,4 @@
+<info>
+    <name>mana</name>
+    <copyright>2004-2009  The Mana World Development Team\n2009-2010  The Mana Developers\n2011-2012  The ManaPlus Developers</copyright>
+</info>
diff --git a/data/themes/pink/CMakeLists.txt b/data/themes/pink/CMakeLists.txt
index a6353dbc4..77eb0d96e 100644
--- a/data/themes/pink/CMakeLists.txt
+++ b/data/themes/pink/CMakeLists.txt
@@ -3,6 +3,7 @@ SET (FILES
     buy.xml
     colors.xml
     equipment.xml
+    info.xml
     inventory.xml
     popup.xml
     progress-indicator.png
diff --git a/data/themes/pink/Makefile.am b/data/themes/pink/Makefile.am
index 43c5982d0..345ca2ac8 100644
--- a/data/themes/pink/Makefile.am
+++ b/data/themes/pink/Makefile.am
@@ -6,6 +6,7 @@ gui_DATA =				\
 	buy.xml			\
 	colors.xml		\
 	equipment.xml		\
+	info.xml		\
 	inventory.xml		\
 	popup.xml		\
 	progress-indicator.png		\
diff --git a/data/themes/pink/info.xml b/data/themes/pink/info.xml
new file mode 100644
index 000000000..e77d203c2
--- /dev/null
+++ b/data/themes/pink/info.xml
@@ -0,0 +1,4 @@
+<info>
+    <name>Pink</name>
+    <copyright>2011 Aline Ferraz de Souza\n2011-2012 ManaPlus Developers</copyright>
+</info>
diff --git a/data/themes/unity/CMakeLists.txt b/data/themes/unity/CMakeLists.txt
index 20545812c..453e628d0 100644
--- a/data/themes/unity/CMakeLists.txt
+++ b/data/themes/unity/CMakeLists.txt
@@ -3,6 +3,7 @@ SET (FILES
     char.xml
     colors.xml
     equipment.xml
+    info.xml
     inventory.xml
     npc.xml
     popup.xml
diff --git a/data/themes/unity/Makefile.am b/data/themes/unity/Makefile.am
index bed2b3c15..ea9df94aa 100644
--- a/data/themes/unity/Makefile.am
+++ b/data/themes/unity/Makefile.am
@@ -6,6 +6,7 @@ gui_DATA =				\
 	char.xml			\
 	colors.xml		\
 	equipment.xml		\
+	info.xml		\
 	inventory.xml		\
 	npc.xml		\
 	popup.xml		\
diff --git a/data/themes/unity/info.xml b/data/themes/unity/info.xml
new file mode 100644
index 000000000..6f587e010
--- /dev/null
+++ b/data/themes/unity/info.xml
@@ -0,0 +1,4 @@
+<info>
+    <name>Unity</name>
+    <copyright>2011 Aline Ferraz de Souza\n2011-2012 ManaPlus Developers</copyright>
+</info>
diff --git a/data/themes/wood/CMakeLists.txt b/data/themes/wood/CMakeLists.txt
index 622c4dcd9..6af25f0bf 100644
--- a/data/themes/wood/CMakeLists.txt
+++ b/data/themes/wood/CMakeLists.txt
@@ -2,6 +2,7 @@ SET (FILES
     buy.xml
     colors.xml
     equipment.xml
+    info.xml
     inventory.xml
     item_shortcut_bgr.png
     mouse.png
diff --git a/data/themes/wood/Makefile.am b/data/themes/wood/Makefile.am
index fc9518b16..2bbbcad78 100644
--- a/data/themes/wood/Makefile.am
+++ b/data/themes/wood/Makefile.am
@@ -5,6 +5,7 @@ gui_DATA =				\
 	buy.xml		\
 	colors.xml		\
 	equipment.xml		\
+	info.xml		\
 	inventory.xml		\
 	item_shortcut_bgr.png		\
 	mouse.png			\
diff --git a/data/themes/wood/info.xml b/data/themes/wood/info.xml
new file mode 100644
index 000000000..8e35d65ad
--- /dev/null
+++ b/data/themes/wood/info.xml
@@ -0,0 +1,4 @@
+<info>
+    <name>Wood</name>
+    <copyright>Vianney Rousset\n2004-2009 The Mana World Development Team\n2009-2010 The Mana Developers\n2011-2012 ManaPlus Developers</copyright>
+</info>
diff --git a/src/gui/setup_theme.cpp b/src/gui/setup_theme.cpp
index 1886405be..66d806fc4 100644
--- a/src/gui/setup_theme.cpp
+++ b/src/gui/setup_theme.cpp
@@ -51,6 +51,7 @@ const char* ACTION_PARTICLE_FONT = "particle font";
 const char* ACTION_HELP_FONT = "help font";
 const char* ACTION_SECURE_FONT = "secure font";
 const char* ACTION_JAPAN_FONT = "japan font";
+const char* ACTION_INFO = "info";
 
 class ThemesModel final : public NamesModel
 {
@@ -194,7 +195,9 @@ Setup_Theme::Setup_Theme() :
     mNpcFontSizeListModel(new FontSizeChoiceListModel),
     mNpcFontSizeLabel(new Label(_("Npc font size"))),
     mNpcFontSize(config.getIntValue("npcfontSize")),
-    mNpcFontSizeDropDown(new DropDown(mNpcFontSizeListModel))
+    mNpcFontSizeDropDown(new DropDown(mNpcFontSizeListModel)),
+    // TRANSLATORS: button name with information about selected theme
+    mInfoButton(new Button(_("i"), ACTION_INFO, this))
 {
     setName(_("Theme"));
 
@@ -249,6 +252,8 @@ Setup_Theme::Setup_Theme() :
     mJapanFontDropDown->setSelectedString(getFileName(
         config.getStringValue("japanFont")));
 
+    updateInfo();
+
     // Do the layout
     LayoutHelper h(this);
     ContainerPlacer place = h.getPlacer(0, 0);
@@ -275,8 +280,7 @@ Setup_Theme::Setup_Theme() :
     place(6, 8, mSecureFontDropDown, 10);
     place(6, 9, mJapanFontDropDown, 10);
 
-    place.getCell().matchColWidth(0, 0);
-    place = h.getPlacer(0, 1);
+    place(17, 0, mInfoButton, 1);
 
     setDimension(gcn::Rectangle(0, 0, 365, 500));
 }
@@ -299,6 +303,22 @@ Setup_Theme::~Setup_Theme()
     mLangListModel = nullptr;
 }
 
+void Setup_Theme::updateInfo()
+{
+    ThemeInfo *info = Theme::loadInfo(mTheme);
+    if (info)
+    {
+        mThemeInfo = "Name: " + info->name
+            + "\nCopyright:\n" + info->copyright;
+    }
+    else
+    {
+        mThemeInfo = "";
+    }
+    replaceAll(mThemeInfo, "\\n", "\n");
+    delete info;
+}
+
 void Setup_Theme::action(const gcn::ActionEvent &event)
 {
     if (event.getId() == ACTION_THEME)
@@ -307,6 +327,7 @@ void Setup_Theme::action(const gcn::ActionEvent &event)
             mTheme = "";
         else
             mTheme = mThemeDropDown->getSelectedString();
+        updateInfo();
     }
     else if (event.getId() == ACTION_FONT)
     {
@@ -340,6 +361,11 @@ void Setup_Theme::action(const gcn::ActionEvent &event)
     {
         mJapanFont = mJapanFontDropDown->getSelectedString();
     }
+    else if (event.getId() == ACTION_INFO)
+    {
+        new OkDialog(_("Theme info"), mThemeInfo, DIALOG_OK,
+            false, true, nullptr, 600);
+    }
 }
 
 void Setup_Theme::cancel()
diff --git a/src/gui/setup_theme.h b/src/gui/setup_theme.h
index 9754b7915..2a0152035 100644
--- a/src/gui/setup_theme.h
+++ b/src/gui/setup_theme.h
@@ -27,6 +27,7 @@
 
 #include <guichan/actionlistener.hpp>
 
+class Button;
 class DropDown;
 class EditDialog;
 class FontsModel;
@@ -35,11 +36,6 @@ class Label;
 class LangListModel;
 class ThemesModel;
 
-namespace gcn
-{
-    class DropDown;
-}
-
 class Setup_Theme final : public SetupTab
 {
     public:
@@ -55,6 +51,8 @@ class Setup_Theme final : public SetupTab
 
         void action(const gcn::ActionEvent &event) override;
 
+        void updateInfo();
+
     private:
         Label *mThemeLabel;
         ThemesModel *mThemesModel;
@@ -102,6 +100,8 @@ class Setup_Theme final : public SetupTab
         int mNpcFontSize;
         DropDown *mNpcFontSizeDropDown;
 
+        Button *mInfoButton;
+        std::string mThemeInfo;
 //        EditDialog *mEditDialog;
 };
 
diff --git a/src/gui/theme.cpp b/src/gui/theme.cpp
index 4abf76eb6..9ecac247c 100644
--- a/src/gui/theme.cpp
+++ b/src/gui/theme.cpp
@@ -1031,3 +1031,35 @@ ImageSet *Theme::getImageSetFromThemeXml(const std::string &name,
     }
     return nullptr;
 }
+
+ThemeInfo *Theme::loadInfo(const std::string &themeName)
+{
+    std::string path;
+    if (themeName.empty())
+        path = "graphics/gui/info.xml";
+    else
+        path = defaultThemePath + themeName + "/info.xml";
+    logger->log("loading: " + path);
+    XML::Document doc(path);
+    const XmlNodePtr rootNode = doc.rootNode();
+
+    if (!rootNode || !xmlNameEqual(rootNode, "info"))
+        return nullptr;
+
+    ThemeInfo *info = new ThemeInfo();
+
+    for_each_xml_child_node(infoNode, rootNode)
+    {
+        if (xmlNameEqual(infoNode, "name"))
+        {
+            info->name = reinterpret_cast<const char*>(
+                xmlNodeGetContent(infoNode));
+        }
+        else if (xmlNameEqual(infoNode, "copyright"))
+        {
+            info->copyright = reinterpret_cast<const char*>(
+            xmlNodeGetContent(infoNode));
+        }
+    }
+    return info;
+}
diff --git a/src/gui/theme.h b/src/gui/theme.h
index 92ff6073b..680fe63bd 100644
--- a/src/gui/theme.h
+++ b/src/gui/theme.h
@@ -39,6 +39,12 @@ class Image;
 class ImageSet;
 class ProgressBar;
 
+struct ThemeInfo final
+{
+    std::string name;
+    std::string copyright;
+};
+
 class Skin final
 {
     public:
@@ -333,6 +339,8 @@ class Theme final : public Palette, public ConfigListener
         static Image *getImageFromThemeXml(const std::string &name,
                                            const std::string &name2);
 
+        static ThemeInfo *loadInfo(const std::string &themeName);
+
     private:
         Theme();
 
-- 
cgit v1.2.3-70-g09d2