From b4078f36342638165651a95ad43dae2e98a2017b Mon Sep 17 00:00:00 2001
From: Anubhav Choudhary <ac.10edu@gmail.com>
Date: Mon, 25 Jan 2021 01:09:20 +0530
Subject: [PATCH] Changed branding keynames + minor fixes

---
 src/branding/default/branding.desc | 17 +++++++----------
 src/libcalamaresui/Branding.cpp    |  8 +++-----
 src/libcalamaresui/Branding.h      | 14 ++++++--------
 src/libcalamaresui/ViewManager.cpp | 24 ++++++++++++++++++------
 src/libcalamaresui/utils/Paste.cpp | 30 ++++++++++++++++++++++--------
 src/libcalamaresui/utils/Paste.h   |  6 ++++--
 6 files changed, 60 insertions(+), 39 deletions(-)

diff --git a/src/branding/default/branding.desc b/src/branding/default/branding.desc
index 8325dd17f..92d0bba10 100644
--- a/src/branding/default/branding.desc
+++ b/src/branding/default/branding.desc
@@ -220,17 +220,14 @@ slideshowAPI: 2
 
 
 # These options are to customize online uploading of logs to pastebins:
-#  - style  :  Defines the kind of pastebin service to be used. ie it can
-#              provide the functionality of controlling privacy of 
-#              paste (in future).Currently only "fiche" servers
-#              are supported. Takes string as input
+#  - 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
-#  - enable :  Defines if the functionality is to be used or not. Takes 
-#              bool as input
-logUpload.style   :    "fiche"
-logUpload.url     :    "termbin.com"
-logUpload.port    :    9999
-logUpload.enable  :    true
+uploadServer.type    :    "fiche"
+uploadServer.url     :    "termbin.com"
+uploadServer.port    :    9999
diff --git a/src/libcalamaresui/Branding.cpp b/src/libcalamaresui/Branding.cpp
index c08fd732e..40383c992 100644
--- a/src/libcalamaresui/Branding.cpp
+++ b/src/libcalamaresui/Branding.cpp
@@ -87,7 +87,6 @@ const QStringList Branding::s_styleEntryStrings =
     "sidebarTextSelect",
     "sidebarTextHighlight"
 };
-
 // clang-format on
 // *INDENT-ON*
 
@@ -513,10 +512,9 @@ Branding::initSimpleSettings( const YAML::Node& doc )
         m_windowHeight = WindowDimension( CalamaresUtils::windowPreferredHeight, WindowDimensionUnit::Pixies );
     }
 
-    m_logUploadEnable = doc[ "logUpload.enable" ].as< bool >( false );
-    m_logUploadURL = getString( doc, "logUpload.url" );
-    m_logUploadPort = doc[ "logUpload.port" ].as< int >();
-    m_logUploadStyle = getString( doc, "logUpload.style" );
+    m_uploadServerURL  = getString( doc, "uploadServer.url" );
+    m_uploadServerPort = doc[ "uploadServer.port" ].as< int >();
+    m_uploadServerType = getString( doc, "uploadServer.type" );
 }
 
 void
diff --git a/src/libcalamaresui/Branding.h b/src/libcalamaresui/Branding.h
index d273c81c6..493579a34 100644
--- a/src/libcalamaresui/Branding.h
+++ b/src/libcalamaresui/Branding.h
@@ -218,10 +218,9 @@ public:
 
 
     //Paste functionality related
-    bool logUploadEnable() { return m_logUploadEnable; };
-    QString logUploadURL() { return m_logUploadURL; };
-    int logUploadPort() { return m_logUploadPort; };
-    QString logUploadStyle() { return m_logUploadStyle; };
+    QString uploadServerType() { return m_uploadServerType; };
+    QString uploadServerURL() { return m_uploadServerURL; };
+    int uploadServerPort() { return m_uploadServerPort; };
 
 public slots:
     QString string( StringEntry stringEntry ) const;
@@ -270,10 +269,9 @@ private:
     bool m_welcomeStyleCalamares;
     bool m_welcomeExpandingLogo;
 
-    bool m_logUploadEnable;
-    QString m_logUploadURL;
-    int m_logUploadPort;
-    QString m_logUploadStyle;
+    QString m_uploadServerType;
+    QString m_uploadServerURL;
+    int m_uploadServerPort;
 
     WindowExpansion m_windowExpansion;
     WindowDimension m_windowHeight, m_windowWidth;
diff --git a/src/libcalamaresui/ViewManager.cpp b/src/libcalamaresui/ViewManager.cpp
index 5786c44a5..ae2460c37 100644
--- a/src/libcalamaresui/ViewManager.cpp
+++ b/src/libcalamaresui/ViewManager.cpp
@@ -141,7 +141,8 @@ ViewManager::insertViewStep( int before, ViewStep* step )
 void
 ViewManager::onInstallationFailed( const QString& message, const QString& details )
 {
-    bool shouldOfferWebPaste = Calamares::Branding::instance()->logUploadEnable();
+    QString UploadServerType = Calamares::Branding::instance()->uploadServerType();
+    bool shouldOfferWebPaste = CalamaresUtils::UploadServersList.contains( UploadServerType );
 
     cError() << "Installation failed:";
     cDebug() << "- message:" << message;
@@ -184,9 +185,16 @@ ViewManager::onInstallationFailed( const QString& message, const QString& detail
     connect( msgBox, &QMessageBox::buttonClicked, [msgBox]( QAbstractButton* button ) {
         if ( msgBox->buttonRole( button ) == QMessageBox::ButtonRole::YesRole )
         {
-            QString pasteURLHost = Calamares::Branding::instance()->logUploadURL();
-            int pasteURLPort = Calamares::Branding::instance()->logUploadPort();
-            QString pasteUrlMsg = CalamaresUtils::sendLogToPastebin( msgBox, pasteURLHost, pasteURLPort );
+            QString pasteUrlMsg;
+            QString UploadServerType = Calamares::Branding::instance()->uploadServerType();
+            if ( UploadServerType == "fiche" )
+            {
+                pasteUrlMsg = CalamaresUtils::sendLogToPastebin( msgBox );
+            }
+            else
+            {
+                pasteUrlMsg = QString();
+            }
 
             QString pasteUrlTitle = tr( "Install Log Paste URL" );
             if ( pasteUrlMsg.isEmpty() )
@@ -532,9 +540,13 @@ ViewManager::updateCancelEnabled( bool enabled )
 }
 
 void
-ViewManager::updateBackAndNextVisibility( bool visible ) { UPDATE_BUTTON_PROPERTY( backAndNextVisible, visible ) }
+ViewManager::updateBackAndNextVisibility( bool visible )
+{
+    UPDATE_BUTTON_PROPERTY( backAndNextVisible, visible )
+}
 
-QVariant ViewManager::data( const QModelIndex& index, int role ) const
+QVariant 
+ViewManager::data( const QModelIndex& index, int role ) const
 {
     if ( !index.isValid() )
     {
diff --git a/src/libcalamaresui/utils/Paste.cpp b/src/libcalamaresui/utils/Paste.cpp
index a48a7c097..269876017 100644
--- a/src/libcalamaresui/utils/Paste.cpp
+++ b/src/libcalamaresui/utils/Paste.cpp
@@ -9,6 +9,7 @@
 
 #include "Paste.h"
 
+#include "Branding.h"
 #include "utils/Logger.h"
 
 #include <QFile>
@@ -17,13 +18,24 @@
 #include <QUrl>
 #include <QClipboard>
 #include <QApplication>
+#include <QStringList>
 
 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 )
+sendLogToPastebin( QObject* parent )
 {
+
+    const QString& ficheHost = Calamares::Branding::instance()->uploadServerURL();
+    quint16 fichePort = Calamares::Branding::instance()->uploadServerPort();
+
     QString pasteUrlFmt = parent->tr( "Install log posted to\n\n%1\n\nLink copied to clipboard" );
 
     QFile pasteSourceFile( Logger::logFile() );
@@ -81,15 +93,17 @@ sendLogToPastebin( QObject* parent, const QString& ficheHost, quint16 fichePort
     QRegularExpression pasteUrlRegex( "^http[s]?://" + ficheHost );
     QString pasteUrlMsg = QString( pasteUrlFmt ).arg( pasteUrlStr );
 
-    QClipboard* clipboard = QApplication::clipboard();
-    clipboard->setText(pasteUrlStr, QClipboard::Clipboard);
-
-    if (clipboard->supportsSelection())
+    if ( nBytesRead >= 8 && pasteUrl.isValid() && pasteUrlRegex.match( pasteUrlStr ).hasMatch() )
     {
-         clipboard->setText(pasteUrlStr, QClipboard::Selection);
-    }
+        QClipboard* clipboard = QApplication::clipboard();
+        clipboard->setText(pasteUrlStr, QClipboard::Clipboard);
 
-    if ( nBytesRead < 8 || !pasteUrl.isValid() || !pasteUrlRegex.match( pasteUrlStr ).hasMatch() )
+        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..69adfa99c 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 <qglobal.h>  // for quint16
+#include<QStringList>
 
 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 sendLogToPastebin( QObject* parent );
+
+extern QStringList UploadServersList;
 
 }  // namespace CalamaresUtils