Skip to content

Commit

Permalink
Cleanup & fixes (#52)
Browse files Browse the repository at this point in the history
* Fix memory leak

* Fix totoz settings appearance

* Fix settings modal name

* Code modernization

* Fix copy link location action

* Fix video provider previewer

* Remove useless code

* Handle some QT 5.15 depreciations

* Enforce auto usage

* Make use same font for pini & emoji selector

* Fix redirect handling for relative urls

* Hopefully fix network changes issues
  • Loading branch information
dguihal authored Apr 6, 2023
1 parent 29f26b3 commit fe7c9d6
Show file tree
Hide file tree
Showing 65 changed files with 1,059 additions and 966 deletions.
8 changes: 6 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*.qbs.user
*.qbs.user.*
*.moc
moc_*.cpp
moc_*
qrc_*.cpp
ui_*.h
Makefile*
Expand All @@ -26,4 +26,8 @@ Makefile*
#QtCtreator Qml
*.qmlproject.user
*.qmlproject.user.*
.vscode
.vscode/
.kde4/
quteqoin
quteqoin.kdev4
build/
10 changes: 4 additions & 6 deletions core/parsers/qqbackendparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,15 @@
/// \param parent
///
QQBackendParser::QQBackendParser(QObject *parent) :
QObject(parent),
m_lastId(0),
m_maxId(0)
QObject(parent),
m_lastId(0),
m_maxId(0)
{

}

//////////////////////////////////////////////////////////////
/// \brief QQBackendParser::~QQBackendParser
///
QQBackendParser::~QQBackendParser()
{
QQBackendParser::~QQBackendParser() = default;

}
133 changes: 133 additions & 0 deletions core/parsers/qqcustomxmlparser.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
#include "qqcustomxmlparser.h"

#include <QBuffer>

constexpr static auto POST_ATTR_START_MARK = "<post ";
constexpr static auto POST_ATTR_END_MARK = "</post>";
constexpr static auto TIME_ATTR_START_MARK = "time=\"";
constexpr static auto TIME_ATTR_END_MARK = "\"";
constexpr static auto ID_ATTR_START_MARK = "id=\"";
constexpr static auto ID_ATTR_END_MARK = "\"";
constexpr static auto INFO_TAG_START_MARK = "<info>";
constexpr static auto INFO_TAG_END_MARK = "</info>";
constexpr static auto MESSAGE_TAG_START_MARK = "<message>";
constexpr static auto MESSAGE_TAG_END_MARK = "</message>";
constexpr static auto LOGIN_TAG_START_MARK = "<login>";
constexpr static auto LOGIN_TAG_END_MARK = "</login>";


QQCustomXmlParser::QQCustomXmlParser(QObject *parent) : QQBackendParser(parent)
{

}

bool QQCustomXmlParser::parseBackend(const QByteArray &data)
{
if (data.isEmpty())
return false;

int indexStart = 0;
while ((indexStart = data.indexOf(POST_ATTR_START_MARK, indexStart)) >= 0)
{
auto indexEnd = data.indexOf(POST_ATTR_END_MARK, indexStart);
if (indexEnd >= 0)
{
if(parsePost(data.mid(indexStart + strlen(POST_ATTR_START_MARK), indexEnd - (indexStart + strlen(POST_ATTR_START_MARK)))))
emit newPostReady(m_currentPost);
}
indexStart = indexEnd;
}

m_lastId = m_maxId;

emit finished();

return true;
}

bool QQCustomXmlParser::parsePost(const QByteArray &data)
{
m_currentPost.reset();

// Extract Id
auto indexStart = data.indexOf(ID_ATTR_START_MARK);
if (indexStart < 0)
return false;
indexStart += strlen(ID_ATTR_START_MARK);

auto indexEnd = data.indexOf(ID_ATTR_END_MARK, indexStart);
if (indexEnd < 0)
return false;
auto postId = data.mid(indexStart, indexEnd - indexStart);

bool ok = true;
qlonglong id = postId.toLongLong(&ok);
if(!ok || id <= m_lastId)
return false;
if(id > m_maxId)
m_maxId = id;

m_currentPost.setId(postId);

// Extract Norloge
indexStart = data.indexOf(TIME_ATTR_START_MARK);
if (indexStart < 0)
return false;
indexStart += strlen(TIME_ATTR_START_MARK);

indexEnd = data.indexOf(TIME_ATTR_END_MARK, indexStart);
if (indexEnd < 0)
return false;
m_currentPost.setNorloge(data.mid(indexStart, indexEnd - indexStart));

// Extract login
indexStart = data.indexOf(LOGIN_TAG_START_MARK);
if (indexStart < 0)
return false;
indexStart += strlen(LOGIN_TAG_START_MARK);

indexEnd = data.indexOf(LOGIN_TAG_END_MARK, indexStart);
if (indexEnd < 0)
return false;
m_currentPost.setLogin(data.mid(indexStart, indexEnd - indexStart));

// Extract info
indexStart = data.indexOf(INFO_TAG_START_MARK);
if (indexStart < 0)
return false;
indexStart += strlen(INFO_TAG_START_MARK);

indexEnd = data.indexOf(INFO_TAG_END_MARK, indexStart);
if (indexEnd < 0)
return false;
m_currentPost.setUA(data.mid(indexStart, indexEnd - indexStart));

// Extract message
indexStart = data.indexOf(MESSAGE_TAG_START_MARK);
if (indexStart < 0)
return false;
indexStart += strlen(MESSAGE_TAG_START_MARK);

indexEnd = data.indexOf(MESSAGE_TAG_END_MARK, indexStart);
if (indexEnd < 0)
return false;
auto rawMessage = data.mid(indexStart, indexEnd - indexStart);

if (m_typeSlip == QQBouchot::SlipTagsEncoded)
{
m_currentPost.setMessage(
QString(rawMessage).
replace("&lt;", "<").
replace("&gt;", ">").
replace("&quote;", "\"").
replace("&#34;", "\"").
replace("&amp;", "&")
);
}
else
m_currentPost.setMessage(rawMessage);

//qDebug() << Q_FUNC_INFO << m_currentPost.message();

return true;
}
27 changes: 27 additions & 0 deletions core/parsers/qqcustomxmlparser.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#ifndef QQCUSTOMXMLPARSER_H
#define QQCUSTOMXMLPARSER_H

#include <QStack>

#include "core/parsers/qqbackendparser.h"
#include "core/qqbouchot.h"

class QQCustomXmlParser : public QQBackendParser
{
Q_OBJECT
public:
QQCustomXmlParser(QObject *parent = 0);

QString errorString () const;

bool parseBackend(const QByteArray &data);

bool parsePost(const QByteArray &data);

void setTypeSlip(QQBouchot::TypeSlip typeSlip) { this->m_typeSlip = typeSlip; }

private:
QQBouchot::TypeSlip m_typeSlip;
};

#endif // QQCUSTOMXMLPARSER_H
5 changes: 3 additions & 2 deletions core/parsers/qqtsvparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
#include <QtDebug>
#include <QBuffer>

#define CHAR_SEP '\t'
constexpr char CHAR_SEP='\t';
constexpr int TSV_STANDARD_FIELD_COUNT = 5;

QQTsvParser::QQTsvParser(QObject *parent) : QQBackendParser(parent)
{
Expand All @@ -24,7 +25,7 @@ bool QQTsvParser::parseBackend(const QByteArray &data)
QByteArray l = f.readLine();

QList<QByteArray> fields = l.split(CHAR_SEP);
if(fields.length() == 5)
if(fields.length() == TSV_STANDARD_FIELD_COUNT)
{
bool ok = true;
qlonglong id = fields.at(0).toLongLong(&ok);
Expand Down
5 changes: 0 additions & 5 deletions core/parsers/qqtsvparser.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@ class QQTsvParser : public QQBackendParser
QString errorString () const;

bool parseBackend(const QByteArray &data);

signals:
void newPostReady(QQPost & newPost);
void finished();

};

#endif // QQTSVPARSER_H
8 changes: 3 additions & 5 deletions core/parsers/qqxmlparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

//
QQXmlParser::QQXmlParser(QObject *parent)
: QQBackendParser(parent), QXmlDefaultHandler()
: QQBackendParser(parent)
{
m_currentPost.reset();
m_typeSlip = QQBouchot::SlipTagsEncoded;
Expand All @@ -30,9 +30,7 @@ QQXmlParser::QQXmlParser(QObject *parent)
}

//
QQXmlParser::~QQXmlParser()
{
}
QQXmlParser::~QQXmlParser() = default;

QString QQXmlParser::errorString () const
{
Expand Down Expand Up @@ -162,7 +160,7 @@ bool QQXmlParser::startElement(const QString &namespaceURI, const QString &local
}
}

if (m_elementNames.size() > 0 &&
if ((! m_elementNames.isEmpty()) &&
((m_elementNames.top() == "info") ||
(m_elementNames.top() == "message") ||
(m_elementNames.top() == "login"))
Expand Down
4 changes: 3 additions & 1 deletion core/qqbackendupdatedevent.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#include "qqbackendupdatedevent.h"

#include <utility>

const QEvent::Type QQBackendUpdatedEvent::BACKEND_UPDATED =
(QEvent::Type)QEvent::registerEventType();

QQBackendUpdatedEvent::QQBackendUpdatedEvent(QEvent::Type type, QString group) :
QEvent(type), m_group(group)
QEvent(type), m_group(std::move(group))
{
}
6 changes: 3 additions & 3 deletions core/qqbakdisplayfilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
///
bool QQBakDisplayFilter::filterMatch(const QQPost *post)
{
if(post == NULL)
if(post == nullptr)
return false;

QQBouchot *b = post->bouchot();
QString login = post->login();
if(login.size() > 0)
return b->isBaked(login, true);
else
return b->isBaked(post->UA(), false);

return b->isBaked(post->UA(), false);
}
2 changes: 1 addition & 1 deletion core/qqbakdisplayfilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class QQBakDisplayFilter : public QQPostDisplayFilter
QQBakDisplayFilter() : QQPostDisplayFilter() {}
virtual ~QQBakDisplayFilter() {}

virtual bool filterMatch(const QQPost *post);
virtual bool filterMatch(const QQPost *post) override;
};

#endif // QQBAKDISPLAYFILTER_H
6 changes: 4 additions & 2 deletions core/qqboardstatechangeevent.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
#include "qqboardstatechangeevent.h"

#include <utility>

const QEvent::Type QQBoardStateChangeEvent::BOARD_STATE_CHANGED =
(QEvent::Type)QEvent::registerEventType();

QQBoardStateChangeEvent::QQBoardStateChangeEvent(const QString &boardName) :
QQBoardStateChangeEvent::QQBoardStateChangeEvent(QString boardName) :
QEvent(BOARD_STATE_CHANGED),
m_boardName(boardName)
m_boardName(std::move(boardName))
{
}

Expand Down
2 changes: 1 addition & 1 deletion core/qqboardstatechangeevent.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class QQBoardStateChangeEvent : public QEvent
public:
static const QEvent::Type BOARD_STATE_CHANGED;

QQBoardStateChangeEvent(const QString &boardName);
QQBoardStateChangeEvent(QString boardName);
QString boardName();

private:
Expand Down
Loading

0 comments on commit fe7c9d6

Please sign in to comment.