From acc8419295fdd6b908f603ab117d4fc8b226184f Mon Sep 17 00:00:00 2001 From: jp9000 Date: Sun, 5 May 2019 20:00:06 -0700 Subject: [PATCH] UI: Add Patreon contributors to About dialog --- UI/forms/OBSAbout.ui | 336 +++++++++++++++++++++----------------- UI/window-basic-about.cpp | 85 +++++++--- UI/window-basic-about.hpp | 1 - UI/window-basic-main.cpp | 8 + UI/window-basic-main.hpp | 6 + 5 files changed, 263 insertions(+), 173 deletions(-) diff --git a/UI/forms/OBSAbout.ui b/UI/forms/OBSAbout.ui index edac7bef5..790a96563 100644 --- a/UI/forms/OBSAbout.ui +++ b/UI/forms/OBSAbout.ui @@ -1,173 +1,211 @@ OBSAbout - + 0 0 - 792 - 389 + 840 + 519 About - - - - 30 - 30 - 256 - 256 - + + + 0 - - - 256 - 256 - + + 0 - - - 256 - 256 - + + 0 - - + + 0 - - :res/images/obs.png - - - true - - - - - - 320 - 30 - 441 - 261 - - - - - 0 - - - - - OBS Studio + + + + 30 + + + 30 + + + 10 + + + 6 + + + 6 + + + + + + 256 + 256 + + + + + 256 + 256 + + + + + + + :res/images/obs.png + + + true + + + + + + + 0 + + + + + OBS Studio + + + + + + + Version + + + + + + + About.Info + + + true + + + + + + + Contribute + + + true + + + + + + + Donate + + + + + + + Get Involved + + + + + + + Qt::Vertical + + + QSizePolicy::Fixed + + + + 20 + 20 + + + + + + + + true + + + + + + + + + + + + 0 + 60 + + + + + 0 - - - - - - Version + + 0 - - - - - - About.Info + + 0 - - true + + 0 - - - - - - Contribute + + 0 - - true - - - - - - - Donate - - - - - - - Get Involved - - - - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - - 0 - 320 - 791 - 71 - - - - - 0 - - - - - About - - - Qt::AlignCenter - - - - - - - Authors - - - Qt::AlignCenter - - - - - - - License - - - Qt::AlignCenter - - - - - + + + + About + + + Qt::AlignCenter + + + + + + + Authors + + + Qt::AlignCenter + + + + + + + License + + + Qt::AlignCenter + + + + + + + diff --git a/UI/window-basic-about.cpp b/UI/window-basic-about.cpp index 725d89431..150af7df5 100644 --- a/UI/window-basic-about.cpp +++ b/UI/window-basic-about.cpp @@ -1,9 +1,14 @@ #include "window-basic-about.hpp" #include "window-basic-main.hpp" #include "qt-wrappers.hpp" +#include "remote-text.hpp" #include #include #include +#include +#include + +using namespace json11; OBSAbout::OBSAbout(QWidget *parent) : QDialog(parent), @@ -11,8 +16,6 @@ OBSAbout::OBSAbout(QWidget *parent) { ui->setupUi(this); - setFixedSize(size()); - setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint); QString bitness; @@ -34,12 +37,12 @@ OBSAbout::OBSAbout(QWidget *parent) ui->version->setText(ver + bitness); ui->contribute->setText(QTStr("About.Contribute")); - ui->donate->setText("" + + ui->donate->setText("  " + QTStr("About.Donate") + ""); ui->donate->setTextInteractionFlags(Qt::TextBrowserInteraction); ui->donate->setOpenExternalLinks(true); - ui->getInvolved->setText("" + + ui->getInvolved->setText("  " + QTStr("About.GetInvolved") + ""); ui->getInvolved->setTextInteractionFlags(Qt::TextBrowserInteraction); ui->getInvolved->setOpenExternalLinks(true); @@ -48,8 +51,6 @@ OBSAbout::OBSAbout(QWidget *parent) ui->authors->setText("" + QTStr("About.Authors") + ""); ui->license->setText("" + QTStr("About.License") + ""); - ui->textBrowser->hide(); - ui->name->setProperty("themeID", "aboutName"); ui->version->setProperty("themeID", "aboutVersion"); ui->about->setProperty("themeID", "aboutHLayout"); @@ -60,15 +61,65 @@ OBSAbout::OBSAbout(QWidget *parent) connect(ui->about, SIGNAL(clicked()), this, SLOT(ShowAbout())); connect(ui->authors, SIGNAL(clicked()), this, SLOT(ShowAuthors())); connect(ui->license, SIGNAL(clicked()), this, SLOT(ShowLicense())); + + QPointer about(this); + + OBSBasic *main = OBSBasic::Get(); + if (main->patronJson.empty() && !main->patronJsonThread) { + RemoteTextThread *thread = new RemoteTextThread( + "https://obsproject.com/patreon/about-box.json", + "application/json"); + QObject::connect(thread, &RemoteTextThread::Result, + main, &OBSBasic::UpdatePatronJson); + QObject::connect(thread, SIGNAL(Result(const QString &, const QString &)), + this, SLOT(ShowAbout())); + main->patronJsonThread.reset(thread); + thread->start(); + } else { + ShowAbout(); + } } void OBSAbout::ShowAbout() { - ui->textBrowser->hide(); - ui->info->show(); - ui->contribute->show(); - ui->donate->show(); - ui->getInvolved->show(); + OBSBasic *main = OBSBasic::Get(); + + if (main->patronJson.empty()) + return; + + std::string error; + Json json = Json::parse(main->patronJson, error); + const Json::array &patrons = json.array_items(); + std::stringstream text; + + text << "

Top Patreon contributors:

"; + text << "

"; + bool first = true; + bool top = true; + + for (const Json &patron : patrons) { + std::string name = patron["name"].string_value(); + std::string link = patron["link"].string_value(); + int amount = patron["amount"].int_value(); + + if (top && amount < 10000) { + text << "

"; + top = false; + } else if (!first) { + text << "
"; + } + + if (!link.empty()) + text << ""; + text << name; + if (!link.empty()) + text << ""; + + if (first) + first = false; + } + + ui->textBrowser->setHtml(QT_UTF8(text.str().c_str())); } void OBSAbout::ShowAuthors() @@ -92,12 +143,6 @@ void OBSAbout::ShowAuthors() } ui->textBrowser->setPlainText(QT_UTF8(text)); - - ui->info->hide(); - ui->contribute->hide(); - ui->donate->hide(); - ui->getInvolved->hide(); - ui->textBrowser->show(); } void OBSAbout::ShowLicense() @@ -119,10 +164,4 @@ void OBSAbout::ShowLicense() } ui->textBrowser->setPlainText(QT_UTF8(text)); - - ui->info->hide(); - ui->contribute->hide(); - ui->donate->hide(); - ui->getInvolved->hide(); - ui->textBrowser->show(); } diff --git a/UI/window-basic-about.hpp b/UI/window-basic-about.hpp index 3a21bbe67..bb507fe2c 100644 --- a/UI/window-basic-about.hpp +++ b/UI/window-basic-about.hpp @@ -11,7 +11,6 @@ class OBSAbout : public QDialog { public: explicit OBSAbout(QWidget *parent = 0); -private: std::unique_ptr ui; private slots: diff --git a/UI/window-basic-main.cpp b/UI/window-basic-main.cpp index 02e8a1b79..e8e17c953 100644 --- a/UI/window-basic-main.cpp +++ b/UI/window-basic-main.cpp @@ -7312,3 +7312,11 @@ bool SceneRenameDelegate::eventFilter(QObject *editor, QEvent *event) return QStyledItemDelegate::eventFilter(editor, event); } + +void OBSBasic::UpdatePatronJson(const QString &text, const QString &error) +{ + if (!error.isEmpty()) + return; + + patronJson = QT_TO_UTF8(text); +} diff --git a/UI/window-basic-main.hpp b/UI/window-basic-main.hpp index d624dcc8d..e7a413bf5 100644 --- a/UI/window-basic-main.hpp +++ b/UI/window-basic-main.hpp @@ -114,6 +114,7 @@ private: class OBSBasic : public OBSMainWindow { Q_OBJECT + friend class OBSAbout; friend class OBSBasicPreview; friend class OBSBasicStatusBar; friend class OBSBasicSourceSelect; @@ -234,6 +235,9 @@ private: QPointer programLayout; QPointer programLabel; + QScopedPointer patronJsonThread; + std::string patronJson; + void UpdateMultiviewProjectorMenu(); void DrawBackdrop(float cx, float cy); @@ -463,6 +467,8 @@ public slots: bool create_new, const QString &name = QString()); + void UpdatePatronJson(const QString &text, const QString &error); + private slots: void AddSceneItem(OBSSceneItem item); void AddScene(OBSSource source);