Slicer  4.8
Slicer is a multi-platform, free and open source software package for visualization and medical image computing
qSlicerExtensionsManagerModel.h
Go to the documentation of this file.
1 /*==============================================================================
2 
3  Program: 3D Slicer
4 
5  Copyright (c) Kitware Inc.
6 
7  See COPYRIGHT.txt
8  or http://www.slicer.org/copyright/copyright.txt for details.
9 
10  Unless required by applicable law or agreed to in writing, software
11  distributed under the License is distributed on an "AS IS" BASIS,
12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  See the License for the specific language governing permissions and
14  limitations under the License.
15 
16  This file was originally developed by Jean-Christophe Fillion-Robin, Kitware Inc.
17  and was partially funded by NIH grant 3P41RR013218-12S1
18 
19 ==============================================================================*/
20 
21 #ifndef __qSlicerExtensionsManagerModel_h
22 #define __qSlicerExtensionsManagerModel_h
23 
24 // Qt includes
25 #include <QHash>
26 #include <QStringList>
27 #include <QUrl>
28 #include <QSettings>
29 #include <QUuid>
30 #include <QVariantMap>
31 
32 // CTK includes
33 #include <ctkErrorLogModel.h>
34 
35 // QtGUI includes
36 #include "qSlicerBaseQTCoreExport.h"
38 
39 class QNetworkReply;
40 class qSlicerExtensionsManagerModelPrivate;
41 class QStandardItemModel;
42 
43 class Q_SLICER_BASE_QTCORE_EXPORT qSlicerExtensionsManagerModel : public QObject
44 {
45  Q_OBJECT
46  Q_PROPERTY(int numberOfInstalledExtensions READ numberOfInstalledExtensions)
47  Q_PROPERTY(QStringList installedExtensions READ installedExtensions)
48  Q_PROPERTY(QStringList enabledExtensions READ enabledExtensions)
49  Q_PROPERTY(QUrl serverUrl READ serverUrl)
50  Q_PROPERTY(QUrl serverUrlWithPackagePath READ serverUrlWithPackagePath)
51  Q_PROPERTY(QUrl serverUrlWithExtensionsStorePath READ serverUrlWithExtensionsStorePath)
52  Q_PROPERTY(QString extensionsInstallPath READ extensionsInstallPath)
53  Q_PROPERTY(bool newExtensionEnabledByDefault READ newExtensionEnabledByDefault WRITE setNewExtensionEnabledByDefault)
54  Q_PROPERTY(QString extensionsSettingsFilePath READ extensionsSettingsFilePath WRITE setExtensionsSettingsFilePath)
55  Q_PROPERTY(QString slicerRevision READ slicerRevision WRITE setSlicerRevision)
56  Q_PROPERTY(QString slicerOs READ slicerOs WRITE setSlicerOs)
57  Q_PROPERTY(QString slicerArch READ slicerArch WRITE setSlicerArch)
58  Q_PROPERTY(QString slicerVersion READ slicerVersion WRITE setSlicerVersion)
59 public:
61  typedef QObject Superclass;
62 
64  typedef qSlicerExtensionsManagerModelPrivate Pimpl;
65 
68 
70  explicit qSlicerExtensionsManagerModel(QObject* parent = 0);
71 
74 
77 
78  QUrl serverUrl()const;
79  QUrl serverUrlWithPackagePath()const;
80  QUrl serverUrlWithExtensionsStorePath()const;
81 
82  QString extensionsInstallPath()const;
83 
84  Q_INVOKABLE QString extensionInstallPath(const QString& extensionName) const;
85 
86  Q_INVOKABLE QStringList extensionModulePaths(const QString& extensionName)const;
87 
88  Q_INVOKABLE QString extensionDescriptionFile(const QString& extensionName) const;
89 
90  void setNewExtensionEnabledByDefault(bool value);
91  bool newExtensionEnabledByDefault()const;
92 
93  Q_INVOKABLE ExtensionMetadataType extensionMetadata(const QString& extensionName)const;
94 
97  Q_INVOKABLE bool isExtensionInstalled(const QString& extensionName)const;
98 
101  int numberOfInstalledExtensions()const;
102 
105  QStringList installedExtensions()const;
106 
109  Q_INVOKABLE bool isExtensionEnabled(const QString& extensionName)const;
110 
115  QStringList scheduledForUpdateExtensions() const;
116 
123  Q_INVOKABLE bool isExtensionUpdateAvailable(const QString& extensionName)const;
124 
130  Q_INVOKABLE bool isExtensionScheduledForUpdate(const QString& extensionName)const;
131 
134  QStringList scheduledForUninstallExtensions() const;
135 
138  Q_INVOKABLE bool isExtensionScheduledForUninstall(const QString& extensionName)const;
139 
142  QStringList enabledExtensions()const;
143 
144  QString extensionsSettingsFilePath()const;
145  void setExtensionsSettingsFilePath(const QString& extensionsSettingsFilePath);
146 
147  QString slicerRevision()const;
148  void setSlicerRevision(const QString& revision);
149 
150  QString slicerOs()const;
151  void setSlicerOs(const QString& os);
152 
153  QString slicerArch()const;
154  void setSlicerArch(const QString& arch);
155 
156  void setSlicerRequirements(const QString& revision, const QString& os, const QString& arch);
157 
158  QString slicerVersion()const;
159  void setSlicerVersion(const QString& version);
160 
165  Q_INVOKABLE QStringList isExtensionCompatible(const QString& extensionName, const QString& slicerRevision,
166  const QString& slicerOs, const QString& slicerArch) const;
167 
174  Q_INVOKABLE QStringList isExtensionCompatible(const QString& extensionName) const;
175 
178  Q_INVOKABLE ExtensionMetadataType retrieveExtensionMetadata(const QString& extensionId);
179 
187  Q_INVOKABLE bool installExtension(const QString &archiveFile);
188 
196  Q_INVOKABLE bool installExtension(const QString& extensionName,
197  ExtensionMetadataType extensionMetadata,
198  const QString &archiveFile);
199 
201  Q_INVOKABLE bool extractExtensionArchive(const QString& extensionName,
202  const QString& archiveFile,
203  const QString &destinationPath);
204 
206  Q_INVOKABLE const QStandardItemModel * model()const;
207 
208  static QHash<QString, QString> serverToExtensionDescriptionKey();
209 
210  static QStringList serverKeysToIgnore();
211 
212  static ExtensionMetadataType filterExtensionMetadata(const ExtensionMetadataType &extensionMetadata);
213 
214  static QStringList readArrayValues(QSettings& settings,
215  const QString& arrayName, const QString fieldName);
216 
217  static void writeArrayValues(QSettings& settings, const QStringList& values,
218  const QString& arrayName, const QString fieldName);
219 
220  static bool writeExtensionDescriptionFile(const QString& file,
221  const ExtensionMetadataType& metadata);
222 
223  static ExtensionMetadataType parseExtensionDescriptionFile(const QString& file);
224 
225 public slots:
226 
230  void setExtensionEnabled(const QString& extensionName, bool value);
231 
235  bool downloadAndInstallExtension(const QString& extensionId);
236 
242  bool scheduleExtensionForUninstall(const QString& extensionName);
243 
247  bool cancelExtensionScheduledForUninstall(const QString& extensionName);
248 
254  void checkForUpdates(bool installUpdates);
255 
262  bool scheduleExtensionForUpdate(const QString& extensionName);
263 
267  bool cancelExtensionScheduledForUpdate(const QString& extensionName);
268 
277  bool updateScheduledExtensions(QStringList &updatedExtensions);
278 
284  bool updateScheduledExtensions();
285 
294  bool uninstallScheduledExtensions(QStringList &uninstalledExtensions);
295 
301  bool uninstallScheduledExtensions();
302 
303  void identifyIncompatibleExtensions();
304 
305  bool exportExtensionList(QString& exportFilePath);
306 
307  QStringList checkInstallPrerequisites() const;
308 
309  void updateModel();
310 
311 signals:
312 
313  void downloadStarted(QNetworkReply * reply);
314 
315  void downloadFinished(QNetworkReply * reply);
316 
317  void updateDownloadProgress(const QString& extensionName,
318  qint64 received, qint64 total);
319 
320  void modelUpdated();
321 
322  void extensionUpdateAvailable(const QString& extensionName);
323 
324  void extensionInstalled(const QString& extensionName);
325 
326  void extensionUpdated(const QString& extensionName);
327 
328  void extensionScheduledForUninstall(const QString& extensionName);
329 
330  void extensionCancelledScheduleForUninstall(const QString& extensionName);
331 
332  void extensionScheduledForUpdate(const QString& extensionName);
333 
334  void extensionCancelledScheduleForUpdate(const QString& extensionName);
335 
336  void extensionUninstalled(const QString& extensionName);
337 
338  void extensionEnabledChanged(const QString& extensionName, bool value);
339 
340  void extensionIdentifedAsIncompatible(const QString& extensionName);
341 
342  void slicerRequirementsChanged(const QString& revision, const QString& os, const QString& arch);
343 
344  void messageLogged(const QString& text, ctkErrorLogLevel::LogLevels level) const;
345 
346 protected slots:
347 
349  void onInstallDownloadFinished(qSlicerExtensionDownloadTask* task);
350 
352  void onUpdateDownloadFinished(qSlicerExtensionDownloadTask* task);
353 
354  void onUpdateDownloadProgress(qSlicerExtensionDownloadTask* task,
355  qint64 received, qint64 total);
356 
357  void onUpdateCheckComplete(const QUuid& requestId,
358  const QList<QVariantMap>& results);
359  void onUpdateCheckFailed(const QUuid& requestId);
360 
361 protected:
362  QScopedPointer<qSlicerExtensionsManagerModelPrivate> d_ptr;
363 
364 private:
365  Q_DECLARE_PRIVATE(qSlicerExtensionsManagerModel);
366  Q_DISABLE_COPY(qSlicerExtensionsManagerModel);
367 };
368 
369 // Metatype already declared in qSlicerIO.h
370 //Q_DECLARE_METATYPE(qSlicerExtensionsManagerModel::ExtensionMetadataType)
371 
372 #endif
QObject Superclass
Superclass typedef.
qSlicerExtensionsManagerModelPrivate Pimpl
Pimpl typedef.