moved notifyChatStatus to rsEvents

This commit is contained in:
csoler 2025-08-17 17:34:46 +02:00
parent e6bd8335dc
commit 798775e12b
11 changed files with 101 additions and 58 deletions

View file

@ -349,22 +349,6 @@ MainWindow::MainWindow(QWidget* parent, Qt::WindowFlags flags)
// connect(NotifyQt::getInstance(), SIGNAL(peerStatusChanged(QString,int)), this, SLOT(updateFriends()));
// connect(NotifyQt::getInstance(), SIGNAL(friendsChanged()), this, SLOT(updateFriends()));
mEventHandlerId = 0;
rsEvents->registerEventsHandler( [this](std::shared_ptr<const RsEvent> e)
{
RsQThreadUtils::postToObject([=]()
{
auto fe = dynamic_cast<const RsFriendListEvent*>(e.get());
if(!fe)
return;
updateFriends();
}
, this );
}, mEventHandlerId, RsEventType::FRIEND_LIST );
loadOwnStatus();
/* Set focus to the current page */
@ -383,6 +367,24 @@ MainWindow::MainWindow(QWidget* parent, Qt::WindowFlags flags)
mFontSizeHandler.registerFontSize(ui->listWidget, 1.5f);
mEventHandlerId_friends = 0;
rsEvents->registerEventsHandler( [this](std::shared_ptr<const RsEvent> e)
{
RsQThreadUtils::postToObject([=]()
{
auto fe = dynamic_cast<const RsFriendListEvent*>(e.get());
if(!fe)
return;
updateFriends();
}
, this );
}, mEventHandlerId_friends, RsEventType::FRIEND_LIST );
mEventHandlerId_system = 0;
rsEvents->registerEventsHandler( [this](std::shared_ptr<const RsEvent> event)
{
RsQThreadUtils::postToObject([=](){
@ -391,19 +393,22 @@ MainWindow::MainWindow(QWidget* parent, Qt::WindowFlags flags)
switch(ev->mEventCode)
{
case RsSystemErrorEventCode::TIME_SHIFT_PROBLEM:
std::cerr << "Time shift problem notification. Ignored." << std::endl;
std::cerr << "Time shift problem notification. Make sure your machine is on time, because it will break chat rooms." << std::endl;
break;
case RsSystemErrorEventCode::DISK_SPACE_ERROR:
displayDiskSpaceWarning(ev->mDiskErrorLocation,ev->mDiskErrorSizeLimit);
break;
case RsSystemErrorEventCode::GENERAL_ERROR:
displayErrorMessage(0,0,QString::fromUtf8(ev->mErrorMsg.c_str()));
break;
default:
break;
}
}, this );
}, mEventHandlerId, RsEventType::SYSTEM_ERROR );
}, mEventHandlerId_system, RsEventType::SYSTEM_ERROR );
}
@ -415,7 +420,8 @@ MainWindow::~MainWindow()
Settings->setValueToGroup("MainWindow", "SplitterState", ui->splitter->saveState());
Settings->setValueToGroup("MainWindow", "State", saveState());
rsEvents->unregisterEventsHandler(mEventHandlerId);
rsEvents->unregisterEventsHandler(mEventHandlerId_friends);
rsEvents->unregisterEventsHandler(mEventHandlerId_system);
delete statusComboBox;
delete peerstatus;

View file

@ -379,7 +379,8 @@ private:
Ui::MainWindow *ui ;
RsEventsHandlerId_t mEventHandlerId;
RsEventsHandlerId_t mEventHandlerId_friends;
RsEventsHandlerId_t mEventHandlerId_system;
};
#endif

View file

@ -28,6 +28,7 @@
#include <algorithm>
#include "gui/elastic/elnode.h"
#include "util/qtthreadsutils.h"
/********
* #define DEBUG_NETWORKVIEW
@ -60,12 +61,32 @@ NetworkView::NetworkView(QWidget *parent)
connect( ui.nameBox, SIGNAL(textChanged(QString)), this, SLOT(setNameSearch(QString)));
_should_update = true ;
rsEvents->registerEventsHandler( [this](std::shared_ptr<const RsEvent> event)
{
RsQThreadUtils::postToObject([=](){
auto ev = dynamic_cast<const RsGossipDiscoveryEvent *>(event.get());
if(!ev) return;
switch(ev->mGossipDiscoveryEventType)
{
case RsGossipDiscoveryEventType::DISCOVERY_INFO_RECEIVED: update();
[[fallthrough]];
default:
break;
}
}, this );
}, mEventHandlerId, RsEventType::GOSSIP_DISCOVERY );
}
NetworkView::~NetworkView()
{
if(mScene != NULL)
delete mScene ;
rsEvents->unregisterEventsHandler(mEventHandlerId);
if(mScene != NULL)
delete mScene ;
}
void NetworkView::setEdgeLength(int l)

View file

@ -24,6 +24,7 @@
#include <QGraphicsScene>
#include <retroshare/rstypes.h>
#include <retroshare/rsevents.h>
#include <retroshare-gui/RsAutoUpdatePage.h>
#include "ui_NetworkView.h"
@ -65,6 +66,7 @@ class NetworkView : public RsAutoUpdatePage
std::map<RsPgpId,GraphWidget::NodeId> _node_ids ;
bool _should_update ;
RsEventsHandlerId_t mEventHandlerId;
};
#endif

View file

@ -34,6 +34,7 @@
#include "gui/chat/ChatLobbyDialog.h"
#include "gui/gxs/GxsIdDetails.h"
#include "util/misc.h"
#include "util/qtthreadsutils.h"
#include "util/HandleRichText.h"
#include "gui/chat/ChatUserNotify.h"//For BradCast
#include "util/DateTime.h"
@ -181,15 +182,25 @@ ChatWidget::ChatWidget(QWidget *parent)
RsQThreadUtils::postToObject([=](){
auto fe = dynamic_cast<const RsFriendListEvent*>(e.get());
if(!fe || fe->mEventCode != RsFriendListEventCode::NODE_STATUS_CHANGED)
if(!fe)
return;
updateStatus(QString::fromStdString(fe->mSslId.toStdString()),fe->mStatus);
switch(fe->mEventCode)
{
case RsFriendListEventCode::NODE_STATUS_CHANGED: updateStatus(QString::fromStdString(fe->mSslId.toStdString()),fe->mStatus);
break;
case RsFriendListEventCode::NODE_STATE_STRING_CHANGED: updatePeersCustomStateString(ChatId(fe->mSslId),QString::fromUtf8(fe->mStateString.c_str()));
break;
default:
break;
}
}, this );
},mEventHandlerId,RsEventType::FRIEND_LIST);
connect(NotifyQt::getInstance(), SIGNAL(peerHasNewCustomStateString(const QString&, const QString&)), this, SLOT(updatePeersCustomStateString(const QString&, const QString&)));
//connect(NotifyQt::getInstance(), SIGNAL(peerHasNewCustomStateString(const QString&, const QString&)), this, SLOT(updatePeersCustomStateString(const QString&, const QString&)));
connect(NotifyQt::getInstance(), SIGNAL(chatFontChanged()), this, SLOT(resetFonts()));
connect(ui->textBrowser, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(contextMenuTextBrowser(QPoint)));
@ -390,7 +401,7 @@ void ChatWidget::init(const ChatId &chat_id, const QString &title)
// initialize first custom state string
QString customStateString = QString::fromUtf8(rsMsgs->getCustomStateString(chatId.toPeerId()).c_str());
updatePeersCustomStateString(QString::fromStdString(chatId.toPeerId().toStdString()), customStateString);
updatePeersCustomStateString(chatId, customStateString);
} else if (chatType() == CHATTYPE_DISTANT){
hist_chat_type = RS_HISTORY_TYPE_DISTANT ;
messageCount = Settings->getDistantChatHistoryCount();
@ -1925,7 +1936,7 @@ void ChatWidget::updateTitle()
ui->titleLabel->setText(RsHtml::plainText(name) + "@" + RsHtml::plainText(title));
}
void ChatWidget::updatePeersCustomStateString(const QString& peer_id, const QString& status_string)
void ChatWidget::updatePeersCustomStateString(const ChatId& id, const QString& status_string)
{
if (chatType() != CHATTYPE_PRIVATE )
{
@ -1934,7 +1945,7 @@ void ChatWidget::updatePeersCustomStateString(const QString& peer_id, const QStr
QString status_text;
if (RsPeerId(peer_id.toStdString()) == chatId.toPeerId()) {
if (id.toPeerId() == chatId.toPeerId()) {
// the peers status string has changed
if (status_string.isEmpty()) {
ui->statusMessageLabel->hide();

View file

@ -190,7 +190,7 @@ private slots:
void updateLenOfChatTextEdit();
void sendChat();
void updatePeersCustomStateString(const QString& peer_id, const QString& status_string) ;
void updatePeersCustomStateString(const ChatId& id, const QString& status_string) ;
bool fileSave();
bool fileSaveAs();

View file

@ -50,7 +50,7 @@ PopupChatDialog::PopupChatDialog(QWidget *parent, Qt::WindowFlags flags)
connect(ui.avatarFrameButton, SIGNAL(toggled(bool)), this, SLOT(showAvatarFrame(bool)));
connect(ui.actionClearOfflineMessages, SIGNAL(triggered()), this, SLOT(clearOfflineMessages()));
connect(NotifyQt::getInstance(), SIGNAL(chatStatusChanged(ChatId,QString)), this, SLOT(chatStatusChanged(ChatId,QString)));
//connect(NotifyQt::getInstance(), SIGNAL(chatStatusChanged(ChatId,QString)), this, SLOT(chatStatusChanged(ChatId,QString)));
}
void PopupChatDialog::init(const ChatId &chat_id, const QString &title)

View file

@ -855,7 +855,14 @@ void ConnectFriendWizard::accept()
ConnectProgressDialog::showProgress(ssl_id);
}
NotifyQt::getInstance()->notifyListChange(NOTIFY_LIST_NEIGHBOURS,1) ;
//NotifyQt::getInstance()->notifyListChange(NOTIFY_LIST_NEIGHBOURS,1) ;
auto ev = std::make_shared<RsFriendListEvent>();
ev->mEventCode = RsFriendListEventCode::NODE_ADDED;
ev->mSslId = peerDetails.id;
ev->mPgpId = peerDetails.gpg_id;
rsEvents->postEvent(ev);
QDialog::accept();
}

View file

@ -102,11 +102,13 @@ NotifyQt::NotifyQt() : cDialog(NULL)
_enabled = false ;
}
#ifdef TO_REMOVE
// register to allow sending over Qt::QueuedConnection
qRegisterMetaType<ChatId>("ChatId");
qRegisterMetaType<ChatMessage>("ChatMessage");
qRegisterMetaType<RsGxsChanges>("RsGxsChanges");
qRegisterMetaType<RsGxsId>("RsGxsId");
#endif
}
#ifdef TO_REMOVE
@ -307,6 +309,7 @@ bool NotifyQt::askForPluginConfirmation(const std::string& plugin_file_name, con
return false;
}
#ifdef TO_REMOVE
void NotifyQt::notifyDiscInfoChanged()
{
{
@ -322,7 +325,6 @@ void NotifyQt::notifyDiscInfoChanged()
emit discInfoChanged() ;
}
#ifdef TO_REMOVE
void NotifyQt::notifyDiskFull(uint32_t loc,uint32_t size_in_mb)
{
{
@ -394,7 +396,6 @@ void NotifyQt::notifyPeerHasNewAvatar(std::string peer_id)
#endif
emit peerHasNewAvatar(QString::fromStdString(peer_id)) ;
}
#endif
void NotifyQt::notifyCustomState(const std::string& peer_id, const std::string& status_string)
{
@ -410,7 +411,6 @@ void NotifyQt::notifyCustomState(const std::string& peer_id, const std::string&
emit peerHasNewCustomStateString(QString::fromStdString(peer_id), QString::fromUtf8(status_string.c_str())) ;
}
#ifdef TO_REMOVE
void NotifyQt::notifyChatLobbyTimeShift(int shift)
{
{
@ -453,7 +453,6 @@ void NotifyQt::notifyChatLobbyEvent(uint64_t lobby_id,uint32_t event_type,const
#endif
emit chatLobbyEvent(lobby_id,event_type,nickname,QString::fromUtf8(str.c_str())) ;
}
#endif
void NotifyQt::notifyChatStatus(const ChatId& chat_id,const std::string& status_string)
{
@ -488,7 +487,6 @@ void NotifyQt::notifyChatCleared(const ChatId& chat_id)
// std::cerr << "(EE) missing code to handle GXS turtle search result." << std::endl;
//}
#ifdef TO_REMOVE
// Mai 2023: distant turtle search now uses RsEvents.
void NotifyQt::notifyTurtleSearchResult(const RsPeerId& pid,uint32_t search_id,const std::list<TurtleFileInfo>& files)
{
@ -528,6 +526,7 @@ void NotifyQt::notifyHistoryChanged(uint32_t msgId, int type)
emit historyChanged(msgId, type);
}
#ifdef TO_REMOVE
void NotifyQt::notifyListChange(int list, int type)
{
{
@ -540,7 +539,6 @@ void NotifyQt::notifyListChange(int list, int type)
#endif
switch(list)
{
#ifdef TO_REMOVE
case NOTIFY_LIST_NEIGHBOURS:
#ifdef NOTIFY_DEBUG
std::cerr << "received neighbours changed" << std::endl ;
@ -614,7 +612,6 @@ void NotifyQt::notifyListChange(int list, int type)
#endif
emit privateChatChanged(list, type);
break;
#endif
case NOTIFY_LIST_CHAT_LOBBY_LIST:
#ifdef NOTIFY_DEBUG
@ -622,21 +619,18 @@ void NotifyQt::notifyListChange(int list, int type)
#endif
emit lobbyListChanged();
break;
#ifdef TO_REMOVE
case NOTIFY_LIST_GROUPLIST:
#ifdef NOTIFY_DEBUG
std::cerr << "received groups changed" << std::endl ;
#endif
emit groupsChanged(type);
break;
#endif
default:
break;
}
return;
}
#ifdef TO_REMOVE
void NotifyQt::notifyListPreChange(int list, int /*type*/)
{
{
@ -1233,6 +1227,7 @@ void NotifyQt::addToaster(uint notifyFlags, const std::string& id, const std::st
}
toaster = new ToasterItem(new ChatToaster(RsPeerId(id), QString::fromUtf8(msg.c_str())));
}
break;
case RS_POPUP_GROUPCHAT:
#ifdef RS_DIRECT_CHAT
if ((popupflags & RS_POPUP_GROUPCHAT) && !_disableAllToaster)

View file

@ -58,15 +58,15 @@ class NotifyQt: public QObject, public NotifyClient
virtual ~NotifyQt() = default;
void setNetworkDialog(NetworkDialog *c) { cDialog = c; }
// void setNetworkDialog(NetworkDialog *c) { cDialog = c; }
// virtual void notifyListPreChange(int list, int type);
virtual void notifyListChange(int list, int type);
// virtual void notifyListChange(int list, int type);
// virtual void notifyErrorMsg(int list, int sev, std::string msg);
// virtual void notifyChatMessage(const ChatMessage& /* msg */);
virtual void notifyChatStatus(const ChatId &chat_id,const std::string& status_string);
virtual void notifyChatCleared(const ChatId &chat_id);
virtual void notifyCustomState(const std::string& peer_id, const std::string& status_string);
// virtual void notifyChatStatus(const ChatId &chat_id,const std::string& status_string);
// virtual void notifyChatCleared(const ChatId &chat_id);
// virtual void notifyCustomState(const std::string& peer_id, const std::string& status_string);
//#ifdef TO_REMOVE
// virtual void notifyTurtleSearchResult(const RsPeerId &pid, uint32_t search_id, const std::list<TurtleFileInfo>& found_files);
//#endif
@ -85,7 +85,7 @@ class NotifyQt: public QObject, public NotifyClient
virtual void notifyHistoryChanged(uint32_t msgId, int type);
virtual void notifyDiscInfoChanged() ;
// virtual void notifyDiscInfoChanged() ;
virtual bool askForPassword(const std::string& title, const std::string& key_details, bool prev_is_bad, std::string& password, bool &cancelled);
virtual bool askForPluginConfirmation(const std::string& plugin_filename, const std::string& plugin_file_hash,bool first_time);
@ -109,25 +109,25 @@ class NotifyQt: public QObject, public NotifyClient
// void filesPostModChanged(bool) const ;
// void transfersChanged() const ;
// void friendsChanged() const ;
void lobbyListChanged() const ;
// void chatLobbyEvent(qulonglong,int,const RsGxsId&,const QString&) ;
// void lobbyListChanged() const ;
// void chatLobbyEvent(qulonglong,int,const RsGxsId&,const QString&) ;
// void neighboursChanged() const ;
void configChanged() const ;
void logInfoChanged(const QString&) const ;
void chatStatusChanged(const ChatId&,const QString&) const ;
// void chatStatusChanged(const ChatId&,const QString&) const ;
void chatCleared(const ChatId&) const ;
void peerHasNewCustomStateString(const QString& /* peer_id */, const QString& /* status_string */) const ;
// void peerHasNewCustomStateString(const QString& /* peer_id */, const QString& /* status_string */) const ;
// void peerHasNewAvatar(const QString& peer_id) const ;
// void ownAvatarChanged() const ;
// void ownStatusMessageChanged() const ;
void errorOccurred(int,int,const QString&) const ;
void diskFull(int,int) const ;
// void errorOccurred(int,int,const QString&) const ;
// void diskFull(int,int) const ;
// void peerStatusChanged(const QString& /* peer_id */, int /* status */);
// void peerStatusChangedSummary() const;
void gxsChange(const RsGxsChanges& /* changes */);
// void gxsChange(const RsGxsChanges& /* changes */);
// void chatMessageReceived(ChatMessage msg);
// void groupsChanged(int type) const ;
void discInfoChanged() const ;
// void discInfoChanged() const ;
void historyChanged(uint msgId, int type);
// void chatLobbyInviteReceived() ;
// void deferredSignatureHandlingRequested() ;

View file

@ -734,12 +734,12 @@ feenableexcept(FE_INVALID | FE_DIVBYZERO);
QObject::connect(notify,SIGNAL(publicChatChanged(int)) ,w->friendsDialog ,SLOT(publicChatChanged(int) ));
// QObject::connect(notify,SIGNAL(neighboursChanged()) ,w->friendsDialog->networkDialog ,SLOT(securedUpdateDisplay())) ;
QObject::connect(notify,SIGNAL(chatStatusChanged(const QString&,const QString&,bool)),w->friendsDialog,SLOT(updatePeerStatusString(const QString&,const QString&,bool)));
// QObject::connect(notify,SIGNAL(chatStatusChanged(const QString&,const QString&,bool)),w->friendsDialog,SLOT(updatePeerStatusString(const QString&,const QString&,bool)));
// QObject::connect(notify,SIGNAL(ownStatusMessageChanged()),w->friendsDialog,SLOT(loadmypersonalstatus()));
// QObject::connect(notify,SIGNAL(logInfoChanged(const QString&)) ,w->friendsDialog->networkDialog,SLOT(setLogInfo(QString))) ;
QObject::connect(notify,SIGNAL(discInfoChanged()) ,w->friendsDialog->networkView,SLOT(update()),Qt::QueuedConnection) ;
QObject::connect(notify,SIGNAL(errorOccurred(int,int,const QString&)),w,SLOT(displayErrorMessage(int,int,const QString&))) ;
// QObject::connect(notify,SIGNAL(discInfoChanged()) ,w->friendsDialog->networkView,SLOT(update()),Qt::QueuedConnection) ;
// QObject::connect(notify,SIGNAL(errorOccurred(int,int,const QString&)),w,SLOT(displayErrorMessage(int,int,const QString&))) ;
w->installGroupChatNotifier();