Commit 34ffffc6 authored by Vitaly Fanaskov's avatar Vitaly Fanaskov Committed by Volker Krause

Rename method name() to id()

Summary:
This makes sense because a string returned by this method is literally a
unique identifier that can be used either on a server side to identify a
data source or in an app itself for a lot of different purposes, e.g.,
for mapping data sources or performing some fast lookup by ID.
A method for getting a short user-visible name will be introduced in one
of the further revisions.

Reviewers: vkrause

Differential Revision: https://phabricator.kde.org/D19727
parent 975f7946
......@@ -29,10 +29,11 @@ AbstractDataSourcePrivate::~AbstractDataSourcePrivate()
{
}
AbstractDataSource::AbstractDataSource(const QString &name, Provider::TelemetryMode mode, AbstractDataSourcePrivate* dd) :
d_ptr(dd ? dd : new AbstractDataSourcePrivate)
AbstractDataSource::AbstractDataSource(const QString &id, Provider::TelemetryMode mode,
AbstractDataSourcePrivate* dd)
: d_ptr(dd ? dd : new AbstractDataSourcePrivate)
{
d_ptr->name = name;
d_ptr->id = id;
d_ptr->mode = mode;
}
......@@ -41,14 +42,14 @@ AbstractDataSource::~AbstractDataSource()
delete d_ptr;
}
QString AbstractDataSource::name() const
QString AbstractDataSource::id() const
{
return d_ptr->name;
return d_ptr->id;
}
void AbstractDataSource::setName(const QString& name)
void AbstractDataSource::setId(const QString& id)
{
d_ptr->name = name;
d_ptr->id = id;
}
void AbstractDataSource::load(QSettings *settings)
......
......@@ -37,17 +37,17 @@ class KUSERFEEDBACKCORE_EXPORT AbstractDataSource
public:
virtual ~AbstractDataSource();
/*! Returns the name of this data source.
/*! Returns the ID of this data source.
* This is used as identifier towards the server and should
* not be shown to the user.
* @see description()
* @returns The data source identifier configured on the feedback server.
*/
QString name() const;
QString id() const;
/*! Returns a human-readable, translated description of what
* this source provides.
* @see name()
* @see id()
* @returns A translated, human-readable string.
*/
virtual QString description() const = 0;
......@@ -112,14 +112,16 @@ protected:
* @param name Must not be empty.
* @param mode The default telemetry mode.
*/
explicit AbstractDataSource(const QString &name, Provider::TelemetryMode mode = Provider::DetailedUsageStatistics, AbstractDataSourcePrivate *dd = nullptr);
explicit AbstractDataSource(const QString &id,
Provider::TelemetryMode mode = Provider::DetailedUsageStatistics,
AbstractDataSourcePrivate *dd = nullptr);
/*! Set the name of this data source.
* The name should not change at runtime, this is only provided
/*! Set the ID of this data source.
* The ID should not change at runtime, this is only provided
* for enabling QML API for generic sources.
* @see name()
* @see id()
*/
void setName(const QString &name);
void setId(const QString &id);
///@cond internal
class AbstractDataSourcePrivate* const d_ptr;
......
......@@ -28,7 +28,7 @@ public:
AbstractDataSourcePrivate();
virtual ~AbstractDataSourcePrivate();
QString name;
QString id;
Provider::TelemetryMode mode;
private:
......
......@@ -77,7 +77,7 @@ public:
void store(QSettings *settings) override;
void reset(QSettings *settings) override;
using AbstractDataSource::setName;
using AbstractDataSource::setId;
private:
Q_DECLARE_PRIVATE(PropertyRatioSource)
};
......
......@@ -146,7 +146,7 @@ void ProviderPrivate::load()
s->endGroup();
foreach (auto source, dataSources) {
s->beginGroup(QStringLiteral("Source-") + source->name());
s->beginGroup(QStringLiteral("Source-") + source->id());
source->load(s.get());
s->endGroup();
}
......@@ -171,7 +171,7 @@ void ProviderPrivate::store()
s->endGroup();
foreach (auto source, dataSources) {
s->beginGroup(QStringLiteral("Source-") + source->name());
s->beginGroup(QStringLiteral("Source-") + source->id());
source->store(s.get());
s->endGroup();
}
......@@ -198,20 +198,20 @@ void ProviderPrivate::aboutToQuit()
bool ProviderPrivate::isValidSource(AbstractDataSource *source) const
{
if (source->name().isEmpty()) {
if (source->id().isEmpty()) {
qCWarning(Log) << "Skipping data source with empty name!";
return false;
}
if (source->telemetryMode() == Provider::NoTelemetry) {
qCWarning(Log) << "Source" << source->name() << "attempts to report data unconditionally, ignoring!";
qCWarning(Log) << "Source" << source->id() << "attempts to report data unconditionally, ignoring!";
return false;
}
if (source->description().isEmpty()) {
qCWarning(Log) << "Source" << source->name() << "has no description, ignoring!";
qCWarning(Log) << "Source" << source->id() << "has no description, ignoring!";
return false;
}
Q_ASSERT(!source->name().isEmpty());
Q_ASSERT(!source->id().isEmpty());
Q_ASSERT(source->telemetryMode() != Provider::NoTelemetry);
Q_ASSERT(!source->description().isEmpty());
return true;
......@@ -228,11 +228,11 @@ QByteArray ProviderPrivate::jsonData(Provider::TelemetryMode mode) const
continue;
const auto data = source->data();
if (data.canConvert<QVariantMap>())
obj.insert(source->name(), QJsonObject::fromVariantMap(data.toMap()));
obj.insert(source->id(), QJsonObject::fromVariantMap(data.toMap()));
else if (data.canConvert<QVariantList>())
obj.insert(source->name(), QJsonArray::fromVariantList(data.value<QVariantList>()));
obj.insert(source->id(), QJsonArray::fromVariantList(data.value<QVariantList>()));
else
qCWarning(Log) << "wrong type for" << source->name() << data;
qCWarning(Log) << "wrong type for" << source->id() << data;
}
}
......@@ -285,7 +285,7 @@ void ProviderPrivate::submitFinished(QNetworkReply *reply)
// reset source counters
foreach (auto source, dataSources) {
s->beginGroup(QStringLiteral("Source-") + source->name());
s->beginGroup(QStringLiteral("Source-") + source->id());
source->reset(s.get());
s->endGroup();
}
......@@ -305,10 +305,10 @@ void ProviderPrivate::submitFinished(QNetworkReply *reply)
scheduleNextSubmission();
}
QVariant ProviderPrivate::sourceData(const QString& sourceName) const
QVariant ProviderPrivate::sourceData(const QString& sourceId) const
{
foreach (auto src, dataSources) {
if (src->name() == sourceName)
if (src->id() == sourceId)
return src->data();
}
return QVariant();
......@@ -506,7 +506,7 @@ void Provider::addDataSource(AbstractDataSource *source)
d->dataSources.push_back(source);
auto s = d->makeSettings();
s->beginGroup(QStringLiteral("Source-") + source->name());
s->beginGroup(QStringLiteral("Source-") + source->id());
source->load(s.get());
}
......@@ -687,7 +687,7 @@ void ProviderPrivate::writeAuditLog(const QDateTime &dt)
continue;
obj.insert(QLatin1String("telemetryMode"), QString::fromLatin1(telemetryModeEnum().valueToKey(source->telemetryMode())));
obj.insert(QLatin1String("description"), source->description());
docObj.insert(source->name(), obj);
docObj.insert(source->id(), obj);
}
QFile file(path + QLatin1Char('/') + dt.toString(QStringLiteral("yyyyMMdd-hhmmss")) + QStringLiteral(".log"));
......
......@@ -70,7 +70,7 @@ public:
void writeAuditLog(const QDateTime &dt);
QVariant sourceData(const QString &sourceName) const override;
QVariant sourceData(const QString &sourceId) const override;
Provider *q;
......
......@@ -35,16 +35,16 @@ PropertyRatioSource* QmlPropertyRatioSource::prSrc() const
return static_cast<PropertyRatioSource*>(source());
}
QString QmlPropertyRatioSource::name() const
QString QmlPropertyRatioSource::id() const
{
return source()->name();
return source()->id();
}
void QmlPropertyRatioSource::setName(const QString& name)
void QmlPropertyRatioSource::setId(const QString& id)
{
if (source()->name() == name)
if (source()->id() == id)
return;
prSrc()->setName(name);
prSrc()->setId(id);
emit changed();
}
......
......@@ -27,7 +27,7 @@ class PropertyRatioSource;
class QmlPropertyRatioSource : public QmlAbstractDataSource
{
Q_OBJECT
Q_PROPERTY(QString name READ name WRITE setName NOTIFY changed)
Q_PROPERTY(QString id READ id WRITE setId NOTIFY changed)
Q_PROPERTY(QString description READ description WRITE setDescription NOTIFY changed)
Q_PROPERTY(QObject* object READ object WRITE setObject NOTIFY changed)
Q_PROPERTY(QString propertyName READ propertyName WRITE setPropertyName NOTIFY changed)
......@@ -35,8 +35,8 @@ public:
explicit QmlPropertyRatioSource(QObject *parent = nullptr);
~QmlPropertyRatioSource();
QString name() const;
void setName(const QString &name);
QString id() const;
void setId(const QString &id);
QString description() const;
void setDescription(const QString &desc);
......
......@@ -28,7 +28,7 @@ public:
QVariant data() override { return m_data; }
QString description() const override { return m_description; }
void setSourceName(const QString &name) { setName(name); }
void setSourceId(const QString &id) { setId(id); }
QVariant m_data;
QString m_description;
......@@ -49,9 +49,9 @@ QString QmlPropertySource::description() const
return source()->description();
}
QString QmlPropertySource::name() const
QString QmlPropertySource::id() const
{
return source()->name();
return source()->id();
}
void KUserFeedback::QmlPropertySource::setData(const QVariant& data)
......@@ -70,11 +70,11 @@ void KUserFeedback::QmlPropertySource::setDescription(const QString& description
}
}
void KUserFeedback::QmlPropertySource::setName(const QString& name)
void KUserFeedback::QmlPropertySource::setId(const QString& id)
{
if (name != source()->name()) {
customSource()->setSourceName(name);
Q_EMIT nameChanged(name);
if (id != source()->id()) {
customSource()->setSourceId(id);
Q_EMIT idChanged(id);
}
}
......
......@@ -30,22 +30,22 @@ namespace KUserFeedback {
class QmlPropertySource : public QmlAbstractDataSource
{
Q_OBJECT
Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
Q_PROPERTY(QString id READ id WRITE setId NOTIFY idChanged)
Q_PROPERTY(QString description READ description WRITE setDescription NOTIFY descriptionChanged)
Q_PROPERTY(QVariant data READ data WRITE setData NOTIFY dataChanged)
public:
QmlPropertySource(QObject* parent = nullptr);
QString name() const;
QString id() const;
QString description() const;
QVariant data() const;
void setName(const QString &name);
void setId(const QString &id);
void setDescription(const QString &description);
void setData(const QVariant &data);
Q_SIGNALS:
void nameChanged(const QString &name);
void idChanged(const QString &id);
void descriptionChanged(const QString &description);
void dataChanged(const QVariant &data);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment