window-basic-about.cpp 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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)
  11. : QDialog(parent),
  12. ui(new Ui::OBSAbout)
  13. {
  14. ui->setupUi(this);
  15. setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
  16. QString bitness;
  17. QString ver;
  18. if(sizeof(void*) == 4)
  19. bitness = " (32 bit)";
  20. else if(sizeof(void*) == 8)
  21. bitness = " (64 bit)";
  22. #ifdef HAVE_OBSCONFIG_H
  23. ver += OBS_VERSION;
  24. #else
  25. ver += LIBOBS_API_MAJOR_VER + "." +
  26. LIBOBS_API_MINOR_VER + "." +
  27. LIBOBS_API_PATCH_VER;
  28. #endif
  29. ui->version->setText(ver + bitness);
  30. ui->contribute->setText(QTStr("About.Contribute"));
  31. ui->donate->setText("&nbsp;&nbsp;<a href='https://obsproject.com/donate'>" +
  32. QTStr("About.Donate") + "</a>");
  33. ui->donate->setTextInteractionFlags(Qt::TextBrowserInteraction);
  34. ui->donate->setOpenExternalLinks(true);
  35. ui->getInvolved->setText("&nbsp;&nbsp;<a href='https://github.com/obsproject/obs-studio/blob/master/CONTRIBUTING.rst'>" +
  36. QTStr("About.GetInvolved") + "</a>");
  37. ui->getInvolved->setTextInteractionFlags(Qt::TextBrowserInteraction);
  38. ui->getInvolved->setOpenExternalLinks(true);
  39. ui->about->setText("<a href='#'>" + QTStr("About") + "</a>");
  40. ui->authors->setText("<a href='#'>" + QTStr("About.Authors") + "</a>");
  41. ui->license->setText("<a href='#'>" + QTStr("About.License") + "</a>");
  42. ui->name->setProperty("themeID", "aboutName");
  43. ui->version->setProperty("themeID", "aboutVersion");
  44. ui->about->setProperty("themeID", "aboutHLayout");
  45. ui->authors->setProperty("themeID", "aboutHLayout");
  46. ui->license->setProperty("themeID", "aboutHLayout");
  47. ui->info->setProperty("themeID", "aboutInfo");
  48. connect(ui->about, SIGNAL(clicked()), this, SLOT(ShowAbout()));
  49. connect(ui->authors, SIGNAL(clicked()), this, SLOT(ShowAuthors()));
  50. connect(ui->license, SIGNAL(clicked()), this, SLOT(ShowLicense()));
  51. QPointer<OBSAbout> about(this);
  52. OBSBasic *main = OBSBasic::Get();
  53. if (main->patronJson.empty() && !main->patronJsonThread) {
  54. RemoteTextThread *thread = new RemoteTextThread(
  55. "https://obsproject.com/patreon/about-box.json",
  56. "application/json");
  57. QObject::connect(thread, &RemoteTextThread::Result,
  58. main, &OBSBasic::UpdatePatronJson);
  59. QObject::connect(thread, SIGNAL(Result(const QString &, const QString &)),
  60. this, 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. if (!GetDataFilePath("authors/AUTHORS", path)) {
  109. ui->textBrowser->setPlainText(error);
  110. return;
  111. }
  112. ui->textBrowser->setPlainText(QString::fromStdString(path));
  113. BPtr<char> text = os_quick_read_utf8_file(path.c_str());
  114. if (!text || !*text) {
  115. ui->textBrowser->setPlainText(error);
  116. return;
  117. }
  118. ui->textBrowser->setPlainText(QT_UTF8(text));
  119. }
  120. void OBSAbout::ShowLicense()
  121. {
  122. std::string path;
  123. QString error = "Error! File could not be read.\n\n \
  124. Go to: https://github.com/obsproject/obs-studio/blob/master/COPYING";
  125. if (!GetDataFilePath("license/gplv2.txt", path)) {
  126. ui->textBrowser->setPlainText(error);
  127. return;
  128. }
  129. BPtr<char> text = os_quick_read_utf8_file(path.c_str());
  130. if (!text || !*text) {
  131. ui->textBrowser->setPlainText(error);
  132. return;
  133. }
  134. ui->textBrowser->setPlainText(QT_UTF8(text));
  135. }