From a497157110da27f1ee34be6af9386e9812e072cc Mon Sep 17 00:00:00 2001 From: thunder2 Date: Wed, 1 May 2013 21:16:46 +0000 Subject: [PATCH] FeedReader: - added new setting to save the config in the background for slow systems - fixed memory leak in p3FeedReader::saveList git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@6349 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- plugins/FeedReader/gui/FeedReaderConfig.cpp | 2 + plugins/FeedReader/gui/FeedReaderConfig.ui | 25 ++++++-- plugins/FeedReader/interface/rsFeedReader.h | 2 + plugins/FeedReader/lang/FeedReader_en.ts | 9 ++- plugins/FeedReader/services/p3FeedReader.cc | 70 ++++++++++++++++++--- plugins/FeedReader/services/p3FeedReader.h | 4 ++ 6 files changed, 99 insertions(+), 13 deletions(-) diff --git a/plugins/FeedReader/gui/FeedReaderConfig.cpp b/plugins/FeedReader/gui/FeedReaderConfig.cpp index dd100e0f0..20d44ba7f 100644 --- a/plugins/FeedReader/gui/FeedReaderConfig.cpp +++ b/plugins/FeedReader/gui/FeedReaderConfig.cpp @@ -50,6 +50,7 @@ void FeedReaderConfig::load() { ui->updateIntervalSpinBox->setValue(rsFeedReader->getStandardUpdateInterval() / 60); ui->storageTimeSpinBox->setValue(rsFeedReader->getStandardStorageTime() / (60 * 60 *24)); + ui->saveInBackgroundCheckBox->setChecked(rsFeedReader->getSaveInBackground()); ui->setMsgToReadOnActivate->setChecked(FeedReaderSetting_SetMsgToReadOnActivate()); ui->openAllInNewTabCheckBox->setChecked(FeedReaderSetting_OpenAllInNewTab()); @@ -67,6 +68,7 @@ bool FeedReaderConfig::save(QString &/*errmsg*/) rsFeedReader->setStandardUpdateInterval(ui->updateIntervalSpinBox->value() * 60); rsFeedReader->setStandardStorageTime(ui->storageTimeSpinBox->value() * 60 *60 * 24); rsFeedReader->setStandardProxy(ui->useProxyCheckBox->isChecked(), ui->proxyAddressLineEdit->text().toUtf8().constData(), ui->proxyPortSpinBox->value()); + rsFeedReader->setSaveInBackground(ui->saveInBackgroundCheckBox->isChecked()); Settings->setValueToGroup("FeedReaderDialog", "SetMsgToReadOnActivate", ui->setMsgToReadOnActivate->isChecked()); Settings->setValueToGroup("FeedReaderDialog", "OpenAllInNewTab", ui->openAllInNewTabCheckBox->isChecked()); diff --git a/plugins/FeedReader/gui/FeedReaderConfig.ui b/plugins/FeedReader/gui/FeedReaderConfig.ui index 988c15bec..8928dc85e 100644 --- a/plugins/FeedReader/gui/FeedReaderConfig.ui +++ b/plugins/FeedReader/gui/FeedReaderConfig.ui @@ -118,17 +118,24 @@ Misc - + + + + Open all feeds in new tab + + + + Set message to read on activate - - + + - Open all feeds in new tab + Save configuration in background (for slow systems, more memory needed) @@ -150,6 +157,16 @@ + + updateIntervalSpinBox + storageTimeSpinBox + useProxyCheckBox + proxyAddressLineEdit + proxyPortSpinBox + saveInBackgroundCheckBox + setMsgToReadOnActivate + openAllInNewTabCheckBox + diff --git a/plugins/FeedReader/interface/rsFeedReader.h b/plugins/FeedReader/interface/rsFeedReader.h index 9112adfc4..be3eb00af 100644 --- a/plugins/FeedReader/interface/rsFeedReader.h +++ b/plugins/FeedReader/interface/rsFeedReader.h @@ -198,6 +198,8 @@ public: virtual void setStandardUpdateInterval(uint32_t updateInterval) = 0; virtual bool getStandardProxy(std::string &proxyAddress, uint16_t &proxyPort) = 0; virtual void setStandardProxy(bool useProxy, const std::string &proxyAddress, uint16_t proxyPort) = 0; + virtual bool getSaveInBackground() = 0; + virtual void setSaveInBackground(bool saveInBackground) = 0; virtual RsFeedAddResult addFolder(const std::string parentId, const std::string &name, std::string &feedId) = 0; virtual RsFeedAddResult setFolder(const std::string &feedId, const std::string &name) = 0; diff --git a/plugins/FeedReader/lang/FeedReader_en.ts b/plugins/FeedReader/lang/FeedReader_en.ts index 79c4484f8..e2f7ae14d 100644 --- a/plugins/FeedReader/lang/FeedReader_en.ts +++ b/plugins/FeedReader/lang/FeedReader_en.ts @@ -264,12 +264,17 @@ - + Set message to read on activate - + + Save configuration in background (for slow systems, more memory needed) + + + + Open all feeds in new tab diff --git a/plugins/FeedReader/services/p3FeedReader.cc b/plugins/FeedReader/services/p3FeedReader.cc index bfb307a0c..cfd589c53 100644 --- a/plugins/FeedReader/services/p3FeedReader.cc +++ b/plugins/FeedReader/services/p3FeedReader.cc @@ -50,6 +50,7 @@ p3FeedReader::p3FeedReader(RsPluginHandler* pgHandler) mStandardProxyPort = 0; mLastClean = 0; mNotify = NULL; + mSaveInBackground = false; mPreviewDownloadThread = NULL; mPreviewProcessThread = NULL; @@ -273,6 +274,23 @@ void p3FeedReader::setStandardProxy(bool useProxy, const std::string &proxyAddre } } +bool p3FeedReader::getSaveInBackground() +{ + RsStackMutex stack(mFeedReaderMtx); /******* LOCK STACK MUTEX *********/ + + return mSaveInBackground; +} + +void p3FeedReader::setSaveInBackground(bool saveInBackground) +{ + RsStackMutex stack(mFeedReaderMtx); /******* LOCK STACK MUTEX *********/ + + if (saveInBackground != mSaveInBackground) { + mSaveInBackground = saveInBackground; + IndicateConfigChanged(); + } +} + void p3FeedReader::stop() { { @@ -1344,11 +1362,15 @@ RsSerialiser *p3FeedReader::setupSerialiser() return rss; } -bool p3FeedReader::saveList(bool &cleanup, std::list & saveData) +bool p3FeedReader::saveList(bool &cleanup, std::list &saveData) { mFeedReaderMtx.lock(); /*********************** LOCK *******/ - cleanup = false; + if (mSaveInBackground) { + cleanup = true; + } else { + cleanup = false; + } RsConfigKeyValueSet *rskv = new RsConfigKeyValueSet(); @@ -1373,8 +1395,15 @@ bool p3FeedReader::saveList(bool &cleanup, std::list & saveData) rs_sprintf(kv.value, "%hu", mStandardProxyPort); rskv->tlvkvs.pairs.push_back(kv); + kv.key = "SaveInBackground"; + rs_sprintf(kv.value, "%hu", mSaveInBackground ? 1 : 0); + rskv->tlvkvs.pairs.push_back(kv); + /* Add KeyValue to saveList */ saveData.push_back(rskv); + if (!cleanup) { + cleanSaveData.push_back(rskv); + } std::map::iterator it1; for (it1 = mFeeds.begin(); it1 != mFeeds.end(); ++it1) { @@ -1382,22 +1411,44 @@ bool p3FeedReader::saveList(bool &cleanup, std::list & saveData) if (fi->preview) { continue; } - saveData.push_back(fi); + if (cleanup) { + saveData.push_back(new RsFeedReaderFeed(*fi)); + } else { + saveData.push_back(fi); + } std::map::iterator it2; for (it2 = fi->msgs.begin(); it2 != fi->msgs.end(); ++it2) { - saveData.push_back(it2->second); + RsFeedReaderMsg *msg = it2->second; + + if (cleanup) { + saveData.push_back(new RsFeedReaderMsg(*msg)); + } else { + saveData.push_back(msg); + } } } + if (mSaveInBackground) { + mFeedReaderMtx.unlock(); /*********************** UNLOCK *******/ + } + /* list completed! */ return true; } void p3FeedReader::saveDone() -{ - mFeedReaderMtx.unlock(); /*********************** UNLOCK *******/ - return; +{ + /* clean settings items */ + std::list::iterator it; + for (it = cleanSaveData.begin(); it != cleanSaveData.end(); ++it) { + delete(*it); + } + cleanSaveData.clear(); + + if (!mSaveInBackground) { + mFeedReaderMtx.unlock(); /*********************** UNLOCK *******/ + } } bool p3FeedReader::loadList(std::list& load) @@ -1466,6 +1517,11 @@ bool p3FeedReader::loadList(std::list& load) if (sscanf(kit->value.c_str(), "%hu", &value) == 1) { mStandardProxyPort = value; } + } else if (kit->key == "SaveInBackground") { + uint16_t value; + if (sscanf(kit->value.c_str(), "%hu", &value) == 1) { + mSaveInBackground = value == 1 ? true : false; + } } } } else { diff --git a/plugins/FeedReader/services/p3FeedReader.h b/plugins/FeedReader/services/p3FeedReader.h index b92c89dab..61c933564 100644 --- a/plugins/FeedReader/services/p3FeedReader.h +++ b/plugins/FeedReader/services/p3FeedReader.h @@ -45,6 +45,8 @@ public: virtual void setStandardUpdateInterval(uint32_t updateInterval); virtual bool getStandardProxy(std::string &proxyAddress, uint16_t &proxyPort); virtual void setStandardProxy(bool useProxy, const std::string &proxyAddress, uint16_t proxyPort); + virtual bool getSaveInBackground(); + virtual void setSaveInBackground(bool saveInBackground); virtual RsFeedAddResult addFolder(const std::string parentId, const std::string &name, std::string &feedId); virtual RsFeedAddResult setFolder(const std::string &feedId, const std::string &name); @@ -98,6 +100,8 @@ private: RsFeedReaderNotify *mNotify; RsMutex mFeedReaderMtx; + std::list cleanSaveData; + bool mSaveInBackground; std::list mThreads; uint32_t mNextFeedId; uint32_t mNextMsgId;