swiched some of the chat room notify to RsEvent and added new event code for SYSTEM errors

This commit is contained in:
csoler 2025-06-25 16:49:26 +02:00
parent 41d972b359
commit 4b9d060c81
8 changed files with 85 additions and 27 deletions

View file

@ -35,6 +35,7 @@
#include "settings/rsharesettings.h" #include "settings/rsharesettings.h"
#include "util/HandleRichText.h" #include "util/HandleRichText.h"
#include "util/misc.h" #include "util/misc.h"
#include "util/qtthreadsutils.h"
#include "util/QtVersion.h" #include "util/QtVersion.h"
#include "retroshare/rsmsgs.h" #include "retroshare/rsmsgs.h"
@ -105,9 +106,39 @@ ChatLobbyWidget::ChatLobbyWidget(QWidget *parent, Qt::WindowFlags flags)
myInviteYesButton = NULL; myInviteYesButton = NULL;
myInviteIdChooser = NULL; myInviteIdChooser = NULL;
QObject::connect( NotifyQt::getInstance(), SIGNAL(lobbyListChanged()), SLOT(lobbyChanged())); //QObject::connect( NotifyQt::getInstance(), SIGNAL(lobbyListChanged()), SLOT(lobbyChanged()));
QObject::connect( NotifyQt::getInstance(), SIGNAL(chatLobbyEvent(qulonglong,int,RsGxsId,QString)), this, SLOT(displayChatLobbyEvent(qulonglong,int,RsGxsId,QString))); //QObject::connect( NotifyQt::getInstance(), SIGNAL(chatLobbyEvent(qulonglong,int,RsGxsId,QString)), this, SLOT(displayChatLobbyEvent(qulonglong,int,RsGxsId,QString)));
QObject::connect( NotifyQt::getInstance(), SIGNAL(chatLobbyInviteReceived()), this, SLOT(readChatLobbyInvites())); //QObject::connect( NotifyQt::getInstance(), SIGNAL(chatLobbyInviteReceived()), this, SLOT(readChatLobbyInvites()));
rsEvents->registerEventsHandler( [this](std::shared_ptr<const RsEvent> event)
{
RsQThreadUtils::postToObject([=](){
auto ev = dynamic_cast<const RsChatStatusEvent *>(event.get());
switch(ev->mEventCode)
{
case RsChatStatusEventCode::CHAT_LOBBY_INVITE_RECEIVED:
readChatLobbyInvites();
break;
case RsChatStatusEventCode::CHAT_LOBBY_LIST_CHANGED:
lobbyChanged();
break;
case RsChatStatusEventCode::CHAT_LOBBY_EVENT_PEER_LEFT:
case RsChatStatusEventCode::CHAT_LOBBY_EVENT_PEER_STATUS:
case RsChatStatusEventCode::CHAT_LOBBY_EVENT_PEER_JOINED:
case RsChatStatusEventCode::CHAT_LOBBY_EVENT_PEER_CHANGE_NICKNAME:
case RsChatStatusEventCode::CHAT_LOBBY_EVENT_KEEP_ALIVE:
handleChatLobbyEvent(ev->mLobbyId,ev->mEventCode,ev->mGxsId,QString::fromUtf8(ev->str.c_str()));
break;
default:
break;
}
}, this );
}, mEventHandlerId, RsEventType::CHAT_SERVICE );
QObject::connect( ui.lobbyTreeWidget, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(lobbyTreeWidgetCustomPopupMenu(QPoint))); QObject::connect( ui.lobbyTreeWidget, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(lobbyTreeWidgetCustomPopupMenu(QPoint)));
QObject::connect( ui.lobbyTreeWidget, SIGNAL(itemDoubleClicked(QTreeWidgetItem*,int)), this, SLOT(itemDoubleClicked(QTreeWidgetItem*,int))); QObject::connect( ui.lobbyTreeWidget, SIGNAL(itemDoubleClicked(QTreeWidgetItem*,int)), this, SLOT(itemDoubleClicked(QTreeWidgetItem*,int)));
@ -236,6 +267,7 @@ ChatLobbyWidget::ChatLobbyWidget(QWidget *parent, Qt::WindowFlags flags)
ChatLobbyWidget::~ChatLobbyWidget() ChatLobbyWidget::~ChatLobbyWidget()
{ {
rsEvents->unregisterEventsHandler(mEventHandlerId);
// save settings // save settings
processSettings(false); processSettings(false);
@ -1158,10 +1190,10 @@ void ChatLobbyWidget::itemDoubleClicked(QTreeWidgetItem *item, int /*column*/)
subscribeChatLobbyAtItem(item); subscribeChatLobbyAtItem(item);
} }
void ChatLobbyWidget::displayChatLobbyEvent(qulonglong lobby_id, int event_type, const RsGxsId &gxs_id, const QString& str) void ChatLobbyWidget::handleChatLobbyEvent(uint64_t lobby_id, RsChatStatusEventCode event_type, const RsGxsId &gxs_id, const QString& str)
{ {
if (ChatLobbyDialog *cld = dynamic_cast<ChatLobbyDialog*>(ChatDialog::getExistingChat(ChatId(lobby_id)))) { if (ChatLobbyDialog *cld = dynamic_cast<ChatLobbyDialog*>(ChatDialog::getExistingChat(ChatId(lobby_id)))) {
cld->displayLobbyEvent(event_type, gxs_id, str); cld->handleLobbyEvent(event_type, gxs_id, str);
} }
} }

View file

@ -89,7 +89,7 @@ protected slots:
void unsubscribeItem(); void unsubscribeItem();
void itemDoubleClicked(QTreeWidgetItem *item, int column); void itemDoubleClicked(QTreeWidgetItem *item, int column);
void updateCurrentLobby() ; void updateCurrentLobby() ;
void displayChatLobbyEvent(qulonglong lobby_id, int event_type, const RsGxsId& gxs_id, const QString& str); void handleChatLobbyEvent(uint64_t lobby_id, RsChatStatusEventCode event_type, const RsGxsId &gxs_id, const QString& str);
void readChatLobbyInvites(); void readChatLobbyInvites();
void showLobby(QTreeWidgetItem *lobby_item) ; void showLobby(QTreeWidgetItem *lobby_item) ;
void showBlankPage(ChatLobbyId id, bool subscribed = false) ; void showBlankPage(ChatLobbyId id, bool subscribed = false) ;
@ -151,5 +151,7 @@ private:
/* UI - from Designer */ /* UI - from Designer */
Ui::ChatLobbyWidget ui; Ui::ChatLobbyWidget ui;
RsEventsHandlerId_t mEventHandlerId;
}; };

View file

@ -32,6 +32,7 @@
#include "retroshare/rsplugin.h" #include "retroshare/rsplugin.h"
#include "retroshare/rsconfig.h" #include "retroshare/rsconfig.h"
#include "retroshare/rsevents.h"
#include "util/argstream.h" #include "util/argstream.h"
#include "util/qtthreadsutils.h" #include "util/qtthreadsutils.h"
@ -380,6 +381,29 @@ MainWindow::MainWindow(QWidget* parent, Qt::WindowFlags flags)
settingsChanged(); settingsChanged();
mFontSizeHandler.registerFontSize(ui->listWidget, 1.5f); mFontSizeHandler.registerFontSize(ui->listWidget, 1.5f);
rsEvents->registerEventsHandler( [this](std::shared_ptr<const RsEvent> event)
{
RsQThreadUtils::postToObject([=](){
auto ev = dynamic_cast<const RsSystemErrorEvent *>(event.get());
switch(ev->mEventCode)
{
case RsSystemErrorEventCode::TIME_SHIFT_PROBLEM:
std::cerr << "Time shift problem notification. Ignored." << std::endl;
break;
case RsSystemErrorEventCode::DISK_SPACE_ERROR:
displayDiskSpaceWarning(ev->mDiskErrorLocation,ev->mDiskErrorSizeLimit);
break;
default:
break;
}
}, this );
}, mEventHandlerId, RsEventType::SYSTEM_ERROR );
} }
/** Destructor. */ /** Destructor. */

View file

@ -846,7 +846,7 @@ QString ChatLobbyDialog::getParticipantName(const RsGxsId& gxs_id) const
} }
void ChatLobbyDialog::displayLobbyEvent(int event_type, const RsGxsId& gxs_id, const QString& str) void ChatLobbyDialog::handleLobbyEvent(RsChatStatusEventCode event_type, const RsGxsId& gxs_id, const QString& str)
{ {
RsGxsId qsParticipant; RsGxsId qsParticipant;
@ -854,17 +854,17 @@ void ChatLobbyDialog::displayLobbyEvent(int event_type, const RsGxsId& gxs_id, c
switch (event_type) switch (event_type)
{ {
case RS_CHAT_LOBBY_EVENT_PEER_LEFT: case RsChatStatusEventCode::CHAT_LOBBY_EVENT_PEER_LEFT:
qsParticipant=gxs_id; qsParticipant=gxs_id;
ui.chatWidget->addChatMsg(true, tr("Chat room management"), QDateTime::currentDateTime(), QDateTime::currentDateTime(), tr("%1 has left the room.").arg(RsHtml::plainText(name)), ChatWidget::MSGTYPE_SYSTEM); ui.chatWidget->addChatMsg(true, tr("Chat room management"), QDateTime::currentDateTime(), QDateTime::currentDateTime(), tr("%1 has left the room.").arg(RsHtml::plainText(name)), ChatWidget::MSGTYPE_SYSTEM);
emit peerLeft(id()) ; emit peerLeft(id()) ;
break; break;
case RS_CHAT_LOBBY_EVENT_PEER_JOINED: case RsChatStatusEventCode::CHAT_LOBBY_EVENT_PEER_JOINED:
qsParticipant=gxs_id; qsParticipant=gxs_id;
ui.chatWidget->addChatMsg(true, tr("Chat room management"), QDateTime::currentDateTime(), QDateTime::currentDateTime(), tr("%1 joined the room.").arg(RsHtml::plainText(name)), ChatWidget::MSGTYPE_SYSTEM); ui.chatWidget->addChatMsg(true, tr("Chat room management"), QDateTime::currentDateTime(), QDateTime::currentDateTime(), tr("%1 joined the room.").arg(RsHtml::plainText(name)), ChatWidget::MSGTYPE_SYSTEM);
emit peerJoined(id()) ; emit peerJoined(id()) ;
break; break;
case RS_CHAT_LOBBY_EVENT_PEER_STATUS: case RsChatStatusEventCode::CHAT_LOBBY_EVENT_PEER_STATUS:
{ {
qsParticipant=gxs_id; qsParticipant=gxs_id;
@ -876,7 +876,7 @@ void ChatLobbyDialog::displayLobbyEvent(int event_type, const RsGxsId& gxs_id, c
} }
break; break;
case RS_CHAT_LOBBY_EVENT_PEER_CHANGE_NICKNAME: case RsChatStatusEventCode::CHAT_LOBBY_EVENT_PEER_CHANGE_NICKNAME:
{ {
qsParticipant=gxs_id; qsParticipant=gxs_id;
@ -892,11 +892,11 @@ void ChatLobbyDialog::displayLobbyEvent(int event_type, const RsGxsId& gxs_id, c
muteParticipant(RsGxsId(str.toStdString())) ; muteParticipant(RsGxsId(str.toStdString())) ;
} }
break; break;
case RS_CHAT_LOBBY_EVENT_KEEP_ALIVE: case RsChatStatusEventCode::CHAT_LOBBY_EVENT_KEEP_ALIVE:
//std::cerr << "Received keep alive packet from " << nickname.toStdString() << " in chat room " << getPeerId() << std::endl; //std::cerr << "Received keep alive packet from " << nickname.toStdString() << " in chat room " << getPeerId() << std::endl;
break; break;
default: default:
std::cerr << "ChatLobbyDialog::displayLobbyEvent() Unhandled chat room event type " << event_type << std::endl; std::cerr << "ChatLobbyDialog::handledLobbyEvent() Unhandled chat room event type " << (int)event_type << std::endl;
} }
if (!qsParticipant.isNull()) if (!qsParticipant.isNull())

View file

@ -42,7 +42,7 @@ class ChatLobbyDialog: public ChatDialog
friend class ChatDialog; friend class ChatDialog;
public: public:
void displayLobbyEvent(int event_type, const RsGxsId &gxs_id, const QString& str); void handleLobbyEvent(RsChatStatusEventCode event_type, const RsGxsId& gxs_id, const QString& str);
virtual void showDialog(uint chatflags); virtual void showDialog(uint chatflags);
virtual ChatWidget *getChatWidget(); virtual ChatWidget *getChatWidget();

View file

@ -320,6 +320,7 @@ void NotifyQt::notifyDiscInfoChanged()
emit discInfoChanged() ; emit discInfoChanged() ;
} }
#ifdef TO_REMOVE
void NotifyQt::notifyDiskFull(uint32_t loc,uint32_t size_in_mb) void NotifyQt::notifyDiskFull(uint32_t loc,uint32_t size_in_mb)
{ {
{ {
@ -333,7 +334,6 @@ void NotifyQt::notifyDiskFull(uint32_t loc,uint32_t size_in_mb)
emit diskFull(loc,size_in_mb) ; emit diskFull(loc,size_in_mb) ;
} }
#ifdef TO_REMOVE
/* peer has changed the state */ /* peer has changed the state */
void NotifyQt::notifyPeerStatusChanged(const std::string& peer_id, uint32_t state) void NotifyQt::notifyPeerStatusChanged(const std::string& peer_id, uint32_t state)
{ {
@ -408,6 +408,7 @@ void NotifyQt::notifyCustomState(const std::string& peer_id, const std::string&
emit peerHasNewCustomStateString(QString::fromStdString(peer_id), QString::fromUtf8(status_string.c_str())) ; emit peerHasNewCustomStateString(QString::fromStdString(peer_id), QString::fromUtf8(status_string.c_str())) ;
} }
#ifdef TO_REMOVE
void NotifyQt::notifyChatLobbyTimeShift(int shift) void NotifyQt::notifyChatLobbyTimeShift(int shift)
{ {
{ {
@ -450,6 +451,7 @@ void NotifyQt::notifyChatLobbyEvent(uint64_t lobby_id,uint32_t event_type,const
#endif #endif
emit chatLobbyEvent(lobby_id,event_type,nickname,QString::fromUtf8(str.c_str())) ; 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) void NotifyQt::notifyChatStatus(const ChatId& chat_id,const std::string& status_string)
{ {
@ -561,7 +563,6 @@ void NotifyQt::notifyListChange(int list, int type)
#endif #endif
emit filesPostModChanged(false) ; /* Local */ emit filesPostModChanged(false) ; /* Local */
break; break;
#endif
case NOTIFY_LIST_CHAT_LOBBY_INVITATION: case NOTIFY_LIST_CHAT_LOBBY_INVITATION:
#ifdef NOTIFY_DEBUG #ifdef NOTIFY_DEBUG
std::cerr << "received files changed" << std::endl ; std::cerr << "received files changed" << std::endl ;
@ -575,7 +576,6 @@ void NotifyQt::notifyListChange(int list, int type)
emit configChanged() ; emit configChanged() ;
break ; break ;
#ifdef REMOVE
case NOTIFY_LIST_SEARCHLIST: case NOTIFY_LIST_SEARCHLIST:
break; break;
case NOTIFY_LIST_CHANNELLIST: case NOTIFY_LIST_CHANNELLIST:

View file

@ -73,11 +73,11 @@ class NotifyQt: public QObject, public NotifyClient
// virtual void notifyTurtleSearchResult(uint32_t search_id,const std::list<TurtleGxsInfo>& found_groups); // virtual void notifyTurtleSearchResult(uint32_t search_id,const std::list<TurtleGxsInfo>& found_groups);
virtual void notifyPeerHasNewAvatar(std::string peer_id) ; virtual void notifyPeerHasNewAvatar(std::string peer_id) ;
virtual void notifyOwnAvatarChanged() ; virtual void notifyOwnAvatarChanged() ;
virtual void notifyChatLobbyEvent(uint64_t /* lobby id */, uint32_t /* event type */, const RsGxsId & /*nickname*/, const std::string& /* any string */) ; // virtual void notifyChatLobbyEvent(uint64_t /* lobby id */, uint32_t /* event type */, const RsGxsId & /*nickname*/, const std::string& /* any string */) ;
virtual void notifyChatLobbyTimeShift(int time_shift) ; // virtual void notifyChatLobbyTimeShift(int time_shift) ;
virtual void notifyOwnStatusMessageChanged() ; virtual void notifyOwnStatusMessageChanged() ;
virtual void notifyDiskFull(uint32_t loc,uint32_t size_in_mb) ; // virtual void notifyDiskFull(uint32_t loc,uint32_t size_in_mb) ;
/* peer has changed the state */ /* peer has changed the state */
// virtual void notifyPeerStatusChanged(const std::string& peer_id, uint32_t state); // virtual void notifyPeerStatusChanged(const std::string& peer_id, uint32_t state);
/* one or more peers has changed the states */ /* one or more peers has changed the states */
@ -110,7 +110,7 @@ class NotifyQt: public QObject, public NotifyClient
// void transfersChanged() const ; // void transfersChanged() const ;
// void friendsChanged() const ; // void friendsChanged() const ;
void lobbyListChanged() const ; void lobbyListChanged() const ;
void chatLobbyEvent(qulonglong,int,const RsGxsId&,const QString&) ; // void chatLobbyEvent(qulonglong,int,const RsGxsId&,const QString&) ;
// void neighboursChanged() const ; // void neighboursChanged() const ;
void configChanged() const ; void configChanged() const ;
void logInfoChanged(const QString&) const ; void logInfoChanged(const QString&) const ;
@ -129,9 +129,9 @@ class NotifyQt: public QObject, public NotifyClient
// 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() ;
// void deferredSignatureHandlingRequested() ; // void deferredSignatureHandlingRequested() ;
void chatLobbyTimeShift(int time_shift) ; // void chatLobbyTimeShift(int time_shift) ;
void connectionWithoutCert(); void connectionWithoutCert();
/* Notify from GUI */ /* Notify from GUI */
@ -147,7 +147,7 @@ class NotifyQt: public QObject, public NotifyClient
private slots: private slots:
void runningTick(); void runningTick();
void handleSignatureEvent() ; void handleSignatureEvent() ;
void handleChatLobbyTimeShift(int) ; // void handleChatLobbyTimeShift(int) ;
private: private:
NotifyQt(); NotifyQt();

View file

@ -726,8 +726,8 @@ feenableexcept(FE_INVALID | FE_DIVBYZERO);
std::cerr << "connecting signals and slots" << std::endl ; std::cerr << "connecting signals and slots" << std::endl ;
#endif #endif
// QObject::connect(notify,SIGNAL(deferredSignatureHandlingRequested()),notify,SLOT(handleSignatureEvent()),Qt::QueuedConnection) ; // QObject::connect(notify,SIGNAL(deferredSignatureHandlingRequested()),notify,SLOT(handleSignatureEvent()),Qt::QueuedConnection) ;
QObject::connect(notify,SIGNAL(chatLobbyTimeShift(int)),notify,SLOT(handleChatLobbyTimeShift(int)),Qt::QueuedConnection) ; // QObject::connect(notify,SIGNAL(chatLobbyTimeShift(int)),notify,SLOT(handleChatLobbyTimeShift(int)),Qt::QueuedConnection) ;
QObject::connect(notify,SIGNAL(diskFull(int,int)) ,w ,SLOT(displayDiskSpaceWarning(int,int))) ; // QObject::connect(notify,SIGNAL(diskFull(int,int)) ,w ,SLOT(displayDiskSpaceWarning(int,int))) ;
// QObject::connect(notify,SIGNAL(filesPostModChanged(bool)) ,w ,SLOT(postModDirectories(bool)) ,Qt::QueuedConnection ) ; // QObject::connect(notify,SIGNAL(filesPostModChanged(bool)) ,w ,SLOT(postModDirectories(bool)) ,Qt::QueuedConnection ) ;
// QObject::connect(notify,SIGNAL(transfersChanged()) ,w->transfersDialog ,SLOT(insertTransfers() )) ; // QObject::connect(notify,SIGNAL(transfersChanged()) ,w->transfersDialog ,SLOT(insertTransfers() )) ;
QObject::connect(notify,SIGNAL(publicChatChanged(int)) ,w->friendsDialog ,SLOT(publicChatChanged(int) )); QObject::connect(notify,SIGNAL(publicChatChanged(int)) ,w->friendsDialog ,SLOT(publicChatChanged(int) ));