From 21ea281df46411ebf787f2043fbf442486918b9c Mon Sep 17 00:00:00 2001 From: csoler Date: Wed, 13 Oct 2021 22:50:09 +0200 Subject: [PATCH] added empty rsFriendServer struct and basic UI functionality --- libretroshare/src/libretroshare.pro | 1 + libretroshare/src/retroshare/rsfriendserver.h | 20 +++++ retroshare-friendserver/src/fsitem.h | 3 +- .../src/gui/FriendServerControl.cpp | 89 +++++++++++++++++-- retroshare-gui/src/gui/FriendServerControl.h | 20 ++++- retroshare-gui/src/gui/FriendServerControl.ui | 44 +++++++++ retroshare-gui/src/gui/FriendsDialog.cpp | 2 +- retroshare-gui/src/gui/settings/ServerPage.ui | 4 +- 8 files changed, 166 insertions(+), 17 deletions(-) create mode 100644 libretroshare/src/retroshare/rsfriendserver.h diff --git a/libretroshare/src/libretroshare.pro b/libretroshare/src/libretroshare.pro index da5f25ba4..caaabd0b7 100644 --- a/libretroshare/src/libretroshare.pro +++ b/libretroshare/src/libretroshare.pro @@ -145,6 +145,7 @@ PUBLIC_HEADERS = retroshare/rsdisc.h \ retroshare/rsrtt.h \ retroshare/rsconfig.h \ retroshare/rsversion.h \ + retroshare/rsfriendserver.h \ retroshare/rsservicecontrol.h \ retroshare/rsgxsdistsync.h diff --git a/libretroshare/src/retroshare/rsfriendserver.h b/libretroshare/src/retroshare/rsfriendserver.h new file mode 100644 index 000000000..cb516c1df --- /dev/null +++ b/libretroshare/src/retroshare/rsfriendserver.h @@ -0,0 +1,20 @@ +#include +#include +#include "util/rstime.h" + +class RsFriendServer +{ +public: + void start() {} + void stop() {} + + void checkServerAddress_async(const std::string&,uint16_t, const std::function& callback) + { + std::this_thread::sleep_for(std::chrono::seconds(1)); + callback(true); + } + void setServerAddress(const std::string&,uint16_t) {} + void setFriendsToRequest(uint32_t) {} +}; + +extern RsFriendServer *rsFriendServer; diff --git a/retroshare-friendserver/src/fsitem.h b/retroshare-friendserver/src/fsitem.h index d05df9873..4714178af 100644 --- a/retroshare-friendserver/src/fsitem.h +++ b/retroshare-friendserver/src/fsitem.h @@ -17,9 +17,8 @@ public: { setPriorityLevel(QOS_PRIORITY_DEFAULT) ; } - virtual void clear() override; - virtual ~RsFriendServerItem() {} + virtual void clear() override {} }; class RsFriendServerClientPublishItem: public RsFriendServerItem diff --git a/retroshare-gui/src/gui/FriendServerControl.cpp b/retroshare-gui/src/gui/FriendServerControl.cpp index d4ab1dc5c..53091c934 100644 --- a/retroshare-gui/src/gui/FriendServerControl.cpp +++ b/retroshare-gui/src/gui/FriendServerControl.cpp @@ -18,24 +18,97 @@ * * *******************************************************************************/ +#include +#include +#include + +#include "retroshare/rsfriendserver.h" + +#include "util/qtthreadsutils.h" +#include "gui/common/FilesDefs.h" + #include "FriendServerControl.h" -//#include #include +RsFriendServer *rsFriendServer = new RsFriendServer; + +#define ICON_STATUS_UNKNOWN ":/images/ledoff1.png" +#define ICON_STATUS_OK ":/images/ledon1.png" + /** Constructor */ FriendServerControl::FriendServerControl(QWidget *parent) { - /* Invoke the Qt Designer generated object setup routine */ - setupUi(this); + /* Invoke the Qt Designer generated object setup routine */ + setupUi(this); -// /* Hide Settings frame */ -// connect( ui.maxFriendLevelSB, SIGNAL(valueChanged(int)), this, SLOT(setMaxFriendLevel(int))); -// connect( ui.edgeLengthSB, SIGNAL(valueChanged(int)), this, SLOT(setEdgeLength(int))); -// connect( ui.freezeCheckBox, SIGNAL(toggled(bool)), this, SLOT(setFreezeState(bool))); -// connect( ui.nameBox, SIGNAL(textChanged(QString)), this, SLOT(setNameSearch(QString))); + mConnectionCheckTimer = new QTimer; + + QObject::connect(mConnectionCheckTimer,SIGNAL(timeout()),this,SLOT(checkServerAddress())); + QObject::connect(torServerAddress_LE,SIGNAL(textChanged(const QString&)),this,SLOT(onOnionAddressEdit(const QString&))); + + mCheckingServerMovie = new QMovie(":/images/loader/circleball-16.gif"); + + updateFriendServerStatusIcon(false); } FriendServerControl::~FriendServerControl() { + delete mCheckingServerMovie; + delete mConnectionCheckTimer; } + +void FriendServerControl::onOnOffClick(bool b) +{ + if(b) + rsFriendServer->start(); + else + rsFriendServer->stop(); +} + +void FriendServerControl::onOnionAddressEdit(const QString&) +{ + // Setup timer to auto-check the friend server address + + mConnectionCheckTimer->stop(); + mConnectionCheckTimer->setSingleShot(true); + mConnectionCheckTimer->setInterval(5000); // check in 5 secs unless something is changed in the mean time. + + mConnectionCheckTimer->start(); + + serverStatusCheckResult_LB->setMovie(mCheckingServerMovie); + mCheckingServerMovie->start(); +} + +void FriendServerControl::checkServerAddress() +{ + rsFriendServer->checkServerAddress_async(torServerAddress_LE->text().toStdString(),torServerPort_SB->value(), + [this](bool test_result) + { + RsQThreadUtils::postToObject( [=]() { updateFriendServerStatusIcon(test_result); },this); + } + ); +} + +void FriendServerControl::onNbFriendsToRequestsChanged(int n) +{ + rsFriendServer->setFriendsToRequest(n); +} + +void FriendServerControl::updateFriendServerStatusIcon(bool ok) +{ + if(ok) + { + torServerStatus_LB->setPixmap(FilesDefs::getPixmapFromQtResourcePath(ICON_STATUS_OK)) ; + torServerStatus_LB->setToolTip(tr("Friend server is currently reachable.")) ; + } + else + { + torServerStatus_LB->setPixmap(FilesDefs::getPixmapFromQtResourcePath(ICON_STATUS_UNKNOWN)) ; + torServerStatus_LB->setToolTip(tr("The proxy is not enabled or broken.\nAre all services up and running fine??\nAlso check your ports!")) ; + } + mCheckingServerMovie->stop(); +} + + + diff --git a/retroshare-gui/src/gui/FriendServerControl.h b/retroshare-gui/src/gui/FriendServerControl.h index ecdbce756..76cbb5b28 100644 --- a/retroshare-gui/src/gui/FriendServerControl.h +++ b/retroshare-gui/src/gui/FriendServerControl.h @@ -26,9 +26,21 @@ class FriendServerControl : public QWidget, public Ui::FriendServerControl { - Q_OBJECT + Q_OBJECT - public: - FriendServerControl(QWidget *parent = 0); - virtual ~FriendServerControl(); +public: + FriendServerControl(QWidget *parent = 0); + virtual ~FriendServerControl(); + +protected slots: + void onOnOffClick(bool b); + void onOnionAddressEdit(const QString&); + void onNbFriendsToRequestsChanged(int n); + void checkServerAddress(); + +private: + void updateFriendServerStatusIcon(bool ok); + + QTimer *mConnectionCheckTimer; + QMovie *mCheckingServerMovie; }; diff --git a/retroshare-gui/src/gui/FriendServerControl.ui b/retroshare-gui/src/gui/FriendServerControl.ui index aa699560c..681399c15 100644 --- a/retroshare-gui/src/gui/FriendServerControl.ui +++ b/retroshare-gui/src/gui/FriendServerControl.ui @@ -74,6 +74,13 @@ + + + + + + + @@ -83,6 +90,43 @@ + + + + + + Server port: + + + + + + + 1025 + + + 65536 + + + 1729 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + diff --git a/retroshare-gui/src/gui/FriendsDialog.cpp b/retroshare-gui/src/gui/FriendsDialog.cpp index 79338c9f8..5e896af02 100644 --- a/retroshare-gui/src/gui/FriendsDialog.cpp +++ b/retroshare-gui/src/gui/FriendsDialog.cpp @@ -89,9 +89,9 @@ FriendsDialog::FriendsDialog(QWidget *parent) : MainPage(parent) ui.avatar->setFrameType(AvatarWidget::STATUS_FRAME); ui.tabWidget->setTabPosition(QTabWidget::North); + ui.tabWidget->addTab(friendServerControl = new FriendServerControl(),QIcon(IMAGE_PEERS), tr("Friend Server")); ui.tabWidget->addTab(networkView = new NetworkView(),QIcon(IMAGE_NETWORK2), tr("Network graph")); ui.tabWidget->addTab(networkDialog = new NetworkDialog(),QIcon(IMAGE_PEERS), tr("Keyring")); - ui.tabWidget->addTab(friendServerControl = new FriendServerControl(),QIcon(IMAGE_PEERS), tr("Friend Server")); ui.tabWidget->hideCloseButton(0); ui.tabWidget->hideCloseButton(1); diff --git a/retroshare-gui/src/gui/settings/ServerPage.ui b/retroshare-gui/src/gui/settings/ServerPage.ui index 5ef7308b1..4cc8cf568 100755 --- a/retroshare-gui/src/gui/settings/ServerPage.ui +++ b/retroshare-gui/src/gui/settings/ServerPage.ui @@ -6,8 +6,8 @@ 0 0 - 712 - 502 + 738 + 540