|
| 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 |
0 commit comments