| 1 | /* |
| 2 | This file is part of KNewStuff2. |
| 3 | SPDX-FileCopyrightText: 2007 Josef Spillner <spillner@kde.org> |
| 4 | SPDX-FileCopyrightText: 2009 Frederik Gladhorn <gladhorn@kde.org> |
| 5 | |
| 6 | SPDX-License-Identifier: LGPL-2.1-or-later |
| 7 | */ |
| 8 | |
| 9 | #ifndef KNEWSTUFF3_INSTALLATION_P_H |
| 10 | #define KNEWSTUFF3_INSTALLATION_P_H |
| 11 | |
| 12 | #include <QObject> |
| 13 | #include <QString> |
| 14 | |
| 15 | #include <KConfigGroup> |
| 16 | |
| 17 | #include "entry.h" |
| 18 | |
| 19 | class QProcess; |
| 20 | class KArchiveDirectory; |
| 21 | class KJob; |
| 22 | |
| 23 | namespace KNSCore |
| 24 | { |
| 25 | /** |
| 26 | * @short KNewStuff entry installation. |
| 27 | * |
| 28 | * The installation class stores all information related to an entry's |
| 29 | * installation. |
| 30 | * |
| 31 | * @author Josef Spillner (spillner@kde.org) |
| 32 | * |
| 33 | * @internal |
| 34 | */ |
| 35 | class KNEWSTUFFCORE_EXPORT Installation : public QObject |
| 36 | { |
| 37 | Q_OBJECT |
| 38 | public: |
| 39 | /** |
| 40 | * Constructor. |
| 41 | */ |
| 42 | explicit Installation(QObject *parent = nullptr); |
| 43 | enum UncompressionOptions { |
| 44 | NeverUncompress, ///@< Never attempt to decompress a file, whatever format it is. Matches "never" knsrc setting |
| 45 | AlwaysUncompress, ///@< Assume all downloaded files are archives, and attempt to decompress them. Will cause failure if decompression fails. Matches |
| 46 | ///"always" knsrc setting |
| 47 | UncompressIfArchive, ///@< If the file is an archive, decompress it, otherwise just pass it on. Matches "archive" knsrc setting |
| 48 | UncompressIntoSubdirIfArchive, ///@< If the file is an archive, decompress it in a subdirectory if it contains multiple files, otherwise just pass it |
| 49 | /// on. Matches "subdir-archive" knsrc setting |
| 50 | 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 |
| 51 | /// file. Matches "subdir" knsrc setting |
| 52 | UseKPackageUncompression, ///@< Use the internal KPackage support for installing and uninstalling the package. Matches "kpackage" knsrc setting |
| 53 | }; |
| 54 | Q_ENUM(UncompressionOptions) |
| 55 | |
| 56 | bool readConfig(const KConfigGroup &group, QString &errorMessage); |
| 57 | |
| 58 | QString targetInstallationPath() const; |
| 59 | |
| 60 | /** |
| 61 | * Returns the uncompression setting, in a computer-readable format |
| 62 | * |
| 63 | * @return The value of this setting |
| 64 | */ |
| 65 | UncompressionOptions uncompressionSetting() const; |
| 66 | |
| 67 | public Q_SLOTS: |
| 68 | /** |
| 69 | * Downloads a payload file. The payload file matching most closely |
| 70 | * the current user language preferences will be downloaded. |
| 71 | * The file will not be installed set, for this \ref install must |
| 72 | * be called. |
| 73 | * |
| 74 | * @param entry Entry to download payload file for |
| 75 | * |
| 76 | * @see signalPayloadLoaded |
| 77 | * @see signalPayloadFailed |
| 78 | */ |
| 79 | void downloadPayload(const KNSCore::Entry &entry); |
| 80 | |
| 81 | /** |
| 82 | * Installs an entry's payload file. This includes verification, if |
| 83 | * necessary, as well as decompression and other steps according to the |
| 84 | * application's *.knsrc file. |
| 85 | * Note that this method is asynchronous and thus the return value will |
| 86 | * only report the successful start of the installation. |
| 87 | * Note also that while entry is const at this point, it will change later |
| 88 | * during the actual installation (the installedFiles list will change, as |
| 89 | * will its status) |
| 90 | * |
| 91 | * @param entry Entry to be installed |
| 92 | * |
| 93 | * @see signalInstallationFinished |
| 94 | * @see signalInstallationFailed |
| 95 | */ |
| 96 | void install(const KNSCore::Entry &entry); |
| 97 | |
| 98 | /** |
| 99 | * Uninstalls an entry. It reverses the steps which were performed |
| 100 | * during the installation. |
| 101 | * |
| 102 | * The entry emitted by signalEntryChanged will be updated with any new information, in particular the following: |
| 103 | * <ul> |
| 104 | * <li>Status will be set to Deleted, unless the uninstall |
| 105 | * script exists with an error and the user chooses to cancel the uninstallation |
| 106 | * <li>uninstalledFiles will list files which were removed during uninstallation |
| 107 | * <li>installedFiles will become empty |
| 108 | * </ul> |
| 109 | * |
| 110 | * @param entry The entry to deinstall |
| 111 | * |
| 112 | */ |
| 113 | void uninstall(KNSCore::Entry entry); |
| 114 | |
| 115 | void slotPayloadResult(KJob *job); |
| 116 | |
| 117 | Q_SIGNALS: |
| 118 | void signalEntryChanged(const KNSCore::Entry &entry); |
| 119 | void signalInstallationFinished(const KNSCore::Entry &entry); |
| 120 | void signalInstallationFailed(const QString &message, const KNSCore::Entry &entry); |
| 121 | /** |
| 122 | * An informational signal fired when a serious error occurs during the installation. |
| 123 | * @param message The description of the error (a message intended to be human readable) |
| 124 | * @since 5.69 |
| 125 | */ |
| 126 | void signalInstallationError(const QString &message, const KNSCore::Entry &entry); |
| 127 | |
| 128 | void signalPayloadLoaded(QUrl payload); // FIXME: return Entry |
| 129 | |
| 130 | private: |
| 131 | void install(KNSCore::Entry entry, const QString &downloadedFile); |
| 132 | |
| 133 | QStringList installDownloadedFileAndUncompress(const KNSCore::Entry &entry, const QString &payloadfile, const QString installdir); |
| 134 | QProcess *runPostInstallationCommand(const QString &installPath, const KNSCore::Entry &entry); |
| 135 | |
| 136 | static QStringList archiveEntries(const QString &path, const KArchiveDirectory *dir); |
| 137 | |
| 138 | // applications can set this if they want the installed files/directories to be piped into a shell command |
| 139 | QString postInstallationCommand; |
| 140 | // a custom command to run for the uninstall |
| 141 | QString uninstallCommand; |
| 142 | // compression policy |
| 143 | |
| 144 | // only one of the five below can be set, that will be the target install path/file name |
| 145 | // FIXME: check this when reading the config and make one path out of it if possible? |
| 146 | QString standardResourceDirectory; |
| 147 | QString targetDirectory; |
| 148 | QString xdgTargetDirectory; |
| 149 | QString installPath; |
| 150 | QString absoluteInstallPath; |
| 151 | |
| 152 | QMap<KJob *, Entry> entry_jobs; |
| 153 | |
| 154 | QString kpackageStructure; |
| 155 | UncompressionOptions uncompressSetting = UncompressionOptions::NeverUncompress; |
| 156 | |
| 157 | Q_DISABLE_COPY(Installation) |
| 158 | }; |
| 159 | |
| 160 | } |
| 161 | |
| 162 | #endif |
| 163 | |