Skip to content

Commit e84a608

Browse files
committed
frontend: Add LogUploadDialog class
This is an extended variant of the prior OBSLogReply class. The major change is that the dialog encapsulates the interface workflow for log uploads, including the confirmation for an upload and handling successful or unsuccessful uploads.
1 parent f5fb189 commit e84a608

File tree

8 files changed

+379
-0
lines changed

8 files changed

+379
-0
lines changed

frontend/OBSApp.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1178,6 +1178,22 @@ const char *OBSApp::GetLastCrashLog() const
11781178
return lastCrashLogFile.c_str();
11791179
}
11801180

1181+
OBS::LogFileState OBSApp::getLogFileState(OBS::LogFileType type) const
1182+
{
1183+
switch (type) {
1184+
case OBS::LogFileType::CrashLog: {
1185+
bool hasNewCrashLog = crashHandler_->hasNewCrashLog();
1186+
1187+
return (hasNewCrashLog) ? OBS::LogFileState::New : OBS::LogFileState::Uploaded;
1188+
}
1189+
case OBS::LogFileType::CurrentAppLog:
1190+
case OBS::LogFileType::LastAppLog:
1191+
return OBS::LogFileState::New;
1192+
default:
1193+
return OBS::LogFileState::NoState;
1194+
}
1195+
}
1196+
11811197
bool OBSApp::TranslateString(const char *lookupVal, const char **out) const
11821198
{
11831199
for (obs_frontend_translate_ui_cb cb : translatorHooks) {

frontend/OBSApp.hpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ Q_DECLARE_METATYPE(VoidFunc)
4141
class QFileSystemWatcher;
4242
class QSocketNotifier;
4343

44+
namespace OBS {
45+
46+
enum class LogFileType { NoType, CurrentAppLog, LastAppLog, CrashLog };
47+
48+
enum class LogFileState { NoState, New, Uploaded };
49+
} // namespace OBS
4450
struct UpdateBranch {
4551
QString name;
4652
QString display_name;
@@ -154,6 +160,8 @@ private slots:
154160

155161
const char *GetLastCrashLog() const;
156162

163+
OBS::LogFileState getLogFileState(OBS::LogFileType type) const;
164+
157165
std::string GetVersionString(bool platform = true) const;
158166
bool IsPortableMode();
159167
bool IsUpdaterDisabled();
@@ -195,6 +203,9 @@ public slots:
195203

196204
signals:
197205
void StyleChanged();
206+
207+
void logUploadFinished(OBS::LogFileType, const QString &fileUrl);
208+
void logUploadFailed(OBS::LogFileType, const QString &errorMessage);
198209
};
199210

200211
int GetAppConfigPath(char *path, size_t size, const char *name);

frontend/cmake/ui-dialogs.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ target_link_libraries(obs-studio PRIVATE OBS::properties-view)
77
target_sources(
88
obs-studio
99
PRIVATE
10+
dialogs/LogUploadDialog.cpp
11+
dialogs/LogUploadDialog.hpp
1012
dialogs/NameDialog.cpp
1113
dialogs/NameDialog.hpp
1214
dialogs/OAuthLogin.cpp

frontend/cmake/ui-qt.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ target_sources(
3131
forms/AutoConfigVideoPage.ui
3232
forms/ColorSelect.ui
3333
forms/obs.qrc
34+
forms/LogUploadDialog.ui
3435
forms/OBSAbout.ui
3536
forms/OBSAdvAudio.ui
3637
forms/OBSBasic.ui

frontend/data/locale/en-US.ini

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,17 @@ LogReturnDialog.Description.Crash="Your crash report has been uploaded. You can
459459
LogReturnDialog.CopyURL="Copy URL"
460460
LogReturnDialog.AnalyzeURL="Analyze"
461461
LogReturnDialog.ErrorUploadingLog="Error uploading log file"
462+
LogUploadDialog.Title="OBS Studio Log File Upload"
463+
LogUploadDialog.Labels.PrivacyNotice="Please read the <a href='https://obsproject.com/privacy-policy'>Privacy Policy</a> and its section regarding file uploads before uploading any files."
464+
LogUploadDialog.Labels.Progress="Log upload in progress - please wait..."
465+
LogUploadDialog.Labels.Description.AppLog="Your log file has been uploaded. You can now share the URL for debugging or support purposes."
466+
LogUploadDialog.Labels.Description.CrashLog="Your crash report has been uploaded. You can now share the URL for debugging purposes."
467+
LogUploadDialog.Buttons.ConfirmUpload="Continue Upload..."
468+
LogUploadDialog.Buttons.CopyURL="Copy Log URL"
469+
LogUploadDialog.Buttons.AnalyzeURL="Analyze Log File"
470+
LogUploadDialog.Buttons.RetryButton="Retry Upload..."
471+
LogUploadDialog.Errors.Template="An error occurred while trying to upload the file:\n\n%1"
472+
LogUploadDialog.Errors.NoLogFile="No file to upload found or file was empty."
462473

463474
# remux dialog
464475
Remux.SourceFile="OBS Recording"
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
/******************************************************************************
2+
Copyright (C) 2023 by Lain Bailey <[email protected]>
3+
4+
This program is free software: you can redistribute it and/or modify
5+
it under the terms of the GNU General Public License as published by
6+
the Free Software Foundation, either version 2 of the License, or
7+
(at your option) any later version.
8+
9+
This program is distributed in the hope that it will be useful,
10+
but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
GNU General Public License for more details.
13+
14+
You should have received a copy of the GNU General Public License
15+
along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
******************************************************************************/
17+
18+
#include "LogUploadDialog.hpp"
19+
20+
#include <OBSApp.hpp>
21+
22+
#include <QClipboard>
23+
#include <QDesktopServices>
24+
#include <QUrlQuery>
25+
26+
#include "moc_LogUploadDialog.cpp"
27+
28+
namespace OBS {
29+
LogUploadDialog::LogUploadDialog(QWidget *parent, LogFileType uploadType)
30+
: QDialog(parent),
31+
ui(new Ui::LogUploadDialog),
32+
uploadType_(uploadType)
33+
{
34+
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
35+
ui->setupUi(this);
36+
37+
ui->stackedWidget->setCurrentIndex(0);
38+
ui->uploadProgress->setVisible(false);
39+
40+
if (uploadType_ == LogFileType::CrashLog) {
41+
ui->analyzeURL->hide();
42+
ui->description->setText(Str("LogUploadDialog.Labels.Description.CrashLog"));
43+
}
44+
45+
connect(ui->confirmUploadButton, &QPushButton::clicked, this, &LogUploadDialog::startLogUpload);
46+
connect(ui->retryButton, &QPushButton::clicked, this, &LogUploadDialog::startLogUpload);
47+
connect(ui->copyURL, &QPushButton::clicked, this, &LogUploadDialog::copyToClipBoard);
48+
connect(ui->analyzeURL, &QPushButton::clicked, this, &LogUploadDialog::openAnalyzeURL);
49+
50+
OBSApp *app = App();
51+
connect(app, &OBSApp::logUploadFinished, this, &LogUploadDialog::handleUploadSuccess);
52+
connect(app, &OBSApp::logUploadFailed, this, &LogUploadDialog::handleUploadFailure);
53+
54+
installEventFilter(CreateShortcutFilter());
55+
56+
LogFileState uploadState = app->getLogFileState(uploadType);
57+
switch (uploadState) {
58+
case LogFileState::Uploaded:
59+
startLogUpload();
60+
break;
61+
default:
62+
break;
63+
}
64+
}
65+
66+
void LogUploadDialog::startLogUpload()
67+
{
68+
if (uploadType_ == LogFileType::NoType) {
69+
return;
70+
}
71+
72+
ui->confirmUploadButton->setEnabled(false);
73+
ui->uploadProgress->setVisible(true);
74+
setCursor(Qt::WaitCursor);
75+
76+
OBSApp *app = App();
77+
78+
switch (uploadType_) {
79+
case LogFileType::CrashLog:
80+
app->uploadLastCrashLog();
81+
break;
82+
case LogFileType::CurrentAppLog:
83+
app->uploadCurrentAppLog();
84+
break;
85+
case LogFileType::LastAppLog:
86+
app->uploadLastAppLog();
87+
break;
88+
default:
89+
break;
90+
}
91+
}
92+
93+
void LogUploadDialog::handleUploadSuccess(LogFileType, const QString &fileURL)
94+
{
95+
unsetCursor();
96+
ui->confirmUploadButton->setEnabled(true);
97+
ui->uploadProgress->setVisible(false);
98+
99+
ui->urlEdit->setText(fileURL);
100+
ui->stackedWidget->setCurrentIndex(1);
101+
}
102+
103+
void LogUploadDialog::handleUploadFailure(LogFileType, const QString &errorMessage)
104+
{
105+
unsetCursor();
106+
ui->confirmUploadButton->setEnabled(true);
107+
ui->uploadProgress->setVisible(false);
108+
109+
QString errorDescription = QTStr("LogUploadDialog.Errors.Template").arg(errorMessage);
110+
ui->uploadErrorMessage->setText(errorDescription);
111+
ui->stackedWidget->setCurrentIndex(2);
112+
}
113+
114+
void LogUploadDialog::copyToClipBoard() const
115+
{
116+
QClipboard *clipboard = QApplication::clipboard();
117+
clipboard->setText(ui->urlEdit->text());
118+
}
119+
120+
void LogUploadDialog::openAnalyzeURL() const
121+
{
122+
QUrlQuery queryParameters;
123+
queryParameters.addQueryItem("log_url", QUrl::toPercentEncoding(ui->urlEdit->text()));
124+
QUrl analyzerUrl = QUrl("https://obsproject.com/tools/analyzer", QUrl::TolerantMode);
125+
126+
analyzerUrl.setQuery(queryParameters);
127+
128+
QDesktopServices::openUrl(analyzerUrl);
129+
}
130+
} // namespace OBS
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/******************************************************************************
2+
Copyright (C) 2023 by Lain Bailey <[email protected]>
3+
4+
This program is free software: you can redistribute it and/or modify
5+
it under the terms of the GNU General Public License as published by
6+
the Free Software Foundation, either version 2 of the License, or
7+
(at your option) any later version.
8+
9+
This program is distributed in the hope that it will be useful,
10+
but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
GNU General Public License for more details.
13+
14+
You should have received a copy of the GNU General Public License
15+
along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
******************************************************************************/
17+
18+
#pragma once
19+
20+
#include "ui_LogUploadDialog.h"
21+
22+
#include <QDialog>
23+
24+
#include <filesystem>
25+
26+
namespace OBS {
27+
28+
enum class LogFileType;
29+
30+
class LogUploadDialog : public QDialog {
31+
Q_OBJECT
32+
33+
private:
34+
std::unique_ptr<Ui::LogUploadDialog> ui;
35+
36+
LogFileType uploadType_;
37+
38+
public:
39+
LogUploadDialog(QWidget *parent, LogFileType uploadType);
40+
41+
private slots:
42+
void startLogUpload();
43+
void handleUploadSuccess(LogFileType uploadType, const QString &fileURL);
44+
void handleUploadFailure(LogFileType uploadType, const QString &errorMessage);
45+
46+
void copyToClipBoard() const;
47+
void openAnalyzeURL() const;
48+
};
49+
} // namespace OBS

0 commit comments

Comments
 (0)