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.
This commit is contained in:
jp9000 2015-05-23 23:39:39 -07:00
parent 72e3ec7b4c
commit 13bed1a448
2 changed files with 40 additions and 49 deletions

View file

@ -23,8 +23,6 @@
#include <QShowEvent>
#include <QDesktopServices>
#include <QFileDialog>
#include <QNetworkRequest>
#include <QNetworkReply>
#include <util/dstr.h>
#include <util/util.hpp>
@ -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<QNetworkReply *>(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<QNetworkReply *>(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,

View file

@ -17,7 +17,6 @@
#pragma once
#include <QNetworkAccessManager>
#include <QBuffer>
#include <QAction>
#include <obs.hpp>
@ -71,14 +70,15 @@ private:
QPointer<QTimer> saveTimer;
QPointer<QThread> updateCheckThread;
QPointer<QThread> logUploadThread;
QPointer<OBSBasicInteraction> interaction;
QPointer<OBSBasicProperties> properties;
QPointer<OBSBasicTransform> transformWindow;
QPointer<OBSBasicAdvAudio> advAudioWindow;
QPointer<OBSBasicFilters> filters;
QNetworkAccessManager networkManager;
QPointer<QTimer> 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();