diff --git a/retroshare-gui/src/gui/FriendsDialog.cpp b/retroshare-gui/src/gui/FriendsDialog.cpp index 545c75915..7078b53d3 100644 --- a/retroshare-gui/src/gui/FriendsDialog.cpp +++ b/retroshare-gui/src/gui/FriendsDialog.cpp @@ -43,6 +43,7 @@ #include "FriendsDialog.h" #include "NetworkView.h" #include "NetworkDialog.h" +#include "gui/common/NewFriendList.h" #include "gui/Identity/IdDialog.h" #ifdef RS_USE_CIRCLES #include "gui/Circles/CirclesDialog.h" @@ -77,10 +78,8 @@ FriendsDialog::FriendsDialog(QWidget *parent) ui.chatWidget->setWelcomeMessage(msg); ui.chatWidget->init(ChatId::makeBroadcastId(), tr("Broadcast")); - connect(NotifyQt::getInstance(), SIGNAL(chatMessageReceived(ChatMessage)), - this, SLOT(chatMessageReceived(ChatMessage))); - connect(NotifyQt::getInstance(), SIGNAL(chatStatusChanged(ChatId,QString)), - this, SLOT(chatStatusReceived(ChatId,QString))); + connect(NotifyQt::getInstance(), SIGNAL(chatMessageReceived(ChatMessage)), this, SLOT(chatMessageReceived(ChatMessage))); + connect(NotifyQt::getInstance(), SIGNAL(chatStatusChanged(ChatId,QString)), this, SLOT(chatStatusReceived(ChatId,QString))); #else // def RS_DIRECT_CHAT ui.tabWidget->removeTab(ui.tabWidget->indexOf(ui.groupChatTab)); #endif // def RS_DIRECT_CHAT @@ -97,47 +96,15 @@ FriendsDialog::FriendsDialog(QWidget *parent) ui.tabWidget->addTab(networkView = new NetworkView(),QIcon(IMAGE_NETWORK2), tr("Network graph")); ui.tabWidget->addTab(networkDialog = new NetworkDialog(),QIcon(IMAGE_PEERS), tr("Keyring")); - //ui.tabWidget->addTab(new ProfileWidget(), tr("Profile")); - //newsFeed = new NewsFeed(); - //int newsFeedTabIndex = ui.tabWidget->insertTab(0, newsFeed, tr("News Feed")); - //ui.tabWidget->setCurrentIndex(newsFeedTabIndex); - ui.tabWidget->hideCloseButton(0); ui.tabWidget->hideCloseButton(1); ui.tabWidget->hideCloseButton(2); ui.tabWidget->hideCloseButton(3); ui.tabWidget->hideCloseButton(4); - /* get the current text and text color of the tab bar */ - //newsFeedTabColor = ui.tabWidget->tabBar()->tabTextColor(newsFeedTabIndex); - //newsFeedText = ui.tabWidget->tabBar()->tabText(newsFeedTabIndex); - - //connect(newsFeed, SIGNAL(newsFeedChanged(int)), this, SLOT(newsFeedChanged(int))); - -// menu = new QMenu(); -// menu->addAction(ui.actionAdd_Friend); -// menu->addAction(ui.actionAdd_Group); -// menu->addAction(ui.actionCreate_new_Chat_lobby); -// -// menu->addSeparator(); -// menu->addAction(ui.actionSet_your_Avatar); -// menu->addAction(ui.actionSet_your_Personal_Message); -// -// ui.menutoolButton->setMenu(menu); - - /*QToolButton *addFriendButton = new QToolButton(this); - addFriendButton->setIcon(QIcon(":/images/user/add_user24.png")); - addFriendButton->setToolTip(tr("Add friend node")); - connect(addFriendButton, SIGNAL(clicked()), this, SLOT(addFriend())); - ui.friendList->addToolButton(addFriendButton);*/ - /* Set initial size the splitter */ ui.splitter->setStretchFactor(0, 0); ui.splitter->setStretchFactor(1, 1); - /*remove -QList sizes; - sizes << height() << 100; // Qt calculates the right sizes - ui.splitter_2->setSizes(sizes);*/ loadmypersonalstatus(); @@ -145,9 +112,9 @@ QList sizes; // load settings RsAutoUpdatePage::lockAllEvents(); - ui.friendList->setColumnVisible(FriendList::COLUMN_LAST_CONTACT, false); - ui.friendList->setColumnVisible(FriendList::COLUMN_IP, false); - ui.friendList->setColumnVisible(FriendList::COLUMN_ID, false); + ui.friendList->setColumnVisible(NewFriendList::COLUMN_LAST_CONTACT, false); + ui.friendList->setColumnVisible(NewFriendList::COLUMN_IP, false); + ui.friendList->setColumnVisible(NewFriendList::COLUMN_ID, false); ui.friendList->setShowGroups(true); processSettings(true); RsAutoUpdatePage::unlockAllEvents(); diff --git a/retroshare-gui/src/gui/FriendsDialog.ui b/retroshare-gui/src/gui/FriendsDialog.ui index 4ee9bcc23..094ffe042 100644 --- a/retroshare-gui/src/gui/FriendsDialog.ui +++ b/retroshare-gui/src/gui/FriendsDialog.ui @@ -384,7 +384,7 @@ NewFriendList QWidget -
NewFriendList.h
+
gui/common/NewFriendList.h
1
diff --git a/retroshare-gui/src/gui/common/FriendListModel.cpp b/retroshare-gui/src/gui/common/FriendListModel.cpp index 441b02bbc..eca3206b5 100644 --- a/retroshare-gui/src/gui/common/FriendListModel.cpp +++ b/retroshare-gui/src/gui/common/FriendListModel.cpp @@ -1,5 +1,5 @@ /******************************************************************************* - * retroshare-gui/src/gui/msgs/RsMessageModel.cpp * + * retroshare-gui/src/gui/msgs/RsFriendListModel.cpp * * * * Copyright 2019 by Cyril Soler * * * @@ -26,12 +26,12 @@ #include #include -#include "gui/common/TagDefs.h" +#include "gui/common/StatusDefs.h" #include "util/HandleRichText.h" #include "util/DateTime.h" +#include "gui/common/FriendListModel.h" #include "gui/gxs/GxsIdDetails.h" #include "gui/gxs/GxsIdTreeWidgetItem.h" -#include "MessageModel.h" #include "retroshare/rsexpr.h" #include "retroshare/rsmsgs.h" @@ -44,27 +44,28 @@ std::ostream& operator<<(std::ostream& o, const QModelIndex& i);// defined elsewhere -const QString RsMessageModel::FilterString("filtered"); +const QString RsFriendListModel::FilterString("filtered"); -RsMessageModel::RsMessageModel(QObject *parent) +RsFriendListModel::RsFriendListModel(QObject *parent) : QAbstractItemModel(parent) { - mCurrentBox = BOX_NONE; - mQuickViewFilter = QUICK_VIEW_ALL; - mFilterType = FILTER_TYPE_NONE; + mDisplayGroups = false; mFilterStrings.clear(); } -void RsMessageModel::preMods() +void RsFriendListModel::preMods() { emit layoutAboutToBeChanged(); } -void RsMessageModel::postMods() +void RsFriendListModel::postMods() { - emit dataChanged(createIndex(0,0,(void*)NULL), createIndex(mMessages.size()-1,COLUMN_THREAD_NB_COLUMNS-1,(void*)NULL)); + if(mDisplayGroups) + emit dataChanged(createIndex(0,0,(void*)NULL), createIndex(mGroups.size()-1,COLUMN_THREAD_NB_COLUMNS-1,(void*)NULL)); + else + emit dataChanged(createIndex(0,0,(void*)NULL), createIndex(mProfiles.size()-1,COLUMN_THREAD_NB_COLUMNS-1,(void*)NULL)); } -int RsMessageModel::rowCount(const QModelIndex& parent) const +int RsFriendListModel::rowCount(const QModelIndex& parent) const { if(!parent.isValid()) return 0; @@ -72,35 +73,46 @@ int RsMessageModel::rowCount(const QModelIndex& parent) const if(parent.column() > 0) return 0; - if(mMessages.empty()) // security. Should never happen. - return 0; + if(mDisplayGroups) + { + if(mGroups.empty()) // security. Should never happen. + return 0; - if(parent.internalPointer() == NULL) - return mMessages.size(); + if(parent.internalPointer() == NULL) + return mGroups.size(); + } + else + { + if(mProfiles.empty()) // security. Should never happen. + return 0; + + if(parent.internalPointer() == NULL) + return mProfiles.size(); + } return 0; } -int RsMessageModel::columnCount(const QModelIndex &parent) const +int RsFriendListModel::columnCount(const QModelIndex &parent) const { return COLUMN_THREAD_NB_COLUMNS ; } -bool RsMessageModel::getMessageData(const QModelIndex& i,Rs::Msgs::MessageInfo& fmpe) const -{ - if(!i.isValid()) - return true; +// bool RsFriendListModel::getProfileData(const QModelIndex& i,Rs::Msgs::MessageInfo& fmpe) const +// { +// if(!i.isValid()) +// return true; +// +// quintptr ref = i.internalId(); +// uint32_t index = 0; +// +// if(!convertInternalIdToMsgIndex(ref,index) || index >= mMessages.size()) +// return false ; +// +// return rsMsgs->getMessage(mMessages[index].msgId,fmpe); +// } - quintptr ref = i.internalId(); - uint32_t index = 0; - - if(!convertInternalIdToMsgIndex(ref,index) || index >= mMessages.size()) - return false ; - - return rsMsgs->getMessage(mMessages[index].msgId,fmpe); -} - -bool RsMessageModel::hasChildren(const QModelIndex &parent) const +bool RsFriendListModel::hasChildren(const QModelIndex &parent) const { if(!parent.isValid()) return true; @@ -108,38 +120,84 @@ bool RsMessageModel::hasChildren(const QModelIndex &parent) const return false ; } -bool RsMessageModel::convertMsgIndexToInternalId(uint32_t index,quintptr& id) +bool RsFriendListModel::convertIndexToInternalId(const EntryIndex& e,quintptr& id) { // the internal id is set to the place in the table of items. We simply shift to allow 0 to mean something special. - id = index + 1 ; + if(e.ind > 0x0fffffff) + return false; + + if(e.type == ENTRY_TYPE_GROUP) + id = e.ind + 0x10000000 ; + else if(e.type == ENTRY_TYPE_PROFILE) + id = e.ind + 0x20000000 ; + else if(e.type == ENTRY_TYPE_NODE) + id = e.ind + 0x30000000 ; + else + return false; return true; } -bool RsMessageModel::convertInternalIdToMsgIndex(quintptr ref,uint32_t& index) +bool RsFriendListModel::convertInternalIdToIndex(quintptr ref,EntryIndex& e) { if(ref == 0) return false ; - index = ref - 1; + e.ind = ref & 0x0fffffff; + + int t = (ref >> 28)&0xf; + + if(t == 0x1) + e.type = ENTRY_TYPE_GROUP ; + else if(t==0x2) + e.type = ENTRY_TYPE_PROFILE ; + else if(t==0x3) + e.type = ENTRY_TYPE_NODE ; + else + return false; + return true; } -QModelIndex RsMessageModel::index(int row, int column, const QModelIndex & parent) const +QModelIndex RsFriendListModel::index(int row, int column, const QModelIndex & parent) const { if(row < 0 || column < 0 || column >= COLUMN_THREAD_NB_COLUMNS) return QModelIndex(); - quintptr ref ; + if(parent.internalId() == 0) + { + quintptr ref ; + + if(mDisplayGroups) + convertIndexToInternalId(EntryIndex(ENTRY_TYPE_GROUP,row),ref); + else + convertIndexToInternalId(EntryIndex(ENTRY_TYPE_PROFILE,row),ref); - if(parent.internalId() == 0 && convertMsgIndexToInternalId(row,ref)) return createIndex(row,column,ref) ; + } - return QModelIndex(); + EntryIndex parent_index ; + EntryIndex new_index; + + convertInternalIdToIndex(parent.internalId(),parent_index); + + new_index.ind = row; + + switch(parent_index.type) + { + case ENTRY_TYPE_GROUP: new_index.type = ENTRY_TYPE_PROFILE; + case ENTRY_TYPE_PROFILE: new_index.type = ENTRY_TYPE_NODE; + default: + return QModelIndex(); + } + quintptr ref ; + convertIndexToInternalId(new_index,ref); + + return createIndex(row,column,ref); } -QModelIndex RsMessageModel::parent(const QModelIndex& index) const +QModelIndex RsFriendListModel::parent(const QModelIndex& index) const { if(!index.isValid()) return QModelIndex(); @@ -147,7 +205,7 @@ QModelIndex RsMessageModel::parent(const QModelIndex& index) const return QModelIndex(); } -Qt::ItemFlags RsMessageModel::flags(const QModelIndex& index) const +Qt::ItemFlags RsFriendListModel::flags(const QModelIndex& index) const { if (!index.isValid()) return 0; @@ -155,46 +213,23 @@ Qt::ItemFlags RsMessageModel::flags(const QModelIndex& index) const return QAbstractItemModel::flags(index); } -QVariant RsMessageModel::headerData(int section, Qt::Orientation orientation, int role) const +QVariant RsFriendListModel::headerData(int section, Qt::Orientation orientation, int role) const { if(role == Qt::DisplayRole) switch(section) { - case COLUMN_THREAD_DATE: return tr("Date"); - case COLUMN_THREAD_AUTHOR: return tr("From"); - case COLUMN_THREAD_SUBJECT: return tr("Subject"); - case COLUMN_THREAD_TAGS: return tr("Tags"); + case COLUMN_THREAD_NAME: return tr("Name"); + case COLUMN_THREAD_ID: return tr("Id"); + case COLUMN_THREAD_LAST_CONTACT: return tr("Last contact"); + case COLUMN_THREAD_IP: return tr("IP"); default: return QVariant(); } - if(role == Qt::DecorationRole) - switch(section) - { - case COLUMN_THREAD_STAR: return QIcon(IMAGE_STAR_ON); - case COLUMN_THREAD_READ: return QIcon(":/images/message-state-header.png"); - case COLUMN_THREAD_ATTACHMENT: return QIcon(":/images/attachment.png"); - default: - return QVariant(); - } - - if(role == Qt::ToolTipRole) - switch(section) - { - case COLUMN_THREAD_ATTACHMENT: return tr("Click to sort by attachments"); - case COLUMN_THREAD_SUBJECT: return tr("Click to sort by subject"); - case COLUMN_THREAD_READ: return tr("Click to sort by read"); - case COLUMN_THREAD_AUTHOR: return tr("Click to sort by from"); - case COLUMN_THREAD_DATE: return tr("Click to sort by date"); - case COLUMN_THREAD_TAGS: return tr("Click to sort by tags"); - case COLUMN_THREAD_STAR: return tr("Click to sort by star"); - default: - return QVariant(); - } return QVariant(); } -QVariant RsMessageModel::data(const QModelIndex &index, int role) const +QVariant RsFriendListModel::data(const QModelIndex &index, int role) const { #ifdef DEBUG_MESSAGE_MODEL std::cerr << "calling data(" << index << ") role=" << role << std::endl; @@ -211,7 +246,6 @@ QVariant RsMessageModel::data(const QModelIndex &index, int role) const } quintptr ref = (index.isValid())?index.internalId():0 ; - uint32_t entry = 0; #ifdef DEBUG_MESSAGE_MODEL std::cerr << "data(" << index << ")" ; @@ -225,7 +259,9 @@ QVariant RsMessageModel::data(const QModelIndex &index, int role) const return QVariant() ; } - if(!convertInternalIdToMsgIndex(ref,entry) || entry >= mMessages.size()) + EntryIndex entry; + + if(!convertInternalIdToIndex(ref,entry)) { #ifdef DEBUG_MESSAGE_MODEL std::cerr << "Bad pointer: " << (void*)ref << std::endl; @@ -233,55 +269,42 @@ QVariant RsMessageModel::data(const QModelIndex &index, int role) const return QVariant() ; } - const Rs::Msgs::MsgInfoSummary& fmpe(mMessages[entry]); - - if(role == Qt::FontRole) - { - QFont font ; - font.setBold(fmpe.msgflags & (RS_MSG_NEW | RS_MSG_UNREAD_BY_USER)); - - return QVariant(font); - } - -#ifdef DEBUG_MESSAGE_MODEL - std::cerr << " [ok]" << std::endl; -#endif - switch(role) { - case Qt::DisplayRole: return displayRole (fmpe,index.column()) ; - case Qt::DecorationRole: return decorationRole(fmpe,index.column()) ; - case Qt::ToolTipRole: return toolTipRole (fmpe,index.column()) ; - case Qt::UserRole: return userRole (fmpe,index.column()) ; - case Qt::TextColorRole: return textColorRole (fmpe,index.column()) ; - case Qt::BackgroundRole: return backgroundRole(fmpe,index.column()) ; - - case FilterRole: return filterRole (fmpe,index.column()) ; - case StatusRole: return statusRole (fmpe,index.column()) ; - case SortRole: return sortRole (fmpe,index.column()) ; - case MsgFlagsRole: return fmpe.msgflags ; - case UnreadRole: return fmpe.msgflags & (RS_MSG_NEW | RS_MSG_UNREAD_BY_USER); - case MsgIdRole: return QString::fromStdString(fmpe.msgId) ; - case SrcIdRole: return QString::fromStdString(fmpe.srcId.toStdString()) ; + case Qt::DisplayRole: return displayRole(entry,index.column()) ; default: return QVariant(); } + +// if(role == Qt::FontRole) +// { +// QFont font ; +// font.setBold(fmpe.msgflags & (RS_MSG_NEW | RS_MSG_UNREAD_BY_USER)); +// +// return QVariant(font); +// } + +// case Qt::DecorationRole: return decorationRole(fmpe,index.column()) ; +// case Qt::ToolTipRole: return toolTipRole (fmpe,index.column()) ; +// case Qt::UserRole: return userRole (fmpe,index.column()) ; +// case Qt::TextColorRole: return textColorRole (fmpe,index.column()) ; +// case Qt::BackgroundRole: return backgroundRole(fmpe,index.column()) ; +// +// case FilterRole: return filterRole (fmpe,index.column()) ; +// case StatusRole: return statusRole (fmpe,index.column()) ; +// case SortRole: return sortRole (fmpe,index.column()) ; +// case MsgFlagsRole: return fmpe.msgflags ; +// case UnreadRole: return fmpe.msgflags & (RS_MSG_NEW | RS_MSG_UNREAD_BY_USER); +// case MsgIdRole: return QString::fromStdString(fmpe.msgId) ; +// case SrcIdRole: return QString::fromStdString(fmpe.srcId.toStdString()) ; } -QVariant RsMessageModel::textColorRole(const Rs::Msgs::MsgInfoSummary& fmpe,int column) const +QVariant RsFriendListModel::textColorRole(const EntryIndex& fmpe,int column) const { - Rs::Msgs::MsgTagType tags; - rsMsgs->getMessageTagTypes(tags); - - for(auto it(fmpe.msgtags.begin());it!=fmpe.msgtags.end();++it) - for(auto it2(tags.types.begin());it2!=tags.types.end();++it2) - if(it2->first == *it) - return QColor(it2->second.second); - return QVariant(); } -QVariant RsMessageModel::statusRole(const Rs::Msgs::MsgInfoSummary& fmpe,int column) const +QVariant RsFriendListModel::statusRole(const EntryIndex& fmpe,int column) const { // if(column != COLUMN_THREAD_DATA) // return QVariant(); @@ -289,71 +312,52 @@ QVariant RsMessageModel::statusRole(const Rs::Msgs::MsgInfoSummary& fmpe,int col return QVariant();//fmpe.mMsgStatus); } -bool RsMessageModel::passesFilter(const Rs::Msgs::MsgInfoSummary& fmpe,int column) const +bool RsFriendListModel::passesFilter(const EntryIndex& e,int column) const { - QString s ; - bool passes_strings = true ; - - if(!mFilterStrings.empty()) - { - switch(mFilterType) - { - case FILTER_TYPE_SUBJECT: s = displayRole(fmpe,COLUMN_THREAD_SUBJECT).toString(); - break; - - case FILTER_TYPE_FROM: s = sortRole(fmpe,COLUMN_THREAD_AUTHOR).toString(); - if(s.isNull()) - passes_strings = false; - break; - case FILTER_TYPE_DATE: s = displayRole(fmpe,COLUMN_THREAD_DATE).toString(); - break; - case FILTER_TYPE_CONTENT: { - Rs::Msgs::MessageInfo minfo; - rsMsgs->getMessage(fmpe.msgId,minfo); - s = QTextDocument(QString::fromUtf8(minfo.msg.c_str())).toPlainText(); - } - break; - case FILTER_TYPE_TAGS: s = displayRole(fmpe,COLUMN_THREAD_TAGS).toString(); - break; - - case FILTER_TYPE_ATTACHMENTS: - { - Rs::Msgs::MessageInfo minfo; - rsMsgs->getMessage(fmpe.msgId,minfo); - - for(auto it(minfo.files.begin());it!=minfo.files.end();++it) - s += QString::fromUtf8((*it).fname.c_str())+" "; - } - }; - } - - if(!s.isNull()) - for(auto iter(mFilterStrings.begin()); iter != mFilterStrings.end(); ++iter) - passes_strings = passes_strings && s.contains(*iter,Qt::CaseInsensitive); - - bool passes_quick_view = - (mQuickViewFilter==QUICK_VIEW_ALL) - || (std::find(fmpe.msgtags.begin(),fmpe.msgtags.end(),mQuickViewFilter) != fmpe.msgtags.end()) - || (mQuickViewFilter==QUICK_VIEW_STARRED && (fmpe.msgflags & RS_MSG_STAR)) - || (mQuickViewFilter==QUICK_VIEW_SYSTEM && (fmpe.msgflags & RS_MSG_SYSTEM)); -#ifdef DEBUG_MESSAGE_MODEL - std::cerr << "Passes filter: type=" << mFilterType << " s=\"" << s.toStdString() << "MsgFlags=" << fmpe.msgflags << " msgtags=" ; - foreach(uint32_t i,fmpe.msgtags) std::cerr << i << " " ; - std::cerr << "\" strings:" << passes_strings << " quick_view:" << passes_quick_view << std::endl; -#endif - - return passes_quick_view && passes_strings; +// QString s ; +// bool passes_strings = true ; +// +// if(!mFilterStrings.empty()) +// { +// switch(mFilterType) +// { +// case FILTER_TYPE_ID: s = displayRole(fmpe,COLUMN_THREAD_SUBJECT).toString(); +// break; +// +// case FILTER_TYPE_NAME: s = sortRole(fmpe,COLUMN_THREAD_AUTHOR).toString(); +// if(s.isNull()) +// passes_strings = false; +// break; +// }; +// } +// +// if(!s.isNull()) +// for(auto iter(mFilterStrings.begin()); iter != mFilterStrings.end(); ++iter) +// passes_strings = passes_strings && s.contains(*iter,Qt::CaseInsensitive); +// +// bool passes_quick_view = +// (mQuickViewFilter==QUICK_VIEW_ALL) +// || (std::find(fmpe.msgtags.begin(),fmpe.msgtags.end(),mQuickViewFilter) != fmpe.msgtags.end()) +// || (mQuickViewFilter==QUICK_VIEW_STARRED && (fmpe.msgflags & RS_MSG_STAR)) +// || (mQuickViewFilter==QUICK_VIEW_SYSTEM && (fmpe.msgflags & RS_MSG_SYSTEM)); +// #ifdef DEBUG_MESSAGE_MODEL +// std::cerr << "Passes filter: type=" << mFilterType << " s=\"" << s.toStdString() << "MsgFlags=" << fmpe.msgflags << " msgtags=" ; +// foreach(uint32_t i,fmpe.msgtags) std::cerr << i << " " ; +// std::cerr << "\" strings:" << passes_strings << " quick_view:" << passes_quick_view << std::endl; +// #endif +// +// return passes_quick_view && passes_strings; } -QVariant RsMessageModel::filterRole(const Rs::Msgs::MsgInfoSummary& fmpe,int column) const +QVariant RsFriendListModel::filterRole(const EntryIndex& e,int column) const { - if(passesFilter(fmpe,column)) + if(passesFilter(e,column)) return QVariant(FilterString); return QVariant(QString()); } -uint32_t RsMessageModel::updateFilterStatus(ForumModelIndex i,int column,const QStringList& strings) +uint32_t RsFriendListModel::updateFilterStatus(ForumModelIndex i,int column,const QStringList& strings) { QString s ; uint32_t count = 0; @@ -362,7 +366,7 @@ uint32_t RsMessageModel::updateFilterStatus(ForumModelIndex i,int column,const Q } -void RsMessageModel::setFilter(FilterType filter_type, const QStringList& strings) +void RsFriendListModel::setFilter(FilterType filter_type, const QStringList& strings) { std::cerr << "Setting filter to filter_type=" << int(filter_type) << " and strings to " ; foreach(const QString& str,strings) @@ -377,317 +381,225 @@ void RsMessageModel::setFilter(FilterType filter_type, const QStringList& string postMods(); } -QVariant RsMessageModel::toolTipRole(const Rs::Msgs::MsgInfoSummary& fmpe,int column) const +QVariant RsFriendListModel::toolTipRole(const EntryIndex& fmpe,int column) const { - if(column == COLUMN_THREAD_AUTHOR) - { - QString str,comment ; - QList icons; - - if(!GxsIdDetails::MakeIdDesc(RsGxsId(fmpe.srcId.toStdString()), true, str, icons, comment,GxsIdDetails::ICON_TYPE_AVATAR)) - return QVariant(); - - int S = QFontMetricsF(QApplication::font()).height(); - QImage pix( (*icons.begin()).pixmap(QSize(4*S,4*S)).toImage()); - - QString embeddedImage; - if(RsHtml::makeEmbeddedImage(pix.scaled(QSize(4*S,4*S), Qt::KeepAspectRatio, Qt::SmoothTransformation), embeddedImage, 8*S * 8*S)) - comment = "
" + embeddedImage + "" + comment + "
"; - - return comment; - } +// if(column == COLUMN_THREAD_AUTHOR) +// { +// QString str,comment ; +// QList icons; +// +// if(!GxsIdDetails::MakeIdDesc(RsGxsId(fmpe.srcId.toStdString()), true, str, icons, comment,GxsIdDetails::ICON_TYPE_AVATAR)) +// return QVariant(); +// +// int S = QFontMetricsF(QApplication::font()).height(); +// QImage pix( (*icons.begin()).pixmap(QSize(4*S,4*S)).toImage()); +// +// QString embeddedImage; +// if(RsHtml::makeEmbeddedImage(pix.scaled(QSize(4*S,4*S), Qt::KeepAspectRatio, Qt::SmoothTransformation), embeddedImage, 8*S * 8*S)) +// comment = "
" + embeddedImage + "" + comment + "
"; +// +// return comment; +// } return QVariant(); } -QVariant RsMessageModel::backgroundRole(const Rs::Msgs::MsgInfoSummary &fmpe, int column) const -{ - return QVariant(); -} - -QVariant RsMessageModel::sizeHintRole(int col) const +QVariant RsFriendListModel::sizeHintRole(int col) const { float factor = QFontMetricsF(QApplication::font()).height()/14.0f ; switch(col) { default: - case COLUMN_THREAD_SUBJECT: return QVariant( QSize(factor * 170, factor*14 )); - case COLUMN_THREAD_DATE: return QVariant( QSize(factor * 75 , factor*14 )); - case COLUMN_THREAD_AUTHOR: return QVariant( QSize(factor * 75 , factor*14 )); + case COLUMN_THREAD_NAME: return QVariant( QSize(factor * 170, factor*14 )); + case COLUMN_THREAD_IP: return QVariant( QSize(factor * 75 , factor*14 )); + case COLUMN_THREAD_ID: return QVariant( QSize(factor * 75 , factor*14 )); + case COLUMN_THREAD_LAST_CONTACT: return QVariant( QSize(factor * 75 , factor*14 )); } } -QVariant RsMessageModel::authorRole(const Rs::Msgs::MsgInfoSummary& fmpe,int column) const +QVariant RsFriendListModel::sortRole(const EntryIndex& fmpe,int column) const { +// switch(column) +// { +// case COLUMN_THREAD_DATE: return QVariant(QString::number(fmpe.ts)); // we should probably have leading zeroes here +// +// case COLUMN_THREAD_READ: return QVariant((bool)IS_MESSAGE_UNREAD(fmpe.msgflags)); +// +// case COLUMN_THREAD_STAR: return QVariant((fmpe.msgflags & RS_MSG_STAR)? 1:0); +// +// case COLUMN_THREAD_AUTHOR:{ +// QString name; +// +// if(GxsIdTreeItemDelegate::computeName(RsGxsId(fmpe.srcId.toStdString()),name)) +// return name; +// } +// default: +// return displayRole(fmpe,column); +// } return QVariant(); } -QVariant RsMessageModel::sortRole(const Rs::Msgs::MsgInfoSummary& fmpe,int column) const +QVariant RsFriendListModel::displayRole(const EntryIndex& e, int col) const { - switch(column) - { - case COLUMN_THREAD_DATE: return QVariant(QString::number(fmpe.ts)); // we should probably have leading zeroes here - - case COLUMN_THREAD_READ: return QVariant((bool)IS_MESSAGE_UNREAD(fmpe.msgflags)); - - case COLUMN_THREAD_STAR: return QVariant((fmpe.msgflags & RS_MSG_STAR)? 1:0); - - case COLUMN_THREAD_AUTHOR:{ - QString name; - - if(GxsIdTreeItemDelegate::computeName(RsGxsId(fmpe.srcId.toStdString()),name)) - return name; - } - default: - return displayRole(fmpe,column); - } -} - -QVariant RsMessageModel::displayRole(const Rs::Msgs::MsgInfoSummary& fmpe,int col) const -{ - switch(col) + switch(e.type) { - case COLUMN_THREAD_SUBJECT: return QVariant(QString::fromUtf8(fmpe.title.c_str())); - case COLUMN_THREAD_ATTACHMENT:return QVariant(QString::number(fmpe.count)); + case ENTRY_TYPE_GROUP: + if(e.ind >= mGroups.size()) + return QVariant(); - case COLUMN_THREAD_STAR: - case COLUMN_THREAD_READ:return QVariant(); - case COLUMN_THREAD_DATE:{ - QDateTime qtime; - qtime.setTime_t(fmpe.ts); + switch(col) + { + case COLUMN_THREAD_NAME: return QVariant(QString::fromUtf8(mGroups[e.ind].name.c_str())); - return QVariant(DateTime::formatDateTime(qtime)); + default: + return QVariant(); + } break; + + case ENTRY_TYPE_PROFILE: + if(e.ind >= mProfiles.size()) + return QVariant(); + + switch(col) + { + case COLUMN_THREAD_NAME: return QVariant(QString::fromUtf8(mProfiles[e.ind].name.c_str())); + case COLUMN_THREAD_ID: return QVariant(QString::fromStdString(mProfiles[e.ind].gpg_id.toStdString()) ); + + default: + return QVariant(); + } break; + + case ENTRY_TYPE_NODE: + if(e.ind >= mLocations.size()) + return QVariant(); + + switch(col) + { + case COLUMN_THREAD_NAME: return QVariant(QString::fromUtf8(mLocations[e.ind].location.c_str())); + case COLUMN_THREAD_LAST_CONTACT: return QVariant(QDateTime::fromTime_t(mLocations[e.ind].lastConnect).toString()); + case COLUMN_THREAD_IP: return QVariant( (mLocations[e.ind].state & RS_PEER_STATE_CONNECTED) ? StatusDefs::connectStateIpString(mLocations[e.ind]) : QString("---")); + case COLUMN_THREAD_ID: return QVariant( QString::fromStdString(mLocations[e.ind].id.toStdString()) ); + + default: + return QVariant(); + } break; + + return QVariant(); } - - case COLUMN_THREAD_TAGS:{ - // Tags - Rs::Msgs::MsgTagInfo tagInfo; - rsMsgs->getMessageTag(fmpe.msgId, tagInfo); - - Rs::Msgs::MsgTagType Tags; - rsMsgs->getMessageTagTypes(Tags); - - QString text; - - // build tag names - std::map >::iterator Tag; - for (auto tagit = tagInfo.tagIds.begin(); tagit != tagInfo.tagIds.end(); ++tagit) - { - if (!text.isNull()) - text += ","; - - auto Tag = Tags.types.find(*tagit); - - if (Tag != Tags.types.end()) - text += TagDefs::name(Tag->first, Tag->second.first); - else - std::cerr << "(WW) unknown tag " << (int)Tag->first << " in message " << fmpe.msgId << std::endl; - } - return text; - } - case COLUMN_THREAD_AUTHOR: return QVariant(); - - default: - return QVariant("[ TODO ]"); - } - - - return QVariant("[ERROR]"); } -QVariant RsMessageModel::userRole(const Rs::Msgs::MsgInfoSummary& fmpe,int col) const +QVariant RsFriendListModel::userRole(const EntryIndex& fmpe,int col) const { - switch(col) - { - case COLUMN_THREAD_AUTHOR: return QVariant(QString::fromStdString(fmpe.srcId.toStdString())); - case COLUMN_THREAD_MSGID: return QVariant(QString::fromStdString(fmpe.msgId)); - default: - return QVariant(); - } +// switch(col) +// { +// case COLUMN_THREAD_AUTHOR: return QVariant(QString::fromStdString(fmpe.srcId.toStdString())); +// case COLUMN_THREAD_MSGID: return QVariant(QString::fromStdString(fmpe.msgId)); +// default: +// return QVariant(); +// } + + return QVariant(); } -QVariant RsMessageModel::decorationRole(const Rs::Msgs::MsgInfoSummary& fmpe,int col) const +QVariant RsFriendListModel::decorationRole(const EntryIndex& fmpe,int col) const { - if(col == COLUMN_THREAD_READ) - if(fmpe.msgflags & (RS_MSG_NEW | RS_MSG_UNREAD_BY_USER)) - return QIcon(":/images/message-state-unread.png"); - else - return QIcon(":/images/message-state-read.png"); - - if(col == COLUMN_THREAD_SUBJECT) - { - if(fmpe.msgflags & RS_MSG_NEW ) return QIcon(":/images/message-state-new.png"); - if(fmpe.msgflags & RS_MSG_USER_REQUEST) return QIcon(":/images/user/user_request16.png"); - if(fmpe.msgflags & RS_MSG_FRIEND_RECOMMENDATION) return QIcon(":/images/user/friend_suggestion16.png"); - if(fmpe.msgflags & RS_MSG_PUBLISH_KEY) return QIcon(":/images/share-icon-16.png"); - - if(fmpe.msgflags & RS_MSG_UNREAD_BY_USER) - { - if((fmpe.msgflags & (RS_MSG_REPLIED | RS_MSG_FORWARDED)) == RS_MSG_REPLIED) return QIcon(":/images/message-mail-replied.png"); - if((fmpe.msgflags & (RS_MSG_REPLIED | RS_MSG_FORWARDED)) == RS_MSG_FORWARDED) return QIcon(":/images/message-mail-forwarded.png"); - if((fmpe.msgflags & (RS_MSG_REPLIED | RS_MSG_FORWARDED)) == (RS_MSG_REPLIED | RS_MSG_FORWARDED)) return QIcon(":/images/message-mail-replied-forw.png"); - - return QIcon(":/images/message-mail.png"); - } - if((fmpe.msgflags & (RS_MSG_REPLIED | RS_MSG_FORWARDED)) == RS_MSG_REPLIED) return QIcon(":/images/message-mail-replied-read.png"); - if((fmpe.msgflags & (RS_MSG_REPLIED | RS_MSG_FORWARDED)) == RS_MSG_FORWARDED) return QIcon(":/images/message-mail-forwarded-read.png"); - if((fmpe.msgflags & (RS_MSG_REPLIED | RS_MSG_FORWARDED)) == (RS_MSG_REPLIED | RS_MSG_FORWARDED)) return QIcon(":/images/message-mail-replied-forw-read.png"); - - return QIcon(":/images/message-mail-read.png"); - } - - if(col == COLUMN_THREAD_STAR) - return QIcon((fmpe.msgflags & RS_MSG_STAR) ? (IMAGE_STAR_ON ): (IMAGE_STAR_OFF)); - - bool isNew = fmpe.msgflags & (RS_MSG_NEW | RS_MSG_UNREAD_BY_USER); - - if(col == COLUMN_THREAD_READ) - return QIcon(isNew ? ":/images/message-state-unread.png": ":/images/message-state-read.png"); +// if(col == COLUMN_THREAD_READ) +// if(fmpe.msgflags & (RS_MSG_NEW | RS_MSG_UNREAD_BY_USER)) +// return QIcon(":/images/message-state-unread.png"); +// else +// return QIcon(":/images/message-state-read.png"); +// +// if(col == COLUMN_THREAD_SUBJECT) +// { +// if(fmpe.msgflags & RS_MSG_NEW ) return QIcon(":/images/message-state-new.png"); +// if(fmpe.msgflags & RS_MSG_USER_REQUEST) return QIcon(":/images/user/user_request16.png"); +// if(fmpe.msgflags & RS_MSG_FRIEND_RECOMMENDATION) return QIcon(":/images/user/friend_suggestion16.png"); +// if(fmpe.msgflags & RS_MSG_PUBLISH_KEY) return QIcon(":/images/share-icon-16.png"); +// +// if(fmpe.msgflags & RS_MSG_UNREAD_BY_USER) +// { +// if((fmpe.msgflags & (RS_MSG_REPLIED | RS_MSG_FORWARDED)) == RS_MSG_REPLIED) return QIcon(":/images/message-mail-replied.png"); +// if((fmpe.msgflags & (RS_MSG_REPLIED | RS_MSG_FORWARDED)) == RS_MSG_FORWARDED) return QIcon(":/images/message-mail-forwarded.png"); +// if((fmpe.msgflags & (RS_MSG_REPLIED | RS_MSG_FORWARDED)) == (RS_MSG_REPLIED | RS_MSG_FORWARDED)) return QIcon(":/images/message-mail-replied-forw.png"); +// +// return QIcon(":/images/message-mail.png"); +// } +// if((fmpe.msgflags & (RS_MSG_REPLIED | RS_MSG_FORWARDED)) == RS_MSG_REPLIED) return QIcon(":/images/message-mail-replied-read.png"); +// if((fmpe.msgflags & (RS_MSG_REPLIED | RS_MSG_FORWARDED)) == RS_MSG_FORWARDED) return QIcon(":/images/message-mail-forwarded-read.png"); +// if((fmpe.msgflags & (RS_MSG_REPLIED | RS_MSG_FORWARDED)) == (RS_MSG_REPLIED | RS_MSG_FORWARDED)) return QIcon(":/images/message-mail-replied-forw-read.png"); +// +// return QIcon(":/images/message-mail-read.png"); +// } +// +// if(col == COLUMN_THREAD_STAR) +// return QIcon((fmpe.msgflags & RS_MSG_STAR) ? (IMAGE_STAR_ON ): (IMAGE_STAR_OFF)); +// +// bool isNew = fmpe.msgflags & (RS_MSG_NEW | RS_MSG_UNREAD_BY_USER); +// +// if(col == COLUMN_THREAD_READ) +// return QIcon(isNew ? ":/images/message-state-unread.png": ":/images/message-state-read.png"); return QVariant(); } -void RsMessageModel::clear() +void RsFriendListModel::clear() { preMods(); - mMessages.clear(); + mGroups.clear(); + mProfiles.clear(); + mLocations.clear(); postMods(); - emit messagesLoaded(); + emit friendListChanged(); } -void RsMessageModel::setMessages(const std::list& msgs) -{ - preMods(); - - beginRemoveRows(QModelIndex(),0,mMessages.size()-1); - endRemoveRows(); - - mMessages.clear(); - mMessagesMap.clear(); - - for(auto it(msgs.begin());it!=msgs.end();++it) - { - mMessagesMap[(*it).msgId] = mMessages.size(); - mMessages.push_back(*it); - } - - // now update prow for all posts - -#ifdef DEBUG_MESSAGE_MODEL - debug_dump(); -#endif - - beginInsertRows(QModelIndex(),0,mMessages.size()-1); - endInsertRows(); - postMods(); - - emit messagesLoaded(); -} - -void RsMessageModel::setCurrentBox(BoxName bn) -{ - if(mCurrentBox != bn) - { - mCurrentBox = bn; - updateMessages(); - } -} - -void RsMessageModel::setQuickViewFilter(QuickViewFilter fn) -{ - if(fn != mQuickViewFilter) - { - std::cerr << "Changing new quickview filter to " << fn << std::endl; - - preMods(); - mQuickViewFilter = fn ; - postMods(); - } -} - -void RsMessageModel::getMessageSummaries(BoxName box,std::list& msgs) -{ - rsMsgs->getMessageSummaries(msgs); - - // filter out messages that are not in the right box. - - for(auto it(msgs.begin());it!=msgs.end();) - { - bool ok = false; - - switch(box) - { - case BOX_INBOX : ok = (it->msgflags & RS_MSG_BOXMASK) == RS_MSG_INBOX && !(it->msgflags & RS_MSG_TRASH); break ; - case BOX_SENT : ok = (it->msgflags & RS_MSG_BOXMASK) == RS_MSG_SENTBOX && !(it->msgflags & RS_MSG_TRASH); break ; - case BOX_OUTBOX : ok = (it->msgflags & RS_MSG_BOXMASK) == RS_MSG_OUTBOX && !(it->msgflags & RS_MSG_TRASH); break ; - case BOX_DRAFTS : ok = (it->msgflags & RS_MSG_BOXMASK) == RS_MSG_DRAFTBOX && !(it->msgflags & RS_MSG_TRASH); break ; - case BOX_TRASH : ok = (it->msgflags & RS_MSG_TRASH) ; break ; - default: - ++it; - continue; - } - - if(ok) - ++it; - else - it = msgs.erase(it) ; - } -} - -void RsMessageModel::updateMessages() -{ - emit messagesAboutToLoad(); - - std::list msgs; - - getMessageSummaries(mCurrentBox,msgs); - setMessages(msgs); - - emit messagesLoaded(); -} +// void RsFriendListModel::setMessages(const std::list& msgs) +// { +// preMods(); +// +// beginRemoveRows(QModelIndex(),0,mMessages.size()-1); +// endRemoveRows(); +// +// mMessages.clear(); +// mMessagesMap.clear(); +// +// for(auto it(msgs.begin());it!=msgs.end();++it) +// { +// mMessagesMap[(*it).msgId] = mMessages.size(); +// mMessages.push_back(*it); +// } +// +// // now update prow for all posts +// +// #ifdef DEBUG_MESSAGE_MODEL +// debug_dump(); +// #endif +// +// beginInsertRows(QModelIndex(),0,mMessages.size()-1); +// endInsertRows(); +// postMods(); +// +// emit messagesLoaded(); +// } +// +// void RsFriendListModel::updateMessages() +// { +// emit messagesAboutToLoad(); +// +// std::list msgs; +// +// getMessageSummaries(mCurrentBox,msgs); +// setMessages(msgs); +// +// emit messagesLoaded(); +// } static bool decreasing_time_comp(const std::pair& e1,const std::pair& e2) { return e2.first < e1.first ; } -void RsMessageModel::setMsgReadStatus(const QModelIndex& i,bool read_status) +void RsFriendListModel::debug_dump() const { - if(!i.isValid()) - return ; - - preMods(); - rsMsgs->MessageRead(i.data(MsgIdRole).toString().toStdString(),!read_status); - - emit dataChanged(i.sibling(i.row(),0),i.sibling(i.row(),COLUMN_THREAD_NB_COLUMNS-1)); -} - -void RsMessageModel::setMsgStar(const QModelIndex& i,bool star) -{ - preMods(); - rsMsgs->MessageStar(i.data(MsgIdRole).toString().toStdString(),star); - - emit dataChanged(i.sibling(i.row(),0),i.sibling(i.row(),COLUMN_THREAD_NB_COLUMNS-1)); -} - -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. - - auto it = mMessagesMap.find(mid); - - if(it == mMessagesMap.end() || it->second >= mMessages.size()) - return QModelIndex(); - - quintptr ref ; - convertMsgIndexToInternalId(it->second,ref); - - return createIndex(it->second,0,ref); -} - -void RsMessageModel::debug_dump() const -{ - for(auto it(mMessages.begin());it!=mMessages.end();++it) - std::cerr << "Id: " << it->msgId << ": from " << it->srcId << ": flags=" << it->msgflags << ": title=\"" << it->title << "\"" << std::endl; + for(auto it(mGroups.begin());it!=mGroups.end();++it) + std::cerr << "Group: " << *it << std::endl; } diff --git a/retroshare-gui/src/gui/common/FriendListModel.h b/retroshare-gui/src/gui/common/FriendListModel.h index 0a1f146a8..c8f1001cb 100644 --- a/retroshare-gui/src/gui/common/FriendListModel.h +++ b/retroshare-gui/src/gui/common/FriendListModel.h @@ -24,6 +24,7 @@ #include #include "retroshare/rsmsgs.h" +#include "retroshare/rspeers.h" // This class holds the actual hierarchy of posts, represented by identifiers // It is responsible for auto-updating when necessary and holds a mutex to allow the Model to @@ -43,17 +44,15 @@ public: explicit RsFriendListModel(QObject *parent = NULL); ~RsFriendListModel(){} + class RsNodeDetails: public RsPeerDetails {};// in the near future, there will be a specific class for Profile/Node details in replacement of RsPeerDetails + class RsProfileDetails: public RsPeerDetails {}; + enum Columns { - COLUMN_THREAD_STAR = 0x00, - COLUMN_THREAD_ATTACHMENT = 0x01, - COLUMN_THREAD_SUBJECT = 0x02, - COLUMN_THREAD_READ = 0x03, - COLUMN_THREAD_AUTHOR = 0x04, - COLUMN_THREAD_DATE = 0x05, - COLUMN_THREAD_TAGS = 0x06, - COLUMN_THREAD_MSGID = 0x07, - COLUMN_THREAD_NB_COLUMNS = 0x08, - COLUMN_THREAD_CONTENT = 0x08, + COLUMN_THREAD_NAME = 0x00, + COLUMN_THREAD_LAST_CONTACT = 0x01, + COLUMN_THREAD_IP = 0x02, + COLUMN_THREAD_ID = 0x03, + COLUMN_THREAD_NB_COLUMNS = 0x04 }; enum Roles{ SortRole = Qt::UserRole+1, @@ -65,14 +64,36 @@ public: SrcIdRole = Qt::UserRole+7, }; + enum FilterType{ FILTER_TYPE_NONE = 0x00, + FILTER_TYPE_ID = 0x01, + FILTER_TYPE_NAME = 0x02 + }; + + enum EntryType{ ENTRY_TYPE_UNKNOWN = 0x00, + ENTRY_TYPE_GROUP = 0x01, + ENTRY_TYPE_PROFILE = 0x02, + ENTRY_TYPE_NODE = 0x03 + }; + + struct EntryIndex + { + EntryIndex(EntryType t,uint32_t i) : type(t),ind(i) {} + EntryIndex() : type(ENTRY_TYPE_UNKNOWN),ind(0) {} + + EntryType type; + uint32_t ind; + }; + QModelIndex root() const{ return createIndex(0,0,(void*)NULL) ;} - QModelIndex getIndexOfMessage(const std::string &mid) const; + + QModelIndex getIndexOfGroup(const RsNodeGroupId& mid) const; static const QString FilterString ; // This method will asynchroneously update the data - const RsMessageId& currentMessageId() const; + EntryType currentItemData(RsGroupInfo&,RsProfileDetails&,RsNodeDetails&) const; + void setFilter(FilterType filter_type, const QStringList& strings) ; int rowCount(const QModelIndex& parent = QModelIndex()) const override; @@ -90,15 +111,17 @@ public: QVariant sizeHintRole (int col) const; - QVariant displayRole (const Rs::Msgs::MsgInfoSummary& fmpe, int col) const; - QVariant decorationRole(const Rs::Msgs::MsgInfoSummary& fmpe, int col) const; - QVariant toolTipRole (const Rs::Msgs::MsgInfoSummary& fmpe, int col) const; - QVariant userRole (const Rs::Msgs::MsgInfoSummary& fmpe, int col) const; - QVariant statusRole (const Rs::Msgs::MsgInfoSummary& fmpe, int col) const; - QVariant sortRole (const Rs::Msgs::MsgInfoSummary& fmpe, int col) const; - QVariant fontRole (const Rs::Msgs::MsgInfoSummary& fmpe, int col) const; - QVariant filterRole (const Rs::Msgs::MsgInfoSummary& fmpe, int col) const; - QVariant textColorRole (const Rs::Msgs::MsgInfoSummary& fmpe, int col) const; + QVariant displayRole (const EntryIndex &e, int col) const; + + QVariant decorationRole(const EntryIndex& fmpe, int col) const; + QVariant toolTipRole (const EntryIndex &fmpe, int col) const; + QVariant userRole (const EntryIndex& fmpe, int col) const; + QVariant statusRole (const EntryIndex& fmpe, int col) const; + QVariant sortRole (const EntryIndex& fmpe, int col) const; + QVariant fontRole (const EntryIndex& fmpe, int col) const; + QVariant textColorRole (const EntryIndex& fmpe, int col) const; + + QVariant filterRole (const EntryIndex& e, int col) const; /*! * \brief debug_dump @@ -111,10 +134,11 @@ public slots: signals: void dataLoaded(); // emitted after the messages have been set. Can be used to updated the UI. + void friendListChanged(); // emitted after the messages have been set. Can be used to updated the UI. void dataAboutToLoad(); private: - bool passesFilter(const Rs::Msgs::MsgInfoSummary& fmpe,int column) const; + bool passesFilter(const EntryIndex &e, int column) const; void preMods() ; void postMods() ; @@ -123,15 +147,17 @@ private: void *getChildRef(void *ref,int row) const; int getChildrenCount(void *ref) const; - static bool convertMsgIndexToInternalId(uint32_t entry,quintptr& ref); - static bool convertInternalIdToMsgIndex(quintptr ref,uint32_t& index); + static bool convertIndexToInternalId(const EntryIndex& e,quintptr& ref); + static bool convertInternalIdToIndex(quintptr ref, EntryIndex& e); uint32_t updateFilterStatus(ForumModelIndex i,int column,const QStringList& strings); QStringList mFilterStrings; FilterType mFilterType; + bool mDisplayGroups ; + std::vector mGroups; - std::vector mProfiles; // normally here we should have a specific class rather than RsPeerDetails - std::vector mLocations;// normally here we should have a specific class rather than RsPeerDetails + std::vector mProfiles; + std::vector mLocations; }; diff --git a/retroshare-gui/src/gui/common/NewFriendList.cpp b/retroshare-gui/src/gui/common/NewFriendList.cpp index 8eaf78ca3..33f9bfd50 100644 --- a/retroshare-gui/src/gui/common/NewFriendList.cpp +++ b/retroshare-gui/src/gui/common/NewFriendList.cpp @@ -56,7 +56,7 @@ #include "gui/connect/ConnectProgressDialog.h" #include "gui/common/ElidedLabel.h" -#include "FriendList.h" +#include "NewFriendList.h" #include "ui_FriendList.h" /* Images for context menu icons */ @@ -109,34 +109,34 @@ Q_DECLARE_METATYPE(ElidedLabel*) NewFriendList::NewFriendList(QWidget *parent) : - QAbstractItemView(parent), - mCompareRole(new RSTreeWidgetItemCompareRole), + QTreeView(parent), +// mCompareRole(new RSTreeWidgetItemCompareRole), mShowGroups(true), mShowState(false), mHideUnconnected(false), groupsHasChanged(false) { - connect(ui->peerTreeWidget, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(peerTreeWidgetCustomPopupMenu())); - connect(ui->peerTreeWidget, SIGNAL(itemExpanded(QTreeWidgetItem *)), this, SLOT(expandItem(QTreeWidgetItem *))); - connect(ui->peerTreeWidget, SIGNAL(itemCollapsed(QTreeWidgetItem *)), this, SLOT(collapseItem(QTreeWidgetItem *))); - connect(ui->peerTreeWidget, SIGNAL(itemClicked(QTreeWidgetItem *, int)), this, SLOT(expandItem(QTreeWidgetItem *)) ); + connect(this, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(peerTreeWidgetCustomPopupMenu())); + connect(this, SIGNAL(itemExpanded(QTreeWidgetItem *)), this, SLOT(expandItem(QTreeWidgetItem *))); + connect(this, SIGNAL(itemCollapsed(QTreeWidgetItem *)), this, SLOT(collapseItem(QTreeWidgetItem *))); + connect(this, SIGNAL(itemClicked(QTreeWidgetItem *, int)), this, SLOT(expandItem(QTreeWidgetItem *)) ); connect(NotifyQt::getInstance(), SIGNAL(groupsChanged(int)), this, SLOT(groupsChanged())); connect(NotifyQt::getInstance(), SIGNAL(friendsChanged()), this, SLOT(insertPeers())); - connect(ui->actionHideOfflineFriends, SIGNAL(triggered(bool)), this, SLOT(setHideUnconnected(bool))); - connect(ui->actionShowState, SIGNAL(triggered(bool)), this, SLOT(setShowState(bool))); - connect(ui->actionShowGroups, SIGNAL(triggered(bool)), this, SLOT(setShowGroups(bool))); - connect(ui->actionExportFriendlist, SIGNAL(triggered()), this, SLOT(exportFriendlistClicked())); - connect(ui->actionImportFriendlist, SIGNAL(triggered()), this, SLOT(importFriendlistClicked())); - - connect(ui->filterLineEdit, SIGNAL(textChanged(QString)), this, SLOT(filterItems(QString))); - - ui->filterLineEdit->setPlaceholderText(tr("Search")) ; - ui->filterLineEdit->showFilterIcon(); +// connect(ui->actionHideOfflineFriends, SIGNAL(triggered(bool)), this, SLOT(setHideUnconnected(bool))); +// connect(ui->actionShowState, SIGNAL(triggered(bool)), this, SLOT(setShowState(bool))); +// connect(ui->actionShowGroups, SIGNAL(triggered(bool)), this, SLOT(setShowGroups(bool))); +// connect(ui->actionExportFriendlist, SIGNAL(triggered()), this, SLOT(exportFriendlistClicked())); +// connect(ui->actionImportFriendlist, SIGNAL(triggered()), this, SLOT(importFriendlistClicked())); +// connect(ui->filterLineEdit, SIGNAL(textChanged(QString)), this, SLOT(filterItems(QString))); +// +// ui->filterLineEdit->setPlaceholderText(tr("Search")) ; +// ui->filterLineEdit->showFilterIcon(); +// /* Add filter actions */ - QTreeWidgetItem *headerItem = ui->peerTreeWidget->headerItem(); + QTreeWidgetItem *headerItem = headerItem(); QString headerText = headerItem->text(COLUMN_NAME); ui->filterLineEdit->addFilter(QIcon(), headerText, COLUMN_NAME, QString("%1 %2").arg(tr("Search"), headerText)); ui->filterLineEdit->addFilter(QIcon(), tr("ID"), COLUMN_ID, tr("Search ID")); diff --git a/retroshare-gui/src/gui/common/NewFriendList.h b/retroshare-gui/src/gui/common/NewFriendList.h index f6d11fa9f..c0dc56edb 100644 --- a/retroshare-gui/src/gui/common/NewFriendList.h +++ b/retroshare-gui/src/gui/common/NewFriendList.h @@ -18,12 +18,12 @@ * * *******************************************************************************/ -#ifndef FRIENDLIST_H -#define FRIENDLIST_H +#pragma once #include #include +#include #include "retroshare/rsstatus.h" @@ -35,7 +35,7 @@ class RSTreeWidgetItemCompareRole; class QTreeWidgetItem; class QToolButton; -class NewFriendList : public QAbstractItemView +class NewFriendList : public QTreeView { Q_OBJECT @@ -159,5 +159,3 @@ private slots: void exportFriendlistClicked(); void importFriendlistClicked(); }; - -#endif // FRIENDLIST_H diff --git a/retroshare-gui/src/gui/common/StatusDefs.cpp b/retroshare-gui/src/gui/common/StatusDefs.cpp index f40949d17..5d0db8395 100644 --- a/retroshare-gui/src/gui/common/StatusDefs.cpp +++ b/retroshare-gui/src/gui/common/StatusDefs.cpp @@ -243,7 +243,7 @@ QString StatusDefs::connectStateWithoutTransportTypeString(RsPeerDetails &detail return stateString; } -QString StatusDefs::connectStateIpString(RsPeerDetails &details) +QString StatusDefs::connectStateIpString(const RsPeerDetails &details) { QString stateString = QString(""); diff --git a/retroshare-gui/src/gui/common/StatusDefs.h b/retroshare-gui/src/gui/common/StatusDefs.h index d06cbb1d9..b922e28e4 100644 --- a/retroshare-gui/src/gui/common/StatusDefs.h +++ b/retroshare-gui/src/gui/common/StatusDefs.h @@ -40,7 +40,7 @@ public: static QString peerStateString(int peerState); static QString connectStateString(RsPeerDetails &details); static QString connectStateWithoutTransportTypeString(RsPeerDetails &details); - static QString connectStateIpString(RsPeerDetails &details); + static QString connectStateIpString(const RsPeerDetails &details); }; #endif