From 39035f7b683d0d4aa0f6bc189c36b9a320f8a5ff Mon Sep 17 00:00:00 2001 From: noavarice Date: Sat, 8 Apr 2017 21:03:59 +0300 Subject: [PATCH] refactor: returned correct code format and some other small changes --- src/persistence/smileypack.cpp | 24 +++++++++++++----------- src/persistence/smileypack.h | 6 +++--- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/persistence/smileypack.cpp b/src/persistence/smileypack.cpp index 796ce2e74..42dc4b132 100644 --- a/src/persistence/smileypack.cpp +++ b/src/persistence/smileypack.cpp @@ -56,6 +56,8 @@ static const QStringList DEFAULT_PATHS = loadDefaultPaths(); static const QString RICH_TEXT_PATTERN = QStringLiteral(""); +static const QString EMOTICONS_FILE_NAME = QStringLiteral("emoticons.xml"); + /** * @brief Construct list of standard directories with "emoticons" sub dir, whether these directories * exist or not @@ -69,8 +71,8 @@ QStringList loadDefaultPaths() setlocale(LC_ALL, ""); #endif const QString EMOTICONS_SUB_PATH = QDir::separator() + QStringLiteral("emoticons"); - QStringList paths - {":/smileys", "~/.kde4/share/emoticons", "~/.kde/share/emoticons", EMOTICONS_SUB_PATH}; + QStringList paths{":/smileys", "~/.kde4/share/emoticons", "~/.kde/share/emoticons", + EMOTICONS_SUB_PATH}; // qTox exclusive emoticons QStandardPaths::StandardLocation location; @@ -125,7 +127,7 @@ SmileyPack& SmileyPack::getInstance() /** * @brief Does the same as listSmileyPaths, but with default paths */ -QVector> SmileyPack::listSmileyPacks() +QList> SmileyPack::listSmileyPacks() { return listSmileyPacks(DEFAULT_PATHS); } @@ -135,10 +137,9 @@ QVector> SmileyPack::listSmileyPacks() * @param paths Paths where to search for file * @return Vector of pairs: {directoryName, absolutePathToFile} */ -QVector> SmileyPack::listSmileyPacks(const QStringList& paths) +QList> SmileyPack::listSmileyPacks(const QStringList& paths) { - QVector> smileyPacks; - const QString fileName = QStringLiteral("emoticons.xml"); + QList> smileyPacks; const QString homePath = QDir::homePath(); for (QString path : paths) { if (path.startsWith('~')) { @@ -152,8 +153,8 @@ QVector> SmileyPack::listSmileyPacks(const QStringList& for (const QString& subdirectory : dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot)) { dir.cd(subdirectory); - if (dir.exists(fileName)) { - QString absPath = dir.absolutePath() + QDir::separator() + fileName; + if (dir.exists(EMOTICONS_FILE_NAME)) { + QString absPath = dir.absolutePath() + QDir::separator() + EMOTICONS_FILE_NAME; QPair p{dir.dirName(), absPath}; if (!smileyPacks.contains(p)) { smileyPacks.append(p); @@ -204,16 +205,17 @@ bool SmileyPack::load(const QString& filename) QDomNodeList emoticonElements = doc.elementsByTagName("emoticon"); const QString itemName = QStringLiteral("file"); const QString childName = QStringLiteral("string"); + const int iconsCount = emoticonElements.size(); emoticons.clear(); emoticonToIcon.clear(); icons.clear(); - const int iconsCount = emoticonElements.size(); icons.reserve(iconsCount); for (int i = 0; i < iconsCount; ++i) { - QString iconName = emoticonElements.at(i).attributes().namedItem(itemName).nodeValue(); + QDomNode node = emoticonElements.at(i); + QString iconName = node.attributes().namedItem(itemName).nodeValue(); QString iconPath = QDir{path}.filePath(iconName); icons.append(QIcon{iconPath}); - QDomElement stringElement = emoticonElements.at(i).firstChildElement(childName); + QDomElement stringElement = node.firstChildElement(childName); QStringList emoticonList; while (!stringElement.isNull()) { QString emoticon = stringElement.text().replace("<", "<").replace(">", ">"); diff --git a/src/persistence/smileypack.h b/src/persistence/smileypack.h index 1c62751ed..326ae8405 100644 --- a/src/persistence/smileypack.h +++ b/src/persistence/smileypack.h @@ -30,8 +30,8 @@ class SmileyPack : public QObject public: static SmileyPack& getInstance(); - static QVector> listSmileyPacks(const QStringList& paths); - static QVector> listSmileyPacks(); + static QList> listSmileyPacks(const QStringList& paths); + static QList> listSmileyPacks(); QString smileyfied(const QString& msg); QList getEmoticons() const; @@ -48,7 +48,7 @@ private: bool load(const QString& filename); QVector icons; - QMap emoticonToIcon; + QMap emoticonToIcon; QList emoticons; QString path; mutable QMutex loadingMutex;