|
| 1 | +/* |
| 2 | + * Copyright (C) 2025 Patchmanager for SailfishOS contributors: |
| 3 | + * - olf "Olf0" <https://github.com/Olf0> |
| 4 | + * - Peter G. "nephros" <[email protected]> |
| 5 | + * - Vlad G. "b100dian" <https://github.com/b100dian> |
| 6 | + * |
| 7 | + * You may use this file under the terms of the BSD license as follows: |
| 8 | + * |
| 9 | + * "Redistribution and use in source and binary forms, with or without |
| 10 | + * modification, are permitted provided that the following conditions are |
| 11 | + * met: |
| 12 | + * * Redistributions of source code must retain the above copyright |
| 13 | + * notice, this list of conditions and the following disclaimer. |
| 14 | + * * Redistributions in binary form must reproduce the above copyright |
| 15 | + * notice, this list of conditions and the following disclaimer in |
| 16 | + * the documentation and/or other materials provided with the |
| 17 | + * distribution. |
| 18 | + * * The names of its contributors may not be used to endorse or promote |
| 19 | + * products derived from this software without specific prior written |
| 20 | + * permission. |
| 21 | + * |
| 22 | + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 23 | + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 24 | + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 25 | + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 26 | + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 27 | + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 28 | + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 29 | + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 30 | + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 31 | + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 32 | + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." |
| 33 | + */ |
| 34 | + |
| 35 | +#ifndef PATCHMANAGERFILTER_H |
| 36 | +#define PATCHMANAGERFILTER_H |
| 37 | + |
| 38 | +#include <QtCore/QObject> |
| 39 | +#include <QCache> |
| 40 | + |
| 41 | +class PatchManagerFilter : public QObject, public QCache<QString, QObject> |
| 42 | +{ |
| 43 | + Q_OBJECT |
| 44 | + Q_PROPERTY(bool active READ active WRITE setActive NOTIFY activeChanged) |
| 45 | + Q_PROPERTY(unsigned int hits READ hits) |
| 46 | + Q_PROPERTY(unsigned int misses READ misses) |
| 47 | +public: |
| 48 | + PatchManagerFilter(QObject *parent = nullptr, int maxCost = 100); |
| 49 | + //~PatchManagerFilter(); |
| 50 | + |
| 51 | + void setup(); |
| 52 | + // override QCache::contains() |
| 53 | + bool contains(const QString &key) const |
| 54 | + { |
| 55 | + if (!m_active) { |
| 56 | + return false; |
| 57 | + } else { |
| 58 | + return (object(key) == 0); |
| 59 | + }; |
| 60 | + }; |
| 61 | + |
| 62 | + void setActive(bool active) { m_active = active; emit activeChanged(active); }; |
| 63 | + bool active() const { return m_active; }; |
| 64 | + |
| 65 | + void hit() { m_hits++; }; |
| 66 | + void miss() { m_misses++; }; |
| 67 | + unsigned int hits() const { return m_hits; }; |
| 68 | + unsigned int misses() const { return m_misses; }; |
| 69 | + |
| 70 | + //QList<QPair<QString, QVariant>> stats() const; |
| 71 | + QString stats() const; |
| 72 | + |
| 73 | + static const QStringList etcList; |
| 74 | + static const QStringList libList; |
| 75 | + |
| 76 | +signals: |
| 77 | + void activeChanged(bool); |
| 78 | + |
| 79 | +private: |
| 80 | + bool m_active; |
| 81 | + unsigned int m_hits = 0; |
| 82 | + unsigned int m_misses = 0; |
| 83 | +}; |
| 84 | + |
| 85 | +#endif // PATCHMANAGERFILTER_H |
0 commit comments