From e6cacc4d3437c3f66bf9bf04ec7234af3055f9bd Mon Sep 17 00:00:00 2001 From: csoler Date: Sat, 14 Jun 2025 21:56:09 +0200 Subject: [PATCH] moved peerStatusChanged() from notify to rsEvents --- .../src/gui/Identity/IdentityListModel.h | 2 +- retroshare-gui/src/gui/MainWindow.cpp | 34 +++---- retroshare-gui/src/gui/MainWindow.h | 3 +- retroshare-gui/src/gui/MessengerWindow.cpp | 22 ++++- retroshare-gui/src/gui/MessengerWindow.h | 3 +- retroshare-gui/src/gui/chat/ChatDialog.cpp | 6 +- retroshare-gui/src/gui/chat/ChatDialog.h | 6 +- retroshare-gui/src/gui/chat/ChatTabWidget.cpp | 4 +- retroshare-gui/src/gui/chat/ChatWidget.cpp | 39 +++++--- retroshare-gui/src/gui/chat/ChatWidget.h | 13 +-- .../src/gui/chat/PopupChatWindow.cpp | 4 +- .../src/gui/chat/PopupDistantChatDialog.cpp | 8 +- .../src/gui/common/AvatarWidget.cpp | 60 ++++++++----- retroshare-gui/src/gui/common/AvatarWidget.h | 10 ++- .../src/gui/common/FriendListModel.cpp | 44 ++++----- .../src/gui/common/FriendListModel.h | 4 +- .../src/gui/common/FriendSelectionWidget.cpp | 38 ++++---- .../src/gui/common/FriendSelectionWidget.h | 3 +- .../src/gui/common/NewFriendList.cpp | 8 +- retroshare-gui/src/gui/common/NewFriendList.h | 20 ++--- retroshare-gui/src/gui/common/StatusDefs.cpp | 90 ++++++++++--------- retroshare-gui/src/gui/common/StatusDefs.h | 14 +-- .../src/gui/msgs/MessageComposer.cpp | 20 ++++- retroshare-gui/src/gui/msgs/MessageComposer.h | 3 +- retroshare-gui/src/gui/notifyqt.cpp | 2 + retroshare-gui/src/gui/notifyqt.h | 8 +- 26 files changed, 281 insertions(+), 187 deletions(-) diff --git a/retroshare-gui/src/gui/Identity/IdentityListModel.h b/retroshare-gui/src/gui/Identity/IdentityListModel.h index 4c3cb43e2..0e1fb5e28 100644 --- a/retroshare-gui/src/gui/Identity/IdentityListModel.h +++ b/retroshare-gui/src/gui/Identity/IdentityListModel.h @@ -168,7 +168,7 @@ public: /* Color definitions (for standard see default.qss) */ QColor mTextColorGroup; - QColor mTextColorStatus[RS_STATUS_COUNT]; + QColor mTextColorStatus[(int)RsStatusValue::RS_STATUS_COUNT]; void setIdentities(const std::list& identities_meta); diff --git a/retroshare-gui/src/gui/MainWindow.cpp b/retroshare-gui/src/gui/MainWindow.cpp index 8803783a4..964b42c92 100644 --- a/retroshare-gui/src/gui/MainWindow.cpp +++ b/retroshare-gui/src/gui/MainWindow.cpp @@ -1471,7 +1471,7 @@ MainWindow::retranslateUi() } /* set status object to status value */ -static void setStatusObject(QObject *pObject, int nStatus) +static void setStatusObject(QObject *pObject, RsStatusValue nStatus) { QMenu *pMenu = dynamic_cast(pObject); if (pMenu) { @@ -1482,7 +1482,7 @@ static void setStatusObject(QObject *pObject, int nStatus) continue; } - if (pAction->data().toInt() == nStatus) { + if (pAction->data().toInt() == (int)nStatus) { pAction->setChecked(true); break; } @@ -1492,7 +1492,7 @@ static void setStatusObject(QObject *pObject, int nStatus) RSComboBox *pComboBox = dynamic_cast(pObject); if (pComboBox) { /* set index of combobox */ - int nIndex = pComboBox->findData(nStatus, Qt::UserRole); + int nIndex = pComboBox->findData((int)nStatus, Qt::UserRole); if (nIndex != -1) { pComboBox->setCurrentIndex(nIndex); } @@ -1555,20 +1555,20 @@ void MainWindow::initializeStatusObject(QObject *pObject, bool bConnect) /* initialize menu */ QActionGroup *pGroup = new QActionGroup(pMenu); - QAction *pAction = new QAction(QIcon(StatusDefs::imageStatus(RS_STATUS_ONLINE)), StatusDefs::name(RS_STATUS_ONLINE), pMenu); - pAction->setData(RS_STATUS_ONLINE); + QAction *pAction = new QAction(QIcon(StatusDefs::imageStatus(RsStatusValue::RS_STATUS_ONLINE)), StatusDefs::name(RsStatusValue::RS_STATUS_ONLINE), pMenu); + pAction->setData((int)RsStatusValue::RS_STATUS_ONLINE); pAction->setCheckable(true); pMenu->addAction(pAction); pGroup->addAction(pAction); - pAction = new QAction(QIcon(StatusDefs::imageStatus(RS_STATUS_BUSY)), StatusDefs::name(RS_STATUS_BUSY), pMenu); - pAction->setData(RS_STATUS_BUSY); + pAction = new QAction(QIcon(StatusDefs::imageStatus(RsStatusValue::RS_STATUS_BUSY)), StatusDefs::name(RsStatusValue::RS_STATUS_BUSY), pMenu); + pAction->setData((int)RsStatusValue::RS_STATUS_BUSY); pAction->setCheckable(true); pMenu->addAction(pAction); pGroup->addAction(pAction); - pAction = new QAction(QIcon(StatusDefs::imageStatus(RS_STATUS_AWAY)), StatusDefs::name(RS_STATUS_AWAY), pMenu); - pAction->setData(RS_STATUS_AWAY); + pAction = new QAction(QIcon(StatusDefs::imageStatus(RsStatusValue::RS_STATUS_AWAY)), StatusDefs::name(RsStatusValue::RS_STATUS_AWAY), pMenu); + pAction->setData((int)RsStatusValue::RS_STATUS_AWAY); pAction->setCheckable(true); pMenu->addAction(pAction); pGroup->addAction(pAction); @@ -1580,9 +1580,9 @@ void MainWindow::initializeStatusObject(QObject *pObject, bool bConnect) /* initialize combobox */ RSComboBox *pComboBox = dynamic_cast(pObject); if (pComboBox) { - pComboBox->addItem(QIcon(StatusDefs::imageStatus(RS_STATUS_ONLINE)), StatusDefs::name(RS_STATUS_ONLINE), RS_STATUS_ONLINE); - pComboBox->addItem(QIcon(StatusDefs::imageStatus(RS_STATUS_BUSY)), StatusDefs::name(RS_STATUS_BUSY), RS_STATUS_BUSY); - pComboBox->addItem(QIcon(StatusDefs::imageStatus(RS_STATUS_AWAY)), StatusDefs::name(RS_STATUS_AWAY), RS_STATUS_AWAY); + pComboBox->addItem(QIcon(StatusDefs::imageStatus(RsStatusValue::RS_STATUS_ONLINE)), StatusDefs::name(RsStatusValue::RS_STATUS_ONLINE), (int)RsStatusValue::RS_STATUS_ONLINE); + pComboBox->addItem(QIcon(StatusDefs::imageStatus(RsStatusValue::RS_STATUS_BUSY)), StatusDefs::name(RsStatusValue::RS_STATUS_BUSY), (int)RsStatusValue::RS_STATUS_BUSY); + pComboBox->addItem(QIcon(StatusDefs::imageStatus(RsStatusValue::RS_STATUS_AWAY)), StatusDefs::name(RsStatusValue::RS_STATUS_AWAY), (int)RsStatusValue::RS_STATUS_AWAY); if (bConnect) { connect(pComboBox, SIGNAL(activated(int)), this, SLOT(statusChangedComboBox(int))); @@ -1610,11 +1610,11 @@ void MainWindow::removeStatusObject(QObject *pObject) } /** Save own status Online,Away,Busy **/ -void MainWindow::setStatus(QObject *pObject, int nStatus) +void MainWindow::setStatus(QObject *pObject, RsStatusValue nStatus) { - if (isIdle && nStatus == (int) RS_STATUS_ONLINE) { + if (isIdle && nStatus == RsStatusValue::RS_STATUS_ONLINE) { /* set idle only when I am online */ - nStatus = RS_STATUS_INACTIVE; + nStatus = RsStatusValue::RS_STATUS_INACTIVE; } rsStatus->sendStatus(RsPeerId(), nStatus); @@ -1634,7 +1634,7 @@ void MainWindow::statusChangedMenu(QAction *pAction) return; } - setStatus(pAction->parent(), pAction->data().toInt()); + setStatus(pAction->parent(), RsStatusValue(pAction->data().toInt())); } /* new status from combobox in statusbar */ @@ -1645,7 +1645,7 @@ void MainWindow::statusChangedComboBox(int index) } /* no object known */ - setStatus(NULL, statusComboBox->itemData(index, Qt::UserRole).toInt()); + setStatus(NULL, RsStatusValue(statusComboBox->itemData(index, Qt::UserRole).toInt())); } /*new setting*/ diff --git a/retroshare-gui/src/gui/MainWindow.h b/retroshare-gui/src/gui/MainWindow.h index 218d84e47..2f458c4ab 100644 --- a/retroshare-gui/src/gui/MainWindow.h +++ b/retroshare-gui/src/gui/MainWindow.h @@ -26,6 +26,7 @@ #include #include "retroshare/rsevents.h" +#include "retroshare/rsstatus.h" #include "gui/common/rwindow.h" #include "gui/common/RSComboBox.h" @@ -185,7 +186,7 @@ public: /* initialize widget with status informations, status constant stored in data or in Qt::UserRole */ void initializeStatusObject(QObject *pObject, bool bConnect); void removeStatusObject(QObject *pObject); - void setStatus(QObject *pObject, int nStatus); + void setStatus(QObject *pObject, RsStatusValue nStatus); RSComboBox *statusComboBoxInstance(); PeerStatus *peerstatusInstance(); diff --git a/retroshare-gui/src/gui/MessengerWindow.cpp b/retroshare-gui/src/gui/MessengerWindow.cpp index 77396a928..ca2a5530e 100644 --- a/retroshare-gui/src/gui/MessengerWindow.cpp +++ b/retroshare-gui/src/gui/MessengerWindow.cpp @@ -40,6 +40,7 @@ #include "notifyqt.h" #include "connect/ConnectFriendWizard.h" #include "util/PixmapMerging.h" +#include "util/qtthreadsutils.h" #include "LogoBar.h" #include "util/Widget.h" #include "util/misc.h" @@ -94,9 +95,23 @@ MessengerWindow::MessengerWindow(QWidget* parent, Qt::WindowFlags flags) ui.avatar->setOwnId(); connect(ui.messagelineEdit, SIGNAL(textChanged(const QString &)), this, SLOT(savestatusmessage())); - connect(NotifyQt::getInstance(), SIGNAL(ownStatusMessageChanged()), this, SLOT(loadmystatusmessage())); - connect(NotifyQt::getInstance(), SIGNAL(peerStatusChanged(QString,int)), this, SLOT(updateOwnStatus(QString,int))); + + //connect(NotifyQt::getInstance(), SIGNAL(peerStatusChanged(QString,int)), this, SLOT(updateOwnStatus(QString,int))); + + mEventHandlerId = 0; + rsEvents->registerEventsHandler( [this](std::shared_ptr e) + { + RsQThreadUtils::postToObject([=](){ + auto fe = dynamic_cast(e.get()); + + if(!fe || fe->mEventCode != RsFriendListEventCode::NODE_STATUS_CHANGED) + return; + + updateOwnStatus(QString::fromStdString(fe->mSslId.toStdString()),fe->mStatus); + + }, this ); + },mEventHandlerId,RsEventType::FRIEND_LIST); for (std::set::iterator peerIt = expandedPeers.begin(); peerIt != expandedPeers.end(); ++peerIt) { ui.friendList->addPeerToExpand(*peerIt); @@ -159,6 +174,7 @@ MessengerWindow::~MessengerWindow () { // save settings processSettings(false); + rsEvents->unregisterEventsHandler(mEventHandlerId); MainWindow *pMainWindow = MainWindow::getInstance(); if (pMainWindow) { @@ -214,7 +230,7 @@ void MessengerWindow::savestatusmessage() rsMsgs->setCustomStateString(ui.messagelineEdit->currentText().toUtf8().constData()); } -void MessengerWindow::updateOwnStatus(const QString &peer_id, int status) +void MessengerWindow::updateOwnStatus(const QString &peer_id, RsStatusValue status) { // add self nick + own status if (peer_id == QString::fromStdString(rsPeers->getOwnId().toStdString())) diff --git a/retroshare-gui/src/gui/MessengerWindow.h b/retroshare-gui/src/gui/MessengerWindow.h index d683ec744..26c5e547a 100644 --- a/retroshare-gui/src/gui/MessengerWindow.h +++ b/retroshare-gui/src/gui/MessengerWindow.h @@ -52,7 +52,7 @@ private slots: /** Open Shared Manager **/ void openShareManager(); - void updateOwnStatus(const QString &peer_id, int status); + void updateOwnStatus(const QString &peer_id, RsStatusValue status); void savestatusmessage(); @@ -68,6 +68,7 @@ private: static std::set expandedPeers ; static std::set expandedGroups ; + RsEventsHandlerId_t mEventHandlerId ; }; #endif diff --git a/retroshare-gui/src/gui/chat/ChatDialog.cpp b/retroshare-gui/src/gui/chat/ChatDialog.cpp index d7edd2152..0b7017a88 100644 --- a/retroshare-gui/src/gui/chat/ChatDialog.cpp +++ b/retroshare-gui/src/gui/chat/ChatDialog.cpp @@ -330,7 +330,7 @@ QString ChatDialog::getOwnName() const return "ChatDialog::getOwnName(): invalid id type passed (RsPeerId is required). This is a bug."; } -void ChatDialog::setPeerStatus(uint32_t status) +void ChatDialog::setPeerStatus(RsStatusValue status) { ChatWidget *cw = getChatWidget(); if (cw) @@ -346,14 +346,14 @@ void ChatDialog::setPeerStatus(uint32_t status) cw->updateStatus(QString::fromStdString(vpid.toStdString()), status); } } -int ChatDialog::getPeerStatus() +RsStatusValue ChatDialog::getPeerStatus() { ChatWidget *cw = getChatWidget(); if (cw) { return cw->getPeerStatus(); } - return 0; + return RsStatusValue::RS_STATUS_UNKNOWN; } QString ChatDialog::getTitle() diff --git a/retroshare-gui/src/gui/chat/ChatDialog.h b/retroshare-gui/src/gui/chat/ChatDialog.h index 7bfbc16ec..0145fe678 100644 --- a/retroshare-gui/src/gui/chat/ChatDialog.h +++ b/retroshare-gui/src/gui/chat/ChatDialog.h @@ -23,6 +23,8 @@ #ifndef CHATDIALOG_H #define CHATDIALOG_H +#include "retroshare/rsstatus.h" + #include #include @@ -58,8 +60,8 @@ public: bool setStyle(); const RSStyle *getStyle(); - int getPeerStatus(); - void setPeerStatus(uint32_t state); + RsStatusValue getPeerStatus(); + void setPeerStatus(RsStatusValue state); void focusDialog(); diff --git a/retroshare-gui/src/gui/chat/ChatTabWidget.cpp b/retroshare-gui/src/gui/chat/ChatTabWidget.cpp index 03357a3e4..9008b250c 100644 --- a/retroshare-gui/src/gui/chat/ChatTabWidget.cpp +++ b/retroshare-gui/src/gui/chat/ChatTabWidget.cpp @@ -113,7 +113,7 @@ void ChatTabWidget::tabInfoChanged(ChatDialog *dialog) } } else if (dialog->hasPeerStatus()) { setBlinking(tab, false); - setTabIcon(tab, QIcon(StatusDefs::imageIM(dialog->getPeerStatus()))); + setTabIcon(tab, QIcon(StatusDefs::imageIM((RsStatusValue)dialog->getPeerStatus()))); } else { setBlinking(tab, false); setTabIcon(tab, QIcon()); @@ -155,7 +155,7 @@ void ChatTabWidget::getInfo(bool &isTyping, bool &hasNewMessage, QIcon *icon) } else { cd = dynamic_cast(currentWidget()); if (cd && cd->hasPeerStatus()) { - *icon = QIcon(StatusDefs::imageIM(cd->getPeerStatus())); + *icon = QIcon(StatusDefs::imageIM((RsStatusValue)cd->getPeerStatus())); } else { *icon = QIcon(); } diff --git a/retroshare-gui/src/gui/chat/ChatWidget.cpp b/retroshare-gui/src/gui/chat/ChatWidget.cpp index abab8336a..0cac7c497 100644 --- a/retroshare-gui/src/gui/chat/ChatWidget.cpp +++ b/retroshare-gui/src/gui/chat/ChatWidget.cpp @@ -38,6 +38,7 @@ #include "gui/chat/ChatUserNotify.h"//For BradCast #include "util/DateTime.h" #include "util/imageutil.h" +#include "util/qtthreadsutils.h" #include "gui/im_history/ImHistoryBrowser.h" #include @@ -74,7 +75,7 @@ ChatWidget::ChatWidget(QWidget *parent) : QWidget(parent) - , completionPosition(0), newMessages(false), typing(false), peerStatus(0) + , completionPosition(0), newMessages(false), typing(false), peerStatus(RsStatusValue::RS_STATUS_UNKNOWN) , sendingBlocked(false), useCMark(false) , lastStatusSendTime(0) , firstShow(true), inChatCharFormatChanged(false), firstSearch(true) @@ -171,8 +172,23 @@ ChatWidget::ChatWidget(QWidget *parent) connect(ui->hashBox, SIGNAL(fileHashingFinished(QList)), this, SLOT(fileHashingFinished(QList))); - connect(NotifyQt::getInstance(), SIGNAL(peerStatusChanged(const QString&, int)), this, SLOT(updateStatus(const QString&, int))); - connect(NotifyQt::getInstance(), SIGNAL(peerHasNewCustomStateString(const QString&, const QString&)), this, SLOT(updatePeersCustomStateString(const QString&, const QString&))); + //connect(NotifyQt::getInstance(), SIGNAL(peerStatusChanged(const QString&, int)), this, SLOT(updateStatus(const QString&, int))); + + mEventHandlerId = 0; + rsEvents->registerEventsHandler( [this](std::shared_ptr e) + { + RsQThreadUtils::postToObject([=](){ + auto fe = dynamic_cast(e.get()); + + if(!fe || fe->mEventCode != RsFriendListEventCode::NODE_STATUS_CHANGED) + return; + + updateStatus(QString::fromStdString(fe->mSslId.toStdString()),fe->mStatus); + + }, 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(chatFontChanged()), this, SLOT(resetFonts())); connect(ui->textBrowser, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(contextMenuTextBrowser(QPoint))); @@ -254,6 +270,7 @@ ChatWidget::ChatWidget(QWidget *parent) ChatWidget::~ChatWidget() { processSettings(false); + rsEvents->unregisterEventsHandler(mEventHandlerId); /* Cleanup plugin functions */ foreach (ChatWidgetHolder *chatWidgetHolder, mChatWidgetHolder) { @@ -1788,7 +1805,7 @@ void ChatWidget::setCurrentFileName(const QString &fileName) setWindowModified(false); } -void ChatWidget::updateStatus(const QString &peer_id, int status) +void ChatWidget::updateStatus(const QString &peer_id, RsStatusValue status) { if (! (chatType() == CHATTYPE_PRIVATE || chatType() == CHATTYPE_DISTANT)) { @@ -1842,26 +1859,27 @@ void ChatWidget::updateStatus(const QString &peer_id, int status) bool atEnd = (scrollbar->value() == scrollbar->maximum()); switch (status) { - case RS_STATUS_OFFLINE: + default: + case RsStatusValue::RS_STATUS_OFFLINE: ui->info_Frame->setVisible(true); ui->infoLabel->setText(peerName + " " + tr("appears to be Offline.") +"\n" + tr("Messages you send will be delivered after Friend is again Online.")); break; - case RS_STATUS_INACTIVE: + case RsStatusValue::RS_STATUS_INACTIVE: ui->info_Frame->setVisible(true); ui->infoLabel->setText(peerName + " " + tr("is Idle and may not reply")); break; - case RS_STATUS_ONLINE: + case RsStatusValue::RS_STATUS_ONLINE: ui->info_Frame->setVisible(false); break; - case RS_STATUS_AWAY: + case RsStatusValue::RS_STATUS_AWAY: ui->infoLabel->setText(peerName + " " + tr("is Away and may not reply")); ui->info_Frame->setVisible(true); break; - case RS_STATUS_BUSY: + case RsStatusValue::RS_STATUS_BUSY: ui->infoLabel->setText(peerName + " " + tr("is Busy and may not reply")); ui->info_Frame->setVisible(true); break; @@ -1869,7 +1887,8 @@ void ChatWidget::updateStatus(const QString &peer_id, int status) ui->titleLabel->setText(peerName); ui->titleLabel->setToolTip(tooltip_info); - ui->statusLabel->setText(QString("(%1)").arg(StatusDefs::name(status))); +#warning inconsistent conversion here + ui->statusLabel->setText(QString("(%1)").arg(StatusDefs::name((RsStatusValue)status))); peerStatus = status; diff --git a/retroshare-gui/src/gui/chat/ChatWidget.h b/retroshare-gui/src/gui/chat/ChatWidget.h index e42df06fe..0b9a28ccb 100644 --- a/retroshare-gui/src/gui/chat/ChatWidget.h +++ b/retroshare-gui/src/gui/chat/ChatWidget.h @@ -31,6 +31,7 @@ #include #include +#include #include #include @@ -62,7 +63,7 @@ public: // status comes from notifyPeerStatusChanged // see rststaus.h for possible values - virtual void updateStatus(int /*status*/) {} + virtual void updateStatus(RsStatusValue /*status*/) {} protected: ChatWidget *mChatWidget; @@ -105,7 +106,7 @@ public: void addToolsAction(QAction *action); QString getTitle() { return title; } - int getPeerStatus() { return peerStatus; } + RsStatusValue getPeerStatus() { return peerStatus; } void setName(const QString &name); bool setStyle(); @@ -130,7 +131,7 @@ public: const QList &chatWidgetHolderList() { return mChatWidgetHolder; } public slots: - void updateStatus(const QString &peer_id, int status); + void updateStatus(const QString &peer_id, RsStatusValue status); void setUseCMark(const bool bUseCMark); void updateCMPreview(); @@ -144,7 +145,7 @@ private slots: signals: void infoChanged(ChatWidget*); void newMessage(ChatWidget*); - void statusChanged(int); + void statusChanged(RsStatusValue); void textBrowserAskContextMenu(QMenu* contextMnu, QString anchorForPosition, const QPoint point); protected: @@ -229,7 +230,7 @@ private: bool newMessages; bool typing; - int peerStatus; + RsStatusValue peerStatus; bool sendingBlocked; bool useCMark; @@ -272,6 +273,8 @@ private: ChatLobbyUserNotify* notify; Ui::ChatWidget *ui; + + RsEventsHandlerId_t mEventHandlerId ; }; #endif // CHATWIDGET_H diff --git a/retroshare-gui/src/gui/chat/PopupChatWindow.cpp b/retroshare-gui/src/gui/chat/PopupChatWindow.cpp index 1f15345b1..f60b7b7e4 100644 --- a/retroshare-gui/src/gui/chat/PopupChatWindow.cpp +++ b/retroshare-gui/src/gui/chat/PopupChatWindow.cpp @@ -350,7 +350,7 @@ void PopupChatWindow::calculateTitle(ChatDialog *dialog) } else { mBlinkIcon = QIcon(); if (cd && cd->hasPeerStatus()) { - icon = QIcon(StatusDefs::imageIM(cd->getPeerStatus())); + icon = QIcon(StatusDefs::imageIM((RsStatusValue)cd->getPeerStatus())); } else { icon = qApp->windowIcon(); } @@ -361,7 +361,7 @@ void PopupChatWindow::calculateTitle(ChatDialog *dialog) if (cd) { QString title = cd->getTitle(); if (cd->hasPeerStatus()) { - title += " (" + StatusDefs::name(cd->getPeerStatus()) + ")"; + title += " (" + StatusDefs::name((RsStatusValue)cd->getPeerStatus()) + ")"; } setWindowTitle(title); } else { diff --git a/retroshare-gui/src/gui/chat/PopupDistantChatDialog.cpp b/retroshare-gui/src/gui/chat/PopupDistantChatDialog.cpp index c5ab40cbf..0e8faba80 100644 --- a/retroshare-gui/src/gui/chat/PopupDistantChatDialog.cpp +++ b/retroshare-gui/src/gui/chat/PopupDistantChatDialog.cpp @@ -121,7 +121,7 @@ void PopupDistantChatDialog::updateDisplay() getChatWidget()->blockSending(tr( "Can't send message immediately, " "because there is no tunnel " "available." )); - setPeerStatus(RS_STATUS_OFFLINE); + setPeerStatus(RsStatusValue::RS_STATUS_OFFLINE); break ; case RS_DISTANT_CHAT_STATUS_REMOTELY_CLOSED: std::cerr << "Chat remotely closed. " << std::endl; @@ -131,7 +131,7 @@ void PopupDistantChatDialog::updateDisplay() getChatWidget()->updateStatusString("%1", tr( "Your partner closed the conversation." ), true ); getChatWidget()->blockSending(tr( "Your partner closed the conversation.")); - setPeerStatus(RS_STATUS_OFFLINE) ; + setPeerStatus(RsStatusValue::RS_STATUS_OFFLINE) ; break ; case RS_DISTANT_CHAT_STATUS_TUNNEL_DN: @@ -145,7 +145,7 @@ void PopupDistantChatDialog::updateDisplay() _status_label->setToolTip(msg); getChatWidget()->updateStatusString("%1", msg, true); getChatWidget()->blockSending(msg); - setPeerStatus(RS_STATUS_OFFLINE); + setPeerStatus(RsStatusValue::RS_STATUS_OFFLINE); break; case RS_DISTANT_CHAT_STATUS_CAN_TALK: @@ -153,7 +153,7 @@ void PopupDistantChatDialog::updateDisplay() msg = QObject::tr( "End-to-end encrypted conversation established"); _status_label->setToolTip(msg); getChatWidget()->unblockSending(); - setPeerStatus(RS_STATUS_ONLINE); + setPeerStatus(RsStatusValue::RS_STATUS_ONLINE); break; } } diff --git a/retroshare-gui/src/gui/common/AvatarWidget.cpp b/retroshare-gui/src/gui/common/AvatarWidget.cpp index 02151730a..afb4c883c 100644 --- a/retroshare-gui/src/gui/common/AvatarWidget.cpp +++ b/retroshare-gui/src/gui/common/AvatarWidget.cpp @@ -27,6 +27,7 @@ #include "gui/notifyqt.h" #include "util/misc.h" +#include "util/qtthreadsutils.h" #include "gui/common/AvatarDefs.h" #include "gui/common/AvatarDialog.h" @@ -39,21 +40,36 @@ AvatarWidget::AvatarWidget(QWidget *parent) : QLabel(parent), ui(new Ui::AvatarWidget) { - ui->setupUi(this); + ui->setupUi(this); - mFlag.isOwnId = false; - defaultAvatar = ":/images/no_avatar_background.png"; - mPeerState = RS_STATUS_OFFLINE ; + mFlag.isOwnId = false; + defaultAvatar = ":/images/no_avatar_background.png"; + mPeerState = RsStatusValue::RS_STATUS_OFFLINE ; - setFrameType(NO_FRAME); + setFrameType(NO_FRAME); + + /* connect signals */ + connect(NotifyQt::getInstance(), SIGNAL(peerHasNewAvatar(const QString&)), this, SLOT(updateAvatar(const QString&))); + connect(NotifyQt::getInstance(), SIGNAL(ownAvatarChanged()), this, SLOT(updateOwnAvatar())); + + mEventHandlerId = 0; + + rsEvents->registerEventsHandler( [this](std::shared_ptr event) + { + RsQThreadUtils::postToObject([=](){ + + const RsFriendListEvent *e = dynamic_cast(event.get()); + if(!e) + return; + updateStatus(QString::fromStdString(e->mSslId.toStdString()),e->mStatus); + }, this ); + }, mEventHandlerId, RsEventType::FRIEND_LIST ); - /* connect signals */ - connect(NotifyQt::getInstance(), SIGNAL(peerHasNewAvatar(const QString&)), this, SLOT(updateAvatar(const QString&))); - connect(NotifyQt::getInstance(), SIGNAL(ownAvatarChanged()), this, SLOT(updateOwnAvatar())); } AvatarWidget::~AvatarWidget() { + rsEvents->unregisterEventsHandler(mEventHandlerId); delete ui; } @@ -68,15 +84,15 @@ QString AvatarWidget::frameState() case STATUS_FRAME: switch (mPeerState) { - case RS_STATUS_OFFLINE: + case RsStatusValue::RS_STATUS_OFFLINE: return "OFFLINE"; - case RS_STATUS_INACTIVE: + case RsStatusValue::RS_STATUS_INACTIVE: return "INACTIVE"; - case RS_STATUS_ONLINE: + case RsStatusValue::RS_STATUS_ONLINE: return "ONLINE"; - case RS_STATUS_AWAY: + case RsStatusValue::RS_STATUS_AWAY: return "AWAY"; - case RS_STATUS_BUSY: + case RsStatusValue::RS_STATUS_BUSY: return "BUSY"; } } @@ -107,6 +123,7 @@ void AvatarWidget::setFrameType(FrameType type) { mFrameType = type; +#ifdef TO_REMOVE switch (mFrameType) { case NO_FRAME: disconnect(NotifyQt::getInstance(), SIGNAL(peerStatusChanged(QString,int)), this, SLOT(updateStatus(const QString&, int))); @@ -118,6 +135,9 @@ void AvatarWidget::setFrameType(FrameType type) connect(NotifyQt::getInstance(), SIGNAL(peerStatusChanged(QString,int)), this, SLOT(updateStatus(const QString&, int))); break; } +#endif + + //refreshAvatarImage(); refreshStatus(); @@ -179,7 +199,7 @@ void AvatarWidget::refreshStatus() } case STATUS_FRAME: { - uint32_t status = 0; + RsStatusValue status = RsStatusValue::RS_STATUS_UNKNOWN; if (mId.isNotSet()) return; @@ -193,7 +213,7 @@ void AvatarWidget::refreshStatus() status = statusInfo.status ; } else if(mId.isDistantChatId()) - status = RS_STATUS_ONLINE ; + status = RsStatusValue::RS_STATUS_ONLINE ; else { std::cerr << "Unhandled chat id type in AvatarWidget::refreshStatus()" << std::endl; @@ -217,10 +237,10 @@ void AvatarWidget::refreshStatus() { switch (dcpinfo.status) { - case RS_DISTANT_CHAT_STATUS_CAN_TALK : status = RS_STATUS_ONLINE ; break; + case RS_DISTANT_CHAT_STATUS_CAN_TALK : status = RsStatusValue::RS_STATUS_ONLINE ; break; case RS_DISTANT_CHAT_STATUS_UNKNOWN : // Fall-through case RS_DISTANT_CHAT_STATUS_TUNNEL_DN : // Fall-through - case RS_DISTANT_CHAT_STATUS_REMOTELY_CLOSED : status = RS_STATUS_OFFLINE; + case RS_DISTANT_CHAT_STATUS_REMOTELY_CLOSED : status = RsStatusValue::RS_STATUS_OFFLINE; } } else @@ -238,20 +258,20 @@ void AvatarWidget::refreshStatus() } } -void AvatarWidget::updateStatus(const QString& peerId, int status) +void AvatarWidget::updateStatus(const QString& peerId, RsStatusValue status) { if (mId.isPeerId() && mId.toPeerId() == RsPeerId(peerId.toStdString())) updateStatus(status) ; } -void AvatarWidget::updateStatus(int status) +void AvatarWidget::updateStatus(RsStatusValue status) { if (mFrameType != STATUS_FRAME) return; mPeerState = status; - setEnabled(((uint32_t) status == RS_STATUS_OFFLINE) ? false : true); + setEnabled((status == RsStatusValue::RS_STATUS_OFFLINE) ? false : true); RsApplication::refreshStyleSheet(this, false); } diff --git a/retroshare-gui/src/gui/common/AvatarWidget.h b/retroshare-gui/src/gui/common/AvatarWidget.h index e3b90022b..4e81b3ef1 100644 --- a/retroshare-gui/src/gui/common/AvatarWidget.h +++ b/retroshare-gui/src/gui/common/AvatarWidget.h @@ -24,7 +24,9 @@ #include #include #include +#include #include +#include namespace Ui { class AvatarWidget; @@ -57,14 +59,14 @@ protected: void mouseReleaseEvent(QMouseEvent *event); private slots: - void updateStatus(const QString& peerId, int status); + void updateStatus(const QString& peerId, RsStatusValue status); void updateAvatar(const QString& peerId); void updateOwnAvatar(); private: void refreshAvatarImage() ; void refreshStatus(); - void updateStatus(int status); + void updateStatus(RsStatusValue status); QString defaultAvatar; Ui::AvatarWidget *ui; @@ -77,7 +79,9 @@ private: // bool isGpg : 1; } mFlag; FrameType mFrameType; - uint32_t mPeerState; + RsStatusValue mPeerState; + + RsEventsHandlerId_t mEventHandlerId; }; #endif // AVATARWIDGET_H diff --git a/retroshare-gui/src/gui/common/FriendListModel.cpp b/retroshare-gui/src/gui/common/FriendListModel.cpp index 9ea271f86..efab4243a 100644 --- a/retroshare-gui/src/gui/common/FriendListModel.cpp +++ b/retroshare-gui/src/gui/common/FriendListModel.cpp @@ -458,7 +458,7 @@ QVariant RsFriendListModel::statusRole(const EntryIndex& fmpe,int /*column*/) co StatusInfo status; rsStatus->getStatus(node->node_info.id, status); - return QVariant(status.status); + return QVariant((int)status.status); } return QVariant(); } @@ -603,7 +603,7 @@ QVariant RsFriendListModel::onlineRole(const EntryIndex& e, int /*col*/) const for(uint32_t i=0;ichild_node_indices.size();++i) if(mLocations[prof->child_node_indices[i]].node_info.state & RS_PEER_STATE_CONNECTED) - return QVariant(RS_STATUS_ONLINE); + return QVariant((int)RsStatusValue::RS_STATUS_ONLINE); } } break; @@ -626,12 +626,12 @@ QVariant RsFriendListModel::onlineRole(const EntryIndex& e, int /*col*/) const const HierarchicalNodeInformation *node = getNodeInfo(e); if(node && bool(node->node_info.state & RS_PEER_STATE_CONNECTED)) - return QVariant(RS_STATUS_ONLINE); + return QVariant((int)RsStatusValue::RS_STATUS_ONLINE); else - return QVariant(RS_STATUS_OFFLINE); + return QVariant((int)RsStatusValue::RS_STATUS_OFFLINE); } } - return QVariant(RS_STATUS_OFFLINE); + return QVariant((int)RsStatusValue::RS_STATUS_OFFLINE); } QVariant RsFriendListModel::fontRole(const EntryIndex& e, int col) const @@ -640,14 +640,14 @@ QVariant RsFriendListModel::fontRole(const EntryIndex& e, int col) const std::cerr << " font role " << e.type << ", (" << (int)e.group_index << ","<< (int)e.profile_index << ","<< (int)e.node_index << ") col="<< col<<": " << std::endl; #endif - int status = onlineRole(e,col).toInt(); + auto status = RsStatusValue(onlineRole(e,col).toInt()); switch (status) { - case RS_STATUS_AWAY: - case RS_STATUS_BUSY: - case RS_STATUS_ONLINE: - case RS_STATUS_INACTIVE: + case RsStatusValue::RS_STATUS_AWAY: + case RsStatusValue::RS_STATUS_BUSY: + case RsStatusValue::RS_STATUS_ONLINE: + case RsStatusValue::RS_STATUS_INACTIVE: { QFont font ; QTreeView* myParent = dynamic_cast(QAbstractItemModel::parent()); @@ -781,7 +781,7 @@ QVariant RsFriendListModel::displayRole(const EntryIndex& e, int col) const else { return QVariant(QString::fromUtf8(node->node_info.location.c_str())+"\n" - + "(" + StatusDefs::name(statusRole(e,col).toInt()) + ")"); + + "(" + StatusDefs::name(RsStatusValue(statusRole(e,col).toInt())) + ")"); } else return QVariant(QString::fromUtf8(node->node_info.location.c_str())); @@ -900,10 +900,10 @@ bool RsFriendListModel::getPeerOnlineStatus(const EntryIndex& e) const return (noded && (noded->node_info.state & RS_PEER_STATE_CONNECTED)); } -const RsFriendListModel::HierarchicalNodeInformation *RsFriendListModel::getBestNodeInformation(const HierarchicalProfileInformation *profileInfo, uint32_t *status) const +const RsFriendListModel::HierarchicalNodeInformation *RsFriendListModel::getBestNodeInformation(const HierarchicalProfileInformation *profileInfo, RsStatusValue *status) const { if (status) { - *status = RS_STATUS_OFFLINE; + *status = RsStatusValue::RS_STATUS_OFFLINE; } if (!profileInfo) { @@ -921,28 +921,28 @@ const RsFriendListModel::HierarchicalNodeInformation *RsFriendListModel::getBest int statusIndex = 0; switch (statusInfo.status) { - case RS_STATUS_OFFLINE: + case RsStatusValue::RS_STATUS_OFFLINE: statusIndex = 1; break; - case RS_STATUS_INACTIVE: + case RsStatusValue::RS_STATUS_INACTIVE: statusIndex = 2; break; - case RS_STATUS_AWAY: + case RsStatusValue::RS_STATUS_AWAY: statusIndex = 3; break; - case RS_STATUS_BUSY: + case RsStatusValue::RS_STATUS_BUSY: statusIndex = 4; break; - case RS_STATUS_ONLINE: + case RsStatusValue::RS_STATUS_ONLINE: statusIndex = 5; break; default: - std::cerr << "FriendListModel: Unknown status " << statusInfo.status << std::endl; + std::cerr << "FriendListModel: Unknown status " << (int)statusInfo.status << std::endl; } if (bestStatusIndex == 0 || statusIndex > bestStatusIndex) { @@ -999,7 +999,7 @@ QVariant RsFriendListModel::decorationRole(const EntryIndex& entry,int col) cons QPixmap sslAvatar; bool foundAvatar = false; const HierarchicalProfileInformation *hn = getProfileInfo(entry); - uint32_t status = RS_STATUS_OFFLINE; + RsStatusValue status = RsStatusValue::RS_STATUS_OFFLINE; const HierarchicalNodeInformation *bestNodeInformation = NULL; if (mDisplayStatusIcon) { @@ -1049,7 +1049,7 @@ QVariant RsFriendListModel::decorationRole(const EntryIndex& entry,int col) cons QPixmap sslAvatar; AvatarDefs::getAvatarFromSslId(RsPeerId(hn->node_info.id.toStdString()), sslAvatar); if (mDisplayStatusIcon) { - QPixmap sslOverlayIcon = FilesDefs::getPixmapFromQtResourcePath(StatusDefs::imageStatus(statusRole(entry, col).toInt())); + QPixmap sslOverlayIcon = FilesDefs::getPixmapFromQtResourcePath(StatusDefs::imageStatus(RsStatusValue(statusRole(entry, col).toInt()))); return QVariant(QIcon(createAvatar(sslAvatar, sslOverlayIcon))); } diff --git a/retroshare-gui/src/gui/common/FriendListModel.h b/retroshare-gui/src/gui/common/FriendListModel.h index e19a84f04..4020e6fc7 100644 --- a/retroshare-gui/src/gui/common/FriendListModel.h +++ b/retroshare-gui/src/gui/common/FriendListModel.h @@ -162,7 +162,7 @@ public: /* Color definitions (for standard see default.qss) */ QColor mTextColorGroup; - QColor mTextColorStatus[RS_STATUS_COUNT]; + QColor mTextColorStatus[(int)RsStatusValue::RS_STATUS_COUNT]; private: const HierarchicalGroupInformation *getGroupInfo (const EntryIndex&) const; @@ -223,7 +223,7 @@ private: uint32_t updateFilterStatus(ForumModelIndex i,int column,const QStringList& strings); - const HierarchicalNodeInformation *getBestNodeInformation(const HierarchicalProfileInformation *profileInfo, uint32_t *status = NULL) const; + const HierarchicalNodeInformation *getBestNodeInformation(const HierarchicalProfileInformation *profileInfo, RsStatusValue *status = NULL) const; QStringList mFilterStrings; FilterType mFilterType; diff --git a/retroshare-gui/src/gui/common/FriendSelectionWidget.cpp b/retroshare-gui/src/gui/common/FriendSelectionWidget.cpp index 3c7ba5a29..47cf2b802 100644 --- a/retroshare-gui/src/gui/common/FriendSelectionWidget.cpp +++ b/retroshare-gui/src/gui/common/FriendSelectionWidget.cpp @@ -255,7 +255,7 @@ static void initSslItem(QTreeWidgetItem *item, const RsPeerDetails &detail, cons QString name = PeerDefs::nameWithLocation(detail); item->setText(COLUMN_NAME, name); - int state = RS_STATUS_OFFLINE; + RsStatusValue state = RsStatusValue::RS_STATUS_OFFLINE; if (detail.state & RS_PEER_STATE_CONNECTED) { std::list::const_iterator it; for (it = statusInfo.begin(); it != statusInfo.end() ; ++it) { @@ -266,7 +266,7 @@ static void initSslItem(QTreeWidgetItem *item, const RsPeerDetails &detail, cons } } - if (state != (int) RS_STATUS_OFFLINE) { + if (state != RsStatusValue::RS_STATUS_OFFLINE) { item->setData(COLUMN_NAME, Qt::ForegroundRole, textColorOnline); } @@ -276,7 +276,7 @@ static void initSslItem(QTreeWidgetItem *item, const RsPeerDetails &detail, cons item->setData(COLUMN_NAME, ROLE_SORT_GROUP, 1); item->setData(COLUMN_NAME, ROLE_SORT_STANDARD_GROUP, 0); item->setData(COLUMN_NAME, ROLE_SORT_NAME, name); - item->setData(COLUMN_NAME, ROLE_SORT_STATE, state); + item->setData(COLUMN_NAME, ROLE_SORT_STATE, (int)state); } void FriendSelectionWidget::fillList() @@ -515,17 +515,17 @@ void FriendSelectionWidget::secured_fillList() sslIds.clear(); rsPeers->getAssociatedSSLIds(*gpgIt, sslIds); - int state = RS_STATUS_OFFLINE; + RsStatusValue state = RsStatusValue::RS_STATUS_OFFLINE; for (statusIt = statusInfo.begin(); statusIt != statusInfo.end() ; ++statusIt) { if (std::find(sslIds.begin(), sslIds.end(), statusIt->id) != sslIds.end()) { - if (statusIt->status != RS_STATUS_OFFLINE) { - state = RS_STATUS_ONLINE; + if (statusIt->status != RsStatusValue::RS_STATUS_OFFLINE) { + state = RsStatusValue::RS_STATUS_ONLINE; break; } } } - if (state != (int) RS_STATUS_OFFLINE) { + if (state != RsStatusValue::RS_STATUS_OFFLINE) { gpgItem->setData(COLUMN_NAME, Qt::ForegroundRole, textColorOnline()); } @@ -536,7 +536,7 @@ void FriendSelectionWidget::secured_fillList() gpgItem->setData(COLUMN_NAME, ROLE_SORT_GROUP, 1); gpgItem->setData(COLUMN_NAME, ROLE_SORT_STANDARD_GROUP, 0); gpgItem->setData(COLUMN_NAME, ROLE_SORT_NAME, name); - gpgItem->setData(COLUMN_NAME, ROLE_SORT_STATE, state); + gpgItem->setData(COLUMN_NAME, ROLE_SORT_STATE, (int)state); if (mListModus == MODUS_CHECK) { gpgItem->setCheckState(0, Qt::Unchecked); @@ -791,13 +791,13 @@ void FriendSelectionWidget::groupsChanged() } } -void FriendSelectionWidget::peerStatusChanged(const RsPeerId& peerid, int status) +void FriendSelectionWidget::peerStatusChanged(const RsPeerId& peerid, RsStatusValue status) { if(!isVisible()) return ; QString gpgId; - int gpgStatus = RS_STATUS_OFFLINE; + RsStatusValue gpgStatus = RsStatusValue::RS_STATUS_OFFLINE; if (mShowTypes & (SHOW_GPG | SHOW_NON_FRIEND_GPG)) { /* need gpg id and online state */ @@ -806,7 +806,7 @@ void FriendSelectionWidget::peerStatusChanged(const RsPeerId& peerid, int status { gpgId = QString::fromStdString(detail.gpg_id.toStdString()); - if (status == (int) RS_STATUS_OFFLINE) { + if (status == RsStatusValue::RS_STATUS_OFFLINE) { /* try other nodes */ std::list sslIds; rsPeers->getAssociatedSSLIds(detail.gpg_id, sslIds); @@ -817,15 +817,15 @@ void FriendSelectionWidget::peerStatusChanged(const RsPeerId& peerid, int status for (statusIt = statusInfo.begin(); statusIt != statusInfo.end() ; ++statusIt) { if (std::find(sslIds.begin(), sslIds.end(), statusIt->id) != sslIds.end()) { - if (statusIt->status != RS_STATUS_OFFLINE) { - gpgStatus = RS_STATUS_ONLINE; + if (statusIt->status != RsStatusValue::RS_STATUS_OFFLINE) { + gpgStatus = RsStatusValue::RS_STATUS_ONLINE; break; } } } } else { /* one node is online */ - gpgStatus = RS_STATUS_ONLINE; + gpgStatus = RsStatusValue::RS_STATUS_ONLINE; } } } @@ -845,7 +845,7 @@ void FriendSelectionWidget::peerStatusChanged(const RsPeerId& peerid, int status case IDTYPE_GPG: { if (item->data(COLUMN_DATA, ROLE_ID).toString() == gpgId) { - if (status != (int) RS_STATUS_OFFLINE) { + if (status != RsStatusValue::RS_STATUS_OFFLINE) { item->setData(COLUMN_NAME, Qt::ForegroundRole, textColorOnline()); } else { item->setData(COLUMN_NAME, Qt::ForegroundRole, QVariant()); @@ -853,7 +853,7 @@ void FriendSelectionWidget::peerStatusChanged(const RsPeerId& peerid, int status item->setIcon(COLUMN_NAME, FilesDefs::getIconFromQtResourcePath(StatusDefs::imageUser(gpgStatus))); - item->setData(COLUMN_NAME, ROLE_SORT_STATE, gpgStatus); + item->setData(COLUMN_NAME, ROLE_SORT_STATE, (int)gpgStatus); bFoundGPG = true; } @@ -863,7 +863,7 @@ void FriendSelectionWidget::peerStatusChanged(const RsPeerId& peerid, int status { if (RsPeerId(item->data(COLUMN_DATA, ROLE_ID).toString().toStdString()) == peerid) { - if (status != (int) RS_STATUS_OFFLINE) { + if (status != RsStatusValue::RS_STATUS_OFFLINE) { item->setData(COLUMN_NAME, Qt::ForegroundRole, textColorOnline()); } else { item->setData(COLUMN_NAME, Qt::ForegroundRole, QVariant()); @@ -871,7 +871,7 @@ void FriendSelectionWidget::peerStatusChanged(const RsPeerId& peerid, int status item->setIcon(COLUMN_NAME, FilesDefs::getIconFromQtResourcePath(StatusDefs::imageUser(status))); - item->setData(COLUMN_NAME, ROLE_SORT_STATE, status); + item->setData(COLUMN_NAME, ROLE_SORT_STATE, (int)status); bFoundSSL = true; } @@ -1274,7 +1274,7 @@ bool FriendSelectionWidget::isSortByState() void FriendSelectionWidget::filterConnected(bool filter) { - ui->friendList->filterMinValItems(COLUMN_NAME, filter ? RS_STATUS_AWAY : RS_STATUS_OFFLINE, ROLE_SORT_STATE); + ui->friendList->filterMinValItems(COLUMN_NAME, filter ? double(RsStatusValue::RS_STATUS_AWAY) : double(RsStatusValue::RS_STATUS_OFFLINE), ROLE_SORT_STATE); mActionFilterConnected->setChecked(filter); diff --git a/retroshare-gui/src/gui/common/FriendSelectionWidget.h b/retroshare-gui/src/gui/common/FriendSelectionWidget.h index c01c888e7..c9be4bf6b 100644 --- a/retroshare-gui/src/gui/common/FriendSelectionWidget.h +++ b/retroshare-gui/src/gui/common/FriendSelectionWidget.h @@ -25,6 +25,7 @@ #include #include "retroshare/rsevents.h" +#include "retroshare/rsstatus.h" #include #include "util/FontSizeHandler.h" @@ -137,7 +138,7 @@ public slots: void filterConnected(bool filter); private slots: - void peerStatusChanged(const RsPeerId &peerid, int status); + void peerStatusChanged(const RsPeerId &peerid, RsStatusValue status); void filterItems(const QString &text); void contextMenuRequested(const QPoint &pos); void itemDoubleClicked(QTreeWidgetItem *item, int column); diff --git a/retroshare-gui/src/gui/common/NewFriendList.cpp b/retroshare-gui/src/gui/common/NewFriendList.cpp index 86966d7fd..e2b920ec1 100644 --- a/retroshare-gui/src/gui/common/NewFriendList.cpp +++ b/retroshare-gui/src/gui/common/NewFriendList.cpp @@ -132,8 +132,8 @@ public: if(is_group_1 ^ is_group_2) // if the two are different, put the group first. return is_group_1 ; - bool online1 = (left .data(RsFriendListModel::OnlineRole).toInt() != RS_STATUS_OFFLINE); - bool online2 = (right.data(RsFriendListModel::OnlineRole).toInt() != RS_STATUS_OFFLINE); + bool online1 = (left .data(RsFriendListModel::OnlineRole).toInt() != (int)RsStatusValue::RS_STATUS_OFFLINE); + bool online2 = (right.data(RsFriendListModel::OnlineRole).toInt() != (int)RsStatusValue::RS_STATUS_OFFLINE); if((online1 != online2) && m_sortByState) return (m_header->sortIndicatorOrder()==Qt::AscendingOrder)?online1:online2 ; // always put online nodes first @@ -155,7 +155,7 @@ public: // Filter offline friends - if(!m_showOfflineNodes && (index.data(RsFriendListModel::OnlineRole).toInt() == RS_STATUS_OFFLINE)) + if(!m_showOfflineNodes && (RsStatusValue(index.data(RsFriendListModel::OnlineRole).toInt()) == RsStatusValue::RS_STATUS_OFFLINE)) return false; return index.data(RsFriendListModel::FilterRole).toString() == RsFriendListModel::FilterString ; @@ -204,7 +204,7 @@ NewFriendList::NewFriendList(QWidget */*parent*/) : /* RsAutoUpdatePage(5000,par rsEvents->registerEventsHandler( [this](std::shared_ptr 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())); +// connect(NotifyQt::getInstance(), SIGNAL(peerStatusChanged(QString,int)), this, SLOT(forceUpdateDisplay())); mModel = new RsFriendListModel(ui->peerTreeWidget); mProxyModel = new FriendListSortFilterProxyModel(ui->peerTreeWidget->header(),this); diff --git a/retroshare-gui/src/gui/common/NewFriendList.h b/retroshare-gui/src/gui/common/NewFriendList.h index 18a7d4b97..204d984d5 100644 --- a/retroshare-gui/src/gui/common/NewFriendList.h +++ b/retroshare-gui/src/gui/common/NewFriendList.h @@ -66,18 +66,18 @@ public: //void updateDisplay() override; QColor textColorGroup() const { return mModel->mTextColorGroup; } - QColor textColorStatusOffline() const { return mModel->mTextColorStatus[RS_STATUS_OFFLINE ]; } - QColor textColorStatusAway() const { return mModel->mTextColorStatus[RS_STATUS_AWAY ]; } - QColor textColorStatusBusy() const { return mModel->mTextColorStatus[RS_STATUS_BUSY ]; } - QColor textColorStatusOnline() const { return mModel->mTextColorStatus[RS_STATUS_ONLINE ]; } - QColor textColorStatusInactive() const { return mModel->mTextColorStatus[RS_STATUS_INACTIVE]; } + QColor textColorStatusOffline() const { return mModel->mTextColorStatus[(uint8_t)RsStatusValue::RS_STATUS_OFFLINE ]; } + QColor textColorStatusAway() const { return mModel->mTextColorStatus[(uint8_t)RsStatusValue::RS_STATUS_AWAY ]; } + QColor textColorStatusBusy() const { return mModel->mTextColorStatus[(uint8_t)RsStatusValue::RS_STATUS_BUSY ]; } + QColor textColorStatusOnline() const { return mModel->mTextColorStatus[(uint8_t)RsStatusValue::RS_STATUS_ONLINE ]; } + QColor textColorStatusInactive() const { return mModel->mTextColorStatus[(uint8_t)RsStatusValue::RS_STATUS_INACTIVE]; } void setTextColorGroup(QColor color) { mModel->mTextColorGroup = color; } - void setTextColorStatusOffline(QColor color) { mModel->mTextColorStatus[RS_STATUS_OFFLINE ] = color; } - void setTextColorStatusAway(QColor color) { mModel->mTextColorStatus[RS_STATUS_AWAY ] = color; } - void setTextColorStatusBusy(QColor color) { mModel->mTextColorStatus[RS_STATUS_BUSY ] = color; } - void setTextColorStatusOnline(QColor color) { mModel->mTextColorStatus[RS_STATUS_ONLINE ] = color; } - void setTextColorStatusInactive(QColor color) { mModel->mTextColorStatus[RS_STATUS_INACTIVE] = color; } + void setTextColorStatusOffline(QColor color) { mModel->mTextColorStatus[(uint8_t)RsStatusValue::RS_STATUS_OFFLINE ] = color; } + void setTextColorStatusAway(QColor color) { mModel->mTextColorStatus[(uint8_t)RsStatusValue::RS_STATUS_AWAY ] = color; } + void setTextColorStatusBusy(QColor color) { mModel->mTextColorStatus[(uint8_t)RsStatusValue::RS_STATUS_BUSY ] = color; } + void setTextColorStatusOnline(QColor color) { mModel->mTextColorStatus[(uint8_t)RsStatusValue::RS_STATUS_ONLINE ] = color; } + void setTextColorStatusInactive(QColor color) { mModel->mTextColorStatus[(uint8_t)RsStatusValue::RS_STATUS_INACTIVE] = color; } public slots: void filterItems(const QString &text); diff --git a/retroshare-gui/src/gui/common/StatusDefs.cpp b/retroshare-gui/src/gui/common/StatusDefs.cpp index 5d0db8395..a9fa4e3f9 100644 --- a/retroshare-gui/src/gui/common/StatusDefs.cpp +++ b/retroshare-gui/src/gui/common/StatusDefs.cpp @@ -24,118 +24,124 @@ #include "StatusDefs.h" -QString StatusDefs::name(unsigned int status) +QString StatusDefs::name(RsStatusValue status) { switch (status) { - case RS_STATUS_OFFLINE: + default: + case RsStatusValue::RS_STATUS_OFFLINE: return qApp->translate("StatusDefs", "Offline"); - case RS_STATUS_AWAY: + case RsStatusValue::RS_STATUS_AWAY: return qApp->translate("StatusDefs", "Away"); - case RS_STATUS_BUSY: + case RsStatusValue::RS_STATUS_BUSY: return qApp->translate("StatusDefs", "Busy"); - case RS_STATUS_ONLINE: + case RsStatusValue::RS_STATUS_ONLINE: return qApp->translate("StatusDefs", "Online"); - case RS_STATUS_INACTIVE: + case RsStatusValue::RS_STATUS_INACTIVE: return qApp->translate("StatusDefs", "Idle"); } - std::cerr << "StatusDefs::name: Unknown status requested " << status; + RsErr() << "StatusDefs::name: Unknown status requested " << (int)status; return ""; } -const char *StatusDefs::imageIM(unsigned int status) +const char *StatusDefs::imageIM(RsStatusValue status) { switch (status) { - case RS_STATUS_OFFLINE: + default: + case RsStatusValue::RS_STATUS_OFFLINE: return ":/images/im-user-offline.png"; - case RS_STATUS_AWAY: + case RsStatusValue::RS_STATUS_AWAY: return ":/images/im-user-away.png"; - case RS_STATUS_BUSY: + case RsStatusValue::RS_STATUS_BUSY: return ":/images/im-user-busy.png"; - case RS_STATUS_ONLINE: + case RsStatusValue::RS_STATUS_ONLINE: return ":/images/im-user.png"; - case RS_STATUS_INACTIVE: + case RsStatusValue::RS_STATUS_INACTIVE: return ":/images/im-user-inactive.png"; } - std::cerr << "StatusDefs::imageIM: Unknown status requested " << status; + RsErr() << "StatusDefs::imageIM: Unknown status requested " << (int)status; return ""; } -const char *StatusDefs::imageUser(unsigned int status) +const char *StatusDefs::imageUser(RsStatusValue status) { switch (status) { - case RS_STATUS_OFFLINE: + default: + case RsStatusValue::RS_STATUS_OFFLINE: return ":/images/user/identityoffline24.png"; - case RS_STATUS_AWAY: + case RsStatusValue::RS_STATUS_AWAY: return ":/images/user/identity24away.png"; - case RS_STATUS_BUSY: + case RsStatusValue::RS_STATUS_BUSY: return ":/images/user/identity24busy.png"; - case RS_STATUS_ONLINE: + case RsStatusValue::RS_STATUS_ONLINE: return ":/images/user/identity24.png"; - case RS_STATUS_INACTIVE: + case RsStatusValue::RS_STATUS_INACTIVE: return ":/images/user/identity24idle.png"; } - std::cerr << "StatusDefs::imageUser: Unknown status requested " << status; + RsErr() << "StatusDefs::imageUser: Unknown status requested " << (int)status; return ""; } -const char *StatusDefs::imageStatus(unsigned int status) +const char *StatusDefs::imageStatus(RsStatusValue status) { switch (status) { - case RS_STATUS_OFFLINE: + default: + case RsStatusValue::RS_STATUS_OFFLINE: return ":/icons/user-offline_64.png"; - case RS_STATUS_AWAY: + case RsStatusValue::RS_STATUS_AWAY: return ":/icons/user-away_64.png"; - case RS_STATUS_BUSY: + case RsStatusValue::RS_STATUS_BUSY: return ":/icons/user-busy_64.png"; - case RS_STATUS_ONLINE: + case RsStatusValue::RS_STATUS_ONLINE: return ":/icons/user-online_64.png"; - case RS_STATUS_INACTIVE: + case RsStatusValue::RS_STATUS_INACTIVE: return ":/icons/user-away-extended_64.png"; } - std::cerr << "StatusDefs::imageUser: Unknown status requested " << status; + RsErr() << "StatusDefs::imageUser: Unknown status requested " << (int)status; return ""; } -QString StatusDefs::tooltip(unsigned int status) +QString StatusDefs::tooltip(RsStatusValue status) { switch (status) { - case RS_STATUS_OFFLINE: + default: + case RsStatusValue::RS_STATUS_OFFLINE: return qApp->translate("StatusDefs", "Friend is offline"); - case RS_STATUS_AWAY: + case RsStatusValue::RS_STATUS_AWAY: return qApp->translate("StatusDefs", "Friend is away"); - case RS_STATUS_BUSY: + case RsStatusValue::RS_STATUS_BUSY: return qApp->translate("StatusDefs", "Friend is busy"); - case RS_STATUS_ONLINE: + case RsStatusValue::RS_STATUS_ONLINE: return qApp->translate("StatusDefs", "Friend is online"); - case RS_STATUS_INACTIVE: + case RsStatusValue::RS_STATUS_INACTIVE: return qApp->translate("StatusDefs", "Friend is idle"); } - std::cerr << "StatusDefs::tooltip: Unknown status requested " << status; + RsErr() << "StatusDefs::tooltip: Unknown status requested " << (int)status; return ""; } -QFont StatusDefs::font(unsigned int status) +QFont StatusDefs::font(RsStatusValue status) { QFont font; switch (status) { - case RS_STATUS_AWAY: - case RS_STATUS_BUSY: - case RS_STATUS_ONLINE: - case RS_STATUS_INACTIVE: + default: + case RsStatusValue::RS_STATUS_AWAY: + case RsStatusValue::RS_STATUS_BUSY: + case RsStatusValue::RS_STATUS_ONLINE: + case RsStatusValue::RS_STATUS_INACTIVE: font.setBold(true); return font; - case RS_STATUS_OFFLINE: + case RsStatusValue::RS_STATUS_OFFLINE: font.setBold(false); return font; } - std::cerr << "StatusDefs::font: Unknown status requested " << status; + RsErr() << "StatusDefs::font: Unknown status requested " << (int)status; return font; } diff --git a/retroshare-gui/src/gui/common/StatusDefs.h b/retroshare-gui/src/gui/common/StatusDefs.h index b922e28e4..3a167930b 100644 --- a/retroshare-gui/src/gui/common/StatusDefs.h +++ b/retroshare-gui/src/gui/common/StatusDefs.h @@ -24,18 +24,20 @@ #include #include +#include "retroshare/rsstatus.h" + struct RsPeerDetails; class StatusDefs { public: - static QString name(unsigned int status); - static const char* imageIM(unsigned int status); - static const char* imageUser(unsigned int status); - static const char* imageStatus(unsigned int status); - static QString tooltip(unsigned int status); + static QString name(RsStatusValue status); + static const char* imageIM(RsStatusValue status); + static const char* imageUser(RsStatusValue status); + static const char* imageStatus(RsStatusValue status); + static QString tooltip(RsStatusValue status); - static QFont font(unsigned int status); + static QFont font(RsStatusValue status); static QString peerStateString(int peerState); static QString connectStateString(RsPeerDetails &details); diff --git a/retroshare-gui/src/gui/msgs/MessageComposer.cpp b/retroshare-gui/src/gui/msgs/MessageComposer.cpp index 0ee408685..a12bab40b 100644 --- a/retroshare-gui/src/gui/msgs/MessageComposer.cpp +++ b/retroshare-gui/src/gui/msgs/MessageComposer.cpp @@ -65,6 +65,7 @@ #include "util/misc.h" #include "util/DateTime.h" #include "util/HandleRichText.h" +#include "util/qtthreadsutils.h" #include "util/QtVersion.h" #include "textformat.h" #include "TagsMenu.h" @@ -214,7 +215,21 @@ MessageComposer::MessageComposer(QWidget *parent, Qt::WindowFlags flags) connect(ui.addBccButton, SIGNAL(clicked()), this, SLOT(addBcc())); connect(ui.addRecommendButton, SIGNAL(clicked()), this, SLOT(addRecommend())); - connect(NotifyQt::getInstance(), SIGNAL(peerStatusChanged(QString,int)), this, SLOT(peerStatusChanged(QString,int))); + //connect(NotifyQt::getInstance(), SIGNAL(peerStatusChanged(QString,int)), this, SLOT(peerStatusChanged(QString,int))); + + rsEvents->registerEventsHandler( [this](std::shared_ptr e) + { + RsQThreadUtils::postToObject([=](){ + auto fe = dynamic_cast(e.get()); + + if(!fe || fe->mEventCode != RsFriendListEventCode::NODE_STATUS_CHANGED) + return; + + peerStatusChanged(QString::fromStdString(fe->mSslId.toStdString()),fe->mStatus); + + }, this ); + },mEventHandlerId,RsEventType::FRIEND_LIST); + connect(ui.friendSelectionWidget, SIGNAL(contentChanged()), this, SLOT(buildCompleter())); connect(ui.friendSelectionWidget, SIGNAL(doubleClicked(int,QString)), this, SLOT(addTo())); connect(ui.friendSelectionWidget, SIGNAL(itemSelectionChanged()), this, SLOT(friendSelectionChanged())); @@ -420,6 +435,7 @@ MessageComposer::MessageComposer(QWidget *parent, Qt::WindowFlags flags) MessageComposer::~MessageComposer() { + rsEvents->unregisterEventsHandler(mEventHandlerId); delete(m_compareRole); } @@ -811,7 +827,7 @@ void MessageComposer::buildCompleter() setNewCompleter(ui.recipientWidget, m_completer); } -void MessageComposer::peerStatusChanged(const QString& peer_id, int status) +void MessageComposer::peerStatusChanged(const QString& peer_id, RsStatusValue status) { int rowCount = ui.recipientWidget->rowCount(); int row; diff --git a/retroshare-gui/src/gui/msgs/MessageComposer.h b/retroshare-gui/src/gui/msgs/MessageComposer.h index 27bf28458..121578f3f 100644 --- a/retroshare-gui/src/gui/msgs/MessageComposer.h +++ b/retroshare-gui/src/gui/msgs/MessageComposer.h @@ -157,7 +157,7 @@ private slots: void editingRecipientFinished(); void contactDetails(); - void peerStatusChanged(const QString& peer_id, int status); + void peerStatusChanged(const QString& peer_id, RsStatusValue status); void friendSelectionChanged(); void tagAboutToShow(); @@ -274,6 +274,7 @@ private: Ui::MessageComposer ui; std::list _recList ; + RsEventsHandlerId_t mEventHandlerId; }; #endif diff --git a/retroshare-gui/src/gui/notifyqt.cpp b/retroshare-gui/src/gui/notifyqt.cpp index e230b2eb1..d3fe147a8 100644 --- a/retroshare-gui/src/gui/notifyqt.cpp +++ b/retroshare-gui/src/gui/notifyqt.cpp @@ -333,6 +333,7 @@ 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) { @@ -364,6 +365,7 @@ void NotifyQt::notifyPeerStatusChangedSummary() emit peerStatusChangedSummary(); } +#endif void NotifyQt::notifyOwnStatusMessageChanged() { diff --git a/retroshare-gui/src/gui/notifyqt.h b/retroshare-gui/src/gui/notifyqt.h index 6e0adb7d8..eb52fad1a 100644 --- a/retroshare-gui/src/gui/notifyqt.h +++ b/retroshare-gui/src/gui/notifyqt.h @@ -79,9 +79,9 @@ class NotifyQt: public QObject, public NotifyClient virtual void notifyOwnStatusMessageChanged() ; 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); +// virtual void notifyPeerStatusChanged(const std::string& peer_id, uint32_t state); /* one or more peers has changed the states */ - virtual void notifyPeerStatusChangedSummary(); +// virtual void notifyPeerStatusChangedSummary(); virtual void notifyHistoryChanged(uint32_t msgId, int type); @@ -122,8 +122,8 @@ class NotifyQt: public QObject, public NotifyClient void ownStatusMessageChanged() 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 peerStatusChanged(const QString& /* peer_id */, int /* status */); +// void peerStatusChangedSummary() const; void gxsChange(const RsGxsChanges& /* changes */); void chatMessageReceived(ChatMessage msg); // void groupsChanged(int type) const ;