Tweaked README, refactored root item & model.

This commit is contained in:
Martin Rotter 2015-11-04 09:12:40 +01:00
parent d48873ab45
commit 0176a73e51
13 changed files with 75 additions and 58 deletions

View File

@ -117,6 +117,4 @@ RSS Guard is written in C++. It is pretty fast even with tons of messages loaded
Philosophy
----------
RSS Guard tends to be independent software. It's free, it's open-source. RSS Guard will never depend on other services - this includes online news aggregators like Feedly, The Old Reader and others.
That's why RSS Guard will never integrate those services unless someone else codes support for them on his own. Remember, RSS Guard supports online synchronization via MySQL/MariaDB or you can use Dropbox to synchronize SQLite data storage.
RSS Guard tends to be independent software. It's free, it's open-source. RSS Guard accepts donations but only to SUPPORT its development.

View File

@ -416,8 +416,7 @@ void FeedsModel::loadActivatedServiceAccounts() {
}
QList<Feed*> FeedsModel::feedsForIndex(const QModelIndex &index) {
RootItem *item = itemForIndex(index);
return feedsForItem(item);
return itemForIndex(index)->getSubTreeFeeds();
}
Feed *FeedsModel::feedForIndex(const QModelIndex &index) {
@ -535,35 +534,9 @@ bool FeedsModel::markFeedsDeleted(const QList<Feed*> &feeds, int deleted, bool r
}
QList<Feed*> FeedsModel::allFeeds() {
return feedsForItem(m_rootItem);
}
QList<Feed*> FeedsModel::feedsForItem(RootItem *root) {
QList<RootItem*> children = root->getSubTree();
QList<Feed*> feeds;
foreach (RootItem *child, children) {
if (child->kind() == RootItemKind::Feed) {
feeds.append(child->toFeed());
}
}
return feeds;
return m_rootItem->getSubTreeFeeds();
}
QList<Category*> FeedsModel::allCategories() {
return categoriesForItem(m_rootItem);
}
QList<Category*> FeedsModel::categoriesForItem(RootItem *root) {
QList<RootItem*> children = root->getSubTree();
QList<Category*> categories;
foreach (RootItem *child, children) {
if (child->kind() == RootItemKind::Category) {
categories.append(child->toCategory());
}
}
return categories;
return m_rootItem->getSubTreeCategories();
}

View File

@ -83,17 +83,9 @@ class FeedsModel : public QAbstractItemModel {
// Returns list of all categories contained in the model.
QList<Category*> allCategories();
// Get list of categories from tree with particular item
// as root.
QList<Category*> categoriesForItem(RootItem *root);
// Returns list of all feeds contained in the model.
QList<Feed*> allFeeds();
// Get list of feeds from tree with particular item
// as root.
QList<Feed*> feedsForItem(RootItem *root);
// Returns list of ALL CHILD feeds which belong to given parent indexes.
//QList<Feed*> feedsForIndexes(const QModelIndexList &indexes);

View File

@ -58,13 +58,11 @@ RootItem *FeedsSelection::selectedItem() const {
QString FeedsSelection::generateListOfIds() {
if (m_selectedItem != NULL &&
(m_selectedItem->kind() == RootItemKind::Feed || m_selectedItem->kind() == RootItemKind::Category)) {
QList<RootItem*> children = m_selectedItem->getSubTree();
QList<Feed*> children = m_selectedItem->getSubTreeFeeds();
QStringList stringy_ids;
foreach (RootItem *child, children) {
if (child->kind() == RootItemKind::Feed) {
stringy_ids.append(QString::number(child->id()));
}
foreach (Feed *child, children) {
stringy_ids.append(QString::number(child->id()));
}
return stringy_ids.join(QSL(", "));

View File

@ -76,13 +76,11 @@ int RootItem::countOfAllMessages() const {
QList<RootItem*> RootItem::getSubTree() {
QList<RootItem*> children;
// Root itself is a CATEGORY or ROOT item.
QList<RootItem*> traversable_items;
traversable_items.append(this);
// Iterate all nested categories.
// Iterate all nested items.
while (!traversable_items.isEmpty()) {
RootItem *active_item = traversable_items.takeFirst();
@ -93,6 +91,46 @@ QList<RootItem*> RootItem::getSubTree() {
return children;
}
QList<Category*> RootItem::getSubTreeCategories() {
QList<Category*> children;
QList<RootItem*> traversable_items;
traversable_items.append(this);
// Iterate all nested items.
while (!traversable_items.isEmpty()) {
RootItem *active_item = traversable_items.takeFirst();
if (active_item->kind() == RootItemKind::Category) {
children.append(active_item->toCategory());
}
traversable_items.append(active_item->childItems());
}
return children;
}
QList<Feed*> RootItem::getSubTreeFeeds() {
QList<Feed*> children;
QList<RootItem*> traversable_items;
traversable_items.append(this);
// Iterate all nested items.
while (!traversable_items.isEmpty()) {
RootItem *active_item = traversable_items.takeFirst();
if (active_item->kind() == RootItemKind::Feed) {
children.append(active_item->toFeed());
}
traversable_items.append(active_item->childItems());
}
return children;
}
bool RootItem::removeChild(RootItem *child) {
return m_childItems.removeOne(child);
}

View File

@ -67,15 +67,21 @@ class RootItem {
child->setParent(this);
}
// TODO: pracovat s těmito věcmi
virtual bool canBeEdited() {
return false;
}
virtual bool editViaDialog() {
return false;
}
virtual bool canBeDeleted() {
return false;
}
virtual void editViaDialog() {
virtual bool deleteViaGui() {
return false;
}
virtual int row() const;
@ -141,6 +147,8 @@ class RootItem {
// Returns flat list of all items from subtree where this item is a root.
// Returned list includes this item too.
QList<RootItem*> getSubTree();
QList<Category*> getSubTreeCategories();
QList<Feed*> getSubTreeFeeds();
// Removes particular child at given index.
// NOTE: Child is NOT freed from the memory.
@ -151,7 +159,7 @@ class RootItem {
return m_kind;
}
// Each item has icon.
// Each item can have icon.
inline QIcon icon() const {
return m_icon;
}

View File

@ -44,6 +44,11 @@ class Feed : public RootItem {
OtherError = 4
};
enum ReadStatus {
Read = 0,
Unread = 1
};
// Constructors.
explicit Feed(RootItem *parent = NULL);
virtual ~Feed();
@ -63,6 +68,8 @@ class Feed : public RootItem {
// Get ALL undeleted messages from this feed in one single list.
virtual QList<Message> undeletedMessages() const = 0;
//virtual bool markRead(ReadStatus read_status) = 0;
inline int autoUpdateInitialInterval() const {
return m_autoUpdateInitialInterval;
}

View File

@ -126,7 +126,7 @@ QVariant StandardCategory::data(int column, int role) const {
}
}
void StandardCategory::editViaDialog() {
bool StandardCategory::editViaDialog() {
// TODO: předávat service root.
/*
QPointer<FormStandardCategoryDetails> form_pointer = new FormStandardCategoryDetails(qApp->mainForm()->tabWidget()->feedMessageViewer()->feedsView()->sourceModel(),
@ -137,6 +137,7 @@ void StandardCategory::editViaDialog() {
delete form_pointer.data();
*/
return false;
}
bool StandardCategory::removeItself() {

View File

@ -50,7 +50,7 @@ class StandardCategory : public Category {
return true;
}
void editViaDialog();
bool editViaDialog();
// Removes category and all its children from persistent
// database.

View File

@ -98,7 +98,7 @@ int StandardFeed::countOfUnreadMessages() const {
return m_unreadCount;
}
void StandardFeed::editViaDialog() {
bool StandardFeed::editViaDialog() {
// TODO: fix passing of the model
/*
@ -108,6 +108,7 @@ void StandardFeed::editViaDialog() {
delete form_pointer.data();
*/
return false;
}
QList<Message> StandardFeed::undeletedMessages() const {

View File

@ -66,7 +66,7 @@ class StandardFeed : public Feed {
return true;
}
void editViaDialog();
bool editViaDialog();
QList<Message> undeletedMessages() const;

View File

@ -33,8 +33,9 @@ TtRssServiceRoot::TtRssServiceRoot(FeedsModel *feeds_model, RootItem *parent) :
TtRssServiceRoot::~TtRssServiceRoot() {
}
void TtRssServiceRoot::editViaDialog() {
bool TtRssServiceRoot::editViaDialog() {
// TODO: zobrazit custom edit dialog pro ttrss
return false;
}
bool TtRssServiceRoot::canBeEdited() {

View File

@ -26,7 +26,7 @@
class FeedsModel;
class TtRssServiceRoot : public ServiceRoot {
Q_DECLARE_TR_FUNCTIONS(StandardServiceRoot)
Q_DECLARE_TR_FUNCTIONS(TtRssServiceRoot)
public:
explicit TtRssServiceRoot(FeedsModel *feeds_model, RootItem *parent = NULL);
@ -34,7 +34,7 @@ class TtRssServiceRoot : public ServiceRoot {
bool canBeEdited();
bool canBeDeleted();
void editViaDialog();
bool editViaDialog();
QVariant data(int column, int role) const;
};