From 81badc36f44bd8618ffada5cab481be5bf387999 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 9 Mar 2021 15:42:21 +0100 Subject: [PATCH] [libcalamaresui] Implement abstract doLogUpload() API This is a "do the right thing" function, which then calls the implementation-specific code for each type. --- src/libcalamaresui/ViewManager.cpp | 5 +++-- src/libcalamaresui/utils/Paste.cpp | 30 +++++++++++++++++++++++------- src/libcalamaresui/utils/Paste.h | 5 ++++- 3 files changed, 30 insertions(+), 10 deletions(-) diff --git a/src/libcalamaresui/ViewManager.cpp b/src/libcalamaresui/ViewManager.cpp index 30614fdfa..3d0fccb78 100644 --- a/src/libcalamaresui/ViewManager.cpp +++ b/src/libcalamaresui/ViewManager.cpp @@ -142,7 +142,8 @@ ViewManager::insertViewStep( int before, ViewStep* step ) void ViewManager::onInstallationFailed( const QString& message, const QString& details ) { - bool shouldOfferWebPaste = Calamares::Branding::instance()->uploadServer().first != Calamares::Branding::UploadServerType::None; + bool shouldOfferWebPaste + = Calamares::Branding::instance()->uploadServer().first != Calamares::Branding::UploadServerType::None; cError() << "Installation failed:" << message; cDebug() << Logger::SubEntry << "- message:" << message; @@ -188,7 +189,7 @@ ViewManager::onInstallationFailed( const QString& message, const QString& detail connect( msgBox, &QMessageBox::buttonClicked, [msgBox]( QAbstractButton* button ) { if ( msgBox->buttonRole( button ) == QMessageBox::ButtonRole::YesRole ) { - QString pasteUrlMsg = CalamaresUtils::Paste::doLogUpload(); + QString pasteUrlMsg = CalamaresUtils::Paste::doLogUpload( msgBox ); QString pasteUrlTitle = tr( "Install Log Paste URL" ); if ( pasteUrlMsg.isEmpty() ) diff --git a/src/libcalamaresui/utils/Paste.cpp b/src/libcalamaresui/utils/Paste.cpp index b65223a43..e6ac63f88 100644 --- a/src/libcalamaresui/utils/Paste.cpp +++ b/src/libcalamaresui/utils/Paste.cpp @@ -36,14 +36,10 @@ logFileContents() return pasteSourceFile.read( 16384 /* bytes */ ); } -namespace CalamaresUtils -{ -QString -ficheLogUpload( QObject* parent ) +static QString +ficheLogUpload( const QUrl& serverUrl, QObject* parent ) { - auto [ type, serverUrl ] = Calamares::Branding::instance()->uploadServer(); - QByteArray pasteData = logFileContents(); if ( pasteData.isEmpty() ) { @@ -110,4 +106,24 @@ ficheLogUpload( QObject* parent ) cDebug() << Logger::SubEntry << "Paste server results:" << pasteUrlMsg; return pasteUrlMsg; } -} // namespace CalamaresUtils + +QString +CalamaresUtils::Paste::doLogUpload( QObject* parent ) +{ + auto [ type, serverUrl ] = Calamares::Branding::instance()->uploadServer(); + if ( !serverUrl.isValid() ) + { + cWarning() << "Upload configure with invalid URL"; + return QString(); + } + + switch ( type ) + { + case Calamares::Branding::UploadServerType::None: + cWarning() << "No upload configured."; + return QString(); + case Calamares::Branding::UploadServerType::Fiche: + return ficheLogUpload( serverUrl, parent ); + } + return QString(); +} diff --git a/src/libcalamaresui/utils/Paste.h b/src/libcalamaresui/utils/Paste.h index 784f2f28a..6258e57a0 100644 --- a/src/libcalamaresui/utils/Paste.h +++ b/src/libcalamaresui/utils/Paste.h @@ -16,12 +16,15 @@ class QObject; namespace CalamaresUtils { +namespace Paste +{ /** @brief Send the current log file to a pastebin * * Returns the (string) URL that the pastebin gives us. */ -QString ficheLogUpload( QObject* parent ); +QString doLogUpload( QObject* parent ); +} // namespace Paste } // namespace CalamaresUtils