diff --git a/retroshare-gui/src/gui/MainWindow.cpp b/retroshare-gui/src/gui/MainWindow.cpp index 35399146a..61eb6548f 100644 --- a/retroshare-gui/src/gui/MainWindow.cpp +++ b/retroshare-gui/src/gui/MainWindow.cpp @@ -83,6 +83,7 @@ #include "statusbar/SoundStatus.h" #include "statusbar/ToasterDisable.h" #include "statusbar/SysTrayStatus.h" +#include "statusbar/torstatus.h" #include #include @@ -244,6 +245,17 @@ MainWindow::MainWindow(QWidget* parent, Qt::WindowFlags flags) peerstatus->setVisible(Settings->valueFromGroup("StatusBar", "ShowPeer", QVariant(true)).toBool()); statusBar()->addWidget(peerstatus); + if(hiddenmode) + { + torstatus = new TorStatus(); + torstatus->setVisible(Settings->valueFromGroup("StatusBar", "ShowTor", QVariant(true)).toBool()); + statusBar()->addWidget(torstatus); + torstatus->getTorStatus(); + } + else + torstatus = NULL ; + +#ifndef RETROTOR natstatus = new NATStatus(); if(hiddenmode) natstatus->setVisible(false); else natstatus->setVisible(Settings->valueFromGroup("StatusBar", "ShowNAT", QVariant(true)).toBool()); @@ -255,6 +267,7 @@ MainWindow::MainWindow(QWidget* parent, Qt::WindowFlags flags) else dhtstatus->setVisible(Settings->valueFromGroup("StatusBar", "ShowDHT", QVariant(true)).toBool()); statusBar()->addWidget(dhtstatus); dhtstatus->getDHTStatus(); +#endif hashingstatus = new HashingStatus(); hashingstatus->setVisible(Settings->valueFromGroup("StatusBar", "ShowHashing", QVariant(true)).toBool()); @@ -710,6 +723,9 @@ void MainWindow::updateStatus() if (ratesstatus) ratesstatus->getRatesStatus(downKb, upKb); + if(torstatus) + torstatus->getTorStatus(); + if(!hiddenmode) { if (natstatus) diff --git a/retroshare-gui/src/gui/MainWindow.h b/retroshare-gui/src/gui/MainWindow.h index a52bf0073..0705cac6e 100644 --- a/retroshare-gui/src/gui/MainWindow.h +++ b/retroshare-gui/src/gui/MainWindow.h @@ -46,6 +46,7 @@ class OpModeStatus; class SoundStatus; class ToasterDisable; class SysTrayStatus; +class TorStatus ; //class ForumsDialog; class GxsChannelDialog ; class GxsForumsDialog ; @@ -293,6 +294,7 @@ private: SoundStatus *soundStatus; ToasterDisable *toasterDisable; SysTrayStatus *sysTrayStatus; + TorStatus *torstatus; /* Status */ std::set m_apStatusObjects; // added objects for status diff --git a/retroshare-gui/src/gui/icons.qrc b/retroshare-gui/src/gui/icons.qrc index 8fbbf5465..aab1afb40 100644 --- a/retroshare-gui/src/gui/icons.qrc +++ b/retroshare-gui/src/gui/icons.qrc @@ -228,6 +228,7 @@ icons/tor-logo.png icons/tor-off.png icons/tor-on.png + icons/no-tor.png icons/tor-starting.png icons/tor-stopping.png icons/user-away_64.png diff --git a/retroshare-gui/src/gui/icons/no-tor.png b/retroshare-gui/src/gui/icons/no-tor.png new file mode 100644 index 000000000..ed0c29538 Binary files /dev/null and b/retroshare-gui/src/gui/icons/no-tor.png differ diff --git a/retroshare-gui/src/gui/statusbar/torstatus.cpp b/retroshare-gui/src/gui/statusbar/torstatus.cpp new file mode 100644 index 000000000..5b541a70b --- /dev/null +++ b/retroshare-gui/src/gui/statusbar/torstatus.cpp @@ -0,0 +1,115 @@ +/**************************************************************** + * RetroShare is distributed under the following license: + * + * Copyright (C) 2009 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 "torstatus.h" + +#include +#include +#include +#include + +#include "retroshare/rsconfig.h" +#include "util/misc.h" + +#ifdef RETROTOR +#include "TorControl/TorManager.h" +#include "TorControl/TorControl.h" +#endif + +#include + +TorStatus::TorStatus(QWidget *parent) + : QWidget(parent) +{ + QHBoxLayout *hbox = new QHBoxLayout(); + hbox->setMargin(0); + hbox->setSpacing(6); + + statusTor = new QLabel("" + tr("Tor") + ":", this ); + statusTor->setToolTip(tr("

This version of Retroshare uses Tor to connect to your friends.

")) ; + hbox->addWidget(statusTor); + + torstatusLabel = new QLabel( this ); + torstatusLabel->setPixmap(QPixmap(":/icons/no-tor.png")); + hbox->addWidget(torstatusLabel); + + _compactMode = false; + + setLayout( hbox ); +} + +void TorStatus::getTorStatus() +{ + statusTor->setVisible(!_compactMode); + QString text = _compactMode?statusTor->text():""; + + /* now the extra bit .... switch on check boxes */ + + int S = QFontMetricsF(torstatusLabel->font()).height(); + +#ifdef RETROTOR + // get Tor status + int tor_control_status = Tor::TorManager::instance()->control()->status(); + int torstatus = Tor::TorManager::instance()->control()->torStatus(); + + QString tor_control_status_str,torstatus_str ; + + switch(tor_control_status) + { + default: + case Tor::TorControl::Error : tor_control_status_str = "Error" ; break ; + case Tor::TorControl::NotConnected: tor_control_status_str = "Not connected" ; break ; + case Tor::TorControl::Connecting: tor_control_status_str = "Connecting" ; break ; + case Tor::TorControl::Authenticating: tor_control_status_str = "Authenticating" ; break ; + case Tor::TorControl::Connected: tor_control_status_str = "Connected" ; break ; + } + + switch(torstatus) + { + default: + case Tor::TorControl::TorUnknown: torstatus_str = "Unknown" ; break ; + case Tor::TorControl::TorOffline: torstatus_str = "Tor offline" ; break ; + case Tor::TorControl::TorReady: torstatus_str = "Tor ready" ; break ; + } + +#define MIN_RS_NET_SIZE 10 + + if(torstatus == Tor::TorControl::TorOffline) + { + // RED - some issue. + torstatusLabel->setPixmap(QPixmap(":/icons/tor-stopping.png").scaledToHeight(1.5*S,Qt::SmoothTransformation)); + torstatusLabel->setToolTip( text + tr("Tor is currently offline")); + } + else if(torstatus == Tor::TorControl::TorReady) + { + torstatusLabel->setPixmap(QPixmap(":/icons/tor-on.png").scaledToHeight(1.5*S,Qt::SmoothTransformation)); + torstatusLabel->setToolTip( text + tr("Tor is OK")); + } + else // torstatus == Tor::TorControl::TorUnknown + { + // GRAY. + torstatusLabel->setPixmap(QPixmap(":/icons/no-tor.png").scaledToHeight(1.5*S,Qt::SmoothTransformation)); + torstatusLabel->setToolTip( text + tr("No tor configuration")); + } +#else + torstatusLabel->setPixmap(QPixmap(":/icons/tor-stopping.png").scaledToHeight(S,Qt::SmoothTransformation)); + torstatusLabel->setToolTip( text + tr("Tor is currently offline")); +#endif +} diff --git a/retroshare-gui/src/gui/statusbar/torstatus.h b/retroshare-gui/src/gui/statusbar/torstatus.h new file mode 100644 index 000000000..6728b7cbc --- /dev/null +++ b/retroshare-gui/src/gui/statusbar/torstatus.h @@ -0,0 +1,41 @@ +/**************************************************************** + * RetroShare is distributed under the following license: + * + * Copyright (C) 2009 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. + ****************************************************************/ + +#pragma once + +#include + +class QLabel; + +class TorStatus : public QWidget +{ + Q_OBJECT +public: + TorStatus(QWidget *parent = 0); + + void getTorStatus( ); + void setCompactMode(bool compact) {_compactMode = compact; } + +private: + QLabel *torstatusLabel, *statusTor; + bool _compactMode; +}; + diff --git a/retroshare-gui/src/retroshare-gui.pro b/retroshare-gui/src/retroshare-gui.pro index a6ed430d2..2fa5aafca 100644 --- a/retroshare-gui/src/retroshare-gui.pro +++ b/retroshare-gui/src/retroshare-gui.pro @@ -581,6 +581,7 @@ HEADERS += rshare.h \ gui/statusbar/peerstatus.h \ gui/statusbar/natstatus.h \ gui/statusbar/dhtstatus.h \ + gui/statusbar/torstatus.h \ gui/statusbar/ratesstatus.h \ gui/statusbar/hashingstatus.h \ gui/statusbar/discstatus.h \ @@ -923,6 +924,7 @@ SOURCES += main.cpp \ gui/statusbar/peerstatus.cpp \ gui/statusbar/natstatus.cpp \ gui/statusbar/dhtstatus.cpp \ + gui/statusbar/torstatus.cpp \ gui/statusbar/ratesstatus.cpp \ gui/statusbar/hashingstatus.cpp \ gui/statusbar/discstatus.cpp \