2014-02-26 07:41:40 +01:00
|
|
|
// This file is part of RSS Guard.
|
|
|
|
//
|
|
|
|
// Copyright (C) 2011-2014 by Martin Rotter <rotter.martinos@gmail.com>
|
|
|
|
//
|
|
|
|
// RSS Guard is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// RSS Guard is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with RSS Guard. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2013-12-21 21:08:52 +01:00
|
|
|
#include "core/feedsmodelrootitem.h"
|
2013-12-11 21:37:59 +01:00
|
|
|
|
2014-08-22 09:27:01 +02:00
|
|
|
#include "miscellaneous/application.h"
|
2014-09-04 15:52:42 +02:00
|
|
|
#include "core/feedsmodelcategory.h"
|
|
|
|
#include "core/feedsmodelfeed.h"
|
2013-12-21 21:08:52 +01:00
|
|
|
|
|
|
|
#include <QVariant>
|
2013-12-11 14:07:18 +01:00
|
|
|
|
|
|
|
|
2013-12-12 10:10:17 +01:00
|
|
|
FeedsModelRootItem::FeedsModelRootItem(FeedsModelRootItem *parent_item)
|
2013-12-22 11:29:10 +01:00
|
|
|
: m_kind(FeedsModelRootItem::RootItem),
|
2014-09-02 21:04:20 +02:00
|
|
|
m_id(NO_PARENT_CATEGORY),
|
|
|
|
m_title(QString()),
|
|
|
|
m_description(QString()),
|
|
|
|
m_icon(QIcon()),
|
|
|
|
m_creationDate(QDateTime()),
|
|
|
|
m_childItems(QList<FeedsModelRootItem*>()),
|
2013-12-22 11:29:10 +01:00
|
|
|
m_parentItem(parent_item) {
|
2014-03-22 18:29:01 +01:00
|
|
|
setupFonts();
|
2013-12-11 14:07:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
FeedsModelRootItem::~FeedsModelRootItem() {
|
2014-01-13 21:43:35 +01:00
|
|
|
qDeleteAll(m_childItems);
|
2013-12-12 15:07:17 +01:00
|
|
|
}
|
|
|
|
|
2014-03-22 18:29:01 +01:00
|
|
|
void FeedsModelRootItem::setupFonts() {
|
2014-04-17 13:49:38 +02:00
|
|
|
m_normalFont = Application::font("FeedsView");
|
2014-03-22 18:29:01 +01:00
|
|
|
m_boldFont = m_normalFont;
|
|
|
|
m_boldFont.setBold(true);
|
|
|
|
}
|
2013-12-11 14:07:18 +01:00
|
|
|
|
2013-12-11 18:54:09 +01:00
|
|
|
int FeedsModelRootItem::row() const {
|
2013-12-12 10:10:17 +01:00
|
|
|
if (m_parentItem) {
|
|
|
|
return m_parentItem->m_childItems.indexOf(const_cast<FeedsModelRootItem*>(this));
|
|
|
|
}
|
|
|
|
else {
|
2013-12-16 10:22:23 +01:00
|
|
|
// This item has no parent. Therefore, its row index is 0.
|
2013-12-12 10:10:17 +01:00
|
|
|
return 0;
|
|
|
|
}
|
2013-12-11 18:54:09 +01:00
|
|
|
}
|
|
|
|
|
2013-12-11 21:37:59 +01:00
|
|
|
QVariant FeedsModelRootItem::data(int column, int role) const {
|
2013-12-12 10:10:17 +01:00
|
|
|
Q_UNUSED(column)
|
|
|
|
Q_UNUSED(role)
|
2013-12-11 21:37:59 +01:00
|
|
|
|
2013-12-16 10:22:23 +01:00
|
|
|
// Do not return anything for the root item.
|
2013-12-11 21:37:59 +01:00
|
|
|
return QVariant();
|
|
|
|
}
|
2013-12-12 22:28:51 +01:00
|
|
|
|
|
|
|
int FeedsModelRootItem::countOfAllMessages() const {
|
2014-01-10 09:18:29 +01:00
|
|
|
int total_count = 0;
|
|
|
|
|
|
|
|
foreach (FeedsModelRootItem *child_item, m_childItems) {
|
2014-09-17 12:21:19 +02:00
|
|
|
if (child_item->kind() != FeedsModelRootItem::RecycleBin) {
|
|
|
|
total_count += child_item->countOfAllMessages();
|
|
|
|
}
|
2014-01-10 09:18:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return total_count;
|
2013-12-12 22:28:51 +01:00
|
|
|
}
|
|
|
|
|
2014-01-17 19:10:10 +01:00
|
|
|
bool FeedsModelRootItem::removeChild(FeedsModelRootItem *child) {
|
|
|
|
return m_childItems.removeOne(child);
|
|
|
|
}
|
|
|
|
|
2014-09-04 15:52:42 +02:00
|
|
|
FeedsModelRootItem *FeedsModelRootItem::child(FeedsModelRootItem::Kind kind_of_child, const QString &identifier) {
|
|
|
|
foreach (FeedsModelRootItem *child, childItems()) {
|
|
|
|
if (child->kind() == kind_of_child) {
|
2014-09-05 07:11:02 +02:00
|
|
|
if ((kind_of_child == Category && static_cast<FeedsModelCategory*>(child)->title() == identifier) ||
|
|
|
|
(kind_of_child == Feed && static_cast<FeedsModelFeed*>(child)->url() == identifier)) {
|
2014-09-04 15:52:42 +02:00
|
|
|
return child;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-12-12 22:28:51 +01:00
|
|
|
int FeedsModelRootItem::countOfUnreadMessages() const {
|
2014-01-10 09:18:29 +01:00
|
|
|
int total_count = 0;
|
|
|
|
|
|
|
|
foreach (FeedsModelRootItem *child_item, m_childItems) {
|
2014-09-17 12:21:19 +02:00
|
|
|
if (child_item->kind() != FeedsModelRootItem::RecycleBin) {
|
|
|
|
total_count += child_item->countOfUnreadMessages();
|
|
|
|
}
|
2014-01-10 09:18:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return total_count;
|
2013-12-12 22:28:51 +01:00
|
|
|
}
|
2013-12-13 16:35:52 +01:00
|
|
|
|
2014-01-10 08:36:08 +01:00
|
|
|
bool FeedsModelRootItem::removeChild(int index) {
|
|
|
|
if (index >= 0 && index < m_childItems.size()) {
|
|
|
|
m_childItems.removeAt(index);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return false;
|
|
|
|
}
|
2014-01-07 19:09:19 +01:00
|
|
|
}
|
|
|
|
|
2014-09-01 18:17:17 +02:00
|
|
|
bool FeedsModelRootItem::isEqual(FeedsModelRootItem *lhs, FeedsModelRootItem *rhs) {
|
2013-12-28 16:00:27 +01:00
|
|
|
return (lhs->kind() == rhs->kind()) && (lhs->id() == rhs->id());
|
|
|
|
}
|
|
|
|
|
2014-09-01 18:17:17 +02:00
|
|
|
bool FeedsModelRootItem::lessThan(FeedsModelRootItem *lhs, FeedsModelRootItem *rhs) {
|
2013-12-28 16:00:27 +01:00
|
|
|
if (lhs->kind() == rhs->kind()) {
|
|
|
|
return lhs->id() < rhs->id();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|