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
This commit is contained in:
thunder2 2013-05-01 21:16:46 +00:00
parent 05f8b15cfe
commit a497157110
6 changed files with 99 additions and 13 deletions

View File

@ -50,6 +50,7 @@ void FeedReaderConfig::load()
{ {
ui->updateIntervalSpinBox->setValue(rsFeedReader->getStandardUpdateInterval() / 60); ui->updateIntervalSpinBox->setValue(rsFeedReader->getStandardUpdateInterval() / 60);
ui->storageTimeSpinBox->setValue(rsFeedReader->getStandardStorageTime() / (60 * 60 *24)); ui->storageTimeSpinBox->setValue(rsFeedReader->getStandardStorageTime() / (60 * 60 *24));
ui->saveInBackgroundCheckBox->setChecked(rsFeedReader->getSaveInBackground());
ui->setMsgToReadOnActivate->setChecked(FeedReaderSetting_SetMsgToReadOnActivate()); ui->setMsgToReadOnActivate->setChecked(FeedReaderSetting_SetMsgToReadOnActivate());
ui->openAllInNewTabCheckBox->setChecked(FeedReaderSetting_OpenAllInNewTab()); ui->openAllInNewTabCheckBox->setChecked(FeedReaderSetting_OpenAllInNewTab());
@ -67,6 +68,7 @@ bool FeedReaderConfig::save(QString &/*errmsg*/)
rsFeedReader->setStandardUpdateInterval(ui->updateIntervalSpinBox->value() * 60); rsFeedReader->setStandardUpdateInterval(ui->updateIntervalSpinBox->value() * 60);
rsFeedReader->setStandardStorageTime(ui->storageTimeSpinBox->value() * 60 *60 * 24); rsFeedReader->setStandardStorageTime(ui->storageTimeSpinBox->value() * 60 *60 * 24);
rsFeedReader->setStandardProxy(ui->useProxyCheckBox->isChecked(), ui->proxyAddressLineEdit->text().toUtf8().constData(), ui->proxyPortSpinBox->value()); 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", "SetMsgToReadOnActivate", ui->setMsgToReadOnActivate->isChecked());
Settings->setValueToGroup("FeedReaderDialog", "OpenAllInNewTab", ui->openAllInNewTabCheckBox->isChecked()); Settings->setValueToGroup("FeedReaderDialog", "OpenAllInNewTab", ui->openAllInNewTabCheckBox->isChecked());

View File

@ -118,17 +118,24 @@
<string>Misc</string> <string>Misc</string>
</property> </property>
<layout class="QGridLayout" name="gridLayout_2"> <layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0"> <item row="2" column="0">
<widget class="QCheckBox" name="openAllInNewTabCheckBox">
<property name="text">
<string>Open all feeds in new tab</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QCheckBox" name="setMsgToReadOnActivate"> <widget class="QCheckBox" name="setMsgToReadOnActivate">
<property name="text"> <property name="text">
<string>Set message to read on activate</string> <string>Set message to read on activate</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="1" column="0"> <item row="0" column="0">
<widget class="QCheckBox" name="openAllInNewTabCheckBox"> <widget class="QCheckBox" name="saveInBackgroundCheckBox">
<property name="text"> <property name="text">
<string>Open all feeds in new tab</string> <string>Save configuration in background (for slow systems, more memory needed)</string>
</property> </property>
</widget> </widget>
</item> </item>
@ -150,6 +157,16 @@
</item> </item>
</layout> </layout>
</widget> </widget>
<tabstops>
<tabstop>updateIntervalSpinBox</tabstop>
<tabstop>storageTimeSpinBox</tabstop>
<tabstop>useProxyCheckBox</tabstop>
<tabstop>proxyAddressLineEdit</tabstop>
<tabstop>proxyPortSpinBox</tabstop>
<tabstop>saveInBackgroundCheckBox</tabstop>
<tabstop>setMsgToReadOnActivate</tabstop>
<tabstop>openAllInNewTabCheckBox</tabstop>
</tabstops>
<resources/> <resources/>
<connections/> <connections/>
</ui> </ui>

View File

@ -198,6 +198,8 @@ public:
virtual void setStandardUpdateInterval(uint32_t updateInterval) = 0; virtual void setStandardUpdateInterval(uint32_t updateInterval) = 0;
virtual bool getStandardProxy(std::string &proxyAddress, uint16_t &proxyPort) = 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 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 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; virtual RsFeedAddResult setFolder(const std::string &feedId, const std::string &name) = 0;

View File

@ -264,12 +264,17 @@
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../gui/FeedReaderConfig.ui" line="124"/> <location filename="../gui/FeedReaderConfig.ui" line="131"/>
<source>Set message to read on activate</source> <source>Set message to read on activate</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../gui/FeedReaderConfig.ui" line="131"/> <location filename="../gui/FeedReaderConfig.ui" line="138"/>
<source>Save configuration in background (for slow systems, more memory needed)</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../gui/FeedReaderConfig.ui" line="124"/>
<source>Open all feeds in new tab</source> <source>Open all feeds in new tab</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>

View File

@ -50,6 +50,7 @@ p3FeedReader::p3FeedReader(RsPluginHandler* pgHandler)
mStandardProxyPort = 0; mStandardProxyPort = 0;
mLastClean = 0; mLastClean = 0;
mNotify = NULL; mNotify = NULL;
mSaveInBackground = false;
mPreviewDownloadThread = NULL; mPreviewDownloadThread = NULL;
mPreviewProcessThread = 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() void p3FeedReader::stop()
{ {
{ {
@ -1344,11 +1362,15 @@ RsSerialiser *p3FeedReader::setupSerialiser()
return rss; return rss;
} }
bool p3FeedReader::saveList(bool &cleanup, std::list<RsItem *> & saveData) bool p3FeedReader::saveList(bool &cleanup, std::list<RsItem *> &saveData)
{ {
mFeedReaderMtx.lock(); /*********************** LOCK *******/ mFeedReaderMtx.lock(); /*********************** LOCK *******/
cleanup = false; if (mSaveInBackground) {
cleanup = true;
} else {
cleanup = false;
}
RsConfigKeyValueSet *rskv = new RsConfigKeyValueSet(); RsConfigKeyValueSet *rskv = new RsConfigKeyValueSet();
@ -1373,8 +1395,15 @@ bool p3FeedReader::saveList(bool &cleanup, std::list<RsItem *> & saveData)
rs_sprintf(kv.value, "%hu", mStandardProxyPort); rs_sprintf(kv.value, "%hu", mStandardProxyPort);
rskv->tlvkvs.pairs.push_back(kv); 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 */ /* Add KeyValue to saveList */
saveData.push_back(rskv); saveData.push_back(rskv);
if (!cleanup) {
cleanSaveData.push_back(rskv);
}
std::map<std::string, RsFeedReaderFeed *>::iterator it1; std::map<std::string, RsFeedReaderFeed *>::iterator it1;
for (it1 = mFeeds.begin(); it1 != mFeeds.end(); ++it1) { for (it1 = mFeeds.begin(); it1 != mFeeds.end(); ++it1) {
@ -1382,22 +1411,44 @@ bool p3FeedReader::saveList(bool &cleanup, std::list<RsItem *> & saveData)
if (fi->preview) { if (fi->preview) {
continue; continue;
} }
saveData.push_back(fi); if (cleanup) {
saveData.push_back(new RsFeedReaderFeed(*fi));
} else {
saveData.push_back(fi);
}
std::map<std::string, RsFeedReaderMsg*>::iterator it2; std::map<std::string, RsFeedReaderMsg*>::iterator it2;
for (it2 = fi->msgs.begin(); it2 != fi->msgs.end(); ++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! */ /* list completed! */
return true; return true;
} }
void p3FeedReader::saveDone() void p3FeedReader::saveDone()
{ {
mFeedReaderMtx.unlock(); /*********************** UNLOCK *******/ /* clean settings items */
return; std::list<RsItem*>::iterator it;
for (it = cleanSaveData.begin(); it != cleanSaveData.end(); ++it) {
delete(*it);
}
cleanSaveData.clear();
if (!mSaveInBackground) {
mFeedReaderMtx.unlock(); /*********************** UNLOCK *******/
}
} }
bool p3FeedReader::loadList(std::list<RsItem *>& load) bool p3FeedReader::loadList(std::list<RsItem *>& load)
@ -1466,6 +1517,11 @@ bool p3FeedReader::loadList(std::list<RsItem *>& load)
if (sscanf(kit->value.c_str(), "%hu", &value) == 1) { if (sscanf(kit->value.c_str(), "%hu", &value) == 1) {
mStandardProxyPort = value; 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 { } else {

View File

@ -45,6 +45,8 @@ public:
virtual void setStandardUpdateInterval(uint32_t updateInterval); virtual void setStandardUpdateInterval(uint32_t updateInterval);
virtual bool getStandardProxy(std::string &proxyAddress, uint16_t &proxyPort); virtual bool getStandardProxy(std::string &proxyAddress, uint16_t &proxyPort);
virtual void setStandardProxy(bool useProxy, const 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 addFolder(const std::string parentId, const std::string &name, std::string &feedId);
virtual RsFeedAddResult setFolder(const std::string &feedId, const std::string &name); virtual RsFeedAddResult setFolder(const std::string &feedId, const std::string &name);
@ -98,6 +100,8 @@ private:
RsFeedReaderNotify *mNotify; RsFeedReaderNotify *mNotify;
RsMutex mFeedReaderMtx; RsMutex mFeedReaderMtx;
std::list<RsItem*> cleanSaveData;
bool mSaveInBackground;
std::list<p3FeedReaderThread*> mThreads; std::list<p3FeedReaderThread*> mThreads;
uint32_t mNextFeedId; uint32_t mNextFeedId;
uint32_t mNextMsgId; uint32_t mNextMsgId;