mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-06-14 01:23:13 -04:00
New methods for calculating the count of peers and messages. It should be faster than getting all data in std::list.
Now used in MainWindow.cpp, MessagesDialog.cpp and peerstatus.cpp void p3Peers::getPeerCount (unsigned int *pnFriendCount, unsigned int *pnOnlineCount); void p3Msgs::getMessageCount(unsigned int *pnInbox, unsigned int *pnInboxNew, unsigned int *pnOutbox, unsigned int *pnDraftbox, unsigned int *pnSentbox); git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@2898 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
e5667a915d
commit
84a87fa11b
15 changed files with 99 additions and 61 deletions
|
@ -1523,6 +1523,23 @@ void p3ConnectMgr::getFriendList(std::list<std::string> &peers)
|
||||||
//}
|
//}
|
||||||
|
|
||||||
|
|
||||||
|
void p3ConnectMgr::getPeerCount (unsigned int *pnFriendCount, unsigned int *pnOnlineCount)
|
||||||
|
{
|
||||||
|
RsStackMutex stack(connMtx); /****** STACK LOCK MUTEX *******/
|
||||||
|
|
||||||
|
if (pnFriendCount) *pnFriendCount = mFriendList.size();
|
||||||
|
if (pnOnlineCount) {
|
||||||
|
*pnOnlineCount = 0;
|
||||||
|
|
||||||
|
std::map<std::string, peerConnectState>::iterator it;
|
||||||
|
for(it = mFriendList.begin(); it != mFriendList.end(); it++) {
|
||||||
|
if (it->second.state & RS_PEER_S_CONNECTED) {
|
||||||
|
(*pnOnlineCount)++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool p3ConnectMgr::connectAttempt(std::string id, struct sockaddr_in &addr,
|
bool p3ConnectMgr::connectAttempt(std::string id, struct sockaddr_in &addr,
|
||||||
uint32_t &delay, uint32_t &period, uint32_t &type)
|
uint32_t &delay, uint32_t &period, uint32_t &type)
|
||||||
|
|
|
@ -258,6 +258,7 @@ bool getOthersNetStatus(std::string id, peerConnectState &state);
|
||||||
void getOnlineList(std::list<std::string> &ssl_peers);
|
void getOnlineList(std::list<std::string> &ssl_peers);
|
||||||
void getFriendList(std::list<std::string> &ssl_peers);
|
void getFriendList(std::list<std::string> &ssl_peers);
|
||||||
//void getOthersList(std::list<std::string> &peers); /deprecated
|
//void getOthersList(std::list<std::string> &peers); /deprecated
|
||||||
|
void getPeerCount (unsigned int *pnFriendCount, unsigned int *pnOnlineCount);
|
||||||
|
|
||||||
|
|
||||||
/**************** handle monitors *****************/
|
/**************** handle monitors *****************/
|
||||||
|
|
|
@ -121,6 +121,7 @@ virtual ~RsMsgs() { return; }
|
||||||
|
|
||||||
virtual bool getMessageSummaries(std::list<MsgInfoSummary> &msgList) = 0;
|
virtual bool getMessageSummaries(std::list<MsgInfoSummary> &msgList) = 0;
|
||||||
virtual bool getMessage(std::string mId, MessageInfo &msg) = 0;
|
virtual bool getMessage(std::string mId, MessageInfo &msg) = 0;
|
||||||
|
virtual void getMessageCount(unsigned int *pnInbox, unsigned int *pnInboxNew, unsigned int *pnOutbox, unsigned int *pnDraftbox, unsigned int *pnSentbox) = 0;
|
||||||
|
|
||||||
virtual bool MessageSend(MessageInfo &info) = 0;
|
virtual bool MessageSend(MessageInfo &info) = 0;
|
||||||
virtual bool MessageDelete(std::string mid) = 0;
|
virtual bool MessageDelete(std::string mid) = 0;
|
||||||
|
|
|
@ -138,6 +138,7 @@ virtual std::string getOwnId() = 0;
|
||||||
virtual bool getOnlineList(std::list<std::string> &ssl_ids) = 0;
|
virtual bool getOnlineList(std::list<std::string> &ssl_ids) = 0;
|
||||||
virtual bool getFriendList(std::list<std::string> &ssl_ids) = 0;
|
virtual bool getFriendList(std::list<std::string> &ssl_ids) = 0;
|
||||||
//virtual bool getOthersList(std::list<std::string> &ssl_ids) = 0;
|
//virtual bool getOthersList(std::list<std::string> &ssl_ids) = 0;
|
||||||
|
virtual void getPeerCount (unsigned int *pnFriendCount, unsigned int *pnnOnlineCount) = 0;
|
||||||
|
|
||||||
virtual bool isOnline(std::string ssl_id) = 0;
|
virtual bool isOnline(std::string ssl_id) = 0;
|
||||||
virtual bool isFriend(std::string ssl_id) = 0;
|
virtual bool isFriend(std::string ssl_id) = 0;
|
||||||
|
|
|
@ -62,7 +62,10 @@ bool p3Msgs::getMessage(std::string mid, MessageInfo &msg)
|
||||||
return mMsgSrv->getMessage(mid, msg);
|
return mMsgSrv->getMessage(mid, msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void p3Msgs::getMessageCount(unsigned int *pnInbox, unsigned int *pnInboxNew, unsigned int *pnOutbox, unsigned int *pnDraftbox, unsigned int *pnSentbox)
|
||||||
|
{
|
||||||
|
mMsgSrv->getMessageCount(pnInbox, pnInboxNew, pnOutbox, pnDraftbox, pnSentbox);
|
||||||
|
}
|
||||||
|
|
||||||
/****************************************/
|
/****************************************/
|
||||||
/****************************************/
|
/****************************************/
|
||||||
|
|
|
@ -55,6 +55,7 @@ class p3Msgs: public RsMsgs
|
||||||
*/
|
*/
|
||||||
virtual bool getMessageSummaries(std::list<MsgInfoSummary> &msgList);
|
virtual bool getMessageSummaries(std::list<MsgInfoSummary> &msgList);
|
||||||
virtual bool getMessage(std::string mId, MessageInfo &msg);
|
virtual bool getMessage(std::string mId, MessageInfo &msg);
|
||||||
|
virtual void getMessageCount(unsigned int *pnInbox, unsigned int *pnInboxNew, unsigned int *pnOutbox, unsigned int *pnDraftbox, unsigned int *pnSentbox);
|
||||||
|
|
||||||
virtual bool MessageSend(MessageInfo &info);
|
virtual bool MessageSend(MessageInfo &info);
|
||||||
virtual bool MessageDelete(std::string mid);
|
virtual bool MessageDelete(std::string mid);
|
||||||
|
|
|
@ -221,6 +221,16 @@ bool p3Peers::getFriendList(std::list<std::string> &ids)
|
||||||
// return true;
|
// return true;
|
||||||
//}
|
//}
|
||||||
|
|
||||||
|
void p3Peers::getPeerCount (unsigned int *pnFriendCount, unsigned int *pnOnlineCount)
|
||||||
|
{
|
||||||
|
#ifdef P3PEERS_DEBUG
|
||||||
|
std::cerr << "p3Peers::getPeerCount()" << std::endl;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* get from mConnectMgr */
|
||||||
|
mConnMgr->getPeerCount(pnFriendCount, pnOnlineCount);
|
||||||
|
}
|
||||||
|
|
||||||
bool p3Peers::isOnline(std::string id)
|
bool p3Peers::isOnline(std::string id)
|
||||||
{
|
{
|
||||||
#ifdef P3PEERS_DEBUG
|
#ifdef P3PEERS_DEBUG
|
||||||
|
|
|
@ -46,6 +46,7 @@ virtual std::string getOwnId();
|
||||||
virtual bool getOnlineList(std::list<std::string> &ids);
|
virtual bool getOnlineList(std::list<std::string> &ids);
|
||||||
virtual bool getFriendList(std::list<std::string> &ids);
|
virtual bool getFriendList(std::list<std::string> &ids);
|
||||||
//virtual bool getOthersList(std::list<std::string> &ids);
|
//virtual bool getOthersList(std::list<std::string> &ids);
|
||||||
|
virtual void getPeerCount (unsigned int *pnFriendCount, unsigned int *pnOnlineCount);
|
||||||
|
|
||||||
virtual bool isOnline(std::string id);
|
virtual bool isOnline(std::string id);
|
||||||
virtual bool isFriend(std::string id);
|
virtual bool isFriend(std::string id);
|
||||||
|
|
|
@ -455,7 +455,7 @@ bool p3MsgService::getMessageSummaries(std::list<MsgInfoSummary> &msgList)
|
||||||
initRsMIS(mit->second, mis);
|
initRsMIS(mit->second, mis);
|
||||||
msgList.push_back(mis);
|
msgList.push_back(mis);
|
||||||
}
|
}
|
||||||
return 1;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -481,6 +481,44 @@ bool p3MsgService::getMessage(std::string mId, MessageInfo &msg)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void p3MsgService::getMessageCount(unsigned int *pnInbox, unsigned int *pnInboxNew, unsigned int *pnOutbox, unsigned int *pnDraftbox, unsigned int *pnSentbox)
|
||||||
|
{
|
||||||
|
RsStackMutex stack(mMsgMtx); /********** STACK LOCKED MTX ******/
|
||||||
|
|
||||||
|
if (pnInbox) *pnInbox = 0;
|
||||||
|
if (pnInboxNew) *pnInboxNew = 0;
|
||||||
|
if (pnOutbox) *pnOutbox = 0;
|
||||||
|
if (pnDraftbox) *pnDraftbox = 0;
|
||||||
|
if (pnSentbox) *pnSentbox = 0;
|
||||||
|
|
||||||
|
std::map<uint32_t, RsMsgItem *>::iterator mit;
|
||||||
|
std::map<uint32_t, RsMsgItem *> *apMsg [2] = { &imsg, &msgOutgoing };
|
||||||
|
|
||||||
|
for (int i = 0; i < 2; i++) {
|
||||||
|
for (mit = apMsg [i]->begin(); mit != apMsg [i]->end(); mit++) {
|
||||||
|
MsgInfoSummary mis;
|
||||||
|
initRsMIS(mit->second, mis);
|
||||||
|
|
||||||
|
switch (mis.msgflags & RS_MSG_BOXMASK) {
|
||||||
|
case RS_MSG_INBOX:
|
||||||
|
if (pnInbox) (*pnInbox)++;
|
||||||
|
if ((mis.msgflags & RS_MSG_NEW) == RS_MSG_NEW) {
|
||||||
|
if (pnInboxNew) (*pnInboxNew)++;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case RS_MSG_OUTBOX:
|
||||||
|
if (pnOutbox) (*pnOutbox)++;
|
||||||
|
break;
|
||||||
|
case RS_MSG_DRAFTBOX:
|
||||||
|
if (pnDraftbox) (*pnDraftbox)++;
|
||||||
|
break;
|
||||||
|
case RS_MSG_SENTBOX:
|
||||||
|
if (pnSentbox) (*pnSentbox)++;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* remove based on the unique mid (stored in sid) */
|
/* remove based on the unique mid (stored in sid) */
|
||||||
bool p3MsgService::removeMsgId(std::string mid)
|
bool p3MsgService::removeMsgId(std::string mid)
|
||||||
|
|
|
@ -57,6 +57,7 @@ bool getMessageNotifications(std::list<MsgInfoSummary> ¬eList);
|
||||||
|
|
||||||
bool getMessageSummaries(std::list<MsgInfoSummary> &msgList);
|
bool getMessageSummaries(std::list<MsgInfoSummary> &msgList);
|
||||||
bool getMessage(std::string mid, MessageInfo &msg);
|
bool getMessage(std::string mid, MessageInfo &msg);
|
||||||
|
void getMessageCount(unsigned int *pnInbox, unsigned int *pnInboxNew, unsigned int *pnOutbox, unsigned int *pnDraftbox, unsigned int *pnSentbox);
|
||||||
|
|
||||||
bool removeMsgId(std::string mid);
|
bool removeMsgId(std::string mid);
|
||||||
bool markMsgIdRead(std::string mid);
|
bool markMsgIdRead(std::string mid);
|
||||||
|
|
|
@ -351,19 +351,11 @@ void MainWindow::updateStatus()
|
||||||
if (natstatus)
|
if (natstatus)
|
||||||
natstatus->getNATStatus();
|
natstatus->getNATStatus();
|
||||||
|
|
||||||
std::list<std::string> ids;
|
unsigned int online = 0;
|
||||||
rsPeers->getOnlineList(ids);
|
rsPeers->getPeerCount (NULL, &online);
|
||||||
int online = ids.size();
|
|
||||||
|
|
||||||
std::list<MsgInfoSummary> msgList;
|
unsigned int newInboxCount = 0;
|
||||||
std::list<MsgInfoSummary>::const_iterator it;
|
rsMsgs->getMessageCount (NULL, &newInboxCount, NULL, NULL, NULL);
|
||||||
|
|
||||||
rsMsgs -> getMessageSummaries(msgList);
|
|
||||||
int newInboxCount = 0;
|
|
||||||
|
|
||||||
for(it = msgList.begin(); it != msgList.end(); it++)
|
|
||||||
if ((it -> msgflags & RS_MSG_BOXMASK) == RS_MSG_INBOX && ((it -> msgflags & RS_MSG_NEW) == RS_MSG_NEW))
|
|
||||||
newInboxCount ++;
|
|
||||||
|
|
||||||
if(newInboxCount)
|
if(newInboxCount)
|
||||||
messageAction->setIcon(QIcon(QPixmap(":/images/messages_new.png"))) ;
|
messageAction->setIcon(QIcon(QPixmap(":/images/messages_new.png"))) ;
|
||||||
|
|
|
@ -79,12 +79,14 @@ public:
|
||||||
Transfers, /** Transfers page. */
|
Transfers, /** Transfers page. */
|
||||||
SharedDirectories, /** Shared Directories page. */
|
SharedDirectories, /** Shared Directories page. */
|
||||||
Messages, /** Messages page. */
|
Messages, /** Messages page. */
|
||||||
|
#ifndef RS_RELEASE_VERSION
|
||||||
Links, /** Links page. */
|
Links, /** Links page. */
|
||||||
Channels, /** Channels page. */
|
Channels, /** Channels page. */
|
||||||
|
#endif
|
||||||
Forums, /** Forums page. */
|
Forums, /** Forums page. */
|
||||||
Blogs /** Blogs page. */
|
#ifdef BLOGS
|
||||||
|
Blogs, /** Blogs page. */
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Create main window */
|
/** Create main window */
|
||||||
|
|
|
@ -1381,39 +1381,14 @@ void MessagesDialog::filterColumnChanged()
|
||||||
|
|
||||||
void MessagesDialog::updateMessageSummaryList()
|
void MessagesDialog::updateMessageSummaryList()
|
||||||
{
|
{
|
||||||
std::list<MsgInfoSummary> msgList;
|
unsigned int newInboxCount = 0;
|
||||||
std::list<MsgInfoSummary>::const_iterator it;
|
unsigned int newOutboxCount = 0;
|
||||||
|
unsigned int newDraftCount = 0;
|
||||||
|
unsigned int newSentboxCount = 0;
|
||||||
|
unsigned int inboxCount = 0;
|
||||||
|
|
||||||
rsMsgs -> getMessageSummaries(msgList);
|
/* calculating the new messages */
|
||||||
int newInboxCount = 0;
|
rsMsgs->getMessageCount (&inboxCount, &newInboxCount, &newOutboxCount, &newDraftCount, &newSentboxCount);
|
||||||
int newOutboxCount = 0;
|
|
||||||
int newDraftCount = 0;
|
|
||||||
int newSentboxCount = 0;
|
|
||||||
int inboxCount = 0;
|
|
||||||
|
|
||||||
/*calculating the new messages*/
|
|
||||||
for(it = msgList.begin(); it != msgList.end(); it++)
|
|
||||||
{
|
|
||||||
if ((it -> msgflags & RS_MSG_BOXMASK) == RS_MSG_INBOX)
|
|
||||||
{
|
|
||||||
inboxCount ++;
|
|
||||||
if ((it -> msgflags & RS_MSG_NEW) == RS_MSG_NEW) {
|
|
||||||
newInboxCount ++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ((it -> msgflags & RS_MSG_BOXMASK) == RS_MSG_OUTBOX)
|
|
||||||
{
|
|
||||||
newOutboxCount ++;
|
|
||||||
}
|
|
||||||
if ((it -> msgflags & RS_MSG_BOXMASK) == RS_MSG_DRAFTBOX)
|
|
||||||
{
|
|
||||||
newDraftCount ++;
|
|
||||||
}
|
|
||||||
if ((it -> msgflags & RS_MSG_BOXMASK) == RS_MSG_SENTBOX )
|
|
||||||
{
|
|
||||||
newSentboxCount ++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
QString textItem;
|
QString textItem;
|
||||||
/*updating the labels in leftcolumn*/
|
/*updating the labels in leftcolumn*/
|
||||||
|
|
|
@ -67,8 +67,7 @@ const uint32_t SFI_DEFAULT_PERIOD = (30 * 3600 * 24); /* 30 Days */
|
||||||
/** Constructor */
|
/** Constructor */
|
||||||
SubFileItem::SubFileItem(std::string hash, std::string name, std::string path, uint64_t size,
|
SubFileItem::SubFileItem(std::string hash, std::string name, std::string path, uint64_t size,
|
||||||
uint32_t flags, std::string srcId)
|
uint32_t flags, std::string srcId)
|
||||||
:QWidget(NULL), mFileHash(hash), mFileName(name), mFileSize(size), mSrcId(srcId),
|
:QWidget(NULL), mPath(path), mFileHash(hash), mFileName(name), mFileSize(size), mSrcId(srcId)
|
||||||
mPath(path)
|
|
||||||
{
|
{
|
||||||
/* Invoke the Qt Designer generated object setup routine */
|
/* Invoke the Qt Designer generated object setup routine */
|
||||||
setupUi(this);
|
setupUi(this);
|
||||||
|
|
|
@ -63,25 +63,21 @@ void PeerStatus::getPeerStatus()
|
||||||
{
|
{
|
||||||
/* set users/friends/network */
|
/* set users/friends/network */
|
||||||
|
|
||||||
std::list<std::string> ids;
|
unsigned int nFriendCount = 0;
|
||||||
rsPeers->getOnlineList(ids);
|
unsigned int nOnlineCount = 0;
|
||||||
int online = ids.size();
|
rsPeers->getPeerCount (&nFriendCount, &nOnlineCount);
|
||||||
|
|
||||||
ids.clear();
|
|
||||||
rsPeers->getFriendList(ids);
|
|
||||||
int friends = ids.size();
|
|
||||||
|
|
||||||
std::ostringstream out;
|
std::ostringstream out;
|
||||||
out << friends << " ";
|
out << nFriendCount << " ";
|
||||||
|
|
||||||
std::ostringstream out2;
|
std::ostringstream out2;
|
||||||
out2 << online << " ";
|
out2 << nOnlineCount << " ";
|
||||||
|
|
||||||
|
|
||||||
if (statusPeers)
|
if (statusPeers)
|
||||||
statusPeers -> setText( tr("<span style=\"color:#000000\"><strong>Friends:</strong></span>") + " " + QString::fromStdString(out.str()) + " | " + tr("<span style=\"color:#0000FF\"><strong>Online:</strong></span>") + " " + QString::fromStdString(out2.str()) );
|
statusPeers -> setText( tr("<span style=\"color:#000000\"><strong>Friends:</strong></span>") + " " + QString::fromStdString(out.str()) + " | " + tr("<span style=\"color:#0000FF\"><strong>Online:</strong></span>") + " " + QString::fromStdString(out2.str()) );
|
||||||
|
|
||||||
if (online > 0)
|
if (nOnlineCount > 0)
|
||||||
{
|
{
|
||||||
iconLabel->setPixmap(QPixmap::QPixmap(":/images/user/identity16.png"));
|
iconLabel->setPixmap(QPixmap::QPixmap(":/images/user/identity16.png"));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue