From 0d493f4bcfae834afdba466c502e11d3bedbe45b Mon Sep 17 00:00:00 2001 From: krepa098 Date: Wed, 30 Jul 2014 09:18:41 +0200 Subject: [PATCH 1/4] ability to detect smileyPacks --- smileypack.cpp | 22 ++++++++++++++++++++-- smileypack.h | 2 ++ widget/form/settingsform.cpp | 22 +++++++--------------- widget/form/settingsform.h | 6 +++--- 4 files changed, 32 insertions(+), 20 deletions(-) diff --git a/smileypack.cpp b/smileypack.cpp index 16029515d..822f263c0 100644 --- a/smileypack.cpp +++ b/smileypack.cpp @@ -34,6 +34,25 @@ SmileyPack& SmileyPack::getInstance() return smileyPack; } +QStringList SmileyPack::listSmileyPacks(const QString &path) +{ + QStringList smileyPacks; + + QDir dir(path); + foreach (const QString& subdirectory, dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot)) + { + dir.cd(subdirectory); + + QFileInfoList entries = dir.entryInfoList(QStringList() << "emoticons.xml", QDir::Files); + if (entries.size() > 0) // does it contain a file called emoticons.xml? + smileyPacks << QDir(QCoreApplication::applicationDirPath()).relativeFilePath(entries[0].absoluteFilePath()); + + dir.cdUp(); + } + + return smileyPacks; +} + bool SmileyPack::load(const QString& filename) { // discard old data @@ -89,7 +108,6 @@ QString SmileyPack::replaceEmoticons(QString msg) QRegExp exp("\\S+"); // matches words int index = msg.indexOf(exp); - int offset = 0; // if a word is key of a smiley, replace it by its corresponding image in Rich Text while (index >= 0) @@ -104,7 +122,7 @@ QString SmileyPack::replaceEmoticons(QString msg) QString imgRichText = ""; - msg.replace(index + offset, key.length(), imgRichText); + msg.replace(index, key.length(), imgRichText); index += imgRichText.length() - key.length(); } index = msg.indexOf(exp, index + key.length()); diff --git a/smileypack.h b/smileypack.h index 155aa2a48..7273ac2aa 100644 --- a/smileypack.h +++ b/smileypack.h @@ -31,6 +31,8 @@ public: bool load(const QString &filename); QString replaceEmoticons(QString msg); + static QStringList listSmileyPacks(const QString& path); + private slots: void onSmileyPackChanged(); diff --git a/widget/form/settingsform.cpp b/widget/form/settingsform.cpp index 9d2c71d00..1b278c961 100644 --- a/widget/form/settingsform.cpp +++ b/widget/form/settingsform.cpp @@ -17,6 +17,7 @@ #include "settingsform.h" #include "widget/widget.h" #include "settings.h" +#include "smileypack.h" #include #include #include @@ -52,7 +53,8 @@ SettingsForm::SettingsForm() makeToxPortable.setChecked(Settings::getInstance().getMakeToxPortable()); smileyPackLabel.setText(tr("Smiley Pack", "Text on smiley pack label")); - smileyPackFilename.setText(Settings::getInstance().getSmileyPack()); + smileyPackBrowser.addItems(SmileyPack::listSmileyPacks("./smileys")); + smileyPackBrowser.setCurrentText(Settings::getInstance().getSmileyPack()); main->setLayout(&layout); layout.addWidget(&nameLabel); @@ -66,8 +68,7 @@ SettingsForm::SettingsForm() layout.addWidget(&useTranslations); layout.addWidget(&makeToxPortable); layout.addWidget(&smileyPackLabel); - layout.addWidget(&smileyPackFilename); - layout.addWidget(&smileyBrowseFileButton); + layout.addWidget(&smileyPackBrowser); layout.addStretch(); head->setLayout(&headLayout); @@ -78,7 +79,7 @@ SettingsForm::SettingsForm() connect(&useTranslations, SIGNAL(stateChanged(int)), this, SLOT(onUseTranslationUpdated())); connect(&makeToxPortable, SIGNAL(stateChanged(int)), this, SLOT(onMakeToxPortableUpdated())); connect(&idLabel, SIGNAL(clicked()), this, SLOT(copyIdClicked())); - connect(&smileyBrowseFileButton, SIGNAL(clicked()), this, SLOT(onBrowseSmileyFilename())); + connect(&smileyPackBrowser, SIGNAL(currentTextChanged(QString)), this, SLOT(onSmileyBrowserTextChanged(QString))); } SettingsForm::~SettingsForm() @@ -126,16 +127,7 @@ void SettingsForm::onMakeToxPortableUpdated() Settings::getInstance().setMakeToxPortable(makeToxPortable.isChecked()); } -void SettingsForm::onBrowseSmileyFilename() +void SettingsForm::onSmileyBrowserTextChanged(const QString &filename) { - // directory containing a file called emoticons.xml - QString filename = QFileDialog::getOpenFileName(nullptr, tr("Select smiley pack"), QDir::currentPath(), "emoticons.xml"); - - // get relative path to app's local directory - QString relPath = QDir::current().relativeFilePath(filename); - - // save - Settings::getInstance().setSmileyPack(relPath); - smileyPackFilename.setText(relPath); + Settings::getInstance().setSmileyPack(filename); } - diff --git a/widget/form/settingsform.h b/widget/form/settingsform.h index 5cf2c5532..5a6bbd93a 100644 --- a/widget/form/settingsform.h +++ b/widget/form/settingsform.h @@ -26,6 +26,7 @@ #include #include #include +#include #include "widget/tool/clickablelabel.h" #include "ui_widget.h" #include "widget/selfcamview.h" @@ -47,7 +48,7 @@ private slots: void onEnableIPv6Updated(); void onUseTranslationUpdated(); void onMakeToxPortableUpdated(); - void onBrowseSmileyFilename(); + void onSmileyBrowserTextChanged(const QString& filename); void copyIdClicked(); private: @@ -58,8 +59,7 @@ private: QCheckBox enableIPv6, useTranslations, makeToxPortable; QVBoxLayout layout, headLayout; QWidget *main, *head; - QLineEdit smileyPackFilename; - QToolButton smileyBrowseFileButton; + QComboBox smileyPackBrowser; public: QLineEdit name, statusText; }; From f7a357d671ca6ecc545ccde614fbfe1f9d82d247 Mon Sep 17 00:00:00 2001 From: krepa098 Date: Wed, 30 Jul 2014 22:07:26 +0200 Subject: [PATCH 2/4] wire up the emote button --- smileypack.cpp | 29 ++++++++++++++++++++-- smileypack.h | 7 +++++- widget/form/chatform.cpp | 53 ++++++++++++++++++++++++++++++++++++++++ widget/form/chatform.h | 2 ++ 4 files changed, 88 insertions(+), 3 deletions(-) diff --git a/smileypack.cpp b/smileypack.cpp index 822f263c0..1e73ea2d0 100644 --- a/smileypack.cpp +++ b/smileypack.cpp @@ -58,6 +58,7 @@ bool SmileyPack::load(const QString& filename) // discard old data assignmentTable.clear(); cache.clear(); + emoticons.clear(); // open emoticons.xml QFile xmlFile(filename); @@ -88,13 +89,17 @@ bool SmileyPack::load(const QString& filename) QString file = emoticonElements.at(i).attributes().namedItem("file").nodeValue(); QDomElement stringElement = emoticonElements.at(i).firstChildElement("string"); + QStringList emoticonSet; // { ":)", ":-)" } etc. + while (!stringElement.isNull()) { - QString rune = stringElement.text(); - assignmentTable.insert(rune, file); + QString emoticon = stringElement.text(); + assignmentTable.insert(emoticon, file); + emoticonSet.push_back(emoticon); stringElement = stringElement.nextSibling().toElement(); } + emoticons.push_back(emoticonSet); } path = QFileInfo(filename).absolutePath(); @@ -131,6 +136,26 @@ QString SmileyPack::replaceEmoticons(QString msg) return msg; } +QList SmileyPack::getEmoticons() const +{ + return emoticons; +} + +QString SmileyPack::getRichText(const QString &key) +{ + QString file = assignmentTable[key]; + if (!cache.contains(file)) { + loadSmiley(file); + } + + return ""; +} + +QIcon SmileyPack::getIcon(const QString &key) +{ + return QIcon(path + '/' + assignmentTable[key]); +} + void SmileyPack::loadSmiley(const QString &name) { QSize size(16, 16); // TODO: adapt to text size diff --git a/smileypack.h b/smileypack.h index 7273ac2aa..69ea898cf 100644 --- a/smileypack.h +++ b/smileypack.h @@ -18,8 +18,9 @@ #define SMILEYPACK_H #include -#include #include +#include +#include //maps emoticons to smileys class SmileyPack : public QObject @@ -30,6 +31,9 @@ public: bool load(const QString &filename); QString replaceEmoticons(QString msg); + QList getEmoticons() const; + QString getRichText(const QString& key); + QIcon getIcon(const QString& key); static QStringList listSmileyPacks(const QString& path); @@ -46,6 +50,7 @@ private: QHash assignmentTable; // matches an emoticon to its corresponding smiley QHash cache; // base64 representation of a smiley QString path; // directory containing the cfg file + QList emoticons; }; #endif // SMILEYPACK_H diff --git a/widget/form/chatform.cpp b/widget/form/chatform.cpp index 07e7d9e4b..896f1c960 100644 --- a/widget/form/chatform.cpp +++ b/widget/form/chatform.cpp @@ -25,6 +25,8 @@ #include #include #include +#include +#include ChatForm::ChatForm(Friend* chatFriend) : f(chatFriend), curRow{0}, lockSliderToBottom{true} @@ -188,6 +190,7 @@ ChatForm::ChatForm(Friend* chatFriend) connect(msgEdit, SIGNAL(enterPressed()), this, SLOT(onSendTriggered())); connect(chatArea->verticalScrollBar(), SIGNAL(rangeChanged(int,int)), this, SLOT(onSliderRangeChanged())); connect(chatArea, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(onChatContextMenuRequested(QPoint))); + connect(emoteButton, SIGNAL(clicked()), this, SLOT(onEmoteButtonClicked())); } ChatForm::~ChatForm() @@ -652,3 +655,53 @@ void ChatForm::onSaveLogClicked() file.write(log.toUtf8()); file.close(); } + +void ChatForm::onEmoteButtonClicked() +{ + QList emoticons = SmileyPack::getInstance().getEmoticons(); + + QMenu menu; + QGridLayout* gridLayout = new QGridLayout; + menu.setLayout(gridLayout); + + int colCount = sqrt(emoticons.size()) + 1; + int row = 0; + int col = 0; + for (QStringList set : emoticons) + { + QPushButton* button = new QPushButton; + button->setIcon(SmileyPack::getInstance().getIcon(set[0])); + button->setToolTip(set.join(" ")); + button->setProperty("sequence", set[0]); + connect(button, &QPushButton::clicked, this, &ChatForm::onAddEmote); + + gridLayout->addWidget(button, row, ++col); + if (col >= colCount) + { + col = 0; + row++; + } + } + + QWidget* sender = qobject_cast(QObject::sender()); + if (sender) + { + QPoint pos(gridLayout->totalSizeHint().width() / 2, gridLayout->totalSizeHint().height()); + menu.exec(sender->mapToGlobal(-pos)); + } +} + +void ChatForm::onAddEmote() +{ + // hide the QMenu + QMenu* menu = qobject_cast(QObject::sender()->parent()); + if (menu) + menu->hide(); + + // insert the emoticon + QWidget* sender = qobject_cast(QObject::sender()); + if (sender) + msgEdit->insertPlainText(' ' + sender->property("sequence").toString() + ' '); + + msgEdit->setFocus(); // refocus so that you can continue typing +} diff --git a/widget/form/chatform.h b/widget/form/chatform.h index d6d44143b..a58dc3237 100644 --- a/widget/form/chatform.h +++ b/widget/form/chatform.h @@ -83,6 +83,8 @@ private slots: void onCancelCallTriggered(); void onChatContextMenuRequested(QPoint pos); void onSaveLogClicked(); + void onEmoteButtonClicked(); + void onAddEmote(); private: Friend* f; From f0306bb25fac0747b62e167ed3361212f8fa4f51 Mon Sep 17 00:00:00 2001 From: krepa098 Date: Thu, 31 Jul 2014 16:08:44 +0200 Subject: [PATCH 3/4] cleanup --- smileypack.cpp | 52 ++++++++++++++++++++++++---------------- smileypack.h | 16 ++++++------- widget/form/chatform.cpp | 2 +- 3 files changed, 40 insertions(+), 30 deletions(-) diff --git a/smileypack.cpp b/smileypack.cpp index 1e73ea2d0..0ccc87af0 100644 --- a/smileypack.cpp +++ b/smileypack.cpp @@ -56,9 +56,10 @@ QStringList SmileyPack::listSmileyPacks(const QString &path) bool SmileyPack::load(const QString& filename) { // discard old data - assignmentTable.clear(); + filenameTable.clear(); cache.clear(); emoticons.clear(); + path.clear(); // open emoticons.xml QFile xmlFile(filename); @@ -80,6 +81,8 @@ bool SmileyPack::load(const QString& filename) * */ + path = QFileInfo(filename).absolutePath(); + QDomDocument doc; doc.setContent(xmlFile.readAll()); @@ -94,16 +97,15 @@ bool SmileyPack::load(const QString& filename) while (!stringElement.isNull()) { QString emoticon = stringElement.text(); - assignmentTable.insert(emoticon, file); + filenameTable.insert(emoticon, file); emoticonSet.push_back(emoticon); + cacheSmiley(file); // preload all smileys stringElement = stringElement.nextSibling().toElement(); } emoticons.push_back(emoticonSet); } - path = QFileInfo(filename).absolutePath(); - // success! return true; } @@ -118,14 +120,9 @@ QString SmileyPack::replaceEmoticons(QString msg) while (index >= 0) { QString key = exp.cap(); - if (assignmentTable.contains(key)) + if (filenameTable.contains(key)) { - QString file = assignmentTable[key]; - if (!cache.contains(file)) { - loadSmiley(file); - } - - QString imgRichText = ""; + QString imgRichText = getSmileyAsRichText(key); msg.replace(index, key.length(), imgRichText); index += imgRichText.length() - key.length(); @@ -141,22 +138,20 @@ QList SmileyPack::getEmoticons() const return emoticons; } -QString SmileyPack::getRichText(const QString &key) +QString SmileyPack::getSmileyAsRichText(const QString &key) { - QString file = assignmentTable[key]; - if (!cache.contains(file)) { - loadSmiley(file); - } - - return ""; + return ""; } QIcon SmileyPack::getIcon(const QString &key) { - return QIcon(path + '/' + assignmentTable[key]); + QPixmap pm; + pm.loadFromData(getCachedSmiley(key), "PNG"); + + return QIcon(pm); } -void SmileyPack::loadSmiley(const QString &name) +void SmileyPack::cacheSmiley(const QString &name) { QSize size(16, 16); // TODO: adapt to text size QString filename = path % '/' % name; @@ -170,8 +165,23 @@ void SmileyPack::loadSmiley(const QString &name) QBuffer buffer(&scaledImgData); scaledImg.save(&buffer, "PNG"); - cache.insert(name, scaledImgData.toBase64()); + cache.insert(name, scaledImgData); + } +} + +QByteArray SmileyPack::getCachedSmiley(const QString &key) +{ + // valid key? + if (!filenameTable.contains(key)) + return QByteArray(); + + // cache it if needed + QString file = filenameTable.value(key); + if (!cache.contains(file)) { + cacheSmiley(file); } + + return cache.value(file); } void SmileyPack::onSmileyPackChanged() diff --git a/smileypack.h b/smileypack.h index 69ea898cf..b315d60d6 100644 --- a/smileypack.h +++ b/smileypack.h @@ -28,14 +28,13 @@ class SmileyPack : public QObject Q_OBJECT public: static SmileyPack& getInstance(); + static QStringList listSmileyPacks(const QString& path); bool load(const QString &filename); QString replaceEmoticons(QString msg); QList getEmoticons() const; - QString getRichText(const QString& key); - QIcon getIcon(const QString& key); - - static QStringList listSmileyPacks(const QString& path); + QString getSmileyAsRichText(const QString& key); + QIcon getIcon(const QString& key); private slots: void onSmileyPackChanged(); @@ -45,11 +44,12 @@ private: SmileyPack(SmileyPack&) = delete; SmileyPack& operator=(const SmileyPack&) = delete; - void loadSmiley(const QString& name); + void cacheSmiley(const QString& name); + QByteArray getCachedSmiley(const QString& key); - QHash assignmentTable; // matches an emoticon to its corresponding smiley - QHash cache; // base64 representation of a smiley - QString path; // directory containing the cfg file + QHash filenameTable; // matches an emoticon to its corresponding smiley ie. ":)" -> "happy.png" + QHash cache; // (scaled) representation of a smiley ie. "happy.png" -> data + QString path; // directory containing the cfg and image files QList emoticons; }; diff --git a/widget/form/chatform.cpp b/widget/form/chatform.cpp index 896f1c960..7dfdaf1d4 100644 --- a/widget/form/chatform.cpp +++ b/widget/form/chatform.cpp @@ -667,7 +667,7 @@ void ChatForm::onEmoteButtonClicked() int colCount = sqrt(emoticons.size()) + 1; int row = 0; int col = 0; - for (QStringList set : emoticons) + for (const QStringList& set : emoticons) { QPushButton* button = new QPushButton; button->setIcon(SmileyPack::getInstance().getIcon(set[0])); From 6fed143048b9cd7708bc4812bb7ea7e02827ebf2 Mon Sep 17 00:00:00 2001 From: krepa098 Date: Thu, 31 Jul 2014 17:36:55 +0200 Subject: [PATCH 4/4] cleanup --- smileypack.cpp | 26 +++++++++++++++----------- smileypack.h | 12 ++++++------ widget/form/chatform.cpp | 4 ++-- widget/form/settingsform.cpp | 10 ++++++---- widget/form/settingsform.h | 2 +- 5 files changed, 30 insertions(+), 24 deletions(-) diff --git a/smileypack.cpp b/smileypack.cpp index 0ccc87af0..7dca525dc 100644 --- a/smileypack.cpp +++ b/smileypack.cpp @@ -34,9 +34,9 @@ SmileyPack& SmileyPack::getInstance() return smileyPack; } -QStringList SmileyPack::listSmileyPacks(const QString &path) +QList > SmileyPack::listSmileyPacks(const QString &path) { - QStringList smileyPacks; + QList > smileyPacks; QDir dir(path); foreach (const QString& subdirectory, dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot)) @@ -45,7 +45,11 @@ QStringList SmileyPack::listSmileyPacks(const QString &path) QFileInfoList entries = dir.entryInfoList(QStringList() << "emoticons.xml", QDir::Files); if (entries.size() > 0) // does it contain a file called emoticons.xml? - smileyPacks << QDir(QCoreApplication::applicationDirPath()).relativeFilePath(entries[0].absoluteFilePath()); + { + QString packageName = dir.dirName(); + QString relPath = QDir(QCoreApplication::applicationDirPath()).relativeFilePath(entries[0].absoluteFilePath()); + smileyPacks << QPair(packageName, relPath); + } dir.cdUp(); } @@ -57,7 +61,7 @@ bool SmileyPack::load(const QString& filename) { // discard old data filenameTable.clear(); - cache.clear(); + imgCache.clear(); emoticons.clear(); path.clear(); @@ -110,7 +114,7 @@ bool SmileyPack::load(const QString& filename) return true; } -QString SmileyPack::replaceEmoticons(QString msg) +QString SmileyPack::smileyfied(QString msg) { QRegExp exp("\\S+"); // matches words @@ -122,7 +126,7 @@ QString SmileyPack::replaceEmoticons(QString msg) QString key = exp.cap(); if (filenameTable.contains(key)) { - QString imgRichText = getSmileyAsRichText(key); + QString imgRichText = getAsRichText(key); msg.replace(index, key.length(), imgRichText); index += imgRichText.length() - key.length(); @@ -138,12 +142,12 @@ QList SmileyPack::getEmoticons() const return emoticons; } -QString SmileyPack::getSmileyAsRichText(const QString &key) +QString SmileyPack::getAsRichText(const QString &key) { return ""; } -QIcon SmileyPack::getIcon(const QString &key) +QIcon SmileyPack::getAsIcon(const QString &key) { QPixmap pm; pm.loadFromData(getCachedSmiley(key), "PNG"); @@ -165,7 +169,7 @@ void SmileyPack::cacheSmiley(const QString &name) QBuffer buffer(&scaledImgData); scaledImg.save(&buffer, "PNG"); - cache.insert(name, scaledImgData); + imgCache.insert(name, scaledImgData); } } @@ -177,11 +181,11 @@ QByteArray SmileyPack::getCachedSmiley(const QString &key) // cache it if needed QString file = filenameTable.value(key); - if (!cache.contains(file)) { + if (!imgCache.contains(file)) { cacheSmiley(file); } - return cache.value(file); + return imgCache.value(file); } void SmileyPack::onSmileyPackChanged() diff --git a/smileypack.h b/smileypack.h index b315d60d6..dd315ab94 100644 --- a/smileypack.h +++ b/smileypack.h @@ -28,13 +28,13 @@ class SmileyPack : public QObject Q_OBJECT public: static SmileyPack& getInstance(); - static QStringList listSmileyPacks(const QString& path); + static QList> listSmileyPacks(const QString& path); bool load(const QString &filename); - QString replaceEmoticons(QString msg); + QString smileyfied(QString msg); QList getEmoticons() const; - QString getSmileyAsRichText(const QString& key); - QIcon getIcon(const QString& key); + QString getAsRichText(const QString& key); + QIcon getAsIcon(const QString& key); private slots: void onSmileyPackChanged(); @@ -48,9 +48,9 @@ private: QByteArray getCachedSmiley(const QString& key); QHash filenameTable; // matches an emoticon to its corresponding smiley ie. ":)" -> "happy.png" - QHash cache; // (scaled) representation of a smiley ie. "happy.png" -> data + QHash imgCache; // (scaled) representation of a smiley ie. "happy.png" -> data + QList emoticons; // {{ ":)", ":-)" }, {":(", ...}, ... } QString path; // directory containing the cfg and image files - QList emoticons; }; #endif // SMILEYPACK_H diff --git a/widget/form/chatform.cpp b/widget/form/chatform.cpp index 7dfdaf1d4..398579318 100644 --- a/widget/form/chatform.cpp +++ b/widget/form/chatform.cpp @@ -242,7 +242,7 @@ void ChatForm::addFriendMessage(QString message) void ChatForm::addMessage(QString author, QString message, QString date) { - message = SmileyPack::getInstance().replaceEmoticons(message); + message = SmileyPack::getInstance().smileyfied(message); addMessage(new QLabel(author), new QLabel(message), new QLabel(date)); } @@ -670,7 +670,7 @@ void ChatForm::onEmoteButtonClicked() for (const QStringList& set : emoticons) { QPushButton* button = new QPushButton; - button->setIcon(SmileyPack::getInstance().getIcon(set[0])); + button->setIcon(SmileyPack::getInstance().getAsIcon(set[0])); button->setToolTip(set.join(" ")); button->setProperty("sequence", set[0]); connect(button, &QPushButton::clicked, this, &ChatForm::onAddEmote); diff --git a/widget/form/settingsform.cpp b/widget/form/settingsform.cpp index 1b278c961..bc2518ede 100644 --- a/widget/form/settingsform.cpp +++ b/widget/form/settingsform.cpp @@ -53,8 +53,9 @@ SettingsForm::SettingsForm() makeToxPortable.setChecked(Settings::getInstance().getMakeToxPortable()); smileyPackLabel.setText(tr("Smiley Pack", "Text on smiley pack label")); - smileyPackBrowser.addItems(SmileyPack::listSmileyPacks("./smileys")); - smileyPackBrowser.setCurrentText(Settings::getInstance().getSmileyPack()); + for (auto entry : SmileyPack::listSmileyPacks("./smileys")) + smileyPackBrowser.addItem(entry.first, entry.second); + smileyPackBrowser.setCurrentIndex(smileyPackBrowser.findData(Settings::getInstance().getSmileyPack())); main->setLayout(&layout); layout.addWidget(&nameLabel); @@ -79,7 +80,7 @@ SettingsForm::SettingsForm() connect(&useTranslations, SIGNAL(stateChanged(int)), this, SLOT(onUseTranslationUpdated())); connect(&makeToxPortable, SIGNAL(stateChanged(int)), this, SLOT(onMakeToxPortableUpdated())); connect(&idLabel, SIGNAL(clicked()), this, SLOT(copyIdClicked())); - connect(&smileyPackBrowser, SIGNAL(currentTextChanged(QString)), this, SLOT(onSmileyBrowserTextChanged(QString))); + connect(&smileyPackBrowser, SIGNAL(currentIndexChanged(int)), this, SLOT(onSmileyBrowserIndexChanged(int))); } SettingsForm::~SettingsForm() @@ -127,7 +128,8 @@ void SettingsForm::onMakeToxPortableUpdated() Settings::getInstance().setMakeToxPortable(makeToxPortable.isChecked()); } -void SettingsForm::onSmileyBrowserTextChanged(const QString &filename) +void SettingsForm::onSmileyBrowserIndexChanged(int index) { + QString filename = smileyPackBrowser.itemData(index).toString(); Settings::getInstance().setSmileyPack(filename); } diff --git a/widget/form/settingsform.h b/widget/form/settingsform.h index 5a6bbd93a..db5a395cf 100644 --- a/widget/form/settingsform.h +++ b/widget/form/settingsform.h @@ -48,7 +48,7 @@ private slots: void onEnableIPv6Updated(); void onUseTranslationUpdated(); void onMakeToxPortableUpdated(); - void onSmileyBrowserTextChanged(const QString& filename); + void onSmileyBrowserIndexChanged(int index); void copyIdClicked(); private: