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 <unistd.h>
|
||||||
|
|
||||||
#include "gui/common/FilesDefs.h"
|
#include "gui/common/FilesDefs.h"
|
||||||
|
#include "util/qtthreadsutils.h"
|
||||||
#include <retroshare/rsstatus.h>
|
#include <retroshare/rsstatus.h>
|
||||||
#include <retroshare/rspeers.h>
|
#include <retroshare/rspeers.h>
|
||||||
#include <retroshare/rsidentity.h>
|
#include <retroshare/rsidentity.h>
|
||||||
|
|
@ -42,8 +43,7 @@
|
||||||
|
|
||||||
PopupDistantChatDialog::~PopupDistantChatDialog()
|
PopupDistantChatDialog::~PopupDistantChatDialog()
|
||||||
{
|
{
|
||||||
_update_timer->stop() ;
|
rsEvents->unregisterEventsHandler(mEventHandlerId);
|
||||||
delete _update_timer ;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PopupDistantChatDialog::PopupDistantChatDialog(const DistantChatPeerId& tunnel_id,QWidget *parent, Qt::WindowFlags flags)
|
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 ;
|
_tunnel_id = tunnel_id ;
|
||||||
|
|
||||||
_status_label = new QToolButton ;
|
_status_label = new QToolButton ;
|
||||||
_update_timer = new QTimer ;
|
|
||||||
|
|
||||||
_status_label->setAutoRaise(true);
|
_status_label->setAutoRaise(true);
|
||||||
_status_label->setIconSize(QSize(24,24));
|
_status_label->setIconSize(QSize(24,24));
|
||||||
|
|
||||||
_update_timer->setInterval(1000) ;
|
mEventHandlerId = 0;
|
||||||
QObject::connect(_update_timer,SIGNAL(timeout()),this,SLOT(updateDisplay())) ;
|
rsEvents->registerEventsHandler( [this](std::shared_ptr<const RsEvent> event)
|
||||||
|
{
|
||||||
|
RsQThreadUtils::postToObject([=](){ handleEvent_main_thread(event); }, this );
|
||||||
|
}, mEventHandlerId, RsEventType::CHAT_SERVICE );
|
||||||
|
|
||||||
_update_timer->start() ;
|
getChatWidget()->addTopBarWidget(_status_label) ;
|
||||||
|
|
||||||
getChatWidget()->addTopBarWidget(_status_label) ;
|
|
||||||
updateDisplay() ;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PopupDistantChatDialog::init(const ChatId &chat_id, const QString &/*title*/)
|
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->setOwnId() ; // sets the flag
|
||||||
ui.ownAvatarWidget->setId(chat_id) ; // sets the actual Id
|
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
|
auto ev = dynamic_cast<const RsDistantChatEvent*>(e.get());
|
||||||
return ; // which both derive from QObject. Signals-slot connexions won't work anymore.
|
|
||||||
|
|
||||||
if(!isVisible())
|
if(!ev)
|
||||||
return ;
|
return;
|
||||||
|
|
||||||
//std::cerr << "Checking tunnel..." ;
|
if(ev->mId != _tunnel_id)
|
||||||
// make sure about the tunnel status
|
return;
|
||||||
//
|
|
||||||
|
|
||||||
DistantChatPeerInfo tinfo;
|
std::cerr << "Got event!" << std::endl;
|
||||||
rsMsgs->getDistantChatStatus(_tunnel_id,tinfo) ;
|
std::cerr << "Event code = " << (int)ev->mEventCode << std::endl;
|
||||||
|
|
||||||
ui.avatarWidget->setId(ChatId(_tunnel_id));
|
|
||||||
|
|
||||||
QString msg;
|
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));
|
_status_label->setIcon(FilesDefs::getIconFromQtResourcePath(IMAGE_GRY_LED));
|
||||||
msg = tr("Remote status unknown.");
|
msg = tr("Remote status unknown.");
|
||||||
|
|
@ -123,7 +137,7 @@ void PopupDistantChatDialog::updateDisplay()
|
||||||
"available." ));
|
"available." ));
|
||||||
setPeerStatus(RsStatusValue::RS_STATUS_OFFLINE);
|
setPeerStatus(RsStatusValue::RS_STATUS_OFFLINE);
|
||||||
break ;
|
break ;
|
||||||
case RS_DISTANT_CHAT_STATUS_REMOTELY_CLOSED:
|
case RsDistantChatEventCode::TUNNEL_STATUS_REMOTELY_CLOSED:
|
||||||
std::cerr << "Chat remotely closed. " << std::endl;
|
std::cerr << "Chat remotely closed. " << std::endl;
|
||||||
_status_label->setIcon(FilesDefs::getIconFromQtResourcePath(IMAGE_RED_LED));
|
_status_label->setIcon(FilesDefs::getIconFromQtResourcePath(IMAGE_RED_LED));
|
||||||
_status_label->setToolTip( QObject::tr("Distant peer has closed the chat") );
|
_status_label->setToolTip( QObject::tr("Distant peer has closed the chat") );
|
||||||
|
|
@ -134,24 +148,31 @@ void PopupDistantChatDialog::updateDisplay()
|
||||||
setPeerStatus(RsStatusValue::RS_STATUS_OFFLINE) ;
|
setPeerStatus(RsStatusValue::RS_STATUS_OFFLINE) ;
|
||||||
break ;
|
break ;
|
||||||
|
|
||||||
case RS_DISTANT_CHAT_STATUS_TUNNEL_DN:
|
case RsDistantChatEventCode::TUNNEL_STATUS_TUNNEL_DN:
|
||||||
|
|
||||||
_status_label->setIcon(FilesDefs::getIconFromQtResourcePath(IMAGE_YEL_LED));
|
_status_label->setIcon(FilesDefs::getIconFromQtResourcePath(IMAGE_YEL_LED));
|
||||||
msg = QObject::tr( "Tunnel is pending");
|
msg = QObject::tr( "Tunnel is pending");
|
||||||
|
|
||||||
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.
|
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);
|
_status_label->setToolTip(msg);
|
||||||
getChatWidget()->updateStatusString("%1", msg, true);
|
getChatWidget()->updateStatusString("%1", msg, true);
|
||||||
getChatWidget()->blockSending(msg);
|
getChatWidget()->blockSending(msg);
|
||||||
setPeerStatus(RsStatusValue::RS_STATUS_OFFLINE);
|
setPeerStatus(RsStatusValue::RS_STATUS_OFFLINE);
|
||||||
break;
|
break;
|
||||||
case RS_DISTANT_CHAT_STATUS_CAN_TALK:
|
|
||||||
|
case RsDistantChatEventCode::TUNNEL_STATUS_CAN_TALK:
|
||||||
|
|
||||||
_status_label->setIcon(FilesDefs::getIconFromQtResourcePath(IMAGE_GRN_LED));
|
_status_label->setIcon(FilesDefs::getIconFromQtResourcePath(IMAGE_GRN_LED));
|
||||||
msg = QObject::tr( "End-to-end encrypted conversation established");
|
msg = QObject::tr( "End-to-end encrypted conversation established");
|
||||||
_status_label->setToolTip(msg);
|
getChatWidget()->updateStatusString("%1", msg, true);
|
||||||
|
_status_label->setToolTip(msg);
|
||||||
getChatWidget()->unblockSending();
|
getChatWidget()->unblockSending();
|
||||||
setPeerStatus(RsStatusValue::RS_STATUS_ONLINE);
|
setPeerStatus(RsStatusValue::RS_STATUS_ONLINE);
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,6 @@
|
||||||
#include <retroshare/rsgxstunnel.h>
|
#include <retroshare/rsgxstunnel.h>
|
||||||
#include "PopupChatDialog.h"
|
#include "PopupChatDialog.h"
|
||||||
|
|
||||||
class QTimer ;
|
|
||||||
class QCloseEvent ;
|
class QCloseEvent ;
|
||||||
|
|
||||||
class PopupDistantChatDialog: public PopupChatDialog
|
class PopupDistantChatDialog: public PopupChatDialog
|
||||||
|
|
@ -44,15 +43,16 @@ class PopupDistantChatDialog: public PopupChatDialog
|
||||||
virtual QString getPeerName(const ChatId &id, QString& additional_info) const ;
|
virtual QString getPeerName(const ChatId &id, QString& additional_info) const ;
|
||||||
virtual QString getOwnName() const;
|
virtual QString getOwnName() const;
|
||||||
|
|
||||||
protected slots:
|
protected:
|
||||||
void updateDisplay() ; // overloads RsAutoUpdatePage
|
void handleEvent_main_thread(std::shared_ptr<const RsEvent> e) ; // overloads RsAutoUpdatePage
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QTimer *_update_timer ;
|
|
||||||
DistantChatPeerId _tunnel_id ;
|
DistantChatPeerId _tunnel_id ;
|
||||||
QToolButton *_status_label ;
|
QToolButton *_status_label ;
|
||||||
|
|
||||||
friend class ChatDialog;
|
friend class ChatDialog;
|
||||||
|
|
||||||
|
RsEventsHandlerId_t mEventHandlerId;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue