added empty rsFriendServer struct and basic UI functionality

This commit is contained in:
csoler 2021-10-13 22:50:09 +02:00
parent 3f6503dfc3
commit 21ea281df4
8 changed files with 166 additions and 17 deletions

View file

@ -145,6 +145,7 @@ PUBLIC_HEADERS = retroshare/rsdisc.h \
retroshare/rsrtt.h \ retroshare/rsrtt.h \
retroshare/rsconfig.h \ retroshare/rsconfig.h \
retroshare/rsversion.h \ retroshare/rsversion.h \
retroshare/rsfriendserver.h \
retroshare/rsservicecontrol.h \ retroshare/rsservicecontrol.h \
retroshare/rsgxsdistsync.h retroshare/rsgxsdistsync.h

View file

@ -0,0 +1,20 @@
#include <functional>
#include <thread>
#include "util/rstime.h"
class RsFriendServer
{
public:
void start() {}
void stop() {}
void checkServerAddress_async(const std::string&,uint16_t, const std::function<void (bool result_status)>& 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;

View file

@ -17,9 +17,8 @@ public:
{ {
setPriorityLevel(QOS_PRIORITY_DEFAULT) ; setPriorityLevel(QOS_PRIORITY_DEFAULT) ;
} }
virtual void clear() override;
virtual ~RsFriendServerItem() {} virtual ~RsFriendServerItem() {}
virtual void clear() override {}
}; };
class RsFriendServerClientPublishItem: public RsFriendServerItem class RsFriendServerClientPublishItem: public RsFriendServerItem

View file

@ -18,24 +18,97 @@
* * * *
*******************************************************************************/ *******************************************************************************/
#include <QTimer>
#include <QMovie>
#include <QTcpSocket>
#include "retroshare/rsfriendserver.h"
#include "util/qtthreadsutils.h"
#include "gui/common/FilesDefs.h"
#include "FriendServerControl.h" #include "FriendServerControl.h"
//#include <retroshare/rsfriendserver.h>
#include <iostream> #include <iostream>
RsFriendServer *rsFriendServer = new RsFriendServer;
#define ICON_STATUS_UNKNOWN ":/images/ledoff1.png"
#define ICON_STATUS_OK ":/images/ledon1.png"
/** Constructor */ /** Constructor */
FriendServerControl::FriendServerControl(QWidget *parent) FriendServerControl::FriendServerControl(QWidget *parent)
{ {
/* Invoke the Qt Designer generated object setup routine */ /* Invoke the Qt Designer generated object setup routine */
setupUi(this); setupUi(this);
// /* Hide Settings frame */ mConnectionCheckTimer = new QTimer;
// connect( ui.maxFriendLevelSB, SIGNAL(valueChanged(int)), this, SLOT(setMaxFriendLevel(int)));
// connect( ui.edgeLengthSB, SIGNAL(valueChanged(int)), this, SLOT(setEdgeLength(int))); QObject::connect(mConnectionCheckTimer,SIGNAL(timeout()),this,SLOT(checkServerAddress()));
// connect( ui.freezeCheckBox, SIGNAL(toggled(bool)), this, SLOT(setFreezeState(bool))); QObject::connect(torServerAddress_LE,SIGNAL(textChanged(const QString&)),this,SLOT(onOnionAddressEdit(const QString&)));
// connect( ui.nameBox, SIGNAL(textChanged(QString)), this, SLOT(setNameSearch(QString)));
mCheckingServerMovie = new QMovie(":/images/loader/circleball-16.gif");
updateFriendServerStatusIcon(false);
} }
FriendServerControl::~FriendServerControl() 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();
}

View file

@ -26,9 +26,21 @@
class FriendServerControl : public QWidget, public Ui::FriendServerControl class FriendServerControl : public QWidget, public Ui::FriendServerControl
{ {
Q_OBJECT Q_OBJECT
public: public:
FriendServerControl(QWidget *parent = 0); FriendServerControl(QWidget *parent = 0);
virtual ~FriendServerControl(); 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;
}; };

View file

@ -74,6 +74,13 @@
</property> </property>
</widget> </widget>
</item> </item>
<item>
<widget class="QLabel" name="serverStatusCheckResult_LB">
<property name="text">
<string/>
</property>
</widget>
</item>
<item> <item>
<widget class="QLabel" name="torServerStatus_LB"> <widget class="QLabel" name="torServerStatus_LB">
<property name="text"> <property name="text">
@ -83,6 +90,43 @@
</item> </item>
</layout> </layout>
</item> </item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QLabel" name="label_3">
<property name="text">
<string>Server port:</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="torServerPort_SB">
<property name="minimum">
<number>1025</number>
</property>
<property name="maximum">
<number>65536</number>
</property>
<property name="value">
<number>1729</number>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item> <item>
<spacer name="verticalSpacer"> <spacer name="verticalSpacer">
<property name="orientation"> <property name="orientation">

View file

@ -89,9 +89,9 @@ FriendsDialog::FriendsDialog(QWidget *parent) : MainPage(parent)
ui.avatar->setFrameType(AvatarWidget::STATUS_FRAME); ui.avatar->setFrameType(AvatarWidget::STATUS_FRAME);
ui.tabWidget->setTabPosition(QTabWidget::North); 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(networkView = new NetworkView(),QIcon(IMAGE_NETWORK2), tr("Network graph"));
ui.tabWidget->addTab(networkDialog = new NetworkDialog(),QIcon(IMAGE_PEERS), tr("Keyring")); 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(0);
ui.tabWidget->hideCloseButton(1); ui.tabWidget->hideCloseButton(1);

View file

@ -6,8 +6,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>712</width> <width>738</width>
<height>502</height> <height>540</height>
</rect> </rect>
</property> </property>
<layout class="QVBoxLayout" name="ServerPageVLayout"> <layout class="QVBoxLayout" name="ServerPageVLayout">