Commit 1313d641 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Fix recent tab when we have several composer opened

parent 008ea3de
Pipeline #81672 passed with stage
in 7 minutes and 14 seconds
......@@ -10,35 +10,16 @@
#include <KConfigGroup>
#include <KSharedConfig>
namespace
{
static const char myEmoticonRecentUsedFilterProxyModelGroupName[] = "EmoticonRecentUsed";
}
using namespace KPIMTextEdit;
EmoticonRecentUsedFilterProxyModel::EmoticonRecentUsedFilterProxyModel(QObject *parent)
: QSortFilterProxyModel(parent)
{
loadRecentUsed();
}
EmoticonRecentUsedFilterProxyModel::~EmoticonRecentUsedFilterProxyModel()
{
writeRecentUsed();
}
void EmoticonRecentUsedFilterProxyModel::loadRecentUsed()
{
KConfigGroup group(KSharedConfig::openConfig(), myEmoticonRecentUsedFilterProxyModelGroupName);
const QStringList recentUsed = group.readEntry("Recents", QStringList());
setUsedIdentifier(recentUsed);
}
void EmoticonRecentUsedFilterProxyModel::writeRecentUsed()
{
KConfigGroup group(KSharedConfig::openConfig(), myEmoticonRecentUsedFilterProxyModelGroupName);
group.writeEntry("Recents", mUsedIdentifier);
group.sync();
}
QStringList EmoticonRecentUsedFilterProxyModel::usedIdentifier() const
{
......@@ -49,20 +30,8 @@ void EmoticonRecentUsedFilterProxyModel::setUsedIdentifier(const QStringList &us
{
if (mUsedIdentifier != usedIdentifier) {
mUsedIdentifier = usedIdentifier;
writeRecentUsed();
invalidateFilter();
}
Q_EMIT usedIdentifierChanged(!mUsedIdentifier.isEmpty());
}
void EmoticonRecentUsedFilterProxyModel::addIdentifier(const QString &identifier)
{
if (!mUsedIdentifier.contains(identifier)) {
mUsedIdentifier.append(identifier);
writeRecentUsed();
invalidateFilter();
}
Q_EMIT usedIdentifierChanged(!mUsedIdentifier.isEmpty());
}
bool EmoticonRecentUsedFilterProxyModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const
......
......@@ -20,18 +20,10 @@ public:
Q_REQUIRED_RESULT QStringList usedIdentifier() const;
void setUsedIdentifier(const QStringList &usedIdentifier);
void addIdentifier(const QString &identifier);
void loadRecentUsed();
protected:
bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const override;
Q_SIGNALS:
void usedIdentifierChanged(bool isNotEmpty);
private:
void writeRecentUsed();
QStringList mUsedIdentifier;
};
}
......@@ -6,16 +6,25 @@
#include "emoticonunicodemodelmanager.h"
#include "emoticonunicodemodel.h"
#include <KConfigGroup>
#include <ksharedconfig.h>
using namespace KPIMTextEdit;
namespace
{
static const char myEmoticonRecentUsedGroupName[] = "EmoticonRecentUsed";
}
EmoticonUnicodeModelManager::EmoticonUnicodeModelManager(QObject *parent)
: QObject(parent)
, mEmoticonUnicodeModel(new EmoticonUnicodeModel(this))
{
mEmoticonUnicodeModel->setEmoticonList(EmoticonUnicodeUtils::allUnicode());
loadRecentUsed();
}
EmoticonUnicodeModelManager::~EmoticonUnicodeModelManager()
{
writeRecentUsed();
}
EmoticonUnicodeModelManager *EmoticonUnicodeModelManager::self()
......@@ -28,3 +37,36 @@ EmoticonUnicodeModel *EmoticonUnicodeModelManager::emoticonUnicodeModel() const
{
return mEmoticonUnicodeModel;
}
const QStringList &EmoticonUnicodeModelManager::recentIdentifier() const
{
return mRecentIdentifier;
}
void EmoticonUnicodeModelManager::setRecentIdentifier(const QStringList &newRecentIdentifier)
{
mRecentIdentifier = newRecentIdentifier;
Q_EMIT usedIdentifierChanged(mRecentIdentifier);
}
void EmoticonUnicodeModelManager::addIdentifier(const QString &identifier)
{
if (!mRecentIdentifier.contains(identifier)) {
mRecentIdentifier.append(identifier);
writeRecentUsed();
}
Q_EMIT usedIdentifierChanged(mRecentIdentifier);
}
void EmoticonUnicodeModelManager::loadRecentUsed()
{
KConfigGroup group(KSharedConfig::openConfig(), myEmoticonRecentUsedGroupName);
mRecentIdentifier = group.readEntry("Recents", QStringList());
}
void EmoticonUnicodeModelManager::writeRecentUsed()
{
KConfigGroup group(KSharedConfig::openConfig(), myEmoticonRecentUsedGroupName);
group.writeEntry("Recents", mRecentIdentifier);
group.sync();
}
......@@ -19,7 +19,17 @@ public:
static EmoticonUnicodeModelManager *self();
Q_REQUIRED_RESULT EmoticonUnicodeModel *emoticonUnicodeModel() const;
Q_REQUIRED_RESULT const QStringList &recentIdentifier() const;
void setRecentIdentifier(const QStringList &newRecentIdentifier);
void addIdentifier(const QString &identifier);
Q_SIGNALS:
void usedIdentifierChanged(const QStringList &lst);
private:
EmoticonUnicodeModel *const mEmoticonUnicodeModel;
QStringList mRecentIdentifier;
void loadRecentUsed();
void writeRecentUsed();
};
}
......@@ -26,7 +26,7 @@ EmoticonUnicodeTab::EmoticonUnicodeTab(QWidget *parent)
f.setPointSize(22);
f.setFamily(QStringLiteral("NotoColorEmoji"));
setFont(f);
connect(mEmoticonUnicodeRecentProxyModel, &EmoticonRecentUsedFilterProxyModel::usedIdentifierChanged, this, &EmoticonUnicodeTab::slotUsedIdentifierChanged);
connect(EmoticonUnicodeModelManager::self(), &EmoticonUnicodeModelManager::usedIdentifierChanged, this, &EmoticonUnicodeTab::slotUsedIdentifierChanged);
}
EmoticonUnicodeTab::~EmoticonUnicodeTab()
......@@ -126,17 +126,19 @@ void EmoticonUnicodeTab::loadEmoticons()
createEmoticonTab(i18n("Dishware"), EmoticonUnicodeUtils::unicodeDishwareEmoji());
createEmoticonTab(i18n("Hotel"), EmoticonUnicodeUtils::unicodeHotelEmoji());
createEmoticonTab(i18n("Award-Medal"), EmoticonUnicodeUtils::unicodeAwardMedalEmoji());
mEmoticonUnicodeRecentProxyModel->setUsedIdentifier(EmoticonUnicodeModelManager::self()->recentIdentifier());
setTabVisible(mSearchTabIndex, false);
setTabVisible(mRecentTabIndex, !mEmoticonUnicodeRecentProxyModel->usedIdentifier().isEmpty());
}
void EmoticonUnicodeTab::slotInsertEmoticons(const QString &identifier)
{
mEmoticonUnicodeRecentProxyModel->addIdentifier(identifier);
EmoticonUnicodeModelManager::self()->addIdentifier(identifier);
Q_EMIT itemSelected(identifier);
}
void EmoticonUnicodeTab::slotUsedIdentifierChanged(bool show)
void EmoticonUnicodeTab::slotUsedIdentifierChanged(const QStringList &lst)
{
setTabVisible(mRecentTabIndex, show);
mEmoticonUnicodeRecentProxyModel->setUsedIdentifier(lst);
setTabVisible(mRecentTabIndex, !lst.empty());
}
......@@ -37,7 +37,7 @@ private:
void createSearchTab();
void createRecentTab();
void slotInsertEmoticons(const QString &identifier);
void slotUsedIdentifierChanged(bool show);
void slotUsedIdentifierChanged(const QStringList &lst);
EmoticonUnicodeProxyModel *const mEmoticonUnicodeSearchProxyModel;
EmoticonRecentUsedFilterProxyModel *const mEmoticonUnicodeRecentProxyModel;
int mSearchTabIndex = -1;
......
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