File indexing completed on 2024-04-28 03:56:26
0001 /* 0002 This file is part of KNewStuff2. 0003 SPDX-FileCopyrightText: 2007 Josef Spillner <spillner@kde.org> 0004 SPDX-FileCopyrightText: 2009 Frederik Gladhorn <gladhorn@kde.org> 0005 0006 SPDX-License-Identifier: LGPL-2.1-or-later 0007 */ 0008 0009 #ifndef KNEWSTUFF3_INSTALLATION_P_H 0010 #define KNEWSTUFF3_INSTALLATION_P_H 0011 0012 #include <QObject> 0013 #include <QString> 0014 0015 #include <KConfigGroup> 0016 0017 #include "entry.h" 0018 0019 class QProcess; 0020 class KArchiveDirectory; 0021 class KJob; 0022 0023 namespace KNSCore 0024 { 0025 /** 0026 * @short KNewStuff entry installation. 0027 * 0028 * The installation class stores all information related to an entry's 0029 * installation. 0030 * 0031 * @author Josef Spillner (spillner@kde.org) 0032 * 0033 * @internal 0034 */ 0035 class KNEWSTUFFCORE_EXPORT Installation : public QObject 0036 { 0037 Q_OBJECT 0038 public: 0039 /** 0040 * Constructor. 0041 */ 0042 explicit Installation(QObject *parent = nullptr); 0043 enum UncompressionOptions { 0044 NeverUncompress, ///@< Never attempt to decompress a file, whatever format it is. Matches "never" knsrc setting 0045 AlwaysUncompress, ///@< Assume all downloaded files are archives, and attempt to decompress them. Will cause failure if decompression fails. Matches 0046 ///"always" knsrc setting 0047 UncompressIfArchive, ///@< If the file is an archive, decompress it, otherwise just pass it on. Matches "archive" knsrc setting 0048 UncompressIntoSubdirIfArchive, ///@< If the file is an archive, decompress it in a subdirectory if it contains multiple files, otherwise just pass it 0049 /// on. Matches "subdir-archive" knsrc setting 0050 UncompressIntoSubdir, ///@< As Archive, except that if there is more than an item in the file, put contents in a subdirectory with the same name as the 0051 /// file. Matches "subdir" knsrc setting 0052 UseKPackageUncompression, ///@< Use the internal KPackage support for installing and uninstalling the package. Matches "kpackage" knsrc setting 0053 }; 0054 Q_ENUM(UncompressionOptions) 0055 0056 bool readConfig(const KConfigGroup &group, QString &errorMessage); 0057 0058 QString targetInstallationPath() const; 0059 0060 /** 0061 * Returns the uncompression setting, in a computer-readable format 0062 * 0063 * @return The value of this setting 0064 */ 0065 UncompressionOptions uncompressionSetting() const; 0066 0067 public Q_SLOTS: 0068 /** 0069 * Downloads a payload file. The payload file matching most closely 0070 * the current user language preferences will be downloaded. 0071 * The file will not be installed set, for this \ref install must 0072 * be called. 0073 * 0074 * @param entry Entry to download payload file for 0075 * 0076 * @see signalPayloadLoaded 0077 * @see signalPayloadFailed 0078 */ 0079 void downloadPayload(const KNSCore::Entry &entry); 0080 0081 /** 0082 * Installs an entry's payload file. This includes verification, if 0083 * necessary, as well as decompression and other steps according to the 0084 * application's *.knsrc file. 0085 * Note that this method is asynchronous and thus the return value will 0086 * only report the successful start of the installation. 0087 * Note also that while entry is const at this point, it will change later 0088 * during the actual installation (the installedFiles list will change, as 0089 * will its status) 0090 * 0091 * @param entry Entry to be installed 0092 * 0093 * @see signalInstallationFinished 0094 * @see signalInstallationFailed 0095 */ 0096 void install(const KNSCore::Entry &entry); 0097 0098 /** 0099 * Uninstalls an entry. It reverses the steps which were performed 0100 * during the installation. 0101 * 0102 * The entry emitted by signalEntryChanged will be updated with any new information, in particular the following: 0103 * <ul> 0104 * <li>Status will be set to Deleted, unless the uninstall 0105 * script exists with an error and the user chooses to cancel the uninstallation 0106 * <li>uninstalledFiles will list files which were removed during uninstallation 0107 * <li>installedFiles will become empty 0108 * </ul> 0109 * 0110 * @param entry The entry to deinstall 0111 * 0112 */ 0113 void uninstall(KNSCore::Entry entry); 0114 0115 void slotPayloadResult(KJob *job); 0116 0117 Q_SIGNALS: 0118 void signalEntryChanged(const KNSCore::Entry &entry); 0119 void signalInstallationFinished(const KNSCore::Entry &entry); 0120 void signalInstallationFailed(const QString &message, const KNSCore::Entry &entry); 0121 /** 0122 * An informational signal fired when a serious error occurs during the installation. 0123 * @param message The description of the error (a message intended to be human readable) 0124 * @since 5.69 0125 */ 0126 void signalInstallationError(const QString &message, const KNSCore::Entry &entry); 0127 0128 void signalPayloadLoaded(QUrl payload); // FIXME: return Entry 0129 0130 private: 0131 void install(KNSCore::Entry entry, const QString &downloadedFile); 0132 0133 QStringList installDownloadedFileAndUncompress(const KNSCore::Entry &entry, const QString &payloadfile, const QString installdir); 0134 QProcess *runPostInstallationCommand(const QString &installPath, const KNSCore::Entry &entry); 0135 0136 static QStringList archiveEntries(const QString &path, const KArchiveDirectory *dir); 0137 0138 // applications can set this if they want the installed files/directories to be piped into a shell command 0139 QString postInstallationCommand; 0140 // a custom command to run for the uninstall 0141 QString uninstallCommand; 0142 // compression policy 0143 0144 // only one of the five below can be set, that will be the target install path/file name 0145 // FIXME: check this when reading the config and make one path out of it if possible? 0146 QString standardResourceDirectory; 0147 QString targetDirectory; 0148 QString xdgTargetDirectory; 0149 QString installPath; 0150 QString absoluteInstallPath; 0151 0152 QMap<KJob *, Entry> entry_jobs; 0153 0154 QString kpackageStructure; 0155 UncompressionOptions uncompressSetting = UncompressionOptions::NeverUncompress; 0156 0157 Q_DISABLE_COPY(Installation) 0158 }; 0159 0160 } 0161 0162 #endif