From cf48632f89383c9f96346ef8d0ac794f611766a0 Mon Sep 17 00:00:00 2001 From: Arttu Tarkiainen Date: Tue, 26 Jan 2021 15:58:42 +0200 Subject: Restructure logging utilities Create a singleton-pattern class as an encapsulation unit for holding and altering the state of debug printing attributes. Move related code from various places under a single umbrella header file for logging utilities, with some minor stylistic changes & cleanup. This acts as a preparatory change for providing non-blocking headless CLI runs when there is no TTY attached - that will be fixed in a follow-up change. Change-Id: Ib7f72cf75362c3ea6713058e92eda997d6df55c3 Reviewed-by: Katja Marttila --- src/libs/installer/packagemanagercore.cpp | 56 ++++--------------------------- 1 file changed, 7 insertions(+), 49 deletions(-) (limited to 'src/libs/installer/packagemanagercore.cpp') diff --git a/src/libs/installer/packagemanagercore.cpp b/src/libs/installer/packagemanagercore.cpp index ca128c6ea..4a0d2c191 100644 --- a/src/libs/installer/packagemanagercore.cpp +++ b/src/libs/installer/packagemanagercore.cpp @@ -1,6 +1,6 @@ /************************************************************************** ** -** Copyright (C) 2020 The Qt Company Ltd. +** Copyright (C) 2021 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the Qt Installer Framework. @@ -45,7 +45,7 @@ #include "settings.h" #include "installercalculator.h" #include "uninstallercalculator.h" -#include "printoutput.h" +#include "loggingutils.h" #include @@ -1202,40 +1202,6 @@ PackageManagerCore::PackageManagerCore(qint64 magicmaker, const QListgainAdminRights(); - gainedAdminRights = true; - } - - RemoteFileEngine file; - file.setFileName(fileName); - if (file.open(openMode)) { - file.write(data.constData(), data.size()); - file.close(); - if (gainedAdminRights) - m_core->dropAdminRights(); - return true; - } - - if (gainedAdminRights) - m_core->dropAdminRights(); - - return false; - } - -private: - PackageManagerCore *m_core; -}; - /*! Destroys the instance. */ @@ -2225,7 +2191,7 @@ void PackageManagerCore::listAvailablePackages(const QString ®exp) if (matchedPackages.count() == 0) qCDebug(QInstaller::lcInstallerInstallLog) << "No matching packages found."; else - QInstaller::printPackageInformation(matchedPackages, localInstalledPackages()); + LoggingHandler::instance().printPackageInformation(matchedPackages, localInstalledPackages()); } bool PackageManagerCore::componentUninstallableFromCommandLine(const QString &componentName) @@ -2321,7 +2287,7 @@ void PackageManagerCore::listInstalledPackages(const QString ®exp) if (re.match(package.name).hasMatch()) packages.append(package); } - QInstaller::printLocalPackageInformation(packages); + LoggingHandler::instance().printLocalPackageInformation(packages); } /*! @@ -3177,15 +3143,7 @@ bool PackageManagerCore::containsValue(const QString &key) const */ bool PackageManagerCore::isVerbose() const { - return QInstaller::isVerbose(); -} - -/*! - Returns verbose level. -*/ -VerbosityLevel PackageManagerCore::verboseLevel() const -{ - return QInstaller::verboseLevel(); + return LoggingHandler::instance().isVerbose(); } /*! @@ -3194,7 +3152,7 @@ VerbosityLevel PackageManagerCore::verboseLevel() const */ void PackageManagerCore::setVerbose(bool on) { - QInstaller::setVerbose(on); + LoggingHandler::instance().setVerbose(on); } PackageManagerCore::Status PackageManagerCore::status() const @@ -3562,7 +3520,7 @@ bool PackageManagerCore::updateComponentData(struct Data &data, Component *compo component->setUninstalled(); const QString localPath = component->localTempPath(); - if (verboseLevel() == VerbosityLevel::Detailed) { + if (LoggingHandler::instance().verboseLevel() == LoggingHandler::Detailed) { static QString lastLocalPath; if (lastLocalPath != localPath) qCDebug(QInstaller::lcDeveloperBuild()) << "Url is:" << localPath; -- cgit v1.2.3