mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-02 06:06:10 -04:00
Added api for news feeds to the plugin interface.
Added news feeds to the FeedReader plugin. Recompile needed. git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@6066 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
f12473f7f7
commit
a60422069c
21 changed files with 1080 additions and 99 deletions
|
@ -55,8 +55,8 @@
|
|||
#define ROLE_FEED_ERROR Qt::UserRole + 8
|
||||
#define ROLE_FEED_DEACTIVATED Qt::UserRole + 9
|
||||
|
||||
FeedReaderDialog::FeedReaderDialog(RsFeedReader *feedReader, QWidget *parent)
|
||||
: MainPage(parent), mFeedReader(feedReader), ui(new Ui::FeedReaderDialog)
|
||||
FeedReaderDialog::FeedReaderDialog(RsFeedReader *feedReader, FeedReaderNotify *notify, QWidget *parent)
|
||||
: MainPage(parent), mFeedReader(feedReader), mNotify(notify), ui(new Ui::FeedReaderDialog)
|
||||
{
|
||||
/* Invoke the Qt Designer generated object setup routine */
|
||||
ui->setupUi(this);
|
||||
|
@ -65,8 +65,6 @@ FeedReaderDialog::FeedReaderDialog(RsFeedReader *feedReader, QWidget *parent)
|
|||
mOpenFeedIds = NULL;
|
||||
mMessageWidget = NULL;
|
||||
|
||||
mNotify = new FeedReaderNotify();
|
||||
mFeedReader->setNotify(mNotify);
|
||||
connect(mNotify, SIGNAL(feedChanged(QString,int)), this, SLOT(feedChanged(QString,int)));
|
||||
connect(mNotify, SIGNAL(msgChanged(QString,QString,int)), this, SLOT(msgChanged(QString,QString,int)));
|
||||
|
||||
|
@ -126,9 +124,6 @@ FeedReaderDialog::~FeedReaderDialog()
|
|||
delete(mFeedCompareRole);
|
||||
delete(ui);
|
||||
|
||||
mFeedReader->setNotify(NULL);
|
||||
delete(mNotify);
|
||||
|
||||
if (mOpenFeedIds) {
|
||||
delete mOpenFeedIds;
|
||||
mOpenFeedIds = NULL;
|
||||
|
|
|
@ -40,7 +40,7 @@ class FeedReaderDialog : public MainPage
|
|||
Q_OBJECT
|
||||
|
||||
public:
|
||||
FeedReaderDialog(RsFeedReader *feedReader, QWidget *parent = 0);
|
||||
FeedReaderDialog(RsFeedReader *feedReader, FeedReaderNotify *notify, QWidget *parent = 0);
|
||||
~FeedReaderDialog();
|
||||
|
||||
virtual UserNotify *getUserNotify(QObject *parent);
|
||||
|
|
166
plugins/FeedReader/gui/FeedReaderFeedItem.cpp
Normal file
166
plugins/FeedReader/gui/FeedReaderFeedItem.cpp
Normal file
|
@ -0,0 +1,166 @@
|
|||
/****************************************************************
|
||||
* 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)
|
||||
: QWidget(NULL), mFeedReader(feedReader), mNotify(notify), mParent(parent), ui(new Ui::FeedReaderFeedItem)
|
||||
{
|
||||
/* 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;
|
||||
|
||||
ui->titleLabel->setText(QString::fromUtf8(feedInfo.name.c_str()));
|
||||
ui->msgTitleLabel->setText(QString::fromUtf8(msgInfo.title.c_str()));
|
||||
ui->descriptionLabel->setText(QString::fromUtf8(msgInfo.description.c_str()));
|
||||
|
||||
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()
|
||||
{
|
||||
mParent->lockLayout(this, true);
|
||||
|
||||
if (ui->expandFrame->isHidden()) {
|
||||
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"));
|
||||
}
|
||||
|
||||
mParent->lockLayout(this, false);
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
70
plugins/FeedReader/gui/FeedReaderFeedItem.h
Normal file
70
plugins/FeedReader/gui/FeedReaderFeedItem.h
Normal file
|
@ -0,0 +1,70 @@
|
|||
/****************************************************************
|
||||
* RetroShare is distributed under the following license:
|
||||
*
|
||||
* Copyright (C) 2013 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.
|
||||
****************************************************************/
|
||||
|
||||
#ifndef _FEEDREADERFEEDITEM_H
|
||||
#define _FEEDREADERFEEDITEM_H
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
namespace Ui {
|
||||
class FeedReaderFeedItem;
|
||||
}
|
||||
|
||||
class RsFeedReader;
|
||||
class FeedReaderNotify;
|
||||
class FeedHolder;
|
||||
class FeedInfo;
|
||||
class FeedMsgInfo;
|
||||
|
||||
class FeedReaderFeedItem : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
FeedReaderFeedItem(RsFeedReader *feedReader, FeedReaderNotify *notify, FeedHolder *parent, const FeedInfo &feedInfo, const FeedMsgInfo &msgInfo);
|
||||
~FeedReaderFeedItem();
|
||||
|
||||
private slots:
|
||||
/* default stuff */
|
||||
void removeItem();
|
||||
void toggle();
|
||||
|
||||
void readAndClearItem();
|
||||
void copyLink();
|
||||
void openLink();
|
||||
|
||||
void msgChanged(const QString &feedId, const QString &msgId, int type);
|
||||
|
||||
private:
|
||||
void setMsgRead();
|
||||
|
||||
RsFeedReader *mFeedReader;
|
||||
FeedReaderNotify *mNotify;
|
||||
FeedHolder *mParent;
|
||||
|
||||
std::string mFeedId;
|
||||
std::string mMsgId;
|
||||
QString mLink;
|
||||
|
||||
Ui::FeedReaderFeedItem *ui;
|
||||
};
|
||||
|
||||
#endif // _FEEDREADERFEEDITEM_H
|
321
plugins/FeedReader/gui/FeedReaderFeedItem.ui
Normal file
321
plugins/FeedReader/gui/FeedReaderFeedItem.ui
Normal file
|
@ -0,0 +1,321 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>FeedReaderFeedItem</class>
|
||||
<widget class="QWidget" name="FeedReaderFeedItem">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>629</width>
|
||||
<height>121</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_4">
|
||||
<property name="leftMargin">
|
||||
<number>1</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>1</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>1</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>1</number>
|
||||
</property>
|
||||
<property name="horizontalSpacing">
|
||||
<number>6</number>
|
||||
</property>
|
||||
<property name="verticalSpacing">
|
||||
<number>1</number>
|
||||
</property>
|
||||
<item row="0" column="0">
|
||||
<widget class="QFrame" name="frame">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="autoFillBackground">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::Box</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Sunken</enum>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_3">
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_6">
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_4">
|
||||
<item>
|
||||
<widget class="QLabel" name="logoLabel">
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>48</width>
|
||||
<height>48</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="pixmap">
|
||||
<pixmap resource="FeedReader_images.qrc">:/images/FeedReader.png</pixmap>
|
||||
</property>
|
||||
<property name="scaledContents">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
||||
<item>
|
||||
<widget class="QLabel" name="titleLabel">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="font">
|
||||
<font>
|
||||
<pointsize>11</pointsize>
|
||||
<weight>75</weight>
|
||||
<bold>true</bold>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string notr="true">Feed name</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="dateTimeLabel">
|
||||
<property name="font">
|
||||
<font>
|
||||
<weight>75</weight>
|
||||
<bold>true</bold>
|
||||
<stylestrategy>PreferAntialias</stylestrategy>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string notr="true">DateTime</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<property name="spacing">
|
||||
<number>8</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QLabel" name="msgTitleLabel">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>16777215</width>
|
||||
<height>60</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string notr="true"><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
|
||||
<html><head><meta name="qrichtext" content="1" /><style type="text/css">
|
||||
p, li { white-space: pre-wrap; }
|
||||
</style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;">
|
||||
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:8pt; color:#666666;">Short Description</span></p></body></html></string>
|
||||
</property>
|
||||
<property name="wordWrap">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="openExternalLinks">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="linkButton">
|
||||
<property name="focusPolicy">
|
||||
<enum>Qt::NoFocus</enum>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="FeedReader_images.qrc">
|
||||
<normaloff>:/images/Link.png</normaloff>:/images/Link.png</iconset>
|
||||
</property>
|
||||
<property name="popupMode">
|
||||
<enum>QToolButton::MenuButtonPopup</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="expandButton">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>24</width>
|
||||
<height>16777215</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="focusPolicy">
|
||||
<enum>Qt::NoFocus</enum>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Expand</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../../../retroshare-gui/src/gui/images.qrc">
|
||||
<normaloff>:/images/edit_add24.png</normaloff>:/images/edit_add24.png</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="readAndClearButton">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>24</width>
|
||||
<height>16777215</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="focusPolicy">
|
||||
<enum>Qt::NoFocus</enum>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Set as read and remove item</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../../../retroshare-gui/src/gui/images.qrc">
|
||||
<normaloff>:/images/cancel.png</normaloff>:/images/cancel.png</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="clearButton">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>24</width>
|
||||
<height>16777215</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="focusPolicy">
|
||||
<enum>Qt::NoFocus</enum>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Remove Item</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../../../retroshare-gui/src/gui/images.qrc">
|
||||
<normaloff>:/images/close_normal.png</normaloff>:/images/close_normal.png</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QFrame" name="expandFrame">
|
||||
<layout class="QVBoxLayout">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QFrame" name="msgFrame">
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::Box</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Sunken</enum>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<property name="leftMargin">
|
||||
<number>5</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>5</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>5</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>5</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QLabel" name="descriptionLabel">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="wordWrap">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="margin">
|
||||
<number>6</number>
|
||||
</property>
|
||||
<property name="indent">
|
||||
<number>-1</number>
|
||||
</property>
|
||||
<property name="openExternalLinks">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="textInteractionFlags">
|
||||
<set>Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources>
|
||||
<include location="FeedReader_images.qrc"/>
|
||||
<include location="../../../retroshare-gui/src/gui/images.qrc"/>
|
||||
</resources>
|
||||
<connections/>
|
||||
</ui>
|
118
plugins/FeedReader/gui/FeedReaderFeedNotify.cpp
Normal file
118
plugins/FeedReader/gui/FeedReaderFeedNotify.cpp
Normal file
|
@ -0,0 +1,118 @@
|
|||
/****************************************************************
|
||||
* 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>
|
||||
|
||||
#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();
|
||||
|
||||
FeedItem feedItem;
|
||||
feedItem.mFeedId = feedId;
|
||||
feedItem.mMsgId = msgId;
|
||||
|
||||
mPendingNewsFeed.push_back(feedItem);
|
||||
|
||||
mMutex->unlock();
|
||||
}
|
||||
|
||||
QWidget *FeedReaderFeedNotify::feedItem(FeedHolder *parent)
|
||||
{
|
||||
bool msgPending = false;
|
||||
FeedInfo feedInfo;
|
||||
FeedMsgInfo msgInfo;
|
||||
|
||||
mMutex->lock();
|
||||
while (!mPendingNewsFeed.empty()) {
|
||||
FeedItem feedItem = mPendingNewsFeed.front();
|
||||
mPendingNewsFeed.pop_front();
|
||||
|
||||
if (mFeedReader->getFeedInfo(feedItem.mFeedId.toStdString(), feedInfo) &&
|
||||
mFeedReader->getMsgInfo(feedItem.mFeedId.toStdString(), feedItem.mMsgId.toStdString(), msgInfo)) {
|
||||
if (msgInfo.flag.isnew) {
|
||||
msgPending = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
mMutex->unlock();
|
||||
|
||||
if (!msgPending) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return new FeedReaderFeedItem(mFeedReader, mNotify, parent, feedInfo, msgInfo);
|
||||
}
|
65
plugins/FeedReader/gui/FeedReaderFeedNotify.h
Normal file
65
plugins/FeedReader/gui/FeedReaderFeedNotify.h
Normal file
|
@ -0,0 +1,65 @@
|
|||
/****************************************************************
|
||||
* 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.
|
||||
****************************************************************/
|
||||
|
||||
#ifndef FEEDREADERFEEDNOTIFY_H
|
||||
#define FEEDREADERFEEDNOTIFY_H
|
||||
|
||||
#include "gui/common/FeedNotify.h"
|
||||
|
||||
class RsFeedReader;
|
||||
class FeedReaderNotify;
|
||||
class QMutex;
|
||||
|
||||
class FeedReaderFeedNotify : public FeedNotify
|
||||
{
|
||||
Q_OBJECT
|
||||
protected:
|
||||
class FeedItem
|
||||
{
|
||||
public:
|
||||
FeedItem() {}
|
||||
|
||||
public:
|
||||
QString mFeedId;
|
||||
QString mMsgId;
|
||||
};
|
||||
|
||||
public:
|
||||
FeedReaderFeedNotify(RsFeedReader *feedReader, FeedReaderNotify *notify, QObject *parent = 0);
|
||||
~FeedReaderFeedNotify();
|
||||
|
||||
virtual bool hasSetting(QString &name);
|
||||
virtual bool notifyEnabled();
|
||||
virtual void setNotifyEnabled(bool enabled);
|
||||
virtual QWidget *feedItem(FeedHolder *parent);
|
||||
|
||||
private slots:
|
||||
void msgChanged(const QString &feedId, const QString &msgId, int type);
|
||||
|
||||
private:
|
||||
RsFeedReader *mFeedReader;
|
||||
FeedReaderNotify *mNotify;
|
||||
|
||||
QMutex *mMutex;
|
||||
QList<FeedItem> mPendingNewsFeed;
|
||||
};
|
||||
|
||||
#endif // FEEDREADERFEEDNOTIFY_H
|
|
@ -42,40 +42,22 @@ bool FeedReaderUserNotify::hasSetting(QString &name)
|
|||
|
||||
bool FeedReaderUserNotify::notifyEnabled()
|
||||
{
|
||||
bool enable = true;
|
||||
|
||||
Settings->beginGroup(QString("FeedReader"));
|
||||
enable = Settings->value("TrayNotifyEnable", enable).toBool();
|
||||
Settings->endGroup();
|
||||
|
||||
return enable;
|
||||
return Settings->valueFromGroup("FeedReader", "TrayNotifyEnable", true).toBool();
|
||||
}
|
||||
|
||||
bool FeedReaderUserNotify::notifyCombined()
|
||||
{
|
||||
bool combined = false;
|
||||
|
||||
Settings->beginGroup(QString("FeedReader"));
|
||||
combined = Settings->value("TrayNotifyCombined", combined).toBool();
|
||||
Settings->endGroup();
|
||||
|
||||
return combined;
|
||||
return Settings->valueFromGroup("FeedReader", "TrayNotifyCombined", false).toBool();
|
||||
}
|
||||
|
||||
bool FeedReaderUserNotify::notifyBlink()
|
||||
{
|
||||
bool blink = false;
|
||||
|
||||
Settings->beginGroup(QString("FeedReader"));
|
||||
blink = Settings->value("TrayNotifyBlink", blink).toBool();
|
||||
Settings->endGroup();
|
||||
|
||||
return blink;
|
||||
return Settings->valueFromGroup("FeedReader", "TrayNotifyBlink", false).toBool();
|
||||
}
|
||||
|
||||
void FeedReaderUserNotify::setNotifyEnabled(bool enabled, bool combined, bool blink)
|
||||
{
|
||||
Settings->beginGroup(QString("FeedReader"));
|
||||
Settings->beginGroup("FeedReader");
|
||||
Settings->setValue("TrayNotifyEnable", enabled);
|
||||
Settings->setValue("TrayNotifyCombined", combined);
|
||||
Settings->setValue("TrayNotifyBlink", blink);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue