Commit 617ea7bb authored by chriadam's avatar chriadam

Merge branch 'jb44742-fixes' into 'master'

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

See merge request mer-core/qtcontacts-sqlite!17
parents 3959d169 367e4b50
......@@ -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