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

0001 /***************************************************************************
0002  *   Copyright (C) 2009-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 SESSION_TASK_H
0022 #define SESSION_TASK_H
0023 
0024 #include <Transaction>
0025 #include <PkTransaction.h>
0026 
0027 #include <QDBusMessage>
0028 #include <QDialog>
0029 
0030 namespace Ui {
0031     class SessionTask;
0032 }
0033 
0034 class PackageModel;
0035 class ReviewChanges;
0036 class PkTransactionWidget;
0037 class SessionTask : public QDialog
0038 {
0039     Q_OBJECT
0040     Q_ENUMS(Errors)
0041 public:
0042     SessionTask(uint xid, const QString &interaction, const QDBusMessage &message, QWidget *parent = nullptr);
0043     ~SessionTask() override;
0044 
0045     typedef enum{
0046         Failed,
0047         InternalError,
0048         NoPackagesFound,
0049         Forbidden,
0050         Cancelled
0051     } DBusError;
0052 
0053     enum Interaction {
0054         ConfirmSearch   = 0x001,
0055         ConfirmDeps     = 0x002,
0056         ConfirmInstall  = 0x004,
0057         Progress        = 0x010,
0058         Finished        = 0x020,
0059         Warning         = 0x040,
0060         Unknown         = 0x100
0061     };
0062     Q_DECLARE_FLAGS(Interactions, Interaction)
0063 
0064     typedef struct {
0065         Transaction::Info info;
0066         QString packageID;
0067         QString summary;
0068     } IPackage;
0069 
0070     bool showConfirmSearch() const;
0071     bool showConfirmDeps() const;
0072     bool showConfirmInstall() const;
0073     bool showProgress() const;
0074     bool showFinished() const;
0075     bool showWarning() const;
0076 
0077     Interactions interactions() const;
0078     uint timeout() const;
0079 
0080     QWidget* mainWidget();
0081     uint parentWId() const;
0082 
0083     void slotContinueClicked();
0084     void slotCancelClicked();
0085 
0086 Q_SIGNALS:
0087     void continueClicked();
0088     void cancelClicked();
0089 
0090 public Q_SLOTS:
0091     void enableButtonOk(bool enable);
0092     void setMainWidget(QWidget *widget);
0093 
0094 protected:
0095     // Virtual methods to easy subclasses
0096     virtual void search();
0097     virtual void commit();
0098     virtual void notFound();
0099     virtual void searchFailed();
0100     virtual void searchSuccess();
0101     virtual void commitFailed();
0102     virtual void commitSuccess(QWidget *widget = nullptr);
0103 
0104     void showCloseButton();
0105     bool foundPackages() const;
0106     int  foundPackagesSize() const;
0107     PackageModel* model() const;
0108     void setTransaction(Transaction::Role role, PkTransaction *transaction = nullptr);
0109     void finishTaskOk();
0110     void sendErrorFinished(DBusError error, const QString &msg);
0111     bool sendMessageFinished(const QDBusMessage &message);
0112     QString parentTitle;
0113 
0114 protected Q_SLOTS:
0115     void setTitle(const QString &title);
0116     void setInfo(const QString &title, const QString &text, const QString &details = QString());
0117     void setError(const QString &title, const QString &text, const QString &details = QString());
0118     void setFinish(const QString &title, const QString &text, QWidget *widget = nullptr);
0119     virtual void addPackage(PackageKit::Transaction::Info info, const QString &packageID, const QString &summary);
0120     virtual void searchFinished(PkTransaction::ExitStatus status);
0121     virtual void commitFinished(PkTransaction::ExitStatus status);
0122 
0123 private Q_SLOTS:
0124     void updatePallete();
0125     void setDialog(QDialog *dialog);
0126 
0127 private:
0128     void removePackages();
0129     void parseInteraction(const QString &interaction);
0130     uint getPidSystem();
0131     uint getPidSession();
0132     QString getCmdLine(uint pid);
0133     bool pathIsTrusted(const QString &exec);
0134     void setExec(const QString &exec);
0135 
0136     uint m_xid;
0137     uint m_pid;
0138     QDBusMessage m_message;
0139     Interactions m_interactions;
0140     uint m_timeout;
0141     PackageModel *m_model;
0142     QStringList m_removePackages;
0143     ReviewChanges *m_reviewChanges = nullptr;
0144     PkTransactionWidget *m_pkTransaction = nullptr;
0145     Ui::SessionTask *ui;
0146 };
0147 
0148 Q_DECLARE_OPERATORS_FOR_FLAGS(SessionTask::Interactions)
0149 
0150 #endif