1
0

window-basic-about.cpp 4.6 KB

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