Added service pointer for forums to the plugin interface.

FeedReader:
- Used the forums pointer from the plugin interface instead of the global pointer

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@6982 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
thunder2 2014-01-03 15:05:48 +00:00
parent 2a9a6f8a75
commit 76b3ccc1a5
6 changed files with 109 additions and 85 deletions

View File

@ -42,6 +42,7 @@ class RsTurtle ;
class RsDht ;
class RsDisc ;
class RsMsgs ;
class RsForums;
class p3LinkMgr ;
class MainPage ;
class QIcon ;
@ -98,6 +99,7 @@ public:
RsTurtle *mTurtle;
RsDisc *mDisc;
RsDht *mDht;
RsForums *mForums;
};
class RsPlugin

View File

@ -2222,18 +2222,6 @@ int RsServer::StartupRetroShare()
rsDisc = new p3Discovery(ad);
rsMsgs = new p3Msgs(msgSrv, chatSrv);
// set interfaces for plugins
//
RsPlugInInterfaces interfaces;
interfaces.mFiles = rsFiles;
interfaces.mPeers = rsPeers;
interfaces.mMsgs = rsMsgs;
interfaces.mTurtle = rsTurtle;
interfaces.mDisc = rsDisc;
interfaces.mDht = rsDht;
mPluginsManager->setInterfaces(interfaces);
// connect components to turtle router.
ftserver->connectToTurtleRouter(tr) ;
@ -2264,6 +2252,20 @@ int RsServer::StartupRetroShare()
pqih -> addService(mBlogs); /* This must be also ticked as a service */
#endif
// set interfaces for plugins
//
RsPlugInInterfaces interfaces;
interfaces.mFiles = rsFiles;
interfaces.mPeers = rsPeers;
interfaces.mMsgs = rsMsgs;
interfaces.mTurtle = rsTurtle;
interfaces.mDisc = rsDisc;
interfaces.mDht = rsDht;
interfaces.mForums = mForums;
mPluginsManager->setInterfaces(interfaces);
// now add plugin objects inside the loop:
// - client services provided by plugins.
// - cache services provided by plugins.

View File

@ -83,8 +83,9 @@ FeedReaderPlugin::FeedReaderPlugin()
mFeedNotify = NULL;
}
void FeedReaderPlugin::setInterfaces(RsPlugInInterfaces &/*interfaces*/)
void FeedReaderPlugin::setInterfaces(RsPlugInInterfaces &interfaces)
{
mInterfaces = interfaces;
}
ConfigPage *FeedReaderPlugin::qt_config_page() const
@ -112,7 +113,7 @@ FeedNotify *FeedReaderPlugin::qt_feedNotify()
RsPQIService *FeedReaderPlugin::rs_pqi_service() const
{
if (mFeedReader == NULL) {
mFeedReader = new p3FeedReader(mPlugInHandler);
mFeedReader = new p3FeedReader(mPlugInHandler, mInterfaces.mForums);
rsFeedReader = mFeedReader;
mNotify = new FeedReaderNotify();

View File

@ -56,6 +56,7 @@ public:
virtual FeedNotify *qt_feedNotify();
private:
RsPlugInInterfaces mInterfaces;
mutable p3FeedReader *mFeedReader;
mutable FeedReaderNotify *mNotify;
mutable RsPluginHandler *mPlugInHandler;

View File

@ -36,7 +36,7 @@ RsFeedReader *rsFeedReader = NULL;
* #define FEEDREADER_DEBUG
*********/
p3FeedReader::p3FeedReader(RsPluginHandler* pgHandler)
p3FeedReader::p3FeedReader(RsPluginHandler* pgHandler, RsForums *forums)
: RsPQIService(RS_SERVICE_TYPE_PLUGIN_FEEDREADER, CONFIG_TYPE_FEEDREADER, 5, pgHandler),
mFeedReaderMtx("p3FeedReader"), mDownloadMutex("p3FeedReaderDownload"), mProcessMutex("p3FeedReaderProcess"), mPreviewMutex("p3FeedReaderPreview")
{
@ -49,6 +49,7 @@ p3FeedReader::p3FeedReader(RsPluginHandler* pgHandler)
mStandardUseProxy = false;
mStandardProxyPort = 0;
mLastClean = 0;
mForums = forums;
mNotify = NULL;
mSaveInBackground = false;
@ -525,12 +526,16 @@ RsFeedAddResult p3FeedReader::setFeed(const std::string &feedId, const FeedInfo
}
if (!forumId.empty()) {
if (mForums) {
/* name or description changed, update forum */
if (!rsForums->setForumInfo(forumId, forumInfo)) {
if (!mForums->setForumInfo(forumId, forumInfo)) {
#ifdef FEEDREADER_DEBUG
std::cerr << "p3FeedReader::setFeed - can't change forum " << forumId << std::endl;
#endif
}
} else {
std::cerr << "p3FeedReader::setFeed - can't change forum " << forumId << ", member mForums is not set" << std::endl;
}
}
return RS_FEED_ADD_RESULT_SUCCESS;
@ -1836,6 +1841,7 @@ void p3FeedReader::onProcessSuccess_addMsgs(const std::string &feedId, std::list
RsFeedReaderErrorState errorState = RS_FEED_ERRORSTATE_OK;
if (forum && !msgs.empty()) {
if (mForums) {
if (fi->forumId.empty()) {
/* create new forum */
std::wstring forumName;
@ -1846,7 +1852,7 @@ void p3FeedReader::onProcessSuccess_addMsgs(const std::string &feedId, std::list
/* search for existing own forum */
// std::list<ForumInfo> forumList;
// if (rsForums->getForumList(forumList)) {
// if (mForums->getForumList(forumList)) {
// std::wstring wName = StringToWString(name);
// for (std::list<ForumInfo>::iterator it = forumList.begin(); it != forumList.end(); ++it) {
// if (it->forumName == wName) {
@ -1859,7 +1865,7 @@ void p3FeedReader::onProcessSuccess_addMsgs(const std::string &feedId, std::list
std::wstring forumDescription;
librs::util::ConvertUtf8ToUtf16(fi->description, forumDescription);
/* create anonymous public forum */
fi->forumId = rsForums->createForum(forumName, forumDescription, RS_DISTRIB_PUBLIC | RS_DISTRIB_AUTHEN_ANON);
fi->forumId = mForums->createForum(forumName, forumDescription, RS_DISTRIB_PUBLIC | RS_DISTRIB_AUTHEN_ANON);
forumId = fi->forumId;
if (fi->forumId.empty()) {
@ -1874,7 +1880,7 @@ void p3FeedReader::onProcessSuccess_addMsgs(const std::string &feedId, std::list
} else {
/* check forum */
ForumInfo forumInfo;
if (rsForums->getForumInfo(fi->forumId, forumInfo)) {
if (mForums->getForumInfo(fi->forumId, forumInfo)) {
if ((forumInfo.subscribeFlags & RS_DISTRIB_ADMIN) == 0) {
errorState = RS_FEED_ERRORSTATE_PROCESS_FORUM_NO_ADMIN;
} else if ((forumInfo.forumFlags & RS_DISTRIB_AUTHEN_REQ) || (forumInfo.forumFlags & RS_DISTRIB_AUTHEN_ANON) == 0) {
@ -1886,6 +1892,9 @@ void p3FeedReader::onProcessSuccess_addMsgs(const std::string &feedId, std::list
errorState = RS_FEED_ERRORSTATE_PROCESS_FORUM_NOT_FOUND;
}
}
} else {
std::cerr << "p3FeedReader::onProcessSuccess_addMsgs - can't process forum, member mForums is not set" << std::endl;
}
}
/* process msgs */
@ -1938,6 +1947,7 @@ void p3FeedReader::onProcessSuccess_addMsgs(const std::string &feedId, std::list
}
if (!forumId.empty() && !forumMsgs.empty()) {
if (mForums) {
/* add messages as forum messages */
std::list<RsFeedReaderMsg>::iterator msgIt;
for (msgIt = forumMsgs.begin(); msgIt != forumMsgs.end(); ++msgIt) {
@ -1955,15 +1965,18 @@ void p3FeedReader::onProcessSuccess_addMsgs(const std::string &feedId, std::list
}
librs::util::ConvertUtf8ToUtf16(description, forumMsgInfo.msg);
if (rsForums->ForumMessageSend(forumMsgInfo)) {
if (mForums->ForumMessageSend(forumMsgInfo)) {
/* set to new */
rsForums->setMessageStatus(forumMsgInfo.forumId, forumMsgInfo.msgId, 0, FORUM_MSG_STATUS_MASK);
mForums->setMessageStatus(forumMsgInfo.forumId, forumMsgInfo.msgId, 0, FORUM_MSG_STATUS_MASK);
} else {
#ifdef FEEDREADER_DEBUG
std::cerr << "p3FeedReader::onProcessSuccess_filterMsg - can't add forum message " << mi.title << " for feed " << forumId << std::endl;
#endif
}
}
} else {
std::cerr << "p3FeedReader::onProcessSuccess_addMsgs - can't process forum, member mForums is not set" << std::endl;
}
}
if (mNotify) {
@ -2070,14 +2083,15 @@ void p3FeedReader::setFeedInfo(const std::string &feedId, const std::string &nam
}
if (!forumId.empty()) {
if (mForums) {
ForumInfo forumInfo;
if (rsForums->getForumInfo(forumId, forumInfo)) {
if (mForums->getForumInfo(forumId, forumInfo)) {
if (forumInfo.forumName != forumInfoNew.forumName || forumInfo.forumDesc != forumInfoNew.forumDesc) {
/* name or description changed, update forum */
#ifdef FEEDREADER_DEBUG
std::cerr << "p3FeedReader::setFeed - change forum " << forumId << std::endl;
#endif
if (!rsForums->setForumInfo(forumId, forumInfoNew)) {
if (!mForums->setForumInfo(forumId, forumInfoNew)) {
#ifdef FEEDREADER_DEBUG
std::cerr << "p3FeedReader::setFeed - can't change forum " << forumId << std::endl;
#endif
@ -2088,5 +2102,8 @@ void p3FeedReader::setFeedInfo(const std::string &feedId, const std::string &nam
std::cerr << "p3FeedReader::setFeed - can't get forum info " << forumId << std::endl;
#endif
}
} else {
std::cerr << "p3FeedReader::setFeedInfo - can't process forum, member mForums is not set" << std::endl;
}
}
}

View File

@ -33,7 +33,7 @@ class p3FeedReaderThread;
class p3FeedReader : public RsPQIService, public RsFeedReader
{
public:
p3FeedReader(RsPluginHandler *pgHandler);
p3FeedReader(RsPluginHandler *pgHandler, RsForums *forums);
/****************** FeedReader Interface *************/
virtual void stop();
@ -97,6 +97,7 @@ private:
void stopPreviewThreads_locked();
time_t mLastClean;
RsForums *mForums;
RsFeedReaderNotify *mNotify;
RsMutex mFeedReaderMtx;