diff --git a/retroshare-gui/src/gui/ChatLobbyWidget.cpp b/retroshare-gui/src/gui/ChatLobbyWidget.cpp index 4caa97706..79a6664b3 100644 --- a/retroshare-gui/src/gui/ChatLobbyWidget.cpp +++ b/retroshare-gui/src/gui/ChatLobbyWidget.cpp @@ -35,6 +35,7 @@ #include "settings/rsharesettings.h" #include "util/HandleRichText.h" #include "util/misc.h" +#include "util/qtthreadsutils.h" #include "util/QtVersion.h" #include "retroshare/rsmsgs.h" @@ -105,9 +106,39 @@ ChatLobbyWidget::ChatLobbyWidget(QWidget *parent, Qt::WindowFlags flags) myInviteYesButton = NULL; myInviteIdChooser = NULL; - 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(chatLobbyInviteReceived()), this, SLOT(readChatLobbyInvites())); + //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(chatLobbyInviteReceived()), this, SLOT(readChatLobbyInvites())); + + rsEvents->registerEventsHandler( [this](std::shared_ptr event) + { + RsQThreadUtils::postToObject([=](){ + auto ev = dynamic_cast(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(itemDoubleClicked(QTreeWidgetItem*,int)), this, SLOT(itemDoubleClicked(QTreeWidgetItem*,int))); @@ -236,6 +267,7 @@ ChatLobbyWidget::ChatLobbyWidget(QWidget *parent, Qt::WindowFlags flags) ChatLobbyWidget::~ChatLobbyWidget() { + rsEvents->unregisterEventsHandler(mEventHandlerId); // save settings processSettings(false); @@ -1158,10 +1190,10 @@ void ChatLobbyWidget::itemDoubleClicked(QTreeWidgetItem *item, int /*column*/) 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(ChatDialog::getExistingChat(ChatId(lobby_id)))) { - cld->displayLobbyEvent(event_type, gxs_id, str); + cld->handleLobbyEvent(event_type, gxs_id, str); } } diff --git a/retroshare-gui/src/gui/ChatLobbyWidget.h b/retroshare-gui/src/gui/ChatLobbyWidget.h index 424780dac..648e7dac9 100644 --- a/retroshare-gui/src/gui/ChatLobbyWidget.h +++ b/retroshare-gui/src/gui/ChatLobbyWidget.h @@ -89,8 +89,8 @@ protected slots: void unsubscribeItem(); void itemDoubleClicked(QTreeWidgetItem *item, int column); void updateCurrentLobby() ; - void displayChatLobbyEvent(qulonglong lobby_id, int event_type, const RsGxsId& gxs_id, const QString& str); - void readChatLobbyInvites(); + void handleChatLobbyEvent(uint64_t lobby_id, RsChatStatusEventCode event_type, const RsGxsId &gxs_id, const QString& str); + void readChatLobbyInvites(); void showLobby(QTreeWidgetItem *lobby_item) ; void showBlankPage(ChatLobbyId id, bool subscribed = false) ; void unsubscribeChatLobby(ChatLobbyId id) ; @@ -151,5 +151,7 @@ private: /* UI - from Designer */ Ui::ChatLobbyWidget ui; + + RsEventsHandlerId_t mEventHandlerId; }; diff --git a/retroshare-gui/src/gui/MainWindow.cpp b/retroshare-gui/src/gui/MainWindow.cpp index 964b42c92..b9abc4ae9 100644 --- a/retroshare-gui/src/gui/MainWindow.cpp +++ b/retroshare-gui/src/gui/MainWindow.cpp @@ -32,6 +32,7 @@ #include "retroshare/rsplugin.h" #include "retroshare/rsconfig.h" +#include "retroshare/rsevents.h" #include "util/argstream.h" #include "util/qtthreadsutils.h" @@ -380,6 +381,29 @@ MainWindow::MainWindow(QWidget* parent, Qt::WindowFlags flags) settingsChanged(); mFontSizeHandler.registerFontSize(ui->listWidget, 1.5f); + + rsEvents->registerEventsHandler( [this](std::shared_ptr event) + { + RsQThreadUtils::postToObject([=](){ + auto ev = dynamic_cast(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. */ diff --git a/retroshare-gui/src/gui/chat/ChatLobbyDialog.cpp b/retroshare-gui/src/gui/chat/ChatLobbyDialog.cpp index dd4a128a4..a0bed44f9 100644 --- a/retroshare-gui/src/gui/chat/ChatLobbyDialog.cpp +++ b/retroshare-gui/src/gui/chat/ChatLobbyDialog.cpp @@ -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; @@ -854,17 +854,17 @@ void ChatLobbyDialog::displayLobbyEvent(int event_type, const RsGxsId& gxs_id, c switch (event_type) { - case RS_CHAT_LOBBY_EVENT_PEER_LEFT: + case RsChatStatusEventCode::CHAT_LOBBY_EVENT_PEER_LEFT: 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); emit peerLeft(id()) ; break; - case RS_CHAT_LOBBY_EVENT_PEER_JOINED: + case RsChatStatusEventCode::CHAT_LOBBY_EVENT_PEER_JOINED: 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); emit peerJoined(id()) ; break; - case RS_CHAT_LOBBY_EVENT_PEER_STATUS: + case RsChatStatusEventCode::CHAT_LOBBY_EVENT_PEER_STATUS: { qsParticipant=gxs_id; @@ -876,7 +876,7 @@ void ChatLobbyDialog::displayLobbyEvent(int event_type, const RsGxsId& gxs_id, c } break; - case RS_CHAT_LOBBY_EVENT_PEER_CHANGE_NICKNAME: + case RsChatStatusEventCode::CHAT_LOBBY_EVENT_PEER_CHANGE_NICKNAME: { qsParticipant=gxs_id; @@ -892,11 +892,11 @@ void ChatLobbyDialog::displayLobbyEvent(int event_type, const RsGxsId& gxs_id, c muteParticipant(RsGxsId(str.toStdString())) ; } 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; break; 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()) diff --git a/retroshare-gui/src/gui/chat/ChatLobbyDialog.h b/retroshare-gui/src/gui/chat/ChatLobbyDialog.h index c3572cc4b..1d388b57f 100644 --- a/retroshare-gui/src/gui/chat/ChatLobbyDialog.h +++ b/retroshare-gui/src/gui/chat/ChatLobbyDialog.h @@ -42,7 +42,7 @@ class ChatLobbyDialog: public ChatDialog friend class ChatDialog; 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 ChatWidget *getChatWidget(); diff --git a/retroshare-gui/src/gui/notifyqt.cpp b/retroshare-gui/src/gui/notifyqt.cpp index b7eb36bd2..aa0da0b12 100644 --- a/retroshare-gui/src/gui/notifyqt.cpp +++ b/retroshare-gui/src/gui/notifyqt.cpp @@ -320,6 +320,7 @@ void NotifyQt::notifyDiscInfoChanged() emit discInfoChanged() ; } +#ifdef TO_REMOVE 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) ; } -#ifdef TO_REMOVE /* peer has changed the 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())) ; } +#ifdef TO_REMOVE void NotifyQt::notifyChatLobbyTimeShift(int shift) { { @@ -450,6 +451,7 @@ 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) { @@ -561,7 +563,6 @@ void NotifyQt::notifyListChange(int list, int type) #endif emit filesPostModChanged(false) ; /* Local */ break; -#endif case NOTIFY_LIST_CHAT_LOBBY_INVITATION: #ifdef NOTIFY_DEBUG std::cerr << "received files changed" << std::endl ; @@ -575,7 +576,6 @@ void NotifyQt::notifyListChange(int list, int type) emit configChanged() ; break ; -#ifdef REMOVE case NOTIFY_LIST_SEARCHLIST: break; case NOTIFY_LIST_CHANNELLIST: diff --git a/retroshare-gui/src/gui/notifyqt.h b/retroshare-gui/src/gui/notifyqt.h index 8adfd9fd7..fd3d51e7f 100644 --- a/retroshare-gui/src/gui/notifyqt.h +++ b/retroshare-gui/src/gui/notifyqt.h @@ -73,11 +73,11 @@ class NotifyQt: public QObject, public NotifyClient // virtual void notifyTurtleSearchResult(uint32_t search_id,const std::list& found_groups); virtual void notifyPeerHasNewAvatar(std::string peer_id) ; virtual void notifyOwnAvatarChanged() ; - 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 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 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 */ // virtual void notifyPeerStatusChanged(const std::string& peer_id, uint32_t state); /* one or more peers has changed the states */ @@ -110,7 +110,7 @@ class NotifyQt: public QObject, public NotifyClient // void transfersChanged() const ; // void friendsChanged() const ; void lobbyListChanged() const ; - void chatLobbyEvent(qulonglong,int,const RsGxsId&,const QString&) ; +// void chatLobbyEvent(qulonglong,int,const RsGxsId&,const QString&) ; // void neighboursChanged() const ; void configChanged() const ; void logInfoChanged(const QString&) const ; @@ -129,9 +129,9 @@ class NotifyQt: public QObject, public NotifyClient // void groupsChanged(int type) const ; void discInfoChanged() const ; void historyChanged(uint msgId, int type); - void chatLobbyInviteReceived() ; +// void chatLobbyInviteReceived() ; // void deferredSignatureHandlingRequested() ; - void chatLobbyTimeShift(int time_shift) ; +// void chatLobbyTimeShift(int time_shift) ; void connectionWithoutCert(); /* Notify from GUI */ @@ -147,7 +147,7 @@ class NotifyQt: public QObject, public NotifyClient private slots: void runningTick(); void handleSignatureEvent() ; - void handleChatLobbyTimeShift(int) ; +// void handleChatLobbyTimeShift(int) ; private: NotifyQt(); diff --git a/retroshare-gui/src/main.cpp b/retroshare-gui/src/main.cpp index dffe7e133..71daf5271 100644 --- a/retroshare-gui/src/main.cpp +++ b/retroshare-gui/src/main.cpp @@ -726,8 +726,8 @@ feenableexcept(FE_INVALID | FE_DIVBYZERO); std::cerr << "connecting signals and slots" << std::endl ; #endif // 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(diskFull(int,int)) ,w ,SLOT(displayDiskSpaceWarning(int,int))) ; +// 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(filesPostModChanged(bool)) ,w ,SLOT(postModDirectories(bool)) ,Qt::QueuedConnection ) ; // QObject::connect(notify,SIGNAL(transfersChanged()) ,w->transfersDialog ,SLOT(insertTransfers() )) ; QObject::connect(notify,SIGNAL(publicChatChanged(int)) ,w->friendsDialog ,SLOT(publicChatChanged(int) ));