From 3dca71330c2b7dc4725696eefc0d703214d5bf97 Mon Sep 17 00:00:00 2001 From: thunder2 Date: Tue, 24 Apr 2012 15:34:22 +0000 Subject: [PATCH] Optimized channel loading and layout. git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@5118 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- retroshare-gui/src/gui/ChannelFeed.cpp | 59 +++++++++++-------- retroshare-gui/src/gui/ChannelFeed.h | 6 +- retroshare-gui/src/gui/ChannelFeed.ui | 30 +++------- .../src/gui/chat/HandleRichText.cpp | 4 +- 4 files changed, 47 insertions(+), 52 deletions(-) diff --git a/retroshare-gui/src/gui/ChannelFeed.cpp b/retroshare-gui/src/gui/ChannelFeed.cpp index 6a461c20c..8fe5e8af1 100644 --- a/retroshare-gui/src/gui/ChannelFeed.cpp +++ b/retroshare-gui/src/gui/ChannelFeed.cpp @@ -51,6 +51,8 @@ * #define CHAN_DEBUG ***/ +#define USE_THREAD + /** Constructor */ ChannelFeed::ChannelFeed(QWidget *parent) : RsAutoUpdatePage(1000,parent) @@ -528,6 +530,7 @@ void ChannelFeed::updateChannelMsgs() actionEnable_Auto_Download->setEnabled(false); } +#ifdef USE_THREAD progressLabel->show(); progressBar->reset(); progressBar->show(); @@ -537,21 +540,33 @@ void ChannelFeed::updateChannelMsgs() // connect thread connect(fillThread, SIGNAL(finished()), this, SLOT(fillThreadFinished()), Qt::BlockingQueuedConnection); - connect(fillThread, SIGNAL(progress(int,int)), this, SLOT(fillThreadProgress(int,int))); - connect(fillThread, SIGNAL(addMsg(QString,QString)), this, SLOT(fillThreadAddMsg(QString,QString)), Qt::BlockingQueuedConnection); + connect(fillThread, SIGNAL(addMsg(QString,QString,int,int)), this, SLOT(fillThreadAddMsg(QString,QString,int,int)), Qt::BlockingQueuedConnection); -#ifdef DEBUG_FORUMS +#ifdef CHAN_DEBUG std::cerr << "ChannelFeed::updateChannelMsgs() Start fill thread" << std::endl; #endif // start thread fillThread->start(); +#else + std::list msgs; + std::list::iterator it; + rsChannels->getChannelMsgList(mChannelId, msgs); + + msgs.sort(sortChannelMsgSummary); + + for (it = msgs.begin(); it != msgs.end(); it++) { + ChanMsgItem *cmi = new ChanMsgItem(this, 0, mChannelId, it->msgId, true); + mChanMsgItems.push_back(cmi); + verticalLayout_2->addWidget(cmi); + } +#endif } void ChannelFeed::fillThreadFinished() { -#ifdef DEBUG_FORUMS - std::cerr << "ChannelFeed::fillThreadFinished" << std::endl; +#ifdef CHAN_DEBUG + std::cerr << "ChannelFeed::fillThreadFinished()" << std::endl; #endif // thread has finished @@ -564,40 +579,37 @@ void ChannelFeed::fillThreadFinished() fillThread = NULL; } +#ifdef CHAN_DEBUG if (thread->wasStopped()) { // thread was stopped -#ifdef DEBUG_FORUMS - std::cerr << "ChannelFeed::fillThreadFinished Thread was stopped" << std::endl; -#endif + std::cerr << "ChannelFeed::fillThreadFinished() Thread was stopped" << std::endl; } +#endif -#ifdef DEBUG_FORUMS - std::cerr << "ChannelFeed::fillThreadFinished Delete thread" << std::endl; +#ifdef CHAN_DEBUG + std::cerr << "ChannelFeed::fillThreadFinished() Delete thread" << std::endl; #endif thread->deleteLater(); thread = NULL; } -#ifdef DEBUG_FORUMS - std::cerr << "ChannelFeed::fillThreadFinished done" << std::endl; +#ifdef CHAN_DEBUG + std::cerr << "ChannelFeed::fillThreadFinished done()" << std::endl; #endif } -void ChannelFeed::fillThreadProgress(int current, int count) -{ - // show fill progress - if (count) { - progressBar->setValue(current * progressBar->maximum() / count); - } -} - -void ChannelFeed::fillThreadAddMsg(const QString &channelId, const QString &channelMsgId) +void ChannelFeed::fillThreadAddMsg(const QString &channelId, const QString &channelMsgId, int current, int count) { if (sender() == fillThread) { + // show fill progress + if (count) { + progressBar->setValue(current * progressBar->maximum() / count); + } + ChanMsgItem *cmi = new ChanMsgItem(this, 0, channelId.toStdString(), channelMsgId.toStdString(), true); mChanMsgItems.push_back(cmi); - verticalLayout_2->addWidget(cmi); + verticalLayout->addWidget(cmi); } } @@ -808,8 +820,7 @@ void ChannelFillThread::run() break; } - emit addMsg(QString::fromStdString(channelId), QString::fromStdString(it->msgId)); - emit progress(++pos, count); + emit addMsg(QString::fromStdString(channelId), QString::fromStdString(it->msgId), ++pos, count); } #ifdef CHAN_DEBUG diff --git a/retroshare-gui/src/gui/ChannelFeed.h b/retroshare-gui/src/gui/ChannelFeed.h index dac3f2217..9be394cd0 100644 --- a/retroshare-gui/src/gui/ChannelFeed.h +++ b/retroshare-gui/src/gui/ChannelFeed.h @@ -80,8 +80,7 @@ private slots: void generateMassData(); void fillThreadFinished(); - void fillThreadProgress(int current, int count); - void fillThreadAddMsg(const QString &channelId, const QString &channelMsgId); + void fillThreadAddMsg(const QString &channelId, const QString &channelMsgId, int current, int count); private: void updateChannelList(); @@ -121,8 +120,7 @@ public: bool wasStopped() { return stopped; } signals: - void progress(int current, int count); - void addMsg(const QString &channelId, const QString &channelMsgId); + void addMsg(const QString &channelId, const QString &channelMsgId, int current, int count); public: std::string channelId; diff --git a/retroshare-gui/src/gui/ChannelFeed.ui b/retroshare-gui/src/gui/ChannelFeed.ui index 3599bb4a0..f534028bc 100644 --- a/retroshare-gui/src/gui/ChannelFeed.ui +++ b/retroshare-gui/src/gui/ChannelFeed.ui @@ -513,18 +513,21 @@ border-image: url(:/images/btn_26_pressed.png) 4; true - - Qt::AlignBottom|Qt::AlignLeading|Qt::AlignLeft - 0 0 400 - 304 + 16 + + + 0 + 0 + + QWidget#scrollAreaWidgetContents{border: none;} @@ -535,25 +538,6 @@ border-image: url(:/images/btn_26_pressed.png) 4; 0 - - - - - - - Qt::Vertical - - - QSizePolicy::MinimumExpanding - - - - 0 - 0 - - - - diff --git a/retroshare-gui/src/gui/chat/HandleRichText.cpp b/retroshare-gui/src/gui/chat/HandleRichText.cpp index 5000143cd..34a1f7778 100644 --- a/retroshare-gui/src/gui/chat/HandleRichText.cpp +++ b/retroshare-gui/src/gui/chat/HandleRichText.cpp @@ -182,7 +182,9 @@ QString formatText(const QString &text, unsigned int flag) if (flag & RSHTML_FORMATTEXT_REMOVE_COLOR) { optimizeFlag |= RSHTML_OPTIMIZEHTML_REMOVE_COLOR; } - optimizeHtml(formattedText, optimizeFlag); + if (optimizeFlag) { + optimizeHtml(formattedText, optimizeFlag); + } return formattedText; }