Cleanups.

This commit is contained in:
Martin Rotter 2014-01-05 21:36:25 +01:00
parent acf5e63f7c
commit 57f651f970
23 changed files with 86 additions and 120 deletions

View File

@ -54,7 +54,8 @@ QNetworkReply *BaseNetworkAccessManager::createRequest(QNetworkAccessManager::Op
new_request.setAttribute(QNetworkRequest::HttpPipeliningAllowedAttribute, true); new_request.setAttribute(QNetworkRequest::HttpPipeliningAllowedAttribute, true);
// Setup custom user-agent. // Setup custom user-agent.
new_request.setRawHeader("User-Agent", QString(APP_USERAGENT).toLocal8Bit()); new_request.setRawHeader(USER_AGENT_HTTP_HEADER,
QString(APP_USERAGENT).toLocal8Bit());
return QNetworkAccessManager::createRequest(op, new_request, outgoingData); return QNetworkAccessManager::createRequest(op, new_request, outgoingData);
} }

View File

@ -129,7 +129,7 @@ QSqlDatabase DatabaseFactory::initialize(const QString &connection_name) {
return database; return database;
} }
QSqlDatabase DatabaseFactory::addConnection(const QString &connection_name) { QSqlDatabase DatabaseFactory::connection(const QString &connection_name) {
if (!m_initialized) { if (!m_initialized) {
m_initialized = true; m_initialized = true;
return initialize(connection_name); return initialize(connection_name);

View File

@ -9,6 +9,22 @@
class DatabaseFactory : public QObject { class DatabaseFactory : public QObject {
Q_OBJECT Q_OBJECT
public:
// Destructor.
virtual ~DatabaseFactory();
// Returns absolute file path to database file.
QString getDatabasePath();
// NOTE: This always returns OPENED database.
QSqlDatabase connection(const QString &connection_name);
// Removes connection.
void removeConnection(const QString &connection_name);
// Singleton getter.
static DatabaseFactory *getInstance();
private: private:
// Conctructor. // Conctructor.
explicit DatabaseFactory(QObject *parent = 0); explicit DatabaseFactory(QObject *parent = 0);
@ -28,22 +44,6 @@ class DatabaseFactory : public QObject {
// Private singleton value. // Private singleton value.
static QPointer<DatabaseFactory> s_instance; static QPointer<DatabaseFactory> s_instance;
public:
// Destructor.
virtual ~DatabaseFactory();
// Returns absolute file path to database file.
QString getDatabasePath();
// NOTE: This returns OPENED database.
QSqlDatabase addConnection(const QString &connection_name);
// Removes connection.
void removeConnection(const QString &connection_name);
// Singleton getter.
static DatabaseFactory *getInstance();
}; };
#endif // DATABASEFACTORY_H #endif // DATABASEFACTORY_H

View File

@ -31,7 +31,8 @@ void Debugging::debugHandler(QtMsgType type,
const QMessageLogContext &placement, const QMessageLogContext &placement,
const QString &message) { const QString &message) {
#ifndef QT_NO_DEBUG_OUTPUT #ifndef QT_NO_DEBUG_OUTPUT
const char *file = qPrintable(QString(placement.file).section(QDir::separator(), -1)); const char *file = qPrintable(QString(placement.file).section(QDir::separator(),
-1));
switch (type) { switch (type) {
case QtDebugMsg: case QtDebugMsg:

View File

@ -5,13 +5,9 @@
class Debugging { class Debugging {
private:
explicit Debugging();
public: public:
// Specifies format of output console messages. // Specifies format of output console messages.
// Macros: // NOTE: QT_NO_DEBUG_OUTPUT - disables debug outputs completely!!!
// QT_NO_DEBUG_OUTPUT - disables debug outputs completely!!!
#if QT_VERSION >= 0x050000 #if QT_VERSION >= 0x050000
static void debugHandler(QtMsgType type, static void debugHandler(QtMsgType type,
const QMessageLogContext &placement, const QMessageLogContext &placement,
@ -20,6 +16,10 @@ class Debugging {
static void debugHandler(QtMsgType type, static void debugHandler(QtMsgType type,
const char *message); const char *message);
#endif #endif
private:
// Constructor.
explicit Debugging();
}; };
#endif // DEBUGGING_H #endif // DEBUGGING_H

View File

@ -23,6 +23,7 @@
#define APP_VERSION "@APP_VERSION@" #define APP_VERSION "@APP_VERSION@"
#define APP_USERAGENT QString("@APP_NAME@/@APP_VERSION@ (@APP_URL@) on @CMAKE_SYSTEM@; Webkit/") + qWebKitVersion() #define APP_USERAGENT QString("@APP_NAME@/@APP_VERSION@ (@APP_URL@) on @CMAKE_SYSTEM@; Webkit/") + qWebKitVersion()
#define USER_AGENT_HTTP_HEADER "User-Agent"
#define TEXT_TITLE_LIMIT 30 #define TEXT_TITLE_LIMIT 30
#define MAX_ZOOM_FACTOR 10.0 #define MAX_ZOOM_FACTOR 10.0
#define ICON_SIZE_SETTINGS 16 #define ICON_SIZE_SETTINGS 16

View File

@ -7,9 +7,6 @@
class QAction; class QAction;
class DynamicShortcuts { class DynamicShortcuts {
private:
explicit DynamicShortcuts();
public: public:
// Checks the application settings and then initializes shortcut of // Checks the application settings and then initializes shortcut of
// each action from actions from the settings. // each action from actions from the settings.
@ -18,6 +15,10 @@ class DynamicShortcuts {
// Stores shortcut of each action from actions into the application // Stores shortcut of each action from actions into the application
// settings. // settings.
static void save(const QList<QAction*> actions); static void save(const QList<QAction*> actions);
private:
// Constructor.
explicit DynamicShortcuts();
}; };
#endif // DYNAMICSHORTCUTS_H #endif // DYNAMICSHORTCUTS_H

View File

@ -18,6 +18,8 @@ void FeedDownloader::updateFeeds(const QList<FeedsModelFeed *> &feeds) {
qDebug().nospace() << "Performing feed updates in thread: \'" << qDebug().nospace() << "Performing feed updates in thread: \'" <<
QThread::currentThreadId() << "\'."; QThread::currentThreadId() << "\'.";
emit started();
for (int i = 0, total = feeds.size(); i < total; i++) { for (int i = 0, total = feeds.size(); i < total; i++) {
feeds.at(i)->update(); feeds.at(i)->update();

View File

@ -20,6 +20,9 @@ class FeedDownloader : public QObject {
virtual ~FeedDownloader(); virtual ~FeedDownloader();
signals: signals:
// Emitted if feed updates started.
void started();
// Emitted if all items from update queue are // Emitted if all items from update queue are
// processed. // processed.
void finished(); void finished();

View File

@ -134,7 +134,7 @@ int FeedsModel::rowCount(const QModelIndex &parent) const {
QList<Message> FeedsModel::messagesForFeeds(const QList<FeedsModelFeed *> &feeds) { QList<Message> FeedsModel::messagesForFeeds(const QList<FeedsModelFeed *> &feeds) {
QList<Message> messages; QList<Message> messages;
QSqlDatabase database = DatabaseFactory::getInstance()->addConnection(objectName()); QSqlDatabase database = DatabaseFactory::getInstance()->connection(objectName());
QSqlQuery query_read_msg(database); QSqlQuery query_read_msg(database);
query_read_msg.setForwardOnly(true); query_read_msg.setForwardOnly(true);
query_read_msg.prepare("SELECT title, url, author, date_created, contents " query_read_msg.prepare("SELECT title, url, author, date_created, contents "
@ -274,7 +274,7 @@ void FeedsModel::loadFromDatabase() {
qDeleteAll(m_rootItem->childItems()); qDeleteAll(m_rootItem->childItems());
m_rootItem->clearChilds(); m_rootItem->clearChilds();
QSqlDatabase database = DatabaseFactory::getInstance()->addConnection(objectName()); QSqlDatabase database = DatabaseFactory::getInstance()->connection(objectName());
CategoryAssignment categories; CategoryAssignment categories;
FeedAssignment feeds; FeedAssignment feeds;
@ -385,7 +385,7 @@ QList<FeedsModelFeed*> FeedsModel::feedsForIndexes(const QModelIndexList &indexe
bool FeedsModel::markFeedsRead(const QList<FeedsModelFeed*> &feeds, bool FeedsModel::markFeedsRead(const QList<FeedsModelFeed*> &feeds,
int read) { int read) {
QSqlDatabase db_handle = DatabaseFactory::getInstance()->addConnection(objectName()); QSqlDatabase db_handle = DatabaseFactory::getInstance()->connection(objectName());
if (!db_handle.transaction()) { if (!db_handle.transaction()) {
qWarning("Starting transaction for feeds read change."); qWarning("Starting transaction for feeds read change.");
@ -421,7 +421,7 @@ bool FeedsModel::markFeedsRead(const QList<FeedsModelFeed*> &feeds,
bool FeedsModel::markFeedsDeleted(const QList<FeedsModelFeed *> &feeds, bool FeedsModel::markFeedsDeleted(const QList<FeedsModelFeed *> &feeds,
int deleted) { int deleted) {
QSqlDatabase db_handle = DatabaseFactory::getInstance()->addConnection(objectName()); QSqlDatabase db_handle = DatabaseFactory::getInstance()->connection(objectName());
if (!db_handle.transaction()) { if (!db_handle.transaction()) {
qWarning("Starting transaction for feeds clearing."); qWarning("Starting transaction for feeds clearing.");

View File

@ -111,7 +111,6 @@ class FeedsModel : public QAbstractItemModel {
QList<QString> m_headerData; QList<QString> m_headerData;
QList<QString> m_tooltipData; QList<QString> m_tooltipData;
QIcon m_countsIcon; QIcon m_countsIcon;
}; };
#endif // FEEDSMODEL_H #endif // FEEDSMODEL_H

View File

@ -52,19 +52,3 @@ FeedsModelCategory:: Type FeedsModelCategory::type() const {
void FeedsModelCategory::setType(const Type &type) { void FeedsModelCategory::setType(const Type &type) {
m_type = type; m_type = type;
} }
QString FeedsModelCategory::description() const {
return m_description;
}
void FeedsModelCategory::setDescription(const QString &description) {
m_description = description;
}
QDateTime FeedsModelCategory::creationDate() const {
return m_creationDate;
}
void FeedsModelCategory::setCreationDate(const QDateTime &creation_date) {
m_creationDate = creation_date;
}

View File

@ -3,8 +3,6 @@
#include "core/feedsmodelrootitem.h" #include "core/feedsmodelrootitem.h"
#include <QDateTime>
class FeedsModelFeed; class FeedsModelFeed;
@ -36,16 +34,8 @@ class FeedsModelCategory : public FeedsModelRootItem {
Type type() const; Type type() const;
void setType(const Type &type); void setType(const Type &type);
QString description() const;
void setDescription(const QString &description);
QDateTime creationDate() const;
void setCreationDate(const QDateTime &creation_date);
protected: protected:
Type m_type; Type m_type;
QDateTime m_creationDate;
QString m_description;
}; };
#endif // FEEDSMODELCLASSICCATEGORY_H #endif // FEEDSMODELCLASSICCATEGORY_H

View File

@ -25,18 +25,10 @@ int FeedsModelFeed::countOfAllMessages() const {
return m_totalCount; return m_totalCount;
} }
void FeedsModelFeed::setCountOfAllMessages(int count) {
m_totalCount = count;
}
int FeedsModelFeed::countOfUnreadMessages() const { int FeedsModelFeed::countOfUnreadMessages() const {
return m_unreadCount; return m_unreadCount;
} }
void FeedsModelFeed::setCountOfUnreadMessages(int count) {
m_unreadCount = count;
}
void FeedsModelFeed::update() { void FeedsModelFeed::update() {
} }
@ -66,7 +58,7 @@ QString FeedsModelFeed::typeToString(FeedsModelFeed::Type type) {
} }
void FeedsModelFeed::updateCounts(bool including_total_count) { void FeedsModelFeed::updateCounts(bool including_total_count) {
QSqlDatabase database = DatabaseFactory::getInstance()->addConnection("FeedsModelFeed"); QSqlDatabase database = DatabaseFactory::getInstance()->connection("FeedsModelFeed");
QSqlQuery query_all(database); QSqlQuery query_all(database);
query_all.setForwardOnly(true); query_all.setForwardOnly(true);

View File

@ -28,10 +28,7 @@ class FeedsModelFeed : public FeedsModelRootItem {
// NOTE: For feeds, counts are stored internally // NOTE: For feeds, counts are stored internally
// and can be updated from the database. // and can be updated from the database.
int countOfAllMessages() const; int countOfAllMessages() const;
void setCountOfAllMessages(int count);
int countOfUnreadMessages() const; int countOfUnreadMessages() const;
void setCountOfUnreadMessages(int count);
// Each feed can be "updated". // Each feed can be "updated".
// NOTE: This method is used in the "update worker". // NOTE: This method is used in the "update worker".

View File

@ -103,6 +103,25 @@ void FeedsModelRootItem::clearChilds() {
m_childItems.clear(); m_childItems.clear();
} }
QDateTime FeedsModelRootItem::creationDate() const {
return m_creationDate;
}
void FeedsModelRootItem::setCreationDate(const QDateTime &creation_date) {
m_creationDate = creation_date;
}
QString FeedsModelRootItem::description() const {
return m_description;
}
void FeedsModelRootItem::setDescription(const QString &description) {
m_description = description;
}
bool FeedsModelRootItem::isEqual(FeedsModelRootItem *lhs, bool FeedsModelRootItem::isEqual(FeedsModelRootItem *lhs,
FeedsModelRootItem *rhs) { FeedsModelRootItem *rhs) {
return (lhs->kind() == rhs->kind()) && (lhs->id() == rhs->id()); return (lhs->kind() == rhs->kind()) && (lhs->id() == rhs->id());

View File

@ -3,6 +3,8 @@
#include <QIcon> #include <QIcon>
#include <QDateTime>
// Represents ROOT item of FeedsModel. // Represents ROOT item of FeedsModel.
// NOTE: This class is derived to add functionality for // NOTE: This class is derived to add functionality for
@ -49,6 +51,12 @@ class FeedsModelRootItem {
QString title() const; QString title() const;
void setTitle(const QString &title); void setTitle(const QString &title);
QDateTime creationDate() const;
void setCreationDate(const QDateTime &creation_date);
QString description() const;
void setDescription(const QString &description);
// Access to children. // Access to children.
QList<FeedsModelRootItem *> childItems() const; QList<FeedsModelRootItem *> childItems() const;
@ -64,6 +72,8 @@ class FeedsModelRootItem {
QString m_title; QString m_title;
int m_id; int m_id;
QIcon m_icon; QIcon m_icon;
QDateTime m_creationDate;
QString m_description;
QList<FeedsModelRootItem*> m_childItems; QList<FeedsModelRootItem*> m_childItems;
FeedsModelRootItem *m_parentItem; FeedsModelRootItem *m_parentItem;
}; };

View File

@ -21,13 +21,12 @@ QVariant FeedsModelStandardCategory::data(int column, int role) const {
switch (role) { switch (role) {
case Qt::ToolTipRole: case Qt::ToolTipRole:
if (column == FDS_MODEL_TITLE_INDEX) { if (column == FDS_MODEL_TITLE_INDEX) {
return QObject::tr("%1\n\n" return QObject::tr("%1 (standard category)\n"
"Category type: standard\n" "%2%3").arg(m_title,
"Creation date: %2%3").arg(m_title, m_description,
m_creationDate.toString(Qt::DefaultLocaleShortDate), m_childItems.size() == 0 ?
m_childItems.size() == 0 ? QObject::tr("\n\nThis category does not contain any nested items.") :
QObject::tr("\n\nThis category does not contain any nested items.") : "");
"");
} }
else if (column == FDS_MODEL_COUNTS_INDEX) { else if (column == FDS_MODEL_COUNTS_INDEX) {
return QObject::tr("%n unread message(s).", "", countOfUnreadMessages()); return QObject::tr("%n unread message(s).", "", countOfUnreadMessages());

View File

@ -22,10 +22,6 @@ FeedsModelStandardFeed::~FeedsModelStandardFeed() {
qDebug("Destroying FeedsModelStandardFeed instance."); qDebug("Destroying FeedsModelStandardFeed instance.");
} }
void FeedsModelStandardFeed::setDescription(const QString &description) {
m_description = description;
}
FeedsModelStandardFeed *FeedsModelStandardFeed::loadFromRecord(const QSqlRecord &record) { FeedsModelStandardFeed *FeedsModelStandardFeed::loadFromRecord(const QSqlRecord &record) {
FeedsModelStandardFeed *feed = new FeedsModelStandardFeed(NULL); FeedsModelStandardFeed *feed = new FeedsModelStandardFeed(NULL);
@ -42,14 +38,6 @@ FeedsModelStandardFeed *FeedsModelStandardFeed::loadFromRecord(const QSqlRecord
return feed; return feed;
} }
QDateTime FeedsModelStandardFeed::creationDate() const {
return m_creationDate;
}
void FeedsModelStandardFeed::setCreationDate(const QDateTime &creation_date) {
m_creationDate = creation_date;
}
QString FeedsModelStandardFeed::encoding() const { QString FeedsModelStandardFeed::encoding() const {
return m_encoding; return m_encoding;
} }
@ -74,10 +62,6 @@ void FeedsModelStandardFeed::setLanguage(const QString &language) {
m_language = language; m_language = language;
} }
QString FeedsModelStandardFeed::description() const {
return m_description;
}
QVariant FeedsModelStandardFeed::data(int column, int role) const { QVariant FeedsModelStandardFeed::data(int column, int role) const {
switch (role) { switch (role) {
case Qt::DisplayRole: case Qt::DisplayRole:
@ -114,13 +98,12 @@ QVariant FeedsModelStandardFeed::data(int column, int role) const {
case Qt::ToolTipRole: case Qt::ToolTipRole:
if (column == FDS_MODEL_TITLE_INDEX) { if (column == FDS_MODEL_TITLE_INDEX) {
return QObject::tr("%1\n\n" return QObject::tr("%1 (%2)\n"
"Feed type: %2\n" "%3\n\n"
"URL: %3\n"
"Encoding: %4\n" "Encoding: %4\n"
"Language: %5").arg(m_title, "Language: %5").arg(m_title,
FeedsModelFeed::typeToString(m_type), FeedsModelFeed::typeToString(m_type),
m_url, m_description,
m_encoding, m_encoding,
m_language.isEmpty() ? m_language.isEmpty() ?
"-" : "-" :
@ -206,7 +189,7 @@ void FeedsModelStandardFeed::update() {
void FeedsModelStandardFeed::updateMessages(const QList<Message> &messages) { void FeedsModelStandardFeed::updateMessages(const QList<Message> &messages) {
int feed_id = id(), message_id; int feed_id = id(), message_id;
qint64 message_creation_date; qint64 message_creation_date;
QSqlDatabase database = DatabaseFactory::getInstance()->addConnection("FeedsModelStandardFeed"); QSqlDatabase database = DatabaseFactory::getInstance()->connection("FeedsModelStandardFeed");
// Prepare queries. // Prepare queries.
QSqlQuery query_select(database); QSqlQuery query_select(database);

View File

@ -25,12 +25,6 @@ class FeedsModelStandardFeed : public FeedsModelFeed {
void update(); void update();
// Various getters/setters. // Various getters/setters.
QString description() const;
void setDescription(const QString &description);
QDateTime creationDate() const;
void setCreationDate(const QDateTime &creation_date);
QString encoding() const; QString encoding() const;
void setEncoding(const QString &encoding); void setEncoding(const QString &encoding);
@ -50,10 +44,8 @@ class FeedsModelStandardFeed : public FeedsModelFeed {
void updateMessages(const QList<Message> &messages); void updateMessages(const QList<Message> &messages);
private: private:
QDateTime m_creationDate;
QString m_encoding; QString m_encoding;
QString m_url; QString m_url;
QString m_description;
QString m_language; QString m_language;
}; };

View File

@ -13,7 +13,7 @@
MessagesModel::MessagesModel(QObject *parent) MessagesModel::MessagesModel(QObject *parent)
: QSqlTableModel(parent, : QSqlTableModel(parent,
DatabaseFactory::getInstance()->addConnection("MessagesModel")) { DatabaseFactory::getInstance()->connection("MessagesModel")) {
setObjectName("MessagesModel"); setObjectName("MessagesModel");
setupFonts(); setupFonts();

View File

@ -134,18 +134,10 @@ void FeedsView::markAllFeedsRead() {
} }
void FeedsView::openSelectedFeedsInNewspaperMode() { void FeedsView::openSelectedFeedsInNewspaperMode() {
QList<FeedsModelFeed*> selected_feeds = selectedFeeds(); QList<Message> messages = m_sourceModel->messagesForFeeds(selectedFeeds());
QList<Message> messages = m_sourceModel->messagesForFeeds(selected_feeds);
if (!messages.isEmpty()) { if (!messages.isEmpty()) {
emit newspaperModeRequested(messages); emit newspaperModeRequested(messages);
// Moreover, mark those feeds as read because they were opened in
// newspaper mode, thus, they are read.
m_sourceModel->markFeedsRead(selected_feeds, 1);
updateCountsOfAllFeeds(false);
emit feedsNeedToBeReloaded(1);
} }
} }

View File

@ -298,7 +298,7 @@
<string>Mark &amp;selected items read</string> <string>Mark &amp;selected items read</string>
</property> </property>
<property name="toolTip"> <property name="toolTip">
<string>Marks all messages (without message filters) from selected feeds as read.</string> <string>Mark all messages (without message filters) from selected feeds as read.</string>
</property> </property>
</action> </action>
<action name="m_actionMarkFeedsAsUnread"> <action name="m_actionMarkFeedsAsUnread">
@ -306,7 +306,7 @@
<string>Mark selected items unread</string> <string>Mark selected items unread</string>
</property> </property>
<property name="toolTip"> <property name="toolTip">
<string>Marks all messages (without message filters) from selected feeds as unread.</string> <string>Mark all messages (without message filters) from selected feeds as unread.</string>
</property> </property>
</action> </action>
<action name="m_actionDeleteSelectedMessages"> <action name="m_actionDeleteSelectedMessages">
@ -322,7 +322,7 @@
<string>Clear selected items</string> <string>Clear selected items</string>
</property> </property>
<property name="toolTip"> <property name="toolTip">
<string>Removes all messages from selected feeds.</string> <string>Remove all messages from selected feeds.</string>
</property> </property>
</action> </action>
<action name="m_actionAddNewFeed"> <action name="m_actionAddNewFeed">
@ -398,7 +398,7 @@
<string>View selected items in newspaper mode</string> <string>View selected items in newspaper mode</string>
</property> </property>
<property name="toolTip"> <property name="toolTip">
<string>Displays all messages from selected feeds/categories in a new &quot;newspaper mode&quot; tab. All selected feeds are marked as read.</string> <string>Displays all messages from selected feeds/categories in a new &quot;newspaper mode&quot; tab. Note that messages are not set as read automatically.</string>
</property> </property>
</action> </action>
</widget> </widget>