2009-07-23 13:11:51 -04:00
|
|
|
/****************************************************************
|
|
|
|
* RetroShare is distributed under the following license:
|
|
|
|
*
|
|
|
|
* Copyright (C) 2006, crypton
|
|
|
|
*
|
|
|
|
* 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
|
2009-08-19 18:15:16 -04:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
2009-07-23 13:11:51 -04:00
|
|
|
* Boston, MA 02110-1301, USA.
|
|
|
|
****************************************************************/
|
|
|
|
|
|
|
|
#include "ServerPage.h"
|
2009-08-17 16:19:02 -04:00
|
|
|
#include <gui/TurtleRouterDialog.h>
|
|
|
|
|
2009-07-23 13:11:51 -04:00
|
|
|
#include "rshare.h"
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
#include <sstream>
|
|
|
|
|
|
|
|
#include "rsiface/rsiface.h"
|
|
|
|
#include "rsiface/rspeers.h"
|
|
|
|
|
|
|
|
#include <QTimer>
|
|
|
|
|
|
|
|
ServerPage::ServerPage(QWidget * parent, Qt::WFlags flags)
|
2009-08-19 18:15:16 -04:00
|
|
|
: ConfigPage(parent, flags)
|
2009-07-23 13:11:51 -04:00
|
|
|
{
|
|
|
|
/* Invoke the Qt Designer generated object setup routine */
|
|
|
|
ui.setupUi(this);
|
|
|
|
|
|
|
|
connect( ui.netModeComboBox, SIGNAL( activated ( int ) ), this, SLOT( toggleUPnP( ) ) );
|
|
|
|
connect( ui.allowIpDeterminationCB, SIGNAL( toggled( bool ) ), this, SLOT( toggleIpDetermination(bool) ) );
|
2009-12-13 16:59:26 -05:00
|
|
|
connect( ui.allowTunnelConnectionCB, SIGNAL( toggled( bool ) ), this, SLOT( toggleTunnelConnection(bool) ) );
|
2009-07-23 13:11:51 -04:00
|
|
|
|
|
|
|
QTimer *timer = new QTimer(this);
|
|
|
|
timer->connect(timer, SIGNAL(timeout()), this, SLOT(updateStatus()));
|
|
|
|
timer->start(1000);
|
|
|
|
|
2009-09-15 20:03:51 -04:00
|
|
|
//load();
|
2009-07-23 13:11:51 -04:00
|
|
|
updateStatus();
|
|
|
|
|
|
|
|
bool b = rsPeers->getAllowServerIPDetermination() ;
|
|
|
|
ui.allowIpDeterminationCB->setChecked(b) ;
|
|
|
|
ui.IPServersLV->setEnabled(b) ;
|
|
|
|
|
2010-02-25 17:44:27 -05:00
|
|
|
// #ifdef RS_RELEASE_VERSION
|
|
|
|
// ui.allowTunnelConnectionCB->hide();
|
|
|
|
// this->toggleTunnelConnection(false);
|
|
|
|
// #endif
|
2009-12-13 16:59:26 -05:00
|
|
|
b = rsPeers->getAllowTunnelConnection() ;
|
|
|
|
ui.allowTunnelConnectionCB->setChecked(b) ;
|
|
|
|
|
2009-07-23 13:11:51 -04:00
|
|
|
std::list<std::string> ip_servers ;
|
|
|
|
rsPeers->getIPServersList(ip_servers) ;
|
|
|
|
|
|
|
|
for(std::list<std::string>::const_iterator it(ip_servers.begin());it!=ip_servers.end();++it)
|
|
|
|
ui.IPServersLV->addItem(QString::fromStdString(*it)) ;
|
|
|
|
|
|
|
|
/* Hide platform specific features */
|
|
|
|
#ifdef Q_WS_WIN
|
|
|
|
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void ServerPage::toggleIpDetermination(bool b)
|
|
|
|
{
|
|
|
|
rsPeers->allowServerIPDetermination(b) ;
|
|
|
|
ui.IPServersLV->setEnabled(b) ;
|
|
|
|
}
|
|
|
|
|
2009-12-13 16:59:26 -05:00
|
|
|
void ServerPage::toggleTunnelConnection(bool b)
|
|
|
|
{
|
|
|
|
std::cerr << "ServerPage::toggleTunnelConnection() set tunnel to : " << b << std::endl;
|
|
|
|
rsPeers->allowTunnelConnection(b) ;
|
|
|
|
}
|
|
|
|
|
2009-07-23 13:11:51 -04:00
|
|
|
void
|
|
|
|
ServerPage::closeEvent (QCloseEvent * event)
|
|
|
|
{
|
|
|
|
QWidget::closeEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/** Saves the changes on this page */
|
|
|
|
bool
|
|
|
|
ServerPage::save(QString &errmsg)
|
|
|
|
{
|
|
|
|
|
|
|
|
/* save the server address */
|
|
|
|
/* save local address */
|
|
|
|
/* save the url for DNS access */
|
|
|
|
|
|
|
|
/* restart server */
|
|
|
|
|
|
|
|
/* save all? */
|
|
|
|
saveAddresses();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Loads the settings for this page */
|
|
|
|
void ServerPage::load()
|
|
|
|
{
|
|
|
|
|
|
|
|
/* load up configuration from rsPeers */
|
|
|
|
RsPeerDetails detail;
|
|
|
|
if (!rsPeers->getPeerDetails(rsPeers->getOwnId(), detail))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* set net mode */
|
|
|
|
int netIndex = 0;
|
|
|
|
switch(detail.tryNetMode)
|
|
|
|
{
|
|
|
|
case RS_NETMODE_EXT:
|
|
|
|
netIndex = 2;
|
|
|
|
break;
|
|
|
|
case RS_NETMODE_UDP:
|
|
|
|
netIndex = 1;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
case RS_NETMODE_UPNP:
|
|
|
|
netIndex = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
ui.netModeComboBox->setCurrentIndex(netIndex);
|
|
|
|
|
|
|
|
netIndex = 1;
|
|
|
|
if (detail.visState & RS_VS_DISC_ON)
|
|
|
|
{
|
|
|
|
netIndex = 0;
|
|
|
|
}
|
|
|
|
ui.discComboBox->setCurrentIndex(netIndex);
|
|
|
|
|
|
|
|
rsiface->lockData(); /* Lock Interface */
|
|
|
|
|
|
|
|
ui.totalDownloadRate->setValue(rsiface->getConfig().maxDownloadDataRate);
|
|
|
|
ui.totalUploadRate->setValue(rsiface->getConfig().maxUploadDataRate);
|
|
|
|
|
|
|
|
rsiface->unlockData(); /* UnLock Interface */
|
|
|
|
|
|
|
|
|
|
|
|
toggleUPnP();
|
2009-08-19 18:15:16 -04:00
|
|
|
|
2009-07-23 13:11:51 -04:00
|
|
|
|
|
|
|
/* Addresses must be set here - otherwise can't edit it */
|
|
|
|
/* set local address */
|
|
|
|
ui.localAddress->setText(QString::fromStdString(detail.localAddr));
|
|
|
|
ui.localPort -> setValue(detail.localPort);
|
|
|
|
/* set the server address */
|
|
|
|
ui.extAddress->setText(QString::fromStdString(detail.extAddr));
|
|
|
|
ui.extPort -> setValue(detail.extPort);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Loads the settings for this page */
|
|
|
|
void ServerPage::updateStatus()
|
|
|
|
{
|
|
|
|
|
|
|
|
/* load up configuration from rsPeers */
|
|
|
|
RsPeerDetails detail;
|
|
|
|
if (!rsPeers->getPeerDetails(rsPeers->getOwnId(), detail))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* only update if can't edit */
|
|
|
|
if (!ui.localPort->isEnabled())
|
|
|
|
{
|
|
|
|
/* set local address */
|
|
|
|
ui.localPort -> setValue(detail.localPort);
|
|
|
|
ui.extPort -> setValue(detail.extPort);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* set local address */
|
|
|
|
ui.localAddress->setText(QString::fromStdString(detail.localAddr));
|
|
|
|
/* set the server address */
|
|
|
|
ui.extAddress->setText(QString::fromStdString(detail.extAddr));
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void ServerPage::toggleUPnP()
|
|
|
|
{
|
|
|
|
/* switch on the radioButton */
|
|
|
|
bool settingChangeable = false;
|
|
|
|
if (0 != ui.netModeComboBox->currentIndex())
|
|
|
|
{
|
|
|
|
settingChangeable = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (settingChangeable)
|
|
|
|
{
|
|
|
|
ui.localAddress->setEnabled(false);
|
|
|
|
ui.localPort -> setEnabled(true);
|
|
|
|
ui.extAddress -> setEnabled(false);
|
|
|
|
ui.extPort -> setEnabled(true);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ui.localAddress->setEnabled(false);
|
|
|
|
ui.localPort -> setEnabled(false);
|
|
|
|
ui.extAddress -> setEnabled(false);
|
|
|
|
ui.extPort -> setEnabled(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ServerPage::saveAddresses()
|
|
|
|
{
|
|
|
|
QString str;
|
|
|
|
|
|
|
|
bool saveAddr = false;
|
|
|
|
|
|
|
|
|
|
|
|
RsPeerDetails detail;
|
|
|
|
std::string ownId = rsPeers->getOwnId();
|
|
|
|
|
|
|
|
if (!rsPeers->getPeerDetails(ownId, detail))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
int netIndex = ui.netModeComboBox->currentIndex();
|
|
|
|
|
|
|
|
/* Check if netMode has changed */
|
|
|
|
int netMode = 0;
|
|
|
|
switch(netIndex)
|
|
|
|
{
|
|
|
|
case 2:
|
|
|
|
netMode = RS_NETMODE_EXT;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
netMode = RS_NETMODE_UDP;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
case 0:
|
|
|
|
netMode = RS_NETMODE_UPNP;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (detail.tryNetMode != netMode)
|
|
|
|
{
|
|
|
|
rsPeers->setNetworkMode(ownId, netMode);
|
|
|
|
}
|
|
|
|
|
|
|
|
int visState = 0;
|
|
|
|
/* Check if vis has changed */
|
|
|
|
if (0 == ui.discComboBox->currentIndex())
|
|
|
|
{
|
|
|
|
visState |= RS_VS_DISC_ON;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (visState != detail.visState)
|
|
|
|
{
|
|
|
|
rsPeers->setVisState(ownId, visState);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (0 != netIndex)
|
|
|
|
{
|
|
|
|
saveAddr = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (saveAddr)
|
|
|
|
{
|
|
|
|
rsPeers->setLocalAddress(rsPeers->getOwnId(), ui.localAddress->text().toStdString(), ui.localPort->value());
|
|
|
|
rsPeers->setExtAddress(rsPeers->getOwnId(), ui.extAddress->text().toStdString(), ui.extPort->value());
|
|
|
|
}
|
|
|
|
|
|
|
|
rsicontrol->ConfigSetDataRates( ui.totalDownloadRate->value(), ui.totalUploadRate->value() );
|
|
|
|
load();
|
|
|
|
}
|
|
|
|
|