Optimized some internals in the news feed items

- std::string -> const std::string&
- QObjectList -> QSet<QObject*>

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@4870 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
thunder2 2012-02-01 12:21:14 +00:00
parent 7cfdbd2d8d
commit ff0d6ff25a
24 changed files with 105 additions and 165 deletions

View file

@ -181,7 +181,7 @@ void NewsFeed::addFeedItem(QWidget *item)
item->setAttribute(Qt::WA_DeleteOnClose, true); item->setAttribute(Qt::WA_DeleteOnClose, true);
connect(item, SIGNAL(destroyed(QObject*)), this, SLOT(itemDestroyed(QObject*))); connect(item, SIGNAL(destroyed(QObject*)), this, SLOT(itemDestroyed(QObject*)));
widgetList.push_back(item); widgets.insert(item);
sendNewsFeedChanged(); sendNewsFeedChanged();
@ -192,12 +192,10 @@ void NewsFeed::addFeedItem(QWidget *item)
} }
} }
void NewsFeed::addFeedItemIfUnique(QWidget *item, int itemType, std::string sslId, bool replace) void NewsFeed::addFeedItemIfUnique(QWidget *item, int itemType, const std::string &sslId, bool replace)
{ {
QObjectList::iterator it; foreach (QObject *itemObject, widgets) {
for (it = widgetList.begin(); it != widgetList.end(); it++) SecurityItem *secitem = dynamic_cast<SecurityItem*>(itemObject);
{
SecurityItem *secitem = dynamic_cast<SecurityItem*>(*it);
if ((secitem) && (secitem->isSame(sslId, itemType))) if ((secitem) && (secitem->isSame(sslId, itemType)))
{ {
if (!replace) if (!replace)
@ -496,7 +494,7 @@ void NewsFeed::addFeedItemChatNew(RsFeedItem &fi)
} }
/* make new widget */ /* make new widget */
ChatMsgItem *cm = new ChatMsgItem(this, NEWSFEED_CHATMSGLIST, fi.mId1, fi.mId2, true); ChatMsgItem *cm = new ChatMsgItem(this, NEWSFEED_CHATMSGLIST, fi.mId1, fi.mId2);
/* store in forum list */ /* store in forum list */
@ -553,11 +551,7 @@ void NewsFeed::openChat(std::string peerId)
void NewsFeed::itemDestroyed(QObject *item) void NewsFeed::itemDestroyed(QObject *item)
{ {
int index = widgetList.indexOf(item); widgets.remove(item);
if (index >= 0) {
widgetList.removeAt(index);
}
sendNewsFeedChanged(); sendNewsFeedChanged();
} }
@ -566,23 +560,21 @@ void NewsFeed::removeAll()
#ifdef NEWS_DEBUG #ifdef NEWS_DEBUG
std::cerr << "NewsFeed::removeAll()" << std::endl; std::cerr << "NewsFeed::removeAll()" << std::endl;
#endif #endif
while (widgetList.count()) {
QObject *item = widgetList.first();
widgetList.pop_front();
foreach (QObject *item, widgets) {
if (item) { if (item) {
item->deleteLater(); item->deleteLater();
} }
} }
widgets.clear();
} }
void NewsFeed::sendNewsFeedChanged() void NewsFeed::sendNewsFeedChanged()
{ {
int count = 0; int count = 0;
QObjectList::iterator it; foreach (QObject *item, widgets) {
for (it = widgetList.begin(); it != widgetList.end(); it++) { if (dynamic_cast<PeerItem*>(item) == NULL) {
if (dynamic_cast<PeerItem*>(*it) == NULL) {
/* don't count PeerItem's */ /* don't count PeerItem's */
count++; count++;
} }

View file

@ -58,7 +58,7 @@ private slots:
private: private:
void addFeedItem(QWidget *item); void addFeedItem(QWidget *item);
void addFeedItemIfUnique(QWidget *item, int itemType, std::string sslId, bool replace); void addFeedItemIfUnique(QWidget *item, int itemType, const std::string &sslId, bool replace);
void addFeedItemPeerConnect(RsFeedItem &fi); void addFeedItemPeerConnect(RsFeedItem &fi);
void addFeedItemPeerDisconnect(RsFeedItem &fi); void addFeedItemPeerDisconnect(RsFeedItem &fi);
@ -85,7 +85,7 @@ private:
void sendNewsFeedChanged(); void sendNewsFeedChanged();
QLayout *mLayout; QLayout *mLayout;
QObjectList widgetList; QSet<QObject*> widgets;
/* lists of feedItems */ /* lists of feedItems */
std::list<ForumNewItem *> mForumNewItems; std::list<ForumNewItem *> mForumNewItems;

View file

@ -48,8 +48,6 @@ public:
AttachFileItem(const QString& localpath); AttachFileItem(const QString& localpath);
AttachFileItem(const std::string& hash, const QString& name, uint64_t size, uint32_t flags, const std::string& srcId); AttachFileItem(const std::string& hash, const QString& name, uint64_t size, uint32_t flags, const std::string& srcId);
/** Default Destructor */
const std::string& FileHash() { return mFileHash; } const std::string& FileHash() { return mFileHash; }
const QString& FileName() { return mFileName; } const QString& FileName() { return mFileName; }
uint64_t FileSize() { return mFileSize; } uint64_t FileSize() { return mFileSize; }

View file

@ -34,9 +34,7 @@ class BlogMsgItem : public QWidget, private Ui::BlogMsgItem
public: public:
/** Default Constructor */ /** Default Constructor */
BlogMsgItem(FeedHolder *parent, uint32_t feedId, std::string peerId, std::string msgId, bool isHome); BlogMsgItem(FeedHolder *parent, uint32_t feedId, const std::string &peerId, const std::string &msgId, bool isHome);
/** Default Destructor */
void updateItemStatic(); void updateItemStatic();
void small(); void small();
@ -63,7 +61,5 @@ private:
std::list<SubFileItem *> mFileItems; std::list<SubFileItem *> mFileItems;
}; };
#endif #endif

View file

@ -33,9 +33,7 @@ class BlogNewItem : public QWidget, private Ui::BlogNewItem
public: public:
/** Default Constructor */ /** Default Constructor */
BlogNewItem(FeedHolder *parent, uint32_t feedId, std::string blogId, bool isHome, bool isNew); BlogNewItem(FeedHolder *parent, uint32_t feedId, const std::string &blogId, bool isHome, bool isNew);
/** Default Destructor */
void updateItemStatic(); void updateItemStatic();
void small(); void small();
@ -60,7 +58,5 @@ private:
bool mIsNew; bool mIsNew;
}; };
#endif #endif

View file

@ -40,7 +40,7 @@
****/ ****/
/** Constructor */ /** Constructor */
ChanMsgItem::ChanMsgItem(FeedHolder *parent, uint32_t feedId, std::string chanId, std::string msgId, bool isHome) ChanMsgItem::ChanMsgItem(FeedHolder *parent, uint32_t feedId, const std::string &chanId, const std::string &msgId, bool isHome)
:QWidget(NULL), mParent(parent), mFeedId(feedId), :QWidget(NULL), mParent(parent), mFeedId(feedId),
mChanId(chanId), mMsgId(msgId), mIsHome(isHome) mChanId(chanId), mMsgId(msgId), mIsHome(isHome)
{ {

View file

@ -34,7 +34,7 @@ class ChanMsgItem : public QWidget, private Ui::ChanMsgItem
public: public:
/** Default Constructor */ /** Default Constructor */
ChanMsgItem(FeedHolder *parent, uint32_t feedId, std::string chanId, std::string msgId, bool isHome); ChanMsgItem(FeedHolder *parent, uint32_t feedId, const std::string &chanId, const std::string &msgId, bool isHome);
void updateItemStatic(); void updateItemStatic();
void small(); void small();

View file

@ -32,7 +32,7 @@
****/ ****/
/** Constructor */ /** Constructor */
ChanNewItem::ChanNewItem(FeedHolder *parent, uint32_t feedId, std::string chanId, bool isHome, bool isNew) ChanNewItem::ChanNewItem(FeedHolder *parent, uint32_t feedId, const std::string &chanId, bool isHome, bool isNew)
:QWidget(NULL), mParent(parent), mFeedId(feedId), :QWidget(NULL), mParent(parent), mFeedId(feedId),
mChanId(chanId), mIsHome(isHome), mIsNew(isNew) mChanId(chanId), mIsHome(isHome), mIsNew(isNew)
{ {

View file

@ -33,9 +33,7 @@ class ChanNewItem : public QWidget, private Ui::ChanNewItem
public: public:
/** Default Constructor */ /** Default Constructor */
ChanNewItem(FeedHolder *parent, uint32_t feedId, std::string chanId, bool isHome, bool isNew); ChanNewItem(FeedHolder *parent, uint32_t feedId, const std::string &chanId, bool isHome, bool isNew);
/** Default Destructor */
void updateItemStatic(); void updateItemStatic();
void small(); void small();
@ -59,7 +57,5 @@ private:
bool mIsNew; bool mIsNew;
}; };
#endif #endif

View file

@ -42,9 +42,8 @@
****/ ****/
/** Constructor */ /** Constructor */
ChatMsgItem::ChatMsgItem(FeedHolder *parent, uint32_t feedId, std::string peerId, std::string message, bool isHome) ChatMsgItem::ChatMsgItem(FeedHolder *parent, uint32_t feedId, const std::string &peerId, const std::string &message)
:QWidget(NULL), mParent(parent), mFeedId(feedId), :QWidget(NULL), mParent(parent), mFeedId(feedId), mPeerId(peerId)
mPeerId(peerId), mIsHome(isHome)
{ {
/* Invoke the Qt Designer generated object setup routine */ /* Invoke the Qt Designer generated object setup routine */
setupUi(this); setupUi(this);
@ -140,7 +139,7 @@ void ChatMsgItem::updateItem()
return; return;
} }
void ChatMsgItem::insertChat(std::string &message) void ChatMsgItem::insertChat(const std::string &message)
{ {
#ifdef DEBUG_ITEM #ifdef DEBUG_ITEM
std::cerr << "ChatMsgItem::insertChat(): " << msg << std::endl; std::cerr << "ChatMsgItem::insertChat(): " << msg << std::endl;

View file

@ -25,19 +25,15 @@
#include "ui_ChatMsgItem.h" #include "ui_ChatMsgItem.h"
#include <stdint.h> #include <stdint.h>
class FeedHolder; class FeedHolder;
class ChatMsgItem : public QWidget, private Ui::ChatMsgItem class ChatMsgItem : public QWidget, private Ui::ChatMsgItem
{ {
Q_OBJECT Q_OBJECT
public: public:
/** Default Constructor */ /** Default Constructor */
ChatMsgItem(FeedHolder *parent, uint32_t feedId, std::string peerId, std::string message, bool isHome); ChatMsgItem(FeedHolder *parent, uint32_t feedId, const std::string &peerId, const std::string &message);
/** Default Destructor */
void updateItemStatic(); void updateItemStatic();
@ -57,15 +53,12 @@ private slots:
void on_quickmsgText_textChanged(); void on_quickmsgText_textChanged();
private: private:
void insertChat(std::string &message); void insertChat(const std::string &message);
FeedHolder *mParent; FeedHolder *mParent;
uint32_t mFeedId; uint32_t mFeedId;
std::string mPeerId; std::string mPeerId;
bool mIsHome;
}; };
#endif #endif

View file

@ -33,7 +33,6 @@ const uint32_t FEEDHOLDER_MSG_BLOG = 0x0004;
class FeedHolder class FeedHolder
{ {
public: public:
virtual void deleteFeedItem(QWidget *item, uint32_t type) = 0; virtual void deleteFeedItem(QWidget *item, uint32_t type) = 0;
virtual void openChat(std::string peerId) = 0; virtual void openChat(std::string peerId) = 0;
}; };

View file

@ -35,8 +35,6 @@ public:
/** Default Constructor */ /** Default Constructor */
ForumMsgItem(FeedHolder *parent, uint32_t feedId, const std::string &forumId, const std::string &postId, bool isHome); ForumMsgItem(FeedHolder *parent, uint32_t feedId, const std::string &forumId, const std::string &postId, bool isHome);
/** Default Destructor */
void updateItemStatic(); void updateItemStatic();
void small(); void small();
@ -63,7 +61,5 @@ private:
bool mIsTop; bool mIsTop;
}; };
#endif #endif

View file

@ -31,7 +31,7 @@
****/ ****/
/** Constructor */ /** Constructor */
ForumNewItem::ForumNewItem(FeedHolder *parent, uint32_t feedId, std::string forumId, bool isHome, bool isNew) ForumNewItem::ForumNewItem(FeedHolder *parent, uint32_t feedId, const std::string &forumId, bool isHome, bool isNew)
:QWidget(NULL), mParent(parent), mFeedId(feedId), :QWidget(NULL), mParent(parent), mFeedId(feedId),
mForumId(forumId), mIsHome(isHome), mIsNew(isNew) mForumId(forumId), mIsHome(isHome), mIsNew(isNew)
{ {
@ -203,4 +203,3 @@ void ForumNewItem::postToForum()
cfm->show(); cfm->show();
} }
} }

View file

@ -33,9 +33,7 @@ class ForumNewItem : public QWidget, private Ui::ForumNewItem
public: public:
/** Default Constructor */ /** Default Constructor */
ForumNewItem(FeedHolder *parent, uint32_t feedId, std::string forumId, bool isHome, bool isNew); ForumNewItem(FeedHolder *parent, uint32_t feedId, const std::string &forumId, bool isHome, bool isNew);
/** Default Destructor */
void updateItemStatic(); void updateItemStatic();
void small(); void small();
@ -60,7 +58,5 @@ private:
bool mIsNew; bool mIsNew;
}; };
#endif #endif

View file

@ -38,7 +38,7 @@
****/ ****/
/** Constructor */ /** Constructor */
MsgItem::MsgItem(FeedHolder *parent, uint32_t feedId, std::string msgId, bool isHome) MsgItem::MsgItem(FeedHolder *parent, uint32_t feedId, const std::string &msgId, bool isHome)
:QWidget(NULL), mParent(parent), mFeedId(feedId), mMsgId(msgId), mIsHome(isHome) :QWidget(NULL), mParent(parent), mFeedId(feedId), mMsgId(msgId), mIsHome(isHome)
{ {
/* Invoke the Qt Designer generated object setup routine */ /* Invoke the Qt Designer generated object setup routine */

View file

@ -34,9 +34,7 @@ class MsgItem : public QWidget, private Ui::MsgItem
public: public:
/** Default Constructor */ /** Default Constructor */
MsgItem(FeedHolder *parent, uint32_t feedId, std::string msgId, bool isHome); MsgItem(FeedHolder *parent, uint32_t feedId, const std::string &msgId, bool isHome);
/** Default Destructor */
void updateItemStatic(); void updateItemStatic();
void small(); void small();
@ -65,7 +63,5 @@ private:
std::list<SubFileItem *> mFileItems; std::list<SubFileItem *> mFileItems;
}; };
#endif #endif

View file

@ -41,7 +41,7 @@
****/ ****/
/** Constructor */ /** Constructor */
PeerItem::PeerItem(FeedHolder *parent, uint32_t feedId, std::string peerId, uint32_t type, bool isHome) PeerItem::PeerItem(FeedHolder *parent, uint32_t feedId, const std::string &peerId, uint32_t type, bool isHome)
:QWidget(NULL), mParent(parent), mFeedId(feedId), :QWidget(NULL), mParent(parent), mFeedId(feedId),
mPeerId(peerId), mType(type), mIsHome(isHome) mPeerId(peerId), mType(type), mIsHome(isHome)
{ {

View file

@ -32,16 +32,13 @@ const uint32_t PEER_TYPE_NEW_FOF = 0x0004; /* new Friend of Friend */
class FeedHolder; class FeedHolder;
class PeerItem : public QWidget, private Ui::PeerItem class PeerItem : public QWidget, private Ui::PeerItem
{ {
Q_OBJECT Q_OBJECT
public: public:
/** Default Constructor */ /** Default Constructor */
PeerItem(FeedHolder *parent, uint32_t feedId, std::string peerId, uint32_t type, bool isHome); PeerItem(FeedHolder *parent, uint32_t feedId, const std::string &peerId, uint32_t type, bool isHome);
/** Default Destructor */
void updateItemStatic(); void updateItemStatic();
void small(); void small();
@ -63,7 +60,6 @@ private slots:
void on_quickmsgText_textChanged(); void on_quickmsgText_textChanged();
private: private:
FeedHolder *mParent; FeedHolder *mParent;
uint32_t mFeedId; uint32_t mFeedId;
@ -73,7 +69,5 @@ private:
bool mIsHome; bool mIsHome;
}; };
#endif #endif

View file

@ -43,7 +43,7 @@
****/ ****/
/** Constructor */ /** Constructor */
SecurityItem::SecurityItem(FeedHolder *parent, uint32_t feedId, std::string gpgId, std::string sslId, uint32_t type, bool isHome) SecurityItem::SecurityItem(FeedHolder *parent, uint32_t feedId, const std::string &gpgId, const std::string &sslId, uint32_t type, bool isHome)
:QWidget(NULL), mParent(parent), mFeedId(feedId), :QWidget(NULL), mParent(parent), mFeedId(feedId),
mSslId(sslId), mGpgId(gpgId), mType(type), mIsHome(isHome) mSslId(sslId), mGpgId(gpgId), mType(type), mIsHome(isHome)
{ {

View file

@ -38,7 +38,7 @@ class SecurityItem : public QWidget, private Ui::SecurityItem
public: public:
/** Default Constructor */ /** Default Constructor */
SecurityItem(FeedHolder *parent, uint32_t feedId, std::string gpgId, std::string sslId, uint32_t type, bool isHome); SecurityItem(FeedHolder *parent, uint32_t feedId, const std::string &gpgId, const std::string &sslId, uint32_t type, bool isHome);
void updateItemStatic(); void updateItemStatic();
void small(); void small();
@ -73,7 +73,5 @@ private:
bool mIsHome; bool mIsHome;
}; };
#endif #endif

View file

@ -31,7 +31,7 @@
****/ ****/
/** Constructor */ /** Constructor */
SubDestItem::SubDestItem(uint32_t type, std::string groupId, std::string inReplyTo) SubDestItem::SubDestItem(uint32_t type, const std::string &groupId, const std::string &inReplyTo)
:QWidget(NULL), mType(type), mGroupId(groupId), mInReplyTo(inReplyTo) :QWidget(NULL), mType(type), mGroupId(groupId), mInReplyTo(inReplyTo)
{ {
/* Invoke the Qt Designer generated object setup routine */ /* Invoke the Qt Designer generated object setup routine */

View file

@ -31,9 +31,7 @@ class SubDestItem : public QWidget, private Ui::SubDestItem
public: public:
/** Default Constructor */ /** Default Constructor */
SubDestItem(uint32_t type, std::string groupId, std::string inReplyTo); SubDestItem(uint32_t type, const std::string &groupId, const std::string &inReplyTo);
/** Default Destructor */
uint32_t DestType() { return mType; } uint32_t DestType() { return mType; }
std::string DestGroupId() { return mGroupId; } std::string DestGroupId() { return mGroupId; }
@ -51,7 +49,5 @@ private:
std::string mInReplyTo; std::string mInReplyTo;
}; };
#endif #endif

View file

@ -57,8 +57,6 @@ public:
/** Default Constructor */ /** Default Constructor */
SubFileItem(const std::string &hash, const std::string &name, const std::string &path, uint64_t size, uint32_t flags, const std::string &srcId); SubFileItem(const std::string &hash, const std::string &name, const std::string &path, uint64_t size, uint32_t flags, const std::string &srcId);
/** Default Destructor */
void smaller(); void smaller();
std::string FileHash() { return mFileHash; } std::string FileHash() { return mFileHash; }
@ -88,7 +86,6 @@ private slots:
void updateItem(); void updateItem();
private: private:
void Setup(); void Setup();
std::string mPath; std::string mPath;
@ -107,7 +104,6 @@ private:
signals: signals:
void fileFinished(SubFileItem * subFileItem); void fileFinished(SubFileItem * subFileItem);
}; };
#endif #endif