Commit 5065fd5c authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Allow to define icon

parent 1ae374aa
......@@ -34,6 +34,16 @@ bool Filter::containString(const QString &searchInString) const
return found;
}
const QString &Filter::iconName() const
{
return mIconName;
}
void Filter::setIconName(const QString &newIconName)
{
mIconName = newIconName;
}
void Filter::setOptions(QuickSearchLine::SearchOptions newOptions)
{
mOptions = newOptions;
......@@ -145,12 +155,15 @@ QuickSearchLine::SearchOptions Filter::currentOptions() const
return mOptions;
}
void Filter::save(const KSharedConfig::Ptr &config, const QString &filtername)
void Filter::save(const KSharedConfig::Ptr &config, const QString &filtername, const QString &iconName)
{
KConfigGroup grp(config, "General");
int numberFilter = grp.readEntry("NumberFilter").toInt();
KConfigGroup newGroup(config, QStringLiteral("Filter_%1").arg(numberFilter++));
newGroup.writeEntry("name", filtername);
if (!iconName.isEmpty()) {
newGroup.writeEntry("iconName", iconName);
}
newGroup.writeEntry("searchString", mSearchString);
newGroup.writeEntry("searchOptions", static_cast<int>(mOptions));
newGroup.writeEntry("tagId", mTagId);
......@@ -185,6 +198,7 @@ Filter *Filter::loadFromConfigGroup(const KConfigGroup &newGroup)
filter->setTagId(newGroup.readEntry("tagId"));
filter->setIdentifier(newGroup.readEntry("identifier"));
filter->setFilterName(newGroup.readEntry("name"));
filter->setIconName(newGroup.readEntry("iconName"));
QList<qint32> lst;
lst = newGroup.readEntry("status", QList<qint32>());
QVector<Akonadi::MessageStatus> messageStatusLst;
......
......@@ -91,7 +91,7 @@ public:
Q_REQUIRED_RESULT QuickSearchLine::SearchOptions currentOptions() const;
void save(const KSharedConfig::Ptr &config, const QString &filtername);
void save(const KSharedConfig::Ptr &config, const QString &filtername, const QString &iconName);
static Q_REQUIRED_RESULT Filter *load(const KSharedConfig::Ptr &config, int filternumber);
void generateRandomIdentifier();
Q_REQUIRED_RESULT QString identifier() const;
......@@ -103,6 +103,9 @@ public:
void setOptions(QuickSearchLine::SearchOptions newOptions);
static Q_REQUIRED_RESULT Filter *loadFromConfigGroup(const KConfigGroup &newGroup);
Q_REQUIRED_RESULT const QString &iconName() const;
void setIconName(const QString &newIconName);
Q_SIGNALS:
void finished();
......@@ -117,6 +120,7 @@ private:
QStringList mSearchList;
QString mIdentifier;
QString mFilterName;
QString mIconName;
};
} // namespace Core
} // namespace MessageList
......
......@@ -39,9 +39,9 @@ QStringList FilterSavedManager::existingFilterNames() const
return lst;
}
void FilterSavedManager::saveFilter(MessageList::Core::Filter *filter, const QString &filtername)
void FilterSavedManager::saveFilter(MessageList::Core::Filter *filter, const QString &filtername, const QString &iconName)
{
filter->save(KSharedConfig::openConfig(), filtername);
filter->save(KSharedConfig::openConfig(), filtername, iconName);
}
void FilterSavedManager::loadMenu(QMenu *menu)
......@@ -50,7 +50,8 @@ void FilterSavedManager::loadMenu(QMenu *menu)
const int numberFilter = grp.readEntry("NumberFilter").toInt();
for (int i = 0; i < numberFilter; ++i) {
KConfigGroup newGroup(KSharedConfig::openConfig(), QStringLiteral("Filter_%1").arg(i));
auto act = menu->addAction(newGroup.readEntry(QStringLiteral("name")));
const QString iconName = newGroup.readEntry(QStringLiteral("iconName"));
auto act = menu->addAction(QIcon::fromTheme(iconName), newGroup.readEntry(QStringLiteral("name")));
const QString identifier = newGroup.readEntry(QStringLiteral("identifier"));
connect(act, &QAction::triggered, this, [this, identifier]() {
Q_EMIT activateFilter(identifier);
......@@ -70,6 +71,7 @@ QVector<FilterSavedManager::FilterInfo> FilterSavedManager::filterInfos() const
FilterSavedManager::FilterInfo info;
info.filterName = newGroup.readEntry(QStringLiteral("name"));
info.identifier = newGroup.readEntry(QStringLiteral("identifier"));
info.iconName = newGroup.readEntry(QStringLiteral("iconName"));
lst << info;
}
return lst;
......@@ -107,7 +109,7 @@ void FilterSavedManager::removeFilter(const QString &identifier)
int numberOfFilter = 0;
for (Filter *f : qAsConst(lst)) {
if ((f->identifier() != identifier) && !f->identifier().isEmpty()) {
f->save(KSharedConfig::openConfig(), f->filterName());
f->save(KSharedConfig::openConfig(), f->filterName(), f->iconName());
numberOfFilter++;
}
}
......
......@@ -19,11 +19,12 @@ public:
struct FilterInfo {
QString filterName;
QString identifier;
QString iconName;
};
explicit FilterSavedManager(QObject *parent = nullptr);
~FilterSavedManager() override;
void saveFilter(MessageList::Core::Filter *filter, const QString &filtername);
void saveFilter(MessageList::Core::Filter *filter, const QString &filtername, const QString &iconName);
void loadMenu(QMenu *menu);
Q_REQUIRED_RESULT QVector<FilterInfo> filterInfos() const;
......
......@@ -180,7 +180,7 @@ void Widget::slotSaveFilter()
QPointer<FilterNameDialog> dlg = new FilterNameDialog(this);
dlg->setExistingFilterNames(FilterSavedManager::self()->existingFilterNames());
if (dlg->exec()) {
FilterSavedManager::self()->saveFilter(d->mFilter, dlg->filterName());
FilterSavedManager::self()->saveFilter(d->mFilter, dlg->filterName(), dlg->iconName());
}
delete dlg;
} else {
......
......@@ -42,6 +42,11 @@ QString FilterNameDialog::filterName() const
return mFilterNameWidget->filterName();
}
QString FilterNameDialog::iconName() const
{
return mFilterNameWidget->iconName();
}
void FilterNameDialog::setExistingFilterNames(const QStringList &lst)
{
mFilterNameWidget->setExistingFilterNames(lst);
......
......@@ -25,6 +25,8 @@ public:
void setExistingFilterNames(const QStringList &lst);
Q_REQUIRED_RESULT QString iconName() const;
private:
FilterNameWidget *const mFilterNameWidget;
};
......
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