mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-20 04:25:42 +08:00
Ref T125, value class for remote files (i.e. files downloaded). Corresponds with backend service T132
This commit is contained in:
committed by
Mathew Sutcliffe
parent
8d72fe5285
commit
50442e6f13
130
src/blackmisc/network/remotefile.h
Normal file
130
src/blackmisc/network/remotefile.h
Normal file
@@ -0,0 +1,130 @@
|
||||
/* Copyright (C) 2017
|
||||
* swift project Community / Contributors
|
||||
*
|
||||
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
|
||||
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
|
||||
* including this file, may be copied, modified, propagated, or distributed except according to the terms
|
||||
* contained in the LICENSE file.
|
||||
*/
|
||||
|
||||
//! \file
|
||||
|
||||
#ifndef BLACKMISC_NETWORK_REMOTEFILE_H
|
||||
#define BLACKMISC_NETWORK_REMOTEFILE_H
|
||||
|
||||
#include "url.h"
|
||||
#include "blackmisc/blackmiscexport.h"
|
||||
#include "blackmisc/timestampbased.h"
|
||||
#include "blackmisc/metaclass.h"
|
||||
#include "blackmisc/propertyindex.h"
|
||||
#include "blackmisc/valueobject.h"
|
||||
#include "blackmisc/variant.h"
|
||||
|
||||
#include <QJsonObject>
|
||||
#include <QMetaType>
|
||||
#include <QString>
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
namespace Network
|
||||
{
|
||||
/*!
|
||||
* Remote file, i.e. a file residing on a server
|
||||
*/
|
||||
class BLACKMISC_EXPORT CRemoteFile :
|
||||
public CValueObject<CRemoteFile>,
|
||||
public BlackMisc::ITimestampBased
|
||||
{
|
||||
public:
|
||||
//! Properties by index
|
||||
enum ColumnIndex
|
||||
{
|
||||
IndexName = BlackMisc::CPropertyIndex::GlobalIndexCRemoteFile,
|
||||
IndexDescription,
|
||||
IndexUrl,
|
||||
IndexSize
|
||||
};
|
||||
|
||||
//! Constructor
|
||||
CRemoteFile() = default;
|
||||
|
||||
//! Constructor
|
||||
CRemoteFile(const QString &name, const QString &description);
|
||||
|
||||
//! Constructor
|
||||
CRemoteFile(const QString &name, qint64 size, const QString &url);
|
||||
|
||||
//! Name
|
||||
const QString &getName() const { return m_name; }
|
||||
|
||||
//! Name + human readable size
|
||||
QString getNameAndSize() const;
|
||||
|
||||
//! Name
|
||||
void setName(const QString &name) { m_name = name.trimmed(); }
|
||||
|
||||
//! Matching name?
|
||||
bool matchesName(const QString &name) const;
|
||||
|
||||
//! Description
|
||||
const QString &getDescription() const { return m_description; }
|
||||
|
||||
//! Description
|
||||
void setDescription(const QString &description) { m_description = description.trimmed(); }
|
||||
|
||||
//! Get URL
|
||||
const CUrl &getUrl() const { return m_url; }
|
||||
|
||||
//! Set URL
|
||||
void setUrl(const CUrl &url) { m_url = url; }
|
||||
|
||||
//! Set URL
|
||||
void setUrl(const QString &url);
|
||||
|
||||
//! Get size
|
||||
qint64 getSize() const { return m_size; }
|
||||
|
||||
//! Human readable file size, e.g. 2KB
|
||||
QString getSizeHumanReadable() const;
|
||||
|
||||
//! Set size
|
||||
void setSize(qint64 size) { m_size = size; }
|
||||
|
||||
//! Created timestamp
|
||||
QString getFormattedCreatedYmdhms() const;
|
||||
|
||||
//! \copydoc BlackMisc::Mixin::String::toQString
|
||||
QString convertToQString(bool i18n = false) const;
|
||||
|
||||
//! \copydoc BlackMisc::Mixin::Index::propertyByIndex
|
||||
CVariant propertyByIndex(const BlackMisc::CPropertyIndex &index) const;
|
||||
|
||||
//! \copydoc BlackMisc::Mixin::Index::setPropertyByIndex
|
||||
void setPropertyByIndex(const BlackMisc::CPropertyIndex &index, const CVariant &variant);
|
||||
|
||||
//! Role from DB JSON
|
||||
static CRemoteFile fromDatabaseJson(const QJsonObject &json);
|
||||
|
||||
private:
|
||||
QString m_name;
|
||||
QString m_description;
|
||||
CUrl m_url;
|
||||
qint64 m_size = 0;
|
||||
qint64 m_created = 0;
|
||||
|
||||
BLACK_METACLASS(
|
||||
CRemoteFile,
|
||||
BLACK_METAMEMBER(timestampMSecsSinceEpoch),
|
||||
BLACK_METAMEMBER(name),
|
||||
BLACK_METAMEMBER(description),
|
||||
BLACK_METAMEMBER(url),
|
||||
BLACK_METAMEMBER(size),
|
||||
BLACK_METAMEMBER(created)
|
||||
);
|
||||
};
|
||||
} // ns
|
||||
} // ns
|
||||
|
||||
Q_DECLARE_METATYPE(BlackMisc::Network::CRemoteFile)
|
||||
|
||||
#endif // guard
|
||||
Reference in New Issue
Block a user