File indexing completed on 2024-05-05 05:48:57

0001 /*
0002     SPDX-FileCopyrightText: 2007 Nicolas Ternisien <nicolas.ternisien@gmail.com>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #pragma once
0008 
0009 #include <QIcon>
0010 #include <QObject>
0011 #include <QString>
0012 #include <QVariant>
0013 #include <QVector>
0014 
0015 #include "logFile.h"
0016 
0017 class Analyzer;
0018 class LogModeItemBuilder;
0019 class LogModeConfiguration;
0020 class LogModeConfigurationWidget;
0021 
0022 class QAction;
0023 
0024 struct ActionData {
0025     QString id;
0026     bool addToActionCollection = true;
0027     QVariant analyzerOptions;
0028 };
0029 Q_DECLARE_METATYPE(ActionData)
0030 
0031 // TODO Do not let this class visible to other classes (except sub-classes)
0032 class LogModePrivate
0033 {
0034 public:
0035     QString id;
0036 
0037     QString name;
0038 
0039     QString iconName;
0040 
0041     QIcon icon;
0042 
0043     QAction *action = nullptr;
0044 
0045     LogModeItemBuilder *itemBuilder = nullptr;
0046 
0047     LogModeConfigurationWidget *logModeConfigurationWidget = nullptr;
0048 
0049     QSharedPointer<LogModeConfiguration> logModeConfiguration;
0050 
0051     bool logFilesExist;
0052 };
0053 
0054 class LogMode : public QObject
0055 {
0056     Q_OBJECT
0057 
0058 public:
0059     LogMode(const QString &id, const QString &name, const QString &iconName);
0060 
0061     ~LogMode() override;
0062 
0063     QString id() const;
0064 
0065     QString name() const;
0066 
0067     QIcon icon() const;
0068 
0069     QAction *action() const;
0070 
0071     LogModeItemBuilder *itemBuilder() const;
0072 
0073     /**
0074      * Returns true if at least one log file exists for this mode.
0075      */
0076     bool filesExist() const;
0077 
0078     /**
0079      * Log mode configuration widget
0080      */
0081     LogModeConfigurationWidget *logModeConfigurationWidget() const;
0082 
0083     template<typename T>
0084     T logModeConfiguration()
0085     {
0086         return static_cast<T>(innerConfiguration());
0087     }
0088 
0089     /**
0090      * Create the Analyzer used to parse the log file
0091      */
0092     virtual Analyzer *createAnalyzer(const QVariant &options = QVariant()) = 0;
0093 
0094     /**
0095      * Create the log file list which will be read
0096      */
0097     virtual QVector<LogFile> createLogFiles() = 0;
0098 
0099 Q_SIGNALS:
0100     void menuChanged();
0101 
0102 protected:
0103     QAction *createDefaultAction();
0104 
0105     /**
0106      * Initializes the flag returned by filesExist().
0107      */
0108     void checkLogFilesPresence(const QStringList &paths);
0109 
0110     LogModePrivate *const d;
0111 
0112 private:
0113     /**
0114      * Log Mode Configuration
0115      */
0116     LogModeConfiguration *innerConfiguration() const;
0117 };