File indexing completed on 2024-04-21 15:08:49
0001 /*************************************************************************** 0002 * Copyright (C) 2012-2016 by Daniel Nicoletti <dantti12@gmail.com> * 0003 * 2022 by Han Young <hanyoung@protonmail.com> * 0004 * * 0005 * This program is free software; you can redistribute it and/or modify * 0006 * it under the terms of the GNU General Public License as published by * 0007 * the Free Software Foundation; either version 2 of the License, or * 0008 * (at your option) any later version. * 0009 * * 0010 * This program is distributed in the hope that it will be useful, * 0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 0013 * GNU General Public License for more details. * 0014 * * 0015 * You should have received a copy of the GNU General Public License * 0016 * along with this program; see the file COPYING. If not, write to * 0017 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * 0018 * Boston, MA 02110-1301, USA. * 0019 ***************************************************************************/ 0020 0021 #pragma once 0022 0023 #include <QStandardItemModel> 0024 #include <QtDBus/QDBusObjectPath> 0025 #include <QtDBus/QDBusPendingCallWatcher> 0026 0027 typedef QList<QDBusObjectPath> ObjectPathList; 0028 0029 class CdInterface; 0030 class DeviceModel : public QStandardItemModel 0031 { 0032 Q_OBJECT 0033 public: 0034 typedef enum { 0035 ObjectPathRole = Qt::UserRole + 1, 0036 ParentObjectPathRole, 0037 IsDeviceRole, 0038 SortRole, 0039 FilenameRole, 0040 ColorspaceRole, 0041 ProfileKindRole, 0042 CanRemoveProfileRole, 0043 ItemTypeRole // device, profile 0044 } DeviceRoles; 0045 explicit DeviceModel(CdInterface *cdInterface, QObject *parent = nullptr); 0046 0047 Qt::ItemFlags flags(const QModelIndex &index) const override; 0048 QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override; 0049 bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override; 0050 QHash<int, QByteArray> roleNames() const override; 0051 0052 int findDeviceIndex(const QDBusObjectPath &device) const; 0053 0054 Q_INVOKABLE void removeProfile(const QDBusObjectPath &profilePath, const QDBusObjectPath &devicePath); 0055 public Q_SLOTS: 0056 void serviceOwnerChanged(const QString &serviceName, const QString &oldOwner, const QString &newOwner); 0057 0058 Q_SIGNALS: 0059 void changed(); 0060 0061 private Q_SLOTS: 0062 void gotDevices(QDBusPendingCallWatcher *call); 0063 void deviceChanged(const QDBusObjectPath &objectPath); 0064 void deviceAdded(const QDBusObjectPath &objectPath, bool emitChanged = true); 0065 void deviceAddedEmit(const QDBusObjectPath &objectPath); 0066 void deviceRemoved(const QDBusObjectPath &objectPath); 0067 0068 private: 0069 QStandardItem *createProfileItem(const QDBusObjectPath &objectPath, const QDBusObjectPath &parentObjectPath, bool checked); 0070 QStandardItem *findProfile(QStandardItem *parent, const QDBusObjectPath &objectPath); 0071 void removeProfilesNotInList(QStandardItem *parent, const ObjectPathList &profiles); 0072 int findItem(const QDBusObjectPath &objectPath); 0073 0074 CdInterface *const m_cdInterface; 0075 };