File indexing completed on 2024-04-14 14:32:48
0001 /*************************************************************************** 0002 * Copyright (C) 2012 by Daniel Nicoletti * 0003 * dantti12@gmail.com * 0004 * 2022 by Han Young <hanyoung@protonmail.com * 0005 * * 0006 * This program is free software; you can redistribute it and/or modify * 0007 * it under the terms of the GNU General Public License as published by * 0008 * the Free Software Foundation; either version 2 of the License, or * 0009 * (at your option) any later version. * 0010 * * 0011 * This program is distributed in the hope that it will be useful, * 0012 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 0014 * GNU General Public License for more details. * 0015 * * 0016 * You should have received a copy of the GNU General Public License * 0017 * along with this program; see the file COPYING. If not, write to * 0018 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * 0019 * Boston, MA 02110-1301, USA. * 0020 ***************************************************************************/ 0021 0022 #pragma once 0023 0024 #include <KConfigGroup> 0025 #include <KQuickConfigModule> 0026 #include <QDBusObjectPath> 0027 0028 class DeviceModel; 0029 class ProfileModel; 0030 class CdInterface; 0031 class DeviceDescription; 0032 class ProfileDescription; 0033 class QSortFilterProxyModel; 0034 class AddProfileComboBoxItem; 0035 class KCMColord : public KQuickConfigModule 0036 { 0037 Q_OBJECT 0038 Q_PROPERTY(DeviceModel *deviceModel READ deviceModel CONSTANT) 0039 Q_PROPERTY(ProfileModel *profileModel READ profileModel CONSTANT) 0040 Q_PROPERTY(DeviceDescription *deviceDescription READ deviceDescription CONSTANT) 0041 Q_PROPERTY(ProfileDescription *profileDescription READ profileDescription CONSTANT) 0042 0043 public: 0044 explicit KCMColord(QObject *parent, const KPluginMetaData &data, const QVariantList &list = QVariantList()); 0045 DeviceModel *deviceModel() const; 0046 ProfileModel *profileModel() const; 0047 DeviceDescription *deviceDescription() const; 0048 ProfileDescription *profileDescription() const; 0049 0050 Q_INVOKABLE void makeProfileDefault(const QDBusObjectPath &profilePath, const QDBusObjectPath &devicePath); 0051 Q_INVOKABLE void assignProfileToDevice(const QDBusObjectPath &profile, const QDBusObjectPath &devicePath) const; 0052 Q_INVOKABLE bool canAddProfileForDevice(const QDBusObjectPath &device); 0053 0054 // DO NOT RETAIN OR USE ANY OBJECT IN THE FIRST CALL AFTER SECOND CALL!!! 0055 // This method destroy any objects allocated in the previous call after 0056 // returning for the second call. This behavior is to prevent memory leak 0057 Q_INVOKABLE QList<QObject *> getComboBoxItemsForDevice(const QDBusObjectPath &device); 0058 Q_INVOKABLE void importProfile(const QUrl &filepath); 0059 Q_INVOKABLE void removeProfile(const QString &filename); 0060 0061 private: 0062 CdInterface *const m_cdInterface; 0063 DeviceModel *const m_deviceModel; 0064 ProfileModel *const m_profileModel; 0065 DeviceDescription *const m_deviceDescription; 0066 ProfileDescription *const m_profileDescription; 0067 QSortFilterProxyModel *const m_filterModel; 0068 QList<QObject *> m_comboBoxItemsToBeDestroyed; 0069 }; 0070 0071 class AddProfileComboBoxItem : public QObject 0072 { 0073 Q_OBJECT 0074 Q_PROPERTY(QDBusObjectPath objectPath MEMBER m_objectPath NOTIFY dataChanged) 0075 Q_PROPERTY(QString profileName MEMBER m_profileName NOTIFY dataChanged) 0076 public: 0077 AddProfileComboBoxItem(QObject *parent, const QDBusObjectPath &path, const QString &name) 0078 : QObject(parent) 0079 , m_objectPath(path) 0080 , m_profileName(name) 0081 { 0082 } 0083 0084 Q_SIGNALS: 0085 void dataChanged(); 0086 0087 private: 0088 QDBusObjectPath m_objectPath; 0089 QString m_profileName; 0090 };