Moved archive download interface files and converted documetnation to doxygen

This commit is contained in:
ksuprynowicz 2023-11-01 19:14:42 +01:00
parent 8332e41989
commit bf8ad07b60
5 changed files with 122 additions and 137 deletions

View file

@ -0,0 +1,106 @@
//
// ArchiveDownloadInterface.h
// libraries/script-engine/src
//
// Created by Elisa Lupin-Jimenez on 6/28/16.
// Copyright 2016 High Fidelity, Inc.
// Copyright 2023 Overte e.V.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
/// @addtogroup Interface
/// @{
#ifndef hifi_ArchiveDownloadInterface_h
#define hifi_ArchiveDownloadInterface_h
#include <QtCore/QObject>
#include <QtCore/QUrl>
#include <QFileInfo>
#include <QString>
/**
* @brief The ArchiveDownloadInterface API provides some facilities for working with the file system.
*/
class ArchiveDownloadInterface : public QObject {
Q_OBJECT
public:
ArchiveDownloadInterface(QObject* parent);
public slots:
/**
* @brief Extracts a filename from a URL, where the filename is specified in the query part of the URL as filename=.
* @param url - The URL to extract the filename from.
* @return The filename specified in the URL; an empty string if no filename is specified.
*/
QString convertUrlToPath(QUrl url);
/**
* @brief Unzips a file in the local file system to a new, unique temporary directory.
* @param path - The path of the zip file in the local file system. May have a leading "file:///".
* Need not have a ".zip" extension if it is in a temporary directory (as created by
* getTempDir).
* @param url - Not used.
* @param autoAdd - Not used by user scripts. The value is simply passed through to the
* unzipResult signal.
* @param isZip - Set to true if path has a ".zip" extension,
* false if it doesn't (but should still be treated as a zip file).
* @param isBlocks - Not used by user scripts. The value is simply passed through to the
* unzipResult signal.
* @example (Old example from JS, needs to be converted)
* Select and unzip a file.
* File.unzipResult.connect(function (zipFile, unzipFiles, autoAdd, isZip, isBlocks) {
* print("File.unzipResult()");
* print("- zipFile: " + zipFile);
* print("- unzipFiles(" + unzipFiles.length + "): " + unzipFiles);
* print("- autoAdd: " + autoAdd);
* print("- isZip: " + isZip);
* print("- isBlocks: " + isBlocks);
* });
*
* var zipFile = Window.browse("Select a Zip File", "", "*.zip");
* if (zipFile) {
* File.runUnzip(zipFile, "", false, true, false);
* } else {
* print("Zip file not selected.");
* }
*/
void runUnzip(QString path, QUrl url, bool autoAdd, bool isZip, bool isBlocks);
/**
* Creates a new, unique directory for temporary use.
* @return The path of the newly created temporary directory.
*/
QString getTempDir();
signals:
/**
* Triggered when runUnzip completes.
* @param zipFile - The file that was unzipped.
* @param unzipFiles - The paths of the unzipped files in a newly created temporary directory. Includes entries
* for any subdirectories created. An empty array if the zipFile could not be unzipped.
* @param autoAdd - The value that runUnzip was called with.
* @param isZip - true if runUnzip was called with isZip == true,
* unless there is no FBX or OBJ file in the unzipped file(s) in which case the value is false.
* @param isBlocks - The value that runUnzip was called with.
*/
void unzipResult(QString zipFile, QStringList unzipFile, bool autoAdd, bool isZip, bool isBlocks);
private:
bool isTempDir(QString tempDir);
bool hasModel(QStringList fileList);
QStringList unzipFile(QString path, QString tempDir);
void recursiveFileScan(QFileInfo file, QString* dirName);
void downloadZip(QString path, const QString link);
};
#endif // hifi_ArchiveDownloadInterface_h
/// @}

View file

@ -60,17 +60,19 @@ Audio::Audio() : _devices(_contextIsHMD) {
onContextChanged();
}
bool Audio::startRecording() {
return resultWithWriteLock<bool>([&] {
const QString FILENAME_PATH_FORMAT = "overte-snap-by-%1-on-%2";
const QString DEFAULT_FORMAT = "wav";
const QString DATETIME_FORMAT = "yyyy-MM-dd_hh-mm-ss";
QUuid Audio::startRecording() {
return resultWithWriteLock<QUuid>([&] {
const QString FILENAME_PREFIX = "overte-audio-";
const QString AUDIO_FORMAT = "wav";
QUuid id = QUuid::createUuid();
QString username = DependencyManager::get<AccountManager>()->getAccountInfo().getUsername();
QString filepath = DependencyManager::get<Snapshot>()->_snapshotsLocation.get();
QDateTime now = QDateTime::currentDateTime();
QString filename = FILENAME_PATH_FORMAT.arg(username, now.toString(DATETIME_FORMAT)) + "." + DEFAULT_FORMAT;
return DependencyManager::get<AudioClient>()->startRecording(filepath + "/" + filename);
QString filename = FILENAME_PREFIX + id.toString() + "." + AUDIO_FORMAT;
if (DependencyManager::get<AudioClient>()->startRecording(filepath + "/" + filename)) {
return id;
} else {
return QUuid();
}
});
}

View file

@ -295,13 +295,12 @@ public:
/*@jsdoc
* Starts making an audio recording of the audio being played in-world (i.e., not local-only audio) to a file in WAV format.
* Audio is recorded to snapshots directory specified in settings.
* @function Audio.startRecording
* @param {string} filename - The path and name of the file to make the recording in. Should have a <code>.wav</code>
* extension. The file is overwritten if it already exists.
* @returns {boolean} <code>true</code> if the specified file could be opened and audio recording has started, otherwise
* <code>false</code>.
* @returns {Uuid} A valid <code>Uuid</code> if the specified file could be opened and audio recording has started, otherwise
* <code>Uuid.NULL</code>.
* @example <caption>Make a 10 second audio recording.</caption>
* if (Audio.startRecording()) {
* if (Audio.startRecording() !== Uuid.NULL) {
* Script.setTimeout(function () {
* Audio.stopRecording();
* print("Audio recording finished.");
@ -311,7 +310,7 @@ public:
* print("Could not make an audio recording file.");
* }
*/
Q_INVOKABLE bool startRecording();
Q_INVOKABLE QUuid startRecording();
/*@jsdoc
* Finishes making an audio recording started with {@link Audio.startRecording|startRecording}.

View file

@ -1,122 +0,0 @@
//
// ArchiveDownloadInterface.h
// libraries/script-engine/src
//
// Created by Elisa Lupin-Jimenez on 6/28/16.
// Copyright 2016 High Fidelity, Inc.
// Copyright 2023 Overte e.V.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
/// @addtogroup ScriptEngine
/// @{
#ifndef hifi_ArchiveDownloadInterface_h
#define hifi_ArchiveDownloadInterface_h
#include <QtCore/QObject>
#include <QtCore/QUrl>
#include <QFileInfo>
#include <QString>
/*@jsdoc
* The <code>File</code> API provides some facilities for working with the file system.
*
* @namespace File
*
* @hifi-interface
* @hifi-client-entity
* @hifi-avatar
* @hifi-server-entity
* @hifi-assignment-client
*/
class ArchiveDownloadInterface : public QObject {
Q_OBJECT
public:
ArchiveDownloadInterface(QObject* parent);
public slots:
/*@jsdoc
* Extracts a filename from a URL, where the filename is specified in the query part of the URL as <code>filename=</code>.
* @function File.convertUrlToPath
* @param {string} url - The URL to extract the filename from.
* @returns {string} The filename specified in the URL; an empty string if no filename is specified.
* @example <caption>Extract a filename from a URL.</caption>
* var url = "http://domain.tld/path/page.html?filename=file.ext";
* print("File name: " + File.convertUrlToPath(url)); // file.ext
*/
QString convertUrlToPath(QUrl url);
/*@jsdoc
* Unzips a file in the local file system to a new, unique temporary directory.
* @function File.runUnzip
* @param {string} path - The path of the zip file in the local file system. May have a leading <code>"file:///"</code>.
* Need not have a <code>".zip"</code> extension if it is in a temporary directory (as created by
* {@link File.getTempDir|getTempDir}).
* @param {string} url - <em>Not used.</em>
* @param {boolean} autoAdd - <em>Not used by user scripts.</em> The value is simply passed through to the
* {@link File.unzipResult|unzipResult} signal.
* @param {boolean} isZip - Set to <code>true</code> if <code>path</code> has a <code>".zip"</code> extension,
* <code>false</code> if it doesn't (but should still be treated as a zip file).
* @param {boolean} isBlocks - <em>Not used by user scripts.</em> The value is simply passed through to the
* {@link File.unzipResult|unzipResult} signal.
* @example <caption>Select and unzip a file.</caption>
* File.unzipResult.connect(function (zipFile, unzipFiles, autoAdd, isZip, isBlocks) {
* print("File.unzipResult()");
* print("- zipFile: " + zipFile);
* print("- unzipFiles(" + unzipFiles.length + "): " + unzipFiles);
* print("- autoAdd: " + autoAdd);
* print("- isZip: " + isZip);
* print("- isBlocks: " + isBlocks);
* });
*
* var zipFile = Window.browse("Select a Zip File", "", "*.zip");
* if (zipFile) {
* File.runUnzip(zipFile, "", false, true, false);
* } else {
* print("Zip file not selected.");
* }
*/
void runUnzip(QString path, QUrl url, bool autoAdd, bool isZip, bool isBlocks);
/*@jsdoc
* Creates a new, unique directory for temporary use.
* @function File.getTempDir
* @returns {string} The path of the newly created temporary directory.
* @example <caption>Create a temporary directory.</caption>
* print("New temporary directory: " + File.getTempDir());
*/
QString getTempDir();
signals:
/*@jsdoc
* Triggered when {@link File.runUnzip|runUnzip} completes.
* @function File.unzipResult
* @param {string} zipFile - The file that was unzipped.
* @param {string[]} unzipFiles - The paths of the unzipped files in a newly created temporary directory. Includes entries
* for any subdirectories created. An empty array if the <code>zipFile</code> could not be unzipped.
* @param {boolean} autoAdd - The value that {@link File.runUnzip|runUnzip} was called with.
* @param {boolean} isZip - <code>true</code> if {@link File.runUnzip|runUnzip} was called with <code>isZip == true</code>,
* unless there is no FBX or OBJ file in the unzipped file(s) in which case the value is <code>false</code>.
* @param {boolean} isBlocks - The value that {@link File.runUnzip|runUnzip} was called with.
* @returns {Signal}
*/
void unzipResult(QString zipFile, QStringList unzipFile, bool autoAdd, bool isZip, bool isBlocks);
private:
bool isTempDir(QString tempDir);
bool hasModel(QStringList fileList);
QStringList unzipFile(QString path, QString tempDir);
void recursiveFileScan(QFileInfo file, QString* dirName);
void downloadZip(QString path, const QString link);
};
#endif // hifi_ArchiveDownloadInterface_h
/// @}