mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-12-14 08:08:53 -05:00
switched PopupDistantChatDialog to rsEvents
This commit is contained in:
parent
296b612965
commit
7873082d28
2 changed files with 55 additions and 34 deletions
|
|
@ -27,6 +27,7 @@
|
|||
#include <unistd.h>
|
||||
|
||||
#include "gui/common/FilesDefs.h"
|
||||
#include "util/qtthreadsutils.h"
|
||||
#include <retroshare/rsstatus.h>
|
||||
#include <retroshare/rspeers.h>
|
||||
#include <retroshare/rsidentity.h>
|
||||
|
|
@ -42,8 +43,7 @@
|
|||
|
||||
PopupDistantChatDialog::~PopupDistantChatDialog()
|
||||
{
|
||||
_update_timer->stop() ;
|
||||
delete _update_timer ;
|
||||
rsEvents->unregisterEventsHandler(mEventHandlerId);
|
||||
}
|
||||
|
||||
PopupDistantChatDialog::PopupDistantChatDialog(const DistantChatPeerId& tunnel_id,QWidget *parent, Qt::WindowFlags flags)
|
||||
|
|
@ -52,18 +52,16 @@ PopupDistantChatDialog::PopupDistantChatDialog(const DistantChatPeerId& tunnel_i
|
|||
_tunnel_id = tunnel_id ;
|
||||
|
||||
_status_label = new QToolButton ;
|
||||
_update_timer = new QTimer ;
|
||||
|
||||
_status_label->setAutoRaise(true);
|
||||
_status_label->setIconSize(QSize(24,24));
|
||||
|
||||
_update_timer->setInterval(1000) ;
|
||||
QObject::connect(_update_timer,SIGNAL(timeout()),this,SLOT(updateDisplay())) ;
|
||||
|
||||
_update_timer->start() ;
|
||||
mEventHandlerId = 0;
|
||||
rsEvents->registerEventsHandler( [this](std::shared_ptr<const RsEvent> event)
|
||||
{
|
||||
RsQThreadUtils::postToObject([=](){ handleEvent_main_thread(event); }, this );
|
||||
}, mEventHandlerId, RsEventType::CHAT_SERVICE );
|
||||
|
||||
getChatWidget()->addTopBarWidget(_status_label) ;
|
||||
updateDisplay() ;
|
||||
}
|
||||
|
||||
void PopupDistantChatDialog::init(const ChatId &chat_id, const QString &/*title*/)
|
||||
|
|
@ -89,30 +87,46 @@ void PopupDistantChatDialog::init(const ChatId &chat_id, const QString &/*title*
|
|||
|
||||
ui.ownAvatarWidget->setOwnId() ; // sets the flag
|
||||
ui.ownAvatarWidget->setId(chat_id) ; // sets the actual Id
|
||||
ui.avatarWidget->setId(chat_id);
|
||||
|
||||
_status_label->setIcon(FilesDefs::getIconFromQtResourcePath(IMAGE_GRY_LED));
|
||||
auto msg = tr("Remote status unknown.");
|
||||
_status_label->setToolTip(msg);
|
||||
getChatWidget()->updateStatusString("%1", msg, true);
|
||||
getChatWidget()->blockSending(tr( "Can't send message immediately, "
|
||||
"because there is no tunnel "
|
||||
"available." ));
|
||||
setPeerStatus(RsStatusValue::RS_STATUS_OFFLINE);
|
||||
}
|
||||
|
||||
void PopupDistantChatDialog::updateDisplay()
|
||||
void PopupDistantChatDialog::handleEvent_main_thread(std::shared_ptr<const RsEvent> e)
|
||||
{
|
||||
if(RsAutoUpdatePage::eventsLocked()) // we need to do that by end, because it's not possible to derive from both PopupChatDialog and RsAutoUpdatePage
|
||||
return ; // which both derive from QObject. Signals-slot connexions won't work anymore.
|
||||
auto ev = dynamic_cast<const RsDistantChatEvent*>(e.get());
|
||||
|
||||
if(!isVisible())
|
||||
if(!ev)
|
||||
return;
|
||||
|
||||
//std::cerr << "Checking tunnel..." ;
|
||||
// make sure about the tunnel status
|
||||
//
|
||||
if(ev->mId != _tunnel_id)
|
||||
return;
|
||||
|
||||
DistantChatPeerInfo tinfo;
|
||||
rsMsgs->getDistantChatStatus(_tunnel_id,tinfo) ;
|
||||
|
||||
ui.avatarWidget->setId(ChatId(_tunnel_id));
|
||||
std::cerr << "Got event!" << std::endl;
|
||||
std::cerr << "Event code = " << (int)ev->mEventCode << std::endl;
|
||||
|
||||
QString msg;
|
||||
|
||||
switch(tinfo.status)
|
||||
switch(ev->mEventCode)
|
||||
{
|
||||
case RS_DISTANT_CHAT_STATUS_UNKNOWN:
|
||||
case RsDistantChatEventCode::TUNNEL_STATUS_CONNECTION_REFUSED:
|
||||
|
||||
_status_label->setIcon(FilesDefs::getIconFromQtResourcePath(IMAGE_RED_LED));
|
||||
msg = tr("Connexion refused.");
|
||||
_status_label->setToolTip(msg);
|
||||
getChatWidget()->updateStatusString("%1", msg, true);
|
||||
getChatWidget()->blockSending(tr( "The distant peer refuses distant chat." ));
|
||||
setPeerStatus(RsStatusValue::RS_STATUS_OFFLINE);
|
||||
break ;
|
||||
|
||||
case RsDistantChatEventCode::TUNNEL_STATUS_UNKNOWN:
|
||||
|
||||
_status_label->setIcon(FilesDefs::getIconFromQtResourcePath(IMAGE_GRY_LED));
|
||||
msg = tr("Remote status unknown.");
|
||||
|
|
@ -123,7 +137,7 @@ void PopupDistantChatDialog::updateDisplay()
|
|||
"available." ));
|
||||
setPeerStatus(RsStatusValue::RS_STATUS_OFFLINE);
|
||||
break ;
|
||||
case RS_DISTANT_CHAT_STATUS_REMOTELY_CLOSED:
|
||||
case RsDistantChatEventCode::TUNNEL_STATUS_REMOTELY_CLOSED:
|
||||
std::cerr << "Chat remotely closed. " << std::endl;
|
||||
_status_label->setIcon(FilesDefs::getIconFromQtResourcePath(IMAGE_RED_LED));
|
||||
_status_label->setToolTip( QObject::tr("Distant peer has closed the chat") );
|
||||
|
|
@ -134,23 +148,30 @@ void PopupDistantChatDialog::updateDisplay()
|
|||
setPeerStatus(RsStatusValue::RS_STATUS_OFFLINE) ;
|
||||
break ;
|
||||
|
||||
case RS_DISTANT_CHAT_STATUS_TUNNEL_DN:
|
||||
case RsDistantChatEventCode::TUNNEL_STATUS_TUNNEL_DN:
|
||||
|
||||
_status_label->setIcon(FilesDefs::getIconFromQtResourcePath(IMAGE_YEL_LED));
|
||||
msg = QObject::tr( "Tunnel is pending");
|
||||
|
||||
{
|
||||
DistantChatPeerInfo tinfo;
|
||||
rsMsgs->getDistantChatStatus(_tunnel_id,tinfo) ;
|
||||
|
||||
if(tinfo.pending_items > 0)
|
||||
msg += QObject::tr("(some undelivered messages)") ; // we cannot use the pending_items count because it accounts for ACKS and keep alive packets as well.
|
||||
}
|
||||
|
||||
_status_label->setToolTip(msg);
|
||||
getChatWidget()->updateStatusString("%1", msg, true);
|
||||
getChatWidget()->blockSending(msg);
|
||||
setPeerStatus(RsStatusValue::RS_STATUS_OFFLINE);
|
||||
break;
|
||||
case RS_DISTANT_CHAT_STATUS_CAN_TALK:
|
||||
|
||||
case RsDistantChatEventCode::TUNNEL_STATUS_CAN_TALK:
|
||||
|
||||
_status_label->setIcon(FilesDefs::getIconFromQtResourcePath(IMAGE_GRN_LED));
|
||||
msg = QObject::tr( "End-to-end encrypted conversation established");
|
||||
getChatWidget()->updateStatusString("%1", msg, true);
|
||||
_status_label->setToolTip(msg);
|
||||
getChatWidget()->unblockSending();
|
||||
setPeerStatus(RsStatusValue::RS_STATUS_ONLINE);
|
||||
|
|
|
|||
|
|
@ -25,7 +25,6 @@
|
|||
#include <retroshare/rsgxstunnel.h>
|
||||
#include "PopupChatDialog.h"
|
||||
|
||||
class QTimer ;
|
||||
class QCloseEvent ;
|
||||
|
||||
class PopupDistantChatDialog: public PopupChatDialog
|
||||
|
|
@ -44,15 +43,16 @@ class PopupDistantChatDialog: public PopupChatDialog
|
|||
virtual QString getPeerName(const ChatId &id, QString& additional_info) const ;
|
||||
virtual QString getOwnName() const;
|
||||
|
||||
protected slots:
|
||||
void updateDisplay() ; // overloads RsAutoUpdatePage
|
||||
protected:
|
||||
void handleEvent_main_thread(std::shared_ptr<const RsEvent> e) ; // overloads RsAutoUpdatePage
|
||||
|
||||
private:
|
||||
QTimer *_update_timer ;
|
||||
DistantChatPeerId _tunnel_id ;
|
||||
QToolButton *_status_label ;
|
||||
|
||||
friend class ChatDialog;
|
||||
|
||||
RsEventsHandlerId_t mEventHandlerId;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue