[libcalamaresui] Factor out the pastebin UI

- offer a convenience method for showing a popup and
  URL information and copying the URL to the clipboard
- use that from ViewManager (on failure) and DebugWindow (on demand)
This commit is contained in:
Adriaan de Groot 2021-03-19 14:17:34 +01:00
parent 981e96ea7f
commit 779e5ecf8f
4 changed files with 45 additions and 21 deletions

View File

@ -216,7 +216,7 @@ DebugWindow::DebugWindow()
// Send Log button only if it would be useful // Send Log button only if it would be useful
m_ui->sendLogButton->setVisible( CalamaresUtils::Paste::isEnabled() ); m_ui->sendLogButton->setVisible( CalamaresUtils::Paste::isEnabled() );
connect( m_ui->sendLogButton, &QPushButton::clicked, [this]() { CalamaresUtils::Paste::doLogUpload( this ); } ); connect( m_ui->sendLogButton, &QPushButton::clicked, [this]() { CalamaresUtils::Paste::doLogUploadUI( this ); } );
CALAMARES_RETRANSLATE( m_ui->retranslateUi( this ); setWindowTitle( tr( "Debug information" ) ); ); CALAMARES_RETRANSLATE( m_ui->retranslateUi( this ); setWindowTitle( tr( "Debug information" ) ); );
} }

View File

@ -190,26 +190,7 @@ ViewManager::onInstallationFailed( const QString& message, const QString& detail
connect( msgBox, &QMessageBox::buttonClicked, [msgBox]( QAbstractButton* button ) { connect( msgBox, &QMessageBox::buttonClicked, [msgBox]( QAbstractButton* button ) {
if ( msgBox->buttonRole( button ) == QMessageBox::ButtonRole::YesRole ) if ( msgBox->buttonRole( button ) == QMessageBox::ButtonRole::YesRole )
{ {
QString pasteUrl = CalamaresUtils::Paste::doLogUpload( msgBox ); CalamaresUtils::Paste::doLogUploadUI( msgBox );
QString pasteUrlMessage;
if ( pasteUrl.isEmpty() )
{
pasteUrlMessage = tr( "The upload was unsuccessful. No web-paste was done." );
}
else
{
QClipboard* clipboard = QApplication::clipboard();
clipboard->setText( pasteUrl, QClipboard::Clipboard );
if ( clipboard->supportsSelection() )
{
clipboard->setText( pasteUrl, QClipboard::Selection );
}
QString pasteUrlFmt = tr( "Install log posted to\n\n%1\n\nLink copied to clipboard" );
pasteUrlMessage = pasteUrlFmt.arg( pasteUrl );
}
QMessageBox::critical( nullptr, tr( "Install Log Paste URL" ), pasteUrlMessage );
} }
QApplication::quit(); QApplication::quit();
} ); } );

View File

@ -14,10 +14,14 @@
#include "utils/Logger.h" #include "utils/Logger.h"
#include "utils/Units.h" #include "utils/Units.h"
#include <QApplication>
#include <QClipboard>
#include <QFile> #include <QFile>
#include <QFileInfo> #include <QFileInfo>
#include <QMessageBox>
#include <QTcpSocket> #include <QTcpSocket>
#include <QUrl> #include <QUrl>
#include <QWidget>
using namespace CalamaresUtils::Units; using namespace CalamaresUtils::Units;
@ -127,6 +131,37 @@ CalamaresUtils::Paste::doLogUpload( QObject* parent )
return QString(); return QString();
} }
QString
CalamaresUtils::Paste::doLogUploadUI( QWidget* parent )
{
// These strings originated in the ViewManager class
QString pasteUrl = CalamaresUtils::Paste::doLogUpload( parent );
QString pasteUrlMessage;
if ( pasteUrl.isEmpty() )
{
pasteUrlMessage = QCoreApplication::translate( "Calamares::ViewManager",
"The upload was unsuccessful. No web-paste was done." );
}
else
{
QClipboard* clipboard = QApplication::clipboard();
clipboard->setText( pasteUrl, QClipboard::Clipboard );
if ( clipboard->supportsSelection() )
{
clipboard->setText( pasteUrl, QClipboard::Selection );
}
QString pasteUrlFmt = QCoreApplication::translate( "Calamares::ViewManager",
"Install log posted to\n\n%1\n\nLink copied to clipboard" );
pasteUrlMessage = pasteUrlFmt.arg( pasteUrl );
}
QMessageBox::critical(
nullptr, QCoreApplication::translate( "Calamares::ViewManager", "Install Log Paste URL" ), pasteUrlMessage );
return pasteUrl;
}
bool bool
CalamaresUtils::Paste::isEnabled() CalamaresUtils::Paste::isEnabled()
{ {

View File

@ -13,6 +13,7 @@
#include <QString> #include <QString>
class QObject; class QObject;
class QWidget;
namespace CalamaresUtils namespace CalamaresUtils
{ {
@ -24,6 +25,13 @@ namespace Paste
*/ */
QString doLogUpload( QObject* parent ); QString doLogUpload( QObject* parent );
/** @brief Send the current log file to a pastebin
*
* As doLogUpload(), but also sets the clipboard and displays
* a message saying it's been done.
*/
QString doLogUploadUI( QWidget* parent );
/** @brief Is paste enabled? /** @brief Is paste enabled?
* *
* Checks the branding instance if paste can be done. * Checks the branding instance if paste can be done.