mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-12-28 00:49:28 -05:00
show best icon for not expanded profiles in friend list
This commit is contained in:
parent
15e6947b07
commit
81e9cd1c51
@ -45,7 +45,7 @@ void AvatarDefs::getOwnAvatar(QPixmap &avatar, const QString& defaultImage)
|
|||||||
|
|
||||||
free(data);
|
free(data);
|
||||||
}
|
}
|
||||||
void AvatarDefs::getAvatarFromSslId(const RsPeerId& sslId, QPixmap &avatar, const QString& defaultImage)
|
bool AvatarDefs::getAvatarFromSslId(const RsPeerId& sslId, QPixmap &avatar, const QString& defaultImage)
|
||||||
{
|
{
|
||||||
unsigned char *data = NULL;
|
unsigned char *data = NULL;
|
||||||
int size = 0;
|
int size = 0;
|
||||||
@ -54,15 +54,16 @@ void AvatarDefs::getAvatarFromSslId(const RsPeerId& sslId, QPixmap &avatar, cons
|
|||||||
rsMsgs->getAvatarData(RsPeerId(sslId), data, size);
|
rsMsgs->getAvatarData(RsPeerId(sslId), data, size);
|
||||||
if (size == 0) {
|
if (size == 0) {
|
||||||
avatar = QPixmap(defaultImage);
|
avatar = QPixmap(defaultImage);
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* load image */
|
/* load image */
|
||||||
GxsIdDetails::loadPixmapFromData(data, size, avatar, GxsIdDetails::LARGE) ;
|
GxsIdDetails::loadPixmapFromData(data, size, avatar, GxsIdDetails::LARGE) ;
|
||||||
|
|
||||||
free(data);
|
free(data);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
void AvatarDefs::getAvatarFromGxsId(const RsGxsId& gxsId, QPixmap &avatar, const QString& defaultImage)
|
bool AvatarDefs::getAvatarFromGxsId(const RsGxsId& gxsId, QPixmap &avatar, const QString& defaultImage)
|
||||||
{
|
{
|
||||||
//int size = 0;
|
//int size = 0;
|
||||||
|
|
||||||
@ -72,16 +73,18 @@ void AvatarDefs::getAvatarFromGxsId(const RsGxsId& gxsId, QPixmap &avatar, const
|
|||||||
if(!rsIdentity->getIdDetails(gxsId, details))
|
if(!rsIdentity->getIdDetails(gxsId, details))
|
||||||
{
|
{
|
||||||
avatar = QPixmap(defaultImage);
|
avatar = QPixmap(defaultImage);
|
||||||
return ;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* load image */
|
/* load image */
|
||||||
|
|
||||||
if(details.mAvatar.mSize == 0 || !GxsIdDetails::loadPixmapFromData(details.mAvatar.mData, details.mAvatar.mSize, avatar,GxsIdDetails::LARGE))
|
if(details.mAvatar.mSize == 0 || !GxsIdDetails::loadPixmapFromData(details.mAvatar.mData, details.mAvatar.mSize, avatar,GxsIdDetails::LARGE))
|
||||||
avatar = GxsIdDetails::makeDefaultIcon(gxsId,GxsIdDetails::LARGE);
|
avatar = GxsIdDetails::makeDefaultIcon(gxsId,GxsIdDetails::LARGE);
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AvatarDefs::getAvatarFromGpgId(const RsPgpId& gpgId, QPixmap &avatar, const QString& defaultImage)
|
bool AvatarDefs::getAvatarFromGpgId(const RsPgpId& gpgId, QPixmap &avatar, const QString& defaultImage)
|
||||||
{
|
{
|
||||||
unsigned char *data = NULL;
|
unsigned char *data = NULL;
|
||||||
int size = 0;
|
int size = 0;
|
||||||
@ -105,11 +108,13 @@ void AvatarDefs::getAvatarFromGpgId(const RsPgpId& gpgId, QPixmap &avatar, const
|
|||||||
|
|
||||||
if (size == 0) {
|
if (size == 0) {
|
||||||
avatar = QPixmap(defaultImage);
|
avatar = QPixmap(defaultImage);
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* load image */
|
/* load image */
|
||||||
GxsIdDetails::loadPixmapFromData(data, size, avatar);
|
GxsIdDetails::loadPixmapFromData(data, size, avatar);
|
||||||
|
|
||||||
free(data);
|
free(data);
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -35,9 +35,9 @@ class AvatarDefs
|
|||||||
public:
|
public:
|
||||||
static void getOwnAvatar(QPixmap &avatar, const QString& defaultImage = AVATAR_DEFAULT_IMAGE);
|
static void getOwnAvatar(QPixmap &avatar, const QString& defaultImage = AVATAR_DEFAULT_IMAGE);
|
||||||
|
|
||||||
static void getAvatarFromSslId(const RsPeerId& sslId, QPixmap &avatar, const QString& defaultImage = AVATAR_DEFAULT_IMAGE);
|
static bool getAvatarFromSslId(const RsPeerId& sslId, QPixmap &avatar, const QString& defaultImage = AVATAR_DEFAULT_IMAGE);
|
||||||
static void getAvatarFromGpgId(const RsPgpId & gpgId, QPixmap &avatar, const QString& defaultImage = AVATAR_DEFAULT_IMAGE);
|
static bool getAvatarFromGpgId(const RsPgpId & gpgId, QPixmap &avatar, const QString& defaultImage = AVATAR_DEFAULT_IMAGE);
|
||||||
static void getAvatarFromGxsId(const RsGxsId & gxsId, QPixmap &avatar, const QString& defaultImage = AVATAR_DEFAULT_IMAGE);
|
static bool getAvatarFromGxsId(const RsGxsId & gxsId, QPixmap &avatar, const QString& defaultImage = AVATAR_DEFAULT_IMAGE);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -491,16 +491,19 @@ QVariant RsFriendListModel::sizeHintRole(const EntryIndex& e,int col) const
|
|||||||
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))
|
||||||
|
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)
|
||||||
{
|
{
|
||||||
default:
|
default:
|
||||||
case COLUMN_THREAD_NAME: return QVariant( QSize(x_factor * 170, y_factor*14*1.2f ));
|
case COLUMN_THREAD_NAME: return QVariant( QSize(x_factor * 170, y_factor*14*1.1f ));
|
||||||
case COLUMN_THREAD_IP: return QVariant( QSize(x_factor * 75 , y_factor*14*1.2f ));
|
case COLUMN_THREAD_IP: return QVariant( QSize(x_factor * 75 , y_factor*14*1.1f ));
|
||||||
case COLUMN_THREAD_ID: return QVariant( QSize(x_factor * 75 , y_factor*14*1.2f ));
|
case COLUMN_THREAD_ID: return QVariant( QSize(x_factor * 75 , y_factor*14*1.1f ));
|
||||||
case COLUMN_THREAD_LAST_CONTACT: return QVariant( QSize(x_factor * 75 , y_factor*14*1.2f ));
|
case COLUMN_THREAD_LAST_CONTACT: return QVariant( QSize(x_factor * 75 , y_factor*14*1.1f ));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -812,6 +815,24 @@ QVariant RsFriendListModel::decorationRole(const EntryIndex& entry,int col) cons
|
|||||||
{
|
{
|
||||||
case ENTRY_TYPE_GROUP: return QVariant(QIcon(IMAGE_GROUP24));
|
case ENTRY_TYPE_GROUP: return QVariant(QIcon(IMAGE_GROUP24));
|
||||||
|
|
||||||
|
case ENTRY_TYPE_PROFILE:
|
||||||
|
{
|
||||||
|
if(!isProfileExpanded(entry))
|
||||||
|
{
|
||||||
|
QPixmap sslAvatar;
|
||||||
|
|
||||||
|
const HierarchicalProfileInformation *hn = getProfileInfo(entry);
|
||||||
|
|
||||||
|
for(uint32_t i=0;i<hn->child_node_indices.size();++i)
|
||||||
|
if(AvatarDefs::getAvatarFromSslId(RsPeerId(mLocations[hn->child_node_indices[i]].node_info.id.toStdString()), sslAvatar))
|
||||||
|
return QVariant(QIcon(sslAvatar));
|
||||||
|
|
||||||
|
return QVariant(QIcon(sslAvatar));
|
||||||
|
}
|
||||||
|
|
||||||
|
return QVariant();
|
||||||
|
}
|
||||||
|
|
||||||
case ENTRY_TYPE_NODE:
|
case ENTRY_TYPE_NODE:
|
||||||
{
|
{
|
||||||
const HierarchicalNodeInformation *hn = getNodeInfo(entry);
|
const HierarchicalNodeInformation *hn = getNodeInfo(entry);
|
||||||
@ -1131,4 +1152,69 @@ QModelIndex RsFriendListModel::getIndexOfGroup(const RsNodeGroupId& mid) const
|
|||||||
return QModelIndex();
|
return QModelIndex();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RsFriendListModel::collapseItem(const QModelIndex& index)
|
||||||
|
{
|
||||||
|
if(getType(index) != ENTRY_TYPE_PROFILE)
|
||||||
|
return;
|
||||||
|
|
||||||
|
EntryIndex entry;
|
||||||
|
|
||||||
|
if(!convertInternalIdToIndex<sizeof(uintptr_t)>(index.internalId(),entry))
|
||||||
|
return;
|
||||||
|
|
||||||
|
const HierarchicalProfileInformation *hp = getProfileInfo(entry);
|
||||||
|
const HierarchicalGroupInformation *hg = getGroupInfo(entry);
|
||||||
|
|
||||||
|
std::string s ;
|
||||||
|
|
||||||
|
if(hg) s += hg->group_info.id.toStdString() ;
|
||||||
|
if(hp) s += hp->profile_info.gpg_id.toStdString();
|
||||||
|
|
||||||
|
if(!s.empty())
|
||||||
|
mExpandedProfiles.erase(s);
|
||||||
|
|
||||||
|
// apparently we cannot be subtle here.
|
||||||
|
emit dataChanged(createIndex(0,0,(void*)NULL), createIndex(mTopLevel.size()-1,COLUMN_THREAD_NB_COLUMNS-1,(void*)NULL));
|
||||||
|
}
|
||||||
|
|
||||||
|
void RsFriendListModel::expandItem(const QModelIndex& index)
|
||||||
|
{
|
||||||
|
if(getType(index) != ENTRY_TYPE_PROFILE)
|
||||||
|
return;
|
||||||
|
|
||||||
|
EntryIndex entry;
|
||||||
|
|
||||||
|
if(!convertInternalIdToIndex<sizeof(uintptr_t)>(index.internalId(),entry))
|
||||||
|
return;
|
||||||
|
|
||||||
|
const HierarchicalProfileInformation *hp = getProfileInfo(entry);
|
||||||
|
const HierarchicalGroupInformation *hg = getGroupInfo(entry);
|
||||||
|
|
||||||
|
std::string s ;
|
||||||
|
|
||||||
|
if(hg) s += hg->group_info.id.toStdString() ;
|
||||||
|
if(hp) s += hp->profile_info.gpg_id.toStdString();
|
||||||
|
|
||||||
|
if(!s.empty())
|
||||||
|
mExpandedProfiles.insert(s);
|
||||||
|
|
||||||
|
// apparently we cannot be subtle here.
|
||||||
|
emit dataChanged(createIndex(0,0,(void*)NULL), createIndex(mTopLevel.size()-1,COLUMN_THREAD_NB_COLUMNS-1,(void*)NULL));
|
||||||
|
}
|
||||||
|
|
||||||
|
bool RsFriendListModel::isProfileExpanded(const EntryIndex& e) const
|
||||||
|
{
|
||||||
|
if(e.type != ENTRY_TYPE_PROFILE)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
const HierarchicalProfileInformation *hp = getProfileInfo(e);
|
||||||
|
const HierarchicalGroupInformation *hg = getGroupInfo(e);
|
||||||
|
|
||||||
|
std::string s ;
|
||||||
|
|
||||||
|
if(hg) s += hg->group_info.id.toStdString() ;
|
||||||
|
if(hp) s += hp->profile_info.gpg_id.toStdString();
|
||||||
|
|
||||||
|
return mExpandedProfiles.find(s) != mExpandedProfiles.end();
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -129,6 +129,9 @@ public:
|
|||||||
|
|
||||||
void setFilter(FilterType filter_type, const QStringList& strings) ;
|
void setFilter(FilterType filter_type, const QStringList& strings) ;
|
||||||
|
|
||||||
|
void expandItem(const QModelIndex&) ;
|
||||||
|
void collapseItem(const QModelIndex&) ;
|
||||||
|
|
||||||
// Overloaded methods from QAbstractItemModel
|
// Overloaded methods from QAbstractItemModel
|
||||||
|
|
||||||
int rowCount(const QModelIndex& parent = QModelIndex()) const override;
|
int rowCount(const QModelIndex& parent = QModelIndex()) const override;
|
||||||
@ -153,6 +156,7 @@ private:
|
|||||||
const HierarchicalProfileInformation *getProfileInfo(const EntryIndex&)const;
|
const HierarchicalProfileInformation *getProfileInfo(const EntryIndex&)const;
|
||||||
const HierarchicalNodeInformation *getNodeInfo(const EntryIndex&) const;
|
const HierarchicalNodeInformation *getNodeInfo(const EntryIndex&) const;
|
||||||
|
|
||||||
|
bool isProfileExpanded(const EntryIndex& e) const;
|
||||||
void checkNode(HierarchicalNodeInformation& node);
|
void checkNode(HierarchicalNodeInformation& node);
|
||||||
bool getPeerOnlineStatus(const EntryIndex& e) const;
|
bool getPeerOnlineStatus(const EntryIndex& e) const;
|
||||||
std::map<RsPgpId,uint32_t>::const_iterator checkProfileIndex(const RsPgpId& pgp_id,
|
std::map<RsPgpId,uint32_t>::const_iterator checkProfileIndex(const RsPgpId& pgp_id,
|
||||||
@ -223,5 +227,9 @@ private:
|
|||||||
// group it belows to.
|
// group it belows to.
|
||||||
|
|
||||||
std::vector<EntryIndex> mTopLevel;
|
std::vector<EntryIndex> mTopLevel;
|
||||||
|
|
||||||
|
// keeps track of expanded/collapsed items, so as to only show icon for collapsed profiles
|
||||||
|
|
||||||
|
std::set<std::string> mExpandedProfiles;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -211,6 +211,9 @@ NewFriendList::NewFriendList(QWidget *parent) : /* RsAutoUpdatePage(5000,parent)
|
|||||||
h->setContextMenuPolicy(Qt::CustomContextMenu);
|
h->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||||
|
|
||||||
connect(ui->peerTreeWidget->header(),SIGNAL(sortIndicatorChanged(int,Qt::SortOrder)), this, SLOT(sortColumn(int,Qt::SortOrder)));
|
connect(ui->peerTreeWidget->header(),SIGNAL(sortIndicatorChanged(int,Qt::SortOrder)), this, SLOT(sortColumn(int,Qt::SortOrder)));
|
||||||
|
|
||||||
|
connect(ui->peerTreeWidget, SIGNAL(expanded(const QModelIndex&)), this, SLOT(itemExpanded(const QModelIndex&)));
|
||||||
|
connect(ui->peerTreeWidget, SIGNAL(collapsed(const QModelIndex&)), this, SLOT(itemCollapsed(const QModelIndex&)));
|
||||||
connect(mActionSortByState, SIGNAL(toggled(bool)), this, SLOT(toggleSortByState(bool)));
|
connect(mActionSortByState, SIGNAL(toggled(bool)), this, SLOT(toggleSortByState(bool)));
|
||||||
connect(ui->peerTreeWidget, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(peerTreeWidgetCustomPopupMenu()));
|
connect(ui->peerTreeWidget, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(peerTreeWidgetCustomPopupMenu()));
|
||||||
|
|
||||||
@ -241,6 +244,15 @@ NewFriendList::~NewFriendList()
|
|||||||
delete ui;
|
delete ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void NewFriendList::itemExpanded(const QModelIndex& index)
|
||||||
|
{
|
||||||
|
mModel->expandItem(mProxyModel->mapToSource(index));
|
||||||
|
}
|
||||||
|
void NewFriendList::itemCollapsed(const QModelIndex& index)
|
||||||
|
{
|
||||||
|
mModel->collapseItem(mProxyModel->mapToSource(index));
|
||||||
|
}
|
||||||
|
|
||||||
void NewFriendList::sortColumn(int col,Qt::SortOrder so)
|
void NewFriendList::sortColumn(int col,Qt::SortOrder so)
|
||||||
{
|
{
|
||||||
std::set<QString> expanded_indexes;
|
std::set<QString> expanded_indexes;
|
||||||
|
@ -90,6 +90,8 @@ public slots:
|
|||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void sortColumn(int col,Qt::SortOrder so);
|
void sortColumn(int col,Qt::SortOrder so);
|
||||||
|
void itemExpanded(const QModelIndex&);
|
||||||
|
void itemCollapsed(const QModelIndex&);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void changeEvent(QEvent *e);
|
void changeEvent(QEvent *e);
|
||||||
|
Loading…
Reference in New Issue
Block a user