mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-02-25 01:10:19 -05:00
proper handling of peer connections notifications
This commit is contained in:
parent
98e41ad075
commit
15e43dce01
@ -477,11 +477,23 @@ void p3LinkMgrIMPL::tickMonitors()
|
||||
if (peer.actions & RS_PEER_CONNECTED)
|
||||
{
|
||||
p3Notify *notify = RsServer::notify();
|
||||
|
||||
if (notify)
|
||||
{
|
||||
// normally these two below should disappear: there's no notion of popup in libretroshare.
|
||||
// all GUI-type display features should be chosen in NotifyQt.
|
||||
notify->AddPopupMessage(RS_POPUP_CONNECT, peer.id.toStdString(),"", "Online: ");
|
||||
notify->AddFeedItem(RS_FEED_ITEM_PEER_CONNECT, peer.id.toStdString());
|
||||
|
||||
notify->notifyPeerConnected(peer.id.toStdString());
|
||||
}
|
||||
}
|
||||
if (peer.actions & RS_PEER_DISCONNECTED)
|
||||
{
|
||||
p3Notify *notify = RsServer::notify();
|
||||
|
||||
if (notify)
|
||||
notify->notifyPeerDisconnected(peer.id.toStdString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -217,6 +217,8 @@ void p3Notify::notifyChatLobbyEvent(uint64_t lobby_id, uint32_t event_type,const
|
||||
void p3Notify::notifyListPreChange(int list, int type) { FOR_ALL_NOTIFY_CLIENTS (*it)->notifyListPreChange(list,type) ; }
|
||||
void p3Notify::notifyListChange (int list, int type) { FOR_ALL_NOTIFY_CLIENTS (*it)->notifyListChange (list,type) ; }
|
||||
|
||||
void p3Notify::notifyPeerConnected (const std::string& peer_id) { FOR_ALL_NOTIFY_CLIENTS (*it)->notifyPeerConnected(peer_id); }
|
||||
void p3Notify::notifyPeerDisconnected (const std::string& peer_id) { FOR_ALL_NOTIFY_CLIENTS (*it)->notifyPeerDisconnected(peer_id); }
|
||||
void p3Notify::notifyErrorMsg (int list, int sev, std::string msg) { FOR_ALL_NOTIFY_CLIENTS (*it)->notifyErrorMsg(list,sev,msg) ; }
|
||||
void p3Notify::notifyChatMessage (const ChatMessage &msg) { FOR_ALL_NOTIFY_CLIENTS (*it)->notifyChatMessage(msg) ; }
|
||||
void p3Notify::notifyChatStatus (const ChatId& chat_id, const std::string& status_string) { FOR_ALL_NOTIFY_CLIENTS (*it)->notifyChatStatus(chat_id,status_string) ; }
|
||||
|
@ -91,6 +91,8 @@ class p3Notify: public RsNotify
|
||||
|
||||
// Notifications of clients. Can be called from anywhere inside libretroshare.
|
||||
//
|
||||
void notifyPeerConnected (const std::string& /* peer_id */);
|
||||
void notifyPeerDisconnected (const std::string& /* peer_id */);
|
||||
void notifyListPreChange (int /* list */, int /* type */) ;
|
||||
void notifyListChange (int /* list */, int /* type */) ;
|
||||
void notifyErrorMsg (int /* list */, int /* sev */, std::string /* msg */) ;
|
||||
|
@ -212,6 +212,8 @@ public:
|
||||
NotifyClient() {}
|
||||
virtual ~NotifyClient() {}
|
||||
|
||||
virtual void notifyPeerConnected (const std::string& /* peer_id */) {}
|
||||
virtual void notifyPeerDisconnected (const std::string& /* peer_id */) {}
|
||||
virtual void notifyListPreChange (int /* list */, int /* type */) {}
|
||||
virtual void notifyListChange (int /* list */, int /* type */) {}
|
||||
virtual void notifyErrorMsg (int /* list */, int /* sev */, std::string /* msg */) {}
|
||||
|
@ -47,6 +47,7 @@ std::ostream& operator<<(std::ostream& o, const QModelIndex& i);// defined elsew
|
||||
|
||||
const QString RsFriendListModel::FilterString("filtered");
|
||||
const uint32_t MAX_INTERNAL_DATA_UPDATE_DELAY = 300 ; // re-update the internal data every 5 mins. Should properly cover sleep/wake-up changes.
|
||||
const uint32_t MAX_NODE_UPDATE_DELAY = 1 ; // re-update the internal data every 5 mins. Should properly cover sleep/wake-up changes.
|
||||
|
||||
static const uint32_t NODE_DETAILS_UPDATE_DELAY = 5; // update each node every 5 secs.
|
||||
|
||||
@ -55,6 +56,8 @@ RsFriendListModel::RsFriendListModel(QObject *parent)
|
||||
{
|
||||
mDisplayGroups = true;
|
||||
mFilterStrings.clear();
|
||||
mLastNodeUpdate=0;
|
||||
mLastInternalDataUpdate=0;
|
||||
}
|
||||
|
||||
void RsFriendListModel::setDisplayStatusString(bool b)
|
||||
@ -578,7 +581,7 @@ QVariant RsFriendListModel::fontRole(const EntryIndex& e, int col) const
|
||||
|
||||
bool b = onlineRole(e,col).toBool();
|
||||
|
||||
if(b && e.type == ENTRY_TYPE_NODE || e.type == ENTRY_TYPE_PROFILE)
|
||||
if(b)
|
||||
{
|
||||
QFont font ;
|
||||
font.setBold(b);
|
||||
@ -698,16 +701,32 @@ QVariant RsFriendListModel::displayRole(const EntryIndex& e, int col) const
|
||||
// This function makes sure that the internal data gets updated. They are situations where the otification system cannot
|
||||
// send the information about changes, such as when the computer is put on sleep.
|
||||
|
||||
void RsFriendListModel::checkInternalData()
|
||||
void RsFriendListModel::checkInternalData(bool force)
|
||||
{
|
||||
if(mLastInternalDataUpdate + MAX_INTERNAL_DATA_UPDATE_DELAY < time(NULL))
|
||||
rstime_t now = time(NULL);
|
||||
|
||||
if(mLastInternalDataUpdate + MAX_INTERNAL_DATA_UPDATE_DELAY < now || force)
|
||||
updateInternalData();
|
||||
|
||||
if(mLastNodeUpdate + MAX_NODE_UPDATE_DELAY < now)
|
||||
{
|
||||
for(uint32_t i=0;i<mLocations.size();++i)
|
||||
if(mLocations[i].last_update_ts + NODE_DETAILS_UPDATE_DELAY < now)
|
||||
{
|
||||
#ifdef DEBUG_MODEL
|
||||
std::cerr << "Updating ID " << node.node_info.id << std::endl;
|
||||
#endif
|
||||
RsPeerId id(mLocations[i].node_info.id); // this avoids zeroing the id field when writing the node data
|
||||
rsPeers->getPeerDetails(id,mLocations[i].node_info);
|
||||
mLocations[i].last_update_ts = now;
|
||||
}
|
||||
|
||||
mLastNodeUpdate = now;
|
||||
}
|
||||
}
|
||||
|
||||
const RsFriendListModel::HierarchicalGroupInformation *RsFriendListModel::getGroupInfo(const EntryIndex& e) const
|
||||
{
|
||||
const_cast<RsFriendListModel*>(this)->checkInternalData();
|
||||
|
||||
if(e.group_index >= mGroups.size())
|
||||
return NULL ;
|
||||
else
|
||||
@ -716,8 +735,6 @@ const RsFriendListModel::HierarchicalGroupInformation *RsFriendListModel::getGro
|
||||
|
||||
const RsFriendListModel::HierarchicalProfileInformation *RsFriendListModel::getProfileInfo(const EntryIndex& e) const
|
||||
{
|
||||
const_cast<RsFriendListModel*>(this)->checkInternalData();
|
||||
|
||||
// First look into the relevant group, then for the correct profile in this group.
|
||||
|
||||
if(e.type != ENTRY_TYPE_PROFILE)
|
||||
@ -738,8 +755,6 @@ const RsFriendListModel::HierarchicalProfileInformation *RsFriendListModel::getP
|
||||
|
||||
const RsFriendListModel::HierarchicalNodeInformation *RsFriendListModel::getNodeInfo(const EntryIndex& e) const
|
||||
{
|
||||
const_cast<RsFriendListModel*>(this)->checkInternalData();
|
||||
|
||||
if(e.type != ENTRY_TYPE_NODE)
|
||||
return NULL ;
|
||||
|
||||
@ -768,16 +783,6 @@ const RsFriendListModel::HierarchicalNodeInformation *RsFriendListModel::getNode
|
||||
time_t now = time(NULL);
|
||||
HierarchicalNodeInformation& node(mLocations[mProfiles[pindex].child_node_indices[e.node_index]]);
|
||||
|
||||
if(node.last_update_ts + NODE_DETAILS_UPDATE_DELAY < now)
|
||||
{
|
||||
#ifdef DEBUG_MODEL
|
||||
std::cerr << "Updating ID " << node.node_info.id << std::endl;
|
||||
#endif
|
||||
RsPeerId id(node.node_info.id); // this avoids zeroing the id field when writing the node data
|
||||
rsPeers->getPeerDetails(id,node.node_info);
|
||||
node.last_update_ts = now;
|
||||
}
|
||||
|
||||
return &node;
|
||||
}
|
||||
|
||||
|
@ -152,6 +152,7 @@ private:
|
||||
const HierarchicalProfileInformation *getProfileInfo(const EntryIndex&)const;
|
||||
const HierarchicalNodeInformation *getNodeInfo(const EntryIndex&) const;
|
||||
|
||||
void checkNode(HierarchicalNodeInformation& node);
|
||||
bool getPeerOnlineStatus(const EntryIndex& e) const;
|
||||
std::map<RsPgpId,uint32_t>::const_iterator checkProfileIndex(const RsPgpId& pgp_id,
|
||||
std::map<RsPgpId,uint32_t>& pgp_indices,
|
||||
@ -175,7 +176,7 @@ private:
|
||||
*/
|
||||
|
||||
public slots:
|
||||
void updateInternalData();
|
||||
void checkInternalData(bool force);
|
||||
void debug_dump() const;
|
||||
|
||||
signals:
|
||||
@ -184,8 +185,8 @@ signals:
|
||||
void dataAboutToLoad();
|
||||
|
||||
private:
|
||||
void updateInternalData();
|
||||
bool passesFilter(const EntryIndex &e, int column) const;
|
||||
void checkInternalData();
|
||||
|
||||
void preMods() ;
|
||||
void postMods() ;
|
||||
@ -205,6 +206,7 @@ private:
|
||||
bool mDisplayGroups ;
|
||||
bool mDisplayStatusString ;
|
||||
rstime_t mLastInternalDataUpdate;
|
||||
rstime_t mLastNodeUpdate;;
|
||||
|
||||
// The 3 vectors below store thehierarchical information for groups, profiles and locations,
|
||||
// meaning which is the child/parent of which. The actual group/profile/node data are also stored in the
|
||||
|
@ -32,7 +32,6 @@
|
||||
|
||||
#include "GroupDefs.h"
|
||||
#include "gui/chat/ChatDialog.h"
|
||||
//#include "gui/chat/CreateLobbyDialog.h"
|
||||
#include "gui/common/AvatarDefs.h"
|
||||
|
||||
#include "gui/connect/ConfCertDialog.h"
|
||||
@ -154,7 +153,7 @@ private:
|
||||
bool m_showOfflineNodes;
|
||||
};
|
||||
|
||||
NewFriendList::NewFriendList(QWidget *parent) : QWidget(parent), ui(new Ui::NewFriendList())
|
||||
NewFriendList::NewFriendList(QWidget *parent) : RsAutoUpdatePage(1000,parent), ui(new Ui::NewFriendList())
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
@ -208,7 +207,7 @@ NewFriendList::NewFriendList(QWidget *parent) : QWidget(parent), ui(new Ui::NewF
|
||||
/* Initialize display menu */
|
||||
createDisplayMenu();
|
||||
|
||||
mModel->updateInternalData();
|
||||
mModel->checkInternalData(true);
|
||||
|
||||
QHeaderView *h = ui->peerTreeWidget->header();
|
||||
h->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
@ -217,8 +216,10 @@ NewFriendList::NewFriendList(QWidget *parent) : QWidget(parent), ui(new Ui::NewF
|
||||
connect(mActionSortByState, SIGNAL(toggled(bool)), this, SLOT(toggleSortByState(bool)));
|
||||
connect(ui->peerTreeWidget, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(peerTreeWidgetCustomPopupMenu()));
|
||||
|
||||
connect(NotifyQt::getInstance(), SIGNAL(friendsChanged()), mModel, SLOT(updateInternalData()));
|
||||
connect(NotifyQt::getInstance(), SIGNAL(groupsChanged(int)), mModel, SLOT(updateInternalData()));
|
||||
connect(NotifyQt::getInstance(), SIGNAL(friendsChanged()), this, SLOT(forceUpdateDisplay()));
|
||||
connect(NotifyQt::getInstance(), SIGNAL(groupsChanged(int)), this, SLOT(forceUpdateDisplay()));
|
||||
connect(NotifyQt::getInstance(), SIGNAL(peerConnected(const QString&)), this, SLOT(forceUpdateDisplay()));
|
||||
connect(NotifyQt::getInstance(), SIGNAL(peerDisconnected(const QString&)), this, SLOT(forceUpdateDisplay()));
|
||||
|
||||
connect(ui->actionShowOfflineFriends, SIGNAL(triggered(bool)), this, SLOT(setShowUnconnected(bool)));
|
||||
connect(ui->actionShowState, SIGNAL(triggered(bool)), this, SLOT(setShowState(bool)));
|
||||
@ -967,7 +968,16 @@ void NewFriendList::addToGroup()
|
||||
|
||||
// add to group
|
||||
rsPeers->assignPeerToGroup(groupId, gpgId, true);
|
||||
mModel->updateInternalData();
|
||||
mModel->checkInternalData(true);
|
||||
}
|
||||
void NewFriendList::forceUpdateDisplay()
|
||||
{
|
||||
mModel->checkInternalData(true);
|
||||
}
|
||||
|
||||
void NewFriendList::updateDisplay()
|
||||
{
|
||||
mModel->checkInternalData(false);
|
||||
}
|
||||
|
||||
void NewFriendList::moveToGroup()
|
||||
@ -991,7 +1001,7 @@ void NewFriendList::moveToGroup()
|
||||
|
||||
// add to group
|
||||
rsPeers->assignPeerToGroup(groupId, gpgId, true);
|
||||
mModel->updateInternalData();
|
||||
mModel->checkInternalData(true);
|
||||
}
|
||||
|
||||
void NewFriendList::removeFromGroup()
|
||||
@ -1009,7 +1019,7 @@ void NewFriendList::removeFromGroup()
|
||||
|
||||
// remove from (all) group(s)
|
||||
rsPeers->assignPeerToGroup(groupId, gpgId, false);
|
||||
mModel->updateInternalData();
|
||||
mModel->checkInternalData(true);
|
||||
}
|
||||
|
||||
void NewFriendList::editGroup()
|
||||
@ -1026,7 +1036,7 @@ void NewFriendList::editGroup()
|
||||
CreateGroup editGrpDialog(groupId, this);
|
||||
editGrpDialog.exec();
|
||||
}
|
||||
mModel->updateInternalData();
|
||||
mModel->checkInternalData(true);
|
||||
}
|
||||
|
||||
void NewFriendList::removeGroup()
|
||||
@ -1037,7 +1047,7 @@ void NewFriendList::removeGroup()
|
||||
return;
|
||||
|
||||
rsPeers->removeGroup(pinfo.id);
|
||||
mModel->updateInternalData();
|
||||
mModel->checkInternalData(true);
|
||||
}
|
||||
|
||||
void NewFriendList::exportFriendlistClicked()
|
||||
|
@ -26,6 +26,7 @@
|
||||
#include <QTreeView>
|
||||
|
||||
#include "FriendListModel.h"
|
||||
#include "RsAutoUpdatePage.h"
|
||||
#include "retroshare/rsstatus.h"
|
||||
|
||||
namespace Ui {
|
||||
@ -37,7 +38,7 @@ class QTreeWidgetItem;
|
||||
class QToolButton;
|
||||
class FriendListSortFilterProxyModel;
|
||||
|
||||
class NewFriendList: public QWidget
|
||||
class NewFriendList: public RsAutoUpdatePage
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
@ -65,6 +66,8 @@ public:
|
||||
std::string getSelectedGroupId() const;
|
||||
void sortByColumn(int column, Qt::SortOrder sortOrder);
|
||||
|
||||
void updateDisplay() override;
|
||||
|
||||
QColor textColorGroup() const { return mModel->mTextColorGroup; }
|
||||
QColor textColorStatusOffline() const { return mModel->mTextColorStatus[RS_STATUS_OFFLINE ]; }
|
||||
QColor textColorStatusAway() const { return mModel->mTextColorStatus[RS_STATUS_AWAY ]; }
|
||||
@ -82,6 +85,7 @@ public:
|
||||
public slots:
|
||||
void filterItems(const QString &text);
|
||||
void toggleSortByState(bool sort);
|
||||
void forceUpdateDisplay();
|
||||
|
||||
void toggleColumnVisible();
|
||||
void setShowGroups(bool show);
|
||||
|
@ -750,6 +750,26 @@ void NotifyQt::notifyListChange(int list, int type)
|
||||
return;
|
||||
}
|
||||
|
||||
void NotifyQt::notifyPeerConnected(const std::string& peer_id)
|
||||
{
|
||||
{
|
||||
QMutexLocker m(&_mutex) ;
|
||||
if(!_enabled)
|
||||
return ;
|
||||
}
|
||||
|
||||
emit peerConnected(QString::fromStdString(peer_id));
|
||||
}
|
||||
void NotifyQt::notifyPeerDisconnected(const std::string& peer_id)
|
||||
{
|
||||
{
|
||||
QMutexLocker m(&_mutex) ;
|
||||
if(!_enabled)
|
||||
return ;
|
||||
}
|
||||
|
||||
emit peerDisconnected(QString::fromStdString(peer_id));
|
||||
}
|
||||
|
||||
void NotifyQt::notifyListPreChange(int list, int /*type*/)
|
||||
{
|
||||
|
@ -60,6 +60,8 @@ class NotifyQt: public QObject, public NotifyClient
|
||||
|
||||
void setNetworkDialog(NetworkDialog *c) { cDialog = c; }
|
||||
|
||||
virtual void notifyPeerConnected(const std::string& /* peer_id */);
|
||||
virtual void notifyPeerDisconnected(const std::string& /* peer_id */);
|
||||
virtual void notifyListPreChange(int list, int type);
|
||||
virtual void notifyListChange(int list, int type);
|
||||
virtual void notifyErrorMsg(int list, int sev, std::string msg);
|
||||
@ -121,6 +123,8 @@ class NotifyQt: public QObject, public NotifyClient
|
||||
// It's beneficial to send info to the GUI using signals, because signals are thread-safe
|
||||
// as they get queued by Qt.
|
||||
//
|
||||
void peerConnected(const QString&) const ;
|
||||
void peerDisconnected(const QString&) const ;
|
||||
void hashingInfoChanged(const QString&) const ;
|
||||
void filesPreModChanged(bool) const ;
|
||||
void filesPostModChanged(bool) const ;
|
||||
|
Loading…
x
Reference in New Issue
Block a user