gk_logger.hpp 4.44 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
/**
 **     __                 _ _   __    __           _     _ 
 **    / _\_ __ ___   __ _| | | / / /\ \ \___  _ __| | __| |
 **    \ \| '_ ` _ \ / _` | | | \ \/  \/ / _ \| '__| |/ _` |
 **    _\ \ | | | | | (_| | | |  \  /\  / (_) | |  | | (_| |
 **    \__/_| |_| |_|\__,_|_|_|   \/  \/ \___/|_|  |_|\__,_|
 **                                                         
 **                  ___     _                              
 **                 /   \___| |_   ___  _____               
 **                / /\ / _ \ | | | \ \/ / _ \              
 **               / /_//  __/ | |_| |>  <  __/              
 **              /___,' \___|_|\__,_/_/\_\___|              
 **
 **
 **   If you have downloaded the source code for "Small World Deluxe" and are reading this,
 **   then thank you from the bottom of our hearts for making use of our hard work, sweat
 **   and tears in whatever you are implementing this into!
 **
Phobos D'thorga's avatar
Phobos D'thorga committed
19
 **   Copyright (C) 2020 - 2021. GekkoFyre.
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
 **
 **   Small World Deluxe 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.
 **
 **   Small world is distributed in the hope that it will be useful,
 **   but WITHOUT ANY WARRANTY; without even the implied warranty of
 **   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 **   GNU General Public License for more details.
 **
 **   You should have received a copy of the GNU General Public License
 **   along with Small World Deluxe.  If not, see <http://www.gnu.org/licenses/>.
 **
 **
 **   The latest source code updates can be obtained from [ 1 ] below at your
 **   discretion. A web-browser or the 'git' application may be required.
 **
38
 **   [ 1 ] - https://code.gekkofyre.io/amateur-radio/small-world-deluxe
39
40
41
42
43
44
 **
 ****************************************************************************************************/

#pragma once

#include "src/defines.hpp"
45
#include "src/file_io.hpp"
46
#include "src/models/tableview/gk_logger_model.hpp"
47
#include <qxmpp/QXmppLogger.h>
48
#include <mutex>
49
#include <memory>
50
#include <QFile>
51
#include <QList>
52
53
#include <QObject>
#include <QString>
54
55
#include <QVariant>
#include <QPointer>
56
#include <QSystemTrayIcon>
57
58
59
60

#if defined(GFYRE_ENBL_MSVC_WINTOAST)
#include "src/contrib/WinToast/src/wintoastlib.h"
#endif
61
62
63
64
65
66
67

namespace GekkoFyre {

class GkEventLogger : public QObject {
    Q_OBJECT

public:
68
    explicit GkEventLogger(const QPointer<QSystemTrayIcon> &sysTrayIcon, const QPointer<GekkoFyre::StringFuncs> &stringFuncs,
69
                           QPointer<GekkoFyre::FileIo> fileIo, const quintptr &win_id, QObject *parent = nullptr);
70
    ~GkEventLogger() override;
71

72
public slots:
73
    void publishEvent(const QString &event, const GekkoFyre::System::Events::Logging::GkSeverity &severity = GekkoFyre::System::Events::Logging::GkSeverity::Warning,
74
                      const QVariant &arguments = "", const bool &sys_notification = false, const bool &publishToConsole = true,
75
                      const bool &publishToStatusBar = false, const bool &displayMsgBox = false, const bool &flashTaskbar = false);
76
    void recvXmppLog(QXmppLogger::MessageType msg_type, QString msg);
77

78
79
80
signals:
    void sendEvent(const GekkoFyre::System::Events::Logging::GkEventLogging &event);
    void removeEvent(const GekkoFyre::System::Events::Logging::GkEventLogging &event);
81
    void sendToStatusBar(const QString &msg);
82

83
private:
84
    QPointer<QSystemTrayIcon> m_trayIcon;
85
    QPointer<GekkoFyre::StringFuncs> gkStringFuncs;
86
87
    QList<GekkoFyre::System::Events::Logging::GkEventLogging> eventLogDb;                       // Where the event log itself is stored in memory...

88
89
90
91
92
    //
    // File I/O
    QPointer<GekkoFyre::FileIo> gkFileIo;
    QFile gkWriteCsvIo;

93
94
95
96
    //
    // Microsoft Windows
    quintptr m_windowId;

97
98
99
100
    #if defined(GFYRE_ENBL_MSVC_WINTOAST)
    std::unique_ptr<WinToastLib::WinToastTemplate> toastTempl;
    #endif

101
    int setEventNo();
102
103
104
    void systemNotification(const QString &title, const GekkoFyre::System::Events::Logging::GkEventLogging &event_msg);
    void sendToConsole(const GekkoFyre::System::Events::Logging::GkEventLogging &event_msg,
                       const GekkoFyre::System::Events::Logging::GkSeverity &severity);
105
106
    void writeToCsv(const GekkoFyre::System::Events::Logging::GkEventLogging &event_msg,
                    const GekkoFyre::System::Events::Logging::GkSeverity &severity);
107
108
109

};
};