Many manyyyyyyyyyyy.

This commit is contained in:
Martin Rotter 2013-11-19 21:25:55 +01:00
parent 1c97bb852c
commit 81c30c504a
8 changed files with 145 additions and 91 deletions

View File

@ -9,7 +9,7 @@ set(APP_VERSION "2.0.0-prealpha-2")
set(APP_AUTHOR "Martin Rotter")
set(APP_URL "http://rssguard.sf.net")
option(USE_QT_5 "Use Qt 5 for building" OFF)
option(USE_QT_5 "Use Qt 5 for building" ON)
message(STATUS "[${APP_LOW_NAME}] Welcome to ${APP_NAME} compilation process.")
message(STATUS "[${APP_LOW_NAME}] Compilation process begins right now.")

View File

@ -1,50 +1,50 @@
DROP TABLE IF EXISTS Information;
-- !
CREATE TABLE IF NOT EXISTS Information (
key TEXT PRIMARY KEY,
value TEXT NOT NULL
);
-- !
INSERT INTO Information VALUES ('schema_version', '0.0.1');
-- !
DROP TABLE IF EXISTS Categories;
-- !
CREATE TABLE IF NOT EXISTS Categories (
id INTEGER PRIMARY KEY,
title TEXT NOT NULL UNIQUE CHECK (title != ''),
description TEXT,
date_created TEXT NOT NULL CHECK (date_created != ''),
icon BLOB
);
-- !
DROP TABLE IF EXISTS Feeds;
-- !
CREATE TABLE IF NOT EXISTS Feeds (
id INTEGER PRIMARY KEY,
title TEXT NOT NULL CHECK (title != ''),
description TEXT,
date_created TEXT NOT NULL CHECK (date_created != ''),
icon BLOB,
category INTEGER NOT NULL CHECK (category >= -1),
encoding TEXT NOT NULL CHECK (encoding != ''),
url TEXT NOT NULL UNIQUE CHECK (url != ''),
type INTEGER NOT NULL
);
-- !
DROP TABLE IF EXISTS Messages;
-- !
CREATE TABLE IF NOT EXISTS Messages (
id INTEGER PRIMARY KEY,
read INTEGER(1) NOT NULL CHECK (read >= 0 AND read <= 1) DEFAULT (0),
deleted INTEGER(1) NOT NULL CHECK (deleted >= 0 AND deleted <= 1) DEFAULT (0),
important INTEGER(1) NOT NULL CHECK (important >= 0 AND important <= 1) DEFAULT (0),
feed INTEGER NOT NULL,
title TEXT NOT NULL CHECK (title != ''),
url TEXT,
author TEXT,
date_created TEXT NOT NULL CHECK (date_created != ''),
date_updated TEXT,
contents TEXT,
FOREIGN KEY (feed) REFERENCES Feeds (id)
DROP TABLE IF EXISTS Information;
-- !
CREATE TABLE IF NOT EXISTS Information (
key TEXT PRIMARY KEY,
value TEXT NOT NULL
);
-- !
INSERT INTO Information VALUES ('schema_version', '0.0.1');
-- !
DROP TABLE IF EXISTS Categories;
-- !
CREATE TABLE IF NOT EXISTS Categories (
id INTEGER PRIMARY KEY,
title TEXT NOT NULL UNIQUE CHECK (title != ''),
description TEXT,
date_created TEXT NOT NULL CHECK (date_created != ''),
icon BLOB
);
-- !
DROP TABLE IF EXISTS Feeds;
-- !
CREATE TABLE IF NOT EXISTS Feeds (
id INTEGER PRIMARY KEY,
title TEXT NOT NULL CHECK (title != ''),
description TEXT,
date_created TEXT NOT NULL CHECK (date_created != ''),
icon BLOB,
category INTEGER NOT NULL CHECK (category >= -1),
encoding TEXT NOT NULL CHECK (encoding != ''),
url TEXT NOT NULL UNIQUE CHECK (url != ''),
type INTEGER NOT NULL
);
-- !
DROP TABLE IF EXISTS Messages;
-- !
CREATE TABLE IF NOT EXISTS Messages (
id INTEGER PRIMARY KEY,
read INTEGER(1) NOT NULL CHECK (read >= 0 AND read <= 1) DEFAULT (0),
deleted INTEGER(1) NOT NULL CHECK (deleted >= 0 AND deleted <= 1) DEFAULT (0),
important INTEGER(1) NOT NULL CHECK (important >= 0 AND important <= 1) DEFAULT (0),
feed INTEGER NOT NULL,
title TEXT NOT NULL CHECK (title != ''),
url TEXT,
author TEXT,
date_created TEXT NOT NULL CHECK (date_created != ''),
date_updated TEXT,
contents TEXT,
FOREIGN KEY (feed) REFERENCES Feeds (id)
);

View File

@ -5,6 +5,7 @@
#include "qtsingleapplication/qtsingleapplication.h"
#include "core/defs.h"
#include "core/datetime.h"
#include "core/messagesmodel.h"
#include "core/databasefactory.h"
#include "gui/iconthemefactory.h"
@ -43,13 +44,12 @@ void MessagesModel::fetchAll() {
void MessagesModel::setupFonts() {
m_normalFont = QtSingleApplication::font("MessagesView");
m_boldFont = m_normalFont;
m_boldFont.setBold(true);
}
void MessagesModel::loadMessages(const QList<int> feed_ids) {
// TODO: Doplnit "AND deleted = 0"
// Conversion of parameter.
QStringList stringy_ids;
stringy_ids.reserve(feed_ids.count());
@ -59,11 +59,24 @@ void MessagesModel::loadMessages(const QList<int> feed_ids) {
}
// TODO: časem povolit.
//setFilter(QString("feed IN (%1) ").arg(stringy_ids.join(',')));
//setFilter(QString("feed IN (%1) AND deleted = 0").arg(stringy_ids.join(',')));
select();
fetchAll();
}
Message MessagesModel::messageAt(int row_index) const {
QSqlRecord rec = record(row_index);
Message message;
message.m_author = rec.value(MSG_DB_AUTHOR_INDEX).toString();
message.m_contents = rec.value(MSG_DB_CONTENTS_INDEX).toString();
message.m_title = rec.value(MSG_DB_TITLE_INDEX).toString();
message.m_url = rec.value(MSG_DB_URL_INDEX).toString();
message.m_updated = DateTime::fromString(rec.value(MSG_DB_DUPDATED_INDEX).toString());
return message;
}
void MessagesModel::setupHeaderData() {
m_headerData << tr("Id") << tr("Read") << tr("Deleted") << tr("Important") <<
tr("Feed") << tr("Title") << tr("Url") << tr("Author") <<
@ -84,7 +97,19 @@ Qt::ItemFlags MessagesModel::flags(const QModelIndex &idx) const {
QVariant MessagesModel::data(const QModelIndex &idx, int role) const {
switch (role) {
case Qt::DisplayRole:
//
case Qt::DisplayRole: {
int index_column = idx.column();
if (index_column != MSG_DB_IMPORTANT_INDEX &&
index_column != MSG_DB_READ_INDEX) {
return QSqlTableModel::data(idx, role);
}
else {
return QVariant();
}
}
// Return RAW data for EditRole.
case Qt::EditRole:
return QSqlTableModel::data(idx, role);
@ -101,30 +126,19 @@ QVariant MessagesModel::data(const QModelIndex &idx, int role) const {
m_readIcon :
m_unreadIcon;
}
else if (index_column == MSG_DB_IMPORTANT_INDEX) {
return record(idx.row()).value(MSG_DB_IMPORTANT_INDEX).toInt() == 1 ?
m_favoriteIcon :
QVariant();
}
else {
return QVariant();
}
}
default:
return QVariant();
}
/*
if (role == Qt::FontRole && idx.column() == 1) {
return record(idx.row()).value(1).toInt() == 1 ? m_normalFont : m_boldFont;
}
else if (role == Qt::DecorationRole && idx.column() == 3) {
if (record(idx.row()).value(1).toInt() == 1) {
return IconThemeFactory::getInstance()->fromTheme("mail-mark-read");
}
else {
return IconThemeFactory::getInstance()->fromTheme("mail-mark-unread");
}
}
else {
return QSqlTableModel::data(idx, role);
}*/
}
bool MessagesModel::setData(const QModelIndex &idx, const QVariant &value, int role) {

View File

@ -4,10 +4,27 @@
#include <QSqlTableModel>
#include <QFont>
#include <QIcon>
#include <QDateTime>
#include "core/defs.h"
// Represents single message.
// NOTE: This is primarily used for transfering data
// to WebBrowser responsible for displaying of messages.
class Message {
private:
QString m_title;
QString m_url;
QString m_author;
QString m_contents;
QDateTime m_updated;
friend class WebBrowser;
friend class MessagesModel;
};
class MessagesModel : public QSqlTableModel {
Q_OBJECT
@ -26,6 +43,9 @@ class MessagesModel : public QSqlTableModel {
// Sets up all icons which are used directly by this model.
void setupIcons();
// Returns const reference to message at given index.
Message messageAt(int row_index) const;
public slots:
// Fetches ALL available data to the model.
// NOTE: This is almost needed when sorting
@ -48,6 +68,7 @@ class MessagesModel : public QSqlTableModel {
QFont m_normalFont;
QFont m_boldFont;
QIcon m_favoriteIcon;
QIcon m_readIcon;
QIcon m_unreadIcon;

View File

@ -12,8 +12,28 @@ MessagesView::MessagesView(QWidget *parent) : QTreeView(parent) {
setModel(m_proxyModel);
hideColumn(0);
header()->setSectionResizeMode(3, QHeaderView::ResizeToContents);
// Setup column resize strategies.
header()->setSectionResizeMode(MSG_DB_ID_INDEX, QHeaderView::Interactive);
header()->setSectionResizeMode(MSG_DB_READ_INDEX, QHeaderView::ResizeToContents);
header()->setSectionResizeMode(MSG_DB_DELETED_INDEX, QHeaderView::Interactive);
header()->setSectionResizeMode(MSG_DB_IMPORTANT_INDEX, QHeaderView::ResizeToContents);
header()->setSectionResizeMode(MSG_DB_FEED_INDEX, QHeaderView::Interactive);
header()->setSectionResizeMode(MSG_DB_TITLE_INDEX, QHeaderView::Stretch);
header()->setSectionResizeMode(MSG_DB_URL_INDEX, QHeaderView::Interactive);
header()->setSectionResizeMode(MSG_DB_AUTHOR_INDEX, QHeaderView::Interactive);
header()->setSectionResizeMode(MSG_DB_DCREATED_INDEX, QHeaderView::Interactive);
header()->setSectionResizeMode(MSG_DB_DUPDATED_INDEX, QHeaderView::Interactive);
header()->setSectionResizeMode(MSG_DB_CONTENTS_INDEX, QHeaderView::Interactive);
// Hide columns.
hideColumn(MSG_DB_ID_INDEX);
hideColumn(MSG_DB_DELETED_INDEX);
hideColumn(MSG_DB_FEED_INDEX);
hideColumn(MSG_DB_URL_INDEX);
hideColumn(MSG_DB_CONTENTS_INDEX);
//hideColumn(0);
// NOTE: It is recommended to call this after the model is set
// due to sorting performance.
@ -32,9 +52,13 @@ MessagesProxyModel *MessagesView::model() {
return m_proxyModel;
}
void MessagesView::setupAppearance() {
header()->setStretchLastSection(true);
void MessagesView::setSortingEnabled(bool enable) {
QTreeView::setSortingEnabled(enable);
header()->setSortIndicatorShown(false);
}
void MessagesView::setupAppearance() {
header()->setStretchLastSection(false);
setUniformRowHeights(true);
setAcceptDrops(false);
setDragEnabled(false);
@ -67,5 +91,7 @@ void MessagesView::currentChanged(const QModelIndex &current,
m_sourceModel->setData(m_sourceModel->index(ind.row(), 1), 1, Qt::EditRole);
emit currentMessageChanged(m_sourceModel->messageAt(ind.row()));
QTreeView::currentChanged(current, previous);
}

View File

@ -16,6 +16,8 @@ class MessagesView : public QTreeView {
explicit MessagesView(QWidget *parent = 0);
virtual ~MessagesView();
void setSortingEnabled(bool enable);
// Model accessors.
MessagesProxyModel *model();
MessagesModel *sourceModel();
@ -33,13 +35,12 @@ class MessagesView : public QTreeView {
signals:
// TODO: dodělat signál.
void currentMessageChanged(/* const Message &message */);
void currentMessageChanged(const Message &message);
void currentMessageRemoved();
private:
MessagesProxyModel *m_proxyModel;
MessagesModel *m_sourceModel;
};
#endif // MESSAGESVIEW_H

View File

@ -167,21 +167,13 @@ void WebBrowser::navigateToUrl(const QUrl &url) {
}
}
void WebBrowser::navigateToMessage() {
void WebBrowser::navigateToMessage(const Message &message) {
// TODO: dodělat.
/*
m_webView->setHtml(SkinFactory::getInstance()->getCurrentMarkup().arg(message.m_data.at(MSG_DB_TITLE_INDEX).toString(),
tr("Check your internet connection or website address"),
QString(),
tr("This failure can be caused by:<br><ul>"
"<li>non-functional internet connection,</li>"
"<li>incorrect website address,</li>"
"<li>bad proxy server settings,</li>"
"<li>target destination outage,</li>"
"<li>many other things.</li>"
"</ul>"),
"aa"));
*/
m_webView->setHtml(SkinFactory::getInstance()->getCurrentMarkup().arg(message.m_title,
tr("Written by ") + message.m_author,
message.m_url,
message.m_contents,
message.m_updated.toString(Qt::ISODate)));
}
void WebBrowser::updateZoomGui() {

View File

@ -61,7 +61,7 @@ class WebBrowser : public TabContent {
void navigateToUrl(const QUrl &url);
// Navigates to message.
void navigateToMessage();
void navigateToMessage(const Message &message);
// Zoom manipulators.
void increaseZoom();