merged upstream/master

This commit is contained in:
csoler 2020-01-17 22:16:24 +01:00
commit c75d372f24
No known key found for this signature in database
GPG key ID: 7BCA522266C0804C
20 changed files with 155 additions and 95 deletions

View file

@ -72,8 +72,21 @@ static NewsFeed *instance = NULL;
/** Constructor */
NewsFeed::NewsFeed(QWidget *parent) : MainPage(parent), ui(new Ui::NewsFeed)
{
mEventHandlerId =0; // needed to force intialization by registerEventsHandler()
rsEvents->registerEventsHandler( [this](std::shared_ptr<const RsEvent> event) { handleEvent(event); }, mEventHandlerId );
mEventTypes = {
RsEventType::AUTHSSL_CONNECTION_AUTENTICATION,
RsEventType::PEER_CONNECTION ,
RsEventType::GXS_CIRCLES ,
RsEventType::GXS_CHANNELS ,
RsEventType::GXS_FORUMS ,
RsEventType::GXS_POSTED ,
RsEventType::MAIL_STATUS
};
for(uint32_t i=0;i<mEventTypes.size();++i)
{
mEventHandlerIds.push_back(0); // needed to force intialization by registerEventsHandler()
rsEvents->registerEventsHandler(mEventTypes[i], [this](std::shared_ptr<const RsEvent> event) { handleEvent(event); }, mEventHandlerIds.back() );
}
/* Invoke the Qt Designer generated object setup routine */
ui->setupUi(this);
@ -117,7 +130,8 @@ QString hlp_str = tr(
NewsFeed::~NewsFeed()
{
rsEvents->unregisterEventsHandler(mEventHandlerId);
for(uint32_t i=0;i<mEventHandlerIds.size();++i)
rsEvents->unregisterEventsHandler(mEventHandlerIds[i]);
// save settings
processSettings(false);
@ -190,7 +204,7 @@ void NewsFeed::handleEvent_main_thread(std::shared_ptr<const RsEvent> event)
if(event->mType == RsEventType::GXS_POSTED && (flags & RS_FEED_TYPE_POSTED))
handlePostedEvent(event);
if(event->mType == RsEventType::MAIL_STATUS_CHANGE && (flags & RS_FEED_TYPE_MSG))
if(event->mType == RsEventType::MAIL_STATUS && (flags & RS_FEED_TYPE_MSG))
handleMailEvent(event);
}
@ -200,6 +214,7 @@ void NewsFeed::handleMailEvent(std::shared_ptr<const RsEvent> event)
dynamic_cast<const RsMailStatusEvent*>(event.get());
if(!pe) return;
switch(pe->mMailStatusEventCode)
{
case RsMailStatusEventCode::NEW_MESSAGE:

View file

@ -118,7 +118,8 @@ private:
/* UI - from Designer */
Ui::NewsFeed *ui;
RsEventsHandlerId_t mEventHandlerId;
std::vector<RsEventsHandlerId_t> mEventHandlerIds;
std::vector<RsEventType> mEventTypes;
};
#endif

View file

@ -178,7 +178,7 @@ NewFriendList::NewFriendList(QWidget *parent) : /* RsAutoUpdatePage(5000,parent)
ui->filterLineEdit->showFilterIcon();
mEventHandlerId=0; // forces initialization
rsEvents->registerEventsHandler( [this](std::shared_ptr<const RsEvent> e) { handleEvent(e); }, mEventHandlerId );
rsEvents->registerEventsHandler( RsEventType::PEER_CONNECTION, [this](std::shared_ptr<const RsEvent> e) { handleEvent(e); }, mEventHandlerId );
mModel = new RsFriendListModel();
mProxyModel = new FriendListSortFilterProxyModel(ui->peerTreeWidget->header(),this);
@ -258,13 +258,10 @@ NewFriendList::NewFriendList(QWidget *parent) : /* RsAutoUpdatePage(5000,parent)
void NewFriendList::handleEvent(std::shared_ptr<const RsEvent> e)
{
if(e->mType == RsEventType::PEER_CONNECTION)
{
// /!\ The function we're in is called from a different thread. It's very important
// to use this trick in order to avoid data races.
// /!\ The function we're in is called from a different thread. It's very important
// to use this trick in order to avoid data races.
RsQThreadUtils::postToObject( [=]() { forceUpdateDisplay() ; }, this ) ;
}
RsQThreadUtils::postToObject( [=]() { forceUpdateDisplay() ; }, this ) ;
}
NewFriendList::~NewFriendList()

View file

@ -52,17 +52,15 @@ GxsChannelDialog::GxsChannelDialog(QWidget *parent)
{
mEventHandlerId = 0;
// Needs to be asynced because this function is likely to be called by another thread!
rsEvents->registerEventsHandler( [this](std::shared_ptr<const RsEvent> event) { RsQThreadUtils::postToObject( [=]() { handleEvent_main_thread(event); }, this ); }, mEventHandlerId );
rsEvents->registerEventsHandler(RsEventType::GXS_CHANNELS, [this](std::shared_ptr<const RsEvent> event) { RsQThreadUtils::postToObject( [=]() { handleEvent_main_thread(event); }, this ); }, mEventHandlerId );
}
void GxsChannelDialog::handleEvent_main_thread(std::shared_ptr<const RsEvent> event)
{
if(event->mType == RsEventType::GXS_CHANNELS)
{
const RsGxsChannelEvent *e = dynamic_cast<const RsGxsChannelEvent*>(event.get());
const RsGxsChannelEvent *e = dynamic_cast<const RsGxsChannelEvent*>(event.get());
if(!e)
return;
if(!e)
return;
switch(e->mChannelEventCode)
{
@ -71,7 +69,6 @@ void GxsChannelDialog::handleEvent_main_thread(std::shared_ptr<const RsEvent> ev
default:
break;
}
}
}
GxsChannelDialog::~GxsChannelDialog()

View file

@ -132,17 +132,15 @@ GxsChannelPostsWidget::GxsChannelPostsWidget(const RsGxsGroupId &channelId, QWid
mEventHandlerId = 0;
// Needs to be asynced because this function is likely to be called by another thread!
rsEvents->registerEventsHandler( [this](std::shared_ptr<const RsEvent> event) { RsQThreadUtils::postToObject( [=]() { handleEvent_main_thread(event); }, this ); }, mEventHandlerId );
rsEvents->registerEventsHandler(RsEventType::GXS_CHANNELS, [this](std::shared_ptr<const RsEvent> event) { RsQThreadUtils::postToObject( [=]() { handleEvent_main_thread(event); }, this ); }, mEventHandlerId );
}
void GxsChannelPostsWidget::handleEvent_main_thread(std::shared_ptr<const RsEvent> event)
{
if(event->mType == RsEventType::GXS_CHANNELS)
{
const RsGxsChannelEvent *e = dynamic_cast<const RsGxsChannelEvent*>(event.get());
const RsGxsChannelEvent *e = dynamic_cast<const RsGxsChannelEvent*>(event.get());
if(!e)
return;
if(!e)
return;
switch(e->mChannelEventCode)
{
@ -156,7 +154,6 @@ void GxsChannelPostsWidget::handleEvent_main_thread(std::shared_ptr<const RsEven
default:
break;
}
}
}
GxsChannelPostsWidget::~GxsChannelPostsWidget()

View file

@ -436,7 +436,7 @@ GxsForumThreadWidget::GxsForumThreadWidget(const RsGxsGroupId &forumId, QWidget
mEventHandlerId = 0;
// Needs to be asynced because this function is likely to be called by another thread!
rsEvents->registerEventsHandler( [this](std::shared_ptr<const RsEvent> event) { RsQThreadUtils::postToObject( [=]() { handleEvent_main_thread(event); }, this ); }, mEventHandlerId );
rsEvents->registerEventsHandler(RsEventType::GXS_FORUMS, [this](std::shared_ptr<const RsEvent> event) { RsQThreadUtils::postToObject( [=]() { handleEvent_main_thread(event); }, this ); }, mEventHandlerId );
}
void GxsForumThreadWidget::handleEvent_main_thread(std::shared_ptr<const RsEvent> event)

View file

@ -45,7 +45,7 @@ GxsForumsDialog::GxsForumsDialog(QWidget *parent)
mEventHandlerId = 0;
// Needs to be asynced because this function is likely to be called by another thread!
rsEvents->registerEventsHandler( [this](std::shared_ptr<const RsEvent> event) { RsQThreadUtils::postToObject( [=]() { handleEvent_main_thread(event); }, this ); }, mEventHandlerId );
rsEvents->registerEventsHandler(RsEventType::GXS_FORUMS, [this](std::shared_ptr<const RsEvent> event) { RsQThreadUtils::postToObject( [=]() { handleEvent_main_thread(event); }, this ); }, mEventHandlerId );
}
void GxsForumsDialog::handleEvent_main_thread(std::shared_ptr<const RsEvent> event)

View file

@ -39,11 +39,9 @@ RsGxsUpdateBroadcast::RsGxsUpdateBroadcast(RsGxsIfaceHelper *ifaceImpl) :
{
mEventHandlerId = 0; // forces initialization in registerEventsHandler()
rsEvents->registerEventsHandler( [this](std::shared_ptr<const RsEvent> event)
rsEvents->registerEventsHandler(RsEventType::GXS_CHANGES, [this](std::shared_ptr<const RsEvent> event)
{
if(event->mType == RsEventType::GXS_CHANGES)
onChangesReceived(*dynamic_cast<const RsGxsChanges*>(event.get()));
onChangesReceived(*dynamic_cast<const RsGxsChanges*>(event.get()));
}, mEventHandlerId );
}