tdesktop/Telegram/SourceFiles/boxes/about_box.cpp

121 lines
3.9 KiB
C++
Raw Normal View History

/*
This file is part of Telegram Desktop,
the official desktop application for the Telegram messaging service.
For license and copyright information please follow this link:
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
2017-04-06 14:38:10 +00:00
#include "boxes/about_box.h"
2017-04-13 08:27:10 +00:00
#include "lang/lang_keys.h"
#include "mainwidget.h"
#include "mainwindow.h"
2017-04-06 14:38:10 +00:00
#include "boxes/confirm_box.h"
#include "ui/widgets/buttons.h"
#include "ui/widgets/labels.h"
#include "styles/style_boxes.h"
#include "platform/platform_file_utilities.h"
#include "platform/platform_info.h"
#include "core/click_handler_types.h"
#include "core/update_checker.h"
AboutBox::AboutBox(QWidget *parent)
: _version(this, lng_about_version(lt_version, currentVersionText()), st::aboutVersionLink)
, _text1(this, lang(lng_about_text_1), Ui::FlatLabel::InitType::Rich, st::aboutLabel)
, _text2(this, lang(lng_about_text_2), Ui::FlatLabel::InitType::Rich, st::aboutLabel)
, _text3(this, st::aboutLabel) {
}
void AboutBox::prepare() {
setTitle([] { return qsl("Telegram Desktop"); });
addButton(langFactory(lng_close), [this] { closeBox(); });
const auto linkFilter = [](const ClickHandlerPtr &link, auto button) {
if (const auto url = dynamic_cast<UrlClickHandler*>(link.get())) {
url->UrlClickHandler::onClick({ button });
return false;
}
return true;
};
_text3->setRichText(lng_about_text_3(lt_faq_open, qsl("[a href=\"%1\"]").arg(telegramFaqLink()), lt_faq_close, qsl("[/a]")));
_text1->setClickHandlerFilter(linkFilter);
_text2->setClickHandlerFilter(linkFilter);
_text3->setClickHandlerFilter(linkFilter);
_version->setClickedCallback([this] { showVersionHistory(); });
setDimensions(st::aboutWidth, st::aboutTextTop + _text1->height() + st::aboutSkip + _text2->height() + st::aboutSkip + _text3->height());
}
2015-10-12 21:02:10 +00:00
void AboutBox::resizeEvent(QResizeEvent *e) {
BoxContent::resizeEvent(e);
_version->moveToLeft(st::boxPadding.left(), st::aboutVersionTop);
_text1->moveToLeft(st::boxPadding.left(), st::aboutTextTop);
_text2->moveToLeft(st::boxPadding.left(), _text1->y() + _text1->height() + st::aboutSkip);
_text3->moveToLeft(st::boxPadding.left(), _text2->y() + _text2->height() + st::aboutSkip);
2015-10-12 21:02:10 +00:00
}
void AboutBox::showVersionHistory() {
if (cRealAlphaVersion()) {
2016-11-22 09:48:13 +00:00
auto url = qsl("https://tdesktop.com/");
if (Platform::IsWindows()) {
url += qsl("win/%1.zip");
} else if (Platform::IsMacOldBuild()) {
url += qsl("mac32/%1.zip");
} else if (Platform::IsMac()) {
url += qsl("mac/%1.zip");
} else if (Platform::IsLinux32Bit()) {
url += qsl("linux32/%1.tar.xz");
} else if (Platform::IsLinux64Bit()) {
url += qsl("linux/%1.tar.xz");
} else {
Unexpected("Platform value.");
}
url = url.arg(qsl("talpha%1_%2").arg(cRealAlphaVersion()).arg(Core::countAlphaVersionSignature(cRealAlphaVersion())));
2019-01-18 11:26:43 +00:00
QApplication::clipboard()->setText(url);
Ui::show(Box<InformBox>("The link to the current private alpha version of Telegram Desktop was copied to the clipboard."));
} else {
QDesktopServices::openUrl(qsl("https://desktop.telegram.org/changelog"));
}
}
void AboutBox::keyPressEvent(QKeyEvent *e) {
if (e->key() == Qt::Key_Enter || e->key() == Qt::Key_Return) {
closeBox();
} else {
BoxContent::keyPressEvent(e);
}
}
2015-10-12 21:02:10 +00:00
QString telegramFaqLink() {
2018-12-17 06:12:44 +00:00
const auto result = qsl("https://telegram.org/faq");
const auto langpacked = [&](const char *language) {
return result + '/' + language;
};
const auto current = Lang::Current().id();
for (const auto language : { "de", "es", "it", "ko" }) {
if (current.startsWith(QLatin1String(language))) {
return langpacked(language);
2015-10-12 21:02:10 +00:00
}
}
2018-12-17 06:12:44 +00:00
if (current.startsWith(qstr("pt-br"))) {
return langpacked("br");
}
2015-10-12 21:02:10 +00:00
return result;
2016-01-31 16:13:51 +00:00
}
QString currentVersionText() {
auto result = QString::fromLatin1(AppVersionStr);
if (cAlphaVersion()) {
result += qsl(" alpha %1").arg(cAlphaVersion() % 1000);
} else if (AppBetaVersion) {
result += " beta";
}
return result;
}