1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

added smiley selection to the new settings dialog, new default search-

This commit is contained in:
krepa098 2014-09-12 19:09:05 +02:00
parent 2aff9fde5c
commit 7e7cebf6b6
3 changed files with 54 additions and 14 deletions

View File

@ -40,24 +40,38 @@ SmileyPack& SmileyPack::getInstance()
return smileyPack;
}
QList<QPair<QString, QString> > SmileyPack::listSmileyPacks(const QString &path)
QList<QPair<QString, QString> > SmileyPack::listSmileyPacks(const QStringList &paths)
{
QList<QPair<QString, QString> > smileyPacks;
QDir dir(path);
foreach (const QString& subdirectory, dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot))
for (QString path : paths)
{
dir.cd(subdirectory);
if (path.leftRef(1) == "~")
path.replace(0, 1, QDir::homePath());
QFileInfoList entries = dir.entryInfoList(QStringList() << "emoticons.xml", QDir::Files);
if (entries.size() > 0) // does it contain a file called emoticons.xml?
QDir dir(path);
if (!dir.exists())
continue;
for (const QString& subdirectory : dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot))
{
QString packageName = dir.dirName();
QString relPath = QDir(QCoreApplication::applicationDirPath()).relativeFilePath(entries[0].absoluteFilePath());
smileyPacks << QPair<QString, QString>(packageName, relPath);
}
dir.cd(subdirectory);
dir.cdUp();
QFileInfoList entries = dir.entryInfoList(QStringList() << "emoticons.xml", QDir::Files);
if (entries.size() > 0) // does it contain a file called emoticons.xml?
{
QString packageName = dir.dirName();
QString absPath = entries[0].absoluteFilePath();
QString relPath = QDir(QCoreApplication::applicationDirPath()).relativeFilePath(absPath);
if (relPath.leftRef(2) == "..")
smileyPacks << QPair<QString, QString>(packageName, absPath);
else
smileyPacks << QPair<QString, QString>(packageName, relPath); // use relative path for subdirectories
}
dir.cdUp();
}
}
return smileyPacks;

View File

@ -22,7 +22,10 @@
#include <QString>
#include <QStringList>
#define SMILEYPACK_DEFAULT_PATH "./smileys"
#define SMILEYPACK_SEARCH_PATHS \
{ \
"./smileys", "/usr/share/qtox/smileys", "/usr/share/emoticons", "~/.kde4/share/emoticons", "~/.kde/share/emoticons" \
}
//maps emoticons to smileys
class SmileyPack : public QObject
@ -30,10 +33,10 @@ class SmileyPack : public QObject
Q_OBJECT
public:
static SmileyPack& getInstance();
static QList<QPair<QString, QString>> listSmileyPacks(const QString& path = SMILEYPACK_DEFAULT_PATH);
static QList<QPair<QString, QString> > listSmileyPacks(const QStringList& paths = SMILEYPACK_SEARCH_PATHS);
static bool isValid(const QString& filename);
bool load(const QString &filename);
bool load(const QString& filename);
QString smileyfied(QString msg);
QList<QStringList> getEmoticons() const;
QString getAsRichText(const QString& key);

View File

@ -4,6 +4,7 @@
#include "camera.h"
#include "selfcamview.h"
#include "core.h"
#include "smileypack.h"
#include <QListWidget>
#include <QListWidgetItem>
@ -14,6 +15,7 @@
#include <QGroupBox>
#include <QCheckBox>
#include <QLineEdit>
#include <QComboBox>
// =======================================
@ -41,8 +43,23 @@ public:
vLayout->addWidget(makeToxPortable);
group->setLayout(vLayout);
// theme
QGroupBox* themeGroup = new QGroupBox(tr("Theme"));
QLabel* smileyLabel = new QLabel(tr("Smiley Pack"));
smileyPack = new QComboBox(this);
auto smileyPacks = SmileyPack::listSmileyPacks();
for(auto pack : smileyPacks)
smileyPack->addItem(QString("%1 (%2)").arg(pack.first).arg(pack.second), pack.second);
QVBoxLayout* themeLayout = new QVBoxLayout();
themeLayout->addWidget(smileyLabel);
themeLayout->addWidget(smileyPack);
themeGroup->setLayout(themeLayout);
QVBoxLayout *mainLayout = new QVBoxLayout();
mainLayout->addWidget(group);
mainLayout->addWidget(themeGroup);
mainLayout->addStretch(1);
setLayout(mainLayout);
}
@ -50,6 +67,7 @@ public:
QCheckBox* enableIPv6;
QCheckBox* useTranslations;
QCheckBox* makeToxPortable;
QComboBox* smileyPack;
};
class IdentityPage : public QWidget
@ -327,6 +345,11 @@ void SettingsDialog::writeConfig()
saveSettings = true;
}
if (settings.getSmileyPack() != generalPage->smileyPack->currentData().toString()) {
settings.setSmileyPack(generalPage->smileyPack->currentData().toString());
saveSettings = true;
}
if (saveSettings) {
settings.save();
}