Skip to content
This repository has been archived by the owner on Jun 11, 2020. It is now read-only.

Smiley fix (part 1 from issue #83) #95

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions resources/icons/theme.th
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

# theme file format:
# - paths to emoticon picture files must be relative to where this theme file is stored.
# - paths must start with a '/'.
# - enter emoticon after the [theme] line, one line per emoticon.
# - multiple textual representations of the same emoticon shall be separated by
# at least one space, i.e ' '.

Name =TOX Qt GUI Smileys
Author =FatCow
Description =description
Version = 1.0
Website =website
Icon =/emoticons/emotion_smile.png

[theme]
/emoticons/emotion_smile.png :) :-) :o)
/emoticons/emotion_sad.png :( :-(
/emoticons/emotion_grin.png :D :-D
/emoticons/emotion_cool.png 8) 8-)
/emoticons/emotion_suprised.png :O :-O
/emoticons/emotion_wink.png ;) ;-)
/emoticons/emotion_cry.png ;( ;-(
/emoticons/emotion_sweat.png (:|
/emoticons/emotion_kiss.png :* :-*
/emoticons/emotion_tongue.png :P :-P
/emoticons/emotion_doubt.png :^) :^-)
/emoticons/emotion_love.png (inlove)
/emoticons/emotion_evilgrin.png ]:) ]:-)
/emoticons/emotion_angel.png O:) O:-) o:) o:-) (angel)

58 changes: 27 additions & 31 deletions src/Settings/guisettingspage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,13 @@ void GuiSettingsPage::setGui()
emojiPack.setEmoji(true);
smileypackCombobox->addItem("☺ "+emojiPack.getName(), emojiPack.save());

// Insert Default pack
Smileypack defaultPack;
defaultPack.setName("TOX Qt GUI Smileys");
defaultPack.setAuthor("FatCow");
defaultPack.setDescription("TODO: Design a default smileypack for TOX Qt GUI.");
defaultPack.setIcon(":/icons/emoticons/emotion_smile.png");
defaultPack.setList(Smileypack::defaultList());
smileypackCombobox->addItem(QIcon(defaultPack.getIcon()), defaultPack.getName(), defaultPack.save());

// Insert smileypacks
searchSmileyPacks();
// User defined smileypacks:
bool defaultSmileyPacks = false;
searchSmileyPacks(defaultSmileyPacks);
// Default smileypacks:
defaultSmileyPacks = true;
searchSmileyPacks(defaultSmileyPacks);

// Load smileypack
int index = smileypackCombobox->findData(settings.getSmileyPack());
Expand Down Expand Up @@ -134,34 +130,34 @@ QGroupBox *GuiSettingsPage::buildSmileypackGroup()
return group;
}

void GuiSettingsPage::searchSmileyPacks()
void GuiSettingsPage::searchSmileyPacks(bool defaultPackDir)
{
// Go to smiley pack folder
QDir dir(Smileypack::packDir());
if (!dir.mkpath(Smileypack::packDir()))
return;

// Go through all packs
dir.setFilter(QDir::Dirs|QDir::NoDot|QDir::NoDotDot);
QDirIterator it(dir);
while (it.hasNext()) {
it.next();

// Check theme file
QFileInfo f(it.filePath() + '/' + "theme");
if (!f.exists()) {
continue;
}

// Parse theme file
QDir themeFileDirectory;

if(defaultPackDir){
themeFileDirectory = QDir(Smileypack::defaultPackDirRelative());
}
else{
themeFileDirectory = QDir(Smileypack::packDir());
}
// find theme files:
QStringList themeFiles;
QString themeFileSuffix = "*.th";
themeFiles = themeFileDirectory.entryList(QStringList(themeFileSuffix),
QDir::Files | QDir::NoSymLinks);
// parse theme files:
for( auto themeFileName : themeFiles)
{
QString filePathToThemeFile = themeFileDirectory.absolutePath() + '/' + themeFileName;
// Parse theme file, fileInfo.absoluteFilePath()
Smileypack newPack;
if (!newPack.parseFile(f.absoluteFilePath())) {
if (!newPack.parseFile(filePathToThemeFile)) { // not used by default since it's relative path
continue;
}

// Add new pack to combobox
QVariant data(newPack.save());
smileypackCombobox->addItem(QIcon(it.filePath() + '/' + newPack.getIcon()), newPack.getName(), data);
smileypackCombobox->addItem(QIcon(themeFileDirectory.absolutePath() + newPack.getIcon()), newPack.getName(), data);
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/Settings/guisettingspage.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#define GUISETTINGSPAGE_HPP

#include "abstractsettingspage.hpp"
#include <QDebug>

class QGroupBox;
class QCheckBox;
Expand All @@ -43,7 +44,7 @@ private slots:
QGroupBox* buildAnimationGroup();
QGroupBox* buildSmileypackGroup();

void searchSmileyPacks();
void searchSmileyPacks(bool defaultPackDir);


EmojiFontSettingsDialog *emojiSettings;
Expand Down
28 changes: 6 additions & 22 deletions src/smileypack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,28 +240,6 @@ const Smileypack::SmileyList Smileypack::emojiList()
return tmpList;
}

const Smileypack::SmileyList Smileypack::defaultList()
{
static const SmileyList tmpList =
{
{":/icons/emoticons/emotion_smile.png", {":)", ":-)", ":o)"}},
{":/icons/emoticons/emotion_sad.png", {":(", ":-("}},
{":/icons/emoticons/emotion_grin.png", {":D", ":-D"}},
{":/icons/emoticons/emotion_cool.png", {"8)", "8-)"}},
{":/icons/emoticons/emotion_suprised.png", {":O", ":-O"}},
{":/icons/emoticons/emotion_wink.png", {";)", ";-)"}},
{":/icons/emoticons/emotion_cry.png", {";(", ";-("}},
{":/icons/emoticons/emotion_sweat.png", {"(:|"}},
{":/icons/emoticons/emotion_kiss.png", {":*", ":-*"}},
{":/icons/emoticons/emotion_tongue.png", {":P", ":-P"}},
{":/icons/emoticons/emotion_doubt.png", {":^)", ":^-)"}},
{":/icons/emoticons/emotion_love.png", {"(inlove)"}},
{":/icons/emoticons/emotion_evilgrin.png", {"]:)", "]:-)"}},
{":/icons/emoticons/emotion_angel.png", {"O:)", "O:-)", "o:)", "o:-)", "(angel)"}}
};
return tmpList;
}

bool Smileypack::parseFile(const QString &filePath)
{
// Open file
Expand Down Expand Up @@ -355,6 +333,12 @@ const QString &Smileypack::packDir()
return path;
}

const QString &Smileypack::defaultPackDirRelative()
{
static QString path = QString("../resources") + '/' + "icons";
return path;
}

QDataStream &operator<<(QDataStream &out, const Smileypack &pack)
{
out << pack.getThemeFile() << pack.getName() << pack.getAuthor() << pack.getDescription() << pack.getVersion() << pack.getWebsite() << pack.getIcon() << pack.isEmoji();
Expand Down
3 changes: 2 additions & 1 deletion src/smileypack.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,13 @@ class Smileypack : public QObject
void setEmoji(bool x) { emoji = x; }

static const QString& packDir();
static const QString& defaultPackDirRelative();
static QString smilify(QString text);
static QString desmilify(QString htmlText);
static QString deemojify(QString text);
static QString resizeEmoji(QString text);
static const SmileyList emojiList();
static const SmileyList defaultList();
// static const SmileyList defaultList();

private:
QString themeFile;
Expand Down