File indexing completed on 2024-04-14 15:49:48

0001 // SPDX-License-Identifier: GPL-3.0-or-later
0002 /*
0003   Copyright 2017 - 2023 Martin Koller, kollix@aon.at
0004 
0005   This file is part of liquidshell.
0006 
0007   liquidshell is free software: you can redistribute it and/or modify
0008   it under the terms of the GNU General Public License as published by
0009   the Free Software Foundation, either version 3 of the License, or
0010   (at your option) any later version.
0011 
0012   liquidshell is distributed in the hope that it will be useful,
0013   but WITHOUT ANY WARRANTY; without even the implied warranty of
0014   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0015   GNU General Public License for more details.
0016 
0017   You should have received a copy of the GNU General Public License
0018   along with liquidshell.  If not, see <http://www.gnu.org/licenses/>.
0019 */
0020 
0021 #ifndef _PkUpdateList_H_
0022 #define _PkUpdateList_H_
0023 
0024 #include <PkUpdates.hxx>
0025 #include <QScrollArea>
0026 #include <QQueue>
0027 #include <QPointer>
0028 #include <QSet>
0029 #include <QMultiHash>
0030 class QCheckBox;
0031 class QProgressBar;
0032 class QVBoxLayout;
0033 class QToolButton;
0034 class QPushButton;
0035 class QLabel;
0036 class QLineEdit;
0037 class QMenu;
0038 
0039 class PkUpdateList : public QWidget
0040 {
0041   Q_OBJECT
0042 
0043   public:
0044     PkUpdateList(QWidget *parent);
0045 
0046     void setPackages(const PkUpdates::PackageList &packages);
0047     void setRefreshProgress(int progress);
0048 
0049     bool isInstallInProgress() const { return !installQ.isEmpty(); }
0050 
0051     QSize sizeHint() const override;
0052 
0053   protected:
0054     void hideEvent(QHideEvent *event) override;
0055 
0056   Q_SIGNALS:
0057     void refreshRequested();
0058     void packageInstalled(QString id);
0059     void packageCountToInstall(int num);
0060 
0061   private Q_SLOTS:
0062     void checkAll(bool on);
0063     void install();
0064     void installOne();
0065     void countChecked();
0066     void filterChanged(const QString &text);
0067 
0068     void askEULA(const QString &eulaID, const QString &packageID,
0069                  const QString &vendor, const QString &licenseAgreement);
0070 
0071   private:  // methods
0072     void enqueue(const QString &packageID);
0073 
0074   private:  // members
0075     QVBoxLayout *vbox;
0076     QScrollArea *scrollArea;
0077     QVBoxLayout *itemsLayout;
0078     QLineEdit *filterEdit;
0079     QProgressBar *progressBar;
0080     QToolButton *installButton;
0081     QMenu *installMenu;
0082     QToolButton *refreshButton;
0083     QCheckBox *checkAllBox;
0084     QSize savedSize;
0085 
0086     enum class AfterInstall { Nothing, Sleep, Shutdown } afterInstall = AfterInstall::Nothing;
0087 
0088     QQueue<QPointer<class PkUpdateListItem>> installQ;
0089     QPointer<PackageKit::Transaction> transaction;
0090     bool packageNoLongerAvailable;
0091 
0092     struct EulaPackage
0093     {
0094       EulaPackage(const QString &e, const QString &p) : eulaID(e), packageID(p) { }
0095       QString eulaID;
0096       QString packageID;
0097     };
0098 
0099     QMultiHash<QString, EulaPackage> eulaDialogs;  // key = license text hash
0100     QSet<QByteArray> acceptedEula;
0101 
0102     PackageKit::Transaction::Restart restart;
0103 };
0104 
0105 //--------------------------------------------------------------------------------
0106 
0107 class PkUpdateListItem : public QWidget
0108 {
0109   Q_OBJECT
0110 
0111   public:
0112     PkUpdateListItem(QWidget *parent, PackageKit::Transaction::Info info, const PkUpdates::PackageData &data);
0113 
0114     void showProgress(bool yes);
0115 
0116     PkUpdates::PackageData package;
0117     QToolButton *label;
0118     QCheckBox *checkBox;
0119     QProgressBar *progress;
0120     QLabel *detailsLabel;
0121     QLabel *errorLabel;
0122     QLabel *packageLabel;
0123 
0124   Q_SIGNALS:
0125     void toggled();
0126 
0127   private Q_SLOTS:
0128     void getUpdateDetails();
0129 
0130     void updateDetail(const QString &packageID,
0131                       const QStringList &updates,
0132                       const QStringList &obsoletes,
0133                       const QStringList &vendorUrls,
0134                       const QStringList &bugzillaUrls,
0135                       const QStringList &cveUrls,
0136                       PackageKit::Transaction::Restart restart,
0137                       const QString &updateText,
0138                       const QString &changelog,
0139                       PackageKit::Transaction::UpdateState state,
0140                       const QDateTime &issued,
0141                       const QDateTime &updated);
0142 };
0143 
0144 #endif