[libcalamaresui] Simplify getting URL response

- get a QByteArray rather than going through a char[] buffer
- bytes-read is not important since the RE can only match if
  there **are** that many characters.
This commit is contained in:
Adriaan de Groot 2021-03-09 14:38:43 +01:00
parent 1bf95eacb0
commit 8af5fb5da5

View File

@ -90,20 +90,17 @@ ficheLogUpload( QObject* parent )
} }
cDebug() << Logger::SubEntry << "Reading response from paste server"; cDebug() << Logger::SubEntry << "Reading response from paste server";
QByteArray responseText = socket->readLine( 1024 );
char resp[ 1024 ];
resp[ 0 ] = '\0';
qint64 nBytesRead = socket->readLine( resp, 1024 );
socket->close(); socket->close();
QUrl pasteUrl = QUrl( QString( resp ).trimmed(), QUrl::StrictMode ); QUrl pasteUrl = QUrl( QString( responseText ).trimmed(), QUrl::StrictMode );
QString pasteUrlStr = pasteUrl.toString(); QString pasteUrlStr = pasteUrl.toString();
QRegularExpression pasteUrlRegex( "^http[s]?://" + ficheHost ); QRegularExpression pasteUrlRegex( "^http[s]?://" + ficheHost );
QString pasteUrlFmt = parent->tr( "Install log posted to\n\n%1\n\nLink copied to clipboard" ); QString pasteUrlFmt = parent->tr( "Install log posted to\n\n%1\n\nLink copied to clipboard" );
QString pasteUrlMsg = pasteUrlFmt.arg( pasteUrlStr ); QString pasteUrlMsg = pasteUrlFmt.arg( pasteUrlStr );
if ( nBytesRead >= 8 && pasteUrl.isValid() && pasteUrlRegex.match( pasteUrlStr ).hasMatch() ) if ( pasteUrl.isValid() && pasteUrlRegex.match( pasteUrlStr ).hasMatch() )
{ {
QClipboard* clipboard = QApplication::clipboard(); QClipboard* clipboard = QApplication::clipboard();
clipboard->setText( pasteUrlStr, QClipboard::Clipboard ); clipboard->setText( pasteUrlStr, QClipboard::Clipboard );