Пример #1
0
bool History::loadChatLog(std::string chatlog, HistoryMementoCollection * hmc, std::string * userlogin, StringList * cuuidList) {

	// complete filename
	Config & config = ConfigManager::getInstance().getCurrentConfig();
	std::string filename = File::convertPathSeparators( 
		config.getConfigDir() + "chatlogs" + File::getPathSeparator() 
		+ _userProfile.getName() + File::getPathSeparator()
		+ chatlog + ".xml"
	);
	////

	//open and read chat log
	FileReader file( filename );
	if(!file.open()) {
		return false;
	}
	std::string lu = file.read();
	std::stringstream ss(lu);
	boost::archive::xml_iarchive ia(ss);
	////

	// contact
	int nbcontact = 0;
	ia >> BOOST_SERIALIZATION_NVP(nbcontact);
	for( int ic = 0; ic < nbcontact; ++ic) {
		std::string cuuid;
		ia >> BOOST_SERIALIZATION_NVP(cuuid);
		cuuidList->push_back(cuuid);
	}

	//user login
	ia >> BOOST_SERIALIZATION_NVP(*userlogin);

	//number of message
	int size = 0;
	ia >> BOOST_SERIALIZATION_NVP(size);

	//load every message
	std::string date, peer, data;
	for(int i = 0; i < size; ++i) {

		//
		//	more compact serialization
		//
		//ia >> BOOST_SERIALIZATION_NVP(date);
		//ia >> BOOST_SERIALIZATION_NVP(peer);
		//ia >> BOOST_SERIALIZATION_NVP(data);

		//Date fdate(	String(date.substr(8,2)).toInteger(), 
		//			String(date.substr(5,2)).toInteger(), 
		//			String(date.substr(0,4)).toInteger());

		//Time ftime(	String(date.substr(11,2)).toInteger(), 
		//			String(date.substr(14,2)).toInteger(), 
		//			String(date.substr(17,4)).toInteger());

		//HistoryMemento* hm = new HistoryMemento(HistoryMemento::ChatSession, fdate, ftime, peer, -1, data);

		HistoryMemento* hm = new HistoryMemento();
		hm->load(ia,HistoryMemento::SERIALIZATION_VERSION);

		/** duration -1 means it is an history message */
		hm->updateDuration(-1);

		hmc->addMemento(hm);
	}
	return true;
}