merged with upstream/master

This commit is contained in:
csoler 2020-07-05 19:58:09 +02:00
commit c00c4eadd3
No known key found for this signature in database
GPG key ID: 7BCA522266C0804C
21 changed files with 453 additions and 233 deletions

View file

@ -397,6 +397,19 @@ bool GroupTreeWidget::isSearchRequestResult(QPoint &point,QString& group_id,uint
return search_req_id > 0;
}
bool GroupTreeWidget::isSearchRequestResultItem(QTreeWidgetItem *item,QString& group_id,uint32_t& search_req_id)
{
QTreeWidgetItem *parent = item->parent();
if(parent == NULL)
return false ;
search_req_id = parent->data(COLUMN_DATA, ROLE_REQUEST_ID).toUInt();
group_id = itemId(item) ;
return search_req_id > 0;
}
bool GroupTreeWidget::isSearchRequestItem(QPoint &point,uint32_t& search_req_id)
{
QTreeWidgetItem *item = ui->treeWidget->itemAt(point);
@ -463,6 +476,17 @@ void GroupTreeWidget::fillGroupItems(QTreeWidgetItem *categoryItem, const QList<
item->setData(COLUMN_DATA, ROLE_NAME, itemInfo.name);
item->setData(COLUMN_DATA, ROLE_DESCRIPTION, itemInfo.description);
// Add children for context strings. This happens in the search.
while(nullptr != item->takeChild(0));
for(auto str:itemInfo.context_strings)
if(!str.empty())
{
QTreeWidgetItem *it = new QTreeWidgetItem(QStringList(QString::fromUtf8(str.c_str())));
it->setData(COLUMN_DATA,ROLE_ID,itemInfo.id);
item->addChild(it);
}
/* Set last post */
qlonglong lastPost = itemInfo.lastpost.toTime_t();
item->setData(COLUMN_DATA, ROLE_LASTPOST, -lastPost); // negative for correct sorting

View file

@ -21,6 +21,8 @@
#ifndef GROUPTREEWIDGET_H
#define GROUPTREEWIDGET_H
#include<set>
#include <QTreeWidgetItem>
#include <QDateTime>
@ -47,16 +49,17 @@ public:
{}
public:
QString id;
QString name;
QString description;
int popularity;
QDateTime lastpost;
QIcon icon;
bool publishKey;
bool adminKey;
quint32 subscribeFlags;
quint32 max_visible_posts ;
QString id;
QString name;
QString description;
int popularity;
QDateTime lastpost;
QIcon icon;
bool publishKey;
bool adminKey;
quint32 subscribeFlags;
quint32 max_visible_posts ;
std::set<std::string> context_strings;
};
//cppcheck-suppress noConstructor
@ -94,6 +97,7 @@ public:
bool isSearchRequestItem(QPoint &point,uint32_t& search_req_id);
bool isSearchRequestResult(QPoint &point, QString &group_id, uint32_t& search_req_id);
bool isSearchRequestResultItem(QTreeWidgetItem *item,QString& group_id,uint32_t& search_req_id);
QTreeWidgetItem *getItemFromId(const QString &id);
QTreeWidgetItem *activateId(const QString &id, bool focus);

View file

@ -29,6 +29,7 @@
#include "gui/settings/rsharesettings.h"
#include "gui/RetroShareLink.h"
#include "gui/gxs/GxsGroupShareKey.h"
#include "gui/common/GroupTreeWidget.h"
#include "gui/common/RSTreeWidget.h"
#include "gui/notifyqt.h"
#include "gui/common/UIStateHelper.h"
@ -290,55 +291,50 @@ void GxsGroupFrameDialog::updateDisplay(bool complete)
if(complete) // || !getGrpIds().empty() || !getGrpIdsMeta().empty()) {
updateGroupSummary(); /* Update group list */
updateSearchResults() ;
// updateSearchResults() ;
}
void GxsGroupFrameDialog::updateSearchResults()
{
const std::set<TurtleRequestId>& reqs = getSearchRequests();
for(auto& it:mSearchGroupsItems)
updateSearchResults(it.first);
}
for(auto it(reqs.begin());it!=reqs.end();++it)
{
std::cerr << "updating search ID " << std::hex << *it << std::dec << std::endl;
void GxsGroupFrameDialog::updateSearchResults(const TurtleRequestId& sid)
{
std::cerr << "updating search ID " << std::hex << sid << std::dec << std::endl;
std::map<RsGxsGroupId,RsGxsGroupSummary> group_infos;
std::map<RsGxsGroupId,RsGxsGroupSearchResults> group_infos;
getDistantSearchResults(*it,group_infos) ;
getDistantSearchResults(sid,group_infos) ;
std::cerr << "retrieved " << std::endl;
std::cerr << "retrieved " << std::endl;
auto it2 = mSearchGroupsItems.find(*it);
auto it2 = mSearchGroupsItems.find(sid);
if(mSearchGroupsItems.end() == it2)
{
std::cerr << "GxsGroupFrameDialog::updateSearchResults(): received result notification for req " << std::hex << *it << std::dec << " but no item present!" << std::endl;
continue ; // we could create the item just as well but since this situation is not supposed to happen, I prefer to make this a failure case.
}
QList<GroupItemInfo> group_items ;
QList<GroupItemInfo> group_items ;
for(auto it3(group_infos.begin());it3!=group_infos.end();++it3)
{
std::cerr << " adding group " << it3->first << " " << it3->second.mGroupId << " \"" << it3->second.mGroupName << "\"" << std::endl;
for(auto s:it3->second.mSearchContexts)
std::cerr << " Context string \"" << s << "\"" << std::endl;
for(auto it3(group_infos.begin());it3!=group_infos.end();++it3)
if(mCachedGroupMetas.find(it3->first) == mCachedGroupMetas.end())
{
std::cerr << " adding new group " << it3->first << " "
<< it3->second.mGroupId << " \""
<< it3->second.mGroupName << "\"" << std::endl;
GroupItemInfo i;
i.id = QString(it3->second.mGroupId.toStdString().c_str());
i.name = QString::fromUtf8(it3->second.mGroupName.c_str());
i.popularity = 0; // could be set to the number of hits
i.lastpost = QDateTime::fromTime_t(it3->second.mLastMessageTs);
i.subscribeFlags = 0; // irrelevant here
i.publishKey = false ; // IS_GROUP_PUBLISHER(groupInfo.mSubscribeFlags);
i.adminKey = false ; // IS_GROUP_ADMIN(groupInfo.mSubscribeFlags);
i.max_visible_posts = it3->second.mNumberOfMessages;
i.context_strings = it3->second.mSearchContexts;
GroupItemInfo i;
i.id = QString(it3->second.mGroupId.toStdString().c_str());
i.name = QString::fromUtf8(it3->second.mGroupName.c_str());
i.popularity = 0; // could be set to the number of hits
i.lastpost = QDateTime::fromTime_t(it3->second.mLastMessageTs);
i.subscribeFlags = 0; // irrelevant here
i.publishKey = false ; // IS_GROUP_PUBLISHER(groupInfo.mSubscribeFlags);
i.adminKey = false ; // IS_GROUP_ADMIN(groupInfo.mSubscribeFlags);
i.max_visible_posts = it3->second.mNumberOfMessages;
group_items.push_back(i);
}
group_items.push_back(i);
}
ui->groupTreeWidget->fillGroupItems(it2->second, group_items);
}
ui->groupTreeWidget->fillGroupItems(it2->second, group_items);
}
void GxsGroupFrameDialog::todo()
@ -364,13 +360,22 @@ void GxsGroupFrameDialog::removeCurrentSearch()
mSearchGroupsItems.erase(it);
mKnownGroups.erase(search_request_id);
clearDistantSearchResults(search_request_id);
}
void GxsGroupFrameDialog::removeAllSearches()
{
for(auto it(mSearchGroupsItems.begin());it!=mSearchGroupsItems.end();++it)
ui->groupTreeWidget->removeSearchItem(it->second) ;
{
QString group_id;
TurtleRequestId search_request_id;
if(ui->groupTreeWidget->isSearchRequestResultItem(it->second,group_id,search_request_id))
clearDistantSearchResults(search_request_id);
ui->groupTreeWidget->removeSearchItem(it->second) ;
}
mSearchGroupsItems.clear();
mKnownGroups.clear();
}
@ -1074,15 +1079,20 @@ void GxsGroupFrameDialog::updateGroupSummary()
{
RsThread::async([this]()
{
std::list<RsGxsGenericGroupData*> groupInfo;
auto groupInfo = new std::list<RsGxsGenericGroupData*>() ;
if(!getGroupData(groupInfo))
if(!getGroupData(*groupInfo))
{
std::cerr << __PRETTY_FUNCTION__ << " failed to collect group info " << std::endl;
std::cerr << __PRETTY_FUNCTION__ << " failed to collect group info." << std::endl;
delete groupInfo;
return;
}
if(groupInfo.empty())
if(groupInfo->empty())
{
std::cerr << __PRETTY_FUNCTION__ << " no group info collected." << std::endl;
delete groupInfo;
return;
}
RsQThreadUtils::postToObject( [this,groupInfo]()
{
@ -1092,7 +1102,7 @@ void GxsGroupFrameDialog::updateGroupSummary()
* Qt::QueuedConnection is important!
*/
insertGroupsData(groupInfo);
insertGroupsData(*groupInfo);
updateSearchResults();
mStateHelper->setLoading(TOKEN_TYPE_GROUP_SUMMARY, false);
@ -1111,12 +1121,14 @@ void GxsGroupFrameDialog::updateGroupSummary()
// now delete the data that is not used anymore
for(auto& g:groupInfo)
for(auto& g:*groupInfo)
{
mCachedGroupMetas[g->mMeta.mGroupId] = g->mMeta;
delete g;
}
delete groupInfo;
}, this );
});
}

View file

@ -161,7 +161,9 @@ private:
virtual void groupTreeCustomActions(RsGxsGroupId /*grpId*/, int /*subscribeFlags*/, QList<QAction*> &/*actions*/) {}
virtual RsGxsCommentService *getCommentService() { return NULL; }
virtual QWidget *createCommentHeaderWidget(const RsGxsGroupId &/*grpId*/, const RsGxsMessageId &/*msgId*/) { return NULL; }
virtual bool getDistantSearchResults(TurtleRequestId /* id */, std::map<RsGxsGroupId,RsGxsGroupSummary>& /* group_infos */){ return false ;}
virtual bool getDistantSearchResults(TurtleRequestId /* id */, std::map<RsGxsGroupId,RsGxsGroupSearchResults>& /* group_infos */){ return false ;}
virtual void clearDistantSearchResults(TurtleRequestId /* id */) {}
virtual RsGxsGenericGroupData *getDistantSearchResultGroupData(const RsGxsGroupId& group_id){ return nullptr ;}
void initUi();
@ -187,7 +189,8 @@ private:
GxsCommentDialog *commentWidget(const RsGxsMessageId &msgId);
protected:
void updateSearchResults();
void updateSearchResults(const TurtleRequestId &sid);
void updateSearchResults(); // update all searches
bool mCountChildMsgs; // Count unread child messages?

View file

@ -61,9 +61,7 @@ void GxsChannelDialog::handleEvent_main_thread(std::shared_ptr<const RsEvent> ev
{
const RsGxsChannelEvent *e = dynamic_cast<const RsGxsChannelEvent*>(event.get());
if(!e)
return;
if(e)
switch(e->mChannelEventCode)
{
case RsChannelEventCode::NEW_MESSAGE: // [[fallthrough]];
@ -72,11 +70,6 @@ void GxsChannelDialog::handleEvent_main_thread(std::shared_ptr<const RsEvent> ev
updateGroupStatisticsReal(e->mChannelGroupId); // update the list immediately
break;
case RsChannelEventCode::RECEIVED_DISTANT_SEARCH_RESULT:
mSearchResults.insert(e->mDistantSearchRequestId);
updateSearchResults();
break;
case RsChannelEventCode::NEW_CHANNEL: // [[fallthrough]];
case RsChannelEventCode::SUBSCRIBE_STATUS_CHANGED:
updateDisplay(true);
@ -89,6 +82,13 @@ void GxsChannelDialog::handleEvent_main_thread(std::shared_ptr<const RsEvent> ev
default:
break;
}
const RsGxsChannelSearchResultEvent*f = dynamic_cast<const RsGxsChannelSearchResultEvent*>(event.get());
if(nullptr != f)
for(auto it:f->mSearchResultsMap)
updateSearchResults(it.first);
}
GxsChannelDialog::~GxsChannelDialog()
@ -396,21 +396,36 @@ void GxsChannelDialog::groupInfoToGroupItemInfo(const RsGxsGenericGroupData *gro
groupItemInfo.description = QString::fromUtf8(channelGroupData->mDescription.c_str());
}
void GxsChannelDialog::clearDistantSearchResults(TurtleRequestId id)
{
rsGxsChannels->clearDistantSearchResults(id);
}
TurtleRequestId GxsChannelDialog::distantSearch(const QString& search_string)
{
return rsGxsChannels->turtleSearchRequest(search_string.toStdString()) ;
}
bool GxsChannelDialog::getDistantSearchResults(TurtleRequestId id, std::map<RsGxsGroupId,RsGxsGroupSummary>& group_infos)
bool GxsChannelDialog::getDistantSearchResults(TurtleRequestId id, std::map<RsGxsGroupId,RsGxsGroupSearchResults>& group_infos)
{
return rsGxsChannels->retrieveDistantSearchResults(id,group_infos);
}
RsGxsGenericGroupData *GxsChannelDialog::getDistantSearchResultGroupData(const RsGxsGroupId& group_id)
{
RsGxsChannelGroup channel_group;
if(rsGxsChannels->getDistantSearchResultGroupData(group_id,channel_group))
return new RsGxsGenericGroupData(channel_group);
else
return nullptr;
}
void GxsChannelDialog::checkRequestGroup(const RsGxsGroupId& grpId)
{
RsGxsChannelGroup distant_group;
if( rsGxsChannels->retrieveDistantGroup(grpId,distant_group)) // normally we should also check that the group meta is not already here.
if( rsGxsChannels->getDistantSearchResultGroupData(grpId,distant_group)) // normally we should also check that the group meta is not already here.
{
std::cerr << "GxsChannelDialog::checkRequestGroup() sending turtle request for group data for group " << grpId << std::endl;
rsGxsChannels->turtleGroupRequest(grpId);

View file

@ -43,10 +43,12 @@ public:
protected:
/* GxsGroupFrameDialog */
virtual bool getDistantSearchResults(TurtleRequestId id, std::map<RsGxsGroupId,RsGxsGroupSummary>& group_infos);
virtual bool getDistantSearchResults(TurtleRequestId id, std::map<RsGxsGroupId, RsGxsGroupSearchResults> &group_infos) override;
virtual RsGxsGenericGroupData *getDistantSearchResultGroupData(const RsGxsGroupId& group_id) override;
virtual TurtleRequestId distantSearch(const QString& search_string) ;
virtual void checkRequestGroup(const RsGxsGroupId& grpId) ;
virtual TurtleRequestId distantSearch(const QString& search_string) override;
virtual void checkRequestGroup(const RsGxsGroupId& grpId) override ;
virtual void clearDistantSearchResults(TurtleRequestId id) override;
// Implementation of some abstract methods in GxsGroupFrameDialog

View file

@ -59,6 +59,7 @@ static const int mTokenTypeGroupData = 1;
static const int CHANNEL_TABS_DETAILS= 0;
static const int CHANNEL_TABS_POSTS = 1;
static const int CHANNEL_TABS_FILES = 2;
/* View mode */
#define VIEW_MODE_FEEDS 1
@ -538,23 +539,20 @@ void GxsChannelPostsWidgetWithModel::updateGroupData()
RsThread::async([this]()
{
RsGxsChannelGroup group;
std::vector<RsGxsChannelGroup> groups;
if(!rsGxsChannels->getChannelsInfo(std::list<RsGxsGroupId>{ groupId() }, groups))
if(rsGxsChannels->getChannelsInfo(std::list<RsGxsGroupId>{ groupId() }, groups) && groups.size()==1)
group = groups[0];
else if(!rsGxsChannels->getDistantSearchResultGroupData(groupId(),group))
{
std::cerr << __PRETTY_FUNCTION__ << " failed to get autodownload value for channel: " << groupId() << std::endl;
std::cerr << __PRETTY_FUNCTION__ << " failed to get group data for channel: " << groupId() << std::endl;
return;
}
if(groups.size() != 1)
{
RsErr() << __PRETTY_FUNCTION__ << " cannot retrieve channel data for group ID " << groupId() << ": ERROR." << std::endl;
return;
}
RsQThreadUtils::postToObject( [this,groups]()
RsQThreadUtils::postToObject( [this,group]()
{
mGroup = groups[0];
mGroup = group;
mChannelPostsModel->updateChannel(groupId());
insertChannelDetails(mGroup);
@ -779,12 +777,14 @@ void GxsChannelPostsWidgetWithModel::insertChannelDetails(const RsGxsChannelGrou
//ui->feedToolButton->setEnabled(true);
//ui->fileToolButton->setEnabled(true);
ui->channel_TW->setTabEnabled(CHANNEL_TABS_POSTS,true);
ui->channel_TW->setTabEnabled(CHANNEL_TABS_FILES,true);
ui->details_TW->setEnabled(true);
}
else
{
ui->details_TW->setEnabled(false);
ui->channel_TW->setTabEnabled(CHANNEL_TABS_POSTS,false);
ui->channel_TW->setTabEnabled(CHANNEL_TABS_FILES,false);
}

View file

@ -161,7 +161,7 @@
<item>
<widget class="QTabWidget" name="channel_TW">
<property name="currentIndex">
<number>1</number>
<number>0</number>
</property>
<widget class="QWidget" name="tab_3">
<attribute name="title">

View file

@ -669,8 +669,11 @@ QVariant RsGxsForumModel::displayRole(const ForumModelPostEntry& fmpe,int col) c
return QVariant(DateTime::formatDateTime(qtime));
}
case COLUMN_THREAD_DISTRIBUTION:
case COLUMN_THREAD_AUTHOR:{
case COLUMN_THREAD_DISTRIBUTION: // passthrough // handled by delegate.
case COLUMN_THREAD_MSGID:
return QVariant();
case COLUMN_THREAD_AUTHOR:
{
QString name;
RsGxsId id = RsGxsId(fmpe.mAuthorId.toStdString());
@ -680,7 +683,6 @@ QVariant RsGxsForumModel::displayRole(const ForumModelPostEntry& fmpe,int col) c
return name;
return QVariant(tr("[Unknown]"));
}
case COLUMN_THREAD_MSGID: return QVariant();
#ifdef TODO
if (filterColumn == COLUMN_THREAD_CONTENT) {
// need content for filter

View file

@ -134,6 +134,13 @@ public:
const QPoint p = QPoint((r.width() - pix.width())/2, (r.height() - pix.height())/2);
painter->drawPixmap(r.topLeft() + p, pix);
}
virtual QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const override
{
static auto img(FilesDefs::getPixmapFromQtResourcePath(IMAGE_WARNING_YELLOW));
return QSize(img.width()*1.2,option.rect.height());
}
};
class ReadStatusItemDelegate: public QStyledItemDelegate
@ -183,6 +190,13 @@ public:
const QPoint p = QPoint((r.width() - pix.width())/2, (r.height() - pix.height())/2);
painter->drawPixmap(r.topLeft() + p, pix);
}
virtual QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const override
{
static auto img(FilesDefs::getPixmapFromQtResourcePath(":/images/message-state-unread.png"));
return QSize(img.width()*1.2,option.rect.height());
}
};
class ForumPostSortFilterProxyModel: public QSortFilterProxyModel
@ -299,9 +313,10 @@ GxsForumThreadWidget::GxsForumThreadWidget(const RsGxsGroupId &forumId, QWidget
QHeaderView * ttheader = ui->threadTreeWidget->header () ;
ttheader->resizeSection (RsGxsForumModel::COLUMN_THREAD_DATE, 140*f);
ttheader->resizeSection (RsGxsForumModel::COLUMN_THREAD_TITLE, 440*f);
ttheader->resizeSection (RsGxsForumModel::COLUMN_THREAD_DISTRIBUTION, 24*f);
ttheader->resizeSection (RsGxsForumModel::COLUMN_THREAD_AUTHOR, 150*f);
ttheader->resizeSection (RsGxsForumModel::COLUMN_THREAD_READ, 24*f);
ui->threadTreeWidget->resizeColumnToContents(RsGxsForumModel::COLUMN_THREAD_DISTRIBUTION);
ui->threadTreeWidget->resizeColumnToContents(RsGxsForumModel::COLUMN_THREAD_READ);
QHeaderView_setSectionResizeModeColumn(ttheader, RsGxsForumModel::COLUMN_THREAD_TITLE, QHeaderView::Interactive);
QHeaderView_setSectionResizeModeColumn(ttheader, RsGxsForumModel::COLUMN_THREAD_DATE, QHeaderView::Interactive);