2013-04-18 17:41:13 -04:00
|
|
|
/****************************************************************
|
|
|
|
* RetroShare is distributed under the following license:
|
|
|
|
*
|
|
|
|
* Copyright (C) 2013, Cyril Soler
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
|
|
|
****************************************************************/
|
|
|
|
|
2013-04-16 17:13:42 -04:00
|
|
|
#include <QTimer>
|
2013-06-12 17:10:09 -04:00
|
|
|
#include <QCloseEvent>
|
|
|
|
#include "RsAutoUpdatePage.h"
|
2013-04-16 17:13:42 -04:00
|
|
|
#include "PopupDistantChatDialog.h"
|
|
|
|
|
2013-04-23 18:43:19 -04:00
|
|
|
#define IMAGE_RED_LED ":/images/redled.png"
|
|
|
|
#define IMAGE_YEL_LED ":/images/yellowled.png"
|
|
|
|
#define IMAGE_GRN_LED ":/images/greenled.png"
|
|
|
|
#define IMAGE_GRY_LED ":/images/grayled.png"
|
|
|
|
|
2013-06-12 17:10:09 -04:00
|
|
|
PopupDistantChatDialog::~PopupDistantChatDialog()
|
|
|
|
{
|
|
|
|
_update_timer->stop() ;
|
|
|
|
delete _update_timer ;
|
2013-04-18 17:41:13 -04:00
|
|
|
}
|
|
|
|
|
2013-04-16 17:13:42 -04:00
|
|
|
PopupDistantChatDialog::PopupDistantChatDialog(QWidget *parent, Qt::WFlags flags)
|
|
|
|
: PopupChatDialog(parent,flags)
|
|
|
|
{
|
2013-06-12 17:10:09 -04:00
|
|
|
_status_label = new QLabel ;
|
|
|
|
_update_timer = new QTimer ;
|
2013-04-16 17:13:42 -04:00
|
|
|
|
2013-06-12 17:10:09 -04:00
|
|
|
_update_timer->setInterval(1000) ;
|
|
|
|
QObject::connect(_update_timer,SIGNAL(timeout()),this,SLOT(updateDisplay())) ;
|
2013-04-16 17:13:42 -04:00
|
|
|
|
2013-06-12 17:10:09 -04:00
|
|
|
_update_timer->start() ;
|
2013-04-23 18:43:19 -04:00
|
|
|
|
|
|
|
addChatBarWidget(_status_label) ;
|
2013-06-12 17:10:09 -04:00
|
|
|
updateDisplay() ;
|
2013-04-16 17:13:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void PopupDistantChatDialog::init(const std::string& hash,const QString & title)
|
|
|
|
{
|
|
|
|
_hash = hash ;
|
2013-04-19 18:24:25 -04:00
|
|
|
PopupChatDialog::init(hash,title) ;
|
2013-04-16 17:13:42 -04:00
|
|
|
}
|
|
|
|
|
2013-06-12 17:10:09 -04:00
|
|
|
void PopupDistantChatDialog::updateDisplay()
|
2013-04-16 17:13:42 -04:00
|
|
|
{
|
2013-06-12 17:10:09 -04:00
|
|
|
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.
|
|
|
|
|
2013-04-16 17:13:42 -04:00
|
|
|
if(!isVisible())
|
|
|
|
return ;
|
|
|
|
|
|
|
|
std::cerr << "Checking tunnel..." ;
|
|
|
|
// make sure about the tunnel status
|
|
|
|
//
|
|
|
|
|
2013-04-23 18:43:19 -04:00
|
|
|
uint32_t status= RS_DISTANT_CHAT_STATUS_UNKNOWN;
|
|
|
|
std::string pgp_id ;
|
|
|
|
rsMsgs->getDistantChatStatus(_hash,status,pgp_id) ;
|
2013-04-16 17:13:42 -04:00
|
|
|
|
|
|
|
switch(status)
|
|
|
|
{
|
|
|
|
case RS_DISTANT_CHAT_STATUS_UNKNOWN: std::cerr << "Unknown hash. Error!" << std::endl;
|
2013-04-23 18:43:19 -04:00
|
|
|
_status_label->setPixmap(QPixmap(IMAGE_GRY_LED)) ;
|
2013-06-12 17:10:09 -04:00
|
|
|
_status_label->setToolTip(QObject::tr("Hash error")) ;
|
2013-04-16 17:13:42 -04:00
|
|
|
break ;
|
|
|
|
case RS_DISTANT_CHAT_STATUS_TUNNEL_DN: std::cerr << "Tunnel asked. Waiting for reponse. " << std::endl;
|
2013-04-23 18:43:19 -04:00
|
|
|
_status_label->setPixmap(QPixmap(IMAGE_RED_LED)) ;
|
2013-06-12 17:10:09 -04:00
|
|
|
_status_label->setToolTip(QObject::tr("Tunnel is broken")) ;
|
2013-04-16 17:13:42 -04:00
|
|
|
break ;
|
|
|
|
case RS_DISTANT_CHAT_STATUS_TUNNEL_OK: std::cerr << "Tunnel is ok. " << std::endl;
|
2013-04-23 18:43:19 -04:00
|
|
|
_status_label->setPixmap(QPixmap(IMAGE_YEL_LED)) ;
|
2013-06-12 17:10:09 -04:00
|
|
|
_status_label->setToolTip(QObject::tr("Tunnel established")) ;
|
2013-04-16 17:13:42 -04:00
|
|
|
break ;
|
|
|
|
case RS_DISTANT_CHAT_STATUS_CAN_TALK: std::cerr << "Tunnel is ok and works. You can talk!" << std::endl;
|
2013-04-23 18:43:19 -04:00
|
|
|
_status_label->setPixmap(QPixmap(IMAGE_GRN_LED)) ;
|
2013-06-12 17:10:09 -04:00
|
|
|
_status_label->setToolTip(QObject::tr("Tunnel is working")) ;
|
2013-04-16 17:13:42 -04:00
|
|
|
break ;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-12 17:10:09 -04:00
|
|
|
void PopupDistantChatDialog::closeEvent(QCloseEvent *e)
|
|
|
|
{
|
|
|
|
std::cerr << "Closing window => closing distant chat for hash " << _hash << std::endl;
|
|
|
|
rsMsgs->closeDistantChatConnexion(_hash) ;
|
|
|
|
|
|
|
|
e->accept() ;
|
|
|
|
|
|
|
|
PopupChatDialog::closeEvent(e) ;
|
|
|
|
}
|
2013-04-16 17:13:42 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|