- added history parameters for chat lobbies

- added max storage time for items in chat history. Avoids filling up the history with chat from volatile peers.
- worked out the layout in config->ChatPage in a more compact design and added help
- set the max size of chat messages to 6000 bytes instead of 2000 which was a bit too low
- default max number of lobby messages saved in each lobby is 20. Avoids flooding for peers who havn't configured it yet.



git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@6770 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2013-09-27 21:18:44 +00:00
parent f25f46dffb
commit e21d869006
11 changed files with 544 additions and 218 deletions

View File

@ -31,6 +31,10 @@
#include "serialiser/rsmsgitems.h"
#include "util/rsstring.h"
// clean too old messages every 5 minutes
//
#define MSG_HISTORY_CLEANING_PERIOD 300
RsHistory *rsHistory = NULL;
p3HistoryMgr::p3HistoryMgr()
@ -40,9 +44,14 @@ p3HistoryMgr::p3HistoryMgr()
mPublicEnable = false;
mPrivateEnable = true;
mLobbyEnable = true;
mPublicSaveCount = 0;
mPublicSaveCount = 0;
mLobbySaveCount = 0;
mPrivateSaveCount = 0;
mLastCleanTime = 0 ;
mMaxStorageDurationSeconds = 10*86400 ; // store for 10 days at most.
}
p3HistoryMgr::~p3HistoryMgr()
@ -55,6 +64,14 @@ void p3HistoryMgr::addMessage(bool incoming, const std::string &chatPeerId, cons
{
uint32_t addMsgId = 0;
time_t now = time(NULL) ;
if(mLastCleanTime + MSG_HISTORY_CLEANING_PERIOD < now)
{
cleanOldMessages() ;
mLastCleanTime = now ;
}
{
RsStackMutex stack(mHistoryMtx); /********** STACK LOCKED MTX ******/
@ -65,13 +82,15 @@ void p3HistoryMgr::addMessage(bool incoming, const std::string &chatPeerId, cons
const RsChatLobbyMsgItem *cli = dynamic_cast<const RsChatLobbyMsgItem*>(chatItem);
if (cli) {
// there is currently no setting for chat lobbies
} else {
if (mPrivateEnable == false && chatPeerId.empty() == false) {
// private chat not enabled
if (cli)
{
if (mLobbyEnable == false && !chatPeerId.empty()) // lobby chat not enabled
return;
}
else
{
if (mPrivateEnable == false && !chatPeerId.empty()) // private chat not enabled
return;
}
}
RsHistoryMsgItem* item = new RsHistoryMsgItem;
@ -97,16 +116,12 @@ void p3HistoryMgr::addMessage(bool incoming, const std::string &chatPeerId, cons
// check the limit
uint32_t limit;
if (chatPeerId.empty()) {
if (chatPeerId.empty())
limit = mPublicSaveCount;
} else {
if (cli) {
// there is currently no setting for chat lobbies
limit = 0;
} else {
limit = mPrivateSaveCount;
}
}
else if (cli)
limit = mLobbySaveCount;
else
limit = mPrivateSaveCount;
if (limit) {
while (mit->second.size() > limit) {
@ -132,6 +147,51 @@ void p3HistoryMgr::addMessage(bool incoming, const std::string &chatPeerId, cons
}
}
void p3HistoryMgr::cleanOldMessages()
{
RsStackMutex stack(mHistoryMtx); /********** STACK LOCKED MTX ******/
std::cerr << "****** cleaning old messages." << std::endl;
time_t now = time(NULL) ;
bool changed = false ;
for(std::map<std::string, std::map<uint32_t, RsHistoryMsgItem*> >::iterator mit = mMessages.begin(); mit != mMessages.end();)
{
for(std::map<uint32_t, RsHistoryMsgItem*>::iterator lit = mit->second.begin();lit!=mit->second.end();)
if(lit->second->recvTime + mMaxStorageDurationSeconds < now)
{
std::map<uint32_t, RsHistoryMsgItem*>::iterator lit2 = lit ;
++lit2 ;
std::cerr << " removing msg id " << lit->first << ", for peer id " << mit->first << std::endl;
delete lit->second ;
mit->second.erase(lit) ;
lit = lit2 ;
changed = true ;
}
else
++lit ;
if(mit->second.empty())
{
std::map<std::string, std::map<uint32_t, RsHistoryMsgItem*> >::iterator mit2 = mit ;
++mit2 ;
std::cerr << " removing peer id " << mit->first << ", since it has no messages" << std::endl;
mMessages.erase(mit) ;
mit = mit2 ;
changed = true ;
}
else
++mit ;
}
if(changed)
IndicateConfigChanged() ;
}
/***** p3Config *****/
RsSerialiser* p3HistoryMgr::setupSerialiser()
@ -170,6 +230,18 @@ bool p3HistoryMgr::saveList(bool& cleanup, std::list<RsItem*>& saveData)
kv.value = mPrivateEnable ? "TRUE" : "FALSE";
vitem->tlvkvs.pairs.push_back(kv);
kv.key = "LOBBY_ENABLE";
kv.value = mLobbyEnable ? "TRUE" : "FALSE";
vitem->tlvkvs.pairs.push_back(kv);
kv.key = "MAX_STORAGE_TIME";
rs_sprintf(kv.value,"%d",mMaxStorageDurationSeconds) ;
vitem->tlvkvs.pairs.push_back(kv);
kv.key = "LOBBY_SAVECOUNT";
rs_sprintf(kv.value, "%lu", mLobbySaveCount);
vitem->tlvkvs.pairs.push_back(kv);
kv.key = "PUBLIC_SAVECOUNT";
rs_sprintf(kv.value, "%lu", mPublicSaveCount);
vitem->tlvkvs.pairs.push_back(kv);
@ -207,8 +279,12 @@ bool p3HistoryMgr::loadList(std::list<RsItem*>& load)
for (it = load.begin(); it != load.end(); it++) {
if (NULL != (msgItem = dynamic_cast<RsHistoryMsgItem*>(*it))) {
std::map<std::string, std::map<uint32_t, RsHistoryMsgItem*> >::iterator mit = mMessages.find(msgItem->chatPeerId);
msgItem->msgId = nextMsgId++;
std::cerr << "Loading msg history item: peer id=" << msgItem->chatPeerId << "), msg id =" << msgItem->msgId << std::endl;
if (mit != mMessages.end()) {
mit->second.insert(std::make_pair(msgItem->msgId, msgItem));
} else {
@ -235,6 +311,20 @@ bool p3HistoryMgr::loadList(std::list<RsItem*>& load)
continue;
}
if (kit->key == "LOBBY_ENABLE") {
mLobbyEnable = (kit->value == "TRUE") ? true : false;
continue;
}
if (kit->key == "MAX_STORAGE_TIME") {
uint32_t val ;
if (sscanf(kit->value.c_str(), "%d", &val) == 1)
mMaxStorageDurationSeconds = val ;
std::cerr << "Loaded max storage time for history = " << val << " seconds" << std::endl;
continue;
}
if (kit->key == "PUBLIC_SAVECOUNT") {
mPublicSaveCount = atoi(kit->value.c_str());
continue;
@ -243,6 +333,10 @@ bool p3HistoryMgr::loadList(std::list<RsItem*>& load)
mPrivateSaveCount = atoi(kit->value.c_str());
continue;
}
if (kit->key == "LOBBY_SAVECOUNT") {
mLobbySaveCount = atoi(kit->value.c_str());
continue;
}
}
delete (*it);
@ -270,40 +364,35 @@ static void convertMsg(const RsHistoryMsgItem* item, HistoryMsg &msg)
msg.message = item->message;
}
//static void convertMsg(const HistoryMsg &msg, RsHistoryMsgItem* item)
//{
// item->msgId = msg.msgId;
// item->chatPeerId = msg.chatPeerId;
// item->incoming = msg.incoming;
// item->peerId = msg.peerId;
// item->peerName = msg.peerName;
// item->sendTime = msg.sendTime;
// item->recvTime = msg.recvTime;
// item->message = msg.message;
//}
bool p3HistoryMgr::getMessages(const std::string &chatPeerId, std::list<HistoryMsg> &msgs, uint32_t loadCount)
{
msgs.clear();
RsStackMutex stack(mHistoryMtx); /********** STACK LOCKED MTX ******/
if (mPublicEnable == false && chatPeerId.empty()) {
std::cerr << "Getting history for peer " << chatPeerId << std::endl;
if (mPublicEnable == false && chatPeerId.empty()) { // chatPeerId.empty() means it's public chat
// public chat not enabled
return false;
}
if (mPrivateEnable == false && chatPeerId.empty() == false) {
// private chat not enabled
if (mPrivateEnable == false && chatPeerId.empty() == false) // private chat not enabled
return false;
if (mLobbyEnable == false && chatPeerId.empty() == false) // private chat not enabled
return false;
}
uint32_t foundCount = 0;
std::map<std::string, std::map<uint32_t, RsHistoryMsgItem*> >::iterator mit = mMessages.find(chatPeerId);
if (mit != mMessages.end()) {
if (mit != mMessages.end())
{
std::map<uint32_t, RsHistoryMsgItem*>::reverse_iterator lit;
for (lit = mit->second.rbegin(); lit != mit->second.rend(); lit++) {
for (lit = mit->second.rbegin(); lit != mit->second.rend(); lit++)
{
HistoryMsg msg;
convertMsg(lit->second, msg);
msgs.insert(msgs.begin(), msg);
@ -313,6 +402,7 @@ bool p3HistoryMgr::getMessages(const std::string &chatPeerId, std::list<HistoryM
}
}
}
std::cerr << msgs.size() << " messages added." << std::endl;
return true;
}
@ -338,6 +428,8 @@ void p3HistoryMgr::clear(const std::string &chatPeerId)
{
RsStackMutex stack(mHistoryMtx); /********** STACK LOCKED MTX ******/
std::cerr << "********** p3History::clear()called for peer id " << chatPeerId << std::endl;
std::map<std::string, std::map<uint32_t, RsHistoryMsgItem*> >::iterator mit = mMessages.find(chatPeerId);
if (mit == mMessages.end()) {
return;
@ -362,6 +454,7 @@ void p3HistoryMgr::removeMessages(const std::list<uint32_t> &msgIds)
std::list<uint32_t> removedIds;
std::list<uint32_t>::iterator iit;
std::cerr << "********** p3History::removeMessages called()" << std::endl;
{
RsStackMutex stack(mHistoryMtx); /********** STACK LOCKED MTX ******/
@ -374,6 +467,7 @@ void p3HistoryMgr::removeMessages(const std::list<uint32_t> &msgIds)
delete(lit->second);
mit->second.erase(lit);
std::cerr << "**** Removing " << mit->first << " msg id = " << lit->first << std::endl;
removedIds.push_back(*iit);
iit = ids.erase(iit);
@ -398,46 +492,88 @@ void p3HistoryMgr::removeMessages(const std::list<uint32_t> &msgIds)
}
}
bool p3HistoryMgr::getEnable(bool ofPublic)
bool p3HistoryMgr::getEnable(uint32_t chat_type)
{
return ofPublic ? mPublicEnable : mPrivateEnable;
switch(chat_type)
{
case RS_HISTORY_TYPE_PUBLIC : return mPublicEnable ;
case RS_HISTORY_TYPE_LOBBY : return mLobbyEnable ;
case RS_HISTORY_TYPE_PRIVATE: return mPrivateEnable ;
default:
std::cerr << "Unexpected value " << chat_type<< " in p3HistoryMgr::getEnable(): this is a bug." << std::endl;
return 0 ;
}
}
void p3HistoryMgr::setEnable(bool forPublic, bool enable)
uint32_t p3HistoryMgr::getMaxStorageDuration()
{
return mMaxStorageDurationSeconds ;
}
void p3HistoryMgr::setMaxStorageDuration(uint32_t seconds)
{
if(mMaxStorageDurationSeconds != seconds)
IndicateConfigChanged() ;
mMaxStorageDurationSeconds = seconds ;
}
void p3HistoryMgr::setEnable(uint32_t chat_type, bool enable)
{
bool oldValue;
if (forPublic) {
oldValue = mPublicEnable;
mPublicEnable = enable;
} else {
oldValue = mPrivateEnable;
mPrivateEnable = enable;
switch(chat_type)
{
case RS_HISTORY_TYPE_PUBLIC : oldValue = mPublicEnable ;
mPublicEnable = enable ;
break ;
case RS_HISTORY_TYPE_LOBBY : oldValue = mLobbyEnable ;
mLobbyEnable = enable;
break ;
case RS_HISTORY_TYPE_PRIVATE: oldValue = mPrivateEnable ;
mPrivateEnable = enable ;
break ;
}
if (oldValue != enable) {
if (oldValue != enable)
IndicateConfigChanged();
}
uint32_t p3HistoryMgr::getSaveCount(uint32_t chat_type)
{
switch(chat_type)
{
case RS_HISTORY_TYPE_PUBLIC : return mPublicSaveCount ;
case RS_HISTORY_TYPE_LOBBY : return mLobbySaveCount ;
case RS_HISTORY_TYPE_PRIVATE: return mPrivateSaveCount ;
default:
std::cerr << "Unexpected value " << chat_type<< " in p3HistoryMgr::getSaveCount(): this is a bug." << std::endl;
return 0 ;
}
}
uint32_t p3HistoryMgr::getSaveCount(bool ofPublic)
{
return ofPublic ? mPublicSaveCount : mPrivateSaveCount;
}
void p3HistoryMgr::setSaveCount(bool forPublic, uint32_t count)
void p3HistoryMgr::setSaveCount(uint32_t chat_type, uint32_t count)
{
uint32_t oldValue;
if (forPublic) {
oldValue = mPublicSaveCount;
mPublicSaveCount = count;
} else {
oldValue = mPrivateSaveCount;
mPrivateSaveCount = count;
switch(chat_type)
{
case RS_HISTORY_TYPE_PUBLIC : oldValue = mPublicSaveCount ;
mPublicSaveCount = count ;
break ;
case RS_HISTORY_TYPE_LOBBY : oldValue = mLobbySaveCount ;
mLobbySaveCount = count;
break ;
case RS_HISTORY_TYPE_PRIVATE: oldValue = mPrivateSaveCount ;
mPrivateSaveCount = count ;
break ;
}
if (oldValue != count) {
if (oldValue != count)
IndicateConfigChanged();
}
}

View File

@ -56,10 +56,13 @@ public:
bool getMessage(uint32_t msgId, HistoryMsg &msg);
void clear(const std::string &chatPeerId);
void removeMessages(const std::list<uint32_t> &msgIds);
bool getEnable(bool ofPublic);
void setEnable(bool forPublic, bool enable);
uint32_t getSaveCount(bool ofPublic);
void setSaveCount(bool forPublic, uint32_t count);
virtual bool getEnable(uint32_t chat_type);
virtual void setEnable(uint32_t chat_type, bool enable);
virtual uint32_t getSaveCount(uint32_t chat_type);
virtual void setSaveCount(uint32_t chat_type, uint32_t count);
virtual void setMaxStorageDuration(uint32_t seconds) ;
virtual uint32_t getMaxStorageDuration() ;
/********* p3config ************/
@ -72,12 +75,22 @@ private:
uint32_t nextMsgId;
std::map<std::string, std::map<uint32_t, RsHistoryMsgItem*> > mMessages;
// Removes messages stored for more than mMaxMsgStorageDurationSeconds seconds.
// This avoids the stored list to grow crazy with time.
//
void cleanOldMessages() ;
bool mPublicEnable;
bool mLobbyEnable;
bool mPrivateEnable;
uint32_t mPublicSaveCount;
uint32_t mLobbySaveCount;
uint32_t mPrivateSaveCount;
uint32_t mMaxStorageDurationSeconds ;
time_t mLastCleanTime ;
std::list<RsItem*> saveCleanupList; /* TEMPORARY LIST WHEN SAVING */
RsMutex mHistoryMtx;

View File

@ -38,6 +38,10 @@ extern RsHistory *rsHistory;
/*!
* data object used for message history
*/
static const uint32_t RS_HISTORY_TYPE_PUBLIC = 0 ;
static const uint32_t RS_HISTORY_TYPE_PRIVATE = 1 ;
static const uint32_t RS_HISTORY_TYPE_LOBBY = 2 ;
class HistoryMsg
{
public:
@ -72,12 +76,14 @@ public:
virtual void removeMessages(const std::list<uint32_t> &msgIds) = 0;
virtual void clear(const std::string &chatPeerId) = 0;
virtual bool getEnable(bool ofPublic) = 0;
virtual void setEnable(bool forPublic, bool enable) = 0;
virtual bool getEnable(uint32_t chat_type) = 0;
virtual void setEnable(uint32_t chat_type, bool enable) = 0;
virtual uint32_t getMaxStorageDuration() = 0 ;
virtual void setMaxStorageDuration(uint32_t seconds) = 0 ;
// 0 = no limit, >0 count of saved messages
virtual uint32_t getSaveCount(bool ofPublic) = 0;
virtual void setSaveCount(bool forPublic, uint32_t count) = 0;
virtual uint32_t getSaveCount(uint32_t chat_type) = 0;
virtual void setSaveCount(uint32_t chat_type, uint32_t count) = 0;
};
#endif

View File

@ -36,6 +36,14 @@ p3History::~p3History()
{
}
void p3History::setMaxStorageDuration(uint32_t seconds)
{
mHistoryMgr->setMaxStorageDuration(seconds) ;
}
uint32_t p3History::getMaxStorageDuration()
{
return mHistoryMgr->getMaxStorageDuration() ;
}
bool p3History::getMessages(const std::string &chatPeerId, std::list<HistoryMsg> &msgs, const uint32_t loadCount)
{
return mHistoryMgr->getMessages(chatPeerId, msgs, loadCount);
@ -56,22 +64,22 @@ void p3History::clear(const std::string &chatPeerId)
mHistoryMgr->clear(chatPeerId);
}
bool p3History::getEnable(bool ofPublic)
bool p3History::getEnable(uint32_t chat_type)
{
return mHistoryMgr->getEnable(ofPublic);
return mHistoryMgr->getEnable(chat_type);
}
void p3History::setEnable(bool forPublic, bool enable)
void p3History::setEnable(uint32_t chat_type, bool enable)
{
mHistoryMgr->setEnable(forPublic, enable);
mHistoryMgr->setEnable(chat_type, enable);
}
uint32_t p3History::getSaveCount(bool ofPublic)
uint32_t p3History::getSaveCount(uint32_t chat_type)
{
return mHistoryMgr->getSaveCount(ofPublic);
return mHistoryMgr->getSaveCount(chat_type);
}
void p3History::setSaveCount(bool forPublic, uint32_t count)
void p3History::setSaveCount(uint32_t chat_type, uint32_t count)
{
mHistoryMgr->setSaveCount(forPublic, count);
mHistoryMgr->setSaveCount(chat_type, count);
}

View File

@ -45,10 +45,12 @@ public:
virtual bool getMessage(uint32_t msgId, HistoryMsg &msg);
virtual void removeMessages(const std::list<uint32_t> &msgIds);
virtual void clear(const std::string &chatPeerId);
virtual bool getEnable(bool ofPublic);
virtual void setEnable(bool forPublic, bool enable);
virtual uint32_t getSaveCount(bool ofPublic);
virtual void setSaveCount(bool forPublic, uint32_t count);
virtual bool getEnable(uint32_t chat_type);
virtual void setEnable(uint32_t chat_type, bool enable);
virtual uint32_t getSaveCount(uint32_t chat_type);
virtual void setSaveCount(uint32_t chat_type, uint32_t count);
virtual void setMaxStorageDuration(uint32_t seconds) ;
virtual uint32_t getMaxStorageDuration() ;
private:
p3HistoryMgr* mHistoryMgr;

View File

@ -1151,12 +1151,12 @@ void p3ChatService::handleRecvChatAvatarItem(RsChatAvatarItem *ca)
bool p3ChatService::checkForMessageSecurity(RsChatMsgItem *ci)
{
// Remove too big messages
if (ci->message.length() > 2000 && (ci->chatFlags & RS_CHAT_FLAG_LOBBY))
if (ci->message.length() > 6000 && (ci->chatFlags & RS_CHAT_FLAG_LOBBY))
{
wchar_t tmp[300];
mbstowcs(tmp, rsPeers->getPeerName(ci->PeerId()).c_str(), 299);
ci->message = std::wstring(L"**** Security warning: Message bigger than 2000 characters, coming from id ") + tmp + L", dropped. ****";
ci->message = std::wstring(L"**** Security warning: Message bigger than 6000 characters, forwarded to you by ") + tmp + L", dropped. ****";
return false;
}
@ -2892,7 +2892,7 @@ void p3ChatService::unsubscribeChatLobby(const ChatLobbyId& id)
// remove history
mHistoryMgr->clear(it->second.virtual_peer_id);
//mHistoryMgr->clear(it->second.virtual_peer_id);
// remove lobby information

View File

@ -202,17 +202,21 @@ void ChatWidget::init(const std::string &peerId, const QString &title)
updateTitle();
}
if (rsHistory->getEnable(false)) {
uint32_t hist_chat_type = isChatLobby?RS_HISTORY_TYPE_LOBBY:RS_HISTORY_TYPE_PRIVATE ;
int messageCount = isChatLobby?(Settings->getLobbyChatHistoryCount()):(Settings->getPrivateChatHistoryCount());
if (rsHistory->getEnable(hist_chat_type))
{
// get chat messages from history
std::list<HistoryMsg> historyMsgs;
int messageCount = Settings->getPrivateChatHistoryCount();
if (messageCount > 0) {
if (messageCount > 0)
{
rsHistory->getMessages(peerId, historyMsgs, messageCount);
std::list<HistoryMsg>::iterator historyIt;
for (historyIt = historyMsgs.begin(); historyIt != historyMsgs.end(); historyIt++) {
for (historyIt = historyMsgs.begin(); historyIt != historyMsgs.end(); historyIt++)
addChatMsg(historyIt->incoming, QString::fromUtf8(historyIt->peerName.c_str()), QDateTime::fromTime_t(historyIt->sendTime), QDateTime::fromTime_t(historyIt->recvTime), QString::fromUtf8(historyIt->message.c_str()), TYPE_HISTORY);
}
}
}

View File

@ -266,12 +266,15 @@ ChatPage::save(QString &/*errmsg*/)
Settings->setPublicChatHistoryCount(ui.publicChatLoadCount->value());
Settings->setPrivateChatHistoryCount(ui.privateChatLoadCount->value());
Settings->setLobbyChatHistoryCount(ui.lobbyChatLoadCount->value());
rsHistory->setEnable(true, ui.publicChatEnable->isChecked());
rsHistory->setEnable(false, ui.privateChatEnable->isChecked());
rsHistory->setEnable(RS_HISTORY_TYPE_PUBLIC , ui.publicChatEnable->isChecked());
rsHistory->setEnable(RS_HISTORY_TYPE_PRIVATE, ui.privateChatEnable->isChecked());
rsHistory->setEnable(RS_HISTORY_TYPE_LOBBY , ui.lobbyChatEnable->isChecked());
rsHistory->setSaveCount(true, ui.publicChatSaveCount->value());
rsHistory->setSaveCount(false, ui.privateChatSaveCount->value());
rsHistory->setSaveCount(RS_HISTORY_TYPE_PUBLIC , ui.publicChatSaveCount->value());
rsHistory->setSaveCount(RS_HISTORY_TYPE_PRIVATE, ui.privateChatSaveCount->value());
rsHistory->setSaveCount(RS_HISTORY_TYPE_LOBBY , ui.lobbyChatSaveCount->value());
rsMsgs->setDefaultNickNameForChatLobby(ui.chatLobbyNick_LE->text().toUtf8().constData()) ;
@ -303,6 +306,8 @@ ChatPage::save(QString &/*errmsg*/)
}
}
rsHistory->setMaxStorageDuration(ui.max_storage_period->value() * 86400) ;
uint chatflags = 0;
if (ui.chat_NewWindow->isChecked())
@ -346,16 +351,21 @@ ChatPage::load()
ui.publicChatLoadCount->setValue(Settings->getPublicChatHistoryCount());
ui.privateChatLoadCount->setValue(Settings->getPrivateChatHistoryCount());
ui.lobbyChatLoadCount->setValue(Settings->getLobbyChatHistoryCount());
ui.publicChatEnable->setChecked(rsHistory->getEnable(true));
ui.privateChatEnable->setChecked(rsHistory->getEnable(false));
ui.publicChatEnable->setChecked(rsHistory->getEnable(RS_HISTORY_TYPE_PUBLIC));
ui.privateChatEnable->setChecked(rsHistory->getEnable(RS_HISTORY_TYPE_PRIVATE));
ui.lobbyChatEnable->setChecked(rsHistory->getEnable(RS_HISTORY_TYPE_LOBBY));
ui.publicChatSaveCount->setValue(rsHistory->getSaveCount(true));
ui.privateChatSaveCount->setValue(rsHistory->getSaveCount(false));
ui.publicChatSaveCount->setValue(rsHistory->getSaveCount(RS_HISTORY_TYPE_PUBLIC));
ui.privateChatSaveCount->setValue(rsHistory->getSaveCount(RS_HISTORY_TYPE_PRIVATE));
ui.lobbyChatSaveCount->setValue(rsHistory->getSaveCount(RS_HISTORY_TYPE_LOBBY));
ui.labelChatFontPreview->setText(fontTempChat.rawName());
ui.labelChatFontPreview->setFont(fontTempChat);
ui.max_storage_period->setValue(rsHistory->getMaxStorageDuration()/86400) ;
/* Load styles */
publicStylePath = loadStyleInfo(ChatStyle::TYPE_PUBLIC, ui.publicList, ui.publicComboBoxVariant, publicStyleVariant);
privateStylePath = loadStyleInfo(ChatStyle::TYPE_PRIVATE, ui.privateList, ui.privateComboBoxVariant, privateStyleVariant);

View File

@ -6,15 +6,15 @@
<rect>
<x>0</x>
<y>0</y>
<width>646</width>
<height>412</height>
<width>606</width>
<height>477</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<item row="3" column="0">
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
<number>0</number>
<number>2</number>
</property>
<widget class="QWidget" name="general">
<attribute name="title">
@ -420,65 +420,267 @@
</attribute>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QGroupBox" name="publicChat">
<property name="title">
<string>Group Chat</string>
<widget class="QLabel" name="label_8">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<layout class="QGridLayout" name="gridLayout_3">
<item row="0" column="0">
<widget class="QCheckBox" name="publicChatEnable">
<property name="text">
<string>Enable</string>
</property>
</widget>
</item>
<item row="1" column="0">
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="label1">
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p align=&quot;justify&quot;&gt;In this tab you can setup how many chat messages Retroshare will keep saved on the disc and how much of the previous conversation it will display, for the different chat systems. The max storage period allows to discard old messages and prevents the chat history from filling up with volatile chat (e.g. chat lobbies and distant chat).&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="textFormat">
<enum>Qt::RichText</enum>
</property>
<property name="scaledContents">
<bool>true</bool>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_6">
<item>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="1">
<widget class="QLabel" name="label_4">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Group chat</string>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QLabel" name="label_5">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Private chat</string>
</property>
</widget>
</item>
<item row="0" column="3">
<widget class="QLabel" name="label_6">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Chatlobbies</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_7">
<property name="layoutDirection">
<enum>Qt::LeftToRight</enum>
</property>
<property name="text">
<string>Enabled:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QCheckBox" name="publicChatEnable">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QCheckBox" name="privateChatEnable">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="1" column="3">
<widget class="QCheckBox" name="lobbyChatEnable">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label1">
<property name="text">
<string>Saved messages (0 = unlimited):</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QSpinBox" name="publicChatSaveCount">
<property name="maximumSize">
<size>
<width>60</width>
<height>16777215</height>
</size>
</property>
<property name="suffix">
<string/>
</property>
<property name="prefix">
<string/>
</property>
<property name="maximum">
<number>1000000000</number>
</property>
</widget>
</item>
<item row="2" column="2">
<widget class="QSpinBox" name="privateChatSaveCount">
<property name="maximumSize">
<size>
<width>60</width>
<height>16777215</height>
</size>
</property>
<property name="suffix">
<string/>
</property>
<property name="prefix">
<string/>
</property>
<property name="maximum">
<number>1000000000</number>
</property>
</widget>
</item>
<item row="2" column="3">
<widget class="QSpinBox" name="lobbyChatSaveCount">
<property name="maximumSize">
<size>
<width>60</width>
<height>16777215</height>
</size>
</property>
<property name="suffix">
<string/>
</property>
<property name="prefix">
<string/>
</property>
<property name="maximum">
<number>1000000000</number>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label2">
<property name="text">
<string>Number of messages restored (0 = off):</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QSpinBox" name="publicChatLoadCount">
<property name="maximumSize">
<size>
<width>60</width>
<height>16777215</height>
</size>
</property>
<property name="maximum">
<number>20</number>
</property>
</widget>
</item>
<item row="3" column="2">
<widget class="QSpinBox" name="privateChatLoadCount">
<property name="maximumSize">
<size>
<width>60</width>
<height>16777215</height>
</size>
</property>
<property name="maximum">
<number>20</number>
</property>
</widget>
</item>
<item row="3" column="3">
<widget class="QSpinBox" name="lobbyChatLoadCount">
<property name="maximumSize">
<size>
<width>60</width>
<height>16777215</height>
</size>
</property>
<property name="maximum">
<number>20</number>
</property>
</widget>
</item>
</layout>
</item>
<item>
<spacer name="horizontalSpacer_4">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<widget class="QGroupBox" name="groupBox_5">
<property name="title">
<string>General</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_8">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<widget class="QLabel" name="label_3">
<property name="text">
<string>Number of saved messages (0 = unlimited)</string>
<string>Maximum storage period, in days:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QSpinBox" name="publicChatSaveCount">
<property name="maximumSize">
<item>
<widget class="QSpinBox" name="max_storage_period"/>
</item>
<item>
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>60</width>
<height>16777215</height>
<width>40</width>
<height>20</height>
</size>
</property>
<property name="suffix">
<string/>
</property>
<property name="prefix">
<string/>
</property>
<property name="maximum">
<number>1000000000</number>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QSpinBox" name="publicChatLoadCount">
<property name="maximumSize">
<size>
<width>60</width>
<height>16777215</height>
</size>
</property>
<property name="maximum">
<number>20</number>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label2">
<property name="text">
<string>Load number of messages (0 = off)</string>
</property>
</widget>
</spacer>
</item>
</layout>
</item>
@ -486,80 +688,14 @@
</widget>
</item>
<item>
<widget class="QGroupBox" name="privateChat">
<property name="title">
<string>Private Chat</string>
</property>
<layout class="QGridLayout" name="gridLayout_5">
<item row="0" column="0">
<widget class="QCheckBox" name="privateChatEnable">
<property name="text">
<string>Enable</string>
</property>
</widget>
</item>
<item row="1" column="0">
<layout class="QGridLayout" name="gridLayout_6">
<item row="0" column="0">
<widget class="QLabel" name="label3">
<property name="text">
<string>Number of saved messages (0 = unlimited)</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QSpinBox" name="privateChatSaveCount">
<property name="maximumSize">
<size>
<width>60</width>
<height>16777215</height>
</size>
</property>
<property name="suffix">
<string/>
</property>
<property name="prefix">
<string/>
</property>
<property name="maximum">
<number>1000000000</number>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QSpinBox" name="privateChatLoadCount">
<property name="maximumSize">
<size>
<width>60</width>
<height>16777215</height>
</size>
</property>
<property name="maximum">
<number>20</number>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label4">
<property name="text">
<string>Load number of messages (0 = off)</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer_3">
<spacer name="verticalSpacer_4">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>176</width>
<height>480</height>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>

View File

@ -462,7 +462,15 @@ void RshareSettings::setHistoryChatStyle(const QString &stylePath, const QString
setValueToGroup("Chat", "StyleHistory", stylePath);
setValueToGroup("Chat", "StylePrivateVariant", styleVariant);
}
int RshareSettings::getLobbyChatHistoryCount()
{
return valueFromGroup("Chat", "LobbyChatHistoryCount", 0).toInt();
}
void RshareSettings::setLobbyChatHistoryCount(int value)
{
setValueToGroup("Chat", "LobbyChatHistoryCount", value);
}
int RshareSettings::getPublicChatHistoryCount()
{
return valueFromGroup("Chat", "PublicChatHistoryCount", 0).toInt();

View File

@ -216,6 +216,9 @@ public:
int getPrivateChatHistoryCount();
void setPrivateChatHistoryCount(int value);
int getLobbyChatHistoryCount();
void setLobbyChatHistoryCount(int value);
//! Save placement, state and size information of a window.
void saveWidgetInformation(QWidget *widget);