From ddc4a37a93e5a1181fcd41f7b6c01b79f2968d41 Mon Sep 17 00:00:00 2001 From: thunder2 Date: Mon, 14 Jan 2013 22:41:31 +0000 Subject: [PATCH] FeedReader: - Recalculate message count of the user notify when a feed with new items is deleted. - Set deleted message to read and !new. - Added test feed item in notify settings. git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@6072 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- .../FeedReader/gui/FeedReaderFeedNotify.cpp | 23 +++++++++++++++++++ plugins/FeedReader/gui/FeedReaderFeedNotify.h | 2 ++ .../FeedReader/gui/FeedReaderUserNotify.cpp | 9 ++++++++ plugins/FeedReader/gui/FeedReaderUserNotify.h | 3 +++ plugins/FeedReader/interface/rsFeedReader.h | 2 ++ plugins/FeedReader/services/p3FeedReader.cc | 7 ++++-- retroshare-gui/src/gui/NewsFeed.cpp | 18 +++++++++++++++ retroshare-gui/src/gui/NewsFeed.h | 2 ++ retroshare-gui/src/gui/common/FeedNotify.cpp | 5 ++++ retroshare-gui/src/gui/common/FeedNotify.h | 1 + .../src/gui/settings/NotifyPage.cpp | 8 +++++++ 11 files changed, 78 insertions(+), 2 deletions(-) diff --git a/plugins/FeedReader/gui/FeedReaderFeedNotify.cpp b/plugins/FeedReader/gui/FeedReaderFeedNotify.cpp index 11bc211c2..21018dd8e 100644 --- a/plugins/FeedReader/gui/FeedReaderFeedNotify.cpp +++ b/plugins/FeedReader/gui/FeedReaderFeedNotify.cpp @@ -20,6 +20,8 @@ ****************************************************************/ #include +#include +#include #include "FeedReaderFeedNotify.h" #include "FeedReaderNotify.h" @@ -116,3 +118,24 @@ QWidget *FeedReaderFeedNotify::feedItem(FeedHolder *parent) return new FeedReaderFeedItem(mFeedReader, mNotify, parent, feedInfo, msgInfo); } + +QWidget *FeedReaderFeedNotify::testFeedItem(FeedHolder *parent) +{ + 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); +} diff --git a/plugins/FeedReader/gui/FeedReaderFeedNotify.h b/plugins/FeedReader/gui/FeedReaderFeedNotify.h index 4a72fc1a0..d7ffec4b9 100644 --- a/plugins/FeedReader/gui/FeedReaderFeedNotify.h +++ b/plugins/FeedReader/gui/FeedReaderFeedNotify.h @@ -31,6 +31,7 @@ class QMutex; class FeedReaderFeedNotify : public FeedNotify { Q_OBJECT + protected: class FeedItem { @@ -50,6 +51,7 @@ public: virtual bool notifyEnabled(); virtual void setNotifyEnabled(bool enabled); virtual QWidget *feedItem(FeedHolder *parent); + virtual QWidget *testFeedItem(FeedHolder *parent); private slots: void msgChanged(const QString &feedId, const QString &msgId, int type); diff --git a/plugins/FeedReader/gui/FeedReaderUserNotify.cpp b/plugins/FeedReader/gui/FeedReaderUserNotify.cpp index e1d4e21a6..89c559223 100644 --- a/plugins/FeedReader/gui/FeedReaderUserNotify.cpp +++ b/plugins/FeedReader/gui/FeedReaderUserNotify.cpp @@ -26,10 +26,12 @@ #include "gui/MainWindow.h" #include "interface/rsFeedReader.h" +#include "retroshare/rsiface.h" FeedReaderUserNotify::FeedReaderUserNotify(FeedReaderDialog *feedReaderDialog, RsFeedReader *feedReader, FeedReaderNotify *notify, QObject *parent) : UserNotify(parent), mFeedReaderDialog(feedReaderDialog), mFeedReader(feedReader), mNotify(notify) { + connect(mNotify, SIGNAL(feedChanged(QString,int)), this, SLOT(feedChanged(QString,int)), Qt::QueuedConnection); connect(mNotify, SIGNAL(msgChanged(QString,QString,int)), this, SLOT(updateIcon()), Qt::QueuedConnection); } @@ -86,3 +88,10 @@ void FeedReaderUserNotify::iconClicked() { MainWindow::showWindow(mFeedReaderDialog); } + +void FeedReaderUserNotify::feedChanged(const QString &/*feedId*/, int type) +{ + if (type == NOTIFY_TYPE_DEL) { + updateIcon(); + } +} diff --git a/plugins/FeedReader/gui/FeedReaderUserNotify.h b/plugins/FeedReader/gui/FeedReaderUserNotify.h index 1e5624d06..43278d366 100644 --- a/plugins/FeedReader/gui/FeedReaderUserNotify.h +++ b/plugins/FeedReader/gui/FeedReaderUserNotify.h @@ -41,6 +41,9 @@ public: virtual bool notifyBlink(); virtual void setNotifyEnabled(bool enabled, bool combined, bool blink); +private slots: + void feedChanged(const QString &feedId, int type); + private: virtual QIcon getIcon(); virtual QIcon getMainIcon(bool hasNew); diff --git a/plugins/FeedReader/interface/rsFeedReader.h b/plugins/FeedReader/interface/rsFeedReader.h index e93dac8bc..53729359f 100644 --- a/plugins/FeedReader/interface/rsFeedReader.h +++ b/plugins/FeedReader/interface/rsFeedReader.h @@ -143,6 +143,7 @@ public: pubDate = 0; flag.isnew = false; flag.read = false; + flag.deleted = false; } std::string msgId; @@ -156,6 +157,7 @@ public: struct { bool isnew : 1; bool read : 1; + bool deleted : 1; } flag; }; diff --git a/plugins/FeedReader/services/p3FeedReader.cc b/plugins/FeedReader/services/p3FeedReader.cc index 65c4818ee..35dcd5049 100644 --- a/plugins/FeedReader/services/p3FeedReader.cc +++ b/plugins/FeedReader/services/p3FeedReader.cc @@ -204,6 +204,7 @@ static void feedMsgToInfo(const RsFeedReaderMsg *msg, FeedMsgInfo &info) info.flag.isnew = (msg->flag & RS_FEEDMSG_FLAG_NEW); info.flag.read = (msg->flag & RS_FEEDMSG_FLAG_READ); + info.flag.deleted = (msg->flag & RS_FEEDMSG_FLAG_DELETED); } void p3FeedReader::setNotify(RsFeedReaderNotify *notify) @@ -758,7 +759,8 @@ bool p3FeedReader::removeMsg(const std::string &feedId, const std::string &msgId return false; } - msgIt->second->flag |= RS_FEEDMSG_FLAG_DELETED; + msgIt->second->flag |= RS_FEEDMSG_FLAG_DELETED | RS_FEEDMSG_FLAG_READ; + msgIt->second->flag &= ~RS_FEEDMSG_FLAG_NEW; } if (changed) { @@ -803,7 +805,8 @@ bool p3FeedReader::removeMsgs(const std::string &feedId, const std::listsecond->flag |= RS_FEEDMSG_FLAG_DELETED; + msgIt->second->flag |= RS_FEEDMSG_FLAG_DELETED | RS_FEEDMSG_FLAG_READ; + msgIt->second->flag &= ~RS_FEEDMSG_FLAG_NEW; removedMsgs.push_back(*idIt); } diff --git a/retroshare-gui/src/gui/NewsFeed.cpp b/retroshare-gui/src/gui/NewsFeed.cpp index 55bf166c3..3e645f1a2 100644 --- a/retroshare-gui/src/gui/NewsFeed.cpp +++ b/retroshare-gui/src/gui/NewsFeed.cpp @@ -409,6 +409,24 @@ void NewsFeed::testFeeds(uint notifyFlags) } } +void NewsFeed::testFeed(FeedNotify *feedNotify) +{ + if (!instance) { + return; + } + + if (!feedNotify) { + return; + } + + QWidget *feedItem = feedNotify->testFeedItem(instance); + if (!feedItem) { + return; + } + + instance->addFeedItem(feedItem); +} + void NewsFeed::addFeedItem(QWidget *item) { item->setAttribute(Qt::WA_DeleteOnClose, true); diff --git a/retroshare-gui/src/gui/NewsFeed.h b/retroshare-gui/src/gui/NewsFeed.h index 390cb63e7..afca54975 100644 --- a/retroshare-gui/src/gui/NewsFeed.h +++ b/retroshare-gui/src/gui/NewsFeed.h @@ -31,6 +31,7 @@ class RsFeedItem; class ForumNewItem; class ChanMsgItem; class ChatMsgItem; +class FeedNotify; class NewsFeed : public MainPage, public FeedHolder, private Ui::NewsFeed { @@ -48,6 +49,7 @@ public: virtual void openChat(std::string peerId); static void testFeeds(uint notifyFlags); + static void testFeed(FeedNotify *feedNotify); signals: void newsFeedChanged(int count); diff --git a/retroshare-gui/src/gui/common/FeedNotify.cpp b/retroshare-gui/src/gui/common/FeedNotify.cpp index 3c2109c70..1db718ece 100644 --- a/retroshare-gui/src/gui/common/FeedNotify.cpp +++ b/retroshare-gui/src/gui/common/FeedNotify.cpp @@ -48,3 +48,8 @@ QWidget *FeedNotify::feedItem(FeedHolder */*parent*/) { return NULL; } + +QWidget *FeedNotify::testFeedItem(FeedHolder */*parent*/) +{ + return NULL; +} diff --git a/retroshare-gui/src/gui/common/FeedNotify.h b/retroshare-gui/src/gui/common/FeedNotify.h index 2d1b54074..cd8f1acbc 100644 --- a/retroshare-gui/src/gui/common/FeedNotify.h +++ b/retroshare-gui/src/gui/common/FeedNotify.h @@ -38,6 +38,7 @@ public: virtual bool notifyEnabled(); virtual void setNotifyEnabled(bool /*enabled*/); virtual QWidget *feedItem(FeedHolder */*parent*/); + virtual QWidget *testFeedItem(FeedHolder */*parent*/); }; #endif // FEEDNOTIFY_H diff --git a/retroshare-gui/src/gui/settings/NotifyPage.cpp b/retroshare-gui/src/gui/settings/NotifyPage.cpp index 418a568a2..bafa327a8 100755 --- a/retroshare-gui/src/gui/settings/NotifyPage.cpp +++ b/retroshare-gui/src/gui/settings/NotifyPage.cpp @@ -285,6 +285,14 @@ void NotifyPage::notifyToggled() void NotifyPage::testNotify() { NewsFeed::testFeeds(getNewsFlags()); + + /* notify of plugins */ + QList::iterator feedNotifyIt; + for (feedNotifyIt = mFeedNotifySettingList.begin(); feedNotifyIt != mFeedNotifySettingList.end(); ++feedNotifyIt) { + if (feedNotifyIt->mEnabledCheckBox->isChecked()) { + NewsFeed::testFeed(feedNotifyIt->mFeedNotify); + } + } } void NotifyPage::testToaster()