From 13bed1a448e3726819778e5759bdf456556b6bf9 Mon Sep 17 00:00:00 2001 From: jp9000 Date: Sat, 23 May 2015 23:39:39 -0700 Subject: [PATCH] UI: Replace Qt5Network classes with libcurl The Qt5Network classes seem to only support OpenSSL, and because OpenSSL isn't available on windows, we would have to distribute it with the program to get SSL access working. The problem with that is that OpenSSL is not GPL-compatible, so we cannot distribute OpenSSL with the program, which means we have to find a better (and preferably superior) library for accessing remote files that can use the windows SSPI for our SSL needs, which comes with the operating system. Fortunately, libcurl is probably the best library out there, and can be compiled with SSPI instead of OpenSSL, so we're just going to switch to libcurl instead. Originally I thought it didn't support SSPI, otherwise I would have implemented it sooner. As a side note, this will make it so we'll able to get files from the internet via plugins, which will be quite useful. --- obs/window-basic-main.cpp | 79 +++++++++++++++++---------------------- obs/window-basic-main.hpp | 10 ++--- 2 files changed, 40 insertions(+), 49 deletions(-) diff --git a/obs/window-basic-main.cpp b/obs/window-basic-main.cpp index 21e29b32b..914ce5c9d 100644 --- a/obs/window-basic-main.cpp +++ b/obs/window-basic-main.cpp @@ -23,8 +23,6 @@ #include #include #include -#include -#include #include #include @@ -46,6 +44,7 @@ #include "qt-wrappers.hpp" #include "display-helpers.hpp" #include "volume-control.hpp" +#include "remote-text.hpp" #include "ui_OBSBasic.h" @@ -1249,16 +1248,17 @@ void OBSBasic::CheckForUpdates() #else ui->actionCheckForUpdates->setEnabled(false); - string versionString("obs-basic "); - versionString += App()->GetVersionString(); + if (updateCheckThread) { + updateCheckThread->wait(); + delete updateCheckThread; + } - QNetworkRequest request; - request.setUrl(QUrl("https://obsproject.com/obs2_update/basic.json")); - request.setRawHeader("User-Agent", versionString.c_str()); - - QNetworkReply *reply = networkManager.get(request); - connect(reply, SIGNAL(finished()), - this, SLOT(updateFileFinished())); + RemoteTextThread *thread = new RemoteTextThread( + "https://obsproject.com/obs2_update/basic.json"); + updateCheckThread = thread; + connect(thread, &RemoteTextThread::Result, + this, &OBSBasic::updateFileFinished); + updateCheckThread->start(); #endif } @@ -1270,22 +1270,16 @@ void OBSBasic::CheckForUpdates() #define VERSION_ENTRY "other" #endif -void OBSBasic::updateFileFinished() +void OBSBasic::updateFileFinished(const QString &text, const QString &error) { ui->actionCheckForUpdates->setEnabled(true); - QNetworkReply *reply = qobject_cast(sender()); - if (!reply || reply->error()) { - blog(LOG_WARNING, "Update check failed: %s", - QT_TO_UTF8(reply->errorString())); + if (text.isEmpty()) { + blog(LOG_WARNING, "Update check failed: %s", QT_TO_UTF8(error)); return; } - QByteArray raw = reply->readAll(); - if (!raw.length()) - return; - - obs_data_t *returnData = obs_data_create_from_json(raw.constData()); + obs_data_t *returnData = obs_data_create_from_json(QT_TO_UTF8(text)); obs_data_t *versionData = obs_data_get_obj(returnData, VERSION_ENTRY); const char *description = obs_data_get_string(returnData, "description"); @@ -1326,8 +1320,6 @@ void OBSBasic::updateFileFinished() obs_data_release(versionData); obs_data_release(returnData); - - reply->deleteLater(); } void OBSBasic::RemoveSelectedScene() @@ -1857,6 +1849,11 @@ void OBSBasic::closeEvent(QCloseEvent *event) if (!event->isAccepted()) return; + if (updateCheckThread) + updateCheckThread->wait(); + if (logUploadThread) + logUploadThread->wait(); + /* Check all child dialogs and ensure they run their proper closeEvent * methods before exiting the application. Otherwise Qt doesn't send * the proper QCloseEvent messages. */ @@ -2444,17 +2441,18 @@ void OBSBasic::UploadLog(const char *file) QBuffer *postData = new QBuffer(); postData->setData(json, (int) strlen(json)); - QNetworkRequest postReq(QUrl("https://api.github.com/gists")); - postReq.setHeader(QNetworkRequest::ContentTypeHeader, - "application/json"); + if (logUploadThread) { + logUploadThread->wait(); + delete logUploadThread; + } - QNetworkReply *reply = networkManager.post(postReq, postData); - - /* set the reply as parent, so the buffer is deleted with the reply */ - postData->setParent(reply); - - connect(reply, SIGNAL(finished()), - this, SLOT(logUploadFinished())); + RemoteTextThread *thread = new RemoteTextThread( + "https://api.github.com/gists", + "application/json", json); + logUploadThread = thread; + connect(thread, &RemoteTextThread::Result, + this, &OBSBasic::logUploadFinished); + logUploadThread->start(); } void OBSBasic::on_actionShowLogs_triggered() @@ -2498,30 +2496,23 @@ void OBSBasic::on_actionCheckForUpdates_triggered() CheckForUpdates(); } -void OBSBasic::logUploadFinished() +void OBSBasic::logUploadFinished(const QString &text, const QString &error) { ui->menuLogFiles->setEnabled(true); - QNetworkReply *reply = qobject_cast(sender()); - if (!reply || reply->error()) { + if (text.isEmpty()) { QMessageBox::information(this, QTStr("LogReturnDialog.ErrorUploadingLog"), - reply->errorString()); + error); return; } - QByteArray raw = reply->readAll(); - if (!raw.length()) - return; - - obs_data_t *returnData = obs_data_create_from_json(raw.constData()); + obs_data_t *returnData = obs_data_create_from_json(QT_TO_UTF8(text)); QString logURL = obs_data_get_string(returnData, "html_url"); obs_data_release(returnData); OBSLogReply logDialog(this, logURL); logDialog.exec(); - - reply->deleteLater(); } static void RenameListItem(OBSBasic *parent, QListWidget *listWidget, diff --git a/obs/window-basic-main.hpp b/obs/window-basic-main.hpp index f200db73d..524c30e5c 100644 --- a/obs/window-basic-main.hpp +++ b/obs/window-basic-main.hpp @@ -17,7 +17,6 @@ #pragma once -#include #include #include #include @@ -71,14 +70,15 @@ private: QPointer saveTimer; + QPointer updateCheckThread; + QPointer logUploadThread; + QPointer interaction; QPointer properties; QPointer transformWindow; QPointer advAudioWindow; QPointer filters; - QNetworkAccessManager networkManager; - QPointer cpuUsageTimer; os_cpu_usage_info_t *cpuUsageInfo = nullptr; @@ -319,9 +319,9 @@ private slots: void on_previewDisabledLabel_customContextMenuRequested( const QPoint &pos); - void logUploadFinished(); + void logUploadFinished(const QString &text, const QString &error); - void updateFileFinished(); + void updateFileFinished(const QString &text, const QString &error); void AddSourceFromAction();