Use PROTOCOL_TELEMETRY_MULTIMODULE for internal multi when available (#7147)
[opentx.git] / companion / src / creditsdialog.cpp
blob29b6b79bc87aee38cb1326e013caae044d342e48
1 /*
2 * Copyright (C) OpenTX
4 * Based on code named
5 * th9x - http://code.google.com/p/th9x
6 * er9x - http://code.google.com/p/er9x
7 * gruvin9x - http://code.google.com/p/gruvin9x
9 * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
21 #include "creditsdialog.h"
22 #include "ui_htmldialog.h"
23 #include "helpers.h"
24 #include <QFile>
26 CreditsDialog::CreditsDialog(QWidget * parent):
27 QDialog(parent),
28 ui(new Ui::HtmlDialog)
30 ui->setupUi(this);
32 setWindowTitle(tr("OpenTX Contributors"));
33 setWindowIcon(CompanionIcon("contributors.png"));
35 QString str = "<html>" \
36 "<head>" \
37 " <style type=\"text/css\">" \
38 " .normal { font-weight:normal;color:#000000;vertical-align:top;font-size:10px;text-align:left;font-family:arial,helvetica,sans-serif; }" \
39 " .bold { font-weight:bold;color:#C00000;vertical-align:top;font-size:10px;text-align:left;font-family:arial,helvetica,sans-serif; }" \
40 " .title { font-weight:bold;color:#000000;font-size:14px;text-align:left;font-family:arial,helvetica,sans-serif; }" \
41 " </style>" \
42 "</head>"
43 "<body class=\"normal\">";
45 foreach(CreditsSection section, readCredits()) {
46 str.append(formatTable(sectionTitle(section.title), section.names, 3));
49 str.append("<table><tr><td class=\"normal\">&nbsp;</td></tr>" \
50 " <tr><td class=\"normal\">" + tr("Honors go to Rafal Tomczak (RadioClone), Thomas Husterer (th9x) and Erez Raviv (er9x and eePe)") + "<br/></td></tr>" \
51 "</table>");
53 #if 0
54 QFile blacklist(":/BLACKLIST.txt");
55 if (blacklist.open(QIODevice::ReadOnly | QIODevice::Text)) {
56 QStringList names;
57 names << blacklist.readAll();
58 str.append(formatTable(tr("OpenTX Blacklist"), names, 1));
60 #endif
62 str.append("</body></html>");
63 ui->textEditor->setHtml(str);
64 ui->textEditor->scroll(0, 0);
65 ui->textEditor->setOpenExternalLinks(true);
68 CreditsDialog::~CreditsDialog()
70 delete ui;
73 QList<CreditsDialog::CreditsSection> CreditsDialog::readCredits()
75 QFile credits(":/CREDITS.txt");
76 QList<CreditsSection> result;
77 if (credits.open(QIODevice::ReadOnly | QIODevice::Text)) {
78 while (!credits.atEnd()) {
79 QByteArray line = credits.readLine().trimmed();
80 if (line.size() >= 2) {
81 if (line.startsWith("[") && line.endsWith("]")) {
82 result.push_back(CreditsSection(line.mid(1, line.size() - 2)));
83 } else {
84 result.back().addName(line);
89 return result;
92 QString CreditsDialog::sectionTitle(const QString & title)
94 if (title == "Main developers")
95 return tr("Main developers");
96 else if (title == "Translators")
97 return tr("Translators");
98 else if (title == "Companies and projects who have donated to OpenTX")
99 return tr("Companies and projects who have donated to OpenTX");
100 else if (title == "People who have donated to OpenTX")
101 return tr("People who have donated to OpenTX");
102 else
103 return tr("Other contributors");
106 QString CreditsDialog::formatTable(const QString & title, const QStringList & names, int columns)
108 const float cwidth = 100.0 / columns;
109 QString str = "<table width=\"100%\" border=0 cellspacing=0 cellpadding=2>" \
110 " <tr><td class=\"normal\">&nbsp;</td></tr>" \
111 " <tr><td class=\"title\">" + title + "</td></tr>" \
112 "</table>";
114 str.append("<table width=\"100%\" border=0 cellspacing=0 cellpadding=2>");
116 int column = 0;
117 foreach(QString name, names) {
118 if (column == 0) {
119 str.append("<tr>");
121 QString trclass = name.contains("monthly") ? "bold" : "normal";
122 str.append(QString("<td width=\"%1%\" class=\"%2\">%3</td>").arg(cwidth).arg(trclass).arg(name.trimmed().replace("monthly", tr("monthly"))));
123 if (++column == columns) {
124 str.append("</tr>");
125 column = 0;
129 if (column != 0) {
130 str.append("</tr>");
133 str.append("</table>");
134 return str;