diff --git a/retroshare-gui/src/RetroShare.pro b/retroshare-gui/src/RetroShare.pro index 212417c8e..217924ab3 100644 --- a/retroshare-gui/src/RetroShare.pro +++ b/retroshare-gui/src/RetroShare.pro @@ -305,6 +305,7 @@ HEADERS += rshare.h \ gui/settings/SoundPage.h \ gui/settings/TransferPage.h \ gui/settings/ChatPage.h \ + gui/settings/RelayPage.h \ gui/settings/AddFileAssociationDialog.h \ gui/toaster/MessageToaster.h \ gui/toaster/OnlineToaster.h \ @@ -424,6 +425,7 @@ FORMS += gui/StartDialog.ui \ gui/settings/TransferPage.ui \ gui/settings/SoundPage.ui \ gui/settings/ChatPage.ui \ + gui/settings/RelayPage.ui \ gui/settings/PluginItem.ui \ gui/toaster/MessageToaster.ui \ gui/toaster/OnlineToaster.ui \ @@ -577,6 +579,7 @@ SOURCES += main.cpp \ gui/settings/SoundPage.cpp \ gui/settings/TransferPage.cpp \ gui/settings/ChatPage.cpp \ + gui/settings/RelayPage.cpp \ gui/settings/AddFileAssociationDialog.cpp \ gui/statusbar/peerstatus.cpp \ gui/statusbar/natstatus.cpp \ diff --git a/retroshare-gui/src/gui/ForumsDialog.cpp b/retroshare-gui/src/gui/ForumsDialog.cpp index 202da0cf9..fae797d1e 100644 --- a/retroshare-gui/src/gui/ForumsDialog.cpp +++ b/retroshare-gui/src/gui/ForumsDialog.cpp @@ -566,7 +566,7 @@ void ForumsDialog::insertForums() uint32_t i = 0; uint32_t popLimit = 0; std::multimap::reverse_iterator rit; - for(rit = popMap.rbegin(); ((rit != popMap.rend()) && (i < popCount)); rit++, i++); + for(rit = popMap.rbegin(); ((rit != popMap.rend()) && (i < popCount)); rit++, i++) ; if (rit != popMap.rend()) { popLimit = rit->first; } diff --git a/retroshare-gui/src/gui/settings/RelayPage.cpp b/retroshare-gui/src/gui/settings/RelayPage.cpp new file mode 100644 index 000000000..6864b66db --- /dev/null +++ b/retroshare-gui/src/gui/settings/RelayPage.cpp @@ -0,0 +1,278 @@ +/**************************************************************** + * RetroShare is distributed under the following license: + * + * Copyright (C) 2006 - 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 "RelayPage.h" + +#include "rshare.h" + +#include +#include + +#include +#include +#include +#include + +#include + +RelayPage::RelayPage(QWidget * parent, Qt::WFlags flags) + : ConfigPage(parent, flags) +{ + /* Invoke the Qt Designer generated object setup routine */ + ui.setupUi(this); + + QObject::connect(ui.noFriendSpinBox,SIGNAL(valueChanged(int)),this,SLOT(updateRelayOptions())); + QObject::connect(ui.noFOFSpinBox,SIGNAL(valueChanged(int)),this,SLOT(updateRelayOptions())); + QObject::connect(ui.noGeneralSpinBox,SIGNAL(valueChanged(int)),this,SLOT(updateRelayOptions())); + QObject::connect(ui.bandFriendSpinBox,SIGNAL(valueChanged(int)),this,SLOT(updateRelayOptions())); + QObject::connect(ui.bandFOFSpinBox,SIGNAL(valueChanged(int)),this,SLOT(updateRelayOptions())); + QObject::connect(ui.bandGeneralSpinBox,SIGNAL(valueChanged(int)),this,SLOT(updateRelayOptions())); + + QObject::connect(ui.addPushButton,SIGNAL(clicked()),this,SLOT(addServer())); + QObject::connect(ui.removePushButton,SIGNAL(clicked()),this,SLOT(removeServer())); + QObject::connect(ui.DhtLineEdit,SIGNAL(textChanged(const QString &)),this,SLOT(checkKey())); + + QObject::connect(ui.enableCheckBox,SIGNAL(stateChanged(int)),this,SLOT(updateEnabled())); + QObject::connect(ui.serverCheckBox,SIGNAL(stateChanged(int)),this,SLOT(updateEnabled())); + + + /* Hide platform specific features */ +#ifdef Q_WS_WIN + +#endif +} + + /** Saves the changes on this page */ +bool RelayPage::save(QString &errmsg) +{ + + int nFriends = ui.noFriendSpinBox->value(); + int friendBandwidth = ui.bandFriendSpinBox->value(); + + int nFOF = ui.noFOFSpinBox->value(); + int fofBandwidth = ui.bandFOFSpinBox->value(); + + int nGeneral = ui.noGeneralSpinBox->value(); + int genBandwidth = ui.bandGeneralSpinBox->value(); + + int total = nFriends + nFOF + nGeneral; + + rsDht->setRelayAllowance(RSDHT_RELAY_CLASS_ALL, total, 0); + rsDht->setRelayAllowance(RSDHT_RELAY_CLASS_FRIENDS, nFriends, 1024 * friendBandwidth); + rsDht->setRelayAllowance(RSDHT_RELAY_CLASS_FOF, nFOF, 1024 * fofBandwidth); + rsDht->setRelayAllowance(RSDHT_RELAY_CLASS_GENERAL, nGeneral, 1024 * genBandwidth); + + uint32_t relayMode = 0; + if (ui.enableCheckBox->isChecked()) + { + relayMode |= RSDHT_RELAY_ENABLED; + + if (ui.serverCheckBox->isChecked()) + { + relayMode |= RSDHT_RELAY_MODE_ON; + } + else + { + relayMode |= RSDHT_RELAY_MODE_OFF; + } + } + else + { + relayMode |= RSDHT_RELAY_MODE_OFF; + } + + rsDht->setRelayMode(relayMode); + return true; +} + + /** Loads the settings for this page */ +void RelayPage::load() +{ + uint32_t count; + uint32_t bandwidth; + rsDht->getRelayAllowance(RSDHT_RELAY_CLASS_FRIENDS, count, bandwidth); + ui.noFriendSpinBox->setValue(count); + ui.bandFriendSpinBox->setValue(bandwidth / 1000); + + rsDht->getRelayAllowance(RSDHT_RELAY_CLASS_FOF, count, bandwidth); + ui.noFOFSpinBox->setValue(count); + ui.bandFOFSpinBox->setValue(bandwidth / 1000); + + rsDht->getRelayAllowance(RSDHT_RELAY_CLASS_GENERAL, count, bandwidth); + ui.noGeneralSpinBox->setValue(count); + ui.bandGeneralSpinBox->setValue(bandwidth / 1000); + + + uint32_t relayMode = rsDht->getRelayMode(); + if (relayMode & RSDHT_RELAY_ENABLED) + { + ui.enableCheckBox->setCheckState(Qt::Checked); + if ((relayMode & RSDHT_RELAY_MODE_MASK) == RSDHT_RELAY_MODE_OFF) + { + ui.serverCheckBox->setCheckState(Qt::Unchecked); + } + else + { + ui.serverCheckBox->setCheckState(Qt::Checked); + } + } + else + { + ui.enableCheckBox->setCheckState(Qt::Unchecked); + ui.serverCheckBox->setCheckState(Qt::Unchecked); + } + + loadServers(); + updateRelayOptions(); + updateEnabled(); + checkKey(); +} + +void RelayPage::loadServers() +{ + std::list servers; + std::list::iterator it; + + rsDht->getRelayServerList(servers); + + ui.serverTreeWidget->clear(); + for(it = servers.begin(); it != servers.end(); it++) + { + QTreeWidgetItem *item = new QTreeWidgetItem(); + item->setData(0, Qt::DisplayRole, QString::fromStdString(*it)); + ui.serverTreeWidget->addTopLevelItem(item); + } +} + + + +void RelayPage::updateRelayOptions() +{ + int nFriends = ui.noFriendSpinBox->value(); + int friendBandwidth = ui.bandFriendSpinBox->value(); + + int nFOF = ui.noFOFSpinBox->value(); + int fofBandwidth = ui.bandFOFSpinBox->value(); + + int nGeneral = ui.noGeneralSpinBox->value(); + int genBandwidth = ui.bandGeneralSpinBox->value(); + + std::ostringstream tfriendout; + tfriendout << nFriends * friendBandwidth * 2; + ui.totalFriendLineEdit->setText(QString::fromStdString(tfriendout.str())); + + std::ostringstream tfofout; + tfofout << nFOF * fofBandwidth * 2; + ui.totalFOFLineEdit->setText(QString::fromStdString(tfofout.str())); + + std::ostringstream tgenout; + tgenout << nGeneral * genBandwidth * 2; + ui.totalGeneralLineEdit->setText(QString::fromStdString(tgenout.str())); + + std::ostringstream totalout; + totalout << (nFriends * friendBandwidth + + nFOF * fofBandwidth + + nGeneral * genBandwidth) * 2; + ui.totalBandwidthLineEdit->setText(QString::fromStdString(totalout.str())); + + std::ostringstream countout; + countout << (nFriends + nFOF + nGeneral); + ui.noTotalLineEdit->setText(QString::fromStdString(countout.str())); +} + +void RelayPage::updateEnabled() +{ + std::cerr << "RelayPage::updateEnabled()" << std::endl; + + if (ui.enableCheckBox->isChecked()) + { + ui.groupBox->setEnabled(true); + if (ui.serverCheckBox->isChecked()) + { + std::cerr << "RelayPage::updateEnabled() Both Enabled" << std::endl; + ui.serverGroupBox->setEnabled(true); + } + else + { + std::cerr << "RelayPage::updateEnabled() Options Only Enabled" << std::endl; + ui.serverGroupBox->setEnabled(false); + } + } + else + { + std::cerr << "RelayPage::updateEnabled() Both Disabled" << std::endl; + ui.groupBox->setEnabled(false); + ui.serverGroupBox->setEnabled(false); + } + +} + + +void RelayPage::checkKey() +{ + + std::string server = ui.DhtLineEdit->text().toStdString(); + std::cerr << "RelayPage::checkKey() length: " << server.length(); + std::cerr << std::endl; + if (server.length() == 40) + { + ui.keyOkBox->setChecked(Qt::Checked); + } + else + { + ui.keyOkBox->setChecked(Qt::Unchecked); + } +} + + +void RelayPage::addServer() +{ + std::cerr << "RelayPage::addServer()"; + std::cerr << std::endl; + + if (!ui.keyOkBox->isChecked()) + { + return; + } + + std::string server = ui.DhtLineEdit->text().toStdString(); + + bool ok = rsDht->addRelayServer(server); + if (ok) + { + ui.DhtLineEdit->setText(QString("")); + } + loadServers(); +} + +void RelayPage::removeServer() +{ + QTreeWidgetItem *item = ui.serverTreeWidget->currentItem(); + if (item) + { + std::string server = item->data(0, Qt::DisplayRole).toString().toStdString(); + rsDht->removeRelayServer(server); + } + + loadServers(); +} + + diff --git a/retroshare-gui/src/gui/settings/RelayPage.h b/retroshare-gui/src/gui/settings/RelayPage.h new file mode 100644 index 000000000..9bce561b3 --- /dev/null +++ b/retroshare-gui/src/gui/settings/RelayPage.h @@ -0,0 +1,57 @@ +/**************************************************************** + * RetroShare is distributed under the following license: + * + * Copyright (C) 2006 - 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. + ****************************************************************/ + +#ifndef RELAYPAGE_H +#define RELAYPAGE_H + +# include + +#include "configpage.h" +#include "ui_RelayPage.h" + +class RelayPage: public ConfigPage +{ + Q_OBJECT + + public: + RelayPage(QWidget * parent = 0, Qt::WFlags flags = 0); + ~RelayPage() {} + + /** Saves the changes on this page */ + virtual bool save(QString &/*errmsg*/); + /** Loads the settings for this page */ + virtual void load(); + + public slots: + void updateRelayOptions(); + void updateEnabled(); + void checkKey(); + void addServer(); + void removeServer(); + void loadServers(); + + private: + + Ui::RelayPage ui; +}; + +#endif //RELAYPAGE_H + diff --git a/retroshare-gui/src/gui/settings/RelayPage.ui b/retroshare-gui/src/gui/settings/RelayPage.ui new file mode 100644 index 000000000..1b5f31e5b --- /dev/null +++ b/retroshare-gui/src/gui/settings/RelayPage.ui @@ -0,0 +1,372 @@ + + + RelayPage + + + + 0 + 0 + 486 + 360 + + + + + + + + + Enable Relay Connections + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Use Relay Servers + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + true + + + Relay options + + + + 0 + + + 0 + + + + + Qt::Horizontal + + + + 110 + 20 + + + + + + + + Number + + + + + + + Qt::Horizontal + + + + 6 + 20 + + + + + + + + Bandwidth per link + + + + + + + Qt::Vertical + + + + + + + Total Bandwidth + + + + + + + Friends + + + + + + + 3 + + + 99 + + + + + + + x + + + + + + + kB/s + + + 1 + + + 100 + + + + + + + Qt::NoFocus + + + true + + + + + + + Friends of Friends + + + + + + + + + + x + + + + + + + kB/s + + + 1 + + + 100 + + + + + + + Qt::NoFocus + + + true + + + + + + + General + + + + + + + + + + x + + + + + + + kB/s + + + 1 + + + 100 + + + + + + + Qt::NoFocus + + + true + + + + + + + Qt::Horizontal + + + + + + + Qt::WheelFocus + + + true + + + + + + + Total: + + + + + + + Qt::Horizontal + + + + 123 + 20 + + + + + + + + Qt::NoFocus + + + true + + + + + + + + + + Relay Server Setup + + + + -1 + + + 0 + + + 0 + + + + + HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH; + + + + + + + + + + false + + + + + + true + + + + + + + Add Server + + + + + + + + Server Dht Key + + + + + + + + Remove Server + + + + + + + + + + + diff --git a/retroshare-gui/src/gui/settings/rsettingswin.cpp b/retroshare-gui/src/gui/settings/rsettingswin.cpp index e2dcd37a2..2639fa22c 100644 --- a/retroshare-gui/src/gui/settings/rsettingswin.cpp +++ b/retroshare-gui/src/gui/settings/rsettingswin.cpp @@ -31,6 +31,7 @@ #include "FileAssociationsPage.h" #include "SoundPage.h" #include "TransferPage.h" +#include "RelayPage.h" #include "ChatPage.h" #include "MessagePage.h" #include "ForumPage.h" @@ -107,8 +108,9 @@ RSettingsWin::initStackedWidget() stackedWidget->addWidget(new GeneralPage(0)); stackedWidget->addWidget(new ServerPage()); stackedWidget->addWidget(new TransferPage()); + stackedWidget->addWidget(new RelayPage() ); stackedWidget->addWidget(new DirectoriesPage()); - stackedWidget->addWidget(new PluginsPage() ); + stackedWidget->addWidget(new PluginsPage() ); stackedWidget->addWidget(new NotifyPage()); stackedWidget->addWidget(new CryptoPage()); stackedWidget->addWidget(new MessagePage()); @@ -143,6 +145,10 @@ RSettingsWin::setNewPage(int page) text = tr("Transfer"); pageicon->setPixmap(QPixmap(":/images/ktorrent32.png")); break; + case Relay: + text = tr("Relay"); + pageicon->setPixmap(QPixmap(":/images/server_24x24.png")); + break; case Notify: text = tr("Notify"); pageicon->setPixmap(QPixmap(":/images/status_unknown.png")); diff --git a/retroshare-gui/src/gui/settings/rsettingswin.h b/retroshare-gui/src/gui/settings/rsettingswin.h index ae51ce2e4..4d8dd28d9 100755 --- a/retroshare-gui/src/gui/settings/rsettingswin.h +++ b/retroshare-gui/src/gui/settings/rsettingswin.h @@ -31,7 +31,7 @@ class RSettingsWin: public QDialog, private Ui::Settings Q_OBJECT public: - enum PageType { LastPage = -1, General = 0, Server, Transfer, + enum PageType { LastPage = -1, General = 0, Server, Transfer,Relay, Directories, Plugins, Notify, Security, Message, Forum, Chat, Appearance, Sound, Fileassociations }; static void showYourself(QWidget *parent, PageType page = LastPage); diff --git a/retroshare-gui/src/gui/settings/settings.ui b/retroshare-gui/src/gui/settings/settings.ui index 6dbea58ac..84bfa4219 100755 --- a/retroshare-gui/src/gui/settings/settings.ui +++ b/retroshare-gui/src/gui/settings/settings.ui @@ -107,6 +107,15 @@ :/images/ktorrent32.png:/images/ktorrent32.png + + + Relays + + + + :/images/server_24x24.png:/images/server_24x24.png + + Directories