KNewStuff

installation.h
1 /*
2  This file is part of KNewStuff2.
3  SPDX-FileCopyrightText: 2007 Josef Spillner <[email protected]>
4  SPDX-FileCopyrightText: 2009 Frederik Gladhorn <[email protected]>
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 "entryinternal.h"
18 
19 #include "knewstuffcore_export.h"
20 
21 class QProcess;
22 class KArchiveDirectory;
23 class KJob;
24 
25 namespace KNSCore
26 {
27 /**
28  * @short KNewStuff entry installation.
29  *
30  * The installation class stores all information related to an entry's
31  * installation.
32  *
33  * @author Josef Spillner ([email protected])
34  *
35  * @internal
36  */
37 class KNEWSTUFFCORE_EXPORT Installation : public QObject
38 {
39  Q_OBJECT
40 public:
41  /**
42  * Constructor.
43  */
44  explicit Installation(QObject *parent = nullptr);
45 #if KNEWSTUFFCORE_BUILD_DEPRECATED_SINCE(5, 79)
46  enum Policy {
47  CheckNever,
48  CheckIfPossible,
49  CheckAlways,
50  };
51 
52  enum Scope {
53  ScopeUser,
54  ScopeSystem,
55  };
56 #endif
57 
59  NeverUncompress, ///@< Never attempt to decompress a file, whatever format it is. Matches "never" knsrc setting
60  AlwaysUncompress, ///@< Assume all downloaded files are archives, and attempt to decompress them. Will cause failure if decompression fails. Matches
61  ///"always" knsrc setting
62  UncompressIfArchive, ///@< If the file is an archive, decompress it, otherwise just pass it on. Matches "archive" knsrc setting
63  UncompressIntoSubdirIfArchive, ///@< If the file is an archive, decompress it in a subdirectory if it contains multiple files, otherwise just pass it
64  /// on. Matches "subdir-archive" knsrc setting
65  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
66  /// file. Matches "subdir" knsrc setting
67  UseKPackageUncompression, ///@< Use the internal KPackage support for installing and uninstalling the package. Matches "kpackage" knsrc setting
68  };
69  Q_ENUM(UncompressionOptions)
70 
71  bool readConfig(const KConfigGroup &group);
72 
73 #if KNEWSTUFFCORE_ENABLE_DEPRECATED_SINCE(5, 71)
74  KNEWSTUFFCORE_DEPRECATED_VERSION(5, 71, "No longer use, feature obsolete")
75  bool isRemote() const;
76 #endif
77 
78 public Q_SLOTS:
79  /**
80  * Downloads a payload file. The payload file matching most closely
81  * the current user language preferences will be downloaded.
82  * The file will not be installed set, for this \ref install must
83  * be called.
84  *
85  * @param entry Entry to download payload file for
86  *
87  * @see signalPayloadLoaded
88  * @see signalPayloadFailed
89  */
90  void downloadPayload(const KNSCore::EntryInternal &entry);
91 
92  /**
93  * Installs an entry's payload file. This includes verification, if
94  * necessary, as well as decompression and other steps according to the
95  * application's *.knsrc file.
96  * Note that this method is asynchronous and thus the return value will
97  * only report the successful start of the installation.
98  * Note also that while entry is const at this point, it will change later
99  * during the actual installation (the installedFiles list will change, as
100  * will its status)
101  *
102  * @param entry Entry to be installed
103  *
104  * @see signalInstallationFinished
105  * @see signalInstallationFailed
106  */
107  void install(const KNSCore::EntryInternal &entry);
108 
109  /**
110  * Uninstalls an entry. It reverses the steps which were performed
111  * during the installation.
112  *
113  * The entry emitted by signalEntryChanged will be updated with any new information, in particular the following:
114  * <ul>
115  * <li>Status will be set to Deleted, unless the uninstall
116  * script exists with an error and the user chooses to cancel the uninstallation
117  * <li>uninstalledFiles will list files which were removed during uninstallation
118  * <li>installedFiles will become empty
119  * </ul>
120  *
121  * @param entry The entry to deinstall
122  *
123  */
124  void uninstall(KNSCore::EntryInternal entry);
125 
126  /**
127  * Returns the uncompression setting, in a computer-readable format
128  *
129  * @return The value of this setting
130  * @since 5.71
131  */
132  UncompressionOptions uncompressionSetting() const;
133 
134  // TODO KF6: remove, was used with deprecated Security class.
135 #if KNEWSTUFFCORE_ENABLE_DEPRECATED_SINCE(5, 31)
136  KNEWSTUFFCORE_DEPRECATED_VERSION(5, 31, "No longer use")
137  void slotInstallationVerification(int result);
138 #endif
139 
140  void slotPayloadResult(KJob *job);
141 
142  /**
143  * @returns the installation path
144  *
145  * @since 5.31
146  */
147  QString targetInstallationPath() const;
148 
149 Q_SIGNALS:
150  void signalEntryChanged(const KNSCore::EntryInternal &entry);
151  void signalInstallationFinished();
152  void signalInstallationFailed(const QString &message);
153  /**
154  * An informational signal fired when a serious error occurs during the installation.
155  * @param message The description of the error (a message intended to be human readable)
156  * @since 5.69
157  */
158  void signalInstallationError(const QString &message);
159 
160  void signalPayloadLoaded(QUrl payload); // FIXME: return Entry
161 
162  // TODO KF6: remove, was used with deprecated Security class.
163 #if KNEWSTUFFCORE_ENABLE_DEPRECATED_SINCE(5, 31)
164  KNEWSTUFFCORE_DEPRECATED_VERSION(5, 31, "No longer use")
165  void signalInformation(const QString &) const;
166  KNEWSTUFFCORE_DEPRECATED_VERSION(5, 31, "No longer use")
167  void signalError(const QString &) const;
168 #endif
169 
170 private:
171  void install(KNSCore::EntryInternal entry, const QString &downloadedFile);
172 
173  QStringList installDownloadedFileAndUncompress(const KNSCore::EntryInternal &entry, const QString &payloadfile, const QString installdir);
174  QProcess *runPostInstallationCommand(const QString &installPath);
175 
176  static QStringList archiveEntries(const QString &path, const KArchiveDirectory *dir);
177 
178  // applications can set this if they want the installed files/directories to be piped into a shell command
179  QString postInstallationCommand;
180  // a custom command to run for the uninstall
181  QString uninstallCommand;
182  // compression policy
183  QString uncompression;
184 
185  // only one of the five below can be set, that will be the target install path/file name
186  // FIXME: check this when reading the config and make one path out of it if possible?
187  QString standardResourceDirectory;
188  QString targetDirectory;
189  QString xdgTargetDirectory;
190  QString installPath;
191  QString absoluteInstallPath;
192 #if KNEWSTUFFCORE_BUILD_DEPRECATED_SINCE(5, 79)
193  // policies whether verification needs to be done
194  Policy checksumPolicy = CheckIfPossible;
195  Policy signaturePolicy = CheckIfPossible;
196  // scope: install into user or system dirs
197  Scope scope = ScopeUser;
198  // FIXME this throws together a file name from entry name and version - why would anyone want that?
199  bool customName = false;
200  bool acceptHtml = false;
201 #endif
202 
203  QMap<KJob *, EntryInternal> entry_jobs;
204 
205  Q_DISABLE_COPY(Installation)
206 };
207 
208 }
209 
210 #endif
< As Archive, except that if there is more than an item in the file, put contents in a subdirectory w...
Definition: installation.h:67
Contains the core functionality for handling interaction with NewStuff providers. ...
< Never attempt to decompress a file, whatever format it is. Matches "never" knsrc setting ...
Definition: installation.h:60
< If the file is an archive, decompress it in a subdirectory if it contains multiple files...
Definition: installation.h:65
< Assume all downloaded files are archives, and attempt to decompress them.
Definition: installation.h:62
KNewStuff data entry container.
Definition: entryinternal.h:49
KNewStuff entry installation.
Definition: installation.h:37
< If the file is an archive, decompress it, otherwise just pass it on. Matches "archive" knsrc settin...
Definition: installation.h:63
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Thu Sep 23 2021 22:42:45 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.