mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-31 04:25:35 +08:00
Ref T203, update info combining artifacts and distributions
This commit is contained in:
@@ -25,5 +25,6 @@
|
||||
#include "blackmisc/db/distributionlist.h"
|
||||
#include "blackmisc/db/artifact.h"
|
||||
#include "blackmisc/db/artifactlist.h"
|
||||
#include "blackmisc/db/updateinfo.h"
|
||||
|
||||
#endif // guard
|
||||
|
||||
@@ -23,6 +23,7 @@ namespace BlackMisc
|
||||
CArtifactList::registerMetadata();
|
||||
CDistribution::registerMetadata();
|
||||
CDistributionList::registerMetadata();
|
||||
CUpdateInfo::registerMetadata();
|
||||
}
|
||||
} // ns
|
||||
} // ns
|
||||
|
||||
145
src/blackmisc/db/updateinfo.cpp
Normal file
145
src/blackmisc/db/updateinfo.cpp
Normal file
@@ -0,0 +1,145 @@
|
||||
/* 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.
|
||||
*/
|
||||
|
||||
#include "updateinfo.h"
|
||||
#include "blackconfig/buildconfig.h"
|
||||
#include <QStringBuilder>
|
||||
|
||||
using namespace BlackConfig;
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
namespace Db
|
||||
{
|
||||
CUpdateInfo::CUpdateInfo(const CArtifactList &artifacts, const CDistributionList &distributions) :
|
||||
m_distributions(distributions)
|
||||
{
|
||||
m_artifactsPilotClient = artifacts.findByType(CArtifact::PilotClientInstaller);
|
||||
m_artifactsXsb = artifacts.findByType(CArtifact::XSwiftBus);
|
||||
}
|
||||
|
||||
CDistributionList CUpdateInfo::getDistributionsPilotClientForCurrentPlatform() const
|
||||
{
|
||||
const CArtifactList artifacts = this->getArtifactsPilotClient().findMatchingForCurrentPlatform();
|
||||
CDistributionList distributions = artifacts.getDistributions();
|
||||
distributions.sortByStability();
|
||||
return distributions;
|
||||
}
|
||||
|
||||
CArtifactList CUpdateInfo::getArtifactsPilotClientForCurrentPlatform() const
|
||||
{
|
||||
CArtifactList artifacts = m_artifactsPilotClient.findMatchingForCurrentPlatform();
|
||||
artifacts.sortByVersion(Qt::DescendingOrder);
|
||||
return artifacts;
|
||||
}
|
||||
|
||||
CArtifactList CUpdateInfo::getArtifactsXsbLatestVersionFirst() const
|
||||
{
|
||||
CArtifactList artifacts(m_artifactsXsb);
|
||||
artifacts.sortByVersion(Qt::DescendingOrder);
|
||||
return artifacts;
|
||||
}
|
||||
|
||||
CArtifactList CUpdateInfo::getArtifactsXsbForCurrentPlatform() const
|
||||
{
|
||||
CArtifactList artifacts = m_artifactsXsb.findMatchingForCurrentPlatform();
|
||||
artifacts.sortByVersion(Qt::DescendingOrder);
|
||||
return artifacts;
|
||||
}
|
||||
|
||||
CDistribution CUpdateInfo::anticipateOwnDistribution() const
|
||||
{
|
||||
if (this->isEmpty()) { return CDistribution(); }
|
||||
const CArtifactList ownArtifacts = this->getArtifactsPilotClientForCurrentPlatform();
|
||||
if (ownArtifacts.isEmpty()) { return CDistribution(); }
|
||||
|
||||
const QVersionNumber myVersion = CBuildConfig::getVersion();
|
||||
const QVersionNumber latestVersion = ownArtifacts.getLatestQVersion();
|
||||
if (myVersion > latestVersion)
|
||||
{
|
||||
// dev. version
|
||||
return ownArtifacts.getDistributions().getLeastStableOrDefault();
|
||||
}
|
||||
|
||||
const CArtifact exactVersion = ownArtifacts.findFirstByVersionOrDefault(myVersion);
|
||||
if (!exactVersion.isUnknown()) { return exactVersion.getDistributions().getMostStableOrDefault(); }
|
||||
|
||||
return CDistribution();
|
||||
}
|
||||
|
||||
QStringList CUpdateInfo::anticipateMyDefaultChannelAndPlatform() const
|
||||
{
|
||||
const CArtifactList myArtifacts = this->getArtifactsPilotClient().findMatchingForCurrentPlatform();
|
||||
const CDistribution mostStable = myArtifacts.getDistributions().getMostStableOrDefault();
|
||||
return QStringList({ mostStable.getClassName(), CPlatform::currentPlatform().getPlatformName() });
|
||||
}
|
||||
|
||||
QString CUpdateInfo::convertToQString(bool i18n) const
|
||||
{
|
||||
return this->convertToQString(", ", i18n);
|
||||
}
|
||||
|
||||
QString CUpdateInfo::convertToQString(const QString &separator, bool i18n) const
|
||||
{
|
||||
Q_UNUSED(i18n);
|
||||
return QLatin1String("artifacts (PC): ") %
|
||||
this->getArtifactsPilotClient().toQString(i18n) %
|
||||
separator %
|
||||
QLatin1String("artifacts (XSB): ") %
|
||||
this->getArtifactsXsb().toQString(i18n) %
|
||||
separator %
|
||||
QLatin1String("distributions: ") %
|
||||
this->getDistributions().toQString(i18n);
|
||||
}
|
||||
|
||||
CVariant CUpdateInfo::propertyByIndex(const CPropertyIndex &index) const
|
||||
{
|
||||
if (index.isMyself()) { return CVariant::from(*this); }
|
||||
const ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||
switch (i)
|
||||
{
|
||||
case IndexArtifactsPilotClient: return CVariant::fromValue(m_artifactsPilotClient);
|
||||
case IndexArtifactsXSwiftBus: CVariant::fromValue(m_artifactsXsb);
|
||||
case IndexDistributions: return CVariant::fromValue(m_distributions);
|
||||
default: return CValueObject::propertyByIndex(index);
|
||||
}
|
||||
}
|
||||
|
||||
void CUpdateInfo::setPropertyByIndex(const CPropertyIndex &index, const CVariant &variant)
|
||||
{
|
||||
if (index.isMyself()) { (*this) = variant.to<CUpdateInfo>(); return; }
|
||||
const ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||
switch (i)
|
||||
{
|
||||
case IndexArtifactsPilotClient: m_artifactsPilotClient = variant.value<CArtifactList>(); break;
|
||||
case IndexArtifactsXSwiftBus: m_artifactsXsb = variant.value<CArtifactList>(); break;
|
||||
case IndexDistributions: m_distributions = variant.value<CDistributionList>(); break;
|
||||
default: CValueObject::setPropertyByIndex(index, variant); break;
|
||||
}
|
||||
}
|
||||
|
||||
CUpdateInfo CUpdateInfo::fromDatabaseJson(const QJsonObject &json, const QString &prefix)
|
||||
{
|
||||
Q_UNUSED(prefix); // not nested
|
||||
const QJsonArray jsonDistributions = json.value("distributions").toArray();
|
||||
const QJsonArray jsonArtifacts = json.value("artifacts").toArray();
|
||||
const CDistributionList distributions = CDistributionList::fromDatabaseJson(jsonDistributions);
|
||||
const CArtifactList artifacts = CArtifactList::fromDatabaseJson(jsonArtifacts);
|
||||
Q_ASSERT_X(jsonDistributions.size() == distributions.size(), Q_FUNC_INFO, "size mismatch");
|
||||
Q_ASSERT_X(artifacts.size() == artifacts.size(), Q_FUNC_INFO, "size mismatch");
|
||||
return CUpdateInfo(artifacts, distributions);
|
||||
}
|
||||
|
||||
CUpdateInfo CUpdateInfo::fromDatabaseJson(const QString &jsonString)
|
||||
{
|
||||
if (jsonString.isEmpty()) { return CUpdateInfo(); }
|
||||
return CUpdateInfo::fromDatabaseJson(Json::jsonObjectFromString(jsonString));
|
||||
}
|
||||
} // ns
|
||||
} // ns
|
||||
125
src/blackmisc/db/updateinfo.h
Normal file
125
src/blackmisc/db/updateinfo.h
Normal file
@@ -0,0 +1,125 @@
|
||||
/* 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_UPDATEINFO_H
|
||||
#define BLACKMISC_DB_UPDATEINFO_H
|
||||
|
||||
#include "artifactlist.h"
|
||||
#include "distributionlist.h"
|
||||
#include "blackmisc/datacache.h"
|
||||
#include "blackmisc/valueobject.h"
|
||||
#include <QStringList>
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
namespace Db
|
||||
{
|
||||
//! Update info, i.e. artifacts and distributions
|
||||
//! \sa CArtifact
|
||||
//! \sa CDistribution
|
||||
class BLACKMISC_EXPORT CUpdateInfo : public CValueObject<CUpdateInfo>
|
||||
{
|
||||
public:
|
||||
//! Properties by index
|
||||
enum ColumnIndex
|
||||
{
|
||||
IndexArtifactsPilotClient = CPropertyIndex::GlobalIndexCUpdateInfo,
|
||||
IndexArtifactsXSwiftBus,
|
||||
IndexDistributions
|
||||
};
|
||||
|
||||
//! Constructor
|
||||
CUpdateInfo() {}
|
||||
|
||||
//! Constructor
|
||||
CUpdateInfo(const CArtifactList &artifacts, const CDistributionList &distributions);
|
||||
|
||||
//! Destructor.
|
||||
~CUpdateInfo() {}
|
||||
|
||||
//! Artifacts (pilot client)
|
||||
const CArtifactList &getArtifactsPilotClient() const { return m_artifactsPilotClient; }
|
||||
|
||||
//! Artifacts for current platform
|
||||
//! \note sorted by version
|
||||
CArtifactList getArtifactsPilotClientForCurrentPlatform() const;
|
||||
|
||||
//! Artifacts (XSwiftBus)
|
||||
const CArtifactList &getArtifactsXsb() const { return m_artifactsXsb; }
|
||||
|
||||
//! Artifacts (XSwiftBus)
|
||||
CArtifactList getArtifactsXsbLatestVersionFirst() const;
|
||||
|
||||
//! Artifacts for current platform
|
||||
//! \note sorted by version
|
||||
CArtifactList getArtifactsXsbForCurrentPlatform() const;
|
||||
|
||||
//! Distributions (all)
|
||||
const CDistributionList &getDistributions() const { return m_distributions; }
|
||||
|
||||
//! Distributions for current platform
|
||||
CDistributionList getDistributionsPilotClientForCurrentPlatform() const;
|
||||
|
||||
//! Own distribution
|
||||
CDistribution anticipateOwnDistribution() const;
|
||||
|
||||
//! Default channel, OS
|
||||
QStringList anticipateMyDefaultChannelAndPlatform() const;
|
||||
|
||||
//! Empty (no data)
|
||||
bool isEmpty() const { return m_artifactsPilotClient.isEmpty() && m_distributions.isEmpty(); }
|
||||
|
||||
//! \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
|
||||
BlackMisc::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 CUpdateInfo fromDatabaseJson(const QJsonObject &json, const QString &prefix = {});
|
||||
|
||||
//! Object from database JSOn format
|
||||
static CUpdateInfo fromDatabaseJson(const QString &jsonString);
|
||||
|
||||
private:
|
||||
CArtifactList m_artifactsPilotClient; //!< artifacts pilot client
|
||||
CArtifactList m_artifactsXsb; //!< artifacts XSwiftBus
|
||||
CDistributionList m_distributions; //!< all distributions (for any artifacts)
|
||||
|
||||
BLACK_METACLASS(
|
||||
CUpdateInfo,
|
||||
BLACK_METAMEMBER(artifactsPilotClient),
|
||||
BLACK_METAMEMBER(artifactsXsb),
|
||||
BLACK_METAMEMBER(distributions)
|
||||
);
|
||||
};
|
||||
|
||||
//! Trait for update info, i.e. distributions and artifacts
|
||||
struct TUpdateInfo : public TDataTrait<CUpdateInfo>
|
||||
{
|
||||
//! Key in data cache
|
||||
static const char *key() { return "updateinfo"; }
|
||||
|
||||
//! First load is synchronous
|
||||
static constexpr bool isPinned() { return true; }
|
||||
};
|
||||
} // ns
|
||||
} // ns
|
||||
|
||||
Q_DECLARE_METATYPE(BlackMisc::Db::CUpdateInfo)
|
||||
|
||||
#endif // guard
|
||||
Reference in New Issue
Block a user