File indexing completed on 2024-04-14 15:48:54
0001 /*************************************************************************** 0002 * Copyright (C) 2008-2011 by Daniel Nicoletti * 0003 * dantti12@gmail.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 #ifndef PACKAGE_MODEL_H 0022 #define PACKAGE_MODEL_H 0023 0024 #include <QAbstractItemModel> 0025 #include <QAbstractItemView> 0026 0027 #include <Transaction> 0028 #include <Details> 0029 0030 class Q_DECL_EXPORT PackageModel : public QAbstractItemModel 0031 { 0032 Q_OBJECT 0033 Q_PROPERTY(bool checkable READ checkable WRITE setCheckable NOTIFY changed) 0034 Q_PROPERTY(QString selectionStateText READ selectionStateText NOTIFY changed) 0035 public: 0036 enum { 0037 NameCol = 0, 0038 VersionCol, 0039 CurrentVersionCol, 0040 ArchCol, 0041 OriginCol, 0042 SizeCol, 0043 ActionCol 0044 }; 0045 enum { 0046 SortRole = Qt::UserRole, 0047 NameRole, 0048 SummaryRole, 0049 VersionRole, 0050 ArchRole, 0051 IconRole, 0052 IdRole, 0053 CheckStateRole, 0054 InfoRole, 0055 ApplicationId, 0056 IsPackageRole, 0057 PackageName, 0058 InfoIconRole 0059 }; 0060 typedef struct { 0061 QString displayName; 0062 QString pkgName; 0063 QString version; 0064 QString arch; 0065 QString repo; 0066 QString packageID; 0067 QString summary; 0068 PackageKit::Transaction::Info info; 0069 QString icon; 0070 QString appId; 0071 QString currentVersion; 0072 bool isPackage = true; 0073 double size = 0; 0074 } InternalPackage; 0075 0076 explicit PackageModel(QObject *parent = nullptr); 0077 0078 Q_INVOKABLE int rowCount(const QModelIndex &parent = QModelIndex()) const override; 0079 int columnCount(const QModelIndex &parent = QModelIndex()) const override; 0080 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; 0081 bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override; 0082 Qt::ItemFlags flags(const QModelIndex &index) const override; 0083 QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override; 0084 0085 Q_INVOKABLE bool allSelected() const; 0086 Q_INVOKABLE QStringList selectedPackagesToInstall() const; 0087 Q_INVOKABLE QStringList selectedPackagesToRemove() const; 0088 Q_INVOKABLE QStringList packagesWithInfo(PackageKit::Transaction::Info info) const; 0089 Q_INVOKABLE QStringList packageIDs() const; 0090 unsigned long downloadSize() const; 0091 Q_INVOKABLE void clear(); 0092 /** 0093 * This removes all selected packages that are not in the model 0094 */ 0095 Q_INVOKABLE void clearSelectedNotPresent(); 0096 0097 bool checkable() const; 0098 void setCheckable(bool checkable); 0099 0100 QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override; 0101 QModelIndex parent(const QModelIndex &index) const override; 0102 0103 QHash<int,QByteArray> roleNames() const override; 0104 0105 public Q_SLOTS: 0106 void addSelectedPackagesFromModel(PackageModel *model); 0107 void addNotSelectedPackage(PackageKit::Transaction::Info info, const QString &packageID, const QString &summary); 0108 void addPackage(PackageKit::Transaction::Info info, const QString &packageID, const QString &summary, bool selected = false); 0109 void addSelectedPackage(PackageKit::Transaction::Info info, const QString &packageID, const QString &summary); 0110 void removePackage(const QString &packageID); 0111 0112 void checkAll(); 0113 void setAllChecked(bool checked); 0114 void checkPackage(const PackageModel::InternalPackage &package, 0115 bool emitDataChanged = true); 0116 void uncheckAll(); 0117 void uncheckPackageDefault(const QString &packageID); 0118 void uncheckPackage(const QString &packageID, 0119 bool forceEmitUnchecked = false, 0120 bool emitDataChanged = true); 0121 void uncheckPackageLogic(const QString &packageID, 0122 bool forceEmitUnchecked = false, 0123 bool emitDataChanged = true); 0124 bool hasChanges() const; 0125 int countInfo(PackageKit::Transaction::Info info) const; 0126 0127 void uncheckInstalledPackages(); 0128 void uncheckAvailablePackages(); 0129 0130 void finished(); 0131 0132 void fetchSizes(); 0133 void fetchSizesFinished(); 0134 void updateSize(const PackageKit::Details &details); 0135 0136 void fetchCurrentVersions(); 0137 void fetchCurrentVersionsFinished(); 0138 void updateCurrentVersion(PackageKit::Transaction::Info info, const QString &packageID, const QString &summary); 0139 0140 void getUpdates(bool fetchCurrentVersions, bool selected); 0141 void toggleSelection(const QString &packageID); 0142 QString selectionStateText() const; 0143 0144 Q_SIGNALS: 0145 void changed(bool value); 0146 void packageUnchecked(const QString &packageID); 0147 0148 private: 0149 QList<InternalPackage> internalSelectedPackages() const; 0150 bool containsChecked(const QString &pid) const; 0151 0152 bool m_finished = true; 0153 bool m_checkable; 0154 QPixmap m_installedEmblem; 0155 QVector<InternalPackage> m_packages; 0156 QHash<QString, InternalPackage> m_checkedPackages; 0157 PackageKit::Transaction *m_getUpdatesTransaction = nullptr; 0158 PackageKit::Transaction *m_fetchSizesTransaction; 0159 PackageKit::Transaction *m_fetchInstalledVersionsTransaction; 0160 QHash<int, QByteArray> m_roles; 0161 }; 0162 0163 #endif