Commit 47ccd5d9 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Allow to load filter from identifier

parent 24cbb0a6
Pipeline #64608 passed with stage
in 40 minutes and 5 seconds
......@@ -167,19 +167,24 @@ Filter *Filter::load(const KSharedConfig::Ptr &config, int filternumber)
KConfigGroup grp(config, "General");
int numberFilter = grp.readEntry("NumberFilter").toInt();
if (filternumber < numberFilter) {
auto filter = new Filter();
KConfigGroup newGroup(config, QStringLiteral("Filter_%1").arg(filternumber));
filter->setSearchString(newGroup.readEntry("searchString"), static_cast<QuickSearchLine::SearchOptions>(newGroup.readEntry("searchOptions").toInt()));
filter->setCurrentFolder(Akonadi::Collection(newGroup.readEntry("currentFolder").toInt()));
filter->setTagId(newGroup.readEntry("tagId"));
filter->setIdentifier(newGroup.readEntry("identifier"));
filter->setFilterName(newGroup.readEntry("name"));
filter->setOptions(static_cast<QuickSearchLine::SearchOptions>(newGroup.readEntry("searchOptions").toInt()));
return filter;
return loadFromConfigGroup(newGroup);
}
return nullptr;
}
Filter *Filter::loadFromConfigGroup(const KConfigGroup &newGroup)
{
auto filter = new Filter();
filter->setSearchString(newGroup.readEntry("searchString"), static_cast<QuickSearchLine::SearchOptions>(newGroup.readEntry("searchOptions").toInt()));
filter->setCurrentFolder(Akonadi::Collection(newGroup.readEntry("currentFolder").toInt()));
filter->setTagId(newGroup.readEntry("tagId"));
filter->setIdentifier(newGroup.readEntry("identifier"));
filter->setFilterName(newGroup.readEntry("name"));
filter->setOptions(static_cast<QuickSearchLine::SearchOptions>(newGroup.readEntry("searchOptions").toInt()));
return filter;
}
void Filter::setSearchString(const QString &search, QuickSearchLine::SearchOptions options)
{
const QString trimStr = search.trimmed();
......
......@@ -100,6 +100,7 @@ public:
void setOptions(const QuickSearchLine::SearchOptions &newOptions);
static Q_REQUIRED_RESULT Filter *loadFromConfigGroup(const KConfigGroup &newGroup);
Q_SIGNALS:
void finished();
......
......@@ -62,6 +62,19 @@ QVector<FilterSavedManager::FilterInfo> FilterSavedManager::filterInfos() const
return lst;
}
Filter *FilterSavedManager::loadFilter(const QString &identifier)
{
const QStringList list = KSharedConfig::openConfig()->groupList().filter(QRegularExpression(QStringLiteral("Filter_\\d+")));
for (const QString &group : list) {
KConfigGroup newGroup(KSharedConfig::openConfig(), group);
if (newGroup.readEntry("identifier") == identifier) {
Filter *f = Filter::loadFromConfigGroup(newGroup);
return f;
}
}
return {};
}
void FilterSavedManager::removeFilter(const QString &identifier)
{
KConfigGroup grp(KSharedConfig::openConfig(), "General");
......
......@@ -30,6 +30,7 @@ public:
static FilterSavedManager *self();
void removeFilter(const QString &identifier);
Q_REQUIRED_RESULT Filter *loadFilter(const QString &identifier);
Q_SIGNALS:
void activateFilter(const QString &identifier);
};
......
......@@ -125,7 +125,12 @@ void SearchLineStatus::initializeActions()
void SearchLineStatus::slotActivateFilter(const QString &identifier)
{
// TODO
Filter *f = FilterSavedManager::self()->loadFilter(identifier);
if (f) {
Q_EMIT activateFilter(f);
} else {
qCWarning(MESSAGELIST_LOG) << "Impossible to load Filter from identifier :" << identifier;
}
}
void SearchLineStatus::slotConfigureFilters()
......
......@@ -18,6 +18,7 @@ namespace MessageList
namespace Core
{
class FilterSavedMenu;
class Filter;
class MESSAGELIST_TESTS_EXPORT SearchLineStatus : public QLineEdit
{
Q_OBJECT
......@@ -40,6 +41,7 @@ Q_SIGNALS:
void clearButtonClicked();
void forceLostFocus();
void saveFilter(const QString &filterName);
void activateFilter(MessageList::Core::Filter *f);
protected:
void contextMenuEvent(QContextMenuEvent *e) 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