File indexing completed on 2024-04-21 16:29:32

0001 /***************************************************************************
0002  *   Copyright (C) 2009-2010 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_DETAILS_H
0022 #define PACKAGE_DETAILS_H
0023 
0024 #include <Transaction>
0025 #include <Details>
0026 
0027 #include <KPixmapSequenceOverlayPainter>
0028 #include <KJob>
0029 
0030 #include <QUrl>
0031 #include <QWidget>
0032 #include <QSortFilterProxyModel>
0033 #include <QPropertyAnimation>
0034 #include <QParallelAnimationGroup>
0035 #include <QActionGroup>
0036 
0037 namespace Ui {
0038     class PackageDetails;
0039 }
0040 
0041 class PackageModel;
0042 class PackageDetails : public QWidget
0043 {
0044     Q_OBJECT
0045 public:
0046     enum FadeWidget {
0047         FadeNone       = 0x0,
0048         FadeStacked    = 0x1,
0049         FadeScreenshot = 0x2
0050     };
0051     Q_DECLARE_FLAGS(FadeWidgets, FadeWidget)
0052     explicit PackageDetails(QWidget *parent = nullptr);
0053     ~PackageDetails() override;
0054 
0055     void init(PackageKit::Transaction::Roles roles);
0056 
0057     void setPackage(const QModelIndex &index);
0058     void hidePackageVersion(bool hide);
0059     void hidePackageArch(bool hide);
0060 
0061 public Q_SLOTS:
0062     void hide();
0063 
0064 Q_SIGNALS:
0065     void ensureVisible(const QModelIndex &index);
0066 
0067 private Q_SLOTS:
0068     void on_screenshotL_clicked();
0069     void actionActivated(QAction *action);
0070     void description(const PackageKit::Details &details);
0071     void files(const QString &packageID, const QStringList &files);
0072     void finished();
0073     void resultJob(KJob *);
0074 
0075     void display();
0076 
0077 private:
0078     void fadeOut(FadeWidgets widgets);
0079     void setupDescription();
0080     QVector<QPair<QString, QString> > locateApplication(const QString &_relPath, const QString &menuId) const;
0081     QUrl thumbnail(const QString &pkgName) const;
0082     QUrl screenshot(const QString &pkgName) const;
0083 
0084     Ui::PackageDetails *ui;
0085     QActionGroup *m_actionGroup;
0086     QModelIndex   m_index;
0087     QString m_packageID;
0088     PackageKit::Details m_details;
0089     QString m_detailsDescription;
0090 
0091     QAction *descriptionAction;
0092     QAction *dependsOnAction;
0093     QAction *requiredByAction;
0094     QAction *fileListAction;
0095 
0096     QString       m_appName;
0097 
0098     QParallelAnimationGroup       *m_expandPanel;
0099     KPixmapSequenceOverlayPainter *m_busySeq;
0100 
0101     QPropertyAnimation *m_fadeStacked;
0102     QPropertyAnimation *m_fadeScreenshot;
0103     bool m_display;
0104     bool m_hideVersion;
0105     bool m_hideArch;
0106 
0107     // We need a copy of prety much every thing
0108     // we have, so that we update only when we are
0109     // totaly transparent this way the user
0110     // does not see the ui flicker
0111     PackageKit::Transaction *m_transaction;
0112     bool         m_hasDetails;
0113     QString      m_currentText;
0114     QPixmap      m_currentIcon;
0115     QString      m_appId;
0116 
0117     // file list buffer
0118     bool         m_hasFileList;
0119     QStringList  m_currentFileList;
0120 
0121     // GetDepends buffer
0122     bool m_hasDepends;
0123     PackageModel *m_dependsModel;
0124     QSortFilterProxyModel *m_dependsProxy;
0125 
0126     // GetRequires buffer
0127     bool m_hasRequires;
0128     PackageModel *m_requiresModel;
0129     QSortFilterProxyModel *m_requiresProxy;
0130 
0131     // Screen shot buffer
0132     QUrl      m_currentScreenshot;
0133     QHash<QUrl, QString> m_screenshotPath;
0134 };
0135 
0136 Q_DECLARE_OPERATORS_FOR_FLAGS(PackageDetails::FadeWidgets)
0137 
0138 #endif