removed groupsChanged and used rsEvents::FRIEND_LIST instead

This commit is contained in:
csoler 2025-06-12 21:12:47 +02:00
parent df02d745d8
commit 0ce2dd8486
19 changed files with 106 additions and 23 deletions

View file

@ -390,6 +390,8 @@ MainWindow::~MainWindow()
Settings->setValueToGroup("MainWindow", "SplitterState", ui->splitter->saveState()); Settings->setValueToGroup("MainWindow", "SplitterState", ui->splitter->saveState());
Settings->setValueToGroup("MainWindow", "State", saveState()); Settings->setValueToGroup("MainWindow", "State", saveState());
rsEvents->unregisterEventsHandler(mEventHandlerId);
delete statusComboBox; delete statusComboBox;
delete peerstatus; delete peerstatus;
delete natstatus; delete natstatus;

View file

@ -38,6 +38,7 @@
#include "gui/notifyqt.h" #include "gui/notifyqt.h"
#include "util/QtVersion.h" #include "util/QtVersion.h"
#include "util/misc.h" #include "util/misc.h"
#include "util/qtthreadsutils.h"
#include "gui/common/FilesDefs.h" #include "gui/common/FilesDefs.h"
/* Images for context menu icons */ /* Images for context menu icons */
@ -73,7 +74,23 @@ ShareManager::ShareManager()
connect(ui.shareddirList, SIGNAL(cellDoubleClicked(int,int)), this, SLOT(doubleClickedCell(int,int))); connect(ui.shareddirList, SIGNAL(cellDoubleClicked(int,int)), this, SLOT(doubleClickedCell(int,int)));
connect(ui.shareddirList, SIGNAL(cellChanged(int,int)), this, SLOT(handleCellChange(int,int))); connect(ui.shareddirList, SIGNAL(cellChanged(int,int)), this, SLOT(handleCellChange(int,int)));
connect(NotifyQt::getInstance(), SIGNAL(groupsChanged(int)), this, SLOT(reload())); // connect(NotifyQt::getInstance(), SIGNAL(groupsChanged(int)), this, SLOT(reload()));
mEventHandlerId = 0;
rsEvents->registerEventsHandler( [this](std::shared_ptr<const RsEvent> e)
{
RsQThreadUtils::postToObject([=]()
{
auto fe = dynamic_cast<const RsFriendListEvent*>(e.get());
if(!fe)
return;
reload();
}
, this );
}, mEventHandlerId, RsEventType::FRIEND_LIST );
QHeaderView* header = ui.shareddirList->horizontalHeader(); QHeaderView* header = ui.shareddirList->horizontalHeader();
QHeaderView_setSectionResizeModeColumn(header, COLUMN_PATH, QHeaderView::Stretch); QHeaderView_setSectionResizeModeColumn(header, COLUMN_PATH, QHeaderView::Stretch);
@ -152,6 +169,7 @@ ShareManager::~ShareManager()
{ {
_instance = NULL; _instance = NULL;
rsEvents->unregisterEventsHandler(mEventHandlerId);
Settings->saveWidgetInformation(this); Settings->saveWidgetInformation(this);
} }

View file

@ -77,6 +77,7 @@ private:
Ui::ShareManager ui; Ui::ShareManager ui;
std::vector<SharedDirInfo> mDirInfos ; std::vector<SharedDirInfo> mDirInfos ;
RsEventsHandlerId_t mEventHandlerId;
}; };
#endif #endif

View file

@ -101,8 +101,8 @@ FriendSelectionWidget::FriendSelectionWidget(QWidget *parent)
connect(ui->friendList, SIGNAL(itemSelectionChanged()), this, SIGNAL(itemSelectionChanged())); connect(ui->friendList, SIGNAL(itemSelectionChanged()), this, SIGNAL(itemSelectionChanged()));
connect(ui->filterLineEdit, SIGNAL(textChanged(QString)), this, SLOT(filterItems(QString))); connect(ui->filterLineEdit, SIGNAL(textChanged(QString)), this, SLOT(filterItems(QString)));
connect(NotifyQt::getInstance(), SIGNAL(groupsChanged(int)), this, SLOT(groupsChanged(int))); //connect(NotifyQt::getInstance(), SIGNAL(groupsChanged(int)), this, SLOT(groupsChanged(int)));
connect(NotifyQt::getInstance(), SIGNAL(peerStatusChanged(const QString&,int)), this, SLOT(peerStatusChanged(const QString&,int))); //connect(NotifyQt::getInstance(), SIGNAL(peerStatusChanged(const QString&,int)), this, SLOT(peerStatusChanged(const QString&,int)));
mCompareRole = new RSTreeWidgetItemCompareRole; mCompareRole = new RSTreeWidgetItemCompareRole;
mActionSortByState = new QAction(tr("Sort by state"), this); mActionSortByState = new QAction(tr("Sort by state"), this);
@ -159,7 +159,21 @@ void FriendSelectionWidget::handleEvent_main_thread(std::shared_ptr<const RsEven
updateDisplay(true); updateDisplay(true);
update(); // Qt flush update(); // Qt flush
break; break;
default: break ; case RsFriendListEventCode::GROUP_ADDED:
case RsFriendListEventCode::GROUP_REMOVED:
case RsFriendListEventCode::GROUP_CHANGED:
groupsChanged();
break;
case RsFriendListEventCode::NODE_STATUS_CHANGED:
{
StatusInfo i;
rsStatus->getStatus(fp->mSslId,i);
peerStatusChanged(fp->mSslId,i.status);
}
default:
break ;
} }
} }
@ -770,21 +784,18 @@ template<> inline void FriendSelectionWidget::setSelectedIds<RsGxsId,FriendSelec
loadIdentities(); loadIdentities();
} }
void FriendSelectionWidget::groupsChanged(int /*type*/) void FriendSelectionWidget::groupsChanged()
{ {
if (mShowTypes & SHOW_GROUP) { if (mShowTypes & SHOW_GROUP) {
fillList(); fillList();
} }
} }
void FriendSelectionWidget::peerStatusChanged(const QString& peerId, int status) void FriendSelectionWidget::peerStatusChanged(const RsPeerId& peerid, int status)
{ {
if(!isVisible()) if(!isVisible())
return ; return ;
if(RsAutoUpdatePage::eventsLocked())
return ;
RsPeerId peerid(peerId.toStdString()) ;
QString gpgId; QString gpgId;
int gpgStatus = RS_STATUS_OFFLINE; int gpgStatus = RS_STATUS_OFFLINE;
@ -850,7 +861,8 @@ void FriendSelectionWidget::peerStatusChanged(const QString& peerId, int status)
break; break;
case IDTYPE_SSL: case IDTYPE_SSL:
{ {
if (item->data(COLUMN_DATA, ROLE_ID).toString() == peerId) { if (RsPeerId(item->data(COLUMN_DATA, ROLE_ID).toString().toStdString()) == peerid)
{
if (status != (int) RS_STATUS_OFFLINE) { if (status != (int) RS_STATUS_OFFLINE) {
item->setData(COLUMN_NAME, Qt::ForegroundRole, textColorOnline()); item->setData(COLUMN_NAME, Qt::ForegroundRole, textColorOnline());
} else { } else {

View file

@ -137,8 +137,7 @@ public slots:
void filterConnected(bool filter); void filterConnected(bool filter);
private slots: private slots:
void groupsChanged(int type); void peerStatusChanged(const RsPeerId &peerid, int status);
void peerStatusChanged(const QString& peerId, int status);
void filterItems(const QString &text); void filterItems(const QString &text);
void contextMenuRequested(const QPoint &pos); void contextMenuRequested(const QPoint &pos);
void itemDoubleClicked(QTreeWidgetItem *item, int column); void itemDoubleClicked(QTreeWidgetItem *item, int column);
@ -147,6 +146,7 @@ private slots:
void deselectAll() ; void deselectAll() ;
private: private:
void groupsChanged();
void fillList(); void fillList();
void secured_fillList(); void secured_fillList();

View file

@ -24,6 +24,7 @@
#include "GroupSelectionBox.h" #include "GroupSelectionBox.h"
#include "GroupDefs.h" #include "GroupDefs.h"
#include "gui/notifyqt.h" #include "gui/notifyqt.h"
#include "util/qtthreadsutils.h"
#include <algorithm> #include <algorithm>
@ -34,11 +35,40 @@ GroupSelectionBox::GroupSelectionBox(QWidget *parent)
{ {
setSelectionMode(QAbstractItemView::SingleSelection); setSelectionMode(QAbstractItemView::SingleSelection);
connect(NotifyQt::getInstance(), SIGNAL(groupsChanged(int)), this, SLOT(fillGroups())); //connect(NotifyQt::getInstance(), SIGNAL(groupsChanged(int)), this, SLOT(fillGroups()));
mEventHandlerId = 0;
rsEvents->registerEventsHandler( [this](std::shared_ptr<const RsEvent> e)
{
RsQThreadUtils::postToObject([=]()
{
auto fe = dynamic_cast<const RsFriendListEvent*>(e.get());
if(!fe)
return;
switch(fe->mEventCode)
{
case RsFriendListEventCode::GROUP_ADDED:
case RsFriendListEventCode::GROUP_REMOVED:
case RsFriendListEventCode::GROUP_CHANGED: fillGroups();
default:
break;
}
}
, this );
}, mEventHandlerId, RsEventType::FRIEND_LIST );
// Fill with available groups // Fill with available groups
fillGroups(); fillGroups();
} }
GroupSelectionBox::~GroupSelectionBox()
{
rsEvents->unregisterEventsHandler(mEventHandlerId);
}
void GroupSelectionBox::fillGroups() void GroupSelectionBox::fillGroups()
{ {
std::list<RsNodeGroupId> selectedIds; std::list<RsNodeGroupId> selectedIds;

View file

@ -21,6 +21,7 @@
#include <QListWidget> #include <QListWidget>
#include <QDialog> #include <QDialog>
#include <retroshare/rsids.h> #include <retroshare/rsids.h>
#include <retroshare/rsevents.h>
class GroupSelectionBox: public QListWidget class GroupSelectionBox: public QListWidget
{ {
@ -28,6 +29,7 @@ class GroupSelectionBox: public QListWidget
public: public:
GroupSelectionBox(QWidget *parent); GroupSelectionBox(QWidget *parent);
virtual ~GroupSelectionBox();
static void selectGroups(const std::list<RsNodeGroupId>& default_groups) ; static void selectGroups(const std::list<RsNodeGroupId>& default_groups) ;
@ -38,6 +40,9 @@ public:
private slots: private slots:
void fillGroups(); void fillGroups();
private:
RsEventsHandlerId_t mEventHandlerId ;
}; };
class GroupSelectionDialog: public QDialog class GroupSelectionDialog: public QDialog

View file

@ -195,9 +195,9 @@ NewFriendList::NewFriendList(QWidget */*parent*/) : /* RsAutoUpdatePage(5000,par
ui->filterLineEdit->setPlaceholderText(tr("Search")) ; ui->filterLineEdit->setPlaceholderText(tr("Search")) ;
ui->filterLineEdit->showFilterIcon(); ui->filterLineEdit->showFilterIcon();
// mEventHandlerId_pssc=0; // forces initialization
mEventHandlerId_peer=0; // forces initialization mEventHandlerId_peer=0; // forces initialization
mEventHandlerId_gssp=0; // forces initialization mEventHandlerId_gssp=0; // forces initialization
mEventHandlerId_pssc=0; // forces initialization
// rsEvents->registerEventsHandler( [this](std::shared_ptr<const RsEvent> e) { handleEvent(e); }, mEventHandlerId_pssc, RsEventType::PEER_STATE_CHANGED ); // rsEvents->registerEventsHandler( [this](std::shared_ptr<const RsEvent> e) { handleEvent(e); }, mEventHandlerId_pssc, RsEventType::PEER_STATE_CHANGED );
rsEvents->registerEventsHandler( [this](std::shared_ptr<const RsEvent> e) { handleEvent(e); }, mEventHandlerId_peer, RsEventType::FRIEND_LIST ); rsEvents->registerEventsHandler( [this](std::shared_ptr<const RsEvent> e) { handleEvent(e); }, mEventHandlerId_peer, RsEventType::FRIEND_LIST );
@ -293,7 +293,7 @@ NewFriendList::~NewFriendList()
{ {
rsEvents->unregisterEventsHandler(mEventHandlerId_peer); rsEvents->unregisterEventsHandler(mEventHandlerId_peer);
rsEvents->unregisterEventsHandler(mEventHandlerId_gssp); rsEvents->unregisterEventsHandler(mEventHandlerId_gssp);
rsEvents->unregisterEventsHandler(mEventHandlerId_pssc); // rsEvents->unregisterEventsHandler(mEventHandlerId_pssc);
delete mModel; delete mModel;
delete mProxyModel; delete mProxyModel;

View file

@ -127,7 +127,7 @@ private:
bool mShowState; bool mShowState;
RsEventsHandlerId_t mEventHandlerId_peer; RsEventsHandlerId_t mEventHandlerId_peer;
RsEventsHandlerId_t mEventHandlerId_gssp; RsEventsHandlerId_t mEventHandlerId_gssp;
RsEventsHandlerId_t mEventHandlerId_pssc; // RsEventsHandlerId_t mEventHandlerId_pssc;
std::set<RsNodeGroupId> openGroups; std::set<RsNodeGroupId> openGroups;
std::set<RsPgpId> openPeers; std::set<RsPgpId> openPeers;

View file

@ -85,6 +85,10 @@ PeerItem::PeerItem(FeedHolder *parent, uint32_t feedId, const RsPeerId &peerId,
updateItem(); updateItem();
} }
PeerItem::~PeerItem()
{
rsEvents->unregisterEventsHandler(mEventHandlerId);
}
uint64_t PeerItem::uniqueIdentifier() const uint64_t PeerItem::uniqueIdentifier() const
{ {
return hash_64bits("PeerItem " + mPeerId.toStdString() + " " + QString::number(mType).toStdString()) ; return hash_64bits("PeerItem " + mPeerId.toStdString() + " " + QString::number(mType).toStdString()) ;

View file

@ -40,6 +40,7 @@ class PeerItem : public FeedItem, private Ui::PeerItem
public: public:
/** Default Constructor */ /** Default Constructor */
PeerItem(FeedHolder *parent, uint32_t feedId, const RsPeerId &peerId, uint32_t type, bool isHome); PeerItem(FeedHolder *parent, uint32_t feedId, const RsPeerId &peerId, uint32_t type, bool isHome);
virtual ~PeerItem();
void updateItemStatic(); void updateItemStatic();

View file

@ -99,6 +99,10 @@ SecurityItem::SecurityItem(FeedHolder *parent, uint32_t feedId, const RsPgpId &g
updateItem(); updateItem();
} }
SecurityItem::~SecurityItem()
{
rsEvents->unregisterEventsHandler(mEventHandlerId);
}
uint64_t SecurityItem::uniqueIdentifier() const uint64_t SecurityItem::uniqueIdentifier() const
{ {
return hash_64bits("SecurityItem " + QString::number(mType).toStdString() + " " + mSslId.toStdString()); return hash_64bits("SecurityItem " + QString::number(mType).toStdString() + " " + mSslId.toStdString());

View file

@ -39,6 +39,7 @@ class SecurityItem : public FeedItem, private Ui::SecurityItem
public: public:
/** Default Constructor */ /** Default Constructor */
SecurityItem(FeedHolder *parent, uint32_t feedId, const RsPgpId &gpgId, const RsPeerId &sslId, const std::string &sslCn, const std::string& ip_addr,uint32_t type, bool isHome); SecurityItem(FeedHolder *parent, uint32_t feedId, const RsPgpId &gpgId, const RsPeerId &sslId, const std::string &sslCn, const std::string& ip_addr,uint32_t type, bool isHome);
~SecurityItem();
void updateItemStatic(); void updateItemStatic();

View file

@ -53,7 +53,7 @@ RsGxsChannelPostsModel::RsGxsChannelPostsModel(QObject *parent)
RsGxsChannelPostsModel::~RsGxsChannelPostsModel() RsGxsChannelPostsModel::~RsGxsChannelPostsModel()
{ {
rsEvents->unregisterEventsHandler(mEventHandlerId); // rsEvents->unregisterEventsHandler(mEventHandlerId);
} }
void RsGxsChannelPostsModel::setMode(TreeMode mode) void RsGxsChannelPostsModel::setMode(TreeMode mode)

View file

@ -256,6 +256,6 @@ private:
QColor mTextColorNotSubscribed ; QColor mTextColorNotSubscribed ;
QColor mTextColorMissing ; QColor mTextColorMissing ;
RsEventsHandlerId_t mEventHandlerId ; //RsEventsHandlerId_t mEventHandlerId ;
friend class const_iterator; friend class const_iterator;
}; };

View file

@ -618,13 +618,14 @@ void NotifyQt::notifyListChange(int list, int type)
#endif #endif
emit lobbyListChanged(); emit lobbyListChanged();
break; break;
#ifdef TO_REMOVE
case NOTIFY_LIST_GROUPLIST: case NOTIFY_LIST_GROUPLIST:
#ifdef NOTIFY_DEBUG #ifdef NOTIFY_DEBUG
std::cerr << "received groups changed" << std::endl ; std::cerr << "received groups changed" << std::endl ;
#endif #endif
emit groupsChanged(type); emit groupsChanged(type);
break; break;
#endif
default: default:
break; break;
} }

View file

@ -126,7 +126,7 @@ class NotifyQt: public QObject, public NotifyClient
void peerStatusChangedSummary() const; void peerStatusChangedSummary() const;
void gxsChange(const RsGxsChanges& /* changes */); void gxsChange(const RsGxsChanges& /* changes */);
void chatMessageReceived(ChatMessage msg); void chatMessageReceived(ChatMessage msg);
void groupsChanged(int type) const ; // void groupsChanged(int type) const ;
void discInfoChanged() const ; void discInfoChanged() const ;
void historyChanged(uint msgId, int type); void historyChanged(uint msgId, int type);
void chatLobbyInviteReceived() ; void chatLobbyInviteReceived() ;

View file

@ -85,7 +85,6 @@ ServerPage::ServerPage(QWidget * parent, Qt::WindowFlags flags)
, manager(NULL), mOngoingConnectivityCheck(-1) , manager(NULL), mOngoingConnectivityCheck(-1)
, mIsHiddenNode(false), mHiddenType(RS_HIDDEN_TYPE_NONE) , mIsHiddenNode(false), mHiddenType(RS_HIDDEN_TYPE_NONE)
, mSamAccessible(false) , mSamAccessible(false)
, mEventHandlerId(0)
{ {
/* Invoke the Qt Designer generated object setup routine */ /* Invoke the Qt Designer generated object setup routine */
ui.setupUi(this); ui.setupUi(this);
@ -262,10 +261,15 @@ ServerPage::ServerPage(QWidget * parent, Qt::WindowFlags flags)
if (ui.tabWidget->currentIndex() == TAB_HIDDEN_SERVICE) if (ui.tabWidget->currentIndex() == TAB_HIDDEN_SERVICE)
updateOutProxyIndicator(); updateOutProxyIndicator();
mEventHandlerId = 0;
rsEvents->registerEventsHandler( [this](std::shared_ptr<const RsEvent> event) { handleEvent(event); }, mEventHandlerId, RsEventType::NETWORK ); rsEvents->registerEventsHandler( [this](std::shared_ptr<const RsEvent> event) { handleEvent(event); }, mEventHandlerId, RsEventType::NETWORK );
} }
ServerPage::~ServerPage()
{
rsEvents->unregisterEventsHandler(mEventHandlerId);
}
void ServerPage::handleEvent(std::shared_ptr<const RsEvent> e) void ServerPage::handleEvent(std::shared_ptr<const RsEvent> e)
{ {
if(e->mType != RsEventType::NETWORK) if(e->mType != RsEventType::NETWORK)

View file

@ -53,7 +53,7 @@ class ServerPage: public ConfigPage, public autoProxyCallback
public: public:
ServerPage(QWidget * parent = 0, Qt::WindowFlags flags = 0); ServerPage(QWidget * parent = 0, Qt::WindowFlags flags = 0);
~ServerPage() {} ~ServerPage() ;
/** Loads the settings for this page */ /** Loads the settings for this page */
virtual void load(); virtual void load();