2010-09-12 10:10:28 -04:00
|
|
|
/****************************************************************
|
|
|
|
* This file is distributed under the following license:
|
|
|
|
*
|
|
|
|
* Copyright (c) 2010, RetroShare Team
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
****************************************************************/
|
|
|
|
|
|
|
|
#include <QCoreApplication>
|
|
|
|
#include <retroshare/rsstatus.h>
|
2010-09-27 17:05:52 -04:00
|
|
|
#include <retroshare/rspeers.h>
|
2010-09-12 10:10:28 -04:00
|
|
|
|
|
|
|
#include "StatusDefs.h"
|
|
|
|
|
2011-01-06 13:26:39 -05:00
|
|
|
QString StatusDefs::name(unsigned int status)
|
2010-09-12 10:10:28 -04:00
|
|
|
{
|
2011-01-06 13:26:39 -05:00
|
|
|
switch (status) {
|
|
|
|
case RS_STATUS_OFFLINE:
|
|
|
|
return qApp->translate("StatusDefs", "Offline");
|
|
|
|
case RS_STATUS_AWAY:
|
|
|
|
return qApp->translate("StatusDefs", "Away");
|
|
|
|
case RS_STATUS_BUSY:
|
|
|
|
return qApp->translate("StatusDefs", "Busy");
|
|
|
|
case RS_STATUS_ONLINE:
|
|
|
|
return qApp->translate("StatusDefs", "Online");
|
|
|
|
case RS_STATUS_INACTIVE:
|
|
|
|
return qApp->translate("StatusDefs", "Idle");
|
|
|
|
}
|
|
|
|
|
|
|
|
std::cerr << "StatusDefs::name: Unknown status requested " << status;
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *StatusDefs::imageIM(unsigned int status)
|
|
|
|
{
|
|
|
|
switch (status) {
|
|
|
|
case RS_STATUS_OFFLINE:
|
|
|
|
return ":/images/im-user-offline.png";
|
|
|
|
case RS_STATUS_AWAY:
|
|
|
|
return ":/images/im-user-away.png";
|
|
|
|
case RS_STATUS_BUSY:
|
|
|
|
return ":/images/im-user-busy.png";
|
|
|
|
case RS_STATUS_ONLINE:
|
|
|
|
return ":/images/im-user.png";
|
|
|
|
case RS_STATUS_INACTIVE:
|
|
|
|
return ":/images/im-user-inactive.png";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::cerr << "StatusDefs::imageIM: Unknown status requested " << status;
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *StatusDefs::imageUser(unsigned int status)
|
|
|
|
{
|
|
|
|
switch (status) {
|
|
|
|
case RS_STATUS_OFFLINE:
|
|
|
|
return ":/images/user/identityoffline24.png";
|
|
|
|
case RS_STATUS_AWAY:
|
|
|
|
return ":/images/user/identity24away.png";
|
|
|
|
case RS_STATUS_BUSY:
|
|
|
|
return ":/images/user/identity24busy.png";
|
|
|
|
case RS_STATUS_ONLINE:
|
|
|
|
return ":/images/user/identity24.png";
|
|
|
|
case RS_STATUS_INACTIVE:
|
|
|
|
return ":/images/user/identity24idle.png";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::cerr << "StatusDefs::imageUser: Unknown status requested " << status;
|
|
|
|
return "";
|
2010-09-12 10:10:28 -04:00
|
|
|
}
|
|
|
|
|
2014-11-20 20:54:21 -05:00
|
|
|
const char *StatusDefs::imageStatus(unsigned int status)
|
|
|
|
{
|
|
|
|
switch (status) {
|
|
|
|
case RS_STATUS_OFFLINE:
|
2015-08-08 14:27:19 -04:00
|
|
|
return ":/icons/user-offline_64.png";
|
2014-11-20 20:54:21 -05:00
|
|
|
case RS_STATUS_AWAY:
|
2015-08-08 14:27:19 -04:00
|
|
|
return ":/icons/user-away_64.png";
|
2014-11-20 20:54:21 -05:00
|
|
|
case RS_STATUS_BUSY:
|
2015-08-08 14:27:19 -04:00
|
|
|
return ":/icons/user-busy_64.png";
|
2014-11-20 20:54:21 -05:00
|
|
|
case RS_STATUS_ONLINE:
|
2015-08-08 14:27:19 -04:00
|
|
|
return ":/icons/user-online_64.png";
|
2014-11-20 20:54:21 -05:00
|
|
|
case RS_STATUS_INACTIVE:
|
2015-08-08 14:27:19 -04:00
|
|
|
return ":/icons/user-away-extended_64.png";
|
2014-11-20 20:54:21 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
std::cerr << "StatusDefs::imageUser: Unknown status requested " << status;
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2011-01-06 13:26:39 -05:00
|
|
|
QString StatusDefs::tooltip(unsigned int status)
|
2010-09-12 10:10:28 -04:00
|
|
|
{
|
2011-01-06 13:26:39 -05:00
|
|
|
switch (status) {
|
|
|
|
case RS_STATUS_OFFLINE:
|
|
|
|
return qApp->translate("StatusDefs", "Friend is offline");
|
|
|
|
case RS_STATUS_AWAY:
|
|
|
|
return qApp->translate("StatusDefs", "Friend is away");
|
|
|
|
case RS_STATUS_BUSY:
|
|
|
|
return qApp->translate("StatusDefs", "Friend is busy");
|
|
|
|
case RS_STATUS_ONLINE:
|
|
|
|
return qApp->translate("StatusDefs", "Friend is online");
|
|
|
|
case RS_STATUS_INACTIVE:
|
|
|
|
return qApp->translate("StatusDefs", "Friend is idle");
|
|
|
|
}
|
|
|
|
|
|
|
|
std::cerr << "StatusDefs::tooltip: Unknown status requested " << status;
|
|
|
|
return "";
|
2010-09-12 10:10:28 -04:00
|
|
|
}
|
|
|
|
|
2011-01-06 13:26:39 -05:00
|
|
|
QFont StatusDefs::font(unsigned int status)
|
2010-09-12 10:10:28 -04:00
|
|
|
{
|
2011-01-06 13:26:39 -05:00
|
|
|
QFont font;
|
|
|
|
|
|
|
|
switch (status) {
|
|
|
|
case RS_STATUS_AWAY:
|
|
|
|
case RS_STATUS_BUSY:
|
|
|
|
case RS_STATUS_ONLINE:
|
|
|
|
case RS_STATUS_INACTIVE:
|
|
|
|
font.setBold(true);
|
|
|
|
return font;
|
|
|
|
case RS_STATUS_OFFLINE:
|
|
|
|
font.setBold(false);
|
|
|
|
return font;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::cerr << "StatusDefs::font: Unknown status requested " << status;
|
|
|
|
return font;
|
2010-09-12 10:10:28 -04:00
|
|
|
}
|
|
|
|
|
2011-01-06 13:26:39 -05:00
|
|
|
QString StatusDefs::peerStateString(int peerState)
|
2010-09-12 10:10:28 -04:00
|
|
|
{
|
2011-01-06 13:26:39 -05:00
|
|
|
if (peerState & RS_PEER_STATE_CONNECTED) {
|
|
|
|
return qApp->translate("StatusDefs", "Connected");
|
|
|
|
} else if (peerState & RS_PEER_STATE_UNREACHABLE) {
|
|
|
|
return qApp->translate("StatusDefs", "Unreachable");
|
|
|
|
} else if (peerState & RS_PEER_STATE_ONLINE) {
|
|
|
|
return qApp->translate("StatusDefs", "Available");
|
|
|
|
} else if (peerState & RS_PEER_STATE_FRIEND) {
|
|
|
|
return qApp->translate("StatusDefs", "Offline");
|
|
|
|
}
|
|
|
|
|
2012-10-11 06:28:24 -04:00
|
|
|
return qApp->translate("StatusDefs", "Neighbor");
|
2010-09-12 10:10:28 -04:00
|
|
|
}
|
|
|
|
|
2011-01-06 13:26:39 -05:00
|
|
|
QString StatusDefs::connectStateString(RsPeerDetails &details)
|
2010-09-12 10:10:28 -04:00
|
|
|
{
|
2011-01-06 13:26:39 -05:00
|
|
|
QString stateString;
|
2015-05-16 07:19:53 -04:00
|
|
|
bool isConnected = false;
|
2011-01-06 13:26:39 -05:00
|
|
|
|
|
|
|
switch (details.connectState) {
|
|
|
|
case 0:
|
|
|
|
stateString = peerStateString(details.state);
|
|
|
|
break;
|
|
|
|
case RS_PEER_CONNECTSTATE_TRYING_TCP:
|
|
|
|
stateString = qApp->translate("StatusDefs", "Trying TCP");
|
|
|
|
break;
|
|
|
|
case RS_PEER_CONNECTSTATE_TRYING_UDP:
|
|
|
|
stateString = qApp->translate("StatusDefs", "Trying UDP");
|
|
|
|
break;
|
|
|
|
case RS_PEER_CONNECTSTATE_CONNECTED_TCP:
|
|
|
|
stateString = qApp->translate("StatusDefs", "Connected: TCP");
|
2015-05-16 07:19:53 -04:00
|
|
|
isConnected = true;
|
2011-01-06 13:26:39 -05:00
|
|
|
break;
|
|
|
|
case RS_PEER_CONNECTSTATE_CONNECTED_UDP:
|
|
|
|
stateString = qApp->translate("StatusDefs", "Connected: UDP");
|
2015-05-16 07:19:53 -04:00
|
|
|
isConnected = true;
|
2011-01-06 13:26:39 -05:00
|
|
|
break;
|
2014-10-26 12:24:45 -04:00
|
|
|
case RS_PEER_CONNECTSTATE_CONNECTED_TOR:
|
2015-06-11 10:30:26 -04:00
|
|
|
stateString = qApp->translate("StatusDefs", "Connected: Tor");
|
2015-05-16 07:19:53 -04:00
|
|
|
isConnected = true;
|
2014-10-26 12:24:45 -04:00
|
|
|
break;
|
2011-01-06 13:26:39 -05:00
|
|
|
case RS_PEER_CONNECTSTATE_CONNECTED_UNKNOWN:
|
|
|
|
stateString = qApp->translate("StatusDefs", "Connected: Unknown");
|
2015-05-16 07:19:53 -04:00
|
|
|
isConnected = true;
|
2011-01-06 13:26:39 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-05-16 07:19:53 -04:00
|
|
|
if(isConnected) {
|
|
|
|
stateString += " ";
|
|
|
|
if(details.actAsServer)
|
|
|
|
stateString += qApp->translate("StatusDefs", "inbound connection");
|
|
|
|
else
|
|
|
|
stateString += qApp->translate("StatusDefs", "outbound connection");
|
|
|
|
}
|
|
|
|
|
2011-01-06 13:26:39 -05:00
|
|
|
if (details.connectStateString.empty() == false) {
|
|
|
|
if (stateString.isEmpty() == false) {
|
|
|
|
stateString += ": ";
|
|
|
|
}
|
|
|
|
stateString += QString::fromStdString(details.connectStateString);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* HACK to display DHT Status info too */
|
|
|
|
if (details.foundDHT) {
|
|
|
|
if (stateString.isEmpty() == false) {
|
|
|
|
stateString += ", ";
|
|
|
|
}
|
|
|
|
stateString += qApp->translate("StatusDefs", "DHT: Contact");
|
|
|
|
}
|
|
|
|
|
|
|
|
return stateString;
|
2010-09-12 10:10:28 -04:00
|
|
|
}
|
2015-03-21 17:58:05 -04:00
|
|
|
|
|
|
|
QString StatusDefs::connectStateWithoutTransportTypeString(RsPeerDetails &details)
|
|
|
|
{
|
|
|
|
QString stateString;
|
|
|
|
|
|
|
|
switch (details.connectState) {
|
|
|
|
case 0:
|
|
|
|
stateString = peerStateString(details.state);
|
|
|
|
break;
|
|
|
|
case RS_PEER_CONNECTSTATE_TRYING_TCP:
|
|
|
|
stateString = qApp->translate("StatusDefs", "Trying TCP");
|
|
|
|
break;
|
|
|
|
case RS_PEER_CONNECTSTATE_TRYING_UDP:
|
|
|
|
stateString = qApp->translate("StatusDefs", "Trying UDP");
|
|
|
|
break;
|
|
|
|
case RS_PEER_CONNECTSTATE_CONNECTED_TCP:
|
|
|
|
case RS_PEER_CONNECTSTATE_CONNECTED_UDP:
|
|
|
|
case RS_PEER_CONNECTSTATE_CONNECTED_TOR:
|
|
|
|
case RS_PEER_CONNECTSTATE_CONNECTED_UNKNOWN:
|
|
|
|
stateString = qApp->translate("StatusDefs", "Connected");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return stateString;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString StatusDefs::connectStateIpString(RsPeerDetails &details)
|
|
|
|
{
|
2015-05-15 10:45:44 -04:00
|
|
|
QString stateString = QString("");
|
2015-03-21 17:58:05 -04:00
|
|
|
|
|
|
|
switch (details.connectState) {
|
|
|
|
case 0:
|
|
|
|
stateString = peerStateString(details.state);
|
|
|
|
break;
|
|
|
|
case RS_PEER_CONNECTSTATE_TRYING_TCP:
|
|
|
|
case RS_PEER_CONNECTSTATE_CONNECTED_TCP:
|
2015-06-17 13:18:52 -04:00
|
|
|
stateString += QString(details.actAsServer ? qApp->translate("StatusDefs", "TCP-in") : qApp->translate("StatusDefs", "TCP-out"));
|
2015-03-21 17:58:05 -04:00
|
|
|
break;
|
|
|
|
case RS_PEER_CONNECTSTATE_TRYING_UDP:
|
|
|
|
case RS_PEER_CONNECTSTATE_CONNECTED_UDP:
|
|
|
|
stateString += qApp->translate("StatusDefs", "UDP");
|
|
|
|
break;
|
|
|
|
case RS_PEER_CONNECTSTATE_CONNECTED_TOR:
|
2015-06-17 13:18:52 -04:00
|
|
|
stateString += QString(details.actAsServer ? qApp->translate("StatusDefs", "Tor-in") : qApp->translate("StatusDefs", "Tor-out"));
|
2015-03-21 17:58:05 -04:00
|
|
|
break;
|
|
|
|
case RS_PEER_CONNECTSTATE_CONNECTED_UNKNOWN:
|
|
|
|
stateString += qApp->translate("StatusDefs", "unkown");
|
|
|
|
break;
|
|
|
|
}
|
2015-05-15 10:45:44 -04:00
|
|
|
stateString += QString(" : ");
|
|
|
|
|
|
|
|
stateString += QString(details.connectAddr.c_str()) ;
|
2015-03-21 17:58:05 -04:00
|
|
|
|
|
|
|
return stateString;
|
|
|
|
}
|