[libcalamaresui] Implement abstract doLogUpload() API

This is a "do the right thing" function, which then calls
the implementation-specific code for each type.
This commit is contained in:
Adriaan de Groot 2021-03-09 15:42:21 +01:00
parent 1ff854f05d
commit 81badc36f4
3 changed files with 30 additions and 10 deletions

View File

@ -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() )

View File

@ -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();
}

View File

@ -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