// This file is part of RSS Guard. // // Copyright (C) 2011-2016 by Martin Rotter // // 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 . #include "services/abstract/feed.h" #include "definitions/definitions.h" #include "miscellaneous/application.h" #include "miscellaneous/databasefactory.h" #include "services/abstract/serviceroot.h" #include Feed::Feed(RootItem *parent) : RootItem(parent), m_url(QString()), m_status(Normal), m_autoUpdateType(DefaultAutoUpdate), m_autoUpdateInitialInterval(DEFAULT_AUTO_UPDATE_INTERVAL), m_autoUpdateRemainingInterval(DEFAULT_AUTO_UPDATE_INTERVAL), m_totalCount(0), m_unreadCount(0) { setKind(RootItemKind::Feed); } Feed::~Feed() { } QList Feed::undeletedMessages() const { QList messages; int account_id = getParentServiceRoot()->accountId(); QSqlDatabase database = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings); QSqlQuery query_read_msg(database); query_read_msg.setForwardOnly(true); query_read_msg.prepare("SELECT * " "FROM Messages " "WHERE is_deleted = 0 AND is_pdeleted = 0 AND feed = :feed AND account_id = :account_id;"); query_read_msg.bindValue(QSL(":feed"), messageForeignKeyId()); query_read_msg.bindValue(QSL(":account_id"), account_id); if (query_read_msg.exec()) { while (query_read_msg.next()) { bool decoded; Message message = Message::fromSqlRecord(query_read_msg.record(), &decoded); if (decoded) { messages.append(message); } } } return messages; } QVariant Feed::data(int column, int role) const { switch (role) { case Qt::ForegroundRole: switch (status()) { case NewMessages: return QColor(Qt::blue); case Error: return QColor(Qt::red); default: return QVariant(); } default: return RootItem::data(column, role); } } int Feed::autoUpdateInitialInterval() const { return m_autoUpdateInitialInterval; } int Feed::countOfAllMessages() const { return m_totalCount; } int Feed::countOfUnreadMessages() const { return m_unreadCount; } void Feed::setCountOfAllMessages(int count_all_messages) { m_totalCount = count_all_messages; } void Feed::setCountOfUnreadMessages(int count_unread_messages) { m_unreadCount = count_unread_messages; } void Feed::setAutoUpdateInitialInterval(int auto_update_interval) { // If new initial auto-update interval is set, then // we should reset time that remains to the next auto-update. m_autoUpdateInitialInterval = auto_update_interval; m_autoUpdateRemainingInterval = auto_update_interval; } Feed::AutoUpdateType Feed::autoUpdateType() const { return m_autoUpdateType; } void Feed::setAutoUpdateType(Feed::AutoUpdateType auto_update_type) { m_autoUpdateType = auto_update_type; } int Feed::autoUpdateRemainingInterval() const { return m_autoUpdateRemainingInterval; } void Feed::setAutoUpdateRemainingInterval(int auto_update_remaining_interval) { m_autoUpdateRemainingInterval = auto_update_remaining_interval; }