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