summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--board.cpp61
-rw-r--r--board.h8
-rw-r--r--fetchconfigaction.cpp (renamed from fetchboardconfigaction.cpp)12
-rw-r--r--fetchconfigaction.h (renamed from fetchboardconfigaction.h)10
-rw-r--r--fetchpostsaction.cpp3
-rw-r--r--tapasboard.pro32
6 files changed, 91 insertions, 35 deletions
diff --git a/board.cpp b/board.cpp
index 4275047..acb2b01 100644
--- a/board.cpp
+++ b/board.cpp
@@ -1,4 +1,3 @@
-#include <QtCore/QRegExp>
#include <QtCore/QDir>
#include <QtCore/QDebug>
#include <QtSql/QSqlQuery>
@@ -6,7 +5,7 @@
#include "global.h"
#include "action.h"
-#include "fetchboardconfigaction.h"
+#include "fetchconfigaction.h"
#include "fetchforumsaction.h"
#include "xmlrpcinterface.h"
#include "board.h"
@@ -38,10 +37,12 @@ Board::Board(const QString& forumUrl, QObject *parent) :
fetchConfigIfOutdated();
fetchForumsIfOutdated();
initializeBbCode(); // TODO This might depend on board config
+ initializeSmilies();
}
Board::~Board()
{
+ disconnect(this, SLOT(handleActionFinished(Action*)));
QSqlDatabase::removeDatabase(_slug);
}
@@ -144,6 +145,28 @@ QString Board::bbcodeToRichText(QString text) const
return text;
}
+QString Board::parseSmilies(QString text) const
+{
+ int pos = 0;
+ text.append(' '); // So that the regexp matches a smilie at the end.
+ while ((pos = _smilieRegexp.indexIn(text, pos)) != -1) {
+ const int len = _smilieRegexp.matchedLength();
+ QString smilie = _smilieRegexp.cap(1);
+ const int smilie_pos = _smilieRegexp.pos(1);
+ const int smilie_len = smilie.length();
+ QHash<QString,QString>::const_iterator i = _smilies.find(smilie);
+ if (i != _smilies.end()) {
+ QString replacement = "<img src=\"" + i.value() + "\" />";
+ text.replace(smilie_pos, smilie_len, replacement);
+ pos += replacement.size();
+ } else {
+ pos += len - 1;
+ }
+ }
+ text.remove(text.length() - 1, 1);
+ return text;
+}
+
QString Board::renderHumanDate(const QDateTime &dateTime)
{
QDate date = dateTime.toLocalTime().date();
@@ -346,6 +369,38 @@ void Board::initializeBbCode()
_bbcodes << qMakePair(QRegExp("\n"), QString("<br>"));
}
+void Board::initializeSmilies()
+{
+ _smilies[":)"] = "image://theme/icon-s-messaging-smiley-happy";
+ _smilies[":("] = "image://theme/icon-s-messaging-smiley-sad";
+ _smilies[":D"] = "image://theme/icon-s-messaging-smiley-very-happy";
+ _smilies["=D>"] = "image://theme/icon-s-messaging-smiley-very-happy";
+ _smilies[":lol:"] = "image://theme/icon-s-messaging-smiley-very-happy";
+ _smilies[";)"] = "image://theme/icon-s-messaging-smiley-wink";
+ _smilies[";D"] = "image://theme/icon-s-messaging-smiley-wink";
+ _smilies[":wink:"] = "image://theme/icon-s-messaging-smiley-wink";
+ _smilies[":P"] = "image://theme/icon-s-messaging-smiley-tongue";
+ _smilies[":p"] = "image://theme/icon-s-messaging-smiley-tongue";
+ _smilies[":mrgreen:"] = "image://theme/icon-s-messaging-smiley-grin";
+ _smilies["O_O"] = "image://theme/icon-s-messaging-smiley-surprised";
+ _smilies["O_o"] = "image://theme/icon-s-messaging-smiley-surprised";
+
+ // Let's construct a single regular expression that will cover all smilies
+ QString regexp("[^A-Za-z](");
+ for (QHash<QString, QString>::const_iterator i = _smilies.begin();
+ i != _smilies.end();
+ i++) {
+ if (i != _smilies.begin()) {
+ regexp += "|";
+ }
+ regexp += QRegExp::escape(i.key());
+ }
+ regexp += ")[^A-Za-z]";
+ qDebug() << "Smilie regexp: " << regexp;
+ _smilieRegexp = QRegExp(regexp);
+ Q_ASSERT(_smilieRegexp.isValid());
+}
+
void Board::fetchConfigIfOutdated()
{
if (_iface->isAccessible()) {
@@ -353,7 +408,7 @@ void Board::fetchConfigIfOutdated()
QDateTime last_fetch = QDateTime::fromString(
getConfig("last_config_fetch"), Qt::ISODate);
if (!last_fetch.isValid() || last_fetch.daysTo(QDateTime::currentDateTimeUtc()) >= BOARD_CONFIG_TTL) {
- enqueueAction(new FetchBoardConfigAction(this));
+ enqueueAction(new FetchConfigAction(this));
}
}
diff --git a/board.h b/board.h
index 78ebf8a..deb1dfb 100644
--- a/board.h
+++ b/board.h
@@ -5,6 +5,7 @@
#include <QtCore/QHash>
#include <QtCore/QObject>
#include <QtCore/QPair>
+#include <QtCore/QRegExp>
#include <QtCore/QQueue>
#include <QtSql/QSqlDatabase>
@@ -34,6 +35,7 @@ public:
QString removeHtml(QString text) const;
QString removeBbcode(QString text) const;
QString bbcodeToRichText(QString text) const;
+ QString parseSmilies(QString text) const;
QString renderHumanDate(const QDateTime& dateTime);
QString renderHumanTime(const QDateTime& dateTime);
@@ -41,14 +43,12 @@ public:
// These functions wrap emitting the signals below
void notifyConfigChanged(const QString& key = QString());
void notifyForumsChanged();
- void notifySmiliesChanged();
void notifyForumTopicsChanged(int forumId, int start, int end);
void notifyTopicPostsChanged(int topicId, int start, int end);
signals:
void configChanged(const QString& key);
void forumsChanged();
- void smiliesChanged();
void forumTopicsChanged(int forumId, int start, int end);
void topicPostsChanged(int topicId, int start, int end);
@@ -66,7 +66,6 @@ private:
void initializeSmilies();
void fetchConfigIfOutdated();
void fetchForumsIfOutdated();
- void fetchSmiliesIfOutdated();
private slots:
void handleActionFinished(Action *action);
@@ -81,7 +80,8 @@ private:
/** Configuration cache */
mutable QHash<QString, QString> _config;
QList< QPair<QRegExp, QString> > _bbcodes;
- QList< QPair<QString, QString> > _smilies;
+ QHash<QString, QString> _smilies;
+ QRegExp _smilieRegexp;
};
inline bool Board::busy() const
diff --git a/fetchboardconfigaction.cpp b/fetchconfigaction.cpp
index 2364dd1..8c0ac63 100644
--- a/fetchboardconfigaction.cpp
+++ b/fetchconfigaction.cpp
@@ -5,26 +5,26 @@
#include "board.h"
#include "xmlrpcinterface.h"
#include "xmlrpcreply.h"
-#include "fetchboardconfigaction.h"
+#include "fetchconfigaction.h"
-FetchBoardConfigAction::FetchBoardConfigAction(Board *board) :
+FetchConfigAction::FetchConfigAction(Board *board) :
Action(board)
{
}
-bool FetchBoardConfigAction::isSupersetOf(Action *action) const
+bool FetchConfigAction::isSupersetOf(Action *action) const
{
// If 'action' is also a fetch board config action then yes, this supersets 'action'.
- return qobject_cast<FetchBoardConfigAction*>(action) != 0;
+ return qobject_cast<FetchConfigAction*>(action) != 0;
}
-void FetchBoardConfigAction::execute()
+void FetchConfigAction::execute()
{
_call = _board->service()->asyncCall("get_config");
connect(_call, SIGNAL(finished(XmlRpcPendingCall*)), SLOT(handleFinishedCall()));
}
-void FetchBoardConfigAction::handleFinishedCall()
+void FetchConfigAction::handleFinishedCall()
{
XmlRpcReply<QVariantMap> result(_call);
if (result.isValid()) {
diff --git a/fetchboardconfigaction.h b/fetchconfigaction.h
index 7f350f9..44dbd3d 100644
--- a/fetchboardconfigaction.h
+++ b/fetchconfigaction.h
@@ -1,15 +1,15 @@
-#ifndef FETCHBOARDCONFIGACTION_H
-#define FETCHBOARDCONFIGACTION_H
+#ifndef FETCHCONFIGACTION_H
+#define FETCHCONFIGACTION_H
#include "action.h"
class XmlRpcPendingCall;
-class FetchBoardConfigAction : public Action
+class FetchConfigAction : public Action
{
Q_OBJECT
public:
- explicit FetchBoardConfigAction(Board *board);
+ explicit FetchConfigAction(Board *board);
bool isSupersetOf(Action *action) const;
@@ -22,4 +22,4 @@ private:
XmlRpcPendingCall *_call;
};
-#endif // FETCHBOARDCONFIGACTION_H
+#endif // FETCHCONFIGACTION_H
diff --git a/fetchpostsaction.cpp b/fetchpostsaction.cpp
index 426f766..7ed9140 100644
--- a/fetchpostsaction.cpp
+++ b/fetchpostsaction.cpp
@@ -99,5 +99,6 @@ QString FetchPostsAction::unencodePostText(const QVariant &v)
QString FetchPostsAction::unencodePostContent(const QVariant &v)
{
- return _board->bbcodeToRichText(unencodePostText(v));
+ QString richText = _board->bbcodeToRichText(unencodePostText(v));
+ return _board->parseSmilies(richText);
}
diff --git a/tapasboard.pro b/tapasboard.pro
index a1173d5..8430ba0 100644
--- a/tapasboard.pro
+++ b/tapasboard.pro
@@ -18,6 +18,7 @@ symbian:TARGET.UID3 = 0xE33C9CB4
# Allow network access on Symbian
symbian:TARGET.CAPABILITY += NetworkServices
+# Extra QT modules required
QT += network sql
# If your application uses the Qt Mobility libraries, uncomment the following
@@ -31,12 +32,11 @@ CONFIG += qdeclarative-boostable
# Add dependency to Symbian components
# CONFIG += qt-components
-# The .cpp file which was generated for your project. Feel free to hack it.
SOURCES += main.cpp \
action.cpp \
board.cpp \
boardmanager.cpp \
- fetchboardconfigaction.cpp \
+ fetchconfigaction.cpp \
xmlrpcinterface.cpp \
xmlrpcpendingcall.cpp \
fetchforumsaction.cpp \
@@ -49,24 +49,11 @@ SOURCES += main.cpp \
imagecache.cpp \
imagenetworkaccessmanager.cpp
-# Please do not modify the following two lines. Required for deployment.
-include(qmlapplicationviewer/qmlapplicationviewer.pri)
-qtcAddDeployment()
-
-OTHER_FILES += \
- qtc_packaging/debian_harmattan/rules \
- qtc_packaging/debian_harmattan/README \
- qtc_packaging/debian_harmattan/manifest.aegis \
- qtc_packaging/debian_harmattan/copyright \
- qtc_packaging/debian_harmattan/control \
- qtc_packaging/debian_harmattan/compat \
- qtc_packaging/debian_harmattan/changelog
-
HEADERS += \
action.h \
board.h \
boardmanager.h \
- fetchboardconfigaction.h \
+ fetchconfigaction.h \
xmlrpcinterface.h \
xmlrpcpendingcall.h \
xmlrpcreply.h \
@@ -80,3 +67,16 @@ HEADERS += \
favoritesmodel.h \
imagecache.h \
imagenetworkaccessmanager.h
+
+OTHER_FILES += \
+ qtc_packaging/debian_harmattan/rules \
+ qtc_packaging/debian_harmattan/README \
+ qtc_packaging/debian_harmattan/manifest.aegis \
+ qtc_packaging/debian_harmattan/copyright \
+ qtc_packaging/debian_harmattan/control \
+ qtc_packaging/debian_harmattan/compat \
+ qtc_packaging/debian_harmattan/changelog
+
+# Please do not modify the following two lines. Required for deployment.
+include(qmlapplicationviewer/qmlapplicationviewer.pri)
+qtcAddDeployment()