File indexing completed on 2024-04-21 15:08:50

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 <QDBusObjectPath>
0024 #include <QDBusPendingCallWatcher>
0025 #include <QStandardItemModel>
0026 
0027 #include "dbus-types.h"
0028 
0029 class CdInterface;
0030 class ProfileModel : 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     } ProfileRoles;
0044     explicit ProfileModel(CdInterface *cdInterface, QObject *parent = nullptr);
0045 
0046     Qt::ItemFlags flags(const QModelIndex &index) const override;
0047     QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
0048 
0049     // Returns a char to help the sort model
0050     static QChar getSortChar(const QString &kind);
0051     static QString getProfileDataSource(const CdStringMap &metadata);
0052     QHash<int, QByteArray> roleNames() const override;
0053 
0054 public Q_SLOTS:
0055     void serviceOwnerChanged(const QString &serviceName, const QString &oldOwner, const QString &newOwner);
0056 
0057 Q_SIGNALS:
0058     void changed(); // not used actually
0059 
0060 private Q_SLOTS:
0061     void gotProfiles(QDBusPendingCallWatcher *call);
0062     void profileChanged(const QDBusObjectPath &objectPath);
0063     void profileAdded(const QDBusObjectPath &objectPath, bool emitChanged = true);
0064     void profileAddedEmit(const QDBusObjectPath &objectPath);
0065     void profileRemoved(const QDBusObjectPath &objectPath);
0066 
0067 private:
0068     int findItem(const QDBusObjectPath &objectPath);
0069 };