int ParserKopete::parserLogsAux(QString prot){ QString dir; QString tmp; QDir directory; QString account; QString protocol; QString home = QDir::homePath(); QFile file; QDomDocument doc; dir.append(home); dir.append("/.kde/share/apps/kopete/logs"); directory.setCurrent(dir); tmp.append(dir); if (prot == "msn"){ if (directory.exists("MSNProtocol")){ tmp.append("/MSNProtocol/"); protocol.append("MSN"); } } else if (prot == "jabber"){ if (directory.exists("JabberProtocol")){ tmp.append("/JabberProtocol/"); protocol.append("Jabber"); } } else if (prot == "icq"){ if (directory.exists("ICQProtocol")){ tmp.append("/ICQProtocol/"); protocol.append("ICQ"); } } else if (prot == "aim"){ if (directory.exists("AIMProtocol")){ tmp.append("/AIMProtocol/"); protocol.append("AIM"); } } else { return -1; } QListIterator<QString> i(m_accounts); while (i.hasNext()){ QString acc; QString aux; aux.append(i.peekNext()); account.clear(); account.append(aux); acc.append(i.next()); acc.replace(QString("."), QString("-")); tmp.append(acc); directory.setPath(tmp); if (directory.exists(tmp)){ QStringList files; files = directory.entryList(); //neither . nor .. FIXME for (int j=2; j<files.size(); j++){ QString f = files.at(j); QString date = f.section('.',-2,-2); QDir::setCurrent(tmp); file.setFileName(files.at(j)); file.open(QIODevice::ReadOnly | QIODevice::Text); doc.setContent(&file); QDomElement logElem = doc.documentElement(); QDomNode n = logElem.firstChild(); while(!n.isNull()) { QDomElement e = n.toElement(); if(!e.isNull()) { processLogs(e,protocol,account,date); } n = n.nextSibling(); } file.close(); } } tmp.clear(); tmp.append(dir); if (prot == "msn"){ tmp.append("/MSNrotocol/"); } else if (prot == "jabber"){ tmp.append("/JabberProtocol/"); } else if (prot == "icq"){ tmp.append("/ICQProtocol/"); } else if (prot == "aim"){ tmp.append("/AIMProtocol/"); } else { return -2; } } return 0; }
void ClientConnection::handleCommand(const std::string& line) { if (boost::iequals(line, "RETRIEVE TASKS")) { auto& query = findTasksForLoginQ(); query.execute(_userId); std::unique_ptr<ClientTask> task; while (query.next(task)) { _stream.writeLine(concatln("TASK ", task->_id, " TITLE ", quoteString(task->_title), " SPENT ", toSeconds(task->_timeSpent))); for (const auto& line : task->_description) { _stream.writeLine(concatln(line)); } _stream.writeLine("\n"); } _stream.writeLine("END TASKS\n"); } else if (boost::iequals(line, "LOG UPLOAD")) { auto& lastEntryTimeQ = findLastLogEntryTimeForClientQ(); lastEntryTimeQ.execute(_clientId); boost::optional<Timestamp> lastEntryTime; bool res = lastEntryTimeQ.next(lastEntryTime); assert(res); assert(! lastEntryTimeQ.next(lastEntryTime)); if (lastEntryTime) { _stream.writeLine(concatln("LAST ENTRY AT ", formatTimestamp(*lastEntryTime))); } else { _stream.writeLine("NO ENTRYS\n"); } int taskId; std::set<std::string> employeeIds; bool loop = true; while (loop) { auto line = _stream.readLine(); LogEntry entry; if (parse(line, TimestampToken(entry._timestamp), " ", BareStringToken(entry._userId), " LOGIN")) { entry._type = LogEntryType_LOGIN; } else if (parse(line, TimestampToken(entry._timestamp), " ", BareStringToken(entry._userId), " LOGOUT")) { entry._type = LogEntryType_LOGOUT; } else if (parse(line, TimestampToken(entry._timestamp), " ", BareStringToken(entry._userId), " TASK ", IntToken(taskId), " START")) { entry._type = LogEntryType_TASK_START; entry._taskId = taskId; } else if (parse(line, TimestampToken(entry._timestamp), " ", BareStringToken(entry._userId), " TASK ", IntToken(taskId), " PAUSE")) { entry._type = LogEntryType_TASK_PAUSE; entry._taskId = taskId; } else if (parse(line, TimestampToken(entry._timestamp), " ", BareStringToken(entry._userId), " TASK ", IntToken(taskId), " FINISH")) { entry._type = LogEntryType_TASK_FINISH; entry._taskId = taskId; } else if (boost::iequals(line, "END LOG")) { loop = false; } else { throw ProtocolError("Invalid log entry", line); } if (loop) { employeeIds.insert(entry._userId); insertLogEntry(entry); } } for (const auto& employeeId : employeeIds) { processLogs(employeeId); } emit tasksStatusChanged(); } else { throw ProtocolError("Invalid command", line); } }