about_box.cpp 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. /*
  2. This file is part of Telegram Desktop,
  3. the official desktop application for the Telegram messaging service.
  4. For license and copyright information please follow this link:
  5. https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
  6. */
  7. #include "boxes/about_box.h"
  8. #include "lang/lang_keys.h"
  9. #include "mainwidget.h"
  10. #include "mainwindow.h"
  11. #include "ui/boxes/confirm_box.h"
  12. #include "ui/widgets/buttons.h"
  13. #include "ui/widgets/labels.h"
  14. #include "ui/text/text_utilities.h"
  15. #include "base/platform/base_platform_info.h"
  16. #include "core/file_utilities.h"
  17. #include "core/click_handler_types.h"
  18. #include "core/update_checker.h"
  19. #include "core/application.h"
  20. #include "styles/style_layers.h"
  21. #include "styles/style_boxes.h"
  22. #include <QtGui/QGuiApplication>
  23. #include <QtGui/QClipboard>
  24. namespace {
  25. rpl::producer<TextWithEntities> Text1() {
  26. return tr::lng_about_text1(
  27. lt_api_link,
  28. tr::lng_about_text1_api(
  29. ) | Ui::Text::ToLink("https://core.telegram.org/api"),
  30. Ui::Text::WithEntities);
  31. }
  32. rpl::producer<TextWithEntities> Text2() {
  33. return tr::lng_about_text2(
  34. lt_gpl_link,
  35. rpl::single(Ui::Text::Link(
  36. "GNU GPL",
  37. "https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE")),
  38. lt_github_link,
  39. rpl::single(Ui::Text::Link(
  40. "GitHub",
  41. "https://github.com/telegramdesktop/tdesktop")),
  42. Ui::Text::WithEntities);
  43. }
  44. rpl::producer<TextWithEntities> Text3() {
  45. return tr::lng_about_text3(
  46. lt_faq_link,
  47. tr::lng_about_text3_faq() | Ui::Text::ToLink(telegramFaqLink()),
  48. Ui::Text::WithEntities);
  49. }
  50. } // namespace
  51. AboutBox::AboutBox(QWidget *parent)
  52. : _version(this, tr::lng_about_version(tr::now, lt_version, currentVersionText()), st::aboutVersionLink)
  53. , _text1(this, Text1(), st::aboutLabel)
  54. , _text2(this, Text2(), st::aboutLabel)
  55. , _text3(this, Text3(), st::aboutLabel) {
  56. }
  57. void AboutBox::prepare() {
  58. setTitle(rpl::single(u"Telegram Desktop"_q));
  59. addButton(tr::lng_close(), [this] { closeBox(); });
  60. _text1->setLinksTrusted();
  61. _text2->setLinksTrusted();
  62. _text3->setLinksTrusted();
  63. _version->setClickedCallback([this] { showVersionHistory(); });
  64. setDimensions(st::aboutWidth, st::aboutTextTop + _text1->height() + st::aboutSkip + _text2->height() + st::aboutSkip + _text3->height());
  65. }
  66. void AboutBox::resizeEvent(QResizeEvent *e) {
  67. BoxContent::resizeEvent(e);
  68. const auto available = width()
  69. - st::boxPadding.left()
  70. - st::boxPadding.right();
  71. _version->moveToLeft(st::boxPadding.left(), st::aboutVersionTop);
  72. _text1->resizeToWidth(available);
  73. _text1->moveToLeft(st::boxPadding.left(), st::aboutTextTop);
  74. _text2->resizeToWidth(available);
  75. _text2->moveToLeft(st::boxPadding.left(), _text1->y() + _text1->height() + st::aboutSkip);
  76. _text3->resizeToWidth(available);
  77. _text3->moveToLeft(st::boxPadding.left(), _text2->y() + _text2->height() + st::aboutSkip);
  78. }
  79. void AboutBox::showVersionHistory() {
  80. if (cRealAlphaVersion()) {
  81. auto url = u"https://tdesktop.com/"_q;
  82. if (Platform::IsWindows32Bit()) {
  83. url += u"win/%1.zip"_q;
  84. } else if (Platform::IsWindows64Bit()) {
  85. url += u"win64/%1.zip"_q;
  86. } else if (Platform::IsWindowsARM64()) {
  87. url += u"winarm/%1.zip"_q;
  88. } else if (Platform::IsMac()) {
  89. url += u"mac/%1.zip"_q;
  90. } else if (Platform::IsLinux()) {
  91. url += u"linux/%1.tar.xz"_q;
  92. } else {
  93. Unexpected("Platform value.");
  94. }
  95. url = url.arg(u"talpha%1_%2"_q.arg(cRealAlphaVersion()).arg(Core::countAlphaVersionSignature(cRealAlphaVersion())));
  96. QGuiApplication::clipboard()->setText(url);
  97. getDelegate()->show(
  98. Ui::MakeInformBox(
  99. "The link to the current private alpha "
  100. "version of Telegram Desktop was copied to the clipboard."),
  101. Ui::LayerOption::CloseOther);
  102. } else {
  103. File::OpenUrl(Core::App().changelogLink());
  104. }
  105. }
  106. void AboutBox::keyPressEvent(QKeyEvent *e) {
  107. if (e->key() == Qt::Key_Enter || e->key() == Qt::Key_Return) {
  108. closeBox();
  109. } else {
  110. BoxContent::keyPressEvent(e);
  111. }
  112. }
  113. QString telegramFaqLink() {
  114. const auto result = u"https://telegram.org/faq"_q;
  115. const auto langpacked = [&](const char *language) {
  116. return result + '/' + language;
  117. };
  118. const auto current = Lang::Id();
  119. for (const auto language : { "de", "es", "it", "ko" }) {
  120. if (current.startsWith(QLatin1String(language))) {
  121. return langpacked(language);
  122. }
  123. }
  124. if (current.startsWith(u"pt-br"_q)) {
  125. return langpacked("br");
  126. }
  127. return result;
  128. }
  129. QString currentVersionText() {
  130. auto result = QString::fromLatin1(AppVersionStr);
  131. if (cAlphaVersion()) {
  132. result += u" alpha %1"_q.arg(cAlphaVersion() % 1000);
  133. } else if (AppBetaVersion) {
  134. result += " beta";
  135. }
  136. if (Platform::IsWindows64Bit()) {
  137. result += " x64";
  138. } else if (Platform::IsWindowsARM64()) {
  139. result += " arm64";
  140. }
  141. return result;
  142. }