File indexing completed on 2024-04-28 16:54:34

0001 /*
0002     SPDX-FileCopyrightText: 2019 Kai Uwe Broulik <kde@privat.broulik.de>
0003 
0004     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0005 */
0006 
0007 #pragma once
0008 
0009 #include <QDBusContext>
0010 #include <QDBusObjectPath>
0011 #include <QObject>
0012 #include <QSet>
0013 #include <QVector>
0014 
0015 #include "notifications.h"
0016 
0017 class QDBusServiceWatcher;
0018 class QTimer;
0019 
0020 namespace NotificationManager
0021 {
0022 class Job;
0023 
0024 class Q_DECL_HIDDEN JobsModelPrivate : public QObject, protected QDBusContext
0025 {
0026     Q_OBJECT
0027 
0028 public:
0029     JobsModelPrivate(QObject *parent);
0030     ~JobsModelPrivate() override;
0031 
0032     // DBus
0033     // kuiserver
0034     void registerService(const QString &service, const QString &objectPath);
0035     void emitJobUrlsChanged();
0036     bool requiresJobTracker() const;
0037     QStringList registeredJobContacts() const;
0038     // V1
0039     QDBusObjectPath requestView(const QString &appName, const QString &appIconName, int capabilities);
0040     // V2
0041     QDBusObjectPath requestView(const QString &desktopEntry, int capabilities, const QVariantMap &hints);
0042 
0043 Q_SIGNALS:
0044     void jobViewAboutToBeAdded(int row, Job *job);
0045     void jobViewAdded(int row, Job *job);
0046 
0047     void jobViewAboutToBeRemoved(int row); //, Job *job);
0048     void jobViewRemoved(int row);
0049 
0050     void jobViewChanged(int row, Job *job, const QVector<int> &roles);
0051 
0052     void serviceOwnershipLost();
0053 
0054     // DBus
0055     // kuiserver
0056     void jobUrlsChanged(const QStringList &urls);
0057 
0058 public: // stuff used by public class
0059     bool init();
0060 
0061     void remove(Job *job);
0062     void removeAt(int row);
0063 
0064     bool m_valid = false;
0065     QVector<Job *> m_jobViews;
0066 
0067 private:
0068     void unwatchJob(Job *job);
0069     void onServiceUnregistered(const QString &serviceName);
0070 
0071     void updateApplicationPercentage(const QString &desktopEntry);
0072 
0073     QStringList jobUrls() const;
0074     void scheduleUpdate(Job *job, int role);
0075 
0076     QDBusServiceWatcher *m_serviceWatcher = nullptr;
0077     // Job -> serviceName
0078     QHash<Job *, QString> m_jobServices;
0079     int m_highestJobId = 1;
0080 
0081     QTimer *m_compressUpdatesTimer = nullptr;
0082     QHash<Job *, QVector<int>> m_pendingDirtyRoles;
0083 
0084     QVector<Job *> m_pendingJobViews;
0085 };
0086 
0087 } // namespace NotificationManager