window-basic-about.cpp 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. #include "window-basic-about.hpp"
  2. #include "window-basic-main.hpp"
  3. #include "qt-wrappers.hpp"
  4. #include "remote-text.hpp"
  5. #include <util/util.hpp>
  6. #include <util/platform.h>
  7. #include <platform.hpp>
  8. #include <json11.hpp>
  9. using namespace json11;
  10. OBSAbout::OBSAbout(QWidget *parent) : QDialog(parent), ui(new Ui::OBSAbout)
  11. {
  12. setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
  13. ui->setupUi(this);
  14. QString ver;
  15. #ifdef HAVE_OBSCONFIG_H
  16. ver += OBS_VERSION;
  17. #else
  18. ver += LIBOBS_API_MAJOR_VER + "." + LIBOBS_API_MINOR_VER + "." +
  19. LIBOBS_API_PATCH_VER;
  20. #endif
  21. ui->version->setText(ver);
  22. ui->contribute->setText(QTStr("About.Contribute"));
  23. if (steam) {
  24. delete ui->donate;
  25. } else {
  26. ui->donate->setText(
  27. "&nbsp;&nbsp;<a href='https://obsproject.com/contribute'>" +
  28. QTStr("About.Donate") + "</a>");
  29. ui->donate->setTextInteractionFlags(Qt::TextBrowserInteraction);
  30. ui->donate->setOpenExternalLinks(true);
  31. }
  32. ui->getInvolved->setText(
  33. "&nbsp;&nbsp;<a href='https://github.com/obsproject/obs-studio/blob/master/CONTRIBUTING.rst'>" +
  34. QTStr("About.GetInvolved") + "</a>");
  35. ui->getInvolved->setTextInteractionFlags(Qt::TextBrowserInteraction);
  36. ui->getInvolved->setOpenExternalLinks(true);
  37. ui->about->setText("<a href='#'>" + QTStr("About") + "</a>");
  38. ui->authors->setText("<a href='#'>" + QTStr("About.Authors") + "</a>");
  39. ui->license->setText("<a href='#'>" + QTStr("About.License") + "</a>");
  40. ui->name->setProperty("themeID", "aboutName");
  41. ui->version->setProperty("themeID", "aboutVersion");
  42. ui->about->setProperty("themeID", "aboutHLayout");
  43. ui->authors->setProperty("themeID", "aboutHLayout");
  44. ui->license->setProperty("themeID", "aboutHLayout");
  45. ui->info->setProperty("themeID", "aboutInfo");
  46. connect(ui->about, SIGNAL(clicked()), this, SLOT(ShowAbout()));
  47. connect(ui->authors, SIGNAL(clicked()), this, SLOT(ShowAuthors()));
  48. connect(ui->license, SIGNAL(clicked()), this, SLOT(ShowLicense()));
  49. QPointer<OBSAbout> about(this);
  50. OBSBasic *main = OBSBasic::Get();
  51. if (main->patronJson.empty() && !main->patronJsonThread) {
  52. RemoteTextThread *thread = new RemoteTextThread(
  53. "https://obsproject.com/patreon/about-box.json",
  54. "application/json");
  55. QObject::connect(thread, &RemoteTextThread::Result, main,
  56. &OBSBasic::UpdatePatronJson);
  57. QObject::connect(
  58. thread,
  59. SIGNAL(Result(const QString &, const QString &)), this,
  60. SLOT(ShowAbout()));
  61. main->patronJsonThread.reset(thread);
  62. thread->start();
  63. } else {
  64. ShowAbout();
  65. }
  66. }
  67. void OBSAbout::ShowAbout()
  68. {
  69. OBSBasic *main = OBSBasic::Get();
  70. if (main->patronJson.empty())
  71. return;
  72. std::string error;
  73. Json json = Json::parse(main->patronJson, error);
  74. const Json::array &patrons = json.array_items();
  75. QString text;
  76. text += "<h1>Top Patreon contributors:</h1>";
  77. text += "<p style=\"font-size:16px;\">";
  78. bool first = true;
  79. bool top = true;
  80. for (const Json &patron : patrons) {
  81. std::string name = patron["name"].string_value();
  82. std::string link = patron["link"].string_value();
  83. int amount = patron["amount"].int_value();
  84. if (top && amount < 10000) {
  85. text += "</p>";
  86. top = false;
  87. } else if (!first) {
  88. text += "<br/>";
  89. }
  90. if (!link.empty()) {
  91. text += "<a href=\"";
  92. text += QT_UTF8(link.c_str()).toHtmlEscaped();
  93. text += "\">";
  94. }
  95. text += QT_UTF8(name.c_str()).toHtmlEscaped();
  96. if (!link.empty())
  97. text += "</a>";
  98. if (first)
  99. first = false;
  100. }
  101. ui->textBrowser->setHtml(text);
  102. }
  103. void OBSAbout::ShowAuthors()
  104. {
  105. std::string path;
  106. QString error = "Error! File could not be read.\n\n \
  107. Go to: https://github.com/obsproject/obs-studio/blob/master/AUTHORS";
  108. #ifdef __APPLE__
  109. if (!GetDataFilePath("AUTHORS", path)) {
  110. #else
  111. if (!GetDataFilePath("authors/AUTHORS", path)) {
  112. #endif
  113. ui->textBrowser->setPlainText(error);
  114. return;
  115. }
  116. ui->textBrowser->setPlainText(QString::fromStdString(path));
  117. BPtr<char> text = os_quick_read_utf8_file(path.c_str());
  118. if (!text || !*text) {
  119. ui->textBrowser->setPlainText(error);
  120. return;
  121. }
  122. ui->textBrowser->setPlainText(QT_UTF8(text));
  123. }
  124. void OBSAbout::ShowLicense()
  125. {
  126. std::string path;
  127. QString error = "Error! File could not be read.\n\n \
  128. Go to: https://github.com/obsproject/obs-studio/blob/master/COPYING";
  129. if (!GetDataFilePath("license/gplv2.txt", path)) {
  130. ui->textBrowser->setPlainText(error);
  131. return;
  132. }
  133. BPtr<char> text = os_quick_read_utf8_file(path.c_str());
  134. if (!text || !*text) {
  135. ui->textBrowser->setPlainText(error);
  136. return;
  137. }
  138. ui->textBrowser->setPlainText(QT_UTF8(text));
  139. }