2013-01-08 17:07:52 -05:00
|
|
|
/****************************************************************
|
|
|
|
* RetroShare is distributed under the following license:
|
|
|
|
*
|
|
|
|
* Copyright (C) 2012 RetroShare Team
|
|
|
|
*
|
|
|
|
* This program 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 2
|
|
|
|
* 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 General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
|
|
|
****************************************************************/
|
|
|
|
|
|
|
|
#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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void FeedReaderFeedNotify::msgChanged(const QString &feedId, const QString &msgId, int type)
|
|
|
|
{
|
|
|
|
if (feedId.isEmpty() || msgId.isEmpty()) {
|
|
|
|
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();
|
|
|
|
|
2014-11-15 20:42:57 -05:00
|
|
|
if (mFeedReader->getFeedInfo(feedItemData.mFeedId.toStdString(), feedInfo) &&
|
|
|
|
mFeedReader->getMsgInfo(feedItemData.mFeedId.toStdString(), 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
return new FeedReaderFeedItem(mFeedReader, mNotify, parent, feedInfo, msgInfo);
|
|
|
|
}
|
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();
|
|
|
|
|
|
|
|
return new FeedReaderFeedItem(mFeedReader, mNotify, parent, feedInfo, msgInfo);
|
|
|
|
}
|