Warning, file /system/kjournald/lib/filtercriteriamodel.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /*
0002     SPDX-License-Identifier: LGPL-2.1-or-later OR MIT
0003     SPDX-FileCopyrightText: 2021 Andreas Cord-Landwehr <cordlandwehr@kde.org>
0004 */
0005 
0006 #ifndef FILTERCRITERIAMODEL_H
0007 #define FILTERCRITERIAMODEL_H
0008 
0009 #include "journaldhelper.h"
0010 #include "kjournald_export.h"
0011 #include <QAbstractItemModel>
0012 #include <QVector>
0013 #include <memory>
0014 
0015 class FilterCriteriaModelPrivate;
0016 
0017 /**
0018  * @brief The JournaldUniqueQueryModel class provides an item model abstraction for journald queryunique API
0019  *
0020  * This class is useful when creating a list model for contents like:
0021  * - boot ids in specific journal database
0022  * - systemd units in specific journal database
0023  * - priorities in specific journal database
0024  *
0025  * The model can be create from an arbitrary local journald database by defining a path or from the
0026  * system's default journal. Values can either be set by @a setFieldString for arbitrary values or in a
0027  * typesafe manner via @a setField for most common fields.
0028  */
0029 class KJOURNALD_EXPORT FilterCriteriaModel : public QAbstractItemModel
0030 {
0031     Q_OBJECT
0032     Q_PROPERTY(QString journalPath WRITE setJournaldPath RESET setSystemJournal)
0033     /**
0034      * Filter for message priorities
0035      */
0036     Q_PROPERTY(int priorityFilter READ priorityFilter NOTIFY priorityFilterChanged)
0037     /**
0038      * Filter list for systemd units
0039      **/
0040     Q_PROPERTY(QStringList systemdUnitFilter READ systemdUnitFilter NOTIFY systemdUnitFilterChanged)
0041     /**
0042      * Filter list for executables (see journald '_EXE' field)
0043      **/
0044     Q_PROPERTY(QStringList exeFilter READ exeFilter NOTIFY exeFilterChanged)
0045     /**
0046      * if set to true, Kernel messages are added to the log output
0047      **/
0048     Q_PROPERTY(bool kernelFilter READ isKernelFilterEnabled NOTIFY kernelFilterChanged)
0049 
0050 public:
0051     enum Category : quint8 {
0052         TRANSPORT = 0,
0053         PRIORITY = 1,
0054         SYSTEMD_UNIT = 2,
0055         EXE = 3,
0056     };
0057     Q_ENUM(Category)
0058 
0059     enum Roles {
0060         TEXT = Qt::DisplayRole,
0061         LONGTEXT = Qt::ToolTipRole,
0062         SELECTED = Qt::CheckStateRole,
0063         CATEGORY = Qt::UserRole + 1,
0064         DATA = Qt::UserRole + 2,
0065     };
0066     Q_ENUM(Roles)
0067 
0068     /**
0069      * @brief Create filter criteria model for the system journal
0070      *
0071      * This tree model provides a tree based structure for the most common filter options.
0072      *
0073      * @param parent the QObject parent
0074      */
0075     explicit FilterCriteriaModel(QObject *parent = nullptr);
0076 
0077     /**
0078      * @brief Create filter criteria model
0079      *
0080      * This tree model provides a tree based structure for the most common filter options.
0081      *
0082      * @param journalPath path to the journald database
0083      * @param parent the QObject parent
0084      */
0085     FilterCriteriaModel(const QString &journalPath, QObject *parent = nullptr);
0086 
0087     /**
0088      * @brief Destroys the object
0089      */
0090     ~FilterCriteriaModel() override;
0091 
0092     /**
0093      * Reset model by reading from a new journald database
0094      *
0095      * @param path The path to directory that obtains the journald DB, usually ending with "journal".
0096      * @return true if path could be found and opened, otherwise false
0097      */
0098     bool setJournaldPath(const QString &path);
0099 
0100     /**
0101      * Switch to local system's default journald database
0102      *
0103      * For details regarding preference, see journald documentation.
0104      */
0105     void setSystemJournal();
0106 
0107     /**
0108      * @return the currently selected priority threshold for displayed log entries
0109      */
0110     int priorityFilter() const;
0111 
0112     /**
0113      * @return the list of enabled system units
0114      */
0115     QStringList systemdUnitFilter() const;
0116 
0117     /**
0118      * @return the list of enabled processes
0119      */
0120     QStringList exeFilter() const;
0121 
0122     /**
0123      * @return true if kernel log entries shall be shown, otherwise false
0124      */
0125     bool isKernelFilterEnabled() const;
0126 
0127     /**
0128      * @copydoc QAbstractItemModel::rolesNames()
0129      */
0130     QHash<int, QByteArray> roleNames() const override;
0131 
0132     /**
0133      * @copydoc QAbstractItemModel::index()
0134      */
0135     QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override;
0136 
0137     /**
0138      * @copydoc QAbstractItemModel::parent()
0139      */
0140     QModelIndex parent(const QModelIndex &index) const override;
0141 
0142     /**
0143      * @copydoc QAbstractItemModel::rowCount()
0144      */
0145     int rowCount(const QModelIndex &parent = QModelIndex()) const override;
0146 
0147     /**
0148      * @copydoc QAbstractItemModel::columnCount()
0149      */
0150     int columnCount(const QModelIndex &parent = QModelIndex()) const override;
0151 
0152     /**
0153      * @copydoc QAbstractItemModel::data()
0154      */
0155     QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
0156 
0157     /**
0158      * @copydoc QAbstractItemModel::setData()
0159      */
0160     Q_INVOKABLE bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
0161 
0162     /**
0163      * @brief Convenience method for access to list of all entries' data of @p category with their selected states
0164      */
0165     QVector<std::pair<QString, bool>> entries(FilterCriteriaModel::Category category) const;
0166 
0167 Q_SIGNALS:
0168     void priorityFilterChanged(int priority);
0169     void systemdUnitFilterChanged();
0170     void exeFilterChanged();
0171     void kernelFilterChanged();
0172 
0173 private:
0174     std::unique_ptr<FilterCriteriaModelPrivate> d;
0175 };
0176 
0177 #endif