mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
ability to detect smileyPacks
This commit is contained in:
parent
133ff15154
commit
0d493f4bcf
|
@ -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 = "<img src=\"data:image/png;base64," % cache[file] % "\">";
|
||||
|
||||
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());
|
||||
|
|
|
@ -31,6 +31,8 @@ public:
|
|||
bool load(const QString &filename);
|
||||
QString replaceEmoticons(QString msg);
|
||||
|
||||
static QStringList listSmileyPacks(const QString& path);
|
||||
|
||||
private slots:
|
||||
void onSmileyPackChanged();
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
#include "settingsform.h"
|
||||
#include "widget/widget.h"
|
||||
#include "settings.h"
|
||||
#include "smileypack.h"
|
||||
#include <QFont>
|
||||
#include <QClipboard>
|
||||
#include <QApplication>
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
#include <QCheckBox>
|
||||
#include <QPushButton>
|
||||
#include <QTextEdit>
|
||||
#include <QComboBox>
|
||||
#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;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue
Block a user