[libcalamaresui] Move message- and clipboard handling

- The Paste API promises just a (string) URL back, not
  a whole message, so return just the URL from the
  abstract API and the concrete (fiche) implementation.
- Set clipboard contents from the UI
- Build (translated) message in the UI code
This commit is contained in:
Adriaan de Groot 2021-03-09 15:51:24 +01:00
parent 81badc36f4
commit 846d6abaa8
2 changed files with 20 additions and 25 deletions

View file

@ -27,6 +27,7 @@
#include <QApplication>
#include <QBoxLayout>
#include <QClipboard>
#include <QFile>
#include <QMessageBox>
#include <QMetaObject>
@ -189,16 +190,26 @@ 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( msgBox );
QString pasteUrlTitle = tr( "Install Log Paste URL" );
if ( pasteUrlMsg.isEmpty() )
QString pasteUrl = CalamaresUtils::Paste::doLogUpload( msgBox );
QString pasteUrlMessage;
if ( pasteUrl.isEmpty() )
{
pasteUrlMsg = tr( "The upload was unsuccessful. No web-paste was done." );
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 );
}
// TODO: make the URL clickable, or copy it to the clipboard automatically
QMessageBox::critical( nullptr, pasteUrlTitle, pasteUrlMsg );
QMessageBox::critical( nullptr, tr( "Install Log Paste URL" ), pasteUrlMessage );
}
QApplication::quit();
} );

View file

@ -12,10 +12,7 @@
#include "Branding.h"
#include "utils/Logger.h"
#include <QApplication>
#include <QClipboard>
#include <QFile>
#include <QStringList>
#include <QTcpSocket>
#include <QUrl>
@ -82,29 +79,16 @@ ficheLogUpload( const QUrl& serverUrl, QObject* parent )
socket->close();
QUrl pasteUrl = QUrl( QString( responseText ).trimmed(), QUrl::StrictMode );
QString pasteUrlStr = pasteUrl.toString();
QString pasteUrlFmt = parent->tr( "Install log posted to\n\n%1\n\nLink copied to clipboard" );
QString pasteUrlMsg = pasteUrlFmt.arg( pasteUrlStr );
if ( pasteUrl.isValid() && pasteUrl.host() == serverUrl.host() )
{
QClipboard* clipboard = QApplication::clipboard();
clipboard->setText( pasteUrlStr, QClipboard::Clipboard );
if ( clipboard->supportsSelection() )
{
clipboard->setText( pasteUrlStr, QClipboard::Selection );
}
cDebug() << Logger::SubEntry << "Paste server results:" << pasteUrl;
return pasteUrl.toString();
}
else
{
cError() << "No data from paste server";
return QString();
}
cDebug() << Logger::SubEntry << "Paste server results:" << pasteUrlMsg;
return pasteUrlMsg;
}
QString