window-basic-about.cpp 4.4 KB

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