2013-01-08 17:07:52 -05:00
|
|
|
/****************************************************************
|
|
|
|
* RetroShare is distributed under the following license:
|
|
|
|
*
|
|
|
|
* Copyright (C) 2012 by Thunder
|
|
|
|
*
|
|
|
|
* 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 <QMenu>
|
|
|
|
#include <QUrl>
|
|
|
|
#include <QClipboard>
|
|
|
|
#include <QDesktopServices>
|
|
|
|
|
|
|
|
#include "FeedReaderFeedItem.h"
|
|
|
|
#include "ui_FeedReaderFeedItem.h"
|
|
|
|
|
|
|
|
#include "FeedReaderNotify.h"
|
|
|
|
|
|
|
|
#include "util/DateTime.h"
|
|
|
|
#include "gui/feeds/FeedHolder.h"
|
|
|
|
|
|
|
|
/** Constructor */
|
|
|
|
FeedReaderFeedItem::FeedReaderFeedItem(RsFeedReader *feedReader, FeedReaderNotify *notify, FeedHolder *parent, const FeedInfo &feedInfo, const FeedMsgInfo &msgInfo)
|
2014-11-15 20:42:57 -05:00
|
|
|
: FeedItem(NULL), mFeedReader(feedReader), mNotify(notify), mParent(parent), ui(new Ui::FeedReaderFeedItem)
|
2013-01-08 17:07:52 -05:00
|
|
|
{
|
|
|
|
/* Invoke the Qt Designer generated object setup routine */
|
|
|
|
ui->setupUi(this);
|
|
|
|
|
|
|
|
setAttribute(Qt::WA_DeleteOnClose, true);
|
|
|
|
|
|
|
|
connect(ui->expandButton, SIGNAL(clicked(void)), this, SLOT(toggle(void)));
|
|
|
|
connect(ui->clearButton, SIGNAL(clicked(void)), this, SLOT(removeItem(void)));
|
|
|
|
connect(ui->readAndClearButton, SIGNAL(clicked()), this, SLOT(readAndClearItem()));
|
|
|
|
connect(ui->linkButton, SIGNAL(clicked()), this, SLOT(openLink()));
|
|
|
|
|
|
|
|
connect(mNotify, SIGNAL(msgChanged(QString,QString,int)), this, SLOT(msgChanged(QString,QString,int)), Qt::QueuedConnection);
|
|
|
|
|
|
|
|
ui->expandFrame->hide();
|
|
|
|
|
|
|
|
mFeedId = feedInfo.feedId;
|
|
|
|
mMsgId = msgInfo.msgId;
|
|
|
|
|
2013-01-10 17:51:04 -05:00
|
|
|
if (feedInfo.icon.empty()) {
|
|
|
|
ui->feedIconLabel->hide();
|
|
|
|
} else {
|
|
|
|
/* use icon from feed */
|
|
|
|
QPixmap pixmap;
|
|
|
|
if (pixmap.loadFromData(QByteArray::fromBase64(feedInfo.icon.c_str()))) {
|
|
|
|
ui->feedIconLabel->setPixmap(pixmap.scaled(16, 16, Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
|
|
|
|
} else {
|
|
|
|
ui->feedIconLabel->hide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-08 17:07:52 -05:00
|
|
|
ui->titleLabel->setText(QString::fromUtf8(feedInfo.name.c_str()));
|
|
|
|
ui->msgTitleLabel->setText(QString::fromUtf8(msgInfo.title.c_str()));
|
2013-01-21 19:11:43 -05:00
|
|
|
ui->descriptionLabel->setText(QString::fromUtf8((msgInfo.descriptionTransformed.empty() ? msgInfo.description : msgInfo.descriptionTransformed).c_str()));
|
2013-01-08 17:07:52 -05:00
|
|
|
|
|
|
|
ui->dateTimeLabel->setText(DateTime::formatLongDateTime(msgInfo.pubDate));
|
|
|
|
|
|
|
|
/* build menu for link button */
|
|
|
|
mLink = QString::fromUtf8(msgInfo.link.c_str());
|
|
|
|
if (mLink.isEmpty()) {
|
|
|
|
ui->linkButton->setEnabled(false);
|
|
|
|
} else {
|
|
|
|
QMenu *menu = new QMenu(this);
|
|
|
|
QAction *action = menu->addAction(tr("Open link in browser"), this, SLOT(openLink()));
|
|
|
|
menu->addAction(tr("Copy link to clipboard"), this, SLOT(copyLink()));
|
|
|
|
|
|
|
|
QFont font = action->font();
|
|
|
|
font.setBold(true);
|
|
|
|
action->setFont(font);
|
|
|
|
|
|
|
|
ui->linkButton->setMenu(menu);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
FeedReaderFeedItem::~FeedReaderFeedItem()
|
|
|
|
{
|
|
|
|
delete(ui);
|
|
|
|
}
|
|
|
|
|
|
|
|
void FeedReaderFeedItem::toggle()
|
|
|
|
{
|
2014-11-15 20:42:57 -05:00
|
|
|
expand(ui->expandFrame->isHidden());
|
|
|
|
}
|
|
|
|
|
2015-06-17 14:59:12 -04:00
|
|
|
void FeedReaderFeedItem::doExpand(bool open)
|
2014-11-15 20:42:57 -05:00
|
|
|
{
|
|
|
|
if (mParent) {
|
|
|
|
mParent->lockLayout(this, true);
|
|
|
|
}
|
2013-01-08 17:07:52 -05:00
|
|
|
|
2014-11-15 20:42:57 -05:00
|
|
|
if (open) {
|
2013-01-08 17:07:52 -05:00
|
|
|
ui->expandFrame->show();
|
|
|
|
ui->expandButton->setIcon(QIcon(QString(":/images/edit_remove24.png")));
|
|
|
|
ui->expandButton->setToolTip(tr("Hide"));
|
|
|
|
|
|
|
|
setMsgRead();
|
|
|
|
} else {
|
|
|
|
ui->expandFrame->hide();
|
|
|
|
ui->expandButton->setIcon(QIcon(QString(":/images/edit_add24.png")));
|
|
|
|
ui->expandButton->setToolTip(tr("Expand"));
|
|
|
|
}
|
|
|
|
|
2014-11-15 20:42:57 -05:00
|
|
|
emit sizeChanged(this);
|
|
|
|
|
|
|
|
if (mParent) {
|
|
|
|
mParent->lockLayout(this, false);
|
|
|
|
}
|
2013-01-08 17:07:52 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void FeedReaderFeedItem::removeItem()
|
|
|
|
{
|
|
|
|
mParent->lockLayout(this, true);
|
|
|
|
hide();
|
|
|
|
mParent->lockLayout(this, false);
|
|
|
|
|
|
|
|
if (mParent) {
|
|
|
|
mParent->deleteFeedItem(this, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********** SPECIFIC FUNCTIONS ***********************/
|
|
|
|
|
|
|
|
void FeedReaderFeedItem::readAndClearItem()
|
|
|
|
{
|
|
|
|
setMsgRead();
|
|
|
|
removeItem();
|
|
|
|
}
|
|
|
|
|
|
|
|
void FeedReaderFeedItem::setMsgRead()
|
|
|
|
{
|
|
|
|
disconnect(mNotify, SIGNAL(msgChanged(QString,QString,int)), this, SLOT(msgChanged(QString,QString,int)));
|
|
|
|
mFeedReader->setMessageRead(mFeedId, mMsgId, true);
|
|
|
|
connect(mNotify, SIGNAL(msgChanged(QString,QString,int)), this, SLOT(msgChanged(QString,QString,int)), Qt::QueuedConnection);
|
|
|
|
}
|
|
|
|
|
|
|
|
void FeedReaderFeedItem::msgChanged(const QString &feedId, const QString &msgId, int /*type*/)
|
|
|
|
{
|
|
|
|
if (feedId.toStdString() != mFeedId) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (msgId.toStdString() != mMsgId) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
FeedMsgInfo msgInfo;
|
|
|
|
if (!mFeedReader->getMsgInfo(mFeedId, mMsgId, msgInfo)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!msgInfo.flag.isnew) {
|
|
|
|
close();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void FeedReaderFeedItem::copyLink()
|
|
|
|
{
|
|
|
|
if (mLink.isEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QApplication::clipboard()->setText(mLink);
|
|
|
|
}
|
|
|
|
|
|
|
|
void FeedReaderFeedItem::openLink()
|
|
|
|
{
|
|
|
|
if (mLink.isEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QDesktopServices::openUrl(QUrl(mLink));
|
|
|
|
}
|