Merge pull request #1694 from csoler/v0.6-ImprovedGUI

added notification when distant chat has undelivered messages. Update…
This commit is contained in:
csoler 2019-11-03 20:50:19 +01:00 committed by GitHub
commit 36441c16dc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 124 additions and 53 deletions

View File

@ -178,8 +178,7 @@ bool DistantChatService::acceptDataFromPeer(const RsGxsId& gxs_id,const RsGxsTun
return res ; return res ;
} }
void DistantChatService::notifyTunnelStatus( void DistantChatService::notifyTunnelStatus( const RsGxsTunnelId& tunnel_id, uint32_t tunnel_status )
const RsGxsTunnelId& tunnel_id, uint32_t tunnel_status )
{ {
#ifdef DEBUG_DISTANT_CHAT #ifdef DEBUG_DISTANT_CHAT
DISTANT_CHAT_DEBUG() << "DistantChatService::notifyTunnelStatus(): got notification " << std::hex << tunnel_status << std::dec << " for tunnel " << tunnel_id << std::endl; DISTANT_CHAT_DEBUG() << "DistantChatService::notifyTunnelStatus(): got notification " << std::hex << tunnel_status << std::dec << " for tunnel " << tunnel_id << std::endl;
@ -195,18 +194,17 @@ void DistantChatService::notifyTunnelStatus(
RsServer::notify()->notifyPeerStatusChanged(tunnel_id.toStdString(),RS_STATUS_ONLINE) ; RsServer::notify()->notifyPeerStatusChanged(tunnel_id.toStdString(),RS_STATUS_ONLINE) ;
break ; break ;
case RsGxsTunnelService::RS_GXS_TUNNEL_STATUS_TUNNEL_DN: RsServer::notify()->notifyChatStatus(ChatId(DistantChatPeerId(tunnel_id)),"tunnel is down...") ; case RsGxsTunnelService::RS_GXS_TUNNEL_STATUS_TUNNEL_DN: RsServer::notify()->notifyChatStatus(ChatId(DistantChatPeerId(tunnel_id)),"Tunnel is down...") ;
RsServer::notify()->notifyPeerStatusChanged(tunnel_id.toStdString(),RS_STATUS_OFFLINE) ; RsServer::notify()->notifyPeerStatusChanged(tunnel_id.toStdString(),RS_STATUS_OFFLINE) ;
break ; break ;
case RsGxsTunnelService::RS_GXS_TUNNEL_STATUS_REMOTELY_CLOSED: RsServer::notify()->notifyChatStatus(ChatId(DistantChatPeerId(tunnel_id)),"tunnel is down...") ; case RsGxsTunnelService::RS_GXS_TUNNEL_STATUS_REMOTELY_CLOSED: RsServer::notify()->notifyChatStatus(ChatId(DistantChatPeerId(tunnel_id)),"Tunnel is down...") ;
RsServer::notify()->notifyPeerStatusChanged(tunnel_id.toStdString(),RS_STATUS_OFFLINE) ; RsServer::notify()->notifyPeerStatusChanged(tunnel_id.toStdString(),RS_STATUS_OFFLINE) ;
break ; break ;
} }
} }
void DistantChatService::receiveData( void DistantChatService::receiveData( const RsGxsTunnelId& tunnel_id, unsigned char* data, uint32_t data_size)
const RsGxsTunnelId& tunnel_id, unsigned char* data, uint32_t data_size)
{ {
#ifdef DEBUG_DISTANT_CHAT #ifdef DEBUG_DISTANT_CHAT
DISTANT_CHAT_DEBUG() << "DistantChatService::receiveData(): got data of size " << std::dec << data_size << " for tunnel " << tunnel_id << std::endl; DISTANT_CHAT_DEBUG() << "DistantChatService::receiveData(): got data of size " << std::dec << data_size << " for tunnel " << tunnel_id << std::endl;
@ -303,16 +301,14 @@ bool DistantChatService::getDistantChatStatus(const DistantChatPeerId& tunnel_id
cinfo.to_id = tinfo.destination_gxs_id; cinfo.to_id = tinfo.destination_gxs_id;
cinfo.own_id = tinfo.source_gxs_id; cinfo.own_id = tinfo.source_gxs_id;
cinfo.pending_items = tinfo.pending_data_packets;
cinfo.peer_id = tunnel_id; cinfo.peer_id = tunnel_id;
switch(tinfo.tunnel_status) switch(tinfo.tunnel_status)
{ {
case RsGxsTunnelService::RS_GXS_TUNNEL_STATUS_CAN_TALK : case RsGxsTunnelService::RS_GXS_TUNNEL_STATUS_CAN_TALK : cinfo.status = RS_DISTANT_CHAT_STATUS_CAN_TALK; break;
cinfo.status = RS_DISTANT_CHAT_STATUS_CAN_TALK; break; case RsGxsTunnelService::RS_GXS_TUNNEL_STATUS_TUNNEL_DN: cinfo.status = RS_DISTANT_CHAT_STATUS_TUNNEL_DN; break;
case RsGxsTunnelService::RS_GXS_TUNNEL_STATUS_TUNNEL_DN: case RsGxsTunnelService::RS_GXS_TUNNEL_STATUS_REMOTELY_CLOSED: cinfo.status = RS_DISTANT_CHAT_STATUS_REMOTELY_CLOSED; break;
cinfo.status = RS_DISTANT_CHAT_STATUS_TUNNEL_DN; break;
case RsGxsTunnelService::RS_GXS_TUNNEL_STATUS_REMOTELY_CLOSED:
cinfo.status = RS_DISTANT_CHAT_STATUS_REMOTELY_CLOSED; break;
case RsGxsTunnelService::RS_GXS_TUNNEL_STATUS_UNKNOWN: case RsGxsTunnelService::RS_GXS_TUNNEL_STATUS_UNKNOWN:
default: default:
cinfo.status = RS_DISTANT_CHAT_STATUS_UNKNOWN; break; cinfo.status = RS_DISTANT_CHAT_STATUS_UNKNOWN; break;

View File

@ -1596,7 +1596,13 @@ bool p3GxsTunnelService::getTunnelInfo(const RsGxsTunnelId& tunnel_id,GxsTunnelI
// Data packets // Data packets
info.pending_data_packets = 0; info.pending_data_packets = 0;
RsPeerId p(tunnel_id);
for(auto it(pendingGxsTunnelDataItems.begin());it!=pendingGxsTunnelDataItems.end();++it)
if(it->second.data_item->PeerId() == p)
++info.pending_data_packets ;
info.total_data_packets_sent=0 ; info.total_data_packets_sent=0 ;
info.total_data_packets_received=0 ; info.total_data_packets_received=0 ;
@ -1704,7 +1710,16 @@ bool p3GxsTunnelService::getTunnelsInfo(std::vector<RsGxsTunnelService::GxsTunne
ti.tunnel_status = it->second.status ; ti.tunnel_status = it->second.status ;
ti.total_size_sent = it->second.total_sent ; ti.total_size_sent = it->second.total_sent ;
ti.total_size_received = it->second.total_received ; ti.total_size_received = it->second.total_received ;
ti.pending_data_packets = 0;
RsPeerId p(it->first);
for(auto it(pendingGxsTunnelDataItems.begin());it!=pendingGxsTunnelDataItems.end();++it)
if(it->second.data_item->PeerId() == p)
++ti.pending_data_packets ;
ti.total_data_packets_sent =0; // not accounted for yet.
ti.total_data_packets_received=0 ; // not accounted for yet.
infos.push_back(ti) ; infos.push_back(ti) ;
} }

View File

@ -343,10 +343,13 @@ struct RsMailStatusEvent : RsEvent
struct DistantChatPeerInfo struct DistantChatPeerInfo
{ {
DistantChatPeerInfo() : status(0),pending_items(0) {}
RsGxsId to_id ; RsGxsId to_id ;
RsGxsId own_id ; RsGxsId own_id ;
DistantChatPeerId peer_id ; // this is the tunnel id actually DistantChatPeerId peer_id ; // this is the tunnel id actually
uint32_t status ; // see the values in rsmsgs.h uint32_t status ; // see the values in rsmsgs.h
uint32_t pending_items; // items not sent, waiting for a tunnel
}; };
// Identifier for an chat endpoint like // Identifier for an chat endpoint like

View File

@ -113,6 +113,7 @@ ChatWidget::ChatWidget(QWidget *parent)
ui->searchButton->setIconSize(iconSize); ui->searchButton->setIconSize(iconSize);
ui->sendButton->setFixedHeight(iconHeight); ui->sendButton->setFixedHeight(iconHeight);
ui->sendButton->setIconSize(iconSize); ui->sendButton->setIconSize(iconSize);
ui->typingLabel->setMaximumHeight(QFontMetricsF(font()).height()*1.2);
//Initialize search //Initialize search
iCharToStartSearch=Settings->getChatSearchCharToStartSearch(); iCharToStartSearch=Settings->getChatSearchCharToStartSearch();

View File

@ -7,16 +7,25 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>667</width> <width>667</width>
<height>334</height> <height>528</height>
</rect> </rect>
</property> </property>
<layout class="QGridLayout"> <layout class="QGridLayout">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<property name="verticalSpacing"> <property name="verticalSpacing">
<number>2</number> <number>2</number>
</property> </property>
<property name="margin">
<number>0</number>
</property>
<item row="1" column="0"> <item row="1" column="0">
<layout class="QHBoxLayout" name="textChatHLayout"> <layout class="QHBoxLayout" name="textChatHLayout">
<property name="spacing"> <property name="spacing">
@ -37,7 +46,16 @@
<enum>QFrame::Raised</enum> <enum>QFrame::Raised</enum>
</property> </property>
<layout class="QVBoxLayout" name="chatTextFrameVLayout"> <layout class="QVBoxLayout" name="chatTextFrameVLayout">
<property name="margin"> <property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number> <number>0</number>
</property> </property>
<item> <item>
@ -113,7 +131,16 @@
<enum>QFrame::Box</enum> <enum>QFrame::Box</enum>
</property> </property>
<layout class="QHBoxLayout" name="infoFrameHLayout"> <layout class="QHBoxLayout" name="infoFrameHLayout">
<property name="margin"> <property name="leftMargin">
<number>6</number>
</property>
<property name="topMargin">
<number>6</number>
</property>
<property name="rightMargin">
<number>6</number>
</property>
<property name="bottomMargin">
<number>6</number> <number>6</number>
</property> </property>
<item> <item>
@ -238,12 +265,6 @@ border-image: url(:/images/closepressed.png)
</item> </item>
<item> <item>
<widget class="QLabel" name="typingLabel"> <widget class="QLabel" name="typingLabel">
<property name="maximumSize">
<size>
<width>400</width>
<height>18</height>
</size>
</property>
<property name="margin"> <property name="margin">
<number>0</number> <number>0</number>
</property> </property>
@ -291,7 +312,7 @@ border-image: url(:/images/closepressed.png)
<height>30</height> <height>30</height>
</size> </size>
</property> </property>
<property name="placeholderText" stdset="0"> <property name="placeholderText">
<string>Type a message here</string> <string>Type a message here</string>
</property> </property>
</widget> </widget>
@ -311,7 +332,16 @@ border-image: url(:/images/closepressed.png)
<enum>QFrame::Sunken</enum> <enum>QFrame::Sunken</enum>
</property> </property>
<layout class="QHBoxLayout" name="toolBarFrameHLayout"> <layout class="QHBoxLayout" name="toolBarFrameHLayout">
<property name="margin"> <property name="leftMargin">
<number>2</number>
</property>
<property name="topMargin">
<number>2</number>
</property>
<property name="rightMargin">
<number>2</number>
</property>
<property name="bottomMargin">
<number>2</number> <number>2</number>
</property> </property>
<item> <item>
@ -520,7 +550,7 @@ border-image: url(:/images/closepressed.png)
<enum>Qt::NoFocus</enum> <enum>Qt::NoFocus</enum>
</property> </property>
<property name="icon"> <property name="icon">
<iconset resource="../images.qrc"> <iconset resource="../WikiPoos/Wiki_images.qrc">
<normaloff>:/images/arrow-left.png</normaloff>:/images/arrow-left.png</iconset> <normaloff>:/images/arrow-left.png</normaloff>:/images/arrow-left.png</iconset>
</property> </property>
<property name="autoRaise"> <property name="autoRaise">
@ -546,7 +576,7 @@ border-image: url(:/images/closepressed.png)
<enum>Qt::NoFocus</enum> <enum>Qt::NoFocus</enum>
</property> </property>
<property name="icon"> <property name="icon">
<iconset resource="../images.qrc"> <iconset resource="../WikiPoos/Wiki_images.qrc">
<normaloff>:/images/arrow-right.png</normaloff>:/images/arrow-right.png</iconset> <normaloff>:/images/arrow-right.png</normaloff>:/images/arrow-right.png</iconset>
</property> </property>
<property name="autoRaise"> <property name="autoRaise">
@ -583,7 +613,16 @@ border-image: url(:/images/closepressed.png)
<enum>QFrame::Plain</enum> <enum>QFrame::Plain</enum>
</property> </property>
<layout class="QHBoxLayout" name="pluginButtonFrameHLayout"> <layout class="QHBoxLayout" name="pluginButtonFrameHLayout">
<property name="margin"> <property name="leftMargin">
<number>2</number>
</property>
<property name="topMargin">
<number>2</number>
</property>
<property name="rightMargin">
<number>2</number>
</property>
<property name="bottomMargin">
<number>2</number> <number>2</number>
</property> </property>
</layout> </layout>
@ -675,7 +714,16 @@ border-image: url(:/images/closepressed.png)
<enum>QFrame::Sunken</enum> <enum>QFrame::Sunken</enum>
</property> </property>
<layout class="QHBoxLayout" name="titleBarFrameHLayout"> <layout class="QHBoxLayout" name="titleBarFrameHLayout">
<property name="margin"> <property name="leftMargin">
<number>2</number>
</property>
<property name="topMargin">
<number>2</number>
</property>
<property name="rightMargin">
<number>2</number>
</property>
<property name="bottomMargin">
<number>2</number> <number>2</number>
</property> </property>
<item> <item>
@ -756,7 +804,16 @@ border-image: url(:/images/closepressed.png)
<enum>QFrame::Plain</enum> <enum>QFrame::Plain</enum>
</property> </property>
<layout class="QHBoxLayout" name="pluginTitleFrameHLayout"> <layout class="QHBoxLayout" name="pluginTitleFrameHLayout">
<property name="margin"> <property name="leftMargin">
<number>2</number>
</property>
<property name="topMargin">
<number>2</number>
</property>
<property name="rightMargin">
<number>2</number>
</property>
<property name="bottomMargin">
<number>2</number> <number>2</number>
</property> </property>
</layout> </layout>
@ -998,6 +1055,7 @@ border-image: url(:/images/closepressed.png)
</customwidget> </customwidget>
</customwidgets> </customwidgets>
<resources> <resources>
<include location="../WikiPoos/Wiki_images.qrc"/>
<include location="../images.qrc"/> <include location="../images.qrc"/>
<include location="../icons.qrc"/> <include location="../icons.qrc"/>
</resources> </resources>

View File

@ -111,7 +111,7 @@ void PopupDistantChatDialog::updateDisplay()
switch(tinfo.status) switch(tinfo.status)
{ {
case RS_DISTANT_CHAT_STATUS_UNKNOWN: case RS_DISTANT_CHAT_STATUS_UNKNOWN:
//std::cerr << "Unknown hash. Error!" << std::endl;
_status_label->setIcon(QIcon(IMAGE_GRY_LED)); _status_label->setIcon(QIcon(IMAGE_GRY_LED));
msg = tr("Remote status unknown."); msg = tr("Remote status unknown.");
_status_label->setToolTip(msg); _status_label->setToolTip(msg);
@ -124,31 +124,31 @@ void PopupDistantChatDialog::updateDisplay()
case RS_DISTANT_CHAT_STATUS_REMOTELY_CLOSED: case RS_DISTANT_CHAT_STATUS_REMOTELY_CLOSED:
std::cerr << "Chat remotely closed. " << std::endl; std::cerr << "Chat remotely closed. " << std::endl;
_status_label->setIcon(QIcon(IMAGE_RED_LED)); _status_label->setIcon(QIcon(IMAGE_RED_LED));
_status_label->setToolTip( _status_label->setToolTip( QObject::tr("Distant peer has closed the chat") );
QObject::tr("Distant peer has closed the chat") );
getChatWidget()->updateStatusString( getChatWidget()->updateStatusString("%1", tr( "Your partner closed the conversation." ), true );
"%1", tr( "The person you are talking to has deleted the" getChatWidget()->blockSending(tr( "Your partner closed the conversation."));
" secured chat tunnel." ), true );
getChatWidget()->blockSending(tr( "The chat partner deleted the secure"
" tunnel, messages will be delivered"
" as soon as possible"));
setPeerStatus(RS_STATUS_OFFLINE) ; setPeerStatus(RS_STATUS_OFFLINE) ;
break ; break ;
case RS_DISTANT_CHAT_STATUS_TUNNEL_DN: case RS_DISTANT_CHAT_STATUS_TUNNEL_DN:
//std::cerr << "Tunnel asked. Waiting for reponse. " << std::endl;
_status_label->setIcon(QIcon(IMAGE_YEL_LED)); _status_label->setIcon(QIcon(IMAGE_YEL_LED));
msg = QObject::tr( "Tunnel is pending... Messages will be delivered as" msg = QObject::tr( "Tunnel is pending");
" soon as possible" );
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(RS_STATUS_OFFLINE); setPeerStatus(RS_STATUS_OFFLINE);
break; break;
case RS_DISTANT_CHAT_STATUS_CAN_TALK: case RS_DISTANT_CHAT_STATUS_CAN_TALK:
//std::cerr << "Tunnel is ok and data is transmitted." << std::endl;
_status_label->setIcon(QIcon(IMAGE_GRN_LED)); _status_label->setIcon(QIcon(IMAGE_GRN_LED));
msg = QObject::tr( "Secured tunnel is working. " msg = QObject::tr( "End-to-end encrypted conversation established");
"Messages are delivered immediately!" );
_status_label->setToolTip(msg); _status_label->setToolTip(msg);
getChatWidget()->unblockSending(); getChatWidget()->unblockSending();
setPeerStatus(RS_STATUS_ONLINE); setPeerStatus(RS_STATUS_ONLINE);
@ -158,17 +158,15 @@ void PopupDistantChatDialog::updateDisplay()
void PopupDistantChatDialog::closeEvent(QCloseEvent *e) void PopupDistantChatDialog::closeEvent(QCloseEvent *e)
{ {
//std::cerr << "Closing window => closing distant chat for hash " << _pid << std::endl;
DistantChatPeerInfo tinfo ; DistantChatPeerInfo tinfo ;
rsMsgs->getDistantChatStatus(_tunnel_id,tinfo) ; rsMsgs->getDistantChatStatus(_tunnel_id,tinfo) ;
if(tinfo.status != RS_DISTANT_CHAT_STATUS_REMOTELY_CLOSED) if(tinfo.status != RS_DISTANT_CHAT_STATUS_REMOTELY_CLOSED)
{ {
QString msg = tr("Closing this window will end the conversation, notify the peer and remove the encrypted tunnel.") ; QString msg = tr("Closing this window will end the conversation. Unsent messages will be dropped.") ;
if(QMessageBox::Ok == QMessageBox::critical(NULL,tr("Kill the tunnel?"),msg, QMessageBox::Ok | QMessageBox::Cancel)) if(QMessageBox::Ok == QMessageBox::critical(NULL,tr("Close conversation?"),msg, QMessageBox::Ok | QMessageBox::Cancel))
rsMsgs->closeDistantChatConnexion(_tunnel_id) ; rsMsgs->closeDistantChatConnexion(_tunnel_id) ;
else else
{ {