mirror of
https://github.com/martinrotter/rssguard.git
synced 2025-02-06 20:33:38 +01:00
Some methods cleaned, work mainly on model.
This commit is contained in:
parent
f912e24b7d
commit
a104844814
@ -19,10 +19,9 @@
|
||||
|
||||
#include "definitions/definitions.h"
|
||||
#include "services/abstract/feed.h"
|
||||
#include "services/abstract/category.h"
|
||||
#include "services/abstract/serviceroot.h"
|
||||
#include "services/standard/standardfeed.h"
|
||||
#include "services/standard/standardcategory.h"
|
||||
#include "services/standard/standardfeedsimportexportmodel.h"
|
||||
#include "services/standard/standardserviceroot.h"
|
||||
#include "miscellaneous/textfactory.h"
|
||||
#include "miscellaneous/databasefactory.h"
|
||||
#include "miscellaneous/iconfactory.h"
|
||||
@ -269,18 +268,18 @@ QList<Feed*> FeedsModel::feedsForScheduledUpdate(bool auto_update_now) {
|
||||
|
||||
foreach (Feed *feed, allFeeds()) {
|
||||
switch (feed->autoUpdateType()) {
|
||||
case StandardFeed::DontAutoUpdate:
|
||||
case Feed::DontAutoUpdate:
|
||||
// Do not auto-update this feed ever.
|
||||
continue;
|
||||
|
||||
case StandardFeed::DefaultAutoUpdate:
|
||||
case Feed::DefaultAutoUpdate:
|
||||
if (auto_update_now) {
|
||||
feeds_for_update.append(feed);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case StandardFeed::SpecificAutoUpdate:
|
||||
case Feed::SpecificAutoUpdate:
|
||||
default:
|
||||
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> messages;
|
||||
|
||||
QSqlDatabase database = qApp->database()->connection(objectName(),
|
||||
DatabaseFactory::FromSettings);
|
||||
QSqlDatabase database = qApp->database()->connection(objectName(), DatabaseFactory::FromSettings);
|
||||
QSqlQuery query_read_msg(database);
|
||||
query_read_msg.setForwardOnly(true);
|
||||
query_read_msg.prepare("SELECT title, url, author, date_created, contents "
|
||||
@ -389,7 +387,7 @@ QModelIndex FeedsModel::indexForItem(RootItem *item) const {
|
||||
|
||||
bool FeedsModel::hasAnyFeedNewMessages() {
|
||||
foreach (const Feed *feed, allFeeds()) {
|
||||
if (feed->status() == StandardFeed::NewMessages) {
|
||||
if (feed->status() == Feed::NewMessages) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -424,15 +422,16 @@ void FeedsModel::reloadWholeLayout() {
|
||||
}
|
||||
|
||||
void FeedsModel::loadActivatedServiceAccounts() {
|
||||
// Delete all childs of the root node and clear them from the memory.
|
||||
qDeleteAll(m_rootItem->childItems());
|
||||
m_rootItem->clearChildren();
|
||||
|
||||
// Iterate all globally available feed "service plugins".
|
||||
foreach (ServiceEntryPoint *entry_point, qApp->feedServices()) {
|
||||
// Load all stored root nodes from the entry point and add those to the model.
|
||||
QList<ServiceRoot*> roots = entry_point->initializeSubtree(this);
|
||||
|
||||
foreach (ServiceRoot *root, roots) {
|
||||
if (SystemFactory::isInstanceOf<StandardServiceRoot>(root)) {
|
||||
|
||||
}
|
||||
|
||||
m_rootItem->appendChild(root);
|
||||
}
|
||||
}
|
||||
@ -454,6 +453,7 @@ Feed *FeedsModel::feedForIndex(const QModelIndex &index) {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
QList<Feed*> FeedsModel::feedsForIndexes(const QModelIndexList &indexes) {
|
||||
QList<Feed*> feeds;
|
||||
|
||||
@ -473,6 +473,7 @@ QList<Feed*> FeedsModel::feedsForIndexes(const QModelIndexList &indexes) {
|
||||
|
||||
return feeds;
|
||||
}
|
||||
*/
|
||||
|
||||
bool FeedsModel::markFeedsRead(const QList<Feed*> &feeds, int read) {
|
||||
QSqlDatabase db_handle = qApp->database()->connection(objectName(), DatabaseFactory::FromSettings);
|
||||
@ -564,10 +565,8 @@ QList<Feed*> FeedsModel::feedsForItem(RootItem *root) {
|
||||
QList<Feed*> feeds;
|
||||
|
||||
foreach (RootItem *child, children) {
|
||||
Feed *converted = dynamic_cast<Feed*>(child);
|
||||
|
||||
if (converted != NULL) {
|
||||
feeds.append(converted);
|
||||
if (child->kind() == RootItemKind::Feed) {
|
||||
feeds.append(child->toFeed());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -27,9 +27,7 @@
|
||||
|
||||
|
||||
class Category;
|
||||
class StandardCategory;
|
||||
class Feed;
|
||||
class FeedsImportExportModel;
|
||||
class QTimer;
|
||||
|
||||
class FeedsModel : public QAbstractItemModel {
|
||||
@ -62,6 +60,7 @@ class FeedsModel : public QAbstractItemModel {
|
||||
}
|
||||
|
||||
// Removes item with given index.
|
||||
// NOTE: Also deletes item from memory.
|
||||
bool removeItem(const QModelIndex &index);
|
||||
|
||||
// Assigns item to the new parent.
|
||||
@ -91,9 +90,9 @@ class FeedsModel : public QAbstractItemModel {
|
||||
QList<Feed*> feedsForItem(RootItem *root);
|
||||
|
||||
// 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);
|
||||
|
||||
// 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.
|
||||
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
|
||||
// which are suitable as IN clause for SQL queries.
|
||||
QStringList textualFeedIds(const QList<Feed*> &feeds);
|
||||
@ -152,11 +155,6 @@ class FeedsModel : public QAbstractItemModel {
|
||||
// Loads feed/categories from the database.
|
||||
void loadActivatedServiceAccounts();
|
||||
|
||||
signals:
|
||||
// Emitted when model requests update of some feeds.
|
||||
void feedsUpdateRequested(const QList<Feed*> feeds);
|
||||
|
||||
private:
|
||||
RootItem *m_rootItem;
|
||||
QList<QString> m_headerData;
|
||||
QList<QString> m_tooltipData;
|
||||
|
@ -86,6 +86,12 @@ class SystemFactory : public QObject {
|
||||
// Tries to download list with new updates.
|
||||
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.
|
||||
static bool isUpdateNewer(const QString &update_version);
|
||||
|
||||
|
@ -58,6 +58,8 @@ class Feed : public RootItem {
|
||||
// Updates counts of all/unread messages for this feed.
|
||||
virtual void updateCounts(bool including_total_count = true, bool update_feed_statuses = true) = 0;
|
||||
|
||||
|
||||
|
||||
inline int autoUpdateInitialInterval() const {
|
||||
return m_autoUpdateInitialInterval;
|
||||
}
|
||||
|
@ -66,14 +66,10 @@ StandardFeed::StandardFeed(const StandardFeed &other)
|
||||
m_passwordProtected = other.passwordProtected();
|
||||
m_username = other.username();
|
||||
m_password = other.password();
|
||||
m_status = other.status();
|
||||
m_networkError = other.networkError();
|
||||
m_type = other.type();
|
||||
m_totalCount = other.countOfAllMessages();
|
||||
m_unreadCount = other.countOfUnreadMessages();
|
||||
m_autoUpdateType = other.autoUpdateType();
|
||||
m_autoUpdateInitialInterval = other.autoUpdateInitialInterval();
|
||||
m_autoUpdateRemainingInterval = other.autoUpdateRemainingInterval();
|
||||
m_encoding = other.encoding();
|
||||
m_url = other.url();
|
||||
m_kind = RootItemKind::Feed;
|
||||
@ -84,6 +80,10 @@ StandardFeed::StandardFeed(const StandardFeed &other)
|
||||
m_parentItem = other.parent();
|
||||
m_creationDate = other.creationDate();
|
||||
m_description = other.description();
|
||||
m_status = other.status();
|
||||
m_autoUpdateType = other.autoUpdateType();
|
||||
m_autoUpdateInitialInterval = other.autoUpdateInitialInterval();
|
||||
m_autoUpdateRemainingInterval = other.autoUpdateRemainingInterval();
|
||||
}
|
||||
|
||||
StandardFeed::~StandardFeed() {
|
||||
|
@ -34,8 +34,10 @@
|
||||
|
||||
StandardServiceRoot::StandardServiceRoot(FeedsModel *feeds_model, RootItem *parent)
|
||||
: 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_description = tr("This is obligatory service account for standard RSS/RDF/ATOM feeds.");
|
||||
m_creationDate = QDateTime::currentDateTime();
|
||||
|
||||
loadFromDatabase();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user