Merge pull request #2221 from PhenomRetroShare/Fix_ForSelfBuiltQtQAssert

Fix for running with Self-Built Qt
This commit is contained in:
csoler 2021-01-19 22:30:55 +01:00 committed by GitHub
commit 41727210cd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 413 additions and 428 deletions

View File

@ -140,42 +140,38 @@ void RsPostedPostsModel::initEmptyHierarchy()
void RsPostedPostsModel::preMods() void RsPostedPostsModel::preMods()
{ {
beginResetModel(); emit layoutAboutToBeChanged();
} }
void RsPostedPostsModel::postMods() void RsPostedPostsModel::postMods()
{ {
endResetModel(); update();
emit layoutChanged();
emit dataChanged(createIndex(0,0,(void*)NULL), createIndex(mDisplayedNbPosts,0,(void*)NULL));
} }
void RsPostedPostsModel::update() void RsPostedPostsModel::update()
{ {
emit dataChanged(createIndex(0,0,(void*)NULL), createIndex(mDisplayedNbPosts,0,(void*)NULL)); emit dataChanged(createIndex(0,0,(void*)NULL), createIndex(mDisplayedNbPosts,0,(void*)NULL));
} }
void RsPostedPostsModel::triggerRedraw() void RsPostedPostsModel::triggerRedraw()
{ {
preMods(); preMods();
postMods(); postMods();
} }
void RsPostedPostsModel::setFilter(const QStringList& strings, uint32_t& count) void RsPostedPostsModel::setFilter(const QStringList& strings, uint32_t& count)
{ {
preMods(); preMods();
beginRemoveRows(QModelIndex(),0,rowCount()-1); beginResetModel();
endRemoveRows(); mFilteredPosts.clear();
endResetModel();
if(strings.empty()) if(strings.empty())
{ {
mFilteredPosts.clear();
for(int i=0;i<(int)(mPosts.size());++i) for(int i=0;i<(int)(mPosts.size());++i)
mFilteredPosts.push_back(i); mFilteredPosts.push_back(i);
} }
else else
{ {
mFilteredPosts.clear();
//mFilteredPosts.push_back(0);
for(int i=0;i<static_cast<int>(mPosts.size());++i) for(int i=0;i<static_cast<int>(mPosts.size());++i)
{ {
bool passes_strings = true; bool passes_strings = true;
@ -199,8 +195,11 @@ void RsPostedPostsModel::setFilter(const QStringList& strings, uint32_t& count)
std::cerr << "After filtering: " << count << " posts remain." << std::endl; std::cerr << "After filtering: " << count << " posts remain." << std::endl;
beginInsertRows(QModelIndex(),0,rowCount()-1); if (rowCount()>0)
endInsertRows(); {
beginInsertRows(QModelIndex(),0,rowCount()-1);
endInsertRows();
}
postMods(); postMods();
} }
@ -210,11 +209,11 @@ int RsPostedPostsModel::rowCount(const QModelIndex& parent) const
if(parent.column() > 0) if(parent.column() > 0)
return 0; return 0;
if(mFilteredPosts.empty()) // security. Should never happen. if(mFilteredPosts.empty()) // rowCount is called by internal Qt so maybe before posts are populated.
return 0; return 0;
if(!parent.isValid()) if(!parent.isValid())
return mDisplayedNbPosts; return mDisplayedNbPosts;
RsErr() << __PRETTY_FUNCTION__ << " rowCount cannot figure out the porper number of rows." << std::endl; RsErr() << __PRETTY_FUNCTION__ << " rowCount cannot figure out the porper number of rows." << std::endl;
return 0; return 0;
@ -473,7 +472,7 @@ private:
Qt::ItemFlags RsPostedPostsModel::flags(const QModelIndex& index) const Qt::ItemFlags RsPostedPostsModel::flags(const QModelIndex& index) const
{ {
if (!index.isValid()) if (!index.isValid())
return 0; return Qt::ItemFlags();
return QAbstractItemModel::flags(index) | Qt::ItemIsEditable; return QAbstractItemModel::flags(index) | Qt::ItemIsEditable;
} }
@ -495,16 +494,16 @@ void RsPostedPostsModel::setPostsInterval(int start,int nb_posts)
preMods(); preMods();
uint32_t old_nb_rows = rowCount() ; uint32_t old_nb_rows = rowCount() ;
mDisplayedNbPosts = (uint32_t)std::min(nb_posts,(int)mFilteredPosts.size() - (start+1)); mDisplayedNbPosts = (uint32_t)std::min(nb_posts,(int)mFilteredPosts.size() - (start+1));
mDisplayedStartIndex = start; mDisplayedStartIndex = start;
beginRemoveRows(QModelIndex(),mDisplayedNbPosts,old_nb_rows); beginRemoveRows(QModelIndex(),mDisplayedNbPosts,old_nb_rows);
endRemoveRows(); endRemoveRows();
beginInsertRows(QModelIndex(),old_nb_rows,mDisplayedNbPosts); beginInsertRows(QModelIndex(),old_nb_rows,mDisplayedNbPosts);
endInsertRows(); endInsertRows();
postMods(); postMods();
} }
@ -517,26 +516,30 @@ void RsPostedPostsModel::deepUpdate()
void RsPostedPostsModel::setPosts(const RsPostedGroup& group, std::vector<RsPostedPost>& posts) void RsPostedPostsModel::setPosts(const RsPostedGroup& group, std::vector<RsPostedPost>& posts)
{ {
preMods(); preMods();
beginRemoveRows(QModelIndex(),0,rowCount()-1); beginResetModel();
endRemoveRows();
mPosts.clear(); mPosts.clear();
mPostedGroup = group; mPostedGroup = group;
createPostsArray(posts); endResetModel();
std::sort(mPosts.begin(),mPosts.end(), PostSorter(mSortingStrategy)); createPostsArray(posts);
uint32_t tmpval; std::sort(mPosts.begin(),mPosts.end(), PostSorter(mSortingStrategy));
setFilter(QStringList(),tmpval);
mDisplayedNbPosts = std::min((uint32_t)mFilteredPosts.size(),DEFAULT_DISPLAYED_NB_POSTS); uint32_t tmpval;
mDisplayedStartIndex = 0; setFilter(QStringList(),tmpval);
beginInsertRows(QModelIndex(),0,rowCount()-1); mDisplayedNbPosts = std::min((uint32_t)mFilteredPosts.size(),DEFAULT_DISPLAYED_NB_POSTS);
endInsertRows(); mDisplayedStartIndex = 0;
if (rowCount()>0)
{
beginInsertRows(QModelIndex(),0,rowCount()-1);
endInsertRows();
}
postMods(); postMods();
@ -599,8 +602,6 @@ void RsPostedPostsModel::update_posts(const RsGxsGroupId& group_id)
}); });
} }
//static bool decreasing_time_comp(const std::pair<time_t,RsGxsMessageId>& e1,const std::pair<time_t,RsGxsMessageId>& e2) { return e2.first < e1.first ; }
void RsPostedPostsModel::createPostsArray(std::vector<RsPostedPost>& posts) void RsPostedPostsModel::createPostsArray(std::vector<RsPostedPost>& posts)
{ {
#ifdef TODO #ifdef TODO

View File

@ -152,93 +152,95 @@ void RsFriendListModel::setDisplayGroups(bool b)
} }
void RsFriendListModel::preMods() void RsFriendListModel::preMods()
{ {
beginResetModel(); emit layoutAboutToBeChanged();
} }
void RsFriendListModel::postMods() void RsFriendListModel::postMods()
{ {
endResetModel(); emit dataChanged(createIndex(0,0,(void*)NULL), createIndex(rowCount()-1,columnCount()-1,(void*)NULL));
emit layoutChanged();
emit dataChanged(createIndex(0,0,(void*)NULL), createIndex(rowCount()-1,columnCount()-1,(void*)NULL));
} }
int RsFriendListModel::rowCount(const QModelIndex& parent) const int RsFriendListModel::rowCount(const QModelIndex& parent) const
{ {
if(parent.column() >= COLUMN_THREAD_NB_COLUMNS) if(parent.column() >= COLUMN_THREAD_NB_COLUMNS)
return 0; return 0;
if(parent.internalId() == 0) if(parent.internalId() == 0)
return mTopLevel.size(); return mTopLevel.size();
EntryIndex index; EntryIndex index;
if(!convertInternalIdToIndex<sizeof(uintptr_t)>(parent.internalId(),index)) if(!convertInternalIdToIndex<sizeof(uintptr_t)>(parent.internalId(),index))
return 0; return 0;
if(index.type == ENTRY_TYPE_GROUP) if(index.type == ENTRY_TYPE_GROUP)
return mGroups[index.group_index].child_profile_indices.size(); return mGroups[index.group_index].child_profile_indices.size();
if(index.type == ENTRY_TYPE_PROFILE) if(index.type == ENTRY_TYPE_PROFILE)
{ {
if(index.group_index < UNDEFINED_GROUP_INDEX_VALUE) if(index.group_index < UNDEFINED_GROUP_INDEX_VALUE)
return mProfiles[mGroups[index.group_index].child_profile_indices[index.profile_index]].child_node_indices.size(); return mProfiles[mGroups[index.group_index].child_profile_indices[index.profile_index]].child_node_indices.size();
else else
return mProfiles[index.profile_index].child_node_indices.size(); return mProfiles[index.profile_index].child_node_indices.size();
} }
else //if(index.type == ENTRY_TYPE_NODE) else //if(index.type == ENTRY_TYPE_NODE)
return 0; return 0;
} }
int RsFriendListModel::columnCount(const QModelIndex &parent) const int RsFriendListModel::columnCount(const QModelIndex &/*parent*/) const
{ {
return COLUMN_THREAD_NB_COLUMNS ; return COLUMN_THREAD_NB_COLUMNS ;
} }
bool RsFriendListModel::hasChildren(const QModelIndex &parent) const bool RsFriendListModel::hasChildren(const QModelIndex &parent) const
{ {
if(!parent.isValid()) if(!parent.isValid())
return true; return true;
EntryIndex parent_index ; EntryIndex parent_index ;
convertInternalIdToIndex<sizeof(uintptr_t)>(parent.internalId(),parent_index); convertInternalIdToIndex<sizeof(uintptr_t)>(parent.internalId(),parent_index);
if(parent_index.type == ENTRY_TYPE_NODE) if(parent_index.type == ENTRY_TYPE_NODE)
return false; return false;
if(parent_index.type == ENTRY_TYPE_PROFILE) if(parent_index.type == ENTRY_TYPE_PROFILE)
{
if(parent_index.group_index < UNDEFINED_GROUP_INDEX_VALUE) if(parent_index.group_index < UNDEFINED_GROUP_INDEX_VALUE)
return !mProfiles[mGroups[parent_index.group_index].child_profile_indices[parent_index.profile_index]].child_node_indices.empty(); return !mProfiles[mGroups[parent_index.group_index].child_profile_indices[parent_index.profile_index]].child_node_indices.empty();
else else
return !mProfiles[parent_index.profile_index].child_node_indices.empty(); return !mProfiles[parent_index.profile_index].child_node_indices.empty();
}
if(parent_index.type == ENTRY_TYPE_GROUP) if(parent_index.type == ENTRY_TYPE_GROUP)
return !mGroups[parent_index.group_index].child_profile_indices.empty(); return !mGroups[parent_index.group_index].child_profile_indices.empty();
return false; return false;
} }
RsFriendListModel::EntryIndex RsFriendListModel::EntryIndex::parent() const RsFriendListModel::EntryIndex RsFriendListModel::EntryIndex::parent() const
{ {
EntryIndex i(*this); EntryIndex i(*this);
switch(type) switch(type)
{ {
case ENTRY_TYPE_GROUP: return EntryIndex(); case ENTRY_TYPE_GROUP: return EntryIndex();
case ENTRY_TYPE_PROFILE: case ENTRY_TYPE_PROFILE:
if(i.group_index==UNDEFINED_GROUP_INDEX_VALUE) if(i.group_index==UNDEFINED_GROUP_INDEX_VALUE)
return EntryIndex(); return EntryIndex();
else else
{ {
i.type = ENTRY_TYPE_GROUP; i.type = ENTRY_TYPE_GROUP;
i.profile_index = UNDEFINED_PROFILE_INDEX_VALUE; i.profile_index = UNDEFINED_PROFILE_INDEX_VALUE;
} }
break; break;
case ENTRY_TYPE_NODE: i.type = ENTRY_TYPE_PROFILE; case ENTRY_TYPE_NODE: i.type = ENTRY_TYPE_PROFILE;
i.node_index = UNDEFINED_NODE_INDEX_VALUE; i.node_index = UNDEFINED_NODE_INDEX_VALUE;
break; break;
} case ENTRY_TYPE_UNKNOWN:
RS_ERR("Unknown Entry type for parent.");
}
return i; return i;
} }
RsFriendListModel::EntryIndex RsFriendListModel::EntryIndex::child(int row,const std::vector<EntryIndex>& top_level) const RsFriendListModel::EntryIndex RsFriendListModel::EntryIndex::child(int row,const std::vector<EntryIndex>& top_level) const
@ -310,32 +312,32 @@ QModelIndex RsFriendListModel::index(int row, int column, const QModelIndex& par
QModelIndex RsFriendListModel::parent(const QModelIndex& index) const QModelIndex RsFriendListModel::parent(const QModelIndex& index) const
{ {
if(!index.isValid()) if(!index.isValid())
return QModelIndex(); return QModelIndex();
EntryIndex I ; EntryIndex I ;
convertInternalIdToIndex<sizeof(uintptr_t)>(index.internalId(),I); convertInternalIdToIndex<sizeof(uintptr_t)>(index.internalId(),I);
EntryIndex p = I.parent(); EntryIndex p = I.parent();
if(p.type == ENTRY_TYPE_UNKNOWN) if(p.type == ENTRY_TYPE_UNKNOWN)
return QModelIndex(); return QModelIndex();
quintptr i; quintptr i;
convertIndexToInternalId<sizeof(uintptr_t)>(p,i); convertIndexToInternalId<sizeof(uintptr_t)>(p,i);
return createIndex(I.parentRow(mGroups.size()),0,i); return createIndex(I.parentRow(mGroups.size()),0,i);
} }
Qt::ItemFlags RsFriendListModel::flags(const QModelIndex& index) const Qt::ItemFlags RsFriendListModel::flags(const QModelIndex& index) const
{ {
if (!index.isValid()) if (!index.isValid())
return 0; return Qt::ItemFlags();
return QAbstractItemModel::flags(index); return QAbstractItemModel::flags(index);
} }
QVariant RsFriendListModel::headerData(int section, Qt::Orientation orientation, int role) const QVariant RsFriendListModel::headerData(int section, Qt::Orientation /*orientation*/, int role) const
{ {
if(role == Qt::DisplayRole) if(role == Qt::DisplayRole)
switch(section) switch(section)
@ -414,17 +416,17 @@ QVariant RsFriendListModel::textColorRole(const EntryIndex& fmpe,int column) con
} }
} }
QVariant RsFriendListModel::statusRole(const EntryIndex& fmpe,int column) const QVariant RsFriendListModel::statusRole(const EntryIndex& /*fmpe*/,int /*column*/) const
{ {
return QVariant();//fmpe.mMsgStatus); return QVariant();//fmpe.mMsgStatus);
} }
bool RsFriendListModel::passesFilter(const EntryIndex& e,int column) const bool RsFriendListModel::passesFilter(const EntryIndex& e,int /*column*/) const
{ {
QString s ; QString s ;
bool passes_strings = true ; bool passes_strings = true ;
if(e.type == ENTRY_TYPE_PROFILE && !mFilterStrings.empty()) if(e.type == ENTRY_TYPE_PROFILE && !mFilterStrings.empty())
{ {
switch(mFilterType) switch(mFilterType)
{ {
@ -435,6 +437,8 @@ bool RsFriendListModel::passesFilter(const EntryIndex& e,int column) const
if(s.isNull()) if(s.isNull())
passes_strings = false; passes_strings = false;
break; break;
case FILTER_TYPE_NONE:
RS_ERR("None Type for Filter.");
}; };
} }
@ -447,18 +451,15 @@ bool RsFriendListModel::passesFilter(const EntryIndex& e,int column) const
QVariant RsFriendListModel::filterRole(const EntryIndex& e,int column) const QVariant RsFriendListModel::filterRole(const EntryIndex& e,int column) const
{ {
if(passesFilter(e,column)) if(passesFilter(e,column))
return QVariant(FilterString); return QVariant(FilterString);
return QVariant(QString()); return QVariant(QString());
} }
uint32_t RsFriendListModel::updateFilterStatus(ForumModelIndex i,int column,const QStringList& strings) uint32_t RsFriendListModel::updateFilterStatus(ForumModelIndex /*i*/,int /*column*/,const QStringList& /*strings*/)
{ {
QString s ; return 0;
uint32_t count = 0;
return count;
} }
@ -479,7 +480,7 @@ void RsFriendListModel::setFilter(FilterType filter_type, const QStringList& str
postMods(); postMods();
} }
QVariant RsFriendListModel::toolTipRole(const EntryIndex& fmpe,int column) const QVariant RsFriendListModel::toolTipRole(const EntryIndex& /*fmpe*/,int /*column*/) const
{ {
return QVariant(); return QVariant();
} }
@ -489,14 +490,14 @@ QVariant RsFriendListModel::sizeHintRole(const EntryIndex& e,int col) const
float x_factor = QFontMetricsF(QApplication::font()).height()/14.0f ; float x_factor = QFontMetricsF(QApplication::font()).height()/14.0f ;
float y_factor = QFontMetricsF(QApplication::font()).height()/14.0f ; float y_factor = QFontMetricsF(QApplication::font()).height()/14.0f ;
if(e.type == ENTRY_TYPE_NODE) if(e.type == ENTRY_TYPE_NODE)
y_factor *= 3.0; y_factor *= 3.0;
if((e.type == ENTRY_TYPE_PROFILE) && !isProfileExpanded(e)) if((e.type == ENTRY_TYPE_PROFILE) && !isProfileExpanded(e))
y_factor *= 3.0; y_factor *= 3.0;
if(e.type == ENTRY_TYPE_GROUP) if(e.type == ENTRY_TYPE_GROUP)
y_factor = std::max(y_factor, 24.0f / 14.0f ); // allows to fit the 24 pixels icon for groups in the line y_factor = std::max(y_factor, 24.0f / 14.0f ); // allows to fit the 24 pixels icon for groups in the line
switch(col) switch(col)
{ {
@ -542,7 +543,7 @@ QVariant RsFriendListModel::sortRole(const EntryIndex& entry,int column) const
} }
} }
QVariant RsFriendListModel::onlineRole(const EntryIndex& e, int col) const QVariant RsFriendListModel::onlineRole(const EntryIndex& e, int /*col*/) const
{ {
switch(e.type) switch(e.type)
{ {
@ -698,7 +699,7 @@ QVariant RsFriendListModel::displayRole(const EntryIndex& e, int col) const
if(col == COLUMN_THREAD_IP) return QVariant(most_recent_ip); if(col == COLUMN_THREAD_IP) return QVariant(most_recent_ip);
} }
} }// Fall-through
default: default:
return QVariant(); return QVariant();
} }
@ -826,7 +827,6 @@ const RsFriendListModel::HierarchicalNodeInformation *RsFriendListModel::getNode
if(e.node_index >= mProfiles[pindex].child_node_indices.size()) if(e.node_index >= mProfiles[pindex].child_node_indices.size())
return NULL ; return NULL ;
time_t now = time(NULL);
HierarchicalNodeInformation& node(mLocations[mProfiles[pindex].child_node_indices[e.node_index]]); HierarchicalNodeInformation& node(mLocations[mProfiles[pindex].child_node_indices[e.node_index]]);
return &node; return &node;
@ -895,8 +895,6 @@ void RsFriendListModel::clear()
emit friendListChanged(); emit friendListChanged();
} }
static bool decreasing_time_comp(const std::pair<time_t,RsGxsMessageId>& e1,const std::pair<time_t,RsGxsMessageId>& e2) { return e2.first < e1.first ; }
void RsFriendListModel::debug_dump() const void RsFriendListModel::debug_dump() const
{ {
std::cerr << "==== FriendListModel Debug dump ====" << std::endl; std::cerr << "==== FriendListModel Debug dump ====" << std::endl;
@ -1084,14 +1082,14 @@ void RsFriendListModel::updateInternalData()
{ {
preMods(); preMods();
beginRemoveRows(QModelIndex(),0,mTopLevel.size()-1); beginResetModel();
mGroups.clear(); mGroups.clear();
mProfiles.clear(); mProfiles.clear();
mLocations.clear(); mLocations.clear();
mTopLevel.clear(); mTopLevel.clear();
endRemoveRows(); endResetModel();
auto TL = mTopLevel ; // This allows to fill TL without touching mTopLevel outside of [begin/end]InsertRows(). auto TL = mTopLevel ; // This allows to fill TL without touching mTopLevel outside of [begin/end]InsertRows().
@ -1218,17 +1216,19 @@ void RsFriendListModel::updateInternalData()
TL.push_back(e); TL.push_back(e);
} }
// finally, tell the model client that layout has changed. // finally, tell the model client that layout has changed.
beginInsertRows(QModelIndex(),0,TL.size()-1); mTopLevel = TL;
mTopLevel = TL; if (TL.size()>0)
{
beginInsertRows(QModelIndex(),0,TL.size()-1);
endInsertRows();
}
endInsertRows(); postMods();
postMods(); mLastInternalDataUpdate = time(NULL);
mLastInternalDataUpdate = time(NULL);
} }
QModelIndex RsFriendListModel::getIndexOfGroup(const RsNodeGroupId& mid) const QModelIndex RsFriendListModel::getIndexOfGroup(const RsNodeGroupId& mid) const
@ -1251,7 +1251,7 @@ void RsFriendListModel::collapseItem(const QModelIndex& index)
if(!convertInternalIdToIndex<sizeof(uintptr_t)>(index.internalId(),entry)) if(!convertInternalIdToIndex<sizeof(uintptr_t)>(index.internalId(),entry))
return; return;
const HierarchicalProfileInformation *hp = getProfileInfo(entry); const HierarchicalProfileInformation *hp = getProfileInfo(entry);
const HierarchicalGroupInformation *hg = getGroupInfo(entry); const HierarchicalGroupInformation *hg = getGroupInfo(entry);
std::string s ; std::string s ;
@ -1276,7 +1276,7 @@ void RsFriendListModel::expandItem(const QModelIndex& index)
if(!convertInternalIdToIndex<sizeof(uintptr_t)>(index.internalId(),entry)) if(!convertInternalIdToIndex<sizeof(uintptr_t)>(index.internalId(),entry))
return; return;
const HierarchicalProfileInformation *hp = getProfileInfo(entry); const HierarchicalProfileInformation *hp = getProfileInfo(entry);
const HierarchicalGroupInformation *hg = getGroupInfo(entry); const HierarchicalGroupInformation *hg = getGroupInfo(entry);
std::string s ; std::string s ;

View File

@ -37,7 +37,9 @@
Q_DECLARE_METATYPE(ChannelPostFileInfo) Q_DECLARE_METATYPE(ChannelPostFileInfo)
#ifdef DEBUG_CHANNEL_MODEL
static std::ostream& operator<<(std::ostream& o, const QModelIndex& i);// defined elsewhere static std::ostream& operator<<(std::ostream& o, const QModelIndex& i);// defined elsewhere
#endif
RsGxsChannelPostFilesModel::RsGxsChannelPostFilesModel(QObject *parent) RsGxsChannelPostFilesModel::RsGxsChannelPostFilesModel(QObject *parent)
: QAbstractItemModel(parent) : QAbstractItemModel(parent)
@ -50,45 +52,43 @@ RsGxsChannelPostFilesModel::RsGxsChannelPostFilesModel(QObject *parent)
void RsGxsChannelPostFilesModel::initEmptyHierarchy() void RsGxsChannelPostFilesModel::initEmptyHierarchy()
{ {
preMods(); beginResetModel();
mFiles.clear(); mFiles.clear();
mFilteredFiles.clear(); mFilteredFiles.clear();
postMods(); endResetModel();
} }
void RsGxsChannelPostFilesModel::preMods() void RsGxsChannelPostFilesModel::preMods()
{ {
//emit layoutAboutToBeChanged(); //Generate SIGSEGV when click on button move next/prev. emit layoutAboutToBeChanged();
beginResetModel();
} }
void RsGxsChannelPostFilesModel::postMods() void RsGxsChannelPostFilesModel::postMods()
{ {
endResetModel(); emit QAbstractItemModel::dataChanged(createIndex(0,0,(void*)NULL), createIndex(mFilteredFiles.size(),COLUMN_FILES_NB_COLUMNS-1,(void*)NULL));
emit layoutChanged();
emit dataChanged(createIndex(0,0,(void*)NULL), createIndex(mFilteredFiles.size(),COLUMN_FILES_NB_COLUMNS-1,(void*)NULL));
} }
void RsGxsChannelPostFilesModel::update() void RsGxsChannelPostFilesModel::update()
{ {
emit dataChanged(createIndex(0,0,(void*)NULL), createIndex(mFilteredFiles.size(),COLUMN_FILES_NB_COLUMNS-1,(void*)NULL)); preMods();
postMods();
} }
int RsGxsChannelPostFilesModel::rowCount(const QModelIndex& parent) const int RsGxsChannelPostFilesModel::rowCount(const QModelIndex& parent) const
{ {
if(parent.column() > 0) if(parent.column() > 0)
return 0; return 0;
if(mFilteredFiles.empty()) // security. Should never happen. if(mFilteredFiles.empty()) // security. Should never happen.
return 0; return 0;
if(!parent.isValid()) if(!parent.isValid())
return mFilteredFiles.size(); // mFilteredPosts always has an item at 0, so size()>=1, and mColumn>=1 return mFilteredFiles.size(); // mFilteredPosts always has an item at 0, so size()>=1, and mColumn>=1
RsErr() << __PRETTY_FUNCTION__ << " rowCount cannot figure out the porper number of rows." << std::endl; RS_ERR(" rowCount cannot figure out the proper number of rows.");
return 0; return 0;
} }
int RsGxsChannelPostFilesModel::columnCount(const QModelIndex &/*parent*/) const int RsGxsChannelPostFilesModel::columnCount(const QModelIndex &/*parent*/) const
@ -99,15 +99,15 @@ int RsGxsChannelPostFilesModel::columnCount(const QModelIndex &/*parent*/) const
bool RsGxsChannelPostFilesModel::getFileData(const QModelIndex& i,ChannelPostFileInfo& fmpe) const bool RsGxsChannelPostFilesModel::getFileData(const QModelIndex& i,ChannelPostFileInfo& fmpe) const
{ {
if(!i.isValid()) if(!i.isValid())
return true; return true;
quintptr ref = i.internalId(); quintptr ref = i.internalId();
uint32_t entry = 0; uint32_t entry = 0;
if(!convertRefPointerToTabEntry(ref,entry) || entry >= mFiles.size()) if(!convertRefPointerToTabEntry(ref,entry) || entry >= mFiles.size())
return false ; return false ;
fmpe = mFiles[mFilteredFiles[entry]]; fmpe = mFiles[mFilteredFiles[entry]];
return true; return true;
@ -115,8 +115,8 @@ bool RsGxsChannelPostFilesModel::getFileData(const QModelIndex& i,ChannelPostFil
bool RsGxsChannelPostFilesModel::hasChildren(const QModelIndex &parent) const bool RsGxsChannelPostFilesModel::hasChildren(const QModelIndex &parent) const
{ {
if(!parent.isValid()) if(!parent.isValid())
return true; return true;
return false; // by default, no channel post has children return false; // by default, no channel post has children
} }
@ -167,22 +167,19 @@ QModelIndex RsGxsChannelPostFilesModel::index(int row, int column, const QModelI
return createIndex(row,column,ref) ; return createIndex(row,column,ref) ;
} }
QModelIndex RsGxsChannelPostFilesModel::parent(const QModelIndex& index) const QModelIndex RsGxsChannelPostFilesModel::parent(const QModelIndex& /*index*/) const
{ {
if(!index.isValid())
return QModelIndex();
return QModelIndex(); // there's no hierarchy here. So nothing to do! return QModelIndex(); // there's no hierarchy here. So nothing to do!
} }
Qt::ItemFlags RsGxsChannelPostFilesModel::flags(const QModelIndex& index) const Qt::ItemFlags RsGxsChannelPostFilesModel::flags(const QModelIndex& index) const
{ {
if (!index.isValid()) if (!index.isValid())
return 0; return Qt::ItemFlag();
if(index.column() == COLUMN_FILES_FILE) if(index.column() == COLUMN_FILES_FILE)
return QAbstractItemModel::flags(index) | Qt::ItemIsEditable; return QAbstractItemModel::flags(index) | Qt::ItemIsEditable;
else else
return QAbstractItemModel::flags(index); return QAbstractItemModel::flags(index);
} }
@ -191,7 +188,7 @@ quintptr RsGxsChannelPostFilesModel::getChildRef(quintptr ref,int index) const
if (index < 0) if (index < 0)
return 0; return 0;
if(ref == quintptr(0)) if(ref == quintptr(0))
{ {
quintptr new_ref; quintptr new_ref;
convertTabEntryToRefPointer(index,new_ref); convertTabEntryToRefPointer(index,new_ref);
@ -221,15 +218,13 @@ quintptr RsGxsChannelPostFilesModel::getParentRow(quintptr ref,int& row) const
int RsGxsChannelPostFilesModel::getChildrenCount(quintptr ref) const int RsGxsChannelPostFilesModel::getChildrenCount(quintptr ref) const
{ {
uint32_t entry = 0 ; if(ref == quintptr(0))
return rowCount()-1;
if(ref == quintptr(0))
return rowCount()-1;
return 0; return 0;
} }
QVariant RsGxsChannelPostFilesModel::headerData(int section, Qt::Orientation orientation, int role) const QVariant RsGxsChannelPostFilesModel::headerData(int section, Qt::Orientation /*orientation*/, int role) const
{ {
if (role != Qt::DisplayRole) if (role != Qt::DisplayRole)
return QVariant(); return QVariant();
@ -298,39 +293,37 @@ QVariant RsGxsChannelPostFilesModel::data(const QModelIndex &index, int role) co
void RsGxsChannelPostFilesModel::setFilter(const QStringList& strings, uint32_t& count) void RsGxsChannelPostFilesModel::setFilter(const QStringList& strings, uint32_t& count)
{ {
preMods(); preMods();
beginRemoveRows(QModelIndex(),0,rowCount()-1); initEmptyHierarchy();
endRemoveRows();
if(strings.empty()) if(strings.empty())
{ {
mFilteredFiles.clear(); for(uint32_t i=0;i<mFiles.size();++i)
for(uint32_t i=0;i<mFiles.size();++i) mFilteredFiles.push_back(i);
mFilteredFiles.push_back(i); }
}
else else
{ {
mFilteredFiles.clear(); for(uint32_t i=0;i<mFiles.size();++i)
//mFilteredPosts.push_back(0); {
bool passes_strings = true;
for(uint32_t i=0;i<mFiles.size();++i)
{
bool passes_strings = true;
for(auto& s:strings) for(auto& s:strings)
passes_strings = passes_strings && QString::fromStdString(mFiles[i].mName).contains(s,Qt::CaseInsensitive); passes_strings = passes_strings && QString::fromStdString(mFiles[i].mName).contains(s,Qt::CaseInsensitive);
if(passes_strings) if(passes_strings)
mFilteredFiles.push_back(i); mFilteredFiles.push_back(i);
} }
} }
count = mFilteredFiles.size(); count = mFilteredFiles.size();
std::cerr << "After filtering: " << count << " posts remain." << std::endl; std::cerr << "After filtering: " << count << " posts remain." << std::endl;
beginInsertRows(QModelIndex(),0,rowCount()-1); if (rowCount()>0)
endInsertRows(); {
beginInsertRows(QModelIndex(),0,rowCount()-1);
endInsertRows();
}
postMods(); postMods();
} }
@ -372,7 +365,7 @@ void RsGxsChannelPostFilesModel::sort(int column, Qt::SortOrder order)
update(); update();
} }
QVariant RsGxsChannelPostFilesModel::sizeHintRole(int col) const QVariant RsGxsChannelPostFilesModel::sizeHintRole(int /*col*/) const
{ {
float factor = QFontMetricsF(QApplication::font()).height()/14.0f ; float factor = QFontMetricsF(QApplication::font()).height()/14.0f ;
@ -435,42 +428,40 @@ QVariant RsGxsChannelPostFilesModel::userRole(const ChannelPostFileInfo& fmpe,in
void RsGxsChannelPostFilesModel::clear() void RsGxsChannelPostFilesModel::clear()
{ {
preMods();
initEmptyHierarchy(); initEmptyHierarchy();
postMods();
emit channelLoaded(); emit channelLoaded();
} }
void RsGxsChannelPostFilesModel::setFiles(const std::list<ChannelPostFileInfo> &files) void RsGxsChannelPostFilesModel::setFiles(const std::list<ChannelPostFileInfo> &files)
{ {
preMods(); preMods();
beginRemoveRows(QModelIndex(),0,mFilteredFiles.size()-1); initEmptyHierarchy();
endRemoveRows();
initEmptyHierarchy(); for(auto& file:files)
mFiles.push_back(file);
for(auto& file:files) for(uint32_t i=0;i<mFiles.size();++i)
mFiles.push_back(file); mFilteredFiles.push_back(i);
for(uint32_t i=0;i<mFiles.size();++i)
mFilteredFiles.push_back(i);
#ifdef DEBUG_CHANNEL_MODEL #ifdef DEBUG_CHANNEL_MODEL
// debug_dump(); // debug_dump();
#endif #endif
beginInsertRows(QModelIndex(),0,mFilteredFiles.size()-1); if (mFilteredFiles.size()>0)
endInsertRows(); {
beginInsertRows(QModelIndex(),0,mFilteredFiles.size()-1);
postMods(); endInsertRows();
}
emit channelLoaded(); emit channelLoaded();
if(!files.empty()) if(!files.empty())
mTimer->start(5000); mTimer->start(5000);
else else
mTimer->stop(); mTimer->stop();
postMods();
} }

View File

@ -203,23 +203,22 @@ void RsGxsChannelPostsModel::handleEvent_main_thread(std::shared_ptr<const RsEve
void RsGxsChannelPostsModel::initEmptyHierarchy() void RsGxsChannelPostsModel::initEmptyHierarchy()
{ {
preMods(); beginResetModel();
mPosts.clear(); mPosts.clear();
mFilteredPosts.clear(); mFilteredPosts.clear();
postMods(); endResetModel();
} }
void RsGxsChannelPostsModel::preMods() void RsGxsChannelPostsModel::preMods()
{ {
beginResetModel(); emit layoutAboutToBeChanged();
} }
void RsGxsChannelPostsModel::postMods() void RsGxsChannelPostsModel::postMods()
{ {
endResetModel(); triggerViewUpdate();
emit layoutChanged();
triggerViewUpdate();
} }
void RsGxsChannelPostsModel::triggerViewUpdate() void RsGxsChannelPostsModel::triggerViewUpdate()
{ {
@ -244,13 +243,13 @@ void RsGxsChannelPostsModel::getFilesList(std::list<ChannelPostFileInfo>& files)
void RsGxsChannelPostsModel::setFilter(const QStringList& strings,bool only_unread, uint32_t& count) void RsGxsChannelPostsModel::setFilter(const QStringList& strings,bool only_unread, uint32_t& count)
{ {
preMods(); preMods();
beginRemoveRows(QModelIndex(),0,rowCount()-1); beginResetModel();
endRemoveRows();
mFilteredPosts.clear(); mFilteredPosts.clear();
//mFilteredPosts.push_back(0); //mFilteredPosts.push_back(0);
endResetModel();
for(size_t i=0;i<mPosts.size();++i) for(size_t i=0;i<mPosts.size();++i)
{ {
@ -268,8 +267,11 @@ void RsGxsChannelPostsModel::setFilter(const QStringList& strings,bool only_unre
count = mFilteredPosts.size(); count = mFilteredPosts.size();
beginInsertRows(QModelIndex(),0,rowCount()-1); if (rowCount()>0)
endInsertRows(); {
beginInsertRows(QModelIndex(),0,rowCount()-1);
endInsertRows();
}
postMods(); postMods();
} }
@ -321,8 +323,8 @@ bool RsGxsChannelPostsModel::getPostData(const QModelIndex& i,RsGxsChannelPost&
bool RsGxsChannelPostsModel::hasChildren(const QModelIndex &parent) const bool RsGxsChannelPostsModel::hasChildren(const QModelIndex &parent) const
{ {
if(!parent.isValid()) if(!parent.isValid())
return true; return true;
return false; // by default, no channel post has children return false; // by default, no channel post has children
} }
@ -374,45 +376,45 @@ QModelIndex RsGxsChannelPostsModel::index(int row, int column, const QModelIndex
return createIndex(row,column,ref) ; return createIndex(row,column,ref) ;
} }
QModelIndex RsGxsChannelPostsModel::parent(const QModelIndex& index) const QModelIndex RsGxsChannelPostsModel::parent(const QModelIndex& /*index*/) const
{ {
if(!index.isValid())
return QModelIndex();
return QModelIndex(); // there's no hierarchy here. So nothing to do! return QModelIndex(); // there's no hierarchy here. So nothing to do!
} }
Qt::ItemFlags RsGxsChannelPostsModel::flags(const QModelIndex& index) const Qt::ItemFlags RsGxsChannelPostsModel::flags(const QModelIndex& index) const
{ {
if (!index.isValid()) if (!index.isValid())
return 0; return Qt::ItemFlags();
return QAbstractItemModel::flags(index); return QAbstractItemModel::flags(index);
} }
bool RsGxsChannelPostsModel::setNumColumns(int n) bool RsGxsChannelPostsModel::setNumColumns(int n)
{ {
if(n < 1) if(n < 1)
{ {
RsErr() << __PRETTY_FUNCTION__ << " Attempt to set a number of column of 0. This is wrong." << std::endl; RsErr() << __PRETTY_FUNCTION__ << " Attempt to set a number of column of 0. This is wrong." << std::endl;
return false; return false;
} }
if((int)mColumns == n) if((int)mColumns == n)
return false; return false;
preMods(); preMods();
beginRemoveRows(QModelIndex(),0,rowCount()-1); beginResetModel();
endRemoveRows(); endResetModel();
mColumns = n; mColumns = n;
beginInsertRows(QModelIndex(),0,rowCount()-1); if (rowCount()>0)
endInsertRows(); {
beginInsertRows(QModelIndex(),0,rowCount()-1);
endInsertRows();
}
postMods(); postMods();
return true; return true;
} }
quintptr RsGxsChannelPostsModel::getChildRef(quintptr ref,int index) const quintptr RsGxsChannelPostsModel::getChildRef(quintptr ref,int index) const
@ -450,8 +452,8 @@ quintptr RsGxsChannelPostsModel::getParentRow(quintptr ref,int& row) const
int RsGxsChannelPostsModel::getChildrenCount(quintptr ref) const int RsGxsChannelPostsModel::getChildrenCount(quintptr ref) const
{ {
if(ref == quintptr(0)) if(ref == quintptr(0))
return rowCount()-1; return rowCount()-1;
return 0; return 0;
} }
@ -549,10 +551,9 @@ void RsGxsChannelPostsModel::updateChannel(const RsGxsGroupId& channel_group_id)
void RsGxsChannelPostsModel::clear() void RsGxsChannelPostsModel::clear()
{ {
preMods(); preMods();
mPosts.clear(); initEmptyHierarchy();
initEmptyHierarchy();
postMods(); postMods();
emit channelPostsLoaded(); emit channelPostsLoaded();
@ -565,28 +566,27 @@ bool operator<(const RsGxsChannelPost& p1,const RsGxsChannelPost& p2)
void RsGxsChannelPostsModel::setPosts(const RsGxsChannelGroup& group, std::vector<RsGxsChannelPost>& posts) void RsGxsChannelPostsModel::setPosts(const RsGxsChannelGroup& group, std::vector<RsGxsChannelPost>& posts)
{ {
preMods(); preMods();
beginRemoveRows(QModelIndex(),0,rowCount()-1); initEmptyHierarchy();
endRemoveRows(); mChannelGroup = group;
mPosts.clear(); createPostsArray(posts);
mChannelGroup = group;
createPostsArray(posts); std::sort(mPosts.begin(),mPosts.end());
std::sort(mPosts.begin(),mPosts.end()); for(uint32_t i=0;i<mPosts.size();++i)
mFilteredPosts.push_back(i);
mFilteredPosts.clear();
for(uint32_t i=0;i<mPosts.size();++i)
mFilteredPosts.push_back(i);
#ifdef DEBUG_CHANNEL_MODEL #ifdef DEBUG_CHANNEL_MODEL
// debug_dump(); // debug_dump();
#endif #endif
beginInsertRows(QModelIndex(),0,rowCount()-1); if (rowCount()>0)
endInsertRows(); {
beginInsertRows(QModelIndex(),0,rowCount()-1);
endInsertRows();
}
postMods(); postMods();
@ -595,8 +595,8 @@ void RsGxsChannelPostsModel::setPosts(const RsGxsChannelGroup& group, std::vecto
void RsGxsChannelPostsModel::update_posts(const RsGxsGroupId& group_id) void RsGxsChannelPostsModel::update_posts(const RsGxsGroupId& group_id)
{ {
if(group_id.isNull()) if(group_id.isNull())
return; return;
RsThread::async([this, group_id]() RsThread::async([this, group_id]()
{ {

View File

@ -238,7 +238,7 @@ void ChannelPostDelegate::paint(QPainter * painter, const QStyleOptionViewItem &
info_text += ", " + QString::number(post.mAttachmentCount)+ " " +((post.mAttachmentCount>1)?tr("files"):tr("file")) + " (" + misc::friendlyUnit(qulonglong(post.mSize)) + ")" ; info_text += ", " + QString::number(post.mAttachmentCount)+ " " +((post.mAttachmentCount>1)?tr("files"):tr("file")) + " (" + misc::friendlyUnit(qulonglong(post.mSize)) + ")" ;
painter->drawText(QPoint(p.x()+0.5*font_height,y),info_text); painter->drawText(QPoint(p.x()+0.5*font_height,y),info_text);
y += font_height; //y += font_height;
painter->restore(); painter->restore();
} }
@ -400,21 +400,21 @@ GxsChannelPostsWidgetWithModel::GxsChannelPostsWidgetWithModel(const RsGxsGroupI
ui->channelPostFiles_TV->setItemDelegate(new ChannelPostFilesDelegate(this)); ui->channelPostFiles_TV->setItemDelegate(new ChannelPostFilesDelegate(this));
ui->channelPostFiles_TV->setPlaceholderText(tr("No files in this post, or no post selected")); ui->channelPostFiles_TV->setPlaceholderText(tr("No files in this post, or no post selected"));
ui->channelPostFiles_TV->setSortingEnabled(true); ui->channelPostFiles_TV->setSortingEnabled(true);
ui->channelPostFiles_TV->sortByColumn(3, Qt::AscendingOrder); // sort by time ui->channelPostFiles_TV->sortByColumn(RsGxsChannelPostFilesModel::COLUMN_FILES_DATE, Qt::DescendingOrder); // sort by time
ui->channelPostFiles_TV->setAlternatingRowColors(false); ui->channelPostFiles_TV->setAlternatingRowColors(false);
ui->channelFiles_TV->setModel(mChannelFilesModel = new RsGxsChannelPostFilesModel());
ui->channelFiles_TV->setItemDelegate(mFilesDelegate = new ChannelPostFilesDelegate(this));
ui->channelFiles_TV->setPlaceholderText(tr("No files in the channel, or no channel selected"));
ui->channelFiles_TV->setSortingEnabled(true);
ui->channelFiles_TV->sortByColumn(RsGxsChannelPostFilesModel::COLUMN_FILES_DATE, Qt::DescendingOrder); // sort by time
connect(ui->channelPostFiles_TV->header(),SIGNAL(sortIndicatorChanged(int,Qt::SortOrder)), this, SLOT(sortColumnPostFiles(int,Qt::SortOrder))); connect(ui->channelPostFiles_TV->header(),SIGNAL(sortIndicatorChanged(int,Qt::SortOrder)), this, SLOT(sortColumnPostFiles(int,Qt::SortOrder)));
connect(ui->channelFiles_TV->header(),SIGNAL(sortIndicatorChanged(int,Qt::SortOrder)), this, SLOT(sortColumnFiles(int,Qt::SortOrder))); connect(ui->channelFiles_TV->header(),SIGNAL(sortIndicatorChanged(int,Qt::SortOrder)), this, SLOT(sortColumnFiles(int,Qt::SortOrder)));
connect(ui->channelPostFiles_TV,SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(showChannelFilesContextMenu(QPoint))); connect(ui->channelPostFiles_TV,SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(showChannelFilesContextMenu(QPoint)));
connect(ui->channelFiles_TV,SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(showChannelFilesContextMenu(QPoint))); connect(ui->channelFiles_TV,SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(showChannelFilesContextMenu(QPoint)));
ui->channelFiles_TV->setModel(mChannelFilesModel = new RsGxsChannelPostFilesModel());
ui->channelFiles_TV->setItemDelegate(mFilesDelegate = new ChannelPostFilesDelegate(this));
ui->channelFiles_TV->setPlaceholderText(tr("No files in the channel, or no channel selected"));
ui->channelFiles_TV->setSortingEnabled(true);
ui->channelFiles_TV->sortByColumn(3, Qt::AscendingOrder); // sort by time
connect(ui->postsTree->selectionModel(),SIGNAL(selectionChanged(const QItemSelection&,const QItemSelection&)),this,SLOT(showPostDetails())); connect(ui->postsTree->selectionModel(),SIGNAL(selectionChanged(const QItemSelection&,const QItemSelection&)),this,SLOT(showPostDetails()));
connect(ui->postsTree,SIGNAL(customContextMenuRequested(const QPoint&)),this,SLOT(postContextMenu(const QPoint&))); connect(ui->postsTree,SIGNAL(customContextMenuRequested(const QPoint&)),this,SLOT(postContextMenu(const QPoint&)));
@ -666,7 +666,7 @@ void GxsChannelPostsWidgetWithModel::download()
std::string destination; std::string destination;
rsGxsChannels->getChannelDownloadDirectory(mGroup.mMeta.mGroupId,destination); rsGxsChannels->getChannelDownloadDirectory(mGroup.mMeta.mGroupId,destination);
for(auto file:post.mFiles) for(auto& file:post.mFiles)
{ {
std::list<RsPeerId> sources; std::list<RsPeerId> sources;
std::string destination; std::string destination;
@ -940,8 +940,9 @@ void GxsChannelPostsWidgetWithModel::postChannelPostLoad()
mChannelPostsModel->getFilesList(files); mChannelPostsModel->getFilesList(files);
mChannelFilesModel->setFiles(files); mChannelFilesModel->setFiles(files);
ui->channelFiles_TV->setAutoSelect(true); ui->channelFiles_TV->setAutoSelect(true);
ui->channelFiles_TV->sortByColumn(3, Qt::AscendingOrder); ui->channelFiles_TV->sortByColumn(ui->channelFiles_TV->header()->sortIndicatorSection()
,ui->channelFiles_TV->header()->sortIndicatorOrder());
ui->infoPosts->setText(QString::number(mChannelPostsModel->getNumberOfPosts()) + " / " + QString::number(mGroup.mMeta.mVisibleMsgCount)); ui->infoPosts->setText(QString::number(mChannelPostsModel->getNumberOfPosts()) + " / " + QString::number(mGroup.mMeta.mVisibleMsgCount));
@ -1207,11 +1208,11 @@ void GxsChannelPostsWidgetWithModel::insertChannelDetails(const RsGxsChannelGrou
QString distrib_string ( "[unknown]" ); QString distrib_string ( "[unknown]" );
switch(group.mMeta.mCircleType) switch((RsGxsCircleType)group.mMeta.mCircleType)
{ {
case GXS_CIRCLE_TYPE_PUBLIC: distrib_string = tr("Public") ; case RsGxsCircleType::PUBLIC: distrib_string = tr("Public") ;
break ; break ;
case GXS_CIRCLE_TYPE_EXTERNAL: case RsGxsCircleType::EXTERNAL:
{ {
RsGxsCircleDetails det ; RsGxsCircleDetails det ;
@ -1223,9 +1224,9 @@ void GxsChannelPostsWidgetWithModel::insertChannelDetails(const RsGxsChannelGrou
distrib_string = tr("Restricted to members of circle ")+QString::fromStdString(group.mMeta.mCircleId.toStdString()) ; distrib_string = tr("Restricted to members of circle ")+QString::fromStdString(group.mMeta.mCircleId.toStdString()) ;
} }
break ; break ;
case GXS_CIRCLE_TYPE_YOUR_EYES_ONLY: distrib_string = tr("Your eyes only"); case RsGxsCircleType::YOUR_EYES_ONLY: distrib_string = tr("Your eyes only");
break ; break ;
case GXS_CIRCLE_TYPE_LOCAL: distrib_string = tr("You and your friend nodes"); case RsGxsCircleType::LOCAL: distrib_string = tr("You and your friend nodes");
break ; break ;
default: default:
std::cerr << "(EE) badly initialised group distribution ID = " << group.mMeta.mCircleType << std::endl; std::cerr << "(EE) badly initialised group distribution ID = " << group.mMeta.mCircleType << std::endl;
@ -1246,7 +1247,7 @@ void GxsChannelPostsWidgetWithModel::insertChannelDetails(const RsGxsChannelGrou
showPostDetails(); showPostDetails();
} }
void GxsChannelPostsWidgetWithModel::showChannelFilesContextMenu(QPoint p) void GxsChannelPostsWidgetWithModel::showChannelFilesContextMenu(QPoint /*p*/)
{ {
QMenu contextMnu(this) ; QMenu contextMnu(this) ;
@ -1317,7 +1318,7 @@ void GxsChannelPostsWidgetWithModel::switchOnlyUnread(bool)
} }
void GxsChannelPostsWidgetWithModel::filterChanged(QString s) void GxsChannelPostsWidgetWithModel::filterChanged(QString s)
{ {
QStringList ql = s.split(' ',QString::SkipEmptyParts); QStringList ql = s.split(' ',Qt::SkipEmptyParts);
uint32_t count; uint32_t count;
mChannelPostsModel->setFilter(ql,ui->showUnread_TB->isChecked(),count); mChannelPostsModel->setFilter(ql,ui->showUnread_TB->isChecked(),count);
mChannelFilesModel->setFilter(ql,count); mChannelFilesModel->setFilter(ql,count);
@ -1420,7 +1421,7 @@ void GxsChannelPostsWidgetWithModel::toggleAutoDownload()
class GxsChannelPostsReadData class GxsChannelPostsReadData
{ {
public: public:
GxsChannelPostsReadData(bool read) explicit GxsChannelPostsReadData(bool read)
{ {
mRead = read; mRead = read;
mLastToken = 0; mLastToken = 0;

View File

@ -50,42 +50,32 @@ RsGxsForumModel::RsGxsForumModel(QObject *parent)
void RsGxsForumModel::preMods() void RsGxsForumModel::preMods()
{ {
//emit layoutAboutToBeChanged(); //Generate SIGSEGV when click on button move next/prev. emit layoutAboutToBeChanged();
beginResetModel();
} }
void RsGxsForumModel::postMods() void RsGxsForumModel::postMods()
{ {
endResetModel(); if(mTreeMode == TREE_MODE_FLAT)
if(mTreeMode == TREE_MODE_FLAT)
emit dataChanged(createIndex(0,0,(void*)NULL), createIndex(mPosts.size(),COLUMN_THREAD_NB_COLUMNS-1,(void*)NULL)); emit dataChanged(createIndex(0,0,(void*)NULL), createIndex(mPosts.size(),COLUMN_THREAD_NB_COLUMNS-1,(void*)NULL));
else else
emit dataChanged(createIndex(0,0,(void*)NULL), createIndex(mPosts[0].mChildren.size(),COLUMN_THREAD_NB_COLUMNS-1,(void*)NULL)); emit dataChanged(createIndex(0,0,(void*)NULL), createIndex(mPosts[0].mChildren.size(),COLUMN_THREAD_NB_COLUMNS-1,(void*)NULL));
emit layoutChanged();
} }
void RsGxsForumModel::setTreeMode(TreeMode mode) void RsGxsForumModel::setTreeMode(TreeMode mode)
{ {
if(mode == mTreeMode) if(mode == mTreeMode)
return; return;
preMods(); preMods();
if(mode == TREE_MODE_TREE) // means we were in FLAT mode, so the last rows are removed. beginResetModel();
{
beginRemoveRows(QModelIndex(),mPosts[0].mChildren.size(),mPosts.size()-1);
endRemoveRows();
}
mTreeMode = mode; mTreeMode = mode;
if(mode == TREE_MODE_FLAT) // means we were in tree mode, so the last rows are added. endResetModel();
{
beginInsertRows(QModelIndex(),mPosts[0].mChildren.size(),mPosts.size()-1);
endInsertRows();
}
postMods(); postMods();
} }
void RsGxsForumModel::setSortMode(SortMode mode) void RsGxsForumModel::setSortMode(SortMode mode)
@ -241,7 +231,7 @@ QModelIndex RsGxsForumModel::parent(const QModelIndex& index) const
Qt::ItemFlags RsGxsForumModel::flags(const QModelIndex& index) const Qt::ItemFlags RsGxsForumModel::flags(const QModelIndex& index) const
{ {
if (!index.isValid()) if (!index.isValid())
return 0; return Qt::ItemFlags();
return QAbstractItemModel::flags(index); return QAbstractItemModel::flags(index);
} }
@ -466,8 +456,8 @@ QVariant RsGxsForumModel::statusRole(const ForumModelPostEntry& fmpe,int column)
QVariant RsGxsForumModel::filterRole(const ForumModelPostEntry& fmpe,int /*column*/) const QVariant RsGxsForumModel::filterRole(const ForumModelPostEntry& fmpe,int /*column*/) const
{ {
if(!mFilteringEnabled || (fmpe.mPostFlags & ForumModelPostEntry::FLAG_POST_CHILDREN_PASSES_FILTER)) if(!mFilteringEnabled || (fmpe.mPostFlags & ForumModelPostEntry::FLAG_POST_CHILDREN_PASSES_FILTER))
return QVariant(FilterString); return QVariant(FilterString);
return QVariant(QString()); return QVariant(QString());
} }
@ -755,65 +745,68 @@ void RsGxsForumModel::clear()
void RsGxsForumModel::setPosts(const RsGxsForumGroup& group, const std::vector<ForumModelPostEntry>& posts,const std::map<RsGxsMessageId,std::vector<std::pair<time_t,RsGxsMessageId> > >& post_versions) void RsGxsForumModel::setPosts(const RsGxsForumGroup& group, const std::vector<ForumModelPostEntry>& posts,const std::map<RsGxsMessageId,std::vector<std::pair<time_t,RsGxsMessageId> > >& post_versions)
{ {
preMods(); preMods();
if(mTreeMode == TREE_MODE_FLAT) beginResetModel();
beginRemoveRows(QModelIndex(),0,mPosts.size()-1); endResetModel();
else
beginRemoveRows(QModelIndex(),0,mPosts[0].mChildren.size()-1);
endRemoveRows(); mForumGroup = group;
mPosts = posts;
mPostVersions = post_versions;
mForumGroup = group; // now update prow for all posts
mPosts = posts;
mPostVersions = post_versions;
// now update prow for all posts for(uint32_t i=0;i<mPosts.size();++i)
for(uint32_t j=0;j<mPosts[i].mChildren.size();++j)
mPosts[mPosts[i].mChildren[j]].prow = j;
for(uint32_t i=0;i<mPosts.size();++i) mPosts[0].prow = 0;
for(uint32_t j=0;j<mPosts[i].mChildren.size();++j)
mPosts[mPosts[i].mChildren[j]].prow = j;
mPosts[0].prow = 0; bool has_unread_below,has_read_below ;
bool has_unread_below,has_read_below ; recursUpdateReadStatusAndTimes(0,has_unread_below,has_read_below) ;
recursUpdateFilterStatus(0,0,QStringList());
recursUpdateReadStatusAndTimes(0,has_unread_below,has_read_below) ;
recursUpdateFilterStatus(0,0,QStringList());
#ifdef DEBUG_FORUMMODEL #ifdef DEBUG_FORUMMODEL
debug_dump(); debug_dump();
#endif #endif
if(mTreeMode == TREE_MODE_FLAT) int count = 0;
beginInsertRows(QModelIndex(),0,mPosts.size()-1); if(mTreeMode == TREE_MODE_FLAT)
else count = mPosts.size();
beginInsertRows(QModelIndex(),0,mPosts[0].mChildren.size()-1); else
endInsertRows(); count = mPosts[0].mChildren.size();
if(count>0)
{
beginInsertRows(QModelIndex(),0,count-1);
endInsertRows();
}
postMods(); postMods();
emit forumLoaded(); emit forumLoaded();
} }
void RsGxsForumModel::update_posts(const RsGxsGroupId& group_id) void RsGxsForumModel::update_posts(const RsGxsGroupId& group_id)
{ {
if(group_id.isNull()) if(group_id.isNull())
return; return;
RsThread::async([this, group_id]() RsThread::async([this, group_id]()
{ {
// 1 - get message data from p3GxsForums // 1 - get message data from p3GxsForums
std::list<RsGxsGroupId> forumIds; std::list<RsGxsGroupId> forumIds;
std::vector<RsMsgMetaData> msg_metas; std::vector<RsMsgMetaData> msg_metas;
std::vector<RsGxsForumGroup> groups; std::vector<RsGxsForumGroup> groups;
forumIds.push_back(group_id); forumIds.push_back(group_id);
if(!rsGxsForums->getForumsInfo(forumIds,groups) || groups.size() != 1) if(!rsGxsForums->getForumsInfo(forumIds,groups) || groups.size() != 1)
{ {
std::cerr << __PRETTY_FUNCTION__ << " failed to retrieve forum group info for forum " << group_id << std::endl; std::cerr << __PRETTY_FUNCTION__ << " failed to retrieve forum group info for forum " << group_id << std::endl;
return; return;
} }
if(!rsGxsForums->getForumMsgMetaData(group_id,msg_metas)) if(!rsGxsForums->getForumMsgMetaData(group_id,msg_metas))
{ {
@ -821,17 +814,17 @@ void RsGxsForumModel::update_posts(const RsGxsGroupId& group_id)
return; return;
} }
// 2 - sort the messages into a proper hierarchy // 2 - sort the messages into a proper hierarchy
auto post_versions = new std::map<RsGxsMessageId,std::vector<std::pair<time_t, RsGxsMessageId> > >() ; auto post_versions = new std::map<RsGxsMessageId,std::vector<std::pair<time_t, RsGxsMessageId> > >() ;
std::vector<ForumModelPostEntry> *vect = new std::vector<ForumModelPostEntry>(); std::vector<ForumModelPostEntry> *vect = new std::vector<ForumModelPostEntry>();
RsGxsForumGroup group = groups[0]; RsGxsForumGroup group = groups[0];
computeMessagesHierarchy(group,msg_metas,*vect,*post_versions); computeMessagesHierarchy(group,msg_metas,*vect,*post_versions);
// 3 - update the model in the UI thread. // 3 - update the model in the UI thread.
RsQThreadUtils::postToObject( [group,vect,post_versions,this]() RsQThreadUtils::postToObject( [group,vect,post_versions,this]()
{ {
/* Here it goes any code you want to be executed on the Qt Gui /* 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 * thread, for example to update the data model with new information
@ -839,15 +832,15 @@ void RsGxsForumModel::update_posts(const RsGxsGroupId& group_id)
* Qt::QueuedConnection is important! * Qt::QueuedConnection is important!
*/ */
setPosts(group,*vect,*post_versions) ; setPosts(group,*vect,*post_versions) ;
delete vect; delete vect;
delete post_versions; delete post_versions;
}, this ); }, this );
}); });
} }
ForumModelIndex RsGxsForumModel::addEntry(std::vector<ForumModelPostEntry>& posts,const ForumModelPostEntry& entry,ForumModelIndex parent) ForumModelIndex RsGxsForumModel::addEntry(std::vector<ForumModelPostEntry>& posts,const ForumModelPostEntry& entry,ForumModelIndex parent)
@ -895,26 +888,25 @@ void RsGxsForumModel::convertMsgToPostEntry(const RsGxsForumGroup& mForumGroup,c
void RsGxsForumModel::computeReputationLevel(uint32_t forum_sign_flags,ForumModelPostEntry& fentry) void RsGxsForumModel::computeReputationLevel(uint32_t forum_sign_flags,ForumModelPostEntry& fentry)
{ {
uint32_t idflags =0; uint32_t idflags =0;
RsReputationLevel reputation_level = RsReputationLevel reputation_level =
rsReputations->overallReputationLevel(fentry.mAuthorId, &idflags); rsReputations->overallReputationLevel(fentry.mAuthorId, &idflags);
bool redacted = false;
if(reputation_level == RsReputationLevel::LOCALLY_NEGATIVE) if(reputation_level == RsReputationLevel::LOCALLY_NEGATIVE)
fentry.mPostFlags |= ForumModelPostEntry::FLAG_POST_IS_REDACTED; fentry.mPostFlags |= ForumModelPostEntry::FLAG_POST_IS_REDACTED;
else else
fentry.mPostFlags &= ~ForumModelPostEntry::FLAG_POST_IS_REDACTED; fentry.mPostFlags &= ~ForumModelPostEntry::FLAG_POST_IS_REDACTED;
// We use a specific item model for forums in order to handle the post pinning. // We use a specific item model for forums in order to handle the post pinning.
if(reputation_level == RsReputationLevel::UNKNOWN) if(reputation_level == RsReputationLevel::UNKNOWN)
fentry.mReputationWarningLevel = 3 ; fentry.mReputationWarningLevel = 3 ;
else if(reputation_level == RsReputationLevel::LOCALLY_NEGATIVE) else if(reputation_level == RsReputationLevel::LOCALLY_NEGATIVE)
fentry.mReputationWarningLevel = 2 ; fentry.mReputationWarningLevel = 2 ;
else if(reputation_level < rsGxsForums->minReputationForForwardingMessages(forum_sign_flags,idflags)) else if(reputation_level < rsGxsForums->minReputationForForwardingMessages(forum_sign_flags,idflags))
fentry.mReputationWarningLevel = 1 ; fentry.mReputationWarningLevel = 1 ;
else else
fentry.mReputationWarningLevel = 0 ; fentry.mReputationWarningLevel = 0 ;
} }
static bool decreasing_time_comp(const std::pair<time_t,RsGxsMessageId>& e1,const std::pair<time_t,RsGxsMessageId>& e2) { return e2.first < e1.first ; } static bool decreasing_time_comp(const std::pair<time_t,RsGxsMessageId>& e1,const std::pair<time_t,RsGxsMessageId>& e2) { return e2.first < e1.first ; }

View File

@ -61,31 +61,32 @@ RsMessageModel::RsMessageModel(QObject *parent)
void RsMessageModel::preMods() void RsMessageModel::preMods()
{ {
emit layoutAboutToBeChanged(); emit layoutAboutToBeChanged();
} }
void RsMessageModel::postMods() void RsMessageModel::postMods()
{ {
emit dataChanged(createIndex(0,0,(void*)NULL), createIndex(mMessages.size()-1,COLUMN_THREAD_NB_COLUMNS-1,(void*)NULL)); emit dataChanged(createIndex(0,0,(void*)NULL), createIndex(mMessages.size()-1,COLUMN_THREAD_NB_COLUMNS-1,(void*)NULL));
emit layoutChanged();
} }
int RsMessageModel::rowCount(const QModelIndex& parent) const int RsMessageModel::rowCount(const QModelIndex& parent) const
{ {
if(!parent.isValid()) if(!parent.isValid())
return 0; return 0;
if(parent.column() > 0) if(parent.column() > 0)
return 0; return 0;
if(mMessages.empty()) // security. Should never happen. if(mMessages.empty()) // security. Should never happen.
return 0; return 0;
if(parent.internalPointer() == NULL) if(parent.internalPointer() == NULL)
return mMessages.size(); return mMessages.size();
return 0; return 0;
} }
int RsMessageModel::columnCount(const QModelIndex &parent) const int RsMessageModel::columnCount(const QModelIndex &/*parent*/) const
{ {
return COLUMN_THREAD_NB_COLUMNS ; return COLUMN_THREAD_NB_COLUMNS ;
} }
@ -145,8 +146,8 @@ QModelIndex RsMessageModel::index(int row, int column, const QModelIndex & paren
QModelIndex RsMessageModel::parent(const QModelIndex& index) const QModelIndex RsMessageModel::parent(const QModelIndex& index) const
{ {
if(!index.isValid()) if(!index.isValid())
return QModelIndex(); return QModelIndex();
return QModelIndex(); return QModelIndex();
} }
@ -154,12 +155,12 @@ QModelIndex RsMessageModel::parent(const QModelIndex& index) const
Qt::ItemFlags RsMessageModel::flags(const QModelIndex& index) const Qt::ItemFlags RsMessageModel::flags(const QModelIndex& index) const
{ {
if (!index.isValid()) if (!index.isValid())
return 0; return Qt::ItemFlags();
return QAbstractItemModel::flags(index); return QAbstractItemModel::flags(index);
} }
QVariant RsMessageModel::headerData(int section, Qt::Orientation orientation, int role) const QVariant RsMessageModel::headerData(int section, Qt::Orientation /*orientation*/, int role) const
{ {
if(role == Qt::DisplayRole) if(role == Qt::DisplayRole)
switch(section) switch(section)
@ -274,20 +275,20 @@ QVariant RsMessageModel::data(const QModelIndex &index, int role) const
} }
} }
QVariant RsMessageModel::textColorRole(const Rs::Msgs::MsgInfoSummary& fmpe,int column) const QVariant RsMessageModel::textColorRole(const Rs::Msgs::MsgInfoSummary& fmpe,int /*column*/) const
{ {
Rs::Msgs::MsgTagType tags; Rs::Msgs::MsgTagType tags;
rsMsgs->getMessageTagTypes(tags); rsMsgs->getMessageTagTypes(tags);
for(auto it(fmpe.msgtags.begin());it!=fmpe.msgtags.end();++it) for(auto it(fmpe.msgtags.begin());it!=fmpe.msgtags.end();++it)
for(auto it2(tags.types.begin());it2!=tags.types.end();++it2) for(auto it2(tags.types.begin());it2!=tags.types.end();++it2)
if(it2->first == *it) if(it2->first == *it)
return QColor(it2->second.second); return QColor(it2->second.second);
return QVariant(); return QVariant();
} }
QVariant RsMessageModel::statusRole(const Rs::Msgs::MsgInfoSummary& fmpe,int column) const QVariant RsMessageModel::statusRole(const Rs::Msgs::MsgInfoSummary& /*fmpe*/,int /*column*/) const
{ {
// if(column != COLUMN_THREAD_DATA) // if(column != COLUMN_THREAD_DATA)
// return QVariant(); // return QVariant();
@ -295,12 +296,12 @@ QVariant RsMessageModel::statusRole(const Rs::Msgs::MsgInfoSummary& fmpe,int col
return QVariant();//fmpe.mMsgStatus); return QVariant();//fmpe.mMsgStatus);
} }
bool RsMessageModel::passesFilter(const Rs::Msgs::MsgInfoSummary& fmpe,int column) const bool RsMessageModel::passesFilter(const Rs::Msgs::MsgInfoSummary& fmpe,int /*column*/) const
{ {
QString s ; QString s ;
bool passes_strings = true ; bool passes_strings = true ;
if(!mFilterStrings.empty()) if(!mFilterStrings.empty())
{ {
switch(mFilterType) switch(mFilterType)
{ {
@ -308,9 +309,9 @@ bool RsMessageModel::passesFilter(const Rs::Msgs::MsgInfoSummary& fmpe,int colum
break; break;
case FILTER_TYPE_FROM: s = sortRole(fmpe,COLUMN_THREAD_AUTHOR).toString(); case FILTER_TYPE_FROM: s = sortRole(fmpe,COLUMN_THREAD_AUTHOR).toString();
if(s.isNull()) if(s.isNull())
passes_strings = false; passes_strings = false;
break; break;
case FILTER_TYPE_DATE: s = displayRole(fmpe,COLUMN_THREAD_DATE).toString(); case FILTER_TYPE_DATE: s = displayRole(fmpe,COLUMN_THREAD_DATE).toString();
break; break;
case FILTER_TYPE_CONTENT: { case FILTER_TYPE_CONTENT: {
@ -330,6 +331,9 @@ bool RsMessageModel::passesFilter(const Rs::Msgs::MsgInfoSummary& fmpe,int colum
for(auto it(minfo.files.begin());it!=minfo.files.end();++it) for(auto it(minfo.files.begin());it!=minfo.files.end();++it)
s += QString::fromUtf8((*it).fname.c_str())+" "; s += QString::fromUtf8((*it).fname.c_str())+" ";
} }
break;
case FILTER_TYPE_NONE:
RS_ERR("None Type for Filter.");
}; };
} }
@ -355,18 +359,15 @@ bool RsMessageModel::passesFilter(const Rs::Msgs::MsgInfoSummary& fmpe,int colum
QVariant RsMessageModel::filterRole(const Rs::Msgs::MsgInfoSummary& fmpe,int column) const QVariant RsMessageModel::filterRole(const Rs::Msgs::MsgInfoSummary& fmpe,int column) const
{ {
if(passesFilter(fmpe,column)) if(passesFilter(fmpe,column))
return QVariant(FilterString); return QVariant(FilterString);
return QVariant(QString()); return QVariant(QString());
} }
uint32_t RsMessageModel::updateFilterStatus(ForumModelIndex i,int column,const QStringList& strings) uint32_t RsMessageModel::updateFilterStatus(ForumModelIndex /*i*/,int /*column*/,const QStringList& /*strings*/)
{ {
QString s ; return 0;
uint32_t count = 0;
return count;
} }
@ -408,7 +409,7 @@ QVariant RsMessageModel::toolTipRole(const Rs::Msgs::MsgInfoSummary& fmpe,int co
return QVariant(); return QVariant();
} }
QVariant RsMessageModel::backgroundRole(const Rs::Msgs::MsgInfoSummary &fmpe, int column) const QVariant RsMessageModel::backgroundRole(const Rs::Msgs::MsgInfoSummary &/*fmpe*/, int /*column*/) const
{ {
return QVariant(); return QVariant();
} }
@ -426,7 +427,7 @@ QVariant RsMessageModel::sizeHintRole(int col) const
} }
} }
QVariant RsMessageModel::authorRole(const Rs::Msgs::MsgInfoSummary& fmpe,int column) const QVariant RsMessageModel::authorRole(const Rs::Msgs::MsgInfoSummary& /*fmpe*/,int /*column*/) const
{ {
return QVariant(); return QVariant();
} }
@ -443,15 +444,16 @@ QVariant RsMessageModel::sortRole(const Rs::Msgs::MsgInfoSummary& fmpe,int colum
case COLUMN_THREAD_SPAM: return QVariant((fmpe.msgflags & RS_MSG_SPAM)? 1:0); case COLUMN_THREAD_SPAM: return QVariant((fmpe.msgflags & RS_MSG_SPAM)? 1:0);
case COLUMN_THREAD_AUTHOR:{ case COLUMN_THREAD_AUTHOR:{
QString name; QString name;
if(GxsIdTreeItemDelegate::computeName(RsGxsId(fmpe.srcId.toStdString()),name)) if(GxsIdTreeItemDelegate::computeName(RsGxsId(fmpe.srcId.toStdString()),name))
return name; return name;
} return ""; //Not Found
default: }
return displayRole(fmpe,column); default:
} return displayRole(fmpe,column);
}
} }
QVariant RsMessageModel::displayRole(const Rs::Msgs::MsgInfoSummary& fmpe,int col) const QVariant RsMessageModel::displayRole(const Rs::Msgs::MsgInfoSummary& fmpe,int col) const
@ -572,9 +574,12 @@ QVariant RsMessageModel::decorationRole(const Rs::Msgs::MsgInfoSummary& fmpe,int
void RsMessageModel::clear() void RsMessageModel::clear()
{ {
preMods(); preMods();
mMessages.clear(); beginResetModel();
mMessages.clear();
mMessagesMap.clear();
endResetModel();
postMods(); postMods();
@ -583,29 +588,26 @@ void RsMessageModel::clear()
void RsMessageModel::setMessages(const std::list<Rs::Msgs::MsgInfoSummary>& msgs) void RsMessageModel::setMessages(const std::list<Rs::Msgs::MsgInfoSummary>& msgs)
{ {
preMods();
beginRemoveRows(QModelIndex(),0,mMessages.size()-1); clear();
endRemoveRows();
mMessages.clear(); for(auto it(msgs.begin());it!=msgs.end();++it)
mMessagesMap.clear(); {
mMessagesMap[(*it).msgId] = mMessages.size();
mMessages.push_back(*it);
}
for(auto it(msgs.begin());it!=msgs.end();++it) // now update prow for all posts
{
mMessagesMap[(*it).msgId] = mMessages.size();
mMessages.push_back(*it);
}
// now update prow for all posts
#ifdef DEBUG_MESSAGE_MODEL #ifdef DEBUG_MESSAGE_MODEL
debug_dump(); debug_dump();
#endif #endif
beginInsertRows(QModelIndex(),0,mMessages.size()-1); if (mMessages.size()>0)
endInsertRows(); {
postMods(); beginInsertRows(QModelIndex(),0,mMessages.size()-1);
endInsertRows();
}
emit messagesLoaded(); emit messagesLoaded();
} }
@ -672,8 +674,6 @@ void RsMessageModel::updateMessages()
emit messagesLoaded(); emit messagesLoaded();
} }
static bool decreasing_time_comp(const std::pair<time_t,RsGxsMessageId>& e1,const std::pair<time_t,RsGxsMessageId>& e2) { return e2.first < e1.first ; }
void RsMessageModel::setMsgReadStatus(const QModelIndex& i,bool read_status) void RsMessageModel::setMsgReadStatus(const QModelIndex& i,bool read_status)
{ {
if(!i.isValid()) if(!i.isValid())
@ -704,12 +704,12 @@ void RsMessageModel::setMsgJunk(const QModelIndex& i,bool junk)
QModelIndex RsMessageModel::getIndexOfMessage(const std::string& mid) const QModelIndex RsMessageModel::getIndexOfMessage(const std::string& mid) const
{ {
// Brutal search. This is not so nice, so dont call that in a loop! If too costly, we'll use a map. // Brutal search. This is not so nice, so dont call that in a loop! If too costly, we'll use a map.
auto it = mMessagesMap.find(mid); auto it = mMessagesMap.find(mid);
if(it == mMessagesMap.end() || it->second >= mMessages.size()) if(it == mMessagesMap.end() || it->second >= mMessages.size())
return QModelIndex(); return QModelIndex();
quintptr ref ; quintptr ref ;
convertMsgIndexToInternalId(it->second,ref); convertMsgIndexToInternalId(it->second,ref);