File: UpdateModel.h

package info (click to toggle)
plasma-discover 6.5.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 14,288 kB
  • sloc: cpp: 30,576; xml: 2,710; python: 311; sh: 5; makefile: 5
file content (90 lines) | stat: -rw-r--r-- 2,892 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/*
 *   SPDX-FileCopyrightText: 2011 Jonathan Thomas <echidnaman@kubuntu.org>
 *
 *   SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
 */

#pragma once

#include "discovercommon_export.h"
#include "resources/AbstractBackendUpdater.h"
#include <QAbstractListModel>

class QTimer;
class ResourcesUpdatesModel;
class AbstractResource;
class UpdateItem;

class DISCOVERCOMMON_EXPORT UpdateModel : public QAbstractListModel
{
    Q_OBJECT
    Q_PROPERTY(ResourcesUpdatesModel *backend READ backend WRITE setBackend)
    Q_PROPERTY(bool hasUpdates READ hasUpdates NOTIFY hasUpdatesChanged)
    Q_PROPERTY(int toUpdateCount READ toUpdateCount NOTIFY toUpdateChanged)
    Q_PROPERTY(int totalUpdatesCount READ totalUpdatesCount NOTIFY hasUpdatesChanged)
    Q_PROPERTY(QString updateSize READ updateSize NOTIFY updateSizeChanged)
public:
    enum Roles {
        SizeRole = Qt::UserRole + 1,
        ResourceRole,
        ResourceProgressRole,
        ResourceStateRole,
        ResourceStateIsDoneRole,
        SectionResourceProgressRole,
        ChangelogRole,
        SectionRole,
        ExtendedRole,
    };
    Q_ENUM(Roles)

    explicit UpdateModel(QObject *parent = nullptr);
    ~UpdateModel() override;

    QVariant data(const QModelIndex &index, int role) const override;
    Qt::ItemFlags flags(const QModelIndex &index) const override;
    int rowCount(const QModelIndex &parent = QModelIndex()) const override;

    bool setData(const QModelIndex &index, const QVariant &value, int role) override;
    void setResources(const QList<AbstractResource *> &res);
    UpdateItem *itemFromIndex(const QModelIndex &index) const;

    void checkResources(const QList<AbstractResource *> &resource, bool checked);
    QHash<int, QByteArray> roleNames() const override;

    bool hasUpdates() const;

    /// all upgradeable packages
    int totalUpdatesCount() const;

    /// packages marked to upgrade
    int toUpdateCount() const;

    Q_SCRIPTABLE void fetchUpdateDetails(int row);

    QString updateSize() const;

    ResourcesUpdatesModel *backend() const;
    void setBackend(ResourcesUpdatesModel *);

public Q_SLOTS:
    void checkAll();
    void uncheckAll();

Q_SIGNALS:
    void hasUpdatesChanged(bool hasUpdates);
    void toUpdateChanged();
    void updateSizeChanged();

private:
    void resourceDataChanged(AbstractResource *res, const QVector<QByteArray> &properties);
    void integrateChangelog(const QString &changelog);
    QModelIndex indexFromItem(UpdateItem *item) const;
    UpdateItem *itemFromResource(AbstractResource *res);
    void resourceHasProgressed(AbstractResource *res, qreal progress, AbstractBackendUpdater::State state);
    void activityChanged();

    QTimer *const m_updateSizeTimer;
    QVector<UpdateItem *> m_updateItems;
    ResourcesUpdatesModel *m_updates;
    QList<AbstractResource *> m_resources;
};