Пример #1
0
void alarms_history::on_comboBoxType_currentIndexChanged(int index)
{
    /* 0 is all
     * 1 is alarm
     * 2 is event
     */
    switch(index)
    {
    case 0:
        _alarm = true;
        _event = true;
        break;
    case 1:
        _alarm = true;
        _event = false;
        break;
    case 2:
        _alarm = false;
        _event = true;
        break;
    default:
        _alarm = true;
        _event = true;
        break;
    }
    LOG_PRINT(info_e, "_current %d\n", _current);
    if (_file_nb == 0) return;
    if (loadLogFile(_current, _alarm, _event, _level) == false)
    {
        LOG_PRINT(error_e, "Cannot open log file %d\n", _current);
    }
}
Пример #2
0
void alarms_history::on_comboBoxDate_currentIndexChanged(int index)
{
    _current = index;
    if (loadLogFile(_current, _alarm, _event, _level) == false)
    {
        LOG_PRINT(error_e, "Cannot open log file %d\n", _current);
    }
}
Пример #3
0
/**
 * @brief Load the log file number fileNb (0 is the last one) and filter by alarm, event and level
 */
bool alarms_history::loadLogFile(int fileNb, bool alarm, bool event, int level)
{
    if (fileNb < 0 || fileNb > logFileList.count())
    {
        return false;
    }
    LOG_PRINT(info_e, "fileNb %d < %d\n", fileNb, logFileList.count());
    LOG_PRINT(info_e, "logFileList '%s'\n", logFileList.at(fileNb).toAscii().data());
    return loadLogFile(logFileList.at(fileNb).toAscii().data(), alarm, event, level);
}
Пример #4
0
QString FrameFileIO::loadFrameFile(QVector<CANFrame>* frameCache)
{
    QString filename;
    QFileDialog dialog;
    bool result = false;

    QStringList filters;
    filters.append(QString(tr("CRTD Logs (*.txt)")));
    filters.append(QString(tr("GVRET Logs (*.csv)")));
    filters.append(QString(tr("Generic ID/Data CSV (*.csv)")));
    filters.append(QString(tr("BusMaster Log (*.log)")));
    filters.append(QString(tr("Microchip Log (*.can)")));

    dialog.setFileMode(QFileDialog::ExistingFile);
    dialog.setNameFilters(filters);
    dialog.setViewMode(QFileDialog::Detail);

    if (dialog.exec() == QDialog::Accepted)
    {
        filename = dialog.selectedFiles()[0];

        QProgressDialog progress(qApp->activeWindow());
        progress.setWindowModality(Qt::WindowModal);
        progress.setLabelText("Loading file...");
        progress.setCancelButton(0);
        progress.setRange(0,0);
        progress.setMinimumDuration(0);
        progress.show();

        qApp->processEvents();

        if (dialog.selectedNameFilter() == filters[0]) result = loadCRTDFile(filename, frameCache);
        if (dialog.selectedNameFilter() == filters[1]) result = loadNativeCSVFile(filename, frameCache);
        if (dialog.selectedNameFilter() == filters[2]) result = loadGenericCSVFile(filename, frameCache);
        if (dialog.selectedNameFilter() == filters[3]) result = loadLogFile(filename, frameCache);
        if (dialog.selectedNameFilter() == filters[4]) result = loadMicrochipFile(filename, frameCache);

        progress.cancel();

        if (result)
        {
            QStringList fileList = filename.split('/');
            filename = fileList[fileList.length() - 1];
            return filename;
        }
        else return QString("");
    }
    return QString("");
}
Пример #5
0
void alarms_history::on_comboBoxLevel_currentIndexChanged(int index)
{
    LOG_PRINT(info_e, "_level %d\n", _level);
    /* 0 is all level */
    if (_level != index && index < nb_of_level_e)
    {
        _level = index;
        LOG_PRINT(info_e, "_level %d\n", _level);
        if (_file_nb == 0) return;
        if (loadLogFile(_current, _alarm, _event, _level) == false)
        {
            LOG_PRINT(error_e, "Cannot open log file %d\n", _current);
        }
    }
}
Пример #6
0
/**
 * @brief This is the reload member. The operation written here, are executed every time this page is shown.
 */
void alarms_history::reload()
{
    /* clear the old value */
    ui->listWidget->clear();
    
    /* get the file list */
    QDir logDir(ALARMS_DIR);
    logFileList = logDir.entryList(QDir::Files|QDir::NoDotAndDotDot, QDir::Reversed);
    
    ui->comboBoxDate->clear();
    
    for (int i = 0; i < logFileList.count(); i++)
    {
        if (logFileList.at(i).endsWith(".log") == false)
        {
            logFileList.removeAt(i);
            i--;
        }
        else
        {
            ui->comboBoxDate->addItem(QDate().fromString(logFileList.at(i),"yyyy_MM_dd.log").toString("yyyy/MM/dd"));
        }
    }
    
    _current = 0;
    _alarm = true;
    _event = true;
    _level = level_all_e;
    
    /* no logfile found */
    _file_nb = logFileList.count();
    if (_file_nb == 0)
    {
        LOG_PRINT(error_e, "No file to load\n");
        return;
    }
    
    /* load the current log file */
    LOG_PRINT(info_e, "_current %d\n",_current);
    ui->comboBoxDate->setCurrentIndex(_current);
    loadLogFile(_current, _alarm, _event, _level);
}
Пример #7
0
void KviWindow::pasteLastLog()
{
	bool bChannel = type() == KviWindow::Channel || type() == KviWindow::DeadChannel;
	QDate date = QDate::currentDate();
	int iInterval = -(int)KVI_OPTION_UINT(bChannel ? KviOption_uintDaysIntervalToPasteOnChannelJoin : KviOption_uintDaysIntervalToPasteOnQueryJoin);
	QDate checkDate = date.addDays(iInterval);

	unsigned int uMaxLines = KVI_OPTION_UINT(bChannel ? KviOption_uintLinesToPasteOnChannelJoin : KviOption_uintLinesToPasteOnQueryJoin);
	if (!uMaxLines)
		return;

	std::vector<std::tuple<QString, QDate, int>> vLines;

	for (; date >= checkDate; date = date.addDays(-1))
		for (int iGzip = 0; iGzip <= 1; iGzip++)
			for (unsigned int uDatetimeFormat = 0; uDatetimeFormat < 3; uDatetimeFormat++)
			{
				bool bGzip = !!iGzip;

				QString szFileName;
				getDefaultLogFileName(szFileName, date, bGzip, uDatetimeFormat);

				QFileInfo fi(szFileName);
				if (!fi.exists() || !fi.isFile())
					continue;

				// Load the log
				QByteArray log = loadLogFile(szFileName, bGzip);

				if(log.size() == 0)
					continue;

				QList<QByteArray> list = log.split('\n');
				unsigned int uCount = list.size();

				while (uCount)
				{
					vLines.emplace_back(QString(list.at(--uCount)), date, uDatetimeFormat);

					if (vLines.size() == uMaxLines)
						goto enough;
				}
			}

	if (vLines.empty())
		return;

enough:
	QString szDummy = __tr2qs("Starting last log");
	output(KVI_OUT_LOG, szDummy);

	for (auto logIter = vLines.rbegin(); logIter != vLines.rend(); ++logIter)
	{
		QString & szLine      = std::get<0>(*logIter);
		const QDate & logDate = std::get<1>(*logIter);
		int uDatetimeFormat   = std::get<2>(*logIter);

		bool ok;
		int msgType = szLine.section(' ', 0, 0).toInt(&ok);
		if (ok)
			szLine = szLine.section(' ', 1);
		else
			msgType = KVI_OUT_LOG;

		QDateTime date;
		switch(uDatetimeFormat)
		{
			case 0:
			{
				QTime time = QTime::fromString(szLine.section(' ', 0, 0), "[hh:mm:ss]");
				if (time.isValid())
				{
					date = QDateTime(logDate, time);
					szLine = szLine.section(' ', 1);
				}
				break;
			}
			case 1:
				date = QDateTime::fromString(szLine.section(' ', 0, 0), Qt::ISODate);
				if (date.isValid())
					szLine = szLine.section(' ', 1);
				break;
			case 2:
			{
				// The system-locale format is hairy, because it has no clear delimiter.
				// Count how many spaces a typical time format has,
				// and assume that that number is not going to change.
				static int iSpaceCount = -1;
				if (iSpaceCount == -1)
				{
					QString szTypicalDate = QDateTime::currentDateTime().toString(Qt::SystemLocaleShortDate);
					iSpaceCount = szTypicalDate.count(' ');
				}
				date = QDateTime::fromString(szLine.section(' ', 0, iSpaceCount), Qt::SystemLocaleShortDate);
				if (date.isValid())
				{
					szLine = szLine.section(' ', iSpaceCount+1);

					// Work around Qt bug:
					// if the date string contains a two-digit year, it may be
					// parsed in the wrong century (i.e. 1916 instead of 2016).
					if (logDate.year() == date.date().year() + 100)
						date = date.addYears(100);
				}
				break;
			}
		}

		if (szLine.endsWith("\r"))
		{
			// Remove the \r char at the szEnd of line
			szLine.chop(1);
		}

		if (szLine.isEmpty())
			continue;

		// Print the line in the channel buffer
		output(msgType, date, "%Q", &szLine);
	}

	szDummy = __tr2qs("End of log");
	output(KVI_OUT_LOG, szDummy);
}
Пример #8
0
// 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);
	}
}