Work on models and many other things.
This commit is contained in:
parent
b94007b554
commit
292cfde3e2
@ -21,13 +21,13 @@ DROP TABLE IF EXISTS Feeds;
|
|||||||
-- !
|
-- !
|
||||||
CREATE TABLE IF NOT EXISTS Feeds (
|
CREATE TABLE IF NOT EXISTS Feeds (
|
||||||
id INTEGER PRIMARY KEY,
|
id INTEGER PRIMARY KEY,
|
||||||
title TEXT NOT NULL UNIQUE CHECK (title != ''),
|
title TEXT NOT NULL CHECK (title != ''),
|
||||||
description TEXT,
|
description TEXT,
|
||||||
date_created TEXT NOT NULL CHECK (date_created != ''),
|
date_created TEXT NOT NULL CHECK (date_created != ''),
|
||||||
icon BLOB,
|
icon BLOB,
|
||||||
category INTEGER NOT NULL CHECK (category >= -1),
|
category INTEGER NOT NULL CHECK (category >= -1),
|
||||||
encoding TEXT NOT NULL CHECK (encoding != ''),
|
encoding TEXT NOT NULL CHECK (encoding != ''),
|
||||||
url TEXT NOT NULL CHECK (url != ''),
|
url TEXT NOT NULL UNIQUE CHECK (url != ''),
|
||||||
type INTEGER NOT NULL
|
type INTEGER NOT NULL
|
||||||
);
|
);
|
||||||
-- !
|
-- !
|
||||||
@ -35,16 +35,16 @@ DROP TABLE IF EXISTS Messages;
|
|||||||
-- !
|
-- !
|
||||||
CREATE TABLE IF NOT EXISTS Messages (
|
CREATE TABLE IF NOT EXISTS Messages (
|
||||||
id INTEGER PRIMARY KEY,
|
id INTEGER PRIMARY KEY,
|
||||||
|
feed INTEGER NOT NULL,
|
||||||
title TEXT NOT NULL CHECK (title != ''),
|
title TEXT NOT NULL CHECK (title != ''),
|
||||||
owner INTEGER NOT NULL,
|
|
||||||
url TEXT,
|
url TEXT,
|
||||||
author TEXT,
|
author TEXT,
|
||||||
date_created TEXT NOT NULL CHECK (date_created != ''),
|
date_created TEXT NOT NULL CHECK (date_created != ''),
|
||||||
date_updated TEXT,
|
date_updated TEXT,
|
||||||
contents TEXT,
|
|
||||||
read INTEGER(1) NOT NULL CHECK (read >= 0 AND read <= 1) DEFAULT (0),
|
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),
|
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),
|
important INTEGER(1) NOT NULL CHECK (important >= 0 AND important <= 1) DEFAULT (0),
|
||||||
|
contents TEXT,
|
||||||
|
|
||||||
FOREIGN KEY (owner) REFERENCES Feeds (id)
|
FOREIGN KEY (feed) REFERENCES Feeds (id)
|
||||||
);
|
);
|
@ -110,20 +110,11 @@ QSqlDatabase DatabaseFactory::initialize(const QString &connection_name) {
|
|||||||
q.finish();
|
q.finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
m_initialized = true;
|
|
||||||
|
|
||||||
return database;
|
return database;
|
||||||
}
|
}
|
||||||
|
|
||||||
QSqlDatabase DatabaseFactory::addConnection(const QString &connection_name) {
|
QSqlDatabase DatabaseFactory::addConnection(const QString &connection_name) {
|
||||||
if (!m_initialized) {
|
|
||||||
// Initialize database file and return connection if it is not
|
|
||||||
// initialized yet.
|
|
||||||
return initialize(connection_name);
|
return initialize(connection_name);
|
||||||
}
|
|
||||||
else {
|
|
||||||
return QSqlDatabase::addDatabase(DATABASE_DRIVER, connection_name);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QSqlDatabase DatabaseFactory::getConnection(const QString &connection_name) {
|
QSqlDatabase DatabaseFactory::getConnection(const QString &connection_name) {
|
||||||
|
@ -22,9 +22,6 @@ class DatabaseFactory : public QObject {
|
|||||||
// Path to database file.
|
// Path to database file.
|
||||||
QString m_databasePath;
|
QString m_databasePath;
|
||||||
|
|
||||||
// True if database file is initialized, otherwise false.
|
|
||||||
bool m_initialized;
|
|
||||||
|
|
||||||
// Private singleton value.
|
// Private singleton value.
|
||||||
static QPointer<DatabaseFactory> s_instance;
|
static QPointer<DatabaseFactory> s_instance;
|
||||||
|
|
||||||
|
@ -34,9 +34,9 @@
|
|||||||
#define APP_DB_INIT_SPLIT "-- !\n"
|
#define APP_DB_INIT_SPLIT "-- !\n"
|
||||||
#define APP_DB_PATH "data/database/local"
|
#define APP_DB_PATH "data/database/local"
|
||||||
#define APP_DB_FILE "database.db"
|
#define APP_DB_FILE "database.db"
|
||||||
|
#define APP_DB_WEB_PATH "data/database/web"
|
||||||
|
|
||||||
#define APP_CFG_PATH "data/config"
|
#define APP_CFG_PATH "data/config"
|
||||||
#define APP_CFG_WEB_PATH "data/database/web"
|
|
||||||
#define APP_CFG_FILE "config.ini"
|
#define APP_CFG_FILE "config.ini"
|
||||||
#define APP_CFG_GUI "gui"
|
#define APP_CFG_GUI "gui"
|
||||||
#define APP_CFG_GEN "main"
|
#define APP_CFG_GEN "main"
|
||||||
|
@ -1,15 +1,35 @@
|
|||||||
#include "core/messagesmodel.h"
|
#include "core/messagesmodel.h"
|
||||||
|
#include "core/databasefactory.h"
|
||||||
|
|
||||||
|
|
||||||
MessagesModel::MessagesModel(QObject *parent) : QSqlTableModel(parent) {
|
MessagesModel::MessagesModel(QObject *parent)
|
||||||
|
: QSqlTableModel(parent,
|
||||||
|
DatabaseFactory::getInstance()->addConnection("MessagesModel")) {
|
||||||
setObjectName("MessagesModel");
|
setObjectName("MessagesModel");
|
||||||
|
setEditStrategy(QSqlTableModel::OnFieldChange);
|
||||||
|
|
||||||
setupHeaderData();
|
setupHeaderData();
|
||||||
|
|
||||||
|
setTable("Messages");
|
||||||
|
select();
|
||||||
|
}
|
||||||
|
|
||||||
|
MessagesModel::~MessagesModel() {
|
||||||
|
qDebug("Destroying MessagesModel instance.");
|
||||||
}
|
}
|
||||||
|
|
||||||
void MessagesModel::setupHeaderData() {
|
void MessagesModel::setupHeaderData() {
|
||||||
// TODO: Enhance this.
|
// TODO: Enhance this.
|
||||||
m_headerData << tr("aaa") <<
|
m_headerData << tr("Id") << tr("Feed") << tr("Title") <<
|
||||||
tr("bbb");
|
tr("URL") << tr("Author") << tr("Created on") <<
|
||||||
|
tr("Last updated on") << tr("Read") << tr("Deleted") <<
|
||||||
|
tr("Important") << tr("Contents");
|
||||||
|
}
|
||||||
|
|
||||||
|
Qt::ItemFlags MessagesModel::flags(const QModelIndex &index) const {
|
||||||
|
Q_UNUSED(index);
|
||||||
|
|
||||||
|
return Qt::ItemIsSelectable | Qt::ItemIsEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant MessagesModel::headerData(int section,
|
QVariant MessagesModel::headerData(int section,
|
||||||
|
@ -9,10 +9,13 @@ class MessagesModel : public QSqlTableModel {
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
// Constructors and destructors.
|
||||||
explicit MessagesModel(QObject *parent = 0);
|
explicit MessagesModel(QObject *parent = 0);
|
||||||
|
virtual ~MessagesModel();
|
||||||
|
|
||||||
|
// Model implementation.
|
||||||
QVariant headerData(int section, Qt::Orientation orientation, int role) const;
|
QVariant headerData(int section, Qt::Orientation orientation, int role) const;
|
||||||
|
Qt::ItemFlags flags(const QModelIndex &index) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void setupHeaderData();
|
void setupHeaderData();
|
||||||
|
@ -1,6 +1,19 @@
|
|||||||
#include "core/messagesproxymodel.h"
|
#include "core/messagesproxymodel.h"
|
||||||
|
#include "core/messagesmodel.h"
|
||||||
|
|
||||||
|
|
||||||
MessagesProxyModel::MessagesProxyModel(QObject *parent)
|
MessagesProxyModel::MessagesProxyModel(QObject *parent)
|
||||||
: QSortFilterProxyModel(parent) {
|
: QSortFilterProxyModel(parent) {
|
||||||
|
m_sourceModel = new MessagesModel(this);
|
||||||
|
|
||||||
|
setObjectName("MessagesProxyModel");
|
||||||
|
setSortRole(Qt::EditRole);
|
||||||
|
setSortCaseSensitivity(Qt::CaseInsensitive);
|
||||||
|
setFilterCaseSensitivity(Qt::CaseInsensitive);
|
||||||
|
setFilterKeyColumn(-1);
|
||||||
|
setSourceModel(m_sourceModel);
|
||||||
|
}
|
||||||
|
|
||||||
|
MessagesProxyModel::~MessagesProxyModel() {
|
||||||
|
qDebug("Destroying MessagesProxyModel instance.");
|
||||||
}
|
}
|
||||||
|
@ -4,16 +4,18 @@
|
|||||||
#include <QSortFilterProxyModel>
|
#include <QSortFilterProxyModel>
|
||||||
|
|
||||||
|
|
||||||
|
class MessagesModel;
|
||||||
|
|
||||||
class MessagesProxyModel : public QSortFilterProxyModel {
|
class MessagesProxyModel : public QSortFilterProxyModel {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
// Constructors and destructors.
|
||||||
explicit MessagesProxyModel(QObject *parent = 0);
|
explicit MessagesProxyModel(QObject *parent = 0);
|
||||||
|
virtual ~MessagesProxyModel();
|
||||||
|
|
||||||
signals:
|
private:
|
||||||
|
MessagesModel *m_sourceModel;
|
||||||
public slots:
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // MESSAGESPROXYMODEL_H
|
#endif // MESSAGESPROXYMODEL_H
|
||||||
|
@ -69,7 +69,7 @@ QSettings::Status Settings::setupSettings() {
|
|||||||
|
|
||||||
// TODO: Separate web settings into another unit.
|
// TODO: Separate web settings into another unit.
|
||||||
// Construct icon cache in the same path.
|
// Construct icon cache in the same path.
|
||||||
QString web_path = app_path + QDir::separator() + APP_CFG_WEB_PATH;
|
QString web_path = app_path + QDir::separator() + APP_DB_WEB_PATH;
|
||||||
QDir(web_path).mkpath(web_path);
|
QDir(web_path).mkpath(web_path);
|
||||||
QWebSettings::setIconDatabasePath(web_path);
|
QWebSettings::setIconDatabasePath(web_path);
|
||||||
|
|
||||||
@ -87,7 +87,7 @@ QSettings::Status Settings::setupSettings() {
|
|||||||
Settings::NonPortable, qApp);
|
Settings::NonPortable, qApp);
|
||||||
|
|
||||||
// Construct icon cache in the same path.
|
// Construct icon cache in the same path.
|
||||||
QString web_path = home_path + QDir::separator() + APP_CFG_WEB_PATH;
|
QString web_path = home_path + QDir::separator() + APP_DB_WEB_PATH;
|
||||||
QDir(web_path).mkpath(web_path);
|
QDir(web_path).mkpath(web_path);
|
||||||
QWebSettings::setIconDatabasePath(web_path);
|
QWebSettings::setIconDatabasePath(web_path);
|
||||||
|
|
||||||
|
@ -15,8 +15,7 @@ FeedMessageViewer::FeedMessageViewer(QWidget *parent)
|
|||||||
m_toolBar(new QToolBar(tr("Toolbar for messages"), this)),
|
m_toolBar(new QToolBar(tr("Toolbar for messages"), this)),
|
||||||
m_messagesView(new MessagesView(this)),
|
m_messagesView(new MessagesView(this)),
|
||||||
m_feedsView(new FeedsView(this)),
|
m_feedsView(new FeedsView(this)),
|
||||||
m_messagesBrowser(new WebBrowser(this))
|
m_messagesBrowser(new WebBrowser(this)) {
|
||||||
{
|
|
||||||
initialize();
|
initialize();
|
||||||
initializeViews();
|
initializeViews();
|
||||||
}
|
}
|
||||||
|
@ -482,8 +482,10 @@ void FormSettings::saveInterface() {
|
|||||||
IconThemeFactory::getInstance()->setCurrentIconTheme(selected_icon_theme);
|
IconThemeFactory::getInstance()->setCurrentIconTheme(selected_icon_theme);
|
||||||
|
|
||||||
// Save and activate new skin.
|
// Save and activate new skin.
|
||||||
|
if (m_ui->m_treeSkins->selectedItems().size() > 0) {
|
||||||
Skin active_skin = m_ui->m_treeSkins->currentItem()->data(0, Qt::UserRole).value<Skin>();
|
Skin active_skin = m_ui->m_treeSkins->currentItem()->data(0, Qt::UserRole).value<Skin>();
|
||||||
SkinFactory::getInstance()->setCurrentSkinName(active_skin.m_baseName);
|
SkinFactory::getInstance()->setCurrentSkinName(active_skin.m_baseName);
|
||||||
|
}
|
||||||
|
|
||||||
// Save tab settings.
|
// Save tab settings.
|
||||||
settings->setValue(APP_CFG_GUI, "tab_close_mid_button",
|
settings->setValue(APP_CFG_GUI, "tab_close_mid_button",
|
||||||
|
@ -90,7 +90,6 @@ void IconThemeFactory::loadCurrentIconTheme(bool notify_widgets) {
|
|||||||
qDebug("Installed icon themes are: %s.",
|
qDebug("Installed icon themes are: %s.",
|
||||||
qPrintable(installed_themes.join(", ")));
|
qPrintable(installed_themes.join(", ")));
|
||||||
|
|
||||||
|
|
||||||
if (installed_themes.contains(theme_name_from_settings)) {
|
if (installed_themes.contains(theme_name_from_settings)) {
|
||||||
// Desired icon theme is installed and can be loaded.
|
// Desired icon theme is installed and can be loaded.
|
||||||
qDebug("Loading icon theme '%s'.", qPrintable(theme_name_from_settings));
|
qDebug("Loading icon theme '%s'.", qPrintable(theme_name_from_settings));
|
||||||
|
@ -1,9 +1,23 @@
|
|||||||
#include "gui/messagesview.h"
|
#include "gui/messagesview.h"
|
||||||
|
#include "core/messagesproxymodel.h"
|
||||||
|
#include "core/messagesmodel.h"
|
||||||
|
|
||||||
|
|
||||||
MessagesView::MessagesView(QWidget *parent) : QTreeView(parent) {
|
MessagesView::MessagesView(QWidget *parent) : QTreeView(parent) {
|
||||||
|
m_proxyModel = new MessagesProxyModel(this);
|
||||||
|
|
||||||
|
setModel(m_proxyModel);
|
||||||
|
setupAppearance();
|
||||||
}
|
}
|
||||||
|
|
||||||
MessagesView::~MessagesView() {
|
MessagesView::~MessagesView() {
|
||||||
qDebug("Destroying MessagesView instance.");
|
qDebug("Destroying MessagesView instance.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MessagesView::setupAppearance() {
|
||||||
|
setAcceptDrops(false);
|
||||||
|
setDragEnabled(false);
|
||||||
|
setDragDropMode(QAbstractItemView::NoDragDrop);
|
||||||
|
setExpandsOnDoubleClick(false);
|
||||||
|
setRootIsDecorated(false);
|
||||||
|
}
|
||||||
|
@ -4,16 +4,21 @@
|
|||||||
#include <QTreeView>
|
#include <QTreeView>
|
||||||
|
|
||||||
|
|
||||||
|
class MessagesProxyModel;
|
||||||
|
|
||||||
class MessagesView : public QTreeView {
|
class MessagesView : public QTreeView {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
// Constructors and destructors.
|
||||||
explicit MessagesView(QWidget *parent = 0);
|
explicit MessagesView(QWidget *parent = 0);
|
||||||
virtual ~MessagesView();
|
virtual ~MessagesView();
|
||||||
|
|
||||||
signals:
|
protected:
|
||||||
|
void setupAppearance();
|
||||||
|
|
||||||
public slots:
|
private:
|
||||||
|
MessagesProxyModel *m_proxyModel;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user