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->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());

View File

@ -118,17 +118,24 @@
<string>Misc</string>
</property>
<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">
<property name="text">
<string>Set message to read on activate</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QCheckBox" name="openAllInNewTabCheckBox">
<item row="0" column="0">
<widget class="QCheckBox" name="saveInBackgroundCheckBox">
<property name="text">
<string>Open all feeds in new tab</string>
<string>Save configuration in background (for slow systems, more memory needed)</string>
</property>
</widget>
</item>
@ -150,6 +157,16 @@
</item>
</layout>
</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/>
<connections/>
</ui>

View File

@ -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;

View File

@ -264,12 +264,17 @@
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../gui/FeedReaderConfig.ui" line="124"/>
<location filename="../gui/FeedReaderConfig.ui" line="131"/>
<source>Set message to read on activate</source>
<translation type="unfinished"></translation>
</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>
<translation type="unfinished"></translation>
</message>

View File

@ -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()
{
{
@ -1348,7 +1366,11 @@ bool p3FeedReader::saveList(bool &cleanup, std::list<RsItem *> & saveData)
{
mFeedReaderMtx.lock(); /*********************** LOCK *******/
if (mSaveInBackground) {
cleanup = true;
} else {
cleanup = false;
}
RsConfigKeyValueSet *rskv = new RsConfigKeyValueSet();
@ -1373,8 +1395,15 @@ bool p3FeedReader::saveList(bool &cleanup, std::list<RsItem *> & 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<std::string, RsFeedReaderFeed *>::iterator it1;
for (it1 = mFeeds.begin(); it1 != mFeeds.end(); ++it1) {
@ -1382,13 +1411,27 @@ bool p3FeedReader::saveList(bool &cleanup, std::list<RsItem *> & saveData)
if (fi->preview) {
continue;
}
if (cleanup) {
saveData.push_back(new RsFeedReaderFeed(*fi));
} else {
saveData.push_back(fi);
}
std::map<std::string, RsFeedReaderMsg*>::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;
@ -1396,8 +1439,16 @@ bool p3FeedReader::saveList(bool &cleanup, std::list<RsItem *> & saveData)
void p3FeedReader::saveDone()
{
/* clean settings items */
std::list<RsItem*>::iterator it;
for (it = cleanSaveData.begin(); it != cleanSaveData.end(); ++it) {
delete(*it);
}
cleanSaveData.clear();
if (!mSaveInBackground) {
mFeedReaderMtx.unlock(); /*********************** UNLOCK *******/
return;
}
}
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) {
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 {

View File

@ -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<RsItem*> cleanSaveData;
bool mSaveInBackground;
std::list<p3FeedReaderThread*> mThreads;
uint32_t mNextFeedId;
uint32_t mNextMsgId;