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);
// 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);
}

View File

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

View File

@ -9,6 +9,22 @@
class DatabaseFactory : public QObject {
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:
// Conctructor.
explicit DatabaseFactory(QObject *parent = 0);
@ -28,22 +44,6 @@ class DatabaseFactory : public QObject {
// Private singleton value.
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

View File

@ -31,7 +31,8 @@ void Debugging::debugHandler(QtMsgType type,
const QMessageLogContext &placement,
const QString &message) {
#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) {
case QtDebugMsg:

View File

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

View File

@ -23,6 +23,7 @@
#define APP_VERSION "@APP_VERSION@"
#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 MAX_ZOOM_FACTOR 10.0
#define ICON_SIZE_SETTINGS 16

View File

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

View File

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

View File

@ -20,6 +20,9 @@ class FeedDownloader : public QObject {
virtual ~FeedDownloader();
signals:
// Emitted if feed updates started.
void started();
// Emitted if all items from update queue are
// processed.
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> messages;
QSqlDatabase database = DatabaseFactory::getInstance()->addConnection(objectName());
QSqlDatabase database = DatabaseFactory::getInstance()->connection(objectName());
QSqlQuery query_read_msg(database);
query_read_msg.setForwardOnly(true);
query_read_msg.prepare("SELECT title, url, author, date_created, contents "
@ -274,7 +274,7 @@ void FeedsModel::loadFromDatabase() {
qDeleteAll(m_rootItem->childItems());
m_rootItem->clearChilds();
QSqlDatabase database = DatabaseFactory::getInstance()->addConnection(objectName());
QSqlDatabase database = DatabaseFactory::getInstance()->connection(objectName());
CategoryAssignment categories;
FeedAssignment feeds;
@ -385,7 +385,7 @@ QList<FeedsModelFeed*> FeedsModel::feedsForIndexes(const QModelIndexList &indexe
bool FeedsModel::markFeedsRead(const QList<FeedsModelFeed*> &feeds,
int read) {
QSqlDatabase db_handle = DatabaseFactory::getInstance()->addConnection(objectName());
QSqlDatabase db_handle = DatabaseFactory::getInstance()->connection(objectName());
if (!db_handle.transaction()) {
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,
int deleted) {
QSqlDatabase db_handle = DatabaseFactory::getInstance()->addConnection(objectName());
QSqlDatabase db_handle = DatabaseFactory::getInstance()->connection(objectName());
if (!db_handle.transaction()) {
qWarning("Starting transaction for feeds clearing.");

View File

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

View File

@ -52,19 +52,3 @@ FeedsModelCategory:: Type FeedsModelCategory::type() const {
void FeedsModelCategory::setType(const 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 <QDateTime>
class FeedsModelFeed;
@ -36,16 +34,8 @@ class FeedsModelCategory : public FeedsModelRootItem {
Type type() const;
void setType(const Type &type);
QString description() const;
void setDescription(const QString &description);
QDateTime creationDate() const;
void setCreationDate(const QDateTime &creation_date);
protected:
Type m_type;
QDateTime m_creationDate;
QString m_description;
};
#endif // FEEDSMODELCLASSICCATEGORY_H

View File

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

View File

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

View File

@ -103,6 +103,25 @@ void FeedsModelRootItem::clearChilds() {
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,
FeedsModelRootItem *rhs) {
return (lhs->kind() == rhs->kind()) && (lhs->id() == rhs->id());

View File

@ -3,6 +3,8 @@
#include <QIcon>
#include <QDateTime>
// Represents ROOT item of FeedsModel.
// NOTE: This class is derived to add functionality for
@ -49,6 +51,12 @@ class FeedsModelRootItem {
QString title() const;
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.
QList<FeedsModelRootItem *> childItems() const;
@ -64,6 +72,8 @@ class FeedsModelRootItem {
QString m_title;
int m_id;
QIcon m_icon;
QDateTime m_creationDate;
QString m_description;
QList<FeedsModelRootItem*> m_childItems;
FeedsModelRootItem *m_parentItem;
};

View File

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

View File

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

View File

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

View File

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

View File

@ -134,18 +134,10 @@ void FeedsView::markAllFeedsRead() {
}
void FeedsView::openSelectedFeedsInNewspaperMode() {
QList<FeedsModelFeed*> selected_feeds = selectedFeeds();
QList<Message> messages = m_sourceModel->messagesForFeeds(selected_feeds);
QList<Message> messages = m_sourceModel->messagesForFeeds(selectedFeeds());
if (!messages.isEmpty()) {
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>
</property>
<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>
</action>
<action name="m_actionMarkFeedsAsUnread">
@ -306,7 +306,7 @@
<string>Mark selected items unread</string>
</property>
<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>
</action>
<action name="m_actionDeleteSelectedMessages">
@ -322,7 +322,7 @@
<string>Clear selected items</string>
</property>
<property name="toolTip">
<string>Removes all messages from selected feeds.</string>
<string>Remove all messages from selected feeds.</string>
</property>
</action>
<action name="m_actionAddNewFeed">
@ -398,7 +398,7 @@
<string>View selected items in newspaper mode</string>
</property>
<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>
</action>
</widget>