NetStatus::NetStatus(QWidget *parent) : QWidget(parent), _sentbytes(0), _recvbytes(0), _lag(0) { setMinimumHeight(16+2); QHBoxLayout *layout = new QHBoxLayout(this); layout->setMargin(1); layout->setSpacing(4); // Download progress bar m_download = new QProgressBar(this); m_download->setMaximumWidth(120); m_download->setSizePolicy(QSizePolicy()); m_download->setTextVisible(false); m_download->setMaximum(100); m_download->hide(); layout->addWidget(m_download); // Host address label _label = new QLabel(tr("not connected"), this); _label->setTextInteractionFlags( Qt::TextSelectableByMouse|Qt::TextSelectableByKeyboard ); _label->setCursor(Qt::IBeamCursor); _label->setContextMenuPolicy(Qt::ActionsContextMenu); layout->addWidget(_label); // Action to copy address to clipboard _copyaction = new QAction(tr("Copy address to clipboard"), this); _copyaction->setEnabled(false); _label->addAction(_copyaction); connect(_copyaction,SIGNAL(triggered()),this,SLOT(copyAddress())); // Action to copy the full session URL to clipboard _urlaction = new QAction(tr("Copy session URL to clipboard"), this); _urlaction->setEnabled(false); _label->addAction(_urlaction); connect(_urlaction, SIGNAL(triggered()), this, SLOT(copyUrl())); // Discover local IP address _discoverIp = new QAction(tr("Get externally visible IP address"), this); _discoverIp->setVisible(false); _label->addAction(_discoverIp); connect(_discoverIp, SIGNAL(triggered()), this, SLOT(discoverAddress())); connect(WhatIsMyIp::instance(), SIGNAL(myAddressIs(QString)), this, SLOT(externalIpDiscovered(QString))); #ifdef HAVE_UPNP connect(net::UPnPClient::instance(), SIGNAL(externalIp(QString)), this, SLOT(externalIpDiscovered(QString))); #endif // Show network statistics QAction *sep = new QAction(this); sep->setSeparator(true); _label->addAction(sep); QAction *showNetStats = new QAction(tr("Statistics"), this); _label->addAction(showNetStats); connect(showNetStats, SIGNAL(triggered()), this, SLOT(showNetStats())); // Security level icon _security = new QLabel(QString(), this); _security->setFixedSize(QSize(16, 16)); _security->hide(); layout->addWidget(_security); _security->setContextMenuPolicy(Qt::ActionsContextMenu); QAction *showcert = new QAction(tr("Show certificate"), this); _security->addAction(showcert); connect(showcert, SIGNAL(triggered()), this, SLOT(showCertificate())); // Low space alert m_lowspace = new QLabel(tr("Low space!"), this); m_lowspace->setToolTip(tr("Server is almost out of space for session history! Reset the session to free some up.")); QPalette lowSpacePalette = m_lowspace->palette(); lowSpacePalette.setColor(QPalette::WindowText, Qt::red); m_lowspace->setPalette(lowSpacePalette); m_lowspace->setVisible(false); layout->addWidget(m_lowspace); // Popup label m_popup = new PopupMessage(this); // Some styles are buggy and have bad tooltip colors, so we force the colors here. QPalette popupPalette; popupPalette.setColor(QPalette::ToolTipBase, Qt::black); popupPalette.setColor(QPalette::ToolTipText, Qt::white); m_popup->setPalette(popupPalette); }
NetStatus::NetStatus(QWidget *parent) : QWidget(parent), _sentbytes(0), _recvbytes(0), _activity(0) { setMinimumHeight(16+2); QHBoxLayout *layout = new QHBoxLayout(this); layout->setMargin(1); layout->setSpacing(4); // Data transfer progress (not always shown) QVBoxLayout *progresslayout = new QVBoxLayout; progresslayout->setContentsMargins(0, 0, 0 ,0); progresslayout->setSpacing(0); // Upload progress bar _upload = new QProgressBar(this); _upload->setMaximumWidth(120); _upload->setSizePolicy(QSizePolicy()); _upload->setTextVisible(false); _upload->hide(); { // Red progress bar for upload QPalette pal = _upload->palette(); pal.setColor(QPalette::Highlight, QColor(198, 48, 48)); _upload->setPalette(pal); } progresslayout->addWidget(_upload); // Download progress bar _download = new QProgressBar(this); _download->setMaximumWidth(120); _download->setSizePolicy(QSizePolicy()); _download->setTextVisible(false); _download->hide(); { // Blue progress bar for download QPalette pal = _upload->palette(); pal.setColor(QPalette::Highlight, QColor(48, 140, 198)); _download->setPalette(pal); } progresslayout->addWidget(_download); layout->addLayout(progresslayout); // Host address label _label = new QLabel(tr("not connected"), this); _label->setTextInteractionFlags( Qt::TextSelectableByMouse|Qt::TextSelectableByKeyboard ); _label->setCursor(Qt::IBeamCursor); _label->setContextMenuPolicy(Qt::ActionsContextMenu); layout->addWidget(_label); // Action to copy address to clipboard _copyaction = new QAction(tr("Copy address to clipboard"), this); _copyaction->setEnabled(false); _label->addAction(_copyaction); connect(_copyaction,SIGNAL(triggered()),this,SLOT(copyAddress())); // Action to copy the full session URL to clipboard _urlaction = new QAction(tr("Copy session URL to clipboard"), this); _urlaction->setEnabled(false); _label->addAction(_urlaction); connect(_urlaction, SIGNAL(triggered()), this, SLOT(copyUrl())); // Discover local IP address _discoverIp = new QAction(tr("Get externally visible IP address"), this); _discoverIp->setVisible(false); _label->addAction(_discoverIp); connect(_discoverIp, SIGNAL(triggered()), this, SLOT(discoverAddress())); connect(WhatIsMyIp::instance(), SIGNAL(myAddressIs(QString)), this, SLOT(externalIpDiscovered(QString))); // Network connection status icon _icon = new QLabel(QString(), this); _icon->setFixedSize(QSize(16, 16)); _icon->hide(); layout->addWidget(_icon); // Security level icon _security = new QLabel(QString(), this); _security->setFixedSize(QSize(16, 16)); _security->hide(); layout->addWidget(_security); _security->setContextMenuPolicy(Qt::ActionsContextMenu); QAction *showcert = new QAction(tr("Show certificate"), this); _security->addAction(showcert); connect(showcert, SIGNAL(triggered()), this, SLOT(showCertificate())); // Popup label _popup = new PopupMessage(this); // Some styles are buggy and have bad tooltip colors, so we force the colors here. QPalette popupPalette; popupPalette.setColor(QPalette::ToolTipBase, Qt::black); popupPalette.setColor(QPalette::ToolTipText, Qt::white); _popup->setPalette(popupPalette); // Timer for activity update _timer = new QTimer(this); _timer->setSingleShot(true); connect(_timer, SIGNAL(timeout()), this, SLOT(updateStats())); }