window-basic-about.cpp 4.5 KB

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