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;
|
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)
|
bool SmileyPack::load(const QString& filename)
|
||||||
{
|
{
|
||||||
// discard old data
|
// discard old data
|
||||||
@ -89,7 +108,6 @@ QString SmileyPack::replaceEmoticons(QString msg)
|
|||||||
QRegExp exp("\\S+"); // matches words
|
QRegExp exp("\\S+"); // matches words
|
||||||
|
|
||||||
int index = msg.indexOf(exp);
|
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
|
// if a word is key of a smiley, replace it by its corresponding image in Rich Text
|
||||||
while (index >= 0)
|
while (index >= 0)
|
||||||
@ -104,7 +122,7 @@ QString SmileyPack::replaceEmoticons(QString msg)
|
|||||||
|
|
||||||
QString imgRichText = "<img src=\"data:image/png;base64," % cache[file] % "\">";
|
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 += imgRichText.length() - key.length();
|
||||||
}
|
}
|
||||||
index = msg.indexOf(exp, index + key.length());
|
index = msg.indexOf(exp, index + key.length());
|
||||||
|
@ -31,6 +31,8 @@ public:
|
|||||||
bool load(const QString &filename);
|
bool load(const QString &filename);
|
||||||
QString replaceEmoticons(QString msg);
|
QString replaceEmoticons(QString msg);
|
||||||
|
|
||||||
|
static QStringList listSmileyPacks(const QString& path);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void onSmileyPackChanged();
|
void onSmileyPackChanged();
|
||||||
|
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
#include "settingsform.h"
|
#include "settingsform.h"
|
||||||
#include "widget/widget.h"
|
#include "widget/widget.h"
|
||||||
#include "settings.h"
|
#include "settings.h"
|
||||||
|
#include "smileypack.h"
|
||||||
#include <QFont>
|
#include <QFont>
|
||||||
#include <QClipboard>
|
#include <QClipboard>
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
@ -52,7 +53,8 @@ SettingsForm::SettingsForm()
|
|||||||
makeToxPortable.setChecked(Settings::getInstance().getMakeToxPortable());
|
makeToxPortable.setChecked(Settings::getInstance().getMakeToxPortable());
|
||||||
|
|
||||||
smileyPackLabel.setText(tr("Smiley Pack", "Text on smiley pack label"));
|
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);
|
main->setLayout(&layout);
|
||||||
layout.addWidget(&nameLabel);
|
layout.addWidget(&nameLabel);
|
||||||
@ -66,8 +68,7 @@ SettingsForm::SettingsForm()
|
|||||||
layout.addWidget(&useTranslations);
|
layout.addWidget(&useTranslations);
|
||||||
layout.addWidget(&makeToxPortable);
|
layout.addWidget(&makeToxPortable);
|
||||||
layout.addWidget(&smileyPackLabel);
|
layout.addWidget(&smileyPackLabel);
|
||||||
layout.addWidget(&smileyPackFilename);
|
layout.addWidget(&smileyPackBrowser);
|
||||||
layout.addWidget(&smileyBrowseFileButton);
|
|
||||||
layout.addStretch();
|
layout.addStretch();
|
||||||
|
|
||||||
head->setLayout(&headLayout);
|
head->setLayout(&headLayout);
|
||||||
@ -78,7 +79,7 @@ SettingsForm::SettingsForm()
|
|||||||
connect(&useTranslations, SIGNAL(stateChanged(int)), this, SLOT(onUseTranslationUpdated()));
|
connect(&useTranslations, SIGNAL(stateChanged(int)), this, SLOT(onUseTranslationUpdated()));
|
||||||
connect(&makeToxPortable, SIGNAL(stateChanged(int)), this, SLOT(onMakeToxPortableUpdated()));
|
connect(&makeToxPortable, SIGNAL(stateChanged(int)), this, SLOT(onMakeToxPortableUpdated()));
|
||||||
connect(&idLabel, SIGNAL(clicked()), this, SLOT(copyIdClicked()));
|
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()
|
SettingsForm::~SettingsForm()
|
||||||
@ -126,16 +127,7 @@ void SettingsForm::onMakeToxPortableUpdated()
|
|||||||
Settings::getInstance().setMakeToxPortable(makeToxPortable.isChecked());
|
Settings::getInstance().setMakeToxPortable(makeToxPortable.isChecked());
|
||||||
}
|
}
|
||||||
|
|
||||||
void SettingsForm::onBrowseSmileyFilename()
|
void SettingsForm::onSmileyBrowserTextChanged(const QString &filename)
|
||||||
{
|
{
|
||||||
// directory containing a file called emoticons.xml
|
Settings::getInstance().setSmileyPack(filename);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,6 +26,7 @@
|
|||||||
#include <QCheckBox>
|
#include <QCheckBox>
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
#include <QTextEdit>
|
#include <QTextEdit>
|
||||||
|
#include <QComboBox>
|
||||||
#include "widget/tool/clickablelabel.h"
|
#include "widget/tool/clickablelabel.h"
|
||||||
#include "ui_widget.h"
|
#include "ui_widget.h"
|
||||||
#include "widget/selfcamview.h"
|
#include "widget/selfcamview.h"
|
||||||
@ -47,7 +48,7 @@ private slots:
|
|||||||
void onEnableIPv6Updated();
|
void onEnableIPv6Updated();
|
||||||
void onUseTranslationUpdated();
|
void onUseTranslationUpdated();
|
||||||
void onMakeToxPortableUpdated();
|
void onMakeToxPortableUpdated();
|
||||||
void onBrowseSmileyFilename();
|
void onSmileyBrowserTextChanged(const QString& filename);
|
||||||
void copyIdClicked();
|
void copyIdClicked();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -58,8 +59,7 @@ private:
|
|||||||
QCheckBox enableIPv6, useTranslations, makeToxPortable;
|
QCheckBox enableIPv6, useTranslations, makeToxPortable;
|
||||||
QVBoxLayout layout, headLayout;
|
QVBoxLayout layout, headLayout;
|
||||||
QWidget *main, *head;
|
QWidget *main, *head;
|
||||||
QLineEdit smileyPackFilename;
|
QComboBox smileyPackBrowser;
|
||||||
QToolButton smileyBrowseFileButton;
|
|
||||||
public:
|
public:
|
||||||
QLineEdit name, statusText;
|
QLineEdit name, statusText;
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user