2018-11-04 09:48:33 -05:00
|
|
|
/*******************************************************************************
|
|
|
|
* plugins/FeedReader/gui/FeedReaderFeedNotify.cpp *
|
|
|
|
* *
|
|
|
|
* Copyright (C) 2012 by RetroShare Team <retroshare.project@gmail.com> *
|
|
|
|
* *
|
|
|
|
* This program is free software: you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU Affero General Public License as *
|
|
|
|
* published by the Free Software Foundation, either version 3 of the *
|
|
|
|
* License, or (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* This program 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 Affero General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU Affero General Public License *
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
|
|
|
|
* *
|
|
|
|
*******************************************************************************/
|
2013-01-08 17:07:52 -05:00
|
|
|
|
|
|
|
#include <QMutex>
|
2013-01-14 17:41:31 -05:00
|
|
|
#include <QDateTime>
|
|
|
|
#include <QBuffer>
|
2013-01-08 17:07:52 -05:00
|
|
|
|
|
|
|
#include "FeedReaderFeedNotify.h"
|
|
|
|
#include "FeedReaderNotify.h"
|
|
|
|
#include "FeedReaderFeedItem.h"
|
|
|
|
#include "gui/settings/rsharesettings.h"
|
|
|
|
#include "retroshare/rsiface.h"
|
|
|
|
|
|
|
|
FeedReaderFeedNotify::FeedReaderFeedNotify(RsFeedReader *feedReader, FeedReaderNotify *notify, QObject *parent) :
|
|
|
|
FeedNotify(parent), mFeedReader(feedReader), mNotify(notify)
|
|
|
|
{
|
|
|
|
mMutex = new QMutex();
|
|
|
|
|
|
|
|
connect(mNotify, SIGNAL(msgChanged(QString,QString,int)), this, SLOT(msgChanged(QString,QString,int)), Qt::QueuedConnection);
|
|
|
|
}
|
|
|
|
|
|
|
|
FeedReaderFeedNotify::~FeedReaderFeedNotify()
|
|
|
|
{
|
|
|
|
delete(mMutex);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool FeedReaderFeedNotify::hasSetting(QString &name)
|
|
|
|
{
|
|
|
|
name = tr("Feed Reader");
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool FeedReaderFeedNotify::notifyEnabled()
|
|
|
|
{
|
|
|
|
return Settings->valueFromGroup("FeedReader", "FeedNotifyEnable", false).toBool();
|
|
|
|
}
|
|
|
|
|
|
|
|
void FeedReaderFeedNotify::setNotifyEnabled(bool enabled)
|
|
|
|
{
|
|
|
|
Settings->setValueToGroup("FeedReader", "FeedNotifyEnable", enabled);
|
|
|
|
|
|
|
|
if (!enabled) {
|
|
|
|
/* remove pending feed items */
|
|
|
|
mMutex->lock();
|
|
|
|
mPendingNewsFeed.clear();
|
|
|
|
mMutex->unlock();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-08 07:22:59 -05:00
|
|
|
void FeedReaderFeedNotify::msgChanged(uint32_t feedId, const QString &msgId, int type)
|
2013-01-08 17:07:52 -05:00
|
|
|
{
|
2020-11-08 07:22:59 -05:00
|
|
|
if (feedId == 0 || msgId.isEmpty()) {
|
2013-01-08 17:07:52 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (type != NOTIFY_TYPE_ADD) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!notifyEnabled()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mMutex->lock();
|
|
|
|
|
2014-11-15 20:42:57 -05:00
|
|
|
FeedItemData feedItemData;
|
|
|
|
feedItemData.mFeedId = feedId;
|
|
|
|
feedItemData.mMsgId = msgId;
|
2013-01-08 17:07:52 -05:00
|
|
|
|
2014-11-15 20:42:57 -05:00
|
|
|
mPendingNewsFeed.push_back(feedItemData);
|
2013-01-08 17:07:52 -05:00
|
|
|
|
|
|
|
mMutex->unlock();
|
|
|
|
}
|
|
|
|
|
2014-11-15 20:42:57 -05:00
|
|
|
FeedItem *FeedReaderFeedNotify::feedItem(FeedHolder *parent)
|
2013-01-08 17:07:52 -05:00
|
|
|
{
|
|
|
|
bool msgPending = false;
|
|
|
|
FeedInfo feedInfo;
|
|
|
|
FeedMsgInfo msgInfo;
|
|
|
|
|
|
|
|
mMutex->lock();
|
|
|
|
while (!mPendingNewsFeed.empty()) {
|
2014-11-15 20:42:57 -05:00
|
|
|
FeedItemData feedItemData = mPendingNewsFeed.front();
|
2013-01-08 17:07:52 -05:00
|
|
|
mPendingNewsFeed.pop_front();
|
|
|
|
|
2020-11-08 07:22:59 -05:00
|
|
|
if (mFeedReader->getFeedInfo(feedItemData.mFeedId, feedInfo) &&
|
|
|
|
mFeedReader->getMsgInfo(feedItemData.mFeedId, feedItemData.mMsgId.toStdString(), msgInfo)) {
|
2013-01-08 17:07:52 -05:00
|
|
|
if (msgInfo.flag.isnew) {
|
|
|
|
msgPending = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mMutex->unlock();
|
|
|
|
|
|
|
|
if (!msgPending) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2020-11-08 07:22:59 -05:00
|
|
|
//TODO: parent?
|
|
|
|
return new FeedReaderFeedItem(mFeedReader, mNotify, feedInfo, msgInfo);
|
2013-01-08 17:07:52 -05:00
|
|
|
}
|
2013-01-14 17:41:31 -05:00
|
|
|
|
2014-11-15 20:42:57 -05:00
|
|
|
FeedItem *FeedReaderFeedNotify::testFeedItem(FeedHolder *parent)
|
2013-01-14 17:41:31 -05:00
|
|
|
{
|
|
|
|
FeedInfo feedInfo;
|
|
|
|
feedInfo.name = tr("Test").toUtf8().constData();
|
|
|
|
|
|
|
|
QByteArray faviconData;
|
|
|
|
QBuffer buffer(&faviconData);
|
|
|
|
buffer.open(QIODevice::WriteOnly);
|
|
|
|
if (QPixmap(":/images/Feed.png").scaled(16, 16, Qt::IgnoreAspectRatio, Qt::SmoothTransformation).save(&buffer, "ICO")) {
|
|
|
|
feedInfo.icon = faviconData.toBase64().constData();
|
|
|
|
}
|
|
|
|
buffer.close();
|
|
|
|
|
|
|
|
FeedMsgInfo msgInfo;
|
|
|
|
msgInfo.title = tr("Test message").toUtf8().constData();
|
|
|
|
msgInfo.description = tr("This is a test message.").toUtf8().constData();
|
|
|
|
msgInfo.pubDate = QDateTime::currentDateTime().toTime_t();
|
|
|
|
|
2020-11-08 07:22:59 -05:00
|
|
|
//TODO: parent?
|
|
|
|
return new FeedReaderFeedItem(mFeedReader, mNotify, feedInfo, msgInfo);
|
2013-01-14 17:41:31 -05:00
|
|
|
}
|