1 /* -*- Mode: c++ -*- */
2 /***************************************************************************
3  *            abouttab.cc
4  *
5  *  Fri Apr 21 18:51:13 CEST 2017
6  *  Copyright 2017 André Nusser
7  *  andre.nusser@googlemail.com
8  ****************************************************************************/
9 
10 /*
11  *  This file is part of DrumGizmo.
12  *
13  *  DrumGizmo is free software; you can redistribute it and/or modify
14  *  it under the terms of the GNU Lesser General Public License as published by
15  *  the Free Software Foundation; either version 3 of the License, or
16  *  (at your option) any later version.
17  *
18  *  DrumGizmo is distributed in the hope that it will be useful,
19  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
20  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21  *  GNU Lesser General Public License for more details.
22  *
23  *  You should have received a copy of the GNU Lesser General Public License
24  *  along with DrumGizmo; if not, write to the Free Software
25  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.
26  */
27 #include "abouttab.h"
28 
29 #include <version.h>
30 #include <translation.h>
31 
32 #include "utf8.h"
33 
34 namespace
35 {
getLocalizedFile(const std::string & file)36 std::string getLocalizedFile(const std::string& file)
37 {
38 	auto language = Translation::getISO639LanguageName();
39 	std::string file_localized = file + "." + language;
40 	GUI::Resource resource_localized{file_localized};
41 	if(resource_localized.valid())
42 	{
43 		return resource_localized.data();
44 	}
45 
46 	GUI::Resource resource{file};
47 	if(resource.valid())
48 	{
49 		return resource.data();
50 	}
51 
52 	return "";
53 }
54 }
55 
56 namespace GUI
57 {
58 
AboutTab(Widget * parent)59 AboutTab::AboutTab(Widget* parent)
60 	: Widget(parent)
61 {
62 	text_edit.setText(getAboutText());
63 	text_edit.setReadOnly(true);
64 	text_edit.resize(std::max((int)width() - 2*margin,0),
65 	                 std::max((int)height() - 2*margin, 0));
66 	text_edit.move(margin, margin);
67 }
68 
resize(std::size_t width,std::size_t height)69 void AboutTab::resize(std::size_t width, std::size_t height)
70 {
71 	Widget::resize(width, height);
72 	text_edit.resize(std::max((int)width - 2*margin, 0),
73 	                 std::max((int)height - 2*margin, 0));
74 }
75 
getAboutText()76 std::string AboutTab::getAboutText()
77 {
78 	std::string about_text;
79 
80 	// About
81 	about_text.append(_(
82 	"=============\n"
83 	"             About\n"
84 	"=============\n"
85 	"\n"));
86 	about_text.append(UTF8().toLatin1(getLocalizedFile(":../ABOUT")));
87 
88 	// Version
89 	about_text.append(_(
90 	"\n"
91 	"=============\n"
92 	"            Version\n"
93 	"=============\n"
94 	"\n"));
95 	about_text.append(std::string(VERSION) + "\n");
96 
97 	// Bugs
98 	about_text.append(_(
99 	"\n"
100 	"=============\n"
101 	"            Bugs\n"
102 	"=============\n"
103 	"\n"));
104 	about_text.append(UTF8().toLatin1(getLocalizedFile(":../BUGS")));
105 
106 	// Authors
107 	about_text.append(_(
108 	"\n"
109 	"=============\n"
110 	"            Authors\n"
111 	"=============\n"
112 	"\n"));
113 	about_text.append(UTF8().toLatin1(getLocalizedFile(":../AUTHORS")));
114 
115 	// GPL
116 	about_text.append(_(
117 	"\n"
118 	"=============\n"
119 	"            License\n"
120 	"=============\n"
121 	"\n"));
122 	about_text.append(UTF8().toLatin1(getLocalizedFile(":../COPYING")));
123 
124 	return about_text;
125 }
126 
127 } // GUI::
128