diff --git a/smileypack.cpp b/smileypack.cpp index 5af07194f..57a754c76 100644 --- a/smileypack.cpp +++ b/smileypack.cpp @@ -40,24 +40,38 @@ SmileyPack& SmileyPack::getInstance() return smileyPack; } -QList > SmileyPack::listSmileyPacks(const QString &path) +QList > SmileyPack::listSmileyPacks(const QStringList &paths) { QList > 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(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(packageName, absPath); + else + smileyPacks << QPair(packageName, relPath); // use relative path for subdirectories + } + + dir.cdUp(); + } } return smileyPacks; diff --git a/smileypack.h b/smileypack.h index 9f4ea31ba..1d4c9ef30 100644 --- a/smileypack.h +++ b/smileypack.h @@ -22,7 +22,10 @@ #include #include -#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> listSmileyPacks(const QString& path = SMILEYPACK_DEFAULT_PATH); + static QList > 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 getEmoticons() const; QString getAsRichText(const QString& key); diff --git a/widget/settingsdialog.cpp b/widget/settingsdialog.cpp index 0f11ee67c..4f9c26a9b 100644 --- a/widget/settingsdialog.cpp +++ b/widget/settingsdialog.cpp @@ -4,6 +4,7 @@ #include "camera.h" #include "selfcamview.h" #include "core.h" +#include "smileypack.h" #include #include @@ -14,6 +15,7 @@ #include #include #include +#include // ======================================= @@ -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(); }