1 /* 2 KCupsLog, a cups log viewer tool 3 SPDX-FileCopyrightText: 2007 Nicolas Ternisien <nicolas.ternisien@gmail.com> 4 5 SPDX-License-Identifier: GPL-2.0-or-later 6 */ 7 8 #include "cupsFactory.h" 9 10 #include <KLocalizedString> 11 12 #include "ksystemlog_debug.h" 13 #include "logMode.h" 14 #include "multipleActions.h" 15 16 #include "cupsAccessLogMode.h" 17 #include "cupsLogMode.h" 18 #include "cupsPageLogMode.h" 19 #include "cupsPdfLogMode.h" 20 21 #include "cupsConfiguration.h" 22 #include "cupsConfigurationWidget.h" 23 createLogModes() const24QList<LogMode *> CupsLogModeFactory::createLogModes() const 25 { 26 // Create the shared configuration and configuration widget between the logModes 27 QSharedPointer<CupsConfiguration> logModeConfiguration = QSharedPointer<CupsConfiguration>(new CupsConfiguration()); 28 auto logModeConfigurationWidget = new CupsConfigurationWidget(); 29 30 QList<LogMode *> logModes; 31 logModes.append(new CupsLogMode(logModeConfiguration, logModeConfigurationWidget)); 32 logModes.append(new CupsAccessLogMode(logModeConfiguration, logModeConfigurationWidget)); 33 logModes.append(new CupsPageLogMode(logModeConfiguration, logModeConfigurationWidget)); 34 logModes.append(new CupsPdfLogMode(logModeConfiguration, logModeConfigurationWidget)); 35 36 return logModes; 37 } 38 createLogModeAction() const39LogModeAction *CupsLogModeFactory::createLogModeAction() const 40 { 41 LogMode *cupsLogMode = Globals::instance().findLogMode(QStringLiteral(CUPS_LOG_MODE_ID)); 42 LogMode *cupsAccessLogMode = Globals::instance().findLogMode(QStringLiteral(CUPS_ACCESS_LOG_MODE_ID)); 43 LogMode *cupsPageLogMode = Globals::instance().findLogMode(QStringLiteral(CUPS_PAGE_LOG_MODE_ID)); 44 LogMode *cupsPdfLogMode = Globals::instance().findLogMode(QStringLiteral(CUPS_PDF_LOG_MODE_ID)); 45 46 bool cupsLogsExist = cupsLogMode->filesExist(); 47 bool cupsAccessLogsExist = cupsAccessLogMode->filesExist(); 48 bool cupsPageLogsExist = cupsPageLogMode->filesExist(); 49 bool cupsPdfLogsExist = cupsPdfLogMode->filesExist(); 50 51 if (!cupsLogsExist && !cupsAccessLogsExist && !cupsPageLogsExist && !cupsPdfLogsExist) { 52 return nullptr; 53 } 54 55 auto multipleActions = new MultipleActions(QIcon::fromTheme(QStringLiteral(CUPS_MODE_ICON)), i18n("Cups"), cupsLogMode); 56 57 if (cupsLogsExist) { 58 multipleActions->addInnerAction(cupsLogMode->action()); 59 } 60 61 if (cupsAccessLogsExist) { 62 multipleActions->addInnerAction(cupsAccessLogMode->action()); 63 } 64 65 if (cupsPageLogsExist) { 66 multipleActions->addInnerAction(cupsPageLogMode->action()); 67 } 68 69 if (cupsPdfLogsExist) { 70 multipleActions->addInnerAction(cupsPdfLogMode->action()); 71 } 72 73 multipleActions->setCategory(LogModeAction::ServicesCategory); 74 75 return multipleActions; 76 } 77