* Enabled network configuration control from GUI.

* Added Safe configuration save before quit().
 * Updated libretroshare's interface files.


git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@337 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
drbob 2008-02-07 16:20:14 +00:00
parent 806b8285f2
commit b7abbda1fb
5 changed files with 296 additions and 229 deletions

View File

@ -455,12 +455,14 @@ void MainWindow::doQuit()
if (confirm->result() == QDialog::Accepted)
{
rsicontrol->ConfigFinalSave();
qApp->quit();
} else {
delete confirm;
}
} else {
rsicontrol->ConfigFinalSave();
qApp->quit();
}
}

View File

@ -23,6 +23,7 @@
#include <rshare.h>
#include "ServerDialog.h"
#include <iostream>
#include <sstream>
#include "rsiface/rsiface.h"
#include "rsiface/rspeers.h"
@ -35,14 +36,13 @@ ServerDialog::ServerDialog(QWidget *parent)
{
/* Invoke the Qt Designer generated object setup routine */
ui.setupUi(this);
/* Create RshareSettings object */
_settings = new RshareSettings();
connect( ui.ManualButton, SIGNAL( toggled( bool ) ), this, SLOT( toggleUPnP( ) ) );
connect( ui.UPnPButton, SIGNAL( toggled( bool ) ), this, SLOT( toggleUPnP( ) ) );
/* Create RshareSettings object */
_settings = new RshareSettings();
connect( ui.netModeComboBox, SIGNAL( activated ( int ) ), this, SLOT( toggleUPnP( ) ) );
/* Hide platform specific features */
#ifdef Q_WS_WIN
@ -66,85 +66,104 @@ ServerDialog::save(QString &errmsg)
}
/** Loads the settings for this page */
void
ServerDialog::load()
/** Loads the settings for this page */
void ServerDialog::load()
{
/* get the shared directories */
rsiface->lockData(); /* Lock Interface */
/* set local address */
ui.localAddress->setText(QString::fromStdString(rsiface->getConfig().localAddr));
ui.localPort -> setValue(rsiface->getConfig().localPort);
/* set the server address */
ui.extAddress->setText(QString::fromStdString(rsiface->getConfig().extAddr));
ui.extPort -> setValue(rsiface->getConfig().extPort);
/* set the flags */
ui.chkFirewall ->setChecked(rsiface->getConfig().firewalled);
ui.chkForwarded ->setChecked(rsiface->getConfig().forwardPort);
/* now handle networking options */
if (rsiface->getConfig().DHTActive)
/* load up configuration from rsPeers */
RsPeerDetails detail;
if (!rsPeers->getPeerDetails(rsPeers->getOwnId(), detail))
{
ui.DHTButton -> setChecked(true);
}
else
{
ui.noDHTButton -> setChecked(true);
return;
}
int dhtPeers = rsiface->getConfig().DHTPeers;
if (!dhtPeers)
/* set net mode */
int netIndex = 0;
switch(detail.netMode)
{
ui.dhtStatus -> setText("DHT Off/Unavailable");
}
else if (dhtPeers < 20)
{
ui.dhtStatus -> setText("DHT Initialising");
}
else
{
ui.dhtStatus -> setText("DHT Active");
}
switch(rsiface->getConfig().uPnPState)
{
case UPNP_STATE_ACTIVE:
ui.upnpStatus -> setText("Forwarding Active");
case RS_NETMODE_EXT:
netIndex = 2;
break;
case UPNP_STATE_FAILED_UDP:
ui.upnpStatus -> setText("TCP Active/UDP Failed");
case RS_NETMODE_UDP:
netIndex = 1;
break;
case UPNP_STATE_FAILED_TCP:
ui.upnpStatus -> setText("Forwarding Failed");
break;
case UPNP_STATE_READY:
ui.upnpStatus -> setText("uPnP Ready");
break;
case UPNP_STATE_UNAVAILABILE:
ui.upnpStatus -> setText("uPnP Unavailable");
break;
case UPNP_STATE_UNINITIALISED:
default:
ui.upnpStatus -> setText("uPnP Uninitialised");
case RS_NETMODE_UPNP:
netIndex = 0;
break;
}
ui.netModeComboBox->setCurrentIndex(netIndex);
}
ui.upnpStatus->setReadOnly(true);
ui.dhtStatus ->setReadOnly(true);
if (rsiface->getConfig().uPnPActive)
/* set dht/disc */
netIndex = 1;
if (detail.visState & RS_VS_DHT_ON)
{
/* flag uPnP */
ui.UPnPButton->setChecked(true);
/* shouldn't fiddle with port */
netIndex = 0;
}
ui.dhtComboBox->setCurrentIndex(netIndex);
netIndex = 1;
if (detail.visState & RS_VS_DISC_ON)
{
netIndex = 0;
}
ui.discComboBox->setCurrentIndex(netIndex);
/* set the addresses */
/* 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);
/* set status */
std::ostringstream out;
out << "Network Mode: ";
switch(detail.netMode)
{
case RS_NETMODE_EXT:
out << "External Forwarded Port (UltraPEER Mode)";
break;
case RS_NETMODE_UDP:
out << "Firewalled";
break;
default:
case RS_NETMODE_UPNP:
out << "Automatic: UPnP Forwarded Port";
break;
}
out << std::endl;
out << "\tLocal Address: " << detail.localAddr;
out << ":" << detail.localPort;
out << std::endl;
out << "\tExternal Address: " << detail.extAddr;
out << ":" << detail.extPort;
out << std::endl;
out << "UPnP Status: ";
out << std::endl;
out << "DHT Status: ";
if (detail.visState & RS_VS_DHT_ON)
out << " Enabled";
else
{
/* noobie */
ui.ManualButton->setChecked(true);
out << " Disabled";
out << std::endl;
}
out << "Discovery Status: ";
if (detail.visState & RS_VS_DISC_ON)
out << " Enabled";
else
out << " Disabled";
out << std::endl;
ui.netStatusBox->setText(QString::fromStdString(out.str()));
ui.netStatusBox ->setReadOnly(true);
rsiface->lockData(); /* Lock Interface */
ui.totalRate->setValue(rsiface->getConfig().maxDataRate);
ui.indivRate->setValue(rsiface->getConfig().maxIndivDataRate);
@ -158,28 +177,32 @@ void ServerDialog::toggleUPnP()
{
/* switch on the radioButton */
bool settingChangeable = false;
if (ui.ManualButton->isChecked())
if (0 != ui.netModeComboBox->currentIndex())
{
settingChangeable = true;
}
if (settingChangeable)
{
ui.dhtComboBox->setEnabled(true);
// disabled until we've got it all working.
//ui.discComboBox->setEnabled(true);
ui.discComboBox->setEnabled(false);
ui.localAddress->setEnabled(true);
ui.localPort -> setEnabled(true);
ui.extAddress -> setEnabled(true);
ui.extPort -> setEnabled(true);
ui.chkFirewall-> setEnabled(true);
ui.chkForwarded->setEnabled(true);
}
else
{
ui.dhtComboBox->setEnabled(false);
ui.discComboBox->setEnabled(false);
ui.localAddress->setEnabled(false);
ui.localPort -> setEnabled(false);
ui.extAddress -> setEnabled(false);
ui.extPort -> setEnabled(false);
ui.chkFirewall-> setEnabled(false);
ui.chkForwarded->setEnabled(false);
}
}
@ -188,10 +211,57 @@ void ServerDialog::saveAddresses()
QString str;
bool saveAddr = false;
//rsicontrol -> NetworkDHTActive(ui.DHTButton->isChecked());
//rsicontrol -> NetworkUPnPActive(ui.UPnPButton->isChecked());
if (ui.ManualButton->isChecked())
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.netMode != netMode)
{
rsPeers->setNetworkMode(ownId, netMode);
}
int visState = 0;
/* Check if vis has changed */
if (0 == ui.discComboBox->currentIndex())
{
visState |= RS_VS_DISC_ON;
}
if (0 == ui.dhtComboBox->currentIndex())
{
visState |= RS_VS_DHT_ON;
}
if (visState != detail.visState)
{
rsPeers->setVisState(ownId, visState);
}
if (0 != netIndex)
{
saveAddr = true;
}
@ -199,7 +269,6 @@ void ServerDialog::saveAddresses()
if (saveAddr)
{
rsPeers->setLocalAddress(rsPeers->getOwnId(), ui.localAddress->text().toStdString(), ui.localPort->value());
//rsicontrol->ConfigSetLanConfig(ui.chkFirewall->isChecked(), ui.chkForwarded->isChecked());
rsPeers->setExtAddress(rsPeers->getOwnId(), ui.extAddress->text().toStdString(), ui.extPort->value());
}

View File

@ -5,14 +5,12 @@
<rect>
<x>0</x>
<y>0</y>
<width>419</width>
<height>371</height>
<width>416</width>
<height>345</height>
</rect>
</property>
<property name="sizePolicy" >
<sizepolicy>
<hsizetype>7</hsizetype>
<vsizetype>7</vsizetype>
<sizepolicy vsizetype="Expanding" hsizetype="Expanding" >
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
@ -522,30 +520,36 @@
</rect>
</property>
<layout class="QHBoxLayout" >
<property name="margin" >
<number>0</number>
</property>
<property name="spacing" >
<number>6</number>
</property>
<property name="leftMargin" >
<number>0</number>
</property>
<property name="topMargin" >
<number>0</number>
</property>
<property name="rightMargin" >
<number>0</number>
</property>
<property name="bottomMargin" >
<number>0</number>
</property>
<item>
<widget class="QLabel" name="label_14" >
<property name="text" >
<string>&lt;html>&lt;head>&lt;meta name="qrichtext" content="1" />&lt;style type="text/css">
p, li { white-space: pre-wrap; }
&lt;/style>&lt;/head>&lt;body style=" font-family:'Arial'; font-size:8pt; font-weight:400; font-style:normal; text-decoration:none;">
&lt;p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Total Rate (KB/s) &lt;/p>&lt;/body>&lt;/html></string>
<string>Total Rate (KB/s) </string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="totalRate" >
<property name="maximum" >
<number>4096</number>
</property>
<property name="minimum" >
<number>1</number>
</property>
<property name="maximum" >
<number>4096</number>
</property>
<property name="value" >
<number>1</number>
</property>
@ -563,30 +567,36 @@ p, li { white-space: pre-wrap; }
</rect>
</property>
<layout class="QHBoxLayout" >
<property name="margin" >
<number>0</number>
</property>
<property name="spacing" >
<number>6</number>
</property>
<property name="leftMargin" >
<number>0</number>
</property>
<property name="topMargin" >
<number>0</number>
</property>
<property name="rightMargin" >
<number>0</number>
</property>
<property name="bottomMargin" >
<number>0</number>
</property>
<item>
<widget class="QLabel" name="label_12" >
<property name="text" >
<string>&lt;html>&lt;head>&lt;meta name="qrichtext" content="1" />&lt;style type="text/css">
p, li { white-space: pre-wrap; }
&lt;/style>&lt;/head>&lt;body style=" font-family:'Arial'; font-size:8pt; font-weight:400; font-style:normal; text-decoration:none;">
&lt;p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Per Person &lt;/p>&lt;/body>&lt;/html></string>
<string>Per Person </string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="indivRate" >
<property name="maximum" >
<number>1024</number>
</property>
<property name="minimum" >
<number>1</number>
</property>
<property name="maximum" >
<number>1024</number>
</property>
<property name="value" >
<number>1</number>
</property>
@ -605,36 +615,47 @@ p, li { white-space: pre-wrap; }
</rect>
</property>
<property name="title" >
<string>Firewall/Router Configuration</string>
<string>External Visibility / Discovery Configuration</string>
</property>
<widget class="QRadioButton" name="ManualButton" >
<widget class="QComboBox" name="dhtComboBox" >
<property name="geometry" >
<rect>
<x>230</x>
<y>20</y>
<x>30</x>
<y>10</y>
<width>161</width>
<height>18</height>
<height>22</height>
</rect>
</property>
<property name="text" >
<string>Manual router setup.</string>
</property>
<item>
<property name="text" >
<string>DHT Enabled</string>
</property>
</item>
<item>
<property name="text" >
<string>DHT Disabled</string>
</property>
</item>
</widget>
<widget class="QRadioButton" name="UPnPButton" >
<widget class="QComboBox" name="discComboBox" >
<property name="geometry" >
<rect>
<x>10</x>
<y>20</y>
<width>211</width>
<height>18</height>
<x>220</x>
<y>10</y>
<width>161</width>
<height>22</height>
</rect>
</property>
<property name="text" >
<string>Use uPnP to configure router</string>
</property>
<property name="checked" >
<bool>true</bool>
</property>
<item>
<property name="text" >
<string>Discovery Enabled</string>
</property>
</item>
<item>
<property name="text" >
<string>Discovery Disabled</string>
</property>
</item>
</widget>
</widget>
<widget class="QGroupBox" name="groupBox_2" >
@ -649,34 +670,30 @@ p, li { white-space: pre-wrap; }
<property name="title" >
<string>Network Address Configuration (takes effect after restart)</string>
</property>
<widget class="QRadioButton" name="DHTButton" >
<widget class="QComboBox" name="netModeComboBox" >
<property name="geometry" >
<rect>
<x>10</x>
<y>20</y>
<width>211</width>
<height>18</height>
<x>30</x>
<y>10</y>
<width>351</width>
<height>22</height>
</rect>
</property>
<property name="text" >
<string>Use DHT to locate friends </string>
</property>
<property name="checked" >
<bool>true</bool>
</property>
</widget>
<widget class="QRadioButton" name="noDHTButton" >
<property name="geometry" >
<rect>
<x>230</x>
<y>20</y>
<width>161</width>
<height>18</height>
</rect>
</property>
<property name="text" >
<string>Manual IP Addresses</string>
</property>
<item>
<property name="text" >
<string>Automatic (Firewalled)</string>
</property>
</item>
<item>
<property name="text" >
<string>Firewalled + No UPnP</string>
</property>
</item>
<item>
<property name="text" >
<string>External (Forwarded) Port</string>
</property>
</item>
</widget>
</widget>
<widget class="QGroupBox" name="groupBox" >
@ -694,31 +711,49 @@ p, li { white-space: pre-wrap; }
<widget class="QWidget" name="layoutWidget" >
<property name="geometry" >
<rect>
<x>110</x>
<x>93</x>
<y>20</y>
<width>274</width>
<height>159</height>
<width>291</width>
<height>152</height>
</rect>
</property>
<layout class="QVBoxLayout" >
<property name="margin" >
<number>0</number>
</property>
<property name="spacing" >
<number>6</number>
</property>
<property name="leftMargin" >
<number>0</number>
</property>
<property name="topMargin" >
<number>0</number>
</property>
<property name="rightMargin" >
<number>0</number>
</property>
<property name="bottomMargin" >
<number>0</number>
</property>
<item>
<widget class="QLineEdit" name="dhtStatus" />
</item>
<item>
<widget class="QLineEdit" name="upnpStatus" />
<widget class="QTextEdit" name="netStatusBox" />
</item>
<item>
<layout class="QGridLayout" >
<property name="margin" >
<property name="leftMargin" >
<number>0</number>
</property>
<property name="spacing" >
<property name="topMargin" >
<number>0</number>
</property>
<property name="rightMargin" >
<number>0</number>
</property>
<property name="bottomMargin" >
<number>0</number>
</property>
<property name="horizontalSpacing" >
<number>6</number>
</property>
<property name="verticalSpacing" >
<number>6</number>
</property>
<item row="0" column="0" >
@ -726,12 +761,12 @@ p, li { white-space: pre-wrap; }
</item>
<item row="0" column="2" >
<widget class="QSpinBox" name="localPort" >
<property name="maximum" >
<number>65535</number>
</property>
<property name="minimum" >
<number>0</number>
</property>
<property name="maximum" >
<number>65535</number>
</property>
<property name="value" >
<number>7812</number>
</property>
@ -747,35 +782,23 @@ p, li { white-space: pre-wrap; }
</layout>
</item>
<item>
<layout class="QHBoxLayout" >
<property name="margin" >
<layout class="QGridLayout" >
<property name="leftMargin" >
<number>0</number>
</property>
<property name="spacing" >
<property name="topMargin" >
<number>0</number>
</property>
<property name="rightMargin" >
<number>0</number>
</property>
<property name="bottomMargin" >
<number>0</number>
</property>
<property name="horizontalSpacing" >
<number>6</number>
</property>
<item>
<widget class="QCheckBox" name="chkFirewall" >
<property name="text" >
<string>Firewalled</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="chkForwarded" >
<property name="text" >
<string>Forwarded Port</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QGridLayout" >
<property name="margin" >
<number>0</number>
</property>
<property name="spacing" >
<property name="verticalSpacing" >
<number>6</number>
</property>
<item row="0" column="0" >
@ -783,12 +806,12 @@ p, li { white-space: pre-wrap; }
</item>
<item row="0" column="2" >
<widget class="QSpinBox" name="extPort" >
<property name="maximum" >
<number>65535</number>
</property>
<property name="minimum" >
<number>0</number>
</property>
<property name="maximum" >
<number>65535</number>
</property>
<property name="value" >
<number>7812</number>
</property>
@ -797,10 +820,7 @@ p, li { white-space: pre-wrap; }
<item row="0" column="1" >
<widget class="QLabel" name="label_4" >
<property name="text" >
<string>&lt;html>&lt;head>&lt;meta name="qrichtext" content="1" />&lt;style type="text/css">
p, li { white-space: pre-wrap; }
&lt;/style>&lt;/head>&lt;body style=" font-family:'Arial'; font-size:8pt; font-weight:400; font-style:normal; text-decoration:none;">
&lt;p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Port:&lt;/p>&lt;/body>&lt;/html></string>
<string>Port:</string>
</property>
</widget>
</item>
@ -818,10 +838,7 @@ p, li { white-space: pre-wrap; }
</rect>
</property>
<property name="text" >
<string>&lt;html>&lt;head>&lt;meta name="qrichtext" content="1" />&lt;style type="text/css">
p, li { white-space: pre-wrap; }
&lt;/style>&lt;/head>&lt;body style=" font-family:'Arial'; font-size:8pt; font-weight:400; font-style:normal; text-decoration:none;">
&lt;p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">External Address:&lt;/p>&lt;/body>&lt;/html></string>
<string>External Address</string>
</property>
</widget>
<widget class="QLabel" name="label_6" >
@ -834,54 +851,27 @@ p, li { white-space: pre-wrap; }
</rect>
</property>
<property name="text" >
<string>&lt;html>&lt;head>&lt;meta name="qrichtext" content="1" />&lt;style type="text/css">
p, li { white-space: pre-wrap; }
&lt;/style>&lt;/head>&lt;body style=" font-family:'Arial'; font-size:8pt; font-weight:400; font-style:normal; text-decoration:none;">
&lt;p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">DHT Status&lt;/p>&lt;/body>&lt;/html></string>
</property>
</widget>
<widget class="QLabel" name="label_3" >
<property name="geometry" >
<rect>
<x>10</x>
<y>60</y>
<width>80</width>
<height>21</height>
</rect>
</property>
<property name="text" >
<string>uPnP Status</string>
<string>Network Status</string>
</property>
</widget>
<widget class="QLabel" name="label" >
<property name="geometry" >
<rect>
<x>10</x>
<y>90</y>
<y>130</y>
<width>81</width>
<height>21</height>
</rect>
</property>
<property name="text" >
<string>&lt;html>&lt;head>&lt;meta name="qrichtext" content="1" />&lt;style type="text/css">
p, li { white-space: pre-wrap; }
&lt;/style>&lt;/head>&lt;body style=" font-family:'Arial'; font-size:8pt; font-weight:400; font-style:normal; text-decoration:none;">
&lt;p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Local Address:&lt;/p>&lt;/body>&lt;/html></string>
<string>Local Address</string>
</property>
</widget>
</widget>
</widget>
<tabstops>
<tabstop>DHTButton</tabstop>
<tabstop>noDHTButton</tabstop>
<tabstop>UPnPButton</tabstop>
<tabstop>ManualButton</tabstop>
<tabstop>dhtStatus</tabstop>
<tabstop>upnpStatus</tabstop>
<tabstop>localAddress</tabstop>
<tabstop>localPort</tabstop>
<tabstop>chkFirewall</tabstop>
<tabstop>chkForwarded</tabstop>
<tabstop>extAddress</tabstop>
<tabstop>extPort</tabstop>
<tabstop>totalRate</tabstop>

View File

@ -256,7 +256,7 @@ virtual int ConfigSetIncomingDir( std::string dir ) = 0;
virtual int ConfigSetDataRates( int total, int indiv ) = 0;
virtual int ConfigSetBootPrompt( bool on ) = 0;
//virtual int ConfigSave( ) = 0;
virtual void ConfigFinalSave( ) = 0;
/****************************************/

View File

@ -45,6 +45,10 @@ const uint32_t RS_NETMODE_UDP = 0x0001;
const uint32_t RS_NETMODE_UPNP = 0x0002;
const uint32_t RS_NETMODE_EXT = 0x0003;
/* Visibility */
const uint32_t RS_VS_DHT_ON = 0x0001;
const uint32_t RS_VS_DISC_ON = 0x0002;
/* State */
const uint32_t RS_PEER_STATE_FRIEND = 0x0001;
const uint32_t RS_PEER_STATE_ONLINE = 0x0002;
@ -90,6 +94,7 @@ class RsPeerDetails
uint16_t extPort;
uint32_t netMode;
uint32_t visState;
/* basic stats */
uint32_t lastConnect; /* how long ago */
@ -129,6 +134,7 @@ virtual bool connectAttempt(std::string id) = 0;
virtual bool setLocalAddress(std::string id, std::string addr, uint16_t port) = 0;
virtual bool setExtAddress( std::string id, std::string addr, uint16_t port) = 0;
virtual bool setNetworkMode(std::string id, uint32_t netMode) = 0;
virtual bool setVisState(std::string id, uint32_t vis) = 0;
/* Auth Stuff */
virtual std::string GetRetroshareInvite() = 0;