void History::updateSMSState(int callId, HistoryMemento::State state) { HistoryMemento * memento = _collection->getMementoBySMSId(callId); if (memento) { memento->updateState(state); unsigned id = _collection->getMementoId(memento); mementoUpdatedEvent(*this, id); } }
void History::updateCallDuration(int callId, int duration) { HistoryMemento * memento = _collection->getMementoByCallId(callId); if (memento) { memento->updateDuration(duration); unsigned id = _collection->getMementoId(memento); mementoUpdatedEvent(*this, id); } }
void QtHistory::replayItem(int id) { if (id != 0){ HistoryMementoCollection * collection = _cHistory.getHistory().getHistoryMementoCollection(); HistoryMemento* memento = collection->getMemento(id); QString data = QString::fromStdString(memento->getData()); QtWengoPhone * qtWengoPhone = (QtWengoPhone *) _cHistory.getCWengoPhone().getPresentation(); //VOXOX - CJC - 2009.06.10 QtVoxMessageBox box(_historyWidget->getWidget()); box.setWindowTitle("VoxOx - Call History"); box.setText(tr("Do you want to call %1?").arg(formatName(memento->getPeer(), _isWengoAccountConnected))); box.setStandardButtons(QMessageBox::Yes | QMessageBox::No ); /*QMessageBox mb(tr("@product@ - Call History"), tr("Do you want to call %1?").arg(formatName(memento->getPeer(), _isWengoAccountConnected)), QMessageBox::Question, QMessageBox::Yes | QMessageBox::Default, QMessageBox::No | QMessageBox::Escape, QMessageBox::NoButton, _historyWidget->getWidget());*/ switch (memento->getState()) { case HistoryMemento::OutgoingSmsOk: case HistoryMemento::OutgoingSmsNok: { //Retrieve info & configure the Sms widget std::string data = _cHistory.getMementoData(id); QString text = QString::fromUtf8(data.c_str(), data.size()); QString phoneNumber = QString::fromStdString(_cHistory.getMementoPeer(id)); //Test existance of Sms (available only if a WengoAccount has been created) QtSms * sms = qtWengoPhone->getQtSms(); if (sms) { sms->setText(text); sms->setPhoneNumber(phoneNumber); sms->getWidget()->show(); } break; } case HistoryMemento::OutgoingCall: case HistoryMemento::IncomingCall: case HistoryMemento::MissedCall: case HistoryMemento::RejectedCall: if (box.exec() == QMessageBox::Yes) { _cHistory.replay(id); } break; case HistoryMemento::ChatSession: _chatLogViewer = new QtChatLogViewer(NULL, *qtWengoPhone, data ); _chatLogViewer->restartChat(); break; default: break; } } }
void QtVoxOxCallBarFrame::fillComboBox() { QStringList tobeinserted = QStringList(); clearComboBox(); //CUserProfile * cUserProfile = // _qtWengoPhone->getCWengoPhone().getCUserProfileHandler().getCUserProfile(); if (!_cUserProfile) { return; } //completion of history //if _qtHistoryWidget is set it means that History has been created bool isWengoAccountConnected = _cUserProfile->getUserProfile().hasWengoAccount(); CHistory* chistory = _cUserProfile->getCHistory(); if (chistory) { HistoryMementoCollection * mementos = chistory->getMementos(HistoryMemento::OutgoingCall, 10); Config & config = ConfigManager::getInstance().getCurrentConfig(); QString wengoSuffix = "@" + QString::fromStdString( config.getWengoRealm() ); for (HistoryMap::iterator it = mementos->begin(); it != mementos->end(); it++) { HistoryMemento * memento = (*it).second; SipAddress sipAddress(memento->getPeer()); QString username(sipAddress.getSipAddress().c_str()); if (isWengoAccountConnected) { username.remove(wengoSuffix); } username.remove("sip:"); if( !username.isEmpty() && (memento->getState()==HistoryMemento::OutgoingCall) && !tobeinserted.contains(username) ) { tobeinserted << username; } } OWSAFE_DELETE(mementos); } //// tobeinserted.sort(); QStringList::const_iterator constIterator; for (constIterator = tobeinserted.constBegin(); constIterator != tobeinserted.constEnd();++constIterator){ addComboBoxItem(*constIterator); } if(tobeinserted.count() > 0){ if(_ui->callBarComboBox->findText(CLEAR_RECENT_CALLS_MESSAGE) == -1){ _ui->callBarComboBox->insertItem (_ui->callBarComboBox->count(), CLEAR_RECENT_CALLS_MESSAGE ); } } clearComboBoxEditText(); }
void QtHistory::showChatLog(int id) { if (id != 0){ HistoryMementoCollection * collection = _cHistory.getHistory().getHistoryMementoCollection(); HistoryMemento* memento = collection->getMemento(id); QtWengoPhone * qtWengoPhone = (QtWengoPhone *) _cHistory.getCWengoPhone().getPresentation(); if(memento->getState() == HistoryMemento::ChatSession){ _chatLogViewer = new QtChatLogViewer(NULL, *qtWengoPhone, QString::fromStdString(memento->getData())); _chatLogViewer->show(); } } }
void History::updateCallState(int callId, HistoryMemento::State state) { HistoryMemento * memento = _collection->getMementoByCallId(callId); if (memento) { memento->updateState(state); unsigned id = _collection->getMementoId(memento); mementoUpdatedEvent(*this, id); if (state == HistoryMemento::MissedCall) { _missedCallCount++; unseenMissedCallsChangedEvent(*this, _missedCallCount); } } }
void QtHistory::updatePresentation() { reset(); _mementoIdList.clear(); HistoryMementoCollection * collection = _cHistory.getHistory().getHistoryMementoCollection(); for (HistoryMap::iterator it = collection->begin(); it != collection->end(); it++) { HistoryMemento * memento = (*it).second; if ((memento->getState() == _stateFilter) || (_stateFilter == HistoryMemento::Any)) { _mementoIdList << it->first; } } HistoryMementoSorter sorter(collection); qSort(_mementoIdList.begin(), _mementoIdList.end(), sorter); }
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(); }
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; } }
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; }