mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
added control over received peers from FS
This commit is contained in:
parent
5847b08766
commit
24ad687c7f
@ -22,6 +22,7 @@
|
|||||||
#include <QMovie>
|
#include <QMovie>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QTcpSocket>
|
#include <QTcpSocket>
|
||||||
|
#include <QMenu>
|
||||||
|
|
||||||
#include "retroshare/rsfriendserver.h"
|
#include "retroshare/rsfriendserver.h"
|
||||||
#include "retroshare/rstor.h"
|
#include "retroshare/rstor.h"
|
||||||
@ -78,13 +79,13 @@ FriendServerControl::FriendServerControl(QWidget *parent)
|
|||||||
|
|
||||||
whileBlocking(autoAccept_CB)->setChecked(rsFriendServer->autoAddFriends());
|
whileBlocking(autoAccept_CB)->setChecked(rsFriendServer->autoAddFriends());
|
||||||
|
|
||||||
// init values
|
// Init values
|
||||||
|
|
||||||
torServerFriendsToRequest_SB->setValue(rsFriendServer->friendsToRequest());
|
whileBlocking(torServerFriendsToRequest_SB)->setValue(rsFriendServer->friendsToRequest());
|
||||||
torServerAddress_LE->setText(QString::fromStdString(rsFriendServer->friendsServerAddress().c_str()));
|
whileBlocking(torServerAddress_LE)->setText(QString::fromStdString(rsFriendServer->friendsServerAddress().c_str()));
|
||||||
torServerPort_SB->setValue(rsFriendServer->friendsServerPort());
|
whileBlocking(torServerPort_SB)->setValue(rsFriendServer->friendsServerPort());
|
||||||
|
|
||||||
// connect slignals/slots
|
// Connect slignals/slots
|
||||||
|
|
||||||
QObject::connect(friendServerOnOff_CB,SIGNAL(toggled(bool)),this,SLOT(onOnOffClick(bool)));
|
QObject::connect(friendServerOnOff_CB,SIGNAL(toggled(bool)),this,SLOT(onOnOffClick(bool)));
|
||||||
QObject::connect(torServerFriendsToRequest_SB,SIGNAL(valueChanged(int)),this,SLOT(onFriendsToRequestChanged(int)));
|
QObject::connect(torServerFriendsToRequest_SB,SIGNAL(valueChanged(int)),this,SLOT(onFriendsToRequestChanged(int)));
|
||||||
@ -93,17 +94,29 @@ FriendServerControl::FriendServerControl(QWidget *parent)
|
|||||||
QObject::connect(autoAccept_CB,SIGNAL(toggled(bool)),this,SLOT(onAutoAddFriends(bool)));
|
QObject::connect(autoAccept_CB,SIGNAL(toggled(bool)),this,SLOT(onAutoAddFriends(bool)));
|
||||||
|
|
||||||
QObject::connect(mConnectionCheckTimer,SIGNAL(timeout()),this,SLOT(checkServerAddress()));
|
QObject::connect(mConnectionCheckTimer,SIGNAL(timeout()),this,SLOT(checkServerAddress()));
|
||||||
|
QObject::connect(status_TW, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(launchStatusContextMenu(QPoint)));
|
||||||
|
|
||||||
mCheckingServerMovie = new QMovie(":/images/loader/circleball-16.gif");
|
mCheckingServerMovie = new QMovie(":/images/loader/circleball-16.gif");
|
||||||
|
|
||||||
updateFriendServerStatusIcon(false);
|
updateFriendServerStatusIcon(false);
|
||||||
|
|
||||||
mEventHandlerId = 0;
|
makeFriend_ACT = new QAction(tr("Make friend")); // makes SSL-only friend with the peer
|
||||||
|
|
||||||
|
QObject::connect(makeFriend_ACT,SIGNAL(triggered()),this,SLOT(makeFriend()));
|
||||||
|
|
||||||
|
mEventHandlerId_fs = 0;
|
||||||
|
|
||||||
rsEvents->registerEventsHandler( [this](std::shared_ptr<const RsEvent> event)
|
rsEvents->registerEventsHandler( [this](std::shared_ptr<const RsEvent> event)
|
||||||
{
|
{
|
||||||
RsQThreadUtils::postToObject([=](){ handleEvent_main_thread(event); }, this );
|
RsQThreadUtils::postToObject([=](){ handleEvent_main_thread(event); }, this );
|
||||||
}, mEventHandlerId, RsEventType::FRIEND_SERVER );
|
}, mEventHandlerId_fs, RsEventType::FRIEND_SERVER );
|
||||||
|
|
||||||
|
mEventHandlerId_peer = 0;
|
||||||
|
|
||||||
|
rsEvents->registerEventsHandler( [this](std::shared_ptr<const RsEvent> event)
|
||||||
|
{
|
||||||
|
RsQThreadUtils::postToObject([=](){ handleEvent_main_thread(event); }, this );
|
||||||
|
}, mEventHandlerId_peer, RsEventType::PEER_CONNECTION );
|
||||||
}
|
}
|
||||||
|
|
||||||
void FriendServerControl::onAutoAddFriends(bool b)
|
void FriendServerControl::onAutoAddFriends(bool b)
|
||||||
@ -112,21 +125,34 @@ void FriendServerControl::onAutoAddFriends(bool b)
|
|||||||
}
|
}
|
||||||
void FriendServerControl::handleEvent_main_thread(std::shared_ptr<const RsEvent> event)
|
void FriendServerControl::handleEvent_main_thread(std::shared_ptr<const RsEvent> event)
|
||||||
{
|
{
|
||||||
if(event->mType != RsEventType::FRIEND_SERVER) return;
|
|
||||||
|
|
||||||
const RsFriendServerEvent *fe = dynamic_cast<const RsFriendServerEvent*>(event.get());
|
|
||||||
if(!fe)
|
|
||||||
return;
|
|
||||||
|
|
||||||
switch(fe->mFriendServerEventType)
|
|
||||||
{
|
{
|
||||||
case RsFriendServerEventCode::PEER_INFO_CHANGED: updateContactsStatus();
|
const RsFriendServerEvent *fe = dynamic_cast<const RsFriendServerEvent*>(event.get());
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
if(fe)
|
||||||
case RsFriendServerEventCode::UNKNOWN: break;
|
switch(fe->mFriendServerEventType)
|
||||||
|
{
|
||||||
|
case RsFriendServerEventCode::PEER_INFO_CHANGED: updateContactsStatus();
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
case RsFriendServerEventCode::UNKNOWN: break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
const RsConnectionEvent *pe = dynamic_cast<const RsConnectionEvent*>(event.get());
|
||||||
|
|
||||||
|
if(pe)
|
||||||
|
switch(pe->mConnectionInfoCode)
|
||||||
|
{
|
||||||
|
case RsConnectionEventCode::PEER_ADDED:
|
||||||
|
case RsConnectionEventCode::PEER_REMOVED:
|
||||||
|
case RsConnectionEventCode::PEER_CONNECTED: updateContactsStatus();
|
||||||
|
break;
|
||||||
|
|
||||||
|
default: ;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
FriendServerControl::~FriendServerControl()
|
FriendServerControl::~FriendServerControl()
|
||||||
@ -134,9 +160,23 @@ FriendServerControl::~FriendServerControl()
|
|||||||
delete mCheckingServerMovie;
|
delete mCheckingServerMovie;
|
||||||
delete mConnectionCheckTimer;
|
delete mConnectionCheckTimer;
|
||||||
|
|
||||||
rsEvents->unregisterEventsHandler(mEventHandlerId);
|
rsEvents->unregisterEventsHandler(mEventHandlerId_fs);
|
||||||
|
rsEvents->unregisterEventsHandler(mEventHandlerId_peer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FriendServerControl::launchStatusContextMenu(QPoint p)
|
||||||
|
{
|
||||||
|
RsPeerId peer_id = getCurrentPeer();
|
||||||
|
|
||||||
|
RsPeerDetails det;
|
||||||
|
if(rsPeers->getPeerDetails(peer_id,det) && det.accept_connection)
|
||||||
|
return;
|
||||||
|
|
||||||
|
QMenu contextMnu(this);
|
||||||
|
contextMnu.addAction(makeFriend_ACT);
|
||||||
|
|
||||||
|
contextMnu.exec(QCursor::pos());
|
||||||
|
}
|
||||||
void FriendServerControl::onOnOffClick(bool b)
|
void FriendServerControl::onOnOffClick(bool b)
|
||||||
{
|
{
|
||||||
if(b)
|
if(b)
|
||||||
@ -294,4 +334,24 @@ void FriendServerControl::updateContactsStatus()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RsPeerId FriendServerControl::getCurrentPeer()
|
||||||
|
{
|
||||||
|
QTableWidgetItem *item = status_TW->currentItem();
|
||||||
|
|
||||||
|
if(!item)
|
||||||
|
return RsPeerId();
|
||||||
|
|
||||||
|
return RsPeerId(status_TW->item(item->row(),NODE_COLUMN)->text().toStdString());
|
||||||
|
}
|
||||||
|
void FriendServerControl::makeFriend()
|
||||||
|
{
|
||||||
|
RsPeerId peer_id = getCurrentPeer();
|
||||||
|
|
||||||
|
rsFriendServer->allowPeer(peer_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -42,8 +42,11 @@ protected slots:
|
|||||||
void onNbFriendsToRequestsChanged(int n);
|
void onNbFriendsToRequestsChanged(int n);
|
||||||
void checkServerAddress();
|
void checkServerAddress();
|
||||||
void onAutoAddFriends(bool b);
|
void onAutoAddFriends(bool b);
|
||||||
|
void launchStatusContextMenu(QPoint p);
|
||||||
|
void makeFriend();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
RsPeerId getCurrentPeer();
|
||||||
void updateContactsStatus();
|
void updateContactsStatus();
|
||||||
void updateFriendServerStatusIcon(bool ok);
|
void updateFriendServerStatusIcon(bool ok);
|
||||||
void handleEvent_main_thread(std::shared_ptr<const RsEvent> event);
|
void handleEvent_main_thread(std::shared_ptr<const RsEvent> event);
|
||||||
@ -52,5 +55,11 @@ private:
|
|||||||
QMovie *mCheckingServerMovie;
|
QMovie *mCheckingServerMovie;
|
||||||
bool mCurrentlyCheckingServerAddress;
|
bool mCurrentlyCheckingServerAddress;
|
||||||
|
|
||||||
RsEventsHandlerId_t mEventHandlerId;
|
RsEventsHandlerId_t mEventHandlerId_fs;
|
||||||
|
RsEventsHandlerId_t mEventHandlerId_peer;
|
||||||
|
|
||||||
|
QAction *makeFriend_ACT;
|
||||||
|
QAction *unmakeFriend_ACT;
|
||||||
|
QAction *removePeer_ACT;
|
||||||
|
QAction *removePeerPermanently_ACT;
|
||||||
};
|
};
|
||||||
|
@ -194,6 +194,9 @@
|
|||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QTableWidget" name="status_TW">
|
<widget class="QTableWidget" name="status_TW">
|
||||||
|
<property name="contextMenuPolicy">
|
||||||
|
<enum>Qt::CustomContextMenu</enum>
|
||||||
|
</property>
|
||||||
<column>
|
<column>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Name</string>
|
<string>Name</string>
|
||||||
|
Loading…
Reference in New Issue
Block a user