Skip to content

Commit

Permalink
Don't detach iconsets
Browse files Browse the repository at this point in the history
some iconsets always have ref count=2. so we had undesireiable detaches. for example in avatars cache
  • Loading branch information
Ri0n committed Oct 12, 2024
1 parent ed7e135 commit 32ac661
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
1 change: 1 addition & 0 deletions src/avatars.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,7 @@ class AvatarCache : public FileCache {
AvatarCache() : FileCache(AvatarFactory::getCacheDir())
{
// Register iconset
iconset_.setName(QLatin1String("Avatars"));
iconset_.addToFactory(); // the factory will own the iconset
updateJids();

Expand Down
19 changes: 12 additions & 7 deletions src/tools/iconset/iconset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1530,14 +1530,14 @@ Iconset &Iconset::operator=(const Iconset &from)
// return is;
// }

void Iconset::detach() { d.detach(); }
// void Iconset::detach() { d.detach(); }

/**
* Appends icons from Iconset \a from to this Iconset.
*/
Iconset &Iconset::operator+=(const Iconset &i)
{
detach();
// detach();

QListIterator<PsiIcon *> it(i.d->list);
while (it.hasNext()) {
Expand All @@ -1553,7 +1553,7 @@ Iconset &Iconset::operator+=(const Iconset &i)
*/
void Iconset::clear()
{
detach();
// detach();

d->clear();
}
Expand All @@ -1576,7 +1576,7 @@ bool Iconset::load(const QString &dir, Format format)
}
Q_ASSERT(!dir.isEmpty());

detach();
// detach();

// make it run okay on windows 9.x (where the pixmap memory is limited)
// QPixmap::Optimization optimization = QPixmap::defaultOptimization();
Expand Down Expand Up @@ -1642,7 +1642,7 @@ const PsiIcon *Iconset::icon(const QString &name) const
*/
void Iconset::setIcon(const QString &name, const PsiIcon &icon)
{
detach();
// detach();

PsiIcon *newIcon = new PsiIcon(icon);

Expand All @@ -1655,7 +1655,7 @@ void Iconset::setIcon(const QString &name, const PsiIcon &icon)
*/
void Iconset::removeIcon(const QString &name)
{
detach();
// detach();

d->remove(name);
}
Expand All @@ -1670,6 +1670,11 @@ const QString &Iconset::id() const { return d->id; }
*/
const QString &Iconset::name() const { return d->name; }

/**
* Sets Iconset name (used for dynamic iconsets).
*/
void Iconset::setName(const QString &name) { d->name = name; }

/**
* Returns the icons size from Iconset.
*/
Expand Down Expand Up @@ -1725,7 +1730,7 @@ void Iconset::setFileName(const QString &f) { d->filename = f; }
*/
void Iconset::setInformation(const Iconset &from)
{
detach();
// detach();
d->setInformation(*(from.d));
}

Expand Down
9 changes: 6 additions & 3 deletions src/tools/iconset/iconset.h
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,11 @@ class Iconset {
void setIcon(const QString &, const PsiIcon &);
void removeIcon(const QString &);

const QString &id() const;
const QString &name() const;
const QString &id() const;

const QString &name() const;
void setName(const QString &name);

const QString &version() const;
const QString &description() const;
const QStringList &authors() const;
Expand All @@ -231,7 +234,7 @@ class Iconset {
static void setSoundPrefs(QString unpackPath, QObject *receiver, const char *slot);

// Iconset copy() const;
void detach();
// void detach();

private:
class Private;
Expand Down

0 comments on commit 32ac661

Please sign in to comment.