File indexing completed on 2024-05-12 05:04:11
0001 // SPDX-FileCopyrightText: 2023 Rishi Kumar <rsi.dev17@gmail.com> 0002 // SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0003 0004 #pragma once 0005 0006 #include "ipinfo.h" 0007 0008 #include <QtQml> 0009 0010 // todo: use std::chrono when c++20 is stable 0011 #define YEAR 31536000 0012 #define DAY 86400 0013 0014 class IpRulesToolModel : public QAbstractListModel 0015 { 0016 Q_OBJECT 0017 QML_ELEMENT 0018 0019 Q_PROPERTY(bool loading READ loading NOTIFY loadingChanged) 0020 0021 public: 0022 enum CustomRoles { 0023 IdRole, 0024 IpRole, 0025 SeverityRole, 0026 CommentRole, 0027 CreatedAtRole, 0028 ExpiredAtRole, 0029 }; 0030 0031 enum TimeInterval { 0032 ThreeYears = YEAR * 3, 0033 OneYear = YEAR, 0034 Sixmonths = YEAR / 2, 0035 Onemonth = YEAR / 12, 0036 Twoweeks = DAY * 14, 0037 Oneday = DAY, 0038 }; 0039 0040 Q_ENUM(TimeInterval) 0041 0042 explicit IpRulesToolModel(QObject *parent = nullptr); 0043 0044 bool loading() const; 0045 void setLoading(bool loading); 0046 0047 QVariant data(const QModelIndex &index, int role) const override; 0048 int rowCount(const QModelIndex &parent) const override; 0049 QHash<int, QByteArray> roleNames() const override; 0050 0051 void filltimeline(); 0052 0053 Q_INVOKABLE void newIpBlock(const QString &ip, int expiresIn, const QString &comment, const QString &severity); 0054 Q_INVOKABLE void deleteIpBlock(int row); 0055 Q_INVOKABLE void updateIpBlock(int row, const QString &ip, const QString &severity, const QString &comment, int expiresIn); 0056 0057 Q_SIGNALS: 0058 void loadingChanged(); 0059 0060 private: 0061 QList<IpInfo> m_ipinfo; 0062 bool m_loading = false; 0063 QUrl m_next; 0064 };