log.h 2.33 KB
Newer Older
1
/*
2
 * Copyright (C) 2014-2019 CZ.NIC
3 4 5 6 7 8 9 10
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 13 14
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
15
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 17 18 19 20 21 22 23 24 25 26 27 28
 *
 * In addition, as a special exception, the copyright holders give
 * permission to link the code of portions of this program with the
 * OpenSSL library under certain conditions as described in each
 * individual source file, and distribute linked combinations including
 * the two.
 */

#pragma once

#include <QObject>
#include <QString>

29
class MemoryLog; /* Forward declaration. */
30 31 32 33 34 35 36 37 38 39 40 41

/*
 * Class Log provides interface between QML and log device.
 * Class is initialised in the main function (main.cpp)
 */
class Log : public QObject {
    Q_OBJECT

public:
	/*!
	 * @brief Constructor.
	 *
42
	 * @param[in] memLog Memory log.
43 44
	 * @param[in] parent Parent object.
	 */
45
	explicit Log(MemoryLog *memLog, QObject *parent = Q_NULLPTR);
46 47 48 49 50 51 52 53 54 55 56 57

	/*!
	 * @brief Destructor.
	 */
	~Log(void);

	/*!
	 * @brief Get log file location.
	 *
	 * @return Full path to log directory.
	 */
	Q_INVOKABLE static
58
	QString getLogFileLocation(void);
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95

	/*!
	 * @brief Load log content from file or memory into QML.
	 *
	 * @param[in] filePath Log file path (empty = use memory log).
	 * @return Log content as text.
	 */
	Q_INVOKABLE
	QString loadLogContent(const QString &filePath);

	/*!
	 * @brief Send log via email.
	 *
	 * @param[in] logContent Log content to be sent.
	 */
	Q_INVOKABLE static
	void sendLogViaEmail(const QString &logContent);

signals:
	/*!
	 * @brief Append new log message to QML log bar.
	 *
	 * @param[in] newLog New log message.
	 */
	void appendNewLogMessage(QString newLog);

private slots:
	/*!
	 * @brief Appends newly logged message to QML log bar.
	 *
	 * @param[in] key Log message key.
	 */
	void appendNewLog(quint64 key);

private:
	MemoryLog *m_memLog; /*!< Pointer to memory log. */
};