Some methods cleaned, work mainly on model.

This commit is contained in:
Martin Rotter 2015-11-03 13:16:11 +01:00
parent f912e24b7d
commit a104844814
6 changed files with 39 additions and 32 deletions

View File

@ -19,10 +19,9 @@
#include "definitions/definitions.h" #include "definitions/definitions.h"
#include "services/abstract/feed.h" #include "services/abstract/feed.h"
#include "services/abstract/category.h"
#include "services/abstract/serviceroot.h" #include "services/abstract/serviceroot.h"
#include "services/standard/standardfeed.h" #include "services/standard/standardserviceroot.h"
#include "services/standard/standardcategory.h"
#include "services/standard/standardfeedsimportexportmodel.h"
#include "miscellaneous/textfactory.h" #include "miscellaneous/textfactory.h"
#include "miscellaneous/databasefactory.h" #include "miscellaneous/databasefactory.h"
#include "miscellaneous/iconfactory.h" #include "miscellaneous/iconfactory.h"
@ -269,18 +268,18 @@ QList<Feed*> FeedsModel::feedsForScheduledUpdate(bool auto_update_now) {
foreach (Feed *feed, allFeeds()) { foreach (Feed *feed, allFeeds()) {
switch (feed->autoUpdateType()) { switch (feed->autoUpdateType()) {
case StandardFeed::DontAutoUpdate: case Feed::DontAutoUpdate:
// Do not auto-update this feed ever. // Do not auto-update this feed ever.
continue; continue;
case StandardFeed::DefaultAutoUpdate: case Feed::DefaultAutoUpdate:
if (auto_update_now) { if (auto_update_now) {
feeds_for_update.append(feed); feeds_for_update.append(feed);
} }
break; break;
case StandardFeed::SpecificAutoUpdate: case Feed::SpecificAutoUpdate:
default: default:
int remaining_interval = feed->autoUpdateRemainingInterval(); int remaining_interval = feed->autoUpdateRemainingInterval();
@ -306,8 +305,7 @@ QList<Feed*> FeedsModel::feedsForScheduledUpdate(bool auto_update_now) {
QList<Message> FeedsModel::messagesForFeeds(const QList<Feed*> &feeds) { QList<Message> FeedsModel::messagesForFeeds(const QList<Feed*> &feeds) {
QList<Message> messages; QList<Message> messages;
QSqlDatabase database = qApp->database()->connection(objectName(), QSqlDatabase database = qApp->database()->connection(objectName(), DatabaseFactory::FromSettings);
DatabaseFactory::FromSettings);
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 "
@ -389,7 +387,7 @@ QModelIndex FeedsModel::indexForItem(RootItem *item) const {
bool FeedsModel::hasAnyFeedNewMessages() { bool FeedsModel::hasAnyFeedNewMessages() {
foreach (const Feed *feed, allFeeds()) { foreach (const Feed *feed, allFeeds()) {
if (feed->status() == StandardFeed::NewMessages) { if (feed->status() == Feed::NewMessages) {
return true; return true;
} }
} }
@ -424,15 +422,16 @@ void FeedsModel::reloadWholeLayout() {
} }
void FeedsModel::loadActivatedServiceAccounts() { void FeedsModel::loadActivatedServiceAccounts() {
// Delete all childs of the root node and clear them from the memory. // Iterate all globally available feed "service plugins".
qDeleteAll(m_rootItem->childItems());
m_rootItem->clearChildren();
foreach (ServiceEntryPoint *entry_point, qApp->feedServices()) { foreach (ServiceEntryPoint *entry_point, qApp->feedServices()) {
// Load all stored root nodes from the entry point and add those to the model. // Load all stored root nodes from the entry point and add those to the model.
QList<ServiceRoot*> roots = entry_point->initializeSubtree(this); QList<ServiceRoot*> roots = entry_point->initializeSubtree(this);
foreach (ServiceRoot *root, roots) { foreach (ServiceRoot *root, roots) {
if (SystemFactory::isInstanceOf<StandardServiceRoot>(root)) {
}
m_rootItem->appendChild(root); m_rootItem->appendChild(root);
} }
} }
@ -454,6 +453,7 @@ Feed *FeedsModel::feedForIndex(const QModelIndex &index) {
} }
} }
/*
QList<Feed*> FeedsModel::feedsForIndexes(const QModelIndexList &indexes) { QList<Feed*> FeedsModel::feedsForIndexes(const QModelIndexList &indexes) {
QList<Feed*> feeds; QList<Feed*> feeds;
@ -473,6 +473,7 @@ QList<Feed*> FeedsModel::feedsForIndexes(const QModelIndexList &indexes) {
return feeds; return feeds;
} }
*/
bool FeedsModel::markFeedsRead(const QList<Feed*> &feeds, int read) { bool FeedsModel::markFeedsRead(const QList<Feed*> &feeds, int read) {
QSqlDatabase db_handle = qApp->database()->connection(objectName(), DatabaseFactory::FromSettings); QSqlDatabase db_handle = qApp->database()->connection(objectName(), DatabaseFactory::FromSettings);
@ -564,10 +565,8 @@ QList<Feed*> FeedsModel::feedsForItem(RootItem *root) {
QList<Feed*> feeds; QList<Feed*> feeds;
foreach (RootItem *child, children) { foreach (RootItem *child, children) {
Feed *converted = dynamic_cast<Feed*>(child); if (child->kind() == RootItemKind::Feed) {
feeds.append(child->toFeed());
if (converted != NULL) {
feeds.append(converted);
} }
} }

View File

@ -27,9 +27,7 @@
class Category; class Category;
class StandardCategory;
class Feed; class Feed;
class FeedsImportExportModel;
class QTimer; class QTimer;
class FeedsModel : public QAbstractItemModel { class FeedsModel : public QAbstractItemModel {
@ -62,6 +60,7 @@ class FeedsModel : public QAbstractItemModel {
} }
// Removes item with given index. // Removes item with given index.
// NOTE: Also deletes item from memory.
bool removeItem(const QModelIndex &index); bool removeItem(const QModelIndex &index);
// Assigns item to the new parent. // Assigns item to the new parent.
@ -91,9 +90,9 @@ class FeedsModel : public QAbstractItemModel {
QList<Feed*> feedsForItem(RootItem *root); QList<Feed*> feedsForItem(RootItem *root);
// Returns list of ALL CHILD feeds which belong to given parent indexes. // Returns list of ALL CHILD feeds which belong to given parent indexes.
QList<Feed*> feedsForIndexes(const QModelIndexList &indexes); //QList<Feed*> feedsForIndexes(const QModelIndexList &indexes);
// Returns ALL CHILD feeds contained within single index. // Returns ALL RECURSIVE CHILD feeds contained within single index.
QList<Feed*> feedsForIndex(const QModelIndex &index); QList<Feed*> feedsForIndex(const QModelIndex &index);
// Returns pointer to feed if it lies on given index // Returns pointer to feed if it lies on given index
@ -144,7 +143,11 @@ class FeedsModel : public QAbstractItemModel {
// Is executed when next auto-update round could be done. // Is executed when next auto-update round could be done.
void executeNextAutoUpdate(); void executeNextAutoUpdate();
protected: signals:
// Emitted when model requests update of some feeds.
void feedsUpdateRequested(const QList<Feed*> feeds);
private:
// Returns converted ids of given feeds // Returns converted ids of given feeds
// which are suitable as IN clause for SQL queries. // which are suitable as IN clause for SQL queries.
QStringList textualFeedIds(const QList<Feed*> &feeds); QStringList textualFeedIds(const QList<Feed*> &feeds);
@ -152,11 +155,6 @@ class FeedsModel : public QAbstractItemModel {
// Loads feed/categories from the database. // Loads feed/categories from the database.
void loadActivatedServiceAccounts(); void loadActivatedServiceAccounts();
signals:
// Emitted when model requests update of some feeds.
void feedsUpdateRequested(const QList<Feed*> feeds);
private:
RootItem *m_rootItem; RootItem *m_rootItem;
QList<QString> m_headerData; QList<QString> m_headerData;
QList<QString> m_tooltipData; QList<QString> m_tooltipData;

View File

@ -86,6 +86,12 @@ class SystemFactory : public QObject {
// Tries to download list with new updates. // Tries to download list with new updates.
QPair<UpdateInfo, QNetworkReply::NetworkError> checkForUpdates(); QPair<UpdateInfo, QNetworkReply::NetworkError> checkForUpdates();
// Check whether given pointer belongs to instance of given class or not.
template<typename Base, typename T>
static bool isInstanceOf(T *ptr) {
return dynamic_cast<Base*>(ptr) != NULL;
}
// Checks if update is newer than current application version. // Checks if update is newer than current application version.
static bool isUpdateNewer(const QString &update_version); static bool isUpdateNewer(const QString &update_version);

View File

@ -58,6 +58,8 @@ class Feed : public RootItem {
// Updates counts of all/unread messages for this feed. // Updates counts of all/unread messages for this feed.
virtual void updateCounts(bool including_total_count = true, bool update_feed_statuses = true) = 0; virtual void updateCounts(bool including_total_count = true, bool update_feed_statuses = true) = 0;
inline int autoUpdateInitialInterval() const { inline int autoUpdateInitialInterval() const {
return m_autoUpdateInitialInterval; return m_autoUpdateInitialInterval;
} }

View File

@ -66,14 +66,10 @@ StandardFeed::StandardFeed(const StandardFeed &other)
m_passwordProtected = other.passwordProtected(); m_passwordProtected = other.passwordProtected();
m_username = other.username(); m_username = other.username();
m_password = other.password(); m_password = other.password();
m_status = other.status();
m_networkError = other.networkError(); m_networkError = other.networkError();
m_type = other.type(); m_type = other.type();
m_totalCount = other.countOfAllMessages(); m_totalCount = other.countOfAllMessages();
m_unreadCount = other.countOfUnreadMessages(); m_unreadCount = other.countOfUnreadMessages();
m_autoUpdateType = other.autoUpdateType();
m_autoUpdateInitialInterval = other.autoUpdateInitialInterval();
m_autoUpdateRemainingInterval = other.autoUpdateRemainingInterval();
m_encoding = other.encoding(); m_encoding = other.encoding();
m_url = other.url(); m_url = other.url();
m_kind = RootItemKind::Feed; m_kind = RootItemKind::Feed;
@ -84,6 +80,10 @@ StandardFeed::StandardFeed(const StandardFeed &other)
m_parentItem = other.parent(); m_parentItem = other.parent();
m_creationDate = other.creationDate(); m_creationDate = other.creationDate();
m_description = other.description(); m_description = other.description();
m_status = other.status();
m_autoUpdateType = other.autoUpdateType();
m_autoUpdateInitialInterval = other.autoUpdateInitialInterval();
m_autoUpdateRemainingInterval = other.autoUpdateRemainingInterval();
} }
StandardFeed::~StandardFeed() { StandardFeed::~StandardFeed() {

View File

@ -34,8 +34,10 @@
StandardServiceRoot::StandardServiceRoot(FeedsModel *feeds_model, RootItem *parent) StandardServiceRoot::StandardServiceRoot(FeedsModel *feeds_model, RootItem *parent)
: ServiceRoot(feeds_model, parent), m_recycleBin(new StandardRecycleBin(this)) { : ServiceRoot(feeds_model, parent), m_recycleBin(new StandardRecycleBin(this)) {
m_title = qApp->system()->getUsername() + "@" + APP_LOW_NAME; m_title = qApp->system()->getUsername() + QL1S("@") + QL1S(APP_LOW_NAME);
m_icon = StandardServiceEntryPoint().icon(); m_icon = StandardServiceEntryPoint().icon();
m_description = tr("This is obligatory service account for standard RSS/RDF/ATOM feeds.");
m_creationDate = QDateTime::currentDateTime();
loadFromDatabase(); loadFromDatabase();
} }