Exemple #1
0
QVariant QtHistory::data(const QModelIndex& index, int role) const {
	if (index.row() < 0 || index.row() >= _mementoIdList.size()) {
		return QVariant();
	}
	int id = _mementoIdList[index.row()];
	HistoryMementoCollection * collection = _cHistory.getHistory().getHistoryMementoCollection();
	HistoryMemento* memento = collection->getMemento(id);
	if (!memento) {
		LOG_ERROR("Couldn't get memento for id " + String::fromNumber(id));
		return QVariant();
	}

	if (role == Qt::DisplayRole) {
		switch (index.column()) {
		case 0:
			return textForMementoState(memento->getState());

		case 1:
			return QVariant(formatName(memento->getPeer(), _isWengoAccountConnected));

		case 2:
			return QVariant(formatDate(qDateTimeForMemento(memento)));
		case 3:
			//VOXOX - CJC - 2009.05.31 Only show duration for calls
			if(memento->getState() == HistoryMemento::OutgoingCall || memento->getState()== HistoryMemento::IncomingCall
				||memento->getState() == HistoryMemento::MissedCall || memento->getState() == HistoryMemento::RejectedCall){
					return QVariant(formatDuration(qTimeForDuration(memento->getDuration())));
				}else{
					return QVariant("");
			}

		default:
			return QVariant();
		}
	} else if (role == Qt::DecorationRole) {
		if (index.column() == 0) {
			return QVariant(iconForMementoState(memento->getState()));
		} else {
			return QVariant();
		}
	} else if (role == Qt::UserRole) {
		return QVariant(id);
	}
	return QVariant();
}
Exemple #2
0
void History::removeChatMementoSession(IMChatSession * imchatSession) {
	int chatSessionID = imchatSession->getId();

	HistoryMementoCollection * collection = NULL;
	if((collection = _chatSessionsMementos[chatSessionID]) != NULL){
		//seek for history chat
		int nbhistory = 0;
		HistoryMap::iterator ithm;
		for (ithm = collection->begin(); ithm != collection->end(); ++ithm) {
			HistoryMemento* hm = ithm->second;

			// duration -1 means it is an history message
			if( hm->getDuration() != -1 ) {
				break;
			}
			++nbhistory;
		}
		////

		// don't save empty chat history
		int size = collection->size() - nbhistory;
		if(size>0) {
			//save chat log
			Date saveDate;
			Time saveTime;
			std::string peer = "";
			std::string filechat =	String::fromNumber(saveDate.getYear(), 2) + String::fromNumber(saveDate.getMonth(), 2) + 
									String::fromNumber(saveDate.getDay(), 2) + String::fromNumber(saveTime.getHour(), 2) + 
									String::fromNumber(saveTime.getMinute(), 2) + String::fromNumber(saveTime.getSecond(), 2)+
									"_" + String::fromNumber(chatSessionID);
			Config & config = ConfigManager::getInstance().getCurrentConfig();
			std::string saverep = File::convertPathSeparators( 
				config.getConfigDir() + "chatlogs" + File::getPathSeparator() 
				+ _userProfile.getName() + File::getPathSeparator() 
			);
			File::createPath(saverep);
			//save file should be unique
			while(File::exists(saverep + filechat + ".xml")) {
				filechat += "_f";
			}
			////
			FileWriter file(saverep + filechat+".xml");
			std::stringstream ss;
			bool serializedSuccessfully = false;
			try {
				boost::archive::xml_oarchive oa(ss);

				//constructs list of login per peer
				std::map<std::string, std::vector<std::string>*> aliasMap;
				IMContactSet contactSet = imchatSession->getIMContactSet();
				for (IMContactSet::const_iterator itc = contactSet.begin(); itc != contactSet.end(); ++itc) {
					Contact * thecontact = _userProfile.getContactList().findContactThatOwns(*itc);
					std::string cuuid = "unrecognized";
					if(thecontact) {
//						cuuid = thecontact->getUUID();
						cuuid = thecontact->getKey();	//VOXOX - JRT - 2009.04.28 
					}	

					if(aliasMap[cuuid] == NULL) {
						aliasMap[cuuid] = new std::vector<std::string>;
					}
//					aliasMap[cuuid]->push_back(itc->cleanContactId());	//VOXOX - JRT - 2009.04.10 
					aliasMap[cuuid]->push_back(itc->getCleanContactId());
				}
				////

				// saves number of peer in this chat
				int nbcontact = aliasMap.size();
				oa << BOOST_SERIALIZATION_NVP(nbcontact);
				////

				//links all peers to this chat
				for(std::map<std::string, std::vector<std::string>*>::const_iterator itam = aliasMap.begin();
					itam != aliasMap.end(); ++itam) {
				
					/** links peer -> chat */

					//filechat
					std::string tobewritten = "<chat>\n\t<id>"+filechat+"</id>\n";

					//different login used by this peer during this chat
					for(std::vector<std::string>::const_iterator itv = itam->second->begin(); itv != itam->second->end(); ++itv) {
						tobewritten += "\t<alias>" + (*itv) + "</alias>\n";
						
						peer += "," + (*itv);
					}
					
					////

					tobewritten += "</chat>\n";
					/////
	
					std::string cuuid = itam->first;
					FileWriter contactFile( saverep + cuuid + ".xml" );
					contactFile.setAppendMode(true);
					contactFile.write(tobewritten);

					/** links chat -> peer */
					oa << BOOST_SERIALIZATION_NVP(cuuid);
				}
				////

				// saves user login for this chat
				IMAccount * imAccount =
					_userProfile.getIMAccountManager().getIMAccount(imchatSession->getIMChat().getIMAccountId());
				std::string userlogin;
				if (imAccount) {
					userlogin = imAccount->getLogin();
					OWSAFE_DELETE(imAccount);
				} else {
					LOG_ERROR("cannot find the IMAccount");
				}
				oa << BOOST_SERIALIZATION_NVP(userlogin);
				////

				// saves size
				oa << BOOST_SERIALIZATION_NVP(size);

				// save all historymementos i.e. all message
				for (;ithm != collection->end(); ++ithm) {
					HistoryMemento* hm = ithm->second;

					//
					//	more compact serialization
					//
					//std::string date = hm->getDate().toString() + " " + hm->getTime().toString();
					//oa << BOOST_SERIALIZATION_NVP(date);
					//std::string peer = hm->getPeer();
					//oa << BOOST_SERIALIZATION_NVP(peer);
					//std::string data = hm->getData();
					//oa << BOOST_SERIALIZATION_NVP(data);

					hm->save(oa,HistoryMemento::SERIALIZATION_VERSION);

				}
				serializedSuccessfully = true;
			} catch (boost::archive::archive_exception & e) {
				LOG_DEBUG(e.what());
				file.write(String::null);
			}

			if (serializedSuccessfully) {
				// xml_oarchive write the end of the xml in its destructor.
				// This is why we do not write inside the try {} catch block
				// because we would write before the xml_oarchive object is
				// deleted.
				file.write(ss.str());
			}
			
			if (peer.size() > 1) {
				peer = peer.substr(1);
			}
			
			HistoryMemento * historyMemento = new HistoryMemento(HistoryMemento::ChatSession, saveDate, saveTime, peer, -1, filechat);
			historyMemento->updateDuration(0);
			_userProfile.getHistory().addMemento(historyMemento);
		}
		_chatSessionsMementos.erase(chatSessionID);
		delete collection;
	}
}