mirror of
https://github.com/obsproject/obs-studio.git
synced 2026-08-29 02:03:03 +08:00
frontend: Pass std::string as result from RemoteTextThread
RemoteTextThread and WhatsNewInfoThread explicitly convert their results into QString, but many consumers need std::string, converting them back. Let's just use std::string directly and only convert to QString where actually needed.
This commit is contained in:
committed by
Ryan Foster
parent
dba426630a
commit
e38e9f8070
@@ -324,14 +324,14 @@ void CrashHandler::handleExistingCrashLogUpload()
|
||||
}
|
||||
}
|
||||
|
||||
void CrashHandler::crashLogUploadResultHandler(const QString &uploadResult, const QString &error)
|
||||
void CrashHandler::crashLogUploadResultHandler(const std::string &uploadResult, const std::string &error)
|
||||
{
|
||||
if (uploadResult.isEmpty()) {
|
||||
emit crashLogUploadFailed(error);
|
||||
if (uploadResult.empty()) {
|
||||
emit crashLogUploadFailed(QString::fromStdString(error));
|
||||
return;
|
||||
}
|
||||
|
||||
json uploadResultData = json::parse(uploadResult.toStdString());
|
||||
json uploadResultData = json::parse(uploadResult);
|
||||
|
||||
try {
|
||||
std::string crashLogUrl = uploadResultData["url"];
|
||||
|
||||
@@ -83,7 +83,7 @@ private:
|
||||
PlatformType getPlatformType() const;
|
||||
|
||||
private slots:
|
||||
void crashLogUploadResultHandler(const QString &uploadResult, const QString &error);
|
||||
void crashLogUploadResultHandler(const std::string &uploadResult, const std::string &error);
|
||||
|
||||
// FIXME: Turn into private slot once OBSBasic does not handle application shutdown duties anymore.
|
||||
public slots:
|
||||
|
||||
@@ -89,9 +89,9 @@ void RemoteTextThread::run()
|
||||
if (code != CURLE_OK) {
|
||||
blog(LOG_WARNING, "RemoteTextThread: HTTP request failed. %s",
|
||||
strlen(error) ? error : curl_easy_strerror(code));
|
||||
emit Result(QString(), QT_UTF8(error));
|
||||
emit Result(std::string{}, std::string{error});
|
||||
} else {
|
||||
emit Result(QT_UTF8(str.c_str()), QString());
|
||||
emit Result(str, std::string{});
|
||||
}
|
||||
|
||||
curl_slist_free_all(header);
|
||||
|
||||
@@ -33,7 +33,7 @@ class RemoteTextThread : public QThread {
|
||||
void run() override;
|
||||
|
||||
signals:
|
||||
void Result(const QString &text, const QString &error);
|
||||
void Result(const std::string &text, const std::string &error);
|
||||
|
||||
public:
|
||||
inline RemoteTextThread(std::string url_, std::string contentType_ = std::string(),
|
||||
|
||||
@@ -268,7 +268,7 @@ try {
|
||||
std::string text;
|
||||
|
||||
if (FetchAndVerifyFile("whatsnew", "obs-studio/updates/whatsnew.json", WHATSNEW_URL, &text)) {
|
||||
emit Result(QString::fromStdString(text));
|
||||
emit Result(text);
|
||||
}
|
||||
} catch (std::string &text) {
|
||||
blog(LOG_WARNING, "%s: %s", __FUNCTION__, text.c_str());
|
||||
|
||||
@@ -11,7 +11,7 @@ class WhatsNewInfoThread : public QThread {
|
||||
virtual void run() override;
|
||||
|
||||
signals:
|
||||
void Result(const QString &text);
|
||||
void Result(const std::string &text);
|
||||
|
||||
public:
|
||||
inline WhatsNewInfoThread() {}
|
||||
|
||||
@@ -2108,12 +2108,12 @@ OBSBasic *OBSBasic::Get()
|
||||
return reinterpret_cast<OBSBasic *>(App()->GetMainWindow());
|
||||
}
|
||||
|
||||
void OBSBasic::UpdatePatronJson(const QString &text, const QString &error)
|
||||
void OBSBasic::UpdatePatronJson(const std::string &text, const std::string &error)
|
||||
{
|
||||
if (!error.isEmpty())
|
||||
if (!error.empty())
|
||||
return;
|
||||
|
||||
patronJson = QT_TO_UTF8(text);
|
||||
patronJson = text;
|
||||
}
|
||||
|
||||
void OBSBasic::SetDisplayAffinity(QWindow *window)
|
||||
|
||||
@@ -284,7 +284,7 @@ private:
|
||||
|
||||
public slots:
|
||||
void close();
|
||||
void UpdatePatronJson(const QString &text, const QString &error);
|
||||
void UpdatePatronJson(const std::string &text, const std::string &error);
|
||||
void UpdateEditMenu();
|
||||
void applicationShutdown() noexcept;
|
||||
void toggleMixerLayout();
|
||||
@@ -639,7 +639,7 @@ private slots:
|
||||
|
||||
void on_resetUI_triggered();
|
||||
|
||||
void logUploadFinished(const QString &text, const QString &error, OBS::LogFileType uploadType);
|
||||
void logUploadFinished(const std::string &text, const std::string &error, OBS::LogFileType uploadType);
|
||||
|
||||
void updateCheckFinished();
|
||||
|
||||
@@ -1603,7 +1603,7 @@ private:
|
||||
void CheckForUpdates(bool manualUpdate);
|
||||
|
||||
void MacBranchesFetched(const QString &branch, bool manualUpdate);
|
||||
void ReceivedIntroJson(const QString &text);
|
||||
void ReceivedIntroJson(const std::string &text);
|
||||
void ShowWhatsNew(const QString &url);
|
||||
|
||||
/* -------------------------------------
|
||||
|
||||
@@ -47,6 +47,7 @@
|
||||
|
||||
#include <qt-wrappers.hpp>
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
#include <QDesktopServices>
|
||||
|
||||
#ifdef _WIN32
|
||||
@@ -287,9 +288,10 @@ void OBSBasic::UploadLog(const char *subdir, const char *file, const LogUploadTy
|
||||
|
||||
logUploadThread.reset(thread);
|
||||
|
||||
connect(thread, &RemoteTextThread::Result, this, [this, uploadType](const QString &text, const QString &error) {
|
||||
logUploadFinished(text, error, uploadType);
|
||||
});
|
||||
connect(thread, &RemoteTextThread::Result, this,
|
||||
[this, uploadType](const std::string &text, const std::string &error) {
|
||||
logUploadFinished(text, error, uploadType);
|
||||
});
|
||||
|
||||
logUploadThread->start();
|
||||
}
|
||||
@@ -384,18 +386,17 @@ void OBSBasic::on_actionRestartSafe_triggered()
|
||||
}
|
||||
}
|
||||
|
||||
void OBSBasic::logUploadFinished(const QString &text, const QString &error, LogUploadType uploadType)
|
||||
void OBSBasic::logUploadFinished(const std::string &text, const std::string &error, LogUploadType uploadType)
|
||||
{
|
||||
OBSApp *app = App();
|
||||
|
||||
if (text.isEmpty()) {
|
||||
emit app->logUploadFailed(uploadType, error);
|
||||
if (text.empty()) {
|
||||
emit app->logUploadFailed(uploadType, QString::fromStdString(error));
|
||||
} else {
|
||||
OBSDataAutoRelease returnData = obs_data_create_from_json(QT_TO_UTF8(text));
|
||||
string resURL = obs_data_get_string(returnData, "url");
|
||||
QString logURL = resURL.c_str();
|
||||
nlohmann::json parsed = nlohmann::json::parse(text);
|
||||
std::string logURL = parsed["url"];
|
||||
|
||||
emit app->logUploadFinished(uploadType, logURL);
|
||||
emit app->logUploadFinished(uploadType, QString::fromStdString(logURL));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -60,7 +60,7 @@ template<typename OBSRef> struct SignalContainer {
|
||||
};
|
||||
} // namespace
|
||||
|
||||
void OBSBasic::ReceivedIntroJson(const QString &text)
|
||||
void OBSBasic::ReceivedIntroJson(const std::string &text)
|
||||
{
|
||||
#ifdef WHATSNEW_ENABLED
|
||||
if (isClosing()) {
|
||||
@@ -69,7 +69,7 @@ void OBSBasic::ReceivedIntroJson(const QString &text)
|
||||
|
||||
WhatsNewList items;
|
||||
try {
|
||||
nlohmann::json json = nlohmann::json::parse(text.toStdString());
|
||||
nlohmann::json json = nlohmann::json::parse(text);
|
||||
items = json.get<WhatsNewList>();
|
||||
} catch (nlohmann::json::exception &e) {
|
||||
blog(LOG_WARNING, "Parsing whatsnew data failed: %s", e.what());
|
||||
|
||||
Reference in New Issue
Block a user