diff --git a/src/branding/default/branding.desc b/src/branding/default/branding.desc index 5a8dd3f49..cd83b02f1 100644 --- a/src/branding/default/branding.desc +++ b/src/branding/default/branding.desc @@ -219,3 +219,16 @@ slideshow: "show.qml" slideshowAPI: 2 +# These options are to customize online uploading of logs to pastebins: +# - type : Defines the kind of pastebin service to be used.Currently +# it accepts two values: +# - none : disables the pastebin functionality +# - fiche : use fiche pastebin server +# - url : Defines the address of pastebin service to be used. +# Takes string as input +# - port : Defines the port number to be used to send logs. Takes +# integer as input +uploadServer : + type : "fiche" + url : "termbin.com" + port : 9999 diff --git a/src/libcalamaresui/Branding.cpp b/src/libcalamaresui/Branding.cpp index a5038d7ee..a71675e38 100644 --- a/src/libcalamaresui/Branding.cpp +++ b/src/libcalamaresui/Branding.cpp @@ -4,6 +4,7 @@ * SPDX-FileCopyrightText: 2017-2019 Adriaan de Groot * SPDX-FileCopyrightText: 2018 Raul Rodrigo Segura (raurodse) * SPDX-FileCopyrightText: 2019 Camilo Higuita + * SPDX-FileCopyrightText: 2021 Anubhav Choudhary * SPDX-License-Identifier: GPL-3.0-or-later * * Calamares is Free Software: see the License-Identifier above. @@ -86,6 +87,13 @@ const QStringList Branding::s_styleEntryStrings = "sidebarTextSelect", "sidebarTextHighlight" }; + +const QStringList Branding::s_uploadServerStrings = +{ + "type", + "url", + "port" +}; // clang-format on // *INDENT-ON* @@ -218,6 +226,12 @@ Branding::Branding( const QString& brandingFilePath, QObject* parent ) return imageFi.absoluteFilePath(); } ); loadStrings( m_style, doc, "style", []( const QString& s ) -> QString { return s; } ); + + const QVariantMap temp = CalamaresUtils::yamlMapToVariant( doc[ "uploadServer" ] ); + for ( auto it = temp.constBegin(); it != temp.constEnd(); ++it ) + { + m_uploadServer.insert( it.key(), it.value().toString() ); + } } catch ( YAML::Exception& e ) { @@ -278,6 +292,11 @@ Branding::imagePath( Branding::ImageEntry imageEntry ) const return m_images.value( s_imageEntryStrings.value( imageEntry ) ); } +QString +Branding::uploadServer( Branding::UploadServerEntry uploadServerEntry ) const +{ + return m_uploadServer.value( s_uploadServerStrings.value( uploadServerEntry ) ); +} QPixmap Branding::image( Branding::ImageEntry imageEntry, const QSize& size ) const diff --git a/src/libcalamaresui/Branding.h b/src/libcalamaresui/Branding.h index b03df3acd..87f71e862 100644 --- a/src/libcalamaresui/Branding.h +++ b/src/libcalamaresui/Branding.h @@ -4,6 +4,7 @@ * SPDX-FileCopyrightText: 2017-2018 Adriaan de Groot * SPDX-FileCopyrightText: 2018 Raul Rodrigo Segura (raurodse) * SPDX-FileCopyrightText: 2019 Camilo Higuita + * SPDX-FileCopyrightText: 2021 Anubhav Choudhary * SPDX-License-Identifier: GPL-3.0-or-later * * Calamares is Free Software: see the License-Identifier above. @@ -22,6 +23,7 @@ #include #include #include +#include namespace YAML { @@ -42,6 +44,7 @@ public: * e.g. *Branding::ProductName to get the string value for * the product name. */ + enum StringEntry { ProductName, @@ -80,6 +83,14 @@ public: }; Q_ENUM( StyleEntry ) + enum UploadServerEntry : short + { + Type, + URL, + Port + }; + Q_ENUM( UploadServerEntry ) + /** @brief Setting for how much the main window may expand. */ enum class WindowExpansion { @@ -223,6 +234,7 @@ public slots: QString styleString( StyleEntry styleEntry ) const; QString imagePath( ImageEntry imageEntry ) const; + QString uploadServer( UploadServerEntry uploadServerEntry ) const; PanelSide sidebarSide() const { return m_sidebarSide; } PanelSide navigationSide() const { return m_navigationSide; } @@ -233,12 +245,14 @@ private: static const QStringList s_stringEntryStrings; static const QStringList s_imageEntryStrings; static const QStringList s_styleEntryStrings; + static const QStringList s_uploadServerStrings; QString m_descriptorPath; // Path to descriptor (e.g. "/etc/calamares/default/branding.desc") QString m_componentName; // Matches last part of full path to containing directory QMap< QString, QString > m_strings; QMap< QString, QString > m_images; QMap< QString, QString > m_style; + QMap< QString, QString > m_uploadServer; /* The slideshow can be done in one of two ways: * - as a sequence of images diff --git a/src/libcalamaresui/ViewManager.cpp b/src/libcalamaresui/ViewManager.cpp index d25b7cdee..b229607ef 100644 --- a/src/libcalamaresui/ViewManager.cpp +++ b/src/libcalamaresui/ViewManager.cpp @@ -4,6 +4,7 @@ * SPDX-FileCopyrightText: 2017-2018 Adriaan de Groot * SPDX-FileCopyrightText: 2019 Dominic Hayes * SPDX-FileCopyrightText: 2019 Gabriel Craciunescu + * SPDX-FileCopyrightText: 2021 Anubhav Choudhary * SPDX-License-Identifier: GPL-3.0-or-later * * Calamares is Free Software: see the License-Identifier above. @@ -141,7 +142,8 @@ ViewManager::insertViewStep( int before, ViewStep* step ) void ViewManager::onInstallationFailed( const QString& message, const QString& details ) { - bool shouldOfferWebPaste = false; // TODO: config var + QString serverType = Calamares::Branding::instance()->uploadServer( Calamares::Branding::Type ); + bool shouldOfferWebPaste = CalamaresUtils::UploadServersList.contains( serverType ); cError() << "Installation failed:" << message; cDebug() << Logger::SubEntry << "- message:" << message; @@ -187,8 +189,16 @@ ViewManager::onInstallationFailed( const QString& message, const QString& detail connect( msgBox, &QMessageBox::buttonClicked, [msgBox]( QAbstractButton* button ) { if ( msgBox->buttonRole( button ) == QMessageBox::ButtonRole::YesRole ) { - // TODO: host and port should be configurable - QString pasteUrlMsg = CalamaresUtils::sendLogToPastebin( msgBox, QStringLiteral( "termbin.com" ), 9999 ); + QString pasteUrlMsg; + QString serverType = Calamares::Branding::instance()->uploadServer( Calamares::Branding::Type ); + if ( serverType == "fiche" ) + { + pasteUrlMsg = CalamaresUtils::ficheLogUpload( msgBox ); + } + else + { + pasteUrlMsg = QString(); + } 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 8099d9024..27ae7f8f7 100644 --- a/src/libcalamaresui/utils/Paste.cpp +++ b/src/libcalamaresui/utils/Paste.cpp @@ -9,20 +9,35 @@ #include "Paste.h" +#include "Branding.h" #include "utils/Logger.h" #include #include #include #include +#include +#include +#include namespace CalamaresUtils { +QStringList UploadServersList = { + "fiche" + // In future more serverTypes can be added as Calamares support them + // "none" serverType is explicitly not mentioned here +}; + QString -sendLogToPastebin( QObject* parent, const QString& ficheHost, quint16 fichePort ) +ficheLogUpload( QObject* parent ) { - QString pasteUrlFmt = parent->tr( "Install log posted to:\n%1" ); + + const QString& ficheHost = Calamares::Branding::instance()->uploadServer( Calamares::Branding::URL ); + quint16 fichePort = Calamares::Branding::instance()->uploadServer( Calamares::Branding::Port ).toInt(); + + QString pasteUrlFmt = parent->tr( "Install log posted to\n\n%1\n\nLink copied to clipboard" ); + QFile pasteSourceFile( Logger::logFile() ); if ( !pasteSourceFile.open( QIODevice::ReadOnly | QIODevice::Text ) ) { @@ -78,7 +93,17 @@ sendLogToPastebin( QObject* parent, const QString& ficheHost, quint16 fichePort QRegularExpression pasteUrlRegex( "^http[s]?://" + ficheHost ); QString pasteUrlMsg = QString( pasteUrlFmt ).arg( pasteUrlStr ); - if ( nBytesRead < 8 || !pasteUrl.isValid() || !pasteUrlRegex.match( pasteUrlStr ).hasMatch() ) + if ( nBytesRead >= 8 && pasteUrl.isValid() && pasteUrlRegex.match( pasteUrlStr ).hasMatch() ) + { + QClipboard* clipboard = QApplication::clipboard(); + clipboard->setText(pasteUrlStr, QClipboard::Clipboard); + + if (clipboard->supportsSelection()) + { + clipboard->setText(pasteUrlStr, QClipboard::Selection); + } + } + else { cError() << "No data from paste server"; return QString(); diff --git a/src/libcalamaresui/utils/Paste.h b/src/libcalamaresui/utils/Paste.h index f802dfe2e..29e73fc1c 100644 --- a/src/libcalamaresui/utils/Paste.h +++ b/src/libcalamaresui/utils/Paste.h @@ -10,7 +10,7 @@ #ifndef UTILS_PASTE_H #define UTILS_PASTE_H -#include // for quint16 +#include class QObject; class QString; @@ -22,7 +22,9 @@ namespace CalamaresUtils * * Returns the (string) URL that the pastebin gives us. */ -QString sendLogToPastebin( QObject* parent, const QString& ficheHost, quint16 fichePort ); +QString ficheLogUpload( QObject* parent ); + +extern QStringList UploadServersList; } // namespace CalamaresUtils