Merge pull request #2862 from defnax/statusicons-settings

Added optional display status icon from friendslist context menu
This commit is contained in:
csoler 2024-07-07 20:10:52 +02:00 committed by GitHub
commit 64f4d84e74
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 166 additions and 8 deletions

View File

@ -54,7 +54,9 @@ bool AvatarDefs::getAvatarFromSslId(const RsPeerId& sslId, QPixmap &avatar, cons
/* get avatar */ /* get avatar */
rsMsgs->getAvatarData(RsPeerId(sslId), data, size); rsMsgs->getAvatarData(RsPeerId(sslId), data, size);
if (size == 0) { if (size == 0) {
avatar = FilesDefs::getPixmapFromQtResourcePath(defaultImage); if (!defaultImage.isEmpty()) {
avatar = FilesDefs::getPixmapFromQtResourcePath(defaultImage);
}
return false; return false;
} }

View File

@ -65,7 +65,7 @@ static const uint32_t NODE_DETAILS_UPDATE_DELAY = 5; // update each node every 5
RsFriendListModel::RsFriendListModel(QObject *parent) RsFriendListModel::RsFriendListModel(QObject *parent)
: QAbstractItemModel(parent) : QAbstractItemModel(parent)
, mDisplayGroups(true), mDisplayStatusString(true) , mDisplayGroups(true), mDisplayStatusString(true), mDisplayStatusIcon (false)
, mLastInternalDataUpdate(0), mLastNodeUpdate(0) , mLastInternalDataUpdate(0), mLastNodeUpdate(0)
{ {
mFilterStrings.clear(); mFilterStrings.clear();
@ -141,6 +141,24 @@ template<> bool RsFriendListModel::convertInternalIdToIndex<8>(quintptr ref,Entr
return true; return true;
} }
static QIcon createAvatar(const QPixmap &avatar, const QPixmap &overlay)
{
int avatarWidth = avatar.width();
int avatarHeight = avatar.height();
QPixmap pixmap(avatar);
int overlaySize = (avatarWidth > avatarHeight) ? (avatarWidth/2.5) : (avatarHeight/2.5);
int overlayX = avatarWidth - overlaySize;
int overlayY = avatarHeight - overlaySize;
QPainter painter(&pixmap);
painter.drawPixmap(overlayX, overlayY, overlaySize, overlaySize, overlay);
QIcon icon;
icon.addPixmap(pixmap);
return icon;
}
void RsFriendListModel::setDisplayStatusString(bool b) void RsFriendListModel::setDisplayStatusString(bool b)
{ {
@ -148,6 +166,12 @@ void RsFriendListModel::setDisplayStatusString(bool b)
postMods(); postMods();
} }
void RsFriendListModel::setDisplayStatusIcon(bool b)
{
mDisplayStatusIcon = b;
postMods();
}
void RsFriendListModel::setDisplayGroups(bool b) void RsFriendListModel::setDisplayGroups(bool b)
{ {
mDisplayGroups = b; mDisplayGroups = b;
@ -874,6 +898,69 @@ bool RsFriendListModel::getPeerOnlineStatus(const EntryIndex& e) const
return (noded && (noded->node_info.state & RS_PEER_STATE_CONNECTED)); return (noded && (noded->node_info.state & RS_PEER_STATE_CONNECTED));
} }
const RsFriendListModel::HierarchicalNodeInformation *RsFriendListModel::getBestNodeInformation(const HierarchicalProfileInformation *profileInfo, uint32_t *status) const
{
if (status) {
*status = RS_STATUS_OFFLINE;
}
if (!profileInfo) {
return NULL;
}
const RsFriendListModel::HierarchicalNodeInformation *bestNodeInformation = NULL;
int bestStatusIndex = 0;
/* Find the best status */
for (uint32_t i = 0; i < profileInfo->child_node_indices.size(); ++i) {
const RsFriendListModel::HierarchicalNodeInformation &nodeInformation = mLocations[profileInfo->child_node_indices[i]];
StatusInfo statusInfo;
rsStatus->getStatus(nodeInformation.node_info.id, statusInfo);
int statusIndex = 0;
switch (statusInfo.status) {
case RS_STATUS_OFFLINE:
statusIndex = 1;
break;
case RS_STATUS_INACTIVE:
statusIndex = 2;
break;
case RS_STATUS_AWAY:
statusIndex = 3;
break;
case RS_STATUS_BUSY:
statusIndex = 4;
break;
case RS_STATUS_ONLINE:
statusIndex = 5;
break;
default:
std::cerr << "FriendListModel: Unknown status " << statusInfo.status << std::endl;
}
if (bestStatusIndex == 0 || statusIndex > bestStatusIndex) {
/* first status or better status */
bestStatusIndex = statusIndex;
bestNodeInformation = &nodeInformation;
if (status) {
*status = statusInfo.status;
}
}
}
if (bestStatusIndex == 0) {
return NULL;
}
return bestNodeInformation;
}
QVariant RsFriendListModel::decorationRole(const EntryIndex& entry,int col) const QVariant RsFriendListModel::decorationRole(const EntryIndex& entry,int col) const
{ {
if(col > 0) if(col > 0)
@ -907,13 +994,42 @@ QVariant RsFriendListModel::decorationRole(const EntryIndex& entry,int col) cons
{ {
if(!isProfileExpanded(entry)) if(!isProfileExpanded(entry))
{ {
QPixmap sslAvatar = FilesDefs::getPixmapFromQtResourcePath(AVATAR_DEFAULT_IMAGE); QPixmap sslAvatar;
bool foundAvatar = false;
const HierarchicalProfileInformation *hn = getProfileInfo(entry); const HierarchicalProfileInformation *hn = getProfileInfo(entry);
uint32_t status = RS_STATUS_OFFLINE;
const HierarchicalNodeInformation *bestNodeInformation = NULL;
for(uint32_t i=0;i<hn->child_node_indices.size();++i) if (mDisplayStatusIcon) {
if(AvatarDefs::getAvatarFromSslId(RsPeerId(mLocations[hn->child_node_indices[i]].node_info.id.toStdString()), sslAvatar)) bestNodeInformation = getBestNodeInformation(hn, &status);
return QVariant(QIcon(sslAvatar)); if (bestNodeInformation) {
if (AvatarDefs::getAvatarFromSslId(RsPeerId(bestNodeInformation->node_info.id.toStdString()), sslAvatar, "")) {
/* Use avatar from best node */
foundAvatar = true;
}
}
}
if (!foundAvatar) {
/* Use first available avatar */
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, "")) {
foundAvatar = true;
break;
}
}
}
if (!foundAvatar || sslAvatar.isNull()) {
sslAvatar = FilesDefs::getPixmapFromQtResourcePath(AVATAR_DEFAULT_IMAGE);
}
if (mDisplayStatusIcon) {
if (bestNodeInformation) {
QPixmap sslOverlayIcon = FilesDefs::getPixmapFromQtResourcePath(StatusDefs::imageStatus(status));
return QVariant(QIcon(createAvatar(sslAvatar, sslOverlayIcon)));
}
}
return QVariant(QIcon(sslAvatar)); return QVariant(QIcon(sslAvatar));
} }
@ -930,6 +1046,10 @@ QVariant RsFriendListModel::decorationRole(const EntryIndex& entry,int col) cons
QPixmap sslAvatar; QPixmap sslAvatar;
AvatarDefs::getAvatarFromSslId(RsPeerId(hn->node_info.id.toStdString()), sslAvatar); AvatarDefs::getAvatarFromSslId(RsPeerId(hn->node_info.id.toStdString()), sslAvatar);
if (mDisplayStatusIcon) {
QPixmap sslOverlayIcon = FilesDefs::getPixmapFromQtResourcePath(StatusDefs::imageStatus(statusRole(entry, col).toInt()));
return QVariant(QIcon(createAvatar(sslAvatar, sslOverlayIcon)));
}
return QVariant(QIcon(sslAvatar)); return QVariant(QIcon(sslAvatar));
} }

View File

@ -129,6 +129,10 @@ public:
void setDisplayStatusString(bool b); void setDisplayStatusString(bool b);
bool getDisplayStatusString() const { return mDisplayStatusString; } bool getDisplayStatusString() const { return mDisplayStatusString; }
void setDisplayStatusIcon(bool b);
bool getDisplayStatusIcon() const { return mDisplayStatusIcon; }
EntryType getType(const QModelIndex&) const; EntryType getType(const QModelIndex&) const;
@ -219,11 +223,14 @@ private:
uint32_t updateFilterStatus(ForumModelIndex i,int column,const QStringList& strings); uint32_t updateFilterStatus(ForumModelIndex i,int column,const QStringList& strings);
const HierarchicalNodeInformation *getBestNodeInformation(const HierarchicalProfileInformation *profileInfo, uint32_t *status = NULL) const;
QStringList mFilterStrings; QStringList mFilterStrings;
FilterType mFilterType; FilterType mFilterType;
bool mDisplayGroups ; bool mDisplayGroups ;
bool mDisplayStatusString ; bool mDisplayStatusString ;
bool mDisplayStatusIcon ;
rstime_t mLastInternalDataUpdate; rstime_t mLastInternalDataUpdate;
rstime_t mLastNodeUpdate;; rstime_t mLastNodeUpdate;;

View File

@ -54,6 +54,7 @@
#include "gui/chat/ChatUserNotify.h" #include "gui/chat/ChatUserNotify.h"
#include "gui/connect/ConnectProgressDialog.h" #include "gui/connect/ConnectProgressDialog.h"
#include "gui/common/ElidedLabel.h" #include "gui/common/ElidedLabel.h"
#include "gui/notifyqt.h"
#include "NewFriendList.h" #include "NewFriendList.h"
#include "ui_NewFriendList.h" #include "ui_NewFriendList.h"
@ -202,6 +203,9 @@ NewFriendList::NewFriendList(QWidget */*parent*/) : /* RsAutoUpdatePage(5000,par
rsEvents->registerEventsHandler( [this](std::shared_ptr<const RsEvent> e) { handleEvent(e); }, mEventHandlerId_peer, RsEventType::PEER_CONNECTION ); rsEvents->registerEventsHandler( [this](std::shared_ptr<const RsEvent> e) { handleEvent(e); }, mEventHandlerId_peer, RsEventType::PEER_CONNECTION );
rsEvents->registerEventsHandler( [this](std::shared_ptr<const RsEvent> e) { handleEvent(e); }, mEventHandlerId_gssp, RsEventType::GOSSIP_DISCOVERY ); rsEvents->registerEventsHandler( [this](std::shared_ptr<const RsEvent> e) { handleEvent(e); }, mEventHandlerId_gssp, RsEventType::GOSSIP_DISCOVERY );
connect(NotifyQt::getInstance(), SIGNAL(peerHasNewAvatar(QString)), this, SLOT(forceUpdateDisplay()));
connect(NotifyQt::getInstance(), SIGNAL(peerStatusChanged(QString,int)), this, SLOT(forceUpdateDisplay()));
mModel = new RsFriendListModel(ui->peerTreeWidget); mModel = new RsFriendListModel(ui->peerTreeWidget);
mProxyModel = new FriendListSortFilterProxyModel(ui->peerTreeWidget->header(),this); mProxyModel = new FriendListSortFilterProxyModel(ui->peerTreeWidget->header(),this);
@ -261,6 +265,7 @@ NewFriendList::NewFriendList(QWidget */*parent*/) : /* RsAutoUpdatePage(5000,par
connect(ui->actionShowOfflineFriends, SIGNAL(triggered(bool)), this, SLOT(setShowUnconnected(bool))); connect(ui->actionShowOfflineFriends, SIGNAL(triggered(bool)), this, SLOT(setShowUnconnected(bool)));
connect(ui->actionShowState, SIGNAL(triggered(bool)), this, SLOT(setShowState(bool)) ); connect(ui->actionShowState, SIGNAL(triggered(bool)), this, SLOT(setShowState(bool)) );
connect(ui->actionShowStateIcon, SIGNAL(triggered(bool)), this, SLOT(setShowStateIcon(bool)) );
connect(ui->actionShowGroups, SIGNAL(triggered(bool)), this, SLOT(setShowGroups(bool)) ); connect(ui->actionShowGroups, SIGNAL(triggered(bool)), this, SLOT(setShowGroups(bool)) );
connect(ui->actionExportFriendlist, SIGNAL(triggered()) , this, SLOT(exportFriendlistClicked())); connect(ui->actionExportFriendlist, SIGNAL(triggered()) , this, SLOT(exportFriendlistClicked()));
connect(ui->actionImportFriendlist, SIGNAL(triggered()) , this, SLOT(importFriendlistClicked())); connect(ui->actionImportFriendlist, SIGNAL(triggered()) , this, SLOT(importFriendlistClicked()));
@ -341,10 +346,12 @@ void NewFriendList::headerContextMenuRequested(QPoint /*p*/)
displayMenu.addAction(ui->actionShowOfflineFriends); displayMenu.addAction(ui->actionShowOfflineFriends);
displayMenu.addAction(ui->actionShowState); displayMenu.addAction(ui->actionShowState);
displayMenu.addAction(ui->actionShowStateIcon);
displayMenu.addAction(ui->actionShowGroups); displayMenu.addAction(ui->actionShowGroups);
ui->actionShowOfflineFriends->setChecked(mProxyModel->showOfflineNodes()); ui->actionShowOfflineFriends->setChecked(mProxyModel->showOfflineNodes());
ui->actionShowState->setChecked(mModel->getDisplayStatusString()); ui->actionShowState->setChecked(mModel->getDisplayStatusString());
ui->actionShowStateIcon->setChecked(mModel->getDisplayStatusIcon());
ui->actionShowGroups->setChecked(mModel->getDisplayGroups()); ui->actionShowGroups->setChecked(mModel->getDisplayGroups());
QHeaderView *header = ui->peerTreeWidget->header(); QHeaderView *header = ui->peerTreeWidget->header();
@ -505,6 +512,8 @@ void NewFriendList::processSettings(bool load)
mModel->setDisplayStatusString(Settings->value("showState", mModel->getDisplayStatusString()).toBool()); mModel->setDisplayStatusString(Settings->value("showState", mModel->getDisplayStatusString()).toBool());
mModel->setDisplayGroups(Settings->value("showGroups", mModel->getDisplayGroups()).toBool()); mModel->setDisplayGroups(Settings->value("showGroups", mModel->getDisplayGroups()).toBool());
mModel->setDisplayStatusIcon(Settings->value("showStateIcon", mModel->getDisplayStatusIcon()).toBool());
setColumnVisible(RsFriendListModel::COLUMN_THREAD_IP,Settings->value("showIP", isColumnVisible(RsFriendListModel::COLUMN_THREAD_IP)).toBool()); setColumnVisible(RsFriendListModel::COLUMN_THREAD_IP,Settings->value("showIP", isColumnVisible(RsFriendListModel::COLUMN_THREAD_IP)).toBool());
setColumnVisible(RsFriendListModel::COLUMN_THREAD_ID,Settings->value("showID", isColumnVisible(RsFriendListModel::COLUMN_THREAD_ID)).toBool()); setColumnVisible(RsFriendListModel::COLUMN_THREAD_ID,Settings->value("showID", isColumnVisible(RsFriendListModel::COLUMN_THREAD_ID)).toBool());
@ -528,6 +537,8 @@ void NewFriendList::processSettings(bool load)
Settings->setValue("hideUnconnected", !mProxyModel->showOfflineNodes()); Settings->setValue("hideUnconnected", !mProxyModel->showOfflineNodes());
Settings->setValue("showState", mModel->getDisplayStatusString()); Settings->setValue("showState", mModel->getDisplayStatusString());
Settings->setValue("showGroups", mModel->getDisplayGroups()); Settings->setValue("showGroups", mModel->getDisplayGroups());
Settings->setValue("showStateIcon", mModel->getDisplayStatusIcon());
Settings->setValue("showIP",isColumnVisible(RsFriendListModel::COLUMN_THREAD_IP)); Settings->setValue("showIP",isColumnVisible(RsFriendListModel::COLUMN_THREAD_IP));
Settings->setValue("showID",isColumnVisible(RsFriendListModel::COLUMN_THREAD_ID)); Settings->setValue("showID",isColumnVisible(RsFriendListModel::COLUMN_THREAD_ID));
@ -1643,6 +1654,12 @@ void NewFriendList::setShowState(bool show)
processSettings(false); processSettings(false);
} }
void NewFriendList::setShowStateIcon(bool show)
{
applyWhileKeepingTree([show,this]() { mModel->setDisplayStatusIcon(show) ; });
processSettings(false);
}
void NewFriendList::setShowGroups(bool show) void NewFriendList::setShowGroups(bool show)
{ {
applyWhileKeepingTree([show,this]() { mModel->setDisplayGroups(show) ; }); applyWhileKeepingTree([show,this]() { mModel->setDisplayGroups(show) ; });

View File

@ -87,6 +87,7 @@ public slots:
void setShowGroups(bool show); void setShowGroups(bool show);
void setShowUnconnected(bool hidden); void setShowUnconnected(bool hidden);
void setShowState(bool show); void setShowState(bool show);
void setShowStateIcon(bool show);
void headerContextMenuRequested(QPoint); void headerContextMenuRequested(QPoint);
void exportFriendlistClicked(); void exportFriendlistClicked();

View File

@ -124,6 +124,17 @@
<string>import your friendlist including groups</string> <string>import your friendlist including groups</string>
</property> </property>
</action> </action>
<action name="actionShowStateIcon">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>Status icons</string>
</property>
<property name="toolTip">
<string>Show status icons</string>
</property>
</action>
</widget> </widget>
<customwidgets> <customwidgets>
<customwidget> <customwidget>

View File

@ -354,7 +354,7 @@ NewFriendList
qproperty-textColorStatusAway: gray; qproperty-textColorStatusAway: gray;
qproperty-textColorStatusBusy: darkred; qproperty-textColorStatusBusy: darkred;
qproperty-textColorStatusOnline: darkGreen; qproperty-textColorStatusOnline: darkGreen;
qproperty-textColorStatusInactive: #A0A040; qproperty-textColorStatusInactive: orange;
qproperty-textColorGroup: rgb(123, 123, 123); qproperty-textColorGroup: rgb(123, 123, 123);
} }