Count the friends (gpg id's) instead of the locations (ssl id's) in the statusbar.

Moved update of the friends from QTimer to signals.
Combined p3LinkMgr::getFriendCount and p3LinkMgr::getOnlineCount and moved to p3PeerMgr.

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@4986 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
thunder2 2012-02-25 01:48:56 +00:00
parent 4867c76bb1
commit 45ac04e2e7
11 changed files with 111 additions and 89 deletions

View File

@ -252,14 +252,12 @@ void p3LinkMgrIMPL::getFriendList(std::list<std::string> &ssl_peers)
{
RsStackMutex stack(mLinkMtx); /****** STACK LOCK MUTEX *******/
std::map<std::string, peerConnectState>::iterator it;
std::map<std::string, peerConnectState>::iterator it;
for(it = mFriendList.begin(); it != mFriendList.end(); it++)
{
ssl_peers.push_back(it->first);
}
return;
}
bool p3LinkMgrIMPL::getPeerName(const std::string &ssl_id, std::string &name)
@ -268,34 +266,6 @@ bool p3LinkMgrIMPL::getPeerName(const std::string &ssl_id, std::string &name)
}
int p3LinkMgrIMPL::getFriendCount()
{
RsStackMutex stack(mLinkMtx); /****** STACK LOCK MUTEX *******/
return mFriendList.size();
}
int p3LinkMgrIMPL::getOnlineCount()
{
RsStackMutex stack(mLinkMtx); /****** STACK LOCK MUTEX *******/
int count = 0;
std::map<std::string, peerConnectState>::iterator it;
for(it = mFriendList.begin(); it != mFriendList.end(); it++)
{
if (it->second.state & RS_PEER_S_CONNECTED)
{
count++;
}
}
return count;
}
bool p3LinkMgrIMPL::getFriendNetStatus(const std::string &id, peerConnectState &state)
{
RsStackMutex stack(mLinkMtx); /****** STACK LOCK MUTEX *******/

View File

@ -166,8 +166,6 @@ virtual struct sockaddr_in getLocalAddress() = 0;
/************* DEPRECIATED FUNCTIONS (TO REMOVE) ********/
virtual void getFriendList(std::list<std::string> &ssl_peers) = 0; // ONLY used by p3peers.cc USE p3PeerMgr instead.
virtual int getOnlineCount() = 0; // ONLY used by p3peers.cc
virtual int getFriendCount() = 0; // ONLY used by p3serverconfig.cc & p3peers.cc
virtual bool getFriendNetStatus(const std::string &id, peerConnectState &state) = 0; // ONLY used by p3peers.cc
virtual void setTunnelConnection(bool b) = 0; // ONLY used by p3peermgr.cc & p3peers.cc MOVE => p3PeerMgr
@ -232,8 +230,6 @@ virtual void peerConnectRequest(std::string id, struct sockaddr_in raddr,
/************* DEPRECIATED FUNCTIONS (TO REMOVE) ********/
virtual void getFriendList(std::list<std::string> &ssl_peers); // ONLY used by p3peers.cc USE p3PeerMgr instead.
virtual int getOnlineCount(); // ONLY used by p3peers.cc
virtual int getFriendCount(); // ONLY used by p3serverconfig.cc & p3peers.cc
virtual bool getFriendNetStatus(const std::string &id, peerConnectState &state); // ONLY used by p3peers.cc
virtual void setTunnelConnection(bool b); // ONLY used by p3peermgr.cc & p3peers.cc MOVE => p3PeerMgr

View File

@ -275,6 +275,51 @@ uint32_t p3PeerMgrIMPL::getConnectionType(const std::string &/*sslId*/)
return RS_NET_CONN_TYPE_FRIEND;
}
int p3PeerMgrIMPL::getFriendCount(bool ssl, bool online)
{
if (online) {
// count only online id's
std::list<std::string> onlineIds;
mLinkMgr->getOnlineList(onlineIds);
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
std::set<std::string> gpgIds;
int count = 0;
std::map<std::string, peerState>::iterator it;
for(it = mFriendList.begin(); it != mFriendList.end(); ++it) {
if (online && std::find(onlineIds.begin(), onlineIds.end(), it->first) == onlineIds.end()) {
continue;
}
if (ssl) {
// count ssl id's only
count++;
} else {
// count unique gpg id's
gpgIds.insert(it->second.gpg_id);
}
}
return ssl ? count : gpgIds.size();
}
if (ssl) {
// count all ssl id's
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
return mFriendList.size();
}
// count all gpg id's
std::list<std::string> gpgIds;
AuthGPG::getAuthGPG()->getGPGAcceptedList(gpgIds);
// add own gpg id, if we have more than one location
std::list<std::string> ownSslIds;
getAssociatedPeers(AuthGPG::getAuthGPG()->getGPGOwnId(), ownSslIds);
return gpgIds.size() + ((ownSslIds.size() > 0) ? 1 : 0);
}
bool p3PeerMgrIMPL::getFriendNetStatus(const std::string &id, peerState &state)
{

View File

@ -184,6 +184,7 @@ virtual bool getPeerName(const std::string &ssl_id, std::string &name) = 0;
virtual bool getGpgId(const std::string &sslId, std::string &gpgId) = 0;
virtual uint32_t getConnectionType(const std::string &sslId) = 0;
virtual int getFriendCount(bool ssl, bool online) = 0;
/************* DEPRECIATED FUNCTIONS (TO REMOVE) ********/
@ -270,6 +271,7 @@ virtual bool getPeerName(const std::string &ssl_id, std::string &name);
virtual bool getGpgId(const std::string &sslId, std::string &gpgId);
virtual uint32_t getConnectionType(const std::string &sslId);
virtual int getFriendCount(bool ssl, bool online);
/************* DEPRECIATED FUNCTIONS (TO REMOVE) ********/

View File

@ -207,20 +207,16 @@ bool p3Peers::getFriendList(std::list<std::string> &ids)
// return true;
//}
bool p3Peers::getPeerCount (unsigned int *pnFriendCount, unsigned int *pnOnlineCount, bool /*ssl*/)
bool p3Peers::getPeerCount (unsigned int *friendCount, unsigned int *onlineCount, bool ssl)
{
#ifdef P3PEERS_DEBUG
std::cerr << "p3Peers::getPeerCount()" << std::endl;
std::cerr << "p3Peers::getPeerCount()" << std::endl;
#endif
// This is no longer accurate!
*pnFriendCount = mLinkMgr->getFriendCount();
*pnOnlineCount = mLinkMgr->getOnlineCount();
/* get from mConnectMgr */
//return mConnMgr->getPeerCount(pnFriendCount, pnOnlineCount, ssl);
if (friendCount) *friendCount = mPeerMgr->getFriendCount(ssl, false);
if (onlineCount) *onlineCount = mPeerMgr->getFriendCount(ssl, true);
return true;
}
bool p3Peers::isOnline(const std::string &id)

View File

@ -51,7 +51,7 @@ virtual std::string getOwnId();
virtual bool getOnlineList(std::list<std::string> &ids);
virtual bool getFriendList(std::list<std::string> &ids);
//virtual bool getOthersList(std::list<std::string> &ids);
virtual bool getPeerCount (unsigned int *pnFriendCount, unsigned int *pnOnlineCount, bool ssl);
virtual bool getPeerCount (unsigned int *friendCount, unsigned int *onlineCount, bool ssl);
virtual bool isOnline(const std::string &id);
virtual bool isFriend(const std::string &id);

View File

@ -185,9 +185,9 @@ uint32_t p3ServerConfig::getUserLevel()
case RSCONFIG_USER_LEVEL_NEW:
{
if (mLinkMgr->getFriendCount() > MIN_BASIC_FRIENDS)
if (mPeerMgr->getFriendCount(true, false) > MIN_BASIC_FRIENDS)
{
userLevel = RSCONFIG_USER_LEVEL_BASIC;
userLevel = RSCONFIG_USER_LEVEL_BASIC;
}
}
case RSCONFIG_USER_LEVEL_BASIC:
@ -195,12 +195,12 @@ uint32_t p3ServerConfig::getUserLevel()
/* check that we have some lastConnect > 0 */
if (mPeerMgr->haveOnceConnected())
{
userLevel = RSCONFIG_USER_LEVEL_CASUAL;
userLevel = RSCONFIG_USER_LEVEL_CASUAL;
}
}
case RSCONFIG_USER_LEVEL_CASUAL:
case RSCONFIG_USER_LEVEL_POWER:
case RSCONFIG_USER_LEVEL_POWER:
{
/* check that the firewall is open */
@ -214,7 +214,7 @@ uint32_t p3ServerConfig::getUserLevel()
(RSNET_NATHOLE_NATPMP == firewallMode) ||
(RSNET_NATHOLE_FORWARDED == firewallMode))))
{
userLevel = RSCONFIG_USER_LEVEL_POWER;
userLevel = RSCONFIG_USER_LEVEL_POWER;
}
}
break; /* for all */

View File

@ -384,6 +384,16 @@ void p3StatusService::statusChange(const std::list<pqipeer> &plist)
changedState = true;
rsicontrol->getNotify().notifyPeerStatusChanged(it->id, RS_STATUS_ONLINE);
}
} else if (it->actions & RS_PEER_MOVED) {
/* now handle remove */
{
RsStackMutex stack(mStatusMtx);
/* remove peer from status map */
mStatusInfoMap.erase(it->id);
} /* UNLOCKED */
changedState = true;
rsicontrol->getNotify().notifyPeerStatusChanged(it->id, RS_STATUS_OFFLINE);
}
}

View File

@ -57,6 +57,7 @@
#include "chat/ChatDialog.h"
#include "RetroShareLink.h"
#include "SoundManager.h"
#include "notifyqt.h"
#ifdef UNFINISHED
#include "unfinished/ApplicationWindow.h"
@ -176,6 +177,7 @@ MainWindow::MainWindow(QWidget* parent, Qt::WFlags flags)
m_bStatusLoadDone = false;
isIdle = false;
onlineCount = 0;
notifyMenu = NULL;
trayIconMessages = NULL;
@ -197,7 +199,6 @@ MainWindow::MainWindow(QWidget* parent, Qt::WFlags flags)
setWindowTitle(tr("RetroShare %1 a secure decentralised communication platform").arg(retroshareVersion()) + " - " + nameAndLocation);
/* WORK OUT IF WE"RE IN ADVANCED MODE OR NOT */
bool advancedMode = false;
std::string advsetting;
@ -360,6 +361,11 @@ MainWindow::MainWindow(QWidget* parent, Qt::WFlags flags)
/* Creates a tray icon with a context menu and adds it to the system's * notification area. */
createTrayIcon();
/* caclulate friend count */
updateFriends();
connect(NotifyQt::getInstance(), SIGNAL(peerStatusChanged(QString,int)), this, SLOT(updateFriends()));
connect(NotifyQt::getInstance(), SIGNAL(friendsChanged()), this, SLOT(updateFriends()));
loadOwnStatus();
/* Set focus to the current page */
@ -803,10 +809,6 @@ void MainWindow::updateStatus()
if(RsAutoUpdatePage::eventsLocked())
return;
unsigned int nFriendCount = 0;
unsigned int nOnlineCount = 0;
rsPeers->getPeerCount (&nFriendCount, &nOnlineCount, false);
float downKb = 0;
float upKb = 0;
rsicontrol -> ConfigGetDataRates(downKb, upKb);
@ -814,9 +816,6 @@ void MainWindow::updateStatus()
if (ratesstatus)
ratesstatus->getRatesStatus(downKb, upKb);
if (peerstatus)
peerstatus->getPeerStatus(nFriendCount, nOnlineCount);
if (natstatus)
natstatus->getNATStatus();
@ -827,22 +826,40 @@ void MainWindow::updateStatus()
discstatus->update();
}
QString tray = "RetroShare\n" + tr("Down: %1 (kB/s)").arg(downKb, 0, 'f', 2) + " | " + tr("Up: %1 (kB/s)").arg(upKb, 0, 'f', 2) + "\n";
if (onlineCount == 1) {
tray += tr("%1 friend connected").arg(onlineCount);
} else {
tray += tr("%1 friends connected").arg(onlineCount);
}
tray += "\n" + nameAndLocation;
if (!notifyToolTip.isEmpty()) {
tray += "\n";
tray += notifyToolTip;
}
trayIcon->setToolTip(tray);
}
void MainWindow::updateFriends()
{
unsigned int friendCount = 0;
rsPeers->getPeerCount (&friendCount, &onlineCount, false);
if (peerstatus)
peerstatus->getPeerStatus(friendCount, onlineCount);
QString trayIconResource;
if (nOnlineCount == 0)
{
if (onlineCount == 0) {
trayIconResource = IMAGE_NOONLINE;
}
else if (nOnlineCount < 2)
{
} else if (onlineCount < 2) {
trayIconResource = IMAGE_ONEONLINE;
}
else if (nOnlineCount < 3)
{
} else if (onlineCount < 3) {
trayIconResource = IMAGE_TWOONLINE;
}
else
{
} else {
trayIconResource = IMAGE_RETROSHARE;
}
@ -860,22 +877,6 @@ void MainWindow::updateStatus()
}
trayIcon->setIcon(icon);
QString tray = "RetroShare\n" + tr("Down: %1 (kB/s)").arg(downKb, 0, 'f', 2) + " | " + tr("Up: %1 (kB/s)").arg(upKb, 0, 'f', 2) + "\n";
if (nOnlineCount == 1) {
tray += tr("%1 friend connected").arg(nOnlineCount);
} else {
tray += tr("%1 friends connected").arg(nOnlineCount);
}
tray += "\n" + nameAndLocation;
if (!notifyToolTip.isEmpty()) {
tray += "\n";
tray += notifyToolTip;
}
trayIcon->setToolTip(tray);
}
void MainWindow::privateChatChanged(int list, int type)

View File

@ -165,6 +165,7 @@ private slots:
void updateMenu();
void updateStatus();
void updateFriends();
void toggleVisibility(QSystemTrayIcon::ActivationReason e);
void toggleVisibilitycontextmenu();
@ -256,6 +257,7 @@ private:
/* Status */
std::set <QObject*> m_apStatusObjects; // added objects for status
bool m_bStatusLoadDone;
unsigned int onlineCount;
void loadOwnStatus();

View File

@ -183,11 +183,11 @@ void NotifyQt::notifyDiskFull(uint32_t loc,uint32_t size_in_mb)
/* peer has changed the state */
void NotifyQt::notifyPeerStatusChanged(const std::string& peer_id, uint32_t state)
{
#ifdef NOTIFY_DEBUG
#ifdef NOTIFY_DEBUG
std::cerr << "Notifyqt:: notified that peer " << peer_id << " has changed the state to " << state << std::endl;
#endif
#endif
emit peerStatusChanged(QString::fromStdString(peer_id), state);
emit peerStatusChanged(QString::fromStdString(peer_id), state);
}
/* one or more peers has changed the states */