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

@ -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 <retroshare/rsfriendserver.h>
#include <iostream>
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();
}