void TimeScene::drawTimeLog(const QModelIndex &index) { Task* task = _model->task(index); std::vector<TaskLog*> *logs = NULL; int groupLevel = 2; if (task != NULL) { logs = task->logs(true); groupLevel = (task->childCount() > 0) ? 1 : 2; } else { Project* project = _model->project(index); if (project != NULL) { logs = project->logs(); groupLevel = 0; } } if ((logs != NULL) && (logs->size() != 0)) { std::sort(logs->begin(), logs->end(), compareTaskLog); DateTime* currentDay = NULL; DTime currentTime(0); for (std::vector<TaskLog*>::iterator iter = logs->begin(); iter != logs->end(); iter++) { TaskLog* log = *iter; DateTime logDate(log->start->getYear(), log->start->getMonth(), log->start->getDay()); if (currentDay == NULL) { currentDay = new DateTime(logDate.toDouble()); currentTime = (*log->end - *log->start); } else if (logDate == *currentDay) { currentTime = currentTime + (*log->end - *log->start); } else { drawTime(*currentDay, currentTime, index, groupLevel); if (currentDay != NULL) { delete(currentDay); currentDay = NULL; } currentDay = new DateTime(logDate.toDouble()); currentTime = (*log->end - *log->start); } } if (currentTime.totalSecs() != 0) { drawTime(*currentDay, currentTime, index, groupLevel); } if (currentDay != NULL) { delete(currentDay); currentDay = NULL; } } _currentY += sizeHint(index).height(); if (!isCollapsed(index)) { for (int x = 0; x < _model->rowCount(index); x++) { QModelIndex child = _model->index(x, 0, index); if (child.isValid()) { drawIndex(child); } } } if (logs != NULL) { delete(logs); } }
extern int incrementCumulativeDays(void) { struct NORcumulativeDays cumulativeDays; int currentDays; char buffer[100]; cumulativeDays.structType = NOR_STRUCT_ID_CUMULATIVE_DAYS; currentDays = getCumulativeDays() + 1; cumulativeDays.cumulativeDaysSinceUpdate = currentDays; ptrsCounts.cumulativeDays = (struct NORcumulativeDays *)AppendStructToFlash(&cumulativeDays); systemCounts.monthday++; fixBadDate(&systemCounts); strcpy(buffer,"Cumulative Days="); longToDecimalString(getCumulativeDays(), buffer+strlen(buffer), 3); logString(buffer,BUFFER,LOG_DETAIL); logDate(); return currentDays; }
// FIXME: this currently does not work if the user has changed his date format, // since . is hardcoded as date parts separator. void KviQueryWindow::pasteLastLog() { QString szQuery = target().toLower(); QString szNetwork = console()->currentNetworkName().toLower(); QDate date = QDate::currentDate(); // Create the filter for the dir // Format: query__<nick>.<network>_*.*.*.log* QString szLogFilter = "query_"; szLogFilter += szQuery; szLogFilter += "."; szLogFilter += szNetwork; szLogFilter += "_*.*.*.log*"; // Get the logs QString szLogPath; g_pApp->getLocalKvircDirectory(szLogPath,KviApplication::Log); QDir logDir(szLogPath); QStringList filter = QStringList(szLogFilter); QStringList logList = logDir.entryList(filter,QDir::Files,QDir::Name | QDir::Reversed); // Scan log files // Format: query_nick.networkName_year.month.day.log // Format: query_nick.networkName_year.month.day.log.gz bool bGzip; QString szFileName; for(QStringList::Iterator it = logList.begin(); it != logList.end(); ++it) { int iLogYear, iLogMonth, iLogDay; szFileName = (*it); QString szTmpName = (*it); QFileInfo fi(szTmpName); bGzip = false; // Skip the log just created on join if(fi.suffix() == "tmp") continue; // Remove trailing dot and extension .gz if(fi.suffix() == "gz") { bGzip = true; szTmpName.chop(3); } // Ok, we have the right nick/network log. Get date QString szLogDate = szTmpName.section('.',-4,-1).section('_',1,1); iLogYear = szLogDate.section('.',0,0).toInt(); iLogMonth = szLogDate.section('.',1,1).toInt(); iLogDay = szLogDate.section('.',2,2).toInt(); // Check log validity int iInterval = -KVI_OPTION_UINT(KviOption_uintDaysIntervalToPasteOnQueryJoin); QDate logDate(iLogYear,iLogMonth,iLogDay); QDate checkDate = date.addDays(iInterval); if(logDate < checkDate) return; else break; } // Get the right log name szFileName.prepend("/"); szFileName.prepend(szLogPath); // Load the log QByteArray log = loadLogFile(szFileName,bGzip); if(log.size() > 0) { QList<QByteArray> list = log.split('\n'); unsigned int uCount = list.size(); unsigned int uLines = KVI_OPTION_UINT(KviOption_uintLinesToPasteOnQueryJoin); unsigned int uStart = uCount - uLines - 1; /* // Check if the log is smaller than the lines to print if(uStart < 0) uStart = 0; */ QString szDummy = __tr2qs("Starting last log"); output(KVI_OUT_QUERYPRIVMSG,szDummy); // Scan the log file for(unsigned int i = uStart; i < uCount; i++) { QString szLine = QString(list.at(i)); szLine = szLine.section(' ',1); #ifdef COMPILE_ON_WINDOWS // Remove the \r char at the szEnd of line szLine.chop(1); #endif // Print the line in the channel buffer output(KVI_OUT_QUERYPRIVMSG,szLine); } szDummy = __tr2qs("End of log"); output(KVI_OUT_QUERYPRIVMSG,szDummy); } }