Commit 367e4b50 authored by chriadam's avatar chriadam

[qtcontacts-sqlite] Improve DLG plugin interface. Contributes to JB#44742

This commit improves the display label group plugin interface by
allowing plugins to report whether the specified locale is a
preferred locale for them, rather than merely valid, as some
plugins may work in multiple locales but should be preferentially
used (e.g. to determine the default display label groups) for
a subset of those locales.

For example, a pinyin grouping plugin might be valid in all locales
but preferred in locales which use Simplified Han writing script.

The database now populates the "default" supported display label
groups from the highest priority preferred plugin rather than
the highest priority valid plugin (falling back to highest priority
valid plugin if no preferred plugins exist for the current locale).
parent 7b785aa5
......@@ -3553,9 +3553,21 @@ QStringList ContactsDatabase::displayLabelGroups() const
QStringList groups;
const QLocale locale;
for (int i = 0; i < m_dlgGenerators.size(); ++i) {
if (m_dlgGenerators.at(i)->validForLocale(locale)) {
if (m_dlgGenerators.at(i)->preferredForLocale(locale)) {
groups = m_dlgGenerators.at(i)->displayLabelGroups();
break;
if (!groups.isEmpty()) {
break;
}
}
}
if (groups.isEmpty()) {
for (int i = 0; i < m_dlgGenerators.size(); ++i) {
if (m_dlgGenerators.at(i)->validForLocale(locale)) {
groups = m_dlgGenerators.at(i)->displayLabelGroups();
if (!groups.isEmpty()) {
break;
}
}
}
}
......
......@@ -75,9 +75,14 @@ int DefaultDlgGenerator::priority() const
return 0;
}
bool DefaultDlgGenerator::preferredForLocale(const QLocale &) const
{
return false; // this default plugin is the fallback, never preferred but always valid.
}
bool DefaultDlgGenerator::validForLocale(const QLocale &) const
{
return true; // this default plugin is the fallback, and always valid.
return true; // this default plugin is the fallback, always valid.
}
QStringList DefaultDlgGenerator::displayLabelGroups() const
......
......@@ -45,6 +45,7 @@ public:
QString name() const Q_DECL_OVERRIDE;
int priority() const Q_DECL_OVERRIDE;
bool validForLocale(const QLocale &locale) const Q_DECL_OVERRIDE;
bool preferredForLocale(const QLocale &locale) const Q_DECL_OVERRIDE;
QString displayLabelGroup(const QString &data) const Q_DECL_OVERRIDE;
QStringList displayLabelGroups() const Q_DECL_OVERRIDE;
};
......
......@@ -56,6 +56,7 @@ public:
virtual ~DisplayLabelGroupGenerator() {}
virtual QString name() const = 0;
virtual int priority() const = 0; // higher priority will be used before lower priority when generating label groups.
virtual bool preferredForLocale(const QLocale &locale) const = 0;
virtual bool validForLocale(const QLocale &locale) const = 0;
virtual QString displayLabelGroup(const QString &data) const = 0;
virtual QStringList displayLabelGroups() const = 0;
......
......@@ -63,9 +63,13 @@ int TestDlgg::priority() const
return 1; // test plugin has slightly higher than the default/fallback.
}
bool TestDlgg::validForLocale(const QLocale &locale) const
bool TestDlgg::preferredForLocale(const QLocale &) const
{
return true; // this test plugin is always "preferred".
}
bool TestDlgg::validForLocale(const QLocale &) const
{
Q_UNUSED(locale)
return true; // this test plugin is always "valid".
}
......
......@@ -45,6 +45,7 @@ public:
TestDlgg(QObject *parent = Q_NULLPTR);
QString name() const Q_DECL_OVERRIDE;
int priority() const Q_DECL_OVERRIDE;
bool preferredForLocale(const QLocale &locale) const Q_DECL_OVERRIDE;
bool validForLocale(const QLocale &locale) const Q_DECL_OVERRIDE;
QString displayLabelGroup(const QString &data) const Q_DECL_OVERRIDE;
QStringList displayLabelGroups() const Q_DECL_OVERRIDE;
......
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