Skip to content
This repository has been archived by the owner on Feb 12, 2023. It is now read-only.

Commit

Permalink
feat(settings): add an option to toggle identicons
Browse files Browse the repository at this point in the history
Solves #4741

Adds a setting to User Interface tab that allows to toggle displaying
identicons instead of default avatar picture.
  • Loading branch information
tox-user committed Nov 21, 2017
1 parent d77fbb4 commit 905ca77
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 11 deletions.
32 changes: 22 additions & 10 deletions src/persistence/profile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -395,11 +395,17 @@ QPixmap Profile::loadAvatar()
QPixmap Profile::loadAvatar(const ToxPk& owner)
{
QPixmap pic;
const QByteArray avataData = loadAvatarData(owner);
if(avataData.isEmpty()) {
pic = QPixmap::fromImage(Identicon(owner.getKey()).toImage(16));
if (Settings::getInstance().getShowIdenticons()) {

const QByteArray avataData = loadAvatarData(owner);
if (avataData.isEmpty()) {
pic = QPixmap::fromImage(Identicon(owner.getKey()).toImage(16));
} else {
pic.loadFromData(avataData);
}

} else {
pic.loadFromData(avataData);
pic.loadFromData(loadAvatarData(owner));
}

return pic;
Expand Down Expand Up @@ -467,12 +473,18 @@ void Profile::setAvatar(QByteArray pic, const ToxPk& owner)
pixmap.loadFromData(pic);
avatarData = pic;
} else {
// with IDENTICON_ROWS=5 this gives a 160x160 image file
const QImage identicon = Identicon(owner.getKey()).toImage(32);
pixmap = QPixmap::fromImage(identicon);
QBuffer buf(&avatarData);
buf.open(QIODevice::WriteOnly);
identicon.save(&buf, "png");
if (Settings::getInstance().getShowIdenticons()) {
// with IDENTICON_ROWS=5 this gives a 160x160 image file
const QImage identicon = Identicon(owner.getKey()).toImage(32);
pixmap = QPixmap::fromImage(identicon);
QBuffer buf(&avatarData);
buf.open(QIODevice::WriteOnly);
identicon.save(&buf, "png");

} else {
pixmap.load(":/img/contact_dark.svg");
}

}

saveAvatar(avatarData, owner);
Expand Down
18 changes: 18 additions & 0 deletions src/persistence/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ void Settings::loadGlobal()
groupchatPosition = s.value("groupchatPosition", true).toBool();
separateWindow = s.value("separateWindow", false).toBool();
dontGroupWindows = s.value("dontGroupWindows", false).toBool();
showIdenticons = s.value("showIdenticons", true).toBool();

const QString DEFAULT_SMILEYS = ":/smileys/emojione/emoticons.xml";
smileyPack = s.value("smileyPack", DEFAULT_SMILEYS).toString();
Expand Down Expand Up @@ -526,6 +527,7 @@ void Settings::saveGlobal()
s.setValue("separateWindow", separateWindow);
s.setValue("dontGroupWindows", dontGroupWindows);
s.setValue("groupchatPosition", groupchatPosition);
s.setValue("showIdenticons", showIdenticons);

s.setValue("smileyPack", smileyPack);
s.setValue("emojiFontPointSize", emojiFontPointSize);
Expand Down Expand Up @@ -2191,6 +2193,22 @@ void Settings::setGroupchatPosition(bool value)
}
}

bool Settings::getShowIdenticons() const
{
const QMutexLocker locker{&bigLock};
return showIdenticons;
}

void Settings::setShowIdenticons(bool value)
{
const QMutexLocker locker{&bigLock};

if (value != showIdenticons) {
showIdenticons = value;
emit showIdenticonsChanged(value);
}
}

int Settings::getCircleCount() const
{
return circleLst.size();
Expand Down
9 changes: 8 additions & 1 deletion src/persistence/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ class Settings : public QObject, public ICoreSettings, public IAudioSettings, pu
Q_PROPERTY(QString style READ getStyle WRITE setStyle NOTIFY styleChanged FINAL)
Q_PROPERTY(bool showSystemTray READ getShowSystemTray WRITE setShowSystemTray NOTIFY
showSystemTrayChanged FINAL)
Q_PROPERTY(bool showIdenticons READ getShowIdenticons WRITE setShowIdenticons NOTIFY
showIdenticonsChanged FINAL)

// ChatView
Q_PROPERTY(bool groupchatPosition READ getGroupchatPosition WRITE setGroupchatPosition NOTIFY
Expand Down Expand Up @@ -209,6 +211,7 @@ public slots:
void styleChanged(const QString& style);
void themeColorChanged(int color);
void compactLayoutChanged(bool enabled);
void showIdenticonsChanged(bool enabled);

// ChatView
void useEmoticonsChanged(bool enabled);
Expand Down Expand Up @@ -499,9 +502,12 @@ public slots:

bool getDontGroupWindows() const;
void setDontGroupWindows(bool value);

bool getGroupchatPosition() const;
void setGroupchatPosition(bool value);

bool getShowIdenticons() const;
void setShowIdenticons(bool value);

bool getAutoLogin() const;
void setAutoLogin(bool state);
Expand Down Expand Up @@ -566,6 +572,7 @@ public slots:
bool groupchatPosition;
bool separateWindow;
bool dontGroupWindows;
bool showIdenticons;
bool enableIPv6;
QString translation;
bool makeToxPortable;
Expand Down
6 changes: 6 additions & 0 deletions src/widget/form/settings/userinterfaceform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ UserInterfaceForm::UserInterfaceForm(SettingsWidget* myParent)
bodyUI->cbSeparateWindow->setChecked(s.getSeparateWindow());
bodyUI->cbDontGroupWindows->setChecked(s.getDontGroupWindows());
bodyUI->cbDontGroupWindows->setEnabled(s.getSeparateWindow());
bodyUI->cbShowIdenticons->setChecked(s.getShowIdenticons());

bodyUI->useEmoticons->setChecked(s.getUseEmoticons());
for (auto entry : SmileyPack::listSmileyPacks())
Expand Down Expand Up @@ -298,6 +299,11 @@ void UserInterfaceForm::on_cbGroupchatPosition_stateChanged()
Settings::getInstance().setGroupchatPosition(bodyUI->cbGroupchatPosition->isChecked());
}

void UserInterfaceForm::on_cbShowIdenticons_stateChanged()
{
Settings::getInstance().setShowIdenticons(bodyUI->cbShowIdenticons->isChecked());
}

void UserInterfaceForm::on_themeColorCBox_currentIndexChanged(int)
{
int index = bodyUI->themeColorCBox->currentIndex();
Expand Down
1 change: 1 addition & 0 deletions src/widget/form/settings/userinterfaceform.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ private slots:
void on_cbDontGroupWindows_stateChanged();
void on_cbGroupchatPosition_stateChanged();
void on_themeColorCBox_currentIndexChanged(int);
void on_cbShowIdenticons_stateChanged();

void on_txtChatFont_currentFontChanged(const QFont& f);
void on_txtChatFontSize_valueChanged(int arg1);
Expand Down
10 changes: 10 additions & 0 deletions src/widget/form/settings/userinterfacesettings.ui
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,16 @@
</item>
</layout>
</item>
<item>
<widget class="QCheckBox" name="cbShowIdenticons">
<property name="toolTip">
<string comment="toolTip for show identicons">If enabled every contact without an avatar set will have a generated avatar based on their Tox ID instead of a default picture. Requires restart to apply.</string>
</property>
<property name="text">
<string>Use identicons instead of empty avatars</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
Expand Down

0 comments on commit 905ca77

Please sign in to comment.