1 /*
2     SPDX-FileCopyrightText: 2007 Nicolas Ternisien <nicolas.ternisien@gmail.com>
3 
4     SPDX-License-Identifier: GPL-2.0-or-later
5 */
6 
7 #include "analyzer.h"
8 
9 #include "ksystemlogConfig.h"
10 #include "ksystemlog_debug.h"
11 
12 #include "logViewModel.h"
13 
14 #include "logFileReader.h"
15 #include "logMode.h"
16 
Analyzer(LogMode * mode)17 Analyzer::Analyzer(LogMode *mode)
18     : QObject(nullptr)
19     , mLogMode(mode)
20     , mInsertionLocking()
21 {
22 }
23 
~Analyzer()24 Analyzer::~Analyzer()
25 {
26     // logMode is managed by Globals
27     // logViewModel is managed by LogViewWidget
28 }
29 
isParsingPaused() const30 bool Analyzer::isParsingPaused() const
31 {
32     return mParsingPaused;
33 }
34 
setParsingPaused(bool paused)35 void Analyzer::setParsingPaused(bool paused)
36 {
37     mParsingPaused = paused;
38 
39     bool watching;
40     // If we resume the parsing, then parse files to know if new lines have been appended.
41     if (mParsingPaused) {
42         qCDebug(KSYSTEMLOG) << "Pausing reading";
43         watching = false;
44     } else {
45         qCDebug(KSYSTEMLOG) << "Relaunch reading";
46         watching = true;
47     }
48 
49     watchLogFiles(watching);
50 }
51 
setLogViewModel(LogViewModel * logViewModel)52 void Analyzer::setLogViewModel(LogViewModel *logViewModel)
53 {
54     mLogViewModel = logViewModel;
55 }
56 
informOpeningProgress(int currentPosition,int total)57 void Analyzer::informOpeningProgress(int currentPosition, int total)
58 {
59     const int each = total / 100;
60     if (each == 0) {
61         return;
62     }
63 
64     if (currentPosition % each == 0) {
65         Q_EMIT openingProgressed();
66     }
67 }
68