mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-30 05:51:23 +08:00
refs #507 download value object for download information
This commit is contained in:
committed by
Mathew Sutcliffe
parent
746985fa3c
commit
f448d50e29
@@ -6,6 +6,8 @@
|
|||||||
#include "blackcorefreefunctions.h"
|
#include "blackcorefreefunctions.h"
|
||||||
#include "blackcore/webreaderflags.h"
|
#include "blackcore/webreaderflags.h"
|
||||||
#include "blackcore/data/globalsetup.h"
|
#include "blackcore/data/globalsetup.h"
|
||||||
|
#include "blackcore/data/download.h"
|
||||||
|
|
||||||
|
|
||||||
#include "voice_channel.h"
|
#include "voice_channel.h"
|
||||||
#include "network.h"
|
#include "network.h"
|
||||||
@@ -26,5 +28,6 @@ namespace BlackCore
|
|||||||
qDBusRegisterMetaType<BlackCore::CLogSubscriptionPair>();
|
qDBusRegisterMetaType<BlackCore::CLogSubscriptionPair>();
|
||||||
|
|
||||||
BlackCore::Data::CGlobalSetup::registerMetadata();
|
BlackCore::Data::CGlobalSetup::registerMetadata();
|
||||||
|
BlackCore::Data::CDownload::registerMetadata();
|
||||||
}
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|||||||
140
src/blackcore/data/download.cpp
Normal file
140
src/blackcore/data/download.cpp
Normal file
@@ -0,0 +1,140 @@
|
|||||||
|
/* Copyright (C) 2015
|
||||||
|
* 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 "download.h"
|
||||||
|
#include "blackmisc/blackmiscfreefunctions.h"
|
||||||
|
#include "blackmisc/project.h"
|
||||||
|
#include <QStringList>
|
||||||
|
|
||||||
|
using namespace BlackMisc;
|
||||||
|
using namespace BlackMisc::Network;
|
||||||
|
|
||||||
|
namespace BlackCore
|
||||||
|
{
|
||||||
|
namespace Data
|
||||||
|
{
|
||||||
|
CDownload::CDownload() :
|
||||||
|
ITimestampBased(0),
|
||||||
|
m_downloadsStableUrls(QStringList {"http://swift-project.org/"}),
|
||||||
|
m_downloadsBetaUrls(QStringList {"http://swift-project.org/"}),
|
||||||
|
m_latestVersionStable(CProject::version()),
|
||||||
|
m_lastSupportedVersionStable("0.6"),
|
||||||
|
m_latestVersionBeta(CProject::version()),
|
||||||
|
m_lastSupportedVersionBeta("0.6")
|
||||||
|
{ }
|
||||||
|
|
||||||
|
CUrlList CDownload::getDownloadUrls() const
|
||||||
|
{
|
||||||
|
return CProject::isBetaTest() ? getDownloadUrlsBeta() : getDownloadUrlsStable();
|
||||||
|
}
|
||||||
|
|
||||||
|
QString CDownload::getLatestVersion() const
|
||||||
|
{
|
||||||
|
return CProject::isBetaTest() ? getLatestVersionBeta() : getLatestVersionStable();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CDownload::hasSameType(const CDownload &otherDownload) const
|
||||||
|
{
|
||||||
|
return this->isDevelopment() == otherDownload.isDevelopment();
|
||||||
|
}
|
||||||
|
|
||||||
|
QString CDownload::convertToQString(bool i18n) const
|
||||||
|
{
|
||||||
|
return convertToQString(", ", i18n);
|
||||||
|
}
|
||||||
|
|
||||||
|
QString CDownload::convertToQString(const QString &separator, bool i18n) const
|
||||||
|
{
|
||||||
|
QString s("timestamp: ");
|
||||||
|
s.append(this->getFormattedUtcTimestampYmdhms());
|
||||||
|
s.append(separator);
|
||||||
|
s.append("Download URLs (stable): ");
|
||||||
|
s.append(getDownloadUrlsStable().toQString(i18n));
|
||||||
|
s.append(separator);
|
||||||
|
s.append("Download URLs (beta): ");
|
||||||
|
s.append(getDownloadUrlsBeta().toQString(i18n));
|
||||||
|
s.append(separator);
|
||||||
|
s.append("Latest version (stable): ");
|
||||||
|
s.append(getLatestVersionStable());
|
||||||
|
s.append(separator);
|
||||||
|
s.append("Latest version (beta): ");
|
||||||
|
s.append(getLatestVersionBeta());
|
||||||
|
s.append(separator);
|
||||||
|
s.append("Latest supported version (stable): ");
|
||||||
|
s.append(getLastSupportedVersionStable());
|
||||||
|
s.append(separator);
|
||||||
|
s.append("Latest supported version (beta): ");
|
||||||
|
s.append(getLastSupportedVersionBeta());
|
||||||
|
s.append(separator);
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
CVariant CDownload::propertyByIndex(const BlackMisc::CPropertyIndex &index) const
|
||||||
|
{
|
||||||
|
if (index.isMyself()) { return CVariant::from(*this); }
|
||||||
|
if (ITimestampBased::canHandleIndex(index)) { return ITimestampBased::propertyByIndex(index); }
|
||||||
|
|
||||||
|
ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||||
|
switch (i)
|
||||||
|
{
|
||||||
|
case IndexDownloadUrlsStable:
|
||||||
|
return CVariant::fromValue(this->m_downloadsStableUrls);
|
||||||
|
case IndexDownloadUrlsBeta:
|
||||||
|
return CVariant::fromValue(this->m_downloadsBetaUrls);
|
||||||
|
case IndexLastSupportedVersionStable:
|
||||||
|
return CVariant::fromValue(this->m_lastSupportedVersionStable);
|
||||||
|
case IndexLatestVersionStable:
|
||||||
|
return CVariant::fromValue(this->m_latestVersionStable);
|
||||||
|
case IndexLastSupportedVersionBeta:
|
||||||
|
return CVariant::fromValue(this->m_lastSupportedVersionBeta);
|
||||||
|
case IndexLatestVersionBeta:
|
||||||
|
return CVariant::fromValue(this->m_latestVersionBeta);
|
||||||
|
default:
|
||||||
|
return CValueObject::propertyByIndex(index);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CDownload::setPropertyByIndex(const CVariant &variant, const BlackMisc::CPropertyIndex &index)
|
||||||
|
{
|
||||||
|
if (index.isMyself()) { (*this) = variant.to<CDownload>(); return; }
|
||||||
|
if (ITimestampBased::canHandleIndex(index))
|
||||||
|
{
|
||||||
|
ITimestampBased::setPropertyByIndex(variant, index);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||||
|
switch (i)
|
||||||
|
{
|
||||||
|
case IndexDownloadUrlsStable:
|
||||||
|
this->m_downloadsStableUrls = variant.value<CUrlList>();
|
||||||
|
break;
|
||||||
|
case IndexDownloadUrlsBeta:
|
||||||
|
this->m_downloadsBetaUrls = variant.value<CUrlList>();
|
||||||
|
break;
|
||||||
|
case IndexLastSupportedVersionStable:
|
||||||
|
this->m_lastSupportedVersionStable = variant.toQString();
|
||||||
|
break;
|
||||||
|
case IndexLatestVersionStable:
|
||||||
|
this->m_latestVersionStable = variant.toQString();
|
||||||
|
break;
|
||||||
|
case IndexLastSupportedVersionBeta:
|
||||||
|
this->m_lastSupportedVersionBeta = variant.toQString();
|
||||||
|
break;
|
||||||
|
case IndexLatestVersionBeta:
|
||||||
|
this->m_latestVersionBeta = variant.toQString();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
CValueObject::setPropertyByIndex(variant, index);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} // ns
|
||||||
|
} // ns
|
||||||
133
src/blackcore/data/download.h
Normal file
133
src/blackcore/data/download.h
Normal file
@@ -0,0 +1,133 @@
|
|||||||
|
/* Copyright (C) 2015
|
||||||
|
* 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 BLACKCORE_DATA_DOWNLOAD_H
|
||||||
|
#define BLACKCORE_DATA_DOWNLOAD_H
|
||||||
|
|
||||||
|
#include "blackcore/blackcoreexport.h"
|
||||||
|
#include "blackcore/datacache.h"
|
||||||
|
#include "blackmisc/network/urllist.h"
|
||||||
|
#include "blackmisc/valueobject.h"
|
||||||
|
#include "blackmisc/variant.h"
|
||||||
|
|
||||||
|
namespace BlackCore
|
||||||
|
{
|
||||||
|
namespace Data
|
||||||
|
{
|
||||||
|
//! Download locations and versions
|
||||||
|
class BLACKCORE_EXPORT CDownload :
|
||||||
|
public BlackMisc::CValueObject<CDownload>,
|
||||||
|
public BlackMisc::ITimestampBased
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
//! Properties by index
|
||||||
|
enum ColumnIndex
|
||||||
|
{
|
||||||
|
IndexDownloadUrlsStable = BlackMisc::CPropertyIndex::GlobalIndexCDownload,
|
||||||
|
IndexDownloadUrlsBeta,
|
||||||
|
IndexLatestVersionStable,
|
||||||
|
IndexLastSupportedVersionStable,
|
||||||
|
IndexLatestVersionBeta,
|
||||||
|
IndexLastSupportedVersionBeta
|
||||||
|
};
|
||||||
|
|
||||||
|
//! Default constructor
|
||||||
|
CDownload();
|
||||||
|
|
||||||
|
//! Destructor.
|
||||||
|
~CDownload() {}
|
||||||
|
|
||||||
|
//! Download URLs, ie here one can download installer
|
||||||
|
const BlackMisc::Network::CUrlList &getDownloadUrlsBeta() const { return m_downloadsBetaUrls; }
|
||||||
|
|
||||||
|
//! Download URLs, ie here one can download installer
|
||||||
|
const BlackMisc::Network::CUrlList &getDownloadUrlsStable() const { return m_downloadsStableUrls; }
|
||||||
|
|
||||||
|
//! Download URLs
|
||||||
|
BlackMisc::Network::CUrlList getDownloadUrls() const;
|
||||||
|
|
||||||
|
//! Latest version stable channel
|
||||||
|
const QString &getLatestVersionStable() const { return m_latestVersionStable; }
|
||||||
|
|
||||||
|
//! Latest version beta channel
|
||||||
|
const QString &getLatestVersionBeta() const { return m_latestVersionBeta; }
|
||||||
|
|
||||||
|
//! Latest version
|
||||||
|
QString getLatestVersion() const;
|
||||||
|
|
||||||
|
//! Last supported version stable
|
||||||
|
const QString &getLastSupportedVersionStable() const { return m_lastSupportedVersionStable; }
|
||||||
|
|
||||||
|
//! Last supported version beta
|
||||||
|
const QString &getLastSupportedVersionBeta() const { return m_lastSupportedVersionStable; }
|
||||||
|
|
||||||
|
//! Productive settings?
|
||||||
|
bool isDevelopment() const { return m_development; }
|
||||||
|
|
||||||
|
//! Same type
|
||||||
|
bool hasSameType(const CDownload &otherDownload) const;
|
||||||
|
|
||||||
|
//! Productive settings?
|
||||||
|
void setDevelopment(bool development) { m_development = development; }
|
||||||
|
|
||||||
|
//! \copydoc CValueObject::convertToQString
|
||||||
|
QString convertToQString(bool i18n = false) const;
|
||||||
|
|
||||||
|
//! To string
|
||||||
|
QString convertToQString(const QString &separator, bool i18n = false) const;
|
||||||
|
|
||||||
|
//! \copydoc CValueObject::propertyByIndex
|
||||||
|
BlackMisc::CVariant propertyByIndex(const BlackMisc::CPropertyIndex &index) const;
|
||||||
|
|
||||||
|
//! \copydoc CValueObject::setPropertyByIndex
|
||||||
|
void setPropertyByIndex(const BlackMisc::CVariant &variant, const BlackMisc::CPropertyIndex &index);
|
||||||
|
|
||||||
|
private:
|
||||||
|
BLACK_ENABLE_TUPLE_CONVERSION(BlackCore::Data::CDownload)
|
||||||
|
|
||||||
|
bool m_development = false; //!< for development
|
||||||
|
BlackMisc::Network::CUrlList m_downloadsStableUrls; //!< Download URLs, here I get the installer
|
||||||
|
BlackMisc::Network::CUrlList m_downloadsBetaUrls; //!< Download URLs, here I get the installer
|
||||||
|
QString m_latestVersionStable; //!< latest version
|
||||||
|
QString m_lastSupportedVersionStable; //!< last supported version
|
||||||
|
QString m_latestVersionBeta; //!< latest version
|
||||||
|
QString m_lastSupportedVersionBeta; //!< last supported version
|
||||||
|
};
|
||||||
|
|
||||||
|
//! Trait for global setup data
|
||||||
|
struct Download : public BlackCore::CDataTrait<CDownload>
|
||||||
|
{
|
||||||
|
//! Key in data cache
|
||||||
|
static const char *key() { return "readers/global/download"; }
|
||||||
|
|
||||||
|
//! Default value
|
||||||
|
static const CDownload &defaultValue()
|
||||||
|
{
|
||||||
|
static const CDownload defaultValue;
|
||||||
|
return defaultValue;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
} // ns
|
||||||
|
} // ns
|
||||||
|
|
||||||
|
Q_DECLARE_METATYPE(BlackCore::Data::CDownload)
|
||||||
|
BLACK_DECLARE_TUPLE_CONVERSION(BlackCore::Data::CDownload, (
|
||||||
|
attr(o.m_timestampMSecsSinceEpoch),
|
||||||
|
attr(o.m_development),
|
||||||
|
attr(o.m_downloadsStableUrls),
|
||||||
|
attr(o.m_downloadsBetaUrls),
|
||||||
|
attr(o.m_latestVersionStable),
|
||||||
|
attr(o.m_lastSupportedVersionStable),
|
||||||
|
attr(o.m_latestVersionBeta),
|
||||||
|
attr(o.m_lastSupportedVersionBeta)
|
||||||
|
))
|
||||||
|
#endif // guard
|
||||||
@@ -89,6 +89,7 @@ namespace BlackMisc
|
|||||||
GlobalIndexIDatastoreInteger = 11000,
|
GlobalIndexIDatastoreInteger = 11000,
|
||||||
GlobalIndexIDatastoreString = 11100,
|
GlobalIndexIDatastoreString = 11100,
|
||||||
GlobalIndexCGlobalSetup = 12000,
|
GlobalIndexCGlobalSetup = 12000,
|
||||||
|
GlobalIndexCDownload = 12100,
|
||||||
GlobalIndexAbuseMode = 20000 // property index abused as map key or otherwise, to be removed if no longer needed
|
GlobalIndexAbuseMode = 20000 // property index abused as map key or otherwise, to be removed if no longer needed
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user