qTox  Version: nightly | Commit: bc751c8e1cac455f9690654fcfe0f560d2d7dfdd
aboutform.cpp
Go to the documentation of this file.
1 /*
2  Copyright © 2014-2019 by The qTox Project Contributors
3 
4  This file is part of qTox, a Qt-based graphical interface for Tox.
5 
6  qTox is libre software: you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  qTox is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with qTox. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #include "aboutform.h"
21 #include "ui_aboutsettings.h"
22 
23 #include "src/net/updatecheck.h"
26 #include "src/widget/style.h"
28 #include "src/widget/translator.h"
29 
30 #include <tox/tox.h>
31 
32 #include <QDebug>
33 #include <QDesktopServices>
34 #include <QPushButton>
35 #include <QTimer>
36 
37 #include <memory>
38 
39 // index of UI in the QStackedWidget
40 enum class updateIndex
41 {
42  available = 0,
43  upToDate = 1,
44  failed = 2
45 };
46 
58  : GenericForm(QPixmap(":/img/settings/general.png"))
59  , bodyUI(new Ui::AboutSettings)
60  , progressTimer(new QTimer(this))
61  , updateCheck(updateCheck)
62 {
63  bodyUI->setupUi(this);
64 
65 #if !UPDATE_CHECK_ENABLED
66  bodyUI->updateStack->setVisible(false);
67 #endif
68  bodyUI->unstableVersion->setVisible(false);
69 #if UPDATE_CHECK_ENABLED
71 #endif
72 
73  // block all child signals during initialization
74  const RecursiveSignalBlocker signalBlocker(this);
75 
77 
78  if (QString(GIT_VERSION).indexOf(" ") > -1)
79  bodyUI->gitVersion->setOpenExternalLinks(false);
80 
81  eventsInit();
83 }
84 
92 {
93  // TODO: When we finally have stable releases: build-in a way to tell
94  // nightly builds from stable releases.
95 
96  QString TOXCORE_VERSION = QString::number(tox_version_major()) + "."
97  + QString::number(tox_version_minor()) + "."
98  + QString::number(tox_version_patch());
99 
100  bodyUI->youAreUsing->setText(tr("You are using qTox version %1.").arg(QString(GIT_DESCRIBE)));
101 
102 #if UPDATE_CHECK_ENABLED
103  if (updateCheck != nullptr) {
107  } else {
108  qWarning() << "AboutForm passed null UpdateCheck!";
109  }
110 #else
111  qDebug() << "AboutForm not showing updates, qTox built without UPDATE_CHECK";
112 #endif
113 
114  QString commitLink = "https://github.com/qTox/qTox/commit/" + QString(GIT_VERSION);
115  bodyUI->gitVersion->setText(
116  tr("Commit hash: %1").arg(createLink(commitLink, QString(GIT_VERSION))));
117 
118  bodyUI->toxCoreVersion->setText(tr("toxcore version: %1").arg(TOXCORE_VERSION));
119  bodyUI->qtVersion->setText(tr("Qt version: %1").arg(QT_VERSION_STR));
120 
121  QString issueBody = QString("##### Brief Description\n\n"
122  "OS: %1\n"
123  "qTox version: %2\n"
124  "Commit hash: %3\n"
125  "toxcore: %4\n"
126  "Qt: %5\n…\n\n"
127  "Reproducible: Always / Almost Always / Sometimes"
128  " / Rarely / Couldn't Reproduce\n\n"
129  "##### Steps to reproduce\n\n"
130  "1. \n2. \n3. …\n\n"
131  "##### Observed Behavior\n\n\n"
132  "##### Expected Behavior\n\n\n"
133  "##### Additional Info\n"
134  "(links, images, etc go here)\n\n"
135  "----\n\n"
136  "More information on how to write good bug reports in the wiki: "
137  "https://github.com/qTox/qTox/wiki/Writing-Useful-Bug-Reports.\n\n"
138  "Please remove any unnecessary template section before submitting.")
139  .arg(QSysInfo::prettyProductName(), GIT_DESCRIBE, GIT_VERSION,
140  TOXCORE_VERSION, QT_VERSION_STR);
141 
142  issueBody.replace("#", "%23").replace(":", "%3A");
143 
144  bodyUI->knownIssues->setText(
145  tr("A list of all known issues may be found at our %1 at Github."
146  " If you discover a bug or security vulnerability within"
147  " qTox, please report it according to the guidelines in our"
148  " %2 wiki article.",
149 
150  "`%1` is replaced by translation of `bug tracker`"
151  "\n`%2` is replaced by translation of `Writing Useful Bug Reports`")
152  .arg(createLink("https://github.com/qTox/qTox/issues",
153  tr("bug-tracker", "Replaces `%1` in the `A list of all known…`")))
154  .arg(createLink("https://github.com/qTox/qTox/wiki/Writing-Useful-Bug-Reports",
155  tr("Writing Useful Bug Reports",
156  "Replaces `%2` in the `A list of all known…`"))));
157 
158  bodyUI->clickToReport->setText(
159  createLink("https://github.com/qTox/qTox/issues/new?body=" + QUrl(issueBody).toEncoded(),
160  QString("<b>%1</b>").arg(tr("Click here to report a bug."))));
161 
162 
163  QString authorInfo =
164  QString("<p>%1</p><p>%2</p>")
165  .arg(tr("Original author: %1").arg(createLink("https://github.com/tux3", "tux3")))
166  .arg(
167  tr("See a full list of %1 at Github",
168  "`%1` is replaced with translation of word `contributors`")
169  .arg(createLink("https://qtox.github.io/gitstats/authors.html",
170  tr("contributors", "Replaces `%1` in `See a full list of…`"))));
171 
172  bodyUI->authorInfo->setText(authorInfo);
173 }
174 
175 void AboutForm::onUpdateAvailable(QString latestVersion, QUrl link)
176 {
177  QObject::disconnect(linkConnection);
178  linkConnection = connect(bodyUI->updateAvailableButton, &QPushButton::clicked,
179  [link]() { QDesktopServices::openUrl(link); });
180  bodyUI->updateStack->setCurrentIndex(static_cast<int>(updateIndex::available));
181 }
182 
184 {
185  bodyUI->updateStack->setCurrentIndex(static_cast<int>(updateIndex::upToDate));
186 }
187 
189 {
190  bodyUI->updateStack->setCurrentIndex(static_cast<int>(updateIndex::failed));
191 }
192 
194 {
195  replaceVersions();
196 }
197 
199 {
200  bodyUI->updateStack->hide();
201  bodyUI->unstableVersion->setVisible(true);
202 }
203 
210 QString AboutForm::createLink(QString path, QString text) const
211 {
212  return QString::fromUtf8(
213  "<a href=\"%1\" style=\"text-decoration: underline; color:%2;\">%3</a>")
214  .arg(path, Style::getColor(Style::Link).name(), text);
215 }
216 
218 {
220  delete bodyUI;
221 }
222 
227 {
228  bodyUI->retranslateUi(this);
229  replaceVersions();
230 }
AboutForm::linkConnection
QMetaObject::Connection linkConnection
Definition: aboutform.h:62
AboutForm::retranslateUi
void retranslateUi()
Retranslate all elements in the form.
Definition: aboutform.cpp:226
profile.h
style.h
recursivesignalblocker.h
AboutForm::~AboutForm
~AboutForm()
Definition: aboutform.cpp:217
settings.h
UpdateCheck::versionIsUnstable
void versionIsUnstable()
Style::Link
@ Link
Definition: style.h:49
AboutForm::AboutForm
AboutForm(UpdateCheck *updateCheck)
Constructor of AboutForm.
Definition: aboutform.cpp:57
Translator::unregister
static void unregister(void *owner)
Unregisters all handlers of an owner.
Definition: translator.cpp:103
UpdateCheck::updateAvailable
void updateAvailable(QString latestVersion, QUrl link)
AboutForm::reloadTheme
void reloadTheme() override
Definition: aboutform.cpp:193
updateIndex::failed
@ failed
AboutForm::bodyUI
Ui::AboutSettings * bodyUI
Definition: aboutform.h:59
AboutForm::onUnstableVersion
void onUnstableVersion()
Definition: aboutform.cpp:198
updatecheck.h
Ui
Definition: filetransferwidget.h:30
updateIndex
updateIndex
Definition: aboutform.cpp:40
updateIndex::available
@ available
AboutForm::onUpToDate
void onUpToDate()
Definition: aboutform.cpp:183
AboutForm::onUpdateCheckFailed
void onUpdateCheckFailed()
Definition: aboutform.cpp:188
aboutform.h
Style::getColor
static QColor getColor(ColorPalette entry)
Definition: style.cpp:209
Translator::registerHandler
static void registerHandler(const std::function< void()> &, void *owner)
Register a function to be called when the UI needs to be retranslated.
Definition: translator.cpp:93
AboutForm::replaceVersions
void replaceVersions()
Update versions and links.
Definition: aboutform.cpp:91
AboutForm::onUpdateAvailable
void onUpdateAvailable(QString latestVersion, QUrl link)
Definition: aboutform.cpp:175
AboutForm::updateCheck
UpdateCheck * updateCheck
Definition: aboutform.h:61
AboutForm::createLink
QString createLink(QString path, QString text) const
Creates hyperlink with specific style.
Definition: aboutform.cpp:210
UpdateCheck::updateCheckFailed
void updateCheckFailed()
GenericForm::eventsInit
void eventsInit()
Prevent stealing mouse wheel scroll.
Definition: genericsettings.cpp:54
translator.h
UpdateCheck::upToDate
void upToDate()
RecursiveSignalBlocker
Recursively blocks all signals from an object and its children.
Definition: recursivesignalblocker.h:27
UpdateCheck
Definition: updatecheck.h:32
GenericForm
Definition: genericsettings.h:24
updateIndex::upToDate
@ upToDate