mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-07-28 00:45:34 -04:00
Safer RsGxsChannel API
Deprecated old method which exposed interna async mechanism to the API users, making their and out life difficult Things that really need to be async like turtle search/requests now accept callbacks, so the caller can be notified everytime some result is got back Implement RsThread::async commodity wrapper to execute blocking API calls without blocking the caller, this could be optimized trasparently using a thread pool if necessary Added hints into some retroshare-gui files on how to use RsThread::async thoghether with QMetaObject::invokeMethod and blocking RetroShare API to simplyfy interaction between GUI and libretroshare
This commit is contained in:
parent
8fd22c8fd1
commit
ea86fe2615
8 changed files with 507 additions and 236 deletions
|
@ -21,6 +21,7 @@
|
|||
|
||||
#include <QMenu>
|
||||
#include <QFileDialog>
|
||||
#include <QMetaObject>
|
||||
|
||||
#include <retroshare/rsfiles.h>
|
||||
|
||||
|
@ -276,17 +277,34 @@ QWidget *GxsChannelDialog::createCommentHeaderWidget(const RsGxsGroupId &grpId,
|
|||
void GxsChannelDialog::toggleAutoDownload()
|
||||
{
|
||||
RsGxsGroupId grpId = groupId();
|
||||
if (grpId.isNull()) {
|
||||
if (grpId.isNull()) return;
|
||||
|
||||
bool autoDownload;
|
||||
if(!rsGxsChannels->getChannelAutoDownload(grpId, autoDownload))
|
||||
{
|
||||
std::cerr << __PRETTY_FUNCTION__ << " failed to get autodownload value "
|
||||
<< "for channel: " << grpId.toStdString() << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
bool autoDownload ;
|
||||
|
||||
if(!rsGxsChannels->getChannelAutoDownload(grpId,autoDownload) || !rsGxsChannels->setChannelAutoDownload(grpId, !autoDownload))
|
||||
RsThread::async([this, grpId, autoDownload]()
|
||||
{
|
||||
std::cerr << "GxsChannelDialog::toggleAutoDownload() Auto Download failed to set";
|
||||
std::cerr << std::endl;
|
||||
}
|
||||
if(!rsGxsChannels->setChannelAutoDownload(grpId, !autoDownload))
|
||||
{
|
||||
std::cerr << __PRETTY_FUNCTION__ << " failed to set autodownload "
|
||||
<< "for channel: " << grpId << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
QMetaObject::invokeMethod(this, [=]()
|
||||
{
|
||||
/* Here it goes any code you want to be executed on the Qt Gui
|
||||
* thread, for example to update the data model with new information
|
||||
* after a blocking call to RetroShare API complete, note that
|
||||
* Qt::QueuedConnection is important!
|
||||
*/
|
||||
}, Qt::QueuedConnection);
|
||||
});
|
||||
}
|
||||
|
||||
void GxsChannelDialog::loadGroupSummaryToken(const uint32_t &token, std::list<RsGroupMetaData> &groupInfo, RsUserdata *&userdata)
|
||||
|
|
|
@ -622,13 +622,13 @@ bool GxsChannelPostsWidget::navigatePostItem(const RsGxsMessageId &msgId)
|
|||
|
||||
void GxsChannelPostsWidget::subscribeGroup(bool subscribe)
|
||||
{
|
||||
if (groupId().isNull()) {
|
||||
return;
|
||||
}
|
||||
RsGxsGroupId grpId(groupId());
|
||||
if (grpId.isNull()) return;
|
||||
|
||||
uint32_t token;
|
||||
rsGxsChannels->subscribeToGroup(token, groupId(), subscribe);
|
||||
// mChannelQueue->queueRequest(token, 0, RS_TOKREQ_ANSTYPE_ACK, TOKEN_TYPE_SUBSCRIBE_CHANGE);
|
||||
RsThread::async([=]()
|
||||
{
|
||||
rsGxsChannels->subscribeToChannel(grpId, subscribe);
|
||||
} );
|
||||
}
|
||||
|
||||
void GxsChannelPostsWidget::setAutoDownload(bool autoDl)
|
||||
|
@ -644,12 +644,32 @@ void GxsChannelPostsWidget::toggleAutoDownload()
|
|||
return;
|
||||
}
|
||||
|
||||
bool autoDownload ;
|
||||
if(!rsGxsChannels->getChannelAutoDownload(grpId,autoDownload) || !rsGxsChannels->setChannelAutoDownload(grpId, !autoDownload))
|
||||
bool autoDownload;
|
||||
if(!rsGxsChannels->getChannelAutoDownload(grpId, autoDownload))
|
||||
{
|
||||
std::cerr << "GxsChannelDialog::toggleAutoDownload() Auto Download failed to set";
|
||||
std::cerr << std::endl;
|
||||
std::cerr << __PRETTY_FUNCTION__ << " failed to get autodownload value "
|
||||
<< "for channel: " << grpId.toStdString() << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
RsThread::async([this, grpId, autoDownload]()
|
||||
{
|
||||
if(!rsGxsChannels->setChannelAutoDownload(grpId, !autoDownload))
|
||||
{
|
||||
std::cerr << __PRETTY_FUNCTION__ << " failed to set autodownload "
|
||||
<< "for channel: " << grpId.toStdString() << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
QMetaObject::invokeMethod(this, [=]()
|
||||
{
|
||||
/* Here it goes any code you want to be executed on the Qt Gui
|
||||
* thread, for example to update the data model with new information
|
||||
* after a blocking call to RetroShare API complete, note that
|
||||
* Qt::QueuedConnection is important!
|
||||
*/
|
||||
}, Qt::QueuedConnection);
|
||||
});
|
||||
}
|
||||
|
||||
bool GxsChannelPostsWidget::insertGroupData(const uint32_t &token, RsGroupMetaData &metaData)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue