Applied code formatter

This commit is contained in:
Dale Glass 2020-09-10 01:04:54 +02:00
parent 84e01630ee
commit 792854ccb7
2 changed files with 28 additions and 34 deletions

View file

@ -13,34 +13,34 @@
#include <QDebug> #include <QDebug>
#include <QLoggingCategory> #include <QLoggingCategory>
Q_LOGGING_CATEGORY(external_resource, "vircadia.networking.external_resource") Q_LOGGING_CATEGORY(external_resource, "vircadia.networking.external_resource")
ExternalResource::ExternalResource(QObject* parent) : QObject(parent) {
ExternalResource::ExternalResource(QObject *parent) : QObject(parent) {
} }
ExternalResource * ExternalResource::getInstance() { ExternalResource* ExternalResource::getInstance() {
static ExternalResource instance; static ExternalResource instance;
return &instance; return &instance;
} }
QUrl ExternalResource::getQUrl(Bucket bucket, const QUrl &relative_path) { QUrl ExternalResource::getQUrl(Bucket bucket, const QUrl& relative_path) {
qCDebug(external_resource) << "Requested URL for bucket " << bucket << ", path " << relative_path; qCDebug(external_resource) << "Requested URL for bucket " << bucket << ", path " << relative_path;
if ( !_bucketBases.contains(bucket)) { if (!_bucketBases.contains(bucket)) {
qCCritical(external_resource) << "External resource " << relative_path << " was requested from unrecognized bucket " << bucket; qCCritical(external_resource) << "External resource " << relative_path << " was requested from unrecognized bucket "
<< bucket;
return QUrl(); return QUrl();
} }
if ( !relative_path.isValid() ) { if (!relative_path.isValid()) {
qCCritical(external_resource) << "External resource " << relative_path << " was requested from bucket " << bucket << " with an invalid path. Error: " << relative_path.errorString(); qCCritical(external_resource) << "External resource " << relative_path << " was requested from bucket " << bucket
<< " with an invalid path. Error: " << relative_path.errorString();
return QUrl(); return QUrl();
} }
if ( !relative_path.isRelative() ) { if (!relative_path.isRelative()) {
qCWarning(external_resource) << "External resource " << relative_path << " was requested from bucket " << bucket << " without using a relative path, returning as-is."; qCWarning(external_resource) << "External resource " << relative_path << " was requested from bucket " << bucket
<< " without using a relative path, returning as-is.";
return relative_path; return relative_path;
} }
@ -48,19 +48,17 @@ QUrl ExternalResource::getQUrl(Bucket bucket, const QUrl &relative_path) {
QUrl base = _bucketBases[bucket]; QUrl base = _bucketBases[bucket];
QUrl merged = base.resolved(relative_path); QUrl merged = base.resolved(relative_path);
qCDebug(external_resource) << "External resource resolved to " << merged; qCDebug(external_resource) << "External resource resolved to " << merged;
return merged; return merged;
} }
QString ExternalResource::getBase(Bucket bucket) { QString ExternalResource::getBase(Bucket bucket) {
std::lock_guard<std::mutex> guard(_bucketMutex); std::lock_guard<std::mutex> guard(_bucketMutex);
return _bucketBases.value(bucket).toString(); return _bucketBases.value(bucket).toString();
}; };
void ExternalResource::setBase(Bucket bucket, const QString &url) { void ExternalResource::setBase(Bucket bucket, const QString& url) {
QUrl new_url(url); QUrl new_url(url);
if (!new_url.isValid() || new_url.isRelative()) { if (!new_url.isValid() || new_url.isRelative()) {

View file

@ -18,7 +18,6 @@
#include <mutex> #include <mutex>
/** /**
* Flexible management for external resources * Flexible management for external resources
* *
@ -36,10 +35,9 @@
class ExternalResource : public QObject { class ExternalResource : public QObject {
Q_OBJECT Q_OBJECT
public: public:
static ExternalResource* getInstance();
static ExternalResource *getInstance(); ~ExternalResource(){};
~ExternalResource() {};
/** /**
* Bucket from which to retrieve the resource * Bucket from which to retrieve the resource
@ -49,7 +47,8 @@ class ExternalResource : public QObject {
* will be done to the Assets bucket instead. This should ease the transition and ensure a clean * will be done to the Assets bucket instead. This should ease the transition and ensure a clean
* separation. * separation.
*/ */
enum class Bucket { enum class Bucket
{
/** Assets that used to be in the hifi-public S3 bucket */ /** Assets that used to be in the hifi-public S3 bucket */
Public, Public,
@ -79,7 +78,6 @@ class ExternalResource : public QObject {
*/ */
QUrl getQUrl(Bucket bucket, const QUrl& relative_path); QUrl getQUrl(Bucket bucket, const QUrl& relative_path);
/** /**
* Returns the location of a resource as a QUrl * Returns the location of a resource as a QUrl
* *
@ -92,9 +90,7 @@ class ExternalResource : public QObject {
* @param relative_path The path of the resource within the bucket * @param relative_path The path of the resource within the bucket
* @returns The resulting URL as a QUrl * @returns The resulting URL as a QUrl
*/ */
QUrl getQUrl(Bucket bucket, QString path) { QUrl getQUrl(Bucket bucket, QString path) { return getQUrl(bucket, QUrl(path)); }
return getQUrl(bucket, QUrl(path));
}
/** /**
* Returns the location of a resource as a QString * Returns the location of a resource as a QString
@ -108,7 +104,7 @@ class ExternalResource : public QObject {
* @param relative_path The path of the resource within the bucket * @param relative_path The path of the resource within the bucket
* @returns The resulting URL as a QString * @returns The resulting URL as a QString
*/ */
QString getUrl(Bucket bucket, const QUrl &relative_path) { QString getUrl(Bucket bucket, const QUrl& relative_path) {
return ExternalResource::getQUrl(bucket, relative_path).toString(); return ExternalResource::getQUrl(bucket, relative_path).toString();
}; };
@ -124,24 +120,24 @@ class ExternalResource : public QObject {
* @param relative_path The path of the resource within the bucket * @param relative_path The path of the resource within the bucket
* @returns The resulting URL as a QString * @returns The resulting URL as a QString
*/ */
Q_INVOKABLE QString getUrl(Bucket bucket, const QString &relative_path) { Q_INVOKABLE QString getUrl(Bucket bucket, const QString& relative_path) {
return ExternalResource::getQUrl(bucket, QUrl(relative_path)).toString(); return ExternalResource::getQUrl(bucket, QUrl(relative_path)).toString();
}; };
Q_INVOKABLE QString getBase(Bucket bucket); Q_INVOKABLE QString getBase(Bucket bucket);
Q_INVOKABLE void setBase(Bucket bucket, const QString &url); Q_INVOKABLE void setBase(Bucket bucket, const QString& url);
private: private:
ExternalResource(QObject* parent = nullptr); ExternalResource(QObject* parent = nullptr);
std::mutex _bucketMutex; std::mutex _bucketMutex;
QMap<Bucket, QUrl> _bucketBases { QMap<Bucket, QUrl> _bucketBases{
{ Bucket::Public, QUrl("https://public.vircadia.com")}, { Bucket::Public, QUrl("https://public.vircadia.com") },
{ Bucket::Content, QUrl("https://content.vircadia.com")}, { Bucket::Content, QUrl("https://content.vircadia.com") },
{ Bucket::Assets, QUrl("https://assets.vircadia.com")}, { Bucket::Assets, QUrl("https://assets.vircadia.com") },
{ Bucket::MPAssets, QUrl("https://mpassets.vircadia.com")}, { Bucket::MPAssets, QUrl("https://mpassets.vircadia.com") },
}; };
}; };