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 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. RSS Guard tends to be independent software. It's free, it's open-source. RSS Guard accepts donations but only to SUPPORT its development.
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.

View file

@ -416,8 +416,7 @@ void FeedsModel::loadActivatedServiceAccounts() {
} }
QList<Feed*> FeedsModel::feedsForIndex(const QModelIndex &index) { QList<Feed*> FeedsModel::feedsForIndex(const QModelIndex &index) {
RootItem *item = itemForIndex(index); return itemForIndex(index)->getSubTreeFeeds();
return feedsForItem(item);
} }
Feed *FeedsModel::feedForIndex(const QModelIndex &index) { 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() { QList<Feed*> FeedsModel::allFeeds() {
return feedsForItem(m_rootItem); return m_rootItem->getSubTreeFeeds();
}
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;
} }
QList<Category*> FeedsModel::allCategories() { QList<Category*> FeedsModel::allCategories() {
return categoriesForItem(m_rootItem); return m_rootItem->getSubTreeCategories();
}
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;
} }

View file

@ -83,17 +83,9 @@ class FeedsModel : public QAbstractItemModel {
// Returns list of all categories contained in the model. // Returns list of all categories contained in the model.
QList<Category*> allCategories(); 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. // Returns list of all feeds contained in the model.
QList<Feed*> allFeeds(); 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. // Returns list of ALL CHILD feeds which belong to given parent indexes.
//QList<Feed*> feedsForIndexes(const QModelIndexList &indexes); //QList<Feed*> feedsForIndexes(const QModelIndexList &indexes);

View file

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

View file

@ -76,13 +76,11 @@ int RootItem::countOfAllMessages() const {
QList<RootItem*> RootItem::getSubTree() { QList<RootItem*> RootItem::getSubTree() {
QList<RootItem*> children; QList<RootItem*> children;
// Root itself is a CATEGORY or ROOT item.
QList<RootItem*> traversable_items; QList<RootItem*> traversable_items;
traversable_items.append(this); traversable_items.append(this);
// Iterate all nested categories. // Iterate all nested items.
while (!traversable_items.isEmpty()) { while (!traversable_items.isEmpty()) {
RootItem *active_item = traversable_items.takeFirst(); RootItem *active_item = traversable_items.takeFirst();
@ -93,6 +91,46 @@ QList<RootItem*> RootItem::getSubTree() {
return children; 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) { bool RootItem::removeChild(RootItem *child) {
return m_childItems.removeOne(child); return m_childItems.removeOne(child);
} }

View file

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

View file

@ -44,6 +44,11 @@ class Feed : public RootItem {
OtherError = 4 OtherError = 4
}; };
enum ReadStatus {
Read = 0,
Unread = 1
};
// Constructors. // Constructors.
explicit Feed(RootItem *parent = NULL); explicit Feed(RootItem *parent = NULL);
virtual ~Feed(); virtual ~Feed();
@ -63,6 +68,8 @@ class Feed : public RootItem {
// Get ALL undeleted messages from this feed in one single list. // Get ALL undeleted messages from this feed in one single list.
virtual QList<Message> undeletedMessages() const = 0; virtual QList<Message> undeletedMessages() const = 0;
//virtual bool markRead(ReadStatus read_status) = 0;
inline int autoUpdateInitialInterval() const { inline int autoUpdateInitialInterval() const {
return m_autoUpdateInitialInterval; 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. // TODO: předávat service root.
/* /*
QPointer<FormStandardCategoryDetails> form_pointer = new FormStandardCategoryDetails(qApp->mainForm()->tabWidget()->feedMessageViewer()->feedsView()->sourceModel(), QPointer<FormStandardCategoryDetails> form_pointer = new FormStandardCategoryDetails(qApp->mainForm()->tabWidget()->feedMessageViewer()->feedsView()->sourceModel(),
@ -137,6 +137,7 @@ void StandardCategory::editViaDialog() {
delete form_pointer.data(); delete form_pointer.data();
*/ */
return false;
} }
bool StandardCategory::removeItself() { bool StandardCategory::removeItself() {

View file

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

View file

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

View file

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

View file

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

View file

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