mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-21 04:45:31 +08:00
Ref T203, artifact class (representing something we have build)
This commit is contained in:
198
src/blackmisc/db/artifact.h
Normal file
198
src/blackmisc/db/artifact.h
Normal file
@@ -0,0 +1,198 @@
|
||||
/* 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_DB_ARTIFACT_H
|
||||
#define BLACKMISC_DB_ARTIFACT_H
|
||||
|
||||
#include "distributionlist.h"
|
||||
#include "datastore.h"
|
||||
#include "blackmisc/platform.h"
|
||||
#include "blackmisc/blackmiscexport.h"
|
||||
#include "blackmisc/network/remotefile.h"
|
||||
#include <QVersionNumber>
|
||||
#include <QString>
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
namespace Db
|
||||
{
|
||||
//! Artifacts ("our software" products)
|
||||
class BLACKMISC_EXPORT CArtifact :
|
||||
public CValueObject<CArtifact>,
|
||||
public IDatastoreObjectWithIntegerKey
|
||||
{
|
||||
public:
|
||||
//! Properties by index
|
||||
enum ColumnIndex
|
||||
{
|
||||
IndexName = CPropertyIndex::GlobalIndexCArtifact,
|
||||
IndexMd5,
|
||||
IndexType,
|
||||
IndexPlatform,
|
||||
IndexVersionString,
|
||||
IndexQVersion,
|
||||
IndexSize,
|
||||
IndexSizeHumanReadable,
|
||||
IndexDistributions
|
||||
};
|
||||
|
||||
//! Type
|
||||
enum ArtifactType
|
||||
{
|
||||
UnknownArtifact,
|
||||
PilotClientInstaller,
|
||||
Symbols,
|
||||
XSwiftBus
|
||||
};
|
||||
|
||||
//! Default constructor
|
||||
CArtifact();
|
||||
|
||||
//! Constructor
|
||||
CArtifact(const QString &name, const QString &version, const QString &md5,
|
||||
ArtifactType type, int size, bool existing, const CPlatform &platform);
|
||||
|
||||
//! Destructor.
|
||||
~CArtifact() {}
|
||||
|
||||
//! Having name?
|
||||
bool hasName() const { return !m_name.isEmpty(); }
|
||||
|
||||
//! Name (i.e. installer name, symbol name)
|
||||
const QString &getName() const { return m_name; }
|
||||
|
||||
//! Set the name
|
||||
void setName(const QString &name) { m_name = name.trimmed(); }
|
||||
|
||||
//! Matching name?
|
||||
bool matchesName(const QString &name, Qt::CaseSensitivity cs = Qt::CaseSensitive) const;
|
||||
|
||||
//! Having a version string?
|
||||
bool hasVersionString() const { return !m_version.isEmpty(); }
|
||||
|
||||
//! Version for platform
|
||||
const QString &getVersionString() const { return m_version; }
|
||||
|
||||
//! Get type
|
||||
ArtifactType getType() const { return static_cast<ArtifactType>(m_type); }
|
||||
|
||||
//! Unknown
|
||||
bool isUnknown() const { return this->getType() == UnknownArtifact; }
|
||||
|
||||
//! Set type
|
||||
void setType(ArtifactType type) { m_type = static_cast<int>(type); }
|
||||
|
||||
//! File size
|
||||
int getFileSize() const { return m_size; }
|
||||
|
||||
//! \copydoc CFileUtils::humanReadableFileSize
|
||||
QString getFileSizeHumanReadable() const;
|
||||
|
||||
//! Set file size
|
||||
void setFileSize(int size) { m_size = size; }
|
||||
|
||||
//! MD5
|
||||
const QString &getMd5() const { return m_md5; }
|
||||
|
||||
//! OS
|
||||
const CPlatform &getPlatform() const { return m_platform; }
|
||||
|
||||
//! Matches any platform
|
||||
bool matchesAnyPlatform(const CPlatform &platform) const;
|
||||
|
||||
//! Set the OS
|
||||
void setPlatform(const CPlatform &platform) { m_platform = platform; }
|
||||
|
||||
//! Related distributions
|
||||
const CDistributionList &getDistributions() const { return m_distributions; }
|
||||
|
||||
//! Most stable distribution if any
|
||||
CDistribution getMostStableDistribution() const { return this->getDistributions().getMostStableOrDefault(); }
|
||||
|
||||
//! Related distributions
|
||||
void setDistributions(const CDistributionList &distributions) { m_distributions = distributions; }
|
||||
|
||||
//! Has distributions?
|
||||
bool hasDistributions() const { return !m_distributions.isEmpty(); }
|
||||
|
||||
//! Is distributed with given distribution?
|
||||
bool isWithDistribution(const CDistribution &distribution, bool acceptMoreStableDistributions) const;
|
||||
|
||||
//! Turn into remote file
|
||||
//! \note requires distributions
|
||||
Network::CRemoteFile asRemoteFile() const;
|
||||
|
||||
//! Version as QVersion
|
||||
QVersionNumber getQVersion() const;
|
||||
|
||||
//! Newer tahn the current build
|
||||
bool isNewerThanCurrentBuild() const;
|
||||
|
||||
//! \copydoc BlackMisc::Mixin::String::toQString
|
||||
QString convertToQString(bool i18n = false) const;
|
||||
|
||||
//! To string
|
||||
QString convertToQString(const QString &separator, 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 BlackMisc::CVariant &variant);
|
||||
|
||||
//! Object from database JSON format
|
||||
static CArtifact fromDatabaseJson(const QJsonObject &json, const QString &prefix = {});
|
||||
|
||||
//! Type as string
|
||||
static const QString &typeToString(ArtifactType type);
|
||||
|
||||
private:
|
||||
QString m_name; //!< channel the files belong to
|
||||
QString m_version; //!< version string
|
||||
QString m_md5; //!< MD5 checksum
|
||||
int m_type = static_cast<int>(UnknownArtifact); //!< artifact type
|
||||
int m_size = -1; //!< size
|
||||
bool m_existing = false; //!< existing artifact for download
|
||||
CPlatform m_platform; //!< platform (i.e. OS)
|
||||
CDistributionList m_distributions; //!< related distributions
|
||||
|
||||
//! Extract version number from a file name
|
||||
static QString versionNumberFromFilename(const QString &filename);
|
||||
|
||||
//! Type from string
|
||||
static ArtifactType stringToType(const QString &str);
|
||||
|
||||
//! Trim the 4th segment of a version string
|
||||
static QString trimVersionString(const QString &version);
|
||||
|
||||
//! Trim a strin representing 4th segment
|
||||
static QString trim4thSegment(const QString &seg);
|
||||
|
||||
BLACK_METACLASS(
|
||||
CArtifact,
|
||||
BLACK_METAMEMBER(name),
|
||||
BLACK_METAMEMBER(version),
|
||||
BLACK_METAMEMBER(md5),
|
||||
BLACK_METAMEMBER(type),
|
||||
BLACK_METAMEMBER(size),
|
||||
BLACK_METAMEMBER(existing),
|
||||
BLACK_METAMEMBER(platform),
|
||||
BLACK_METAMEMBER(distributions),
|
||||
BLACK_METAMEMBER(timestampMSecsSinceEpoch)
|
||||
);
|
||||
};
|
||||
} // ns
|
||||
} // ns
|
||||
|
||||
Q_DECLARE_METATYPE(BlackMisc::Db::CArtifact)
|
||||
Q_DECLARE_METATYPE(BlackMisc::Db::CArtifact::ArtifactType)
|
||||
|
||||
#endif // guard
|
||||
Reference in New Issue
Block a user