File indexing completed on 2024-04-28 15:28:57

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 "entryinternal.h"
0018 
0019 #include "knewstuffcore_export.h"
0020 
0021 class QProcess;
0022 class KArchiveDirectory;
0023 class KJob;
0024 
0025 namespace KNSCore
0026 {
0027 /**
0028  * @short KNewStuff entry installation.
0029  *
0030  * The installation class stores all information related to an entry's
0031  * installation.
0032  *
0033  * @author Josef Spillner (spillner@kde.org)
0034  *
0035  * @internal
0036  */
0037 class KNEWSTUFFCORE_EXPORT Installation : public QObject
0038 {
0039     Q_OBJECT
0040 public:
0041     /**
0042      * Constructor.
0043      */
0044     explicit Installation(QObject *parent = nullptr);
0045 #if KNEWSTUFFCORE_BUILD_DEPRECATED_SINCE(5, 79)
0046     enum Policy {
0047         CheckNever,
0048         CheckIfPossible,
0049         CheckAlways,
0050     };
0051 
0052     enum Scope {
0053         ScopeUser,
0054         ScopeSystem,
0055     };
0056 #endif
0057 
0058     enum UncompressionOptions {
0059         NeverUncompress, ///@< Never attempt to decompress a file, whatever format it is. Matches "never" knsrc setting
0060         AlwaysUncompress, ///@< Assume all downloaded files are archives, and attempt to decompress them. Will cause failure if decompression fails. Matches
0061                           ///"always" knsrc setting
0062         UncompressIfArchive, ///@< If the file is an archive, decompress it, otherwise just pass it on. Matches "archive" knsrc setting
0063         UncompressIntoSubdirIfArchive, ///@< If the file is an archive, decompress it in a subdirectory if it contains multiple files, otherwise just pass it
0064                                        /// on. Matches "subdir-archive" knsrc setting
0065         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
0066                               /// file. Matches "subdir" knsrc setting
0067         UseKPackageUncompression, ///@< Use the internal KPackage support for installing and uninstalling the package. Matches "kpackage" knsrc setting
0068     };
0069     Q_ENUM(UncompressionOptions)
0070 
0071     bool readConfig(const KConfigGroup &group);
0072 
0073 #if KNEWSTUFFCORE_ENABLE_DEPRECATED_SINCE(5, 71)
0074     KNEWSTUFFCORE_DEPRECATED_VERSION(5, 71, "No longer use, feature obsolete")
0075     bool isRemote() const;
0076 #endif
0077 
0078 public Q_SLOTS:
0079     /**
0080      * Downloads a payload file. The payload file matching most closely
0081      * the current user language preferences will be downloaded.
0082      * The file will not be installed set, for this \ref install must
0083      * be called.
0084      *
0085      * @param entry Entry to download payload file for
0086      *
0087      * @see signalPayloadLoaded
0088      * @see signalPayloadFailed
0089      */
0090     void downloadPayload(const KNSCore::EntryInternal &entry);
0091 
0092     /**
0093      * Installs an entry's payload file. This includes verification, if
0094      * necessary, as well as decompression and other steps according to the
0095      * application's *.knsrc file.
0096      * Note that this method is asynchronous and thus the return value will
0097      * only report the successful start of the installation.
0098      * Note also that while entry is const at this point, it will change later
0099      * during the actual installation (the installedFiles list will change, as
0100      * will its status)
0101      *
0102      * @param entry Entry to be installed
0103      *
0104      * @see signalInstallationFinished
0105      * @see signalInstallationFailed
0106      */
0107     void install(const KNSCore::EntryInternal &entry);
0108 
0109     /**
0110      * Uninstalls an entry. It reverses the steps which were performed
0111      * during the installation.
0112      *
0113      * The entry emitted by signalEntryChanged will be updated with any new information, in particular the following:
0114      * <ul>
0115      * <li>Status will be set to Deleted, unless the uninstall
0116      * script exists with an error and the user chooses to cancel the uninstallation
0117      * <li>uninstalledFiles will list files which were removed during uninstallation
0118      * <li>installedFiles will become empty
0119      * </ul>
0120      *
0121      * @param entry The entry to deinstall
0122      *
0123      */
0124     void uninstall(KNSCore::EntryInternal entry);
0125 
0126     /**
0127      * Returns the uncompression setting, in a computer-readable format
0128      *
0129      * @return The value of this setting
0130      * @since 5.71
0131      */
0132     UncompressionOptions uncompressionSetting() const;
0133 
0134     // TODO KF6: remove, was used with deprecated Security class.
0135 #if KNEWSTUFFCORE_ENABLE_DEPRECATED_SINCE(5, 31)
0136     KNEWSTUFFCORE_DEPRECATED_VERSION(5, 31, "No longer use")
0137     void slotInstallationVerification(int result);
0138 #endif
0139 
0140     void slotPayloadResult(KJob *job);
0141 
0142     /**
0143      * @returns the installation path
0144      *
0145      * @since 5.31
0146      */
0147     QString targetInstallationPath() const;
0148 
0149 Q_SIGNALS:
0150     void signalEntryChanged(const KNSCore::EntryInternal &entry);
0151     void signalInstallationFinished();
0152     void signalInstallationFailed(const QString &message);
0153     /**
0154      * An informational signal fired when a serious error occurs during the installation.
0155      * @param message The description of the error (a message intended to be human readable)
0156      * @since 5.69
0157      */
0158     void signalInstallationError(const QString &message);
0159 
0160     void signalPayloadLoaded(QUrl payload); // FIXME: return Entry
0161 
0162     // TODO KF6: remove, was used with deprecated Security class.
0163 #if KNEWSTUFFCORE_ENABLE_DEPRECATED_SINCE(5, 31)
0164     KNEWSTUFFCORE_DEPRECATED_VERSION(5, 31, "No longer use")
0165     void signalInformation(const QString &) const;
0166     KNEWSTUFFCORE_DEPRECATED_VERSION(5, 31, "No longer use")
0167     void signalError(const QString &) const;
0168 #endif
0169 
0170 private:
0171     void install(KNSCore::EntryInternal entry, const QString &downloadedFile);
0172 
0173     QStringList installDownloadedFileAndUncompress(const KNSCore::EntryInternal &entry, const QString &payloadfile, const QString installdir);
0174     QProcess *runPostInstallationCommand(const QString &installPath);
0175 
0176     static QStringList archiveEntries(const QString &path, const KArchiveDirectory *dir);
0177 
0178     // applications can set this if they want the installed files/directories to be piped into a shell command
0179     QString postInstallationCommand;
0180     // a custom command to run for the uninstall
0181     QString uninstallCommand;
0182     // compression policy
0183     QString uncompression;
0184 
0185     // only one of the five below can be set, that will be the target install path/file name
0186     // FIXME: check this when reading the config and make one path out of it if possible?
0187     QString standardResourceDirectory;
0188     QString targetDirectory;
0189     QString xdgTargetDirectory;
0190     QString installPath;
0191     QString absoluteInstallPath;
0192 #if KNEWSTUFFCORE_BUILD_DEPRECATED_SINCE(5, 79)
0193     // policies whether verification needs to be done
0194     Policy checksumPolicy = CheckIfPossible;
0195     Policy signaturePolicy = CheckIfPossible;
0196     // scope: install into user or system dirs
0197     Scope scope = ScopeUser;
0198     // FIXME this throws together a file name from entry name and version - why would anyone want that?
0199     bool customName = false;
0200     bool acceptHtml = false;
0201 #endif
0202 
0203     QMap<KJob *, EntryInternal> entry_jobs;
0204 
0205     Q_DISABLE_COPY(Installation)
0206 };
0207 
0208 }
0209 
0210 #endif