summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJavier S. Pedro <maemo@javispedro.com>2013-04-02 02:02:19 +0200
committerJavier S. Pedro <maemo@javispedro.com>2013-04-02 02:02:19 +0200
commit9f12671ee8dd38a130a16c9146001c9c2494d77c (patch)
tree7d52a44132c0b4ea3fb46c8e6a8baa7901473ec8
parent5f66a8e03f3a748d01e162d151c3a7e987899f09 (diff)
downloadtapasboard-9f12671ee8dd38a130a16c9146001c9c2494d77c.tar.gz
tapasboard-9f12671ee8dd38a130a16c9146001c9c2494d77c.zip
read favorite boards from a .ini instead of hardcoding them
-rw-r--r--board.cpp2
-rw-r--r--favoritesmodel.cpp75
-rw-r--r--favoritesmodel.h37
-rw-r--r--main.cpp2
-rw-r--r--qml/tapasboard/MainPage.qml38
-rw-r--r--qml/tapasboard/TopicPage.qml1
-rw-r--r--qml/tapasboard/main.qml18
-rw-r--r--tapasboard.pro6
8 files changed, 147 insertions, 32 deletions
diff --git a/board.cpp b/board.cpp
index 3acf03b..b3e113e 100644
--- a/board.cpp
+++ b/board.cpp
@@ -329,6 +329,8 @@ void Board::initializeBbCode()
_bbcodes << qMakePair(QRegExp("\\[url=([^]]*)\\]", Qt::CaseInsensitive), QString("<a href=\"\\1\">"));
_bbcodes << qMakePair(QRegExp("\\[/url\\]", Qt::CaseInsensitive), QString("</a>"));
+ _bbcodes << qMakePair(QRegExp("\\[hr\\]", Qt::CaseInsensitive), QString("<hr>"));
+
_bbcodes << qMakePair(QRegExp("\n"), QString("<br>"));
}
diff --git a/favoritesmodel.cpp b/favoritesmodel.cpp
new file mode 100644
index 0000000..de4bf2d
--- /dev/null
+++ b/favoritesmodel.cpp
@@ -0,0 +1,75 @@
+#include <QtCore/QSettings>
+#include <QtCore/QDebug>
+
+#include "favoritesmodel.h"
+
+FavoritesModel::FavoritesModel(QObject *parent) :
+ QAbstractListModel(parent)
+{
+ QHash<int, QByteArray> roles = roleNames();
+ roles[NameRole] = QByteArray("title");
+ roles[LogoRole] = QByteArray("logo");
+ roles[BoardUrlRole] = QByteArray("boardUrl");
+ setRoleNames(roles);
+
+ load();
+ if (_boards.empty()) {
+ // Let's load some defaults
+ qDebug() << "Setting up some default boards";
+ FavoriteBoard board;
+ board.name = "Tapatalk Community Forum";
+ board.url = "http://support.tapatalk.com/mobiquo/mobiquo.php";
+ _boards << board;
+ save();
+ }
+}
+
+int FavoritesModel::rowCount(const QModelIndex &parent) const
+{
+ if (parent.isValid()) return 0;
+ return _boards.size();
+}
+
+QVariant FavoritesModel::data(const QModelIndex &index, int role) const
+{
+ if (!index.isValid()) return QVariant();
+ const int row = index.row();
+ if (row >= _boards.size()) return QVariant();
+
+ switch (role) {
+ case NameRole:
+ return _boards[row].name;
+ case BoardUrlRole:
+ return _boards[row].url;
+ }
+
+ return QVariant();
+}
+
+void FavoritesModel::load()
+{
+ QSettings settings;
+ const int size = settings.beginReadArray("boards");
+ _boards.reserve(size);
+ for (int i = 0; i < size; i++) {
+ settings.setArrayIndex(i);
+ FavoriteBoard board;
+ board.name = settings.value("name").toString();
+ board.url = settings.value("url").toString();
+ _boards.append(board);
+ }
+ settings.endArray();
+}
+
+void FavoritesModel::save()
+{
+ QSettings settings;
+ const int size = _boards.size();
+ settings.beginWriteArray("boards", size);
+ for (int i = 0; i < size; i++) {
+ settings.setArrayIndex(i);
+ settings.setValue("name", _boards[i].name);
+ settings.setValue("url", _boards[i].url);
+ }
+ settings.endArray();
+}
diff --git a/favoritesmodel.h b/favoritesmodel.h
new file mode 100644
index 0000000..59959d4
--- /dev/null
+++ b/favoritesmodel.h
@@ -0,0 +1,37 @@
+#ifndef FAVORITESMODEL_H
+#define FAVORITESMODEL_H
+
+#include <QtCore/QAbstractListModel>
+
+class FavoritesModel : public QAbstractListModel
+{
+ Q_OBJECT
+public:
+ explicit FavoritesModel(QObject *parent = 0);
+
+ enum DataRoles {
+ NameRole = Qt::DisplayRole,
+ LogoRole = Qt::DecorationRole,
+
+ BoardUrlRole = Qt::UserRole
+ };
+
+ int rowCount(const QModelIndex &parent = QModelIndex()) const;
+ QVariant data(const QModelIndex &index, int role) const;
+
+protected:
+ struct FavoriteBoard {
+ QString name;
+ QString url;
+ };
+
+private:
+ void load();
+ void save();
+
+private:
+
+ QList<FavoriteBoard> _boards;
+};
+
+#endif // FAVORITESMODEL_H
diff --git a/main.cpp b/main.cpp
index 47b7147..ba01c2d 100644
--- a/main.cpp
+++ b/main.cpp
@@ -4,6 +4,7 @@
#include "global.h"
#include "board.h"
+#include "favoritesmodel.h"
#include "boardmodel.h"
#include "forummodel.h"
#include "topicmodel.h"
@@ -20,6 +21,7 @@ Q_DECL_EXPORT int main(int argc, char *argv[])
QScopedPointer<BoardManager> manager(new BoardManager);
board_manager = manager.data(); // Set the global pointer to this singleton
+ qmlRegisterType<FavoritesModel>("com.javispedro.tapasboard", 1, 0, "FavoritesModel");
qmlRegisterType<BoardModel>("com.javispedro.tapasboard", 1, 0, "BoardModel");
qmlRegisterType<ForumModel>("com.javispedro.tapasboard", 1, 0, "ForumModel");
qmlRegisterType<TopicModel>("com.javispedro.tapasboard", 1, 0, "TopicModel");
diff --git a/qml/tapasboard/MainPage.qml b/qml/tapasboard/MainPage.qml
index 7337b12..de3240a 100644
--- a/qml/tapasboard/MainPage.qml
+++ b/qml/tapasboard/MainPage.qml
@@ -1,17 +1,31 @@
import QtQuick 1.1
-import com.nokia.meego 1.0
+import com.nokia.meego 1.1
+import com.nokia.extras 1.1
+import com.javispedro.tapasboard 1.0
Page {
- tools: commonTools
+ ListView {
+ id: favoritesView
+ anchors.fill: parent
+ model: FavoritesModel {
- Button {
- anchors {
- centerIn: parent
- }
- text: qsTr("Open board")
- onClicked: pageStack.push(Qt.resolvedUrl("BoardPage.qml"), {
- boardUrl: "http://support.tapatalk.com/mobiquo/mobiquo.php",
- rootForumId: 0
- })
- }
+ }
+ delegate: ListDelegate {
+ id: favoriteItem
+
+ Image {
+ id: topicItemImage
+ source: "image://theme/icon-m-common-drilldown-arrow" + (theme.inverted ? "-inverse" : "")
+ anchors.right: parent.right
+ anchors.verticalCenter: parent.verticalCenter
+ }
+
+ onClicked: {
+ pageStack.push(Qt.resolvedUrl("BoardPage.qml"), {
+ boardUrl: model.boardUrl,
+ rootForumId: 0
+ });
+ }
+ }
+ }
}
diff --git a/qml/tapasboard/TopicPage.qml b/qml/tapasboard/TopicPage.qml
index d3b2a35..805154f 100644
--- a/qml/tapasboard/TopicPage.qml
+++ b/qml/tapasboard/TopicPage.qml
@@ -84,6 +84,7 @@ Page {
font: UiConstants.TitleFont
visible: text != ""
textFormat: Text.PlainText
+ wrapMode: Text.Wrap
}
Text {
diff --git a/qml/tapasboard/main.qml b/qml/tapasboard/main.qml
index bfb4552..11a7e44 100644
--- a/qml/tapasboard/main.qml
+++ b/qml/tapasboard/main.qml
@@ -9,22 +9,4 @@ PageStackWindow {
MainPage {
id: mainPage
}
-
- ToolBarLayout {
- id: commonTools
- visible: true
- ToolIcon {
- platformIconId: "toolbar-view-menu"
- anchors.right: (parent === undefined) ? undefined : parent.right
- onClicked: (myMenu.status === DialogStatus.Closed) ? myMenu.open() : myMenu.close()
- }
- }
-
- Menu {
- id: myMenu
- visualParent: pageStack
- MenuLayout {
- MenuItem { text: qsTr("Sample menu item") }
- }
- }
}
diff --git a/tapasboard.pro b/tapasboard.pro
index 1ecefde..c0c2026 100644
--- a/tapasboard.pro
+++ b/tapasboard.pro
@@ -44,7 +44,8 @@ SOURCES += main.cpp \
forummodel.cpp \
fetchtopicsaction.cpp \
topicmodel.cpp \
- fetchpostsaction.cpp
+ fetchpostsaction.cpp \
+ favoritesmodel.cpp
# Please do not modify the following two lines. Required for deployment.
include(qmlapplicationviewer/qmlapplicationviewer.pri)
@@ -73,4 +74,5 @@ HEADERS += \
forummodel.h \
fetchtopicsaction.h \
topicmodel.h \
- fetchpostsaction.h
+ fetchpostsaction.h \
+ favoritesmodel.h