| 1 | /* ---------------------------------- logDialog.cpp --------------------------------------------------------------------------- |
| 2 | Class to display the "view log" dialog |
| 3 | |
| 4 | =============================================================================================================================== |
| 5 | =============================================================================================================================== |
| 6 | This file is part of "luckyBackup" project |
| 7 | Copyright, Loukas Avgeriou |
| 8 | luckyBackup is distributed under the terms of the GNU General Public License |
| 9 | luckyBackup is free software: you can redistribute it and/or modify |
| 10 | it under the terms of the GNU General Public License as published by |
| 11 | the Free Software Foundation, either version 3 of the License, or |
| 12 | (at your option) any later version. |
| 13 | |
| 14 | luckyBackup is distributed in the hope that it will be useful, |
| 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | GNU General Public License for more details. |
| 18 | |
| 19 | You should have received a copy of the GNU General Public License |
| 20 | along with luckyBackup. If not, see <http://www.gnu.org/licenses/>. |
| 21 | |
| 22 | |
| 23 | project version : Please see "main.cpp" for project version |
| 24 | |
| 25 | developer : luckyb |
| 26 | last modified : 22 May 2016 |
| 27 | =============================================================================================================================== |
| 28 | =============================================================================================================================== |
| 29 | */ |
| 30 | |
| 31 | |
| 32 | #include "logDialog.h"cxx . . $ `<file>/src/logDialog.h`/ |
| 33 | |
| 34 | #include <QTimer> |
| 35 | |
| 36 | #include "global.h"cxx . . $ `<file>/src/global.h`/ |
| 37 | #include "readLogFile.h"cxx . . $ `<file>/src/readLogFile.h`/ |
| 38 | |
| 39 | // class logDialog Constructor================================================================================================= |
| 40 | |
| 41 | logDialogcxx . . $ logDialog#::logDialogcxx . . $ logDialog#logDialog(f0ccea2e72bcf7e0). (QUrlcxx . . $ QUrl# logUrl, QWidgetcxx . . $ QWidget# *parent) : QDialogcxx . . $ QDialog#QDialog(872e7b0c281abd8d). (parent) |
| 42 | { |
| 43 | uiLcxx . . $ logDialog#uiL..setupUicxx . . $ Ui_logDialog#setupUi(d194de0c0f68c28b).(this); |
| 44 | logTextcxx . . $ logDialog#logText. =cxx . . $ QString#`operator=`(d02845eef0c33901). ""; |
| 45 | errorCountcxx . . $ logDialog#errorCount. = 0; |
| 46 | totalErrorscxx . . $ logDialog#totalErrors. = 0; |
| 47 | |
| 48 | readlogfilecxx . . $ logDialog#readlogfile. = new ReadLogFilecxx . . $ ReadLogFile#ReadLogFile(749de1b6ae65bddd).(this); |
| 49 | connectcxx . . $ QObject#connect(158df1d9a01a3410).( readlogfilecxx . . $ logDialog#readlogfile., SIGNALcxx . . $ `<external>/1208926524888476972/qobjectdefs.h:271:10`!(error(const QString)), this, SLOTcxx . . $ `<external>/1208926524888476972/qobjectdefs.h:270:10`!(refreshWindowError(const QString &)) ); |
| 50 | connectcxx . . $ QObject#connect(158df1d9a01a3410).( readlogfilecxx . . $ logDialog#readlogfile., SIGNALcxx . . $ `<external>/1208926524888476972/qobjectdefs.h:271:10`!(newText(const QString)), this, SLOTcxx . . $ `<external>/1208926524888476972/qobjectdefs.h:270:10`!(refreshWindow(const QString &)) ); |
| 51 | connectcxx . . $ QObject#connect(158df1d9a01a3410).( readlogfilecxx . . $ logDialog#readlogfile., SIGNALcxx . . $ `<external>/1208926524888476972/qobjectdefs.h:271:10`!(terminated()), this, SLOTcxx . . $ `<external>/1208926524888476972/qobjectdefs.h:270:10`!(logReadEnd())); |
| 52 | connectcxx . . $ QObject#connect(158df1d9a01a3410).( readlogfilecxx . . $ logDialog#readlogfile., SIGNALcxx . . $ `<external>/1208926524888476972/qobjectdefs.h:271:10`!(finished()), this, SLOTcxx . . $ `<external>/1208926524888476972/qobjectdefs.h:270:10`!(logReadEnd())); |
| 53 | |
| 54 | (uiLcxx . . $ logDialog#uiL..logViewcxx . . $ Ui_logDialog#logView.->documentcxx . . $ QTextEdit#document(f21741221844491e).())->setMaximumBlockCountcxx . . $ QTextDocument#setMaximumBlockCount(d4f767463ce0a6b3).(50000); // set maximum blocks to avoid freeze |
| 55 | |
| 56 | connectcxx . . $ QObject#connect(158df1d9a01a3410). ( uiLcxx . . $ logDialog#uiL..button_closecxx . . $ Ui_logDialog#button_close., SIGNALcxx . . $ `<external>/1208926524888476972/qobjectdefs.h:271:10`!( clicked() ), this, SLOTcxx . . $ `<external>/1208926524888476972/qobjectdefs.h:270:10`!( closeLog() ) ); //connect close pushButton SLOT ---------------- |
| 57 | connectcxx . . $ QObject#connect(158df1d9a01a3410). ( uiLcxx . . $ logDialog#uiL..button_previouscxx . . $ Ui_logDialog#button_previous., SIGNALcxx . . $ `<external>/1208926524888476972/qobjectdefs.h:271:10`!( clicked() ), this, SLOTcxx . . $ `<external>/1208926524888476972/qobjectdefs.h:270:10`!( prevError() ) ); //connect previous pushButton SLOT |
| 58 | connectcxx . . $ QObject#connect(158df1d9a01a3410). ( uiLcxx . . $ logDialog#uiL..button_nextcxx . . $ Ui_logDialog#button_next., SIGNALcxx . . $ `<external>/1208926524888476972/qobjectdefs.h:271:10`!( clicked() ), this, SLOTcxx . . $ `<external>/1208926524888476972/qobjectdefs.h:270:10`!( nextError() ) ); //connect next pushButton SLOT |
| 59 | |
| 60 | readlogfilecxx . . $ logDialog#readlogfile. -> setLogUrlcxx . . $ ReadLogFile#setLogUrl(7df51288a9ebd664).(logUrl.toStringcxx . . $ QUrl#toString(632475ebea3355f1).()); |
| 61 | QTimercxx . . $ QTimer#::singleShotcxx . . $ QTimer#singleShot(24d02da3284e5f26).(500, this, SLOTcxx . . $ `<external>/1208926524888476972/qobjectdefs.h:270:10`!(readLogFileNOW())); // allow some time for the dialog to appear |
| 62 | } |
| 63 | |
| 64 | // readLogFileNOW ===================================================================================================== |
| 65 | //Start a new thread to read the logfile |
| 66 | void logDialogcxx . . $ logDialog#::readLogFileNOWcxx . . $ logDialog#readLogFileNOW(49f6e7a06ebc5aa8).() |
| 67 | { |
| 68 | uiLcxx . . $ logDialog#uiL..logViewcxx . . $ Ui_logDialog#logView. -> setTextcxx . . $ QTextEdit#setText(3520e46b33348bf6).(trcxx . . $ logDialog#tr(75d9f1c324b4579d).("loading logfile...")); |
| 69 | uiLcxx . . $ logDialog#uiL..button_closecxx . . $ Ui_logDialog#button_close. -> setTextcxx . . $ QAbstractButton#setText(3520e46b33348bf6).(trcxx . . $ logDialog#tr(75d9f1c324b4579d).("wait")); |
| 70 | readlogfilecxx . . $ logDialog#readlogfile. -> startcxx . . $ QThread#start(bd4fe741c868f69f).(); |
| 71 | } |
| 72 | |
| 73 | // refreshWindow ===================================================================================================== |
| 74 | //Refresh the log window with text |
| 75 | void logDialogcxx . . $ logDialog#::refreshWindowcxx . . $ logDialog#refreshWindow(3520e46b33348bf6).(const QStringcxx . . $ QString# &newText) |
| 76 | { |
| 77 | if (uiLcxx . . $ logDialog#uiL..logViewcxx . . $ Ui_logDialog#logView. -> toPlainTextcxx . . $ QTextEdit#toPlainText(6ef7b6c27b00b43d).() ==cxx . . $ QString#`operator==`(7d4bdb1abc417636). "loading logfile...") |
| 78 | uiLcxx . . $ logDialog#uiL..logViewcxx . . $ Ui_logDialog#logView. -> clearcxx . . $ QTextEdit#clear(49f6e7a06ebc5aa8).(); |
| 79 | uiLcxx . . $ logDialog#uiL..logViewcxx . . $ Ui_logDialog#logView. -> appendcxx . . $ QTextEdit#append(3520e46b33348bf6).(newText); |
| 80 | totalErrorscxx . . $ logDialog#totalErrors. = readlogfilecxx . . $ logDialog#readlogfile. -> TotalErrorscxx . . $ ReadLogFile#TotalErrors(b126dc7c1de90089).(); |
| 81 | // QCoreApplication::processEvents(); |
| 82 | } |
| 83 | |
| 84 | // logReadEnd ===================================================================================================== |
| 85 | //Do some stuff when finished reading log |
| 86 | void logDialogcxx . . $ logDialog#::logReadEndcxx . . $ logDialog#logReadEnd(49f6e7a06ebc5aa8).() |
| 87 | { |
| 88 | if (totalErrorscxx . . $ logDialog#totalErrors. > 0) |
| 89 | uiLcxx . . $ logDialog#uiL..button_nextcxx . . $ Ui_logDialog#button_next. -> setEnabledcxx . . $ QWidget#setEnabled(b45ddcbc8423892c).(true); |
| 90 | uiLcxx . . $ logDialog#uiL..button_closecxx . . $ Ui_logDialog#button_close. -> setTextcxx . . $ QAbstractButton#setText(3520e46b33348bf6).(trcxx . . $ logDialog#tr(75d9f1c324b4579d).("close")); |
| 91 | uiLcxx . . $ logDialog#uiL..button_closecxx . . $ Ui_logDialog#button_close. -> setEnabledcxx . . $ QWidget#setEnabled(b45ddcbc8423892c).(true); |
| 92 | errorCountcxx . . $ logDialog#errorCount. = 0; //set current error to be the first of the logfile |
| 93 | firstScrollcxx . . $ logDialog#firstScroll.=true; |
| 94 | } |
| 95 | |
| 96 | // refreshWindowError ===================================================================================================== |
| 97 | //Refresh the log window with Error text |
| 98 | void logDialogcxx . . $ logDialog#::refreshWindowErrorcxx . . $ logDialog#refreshWindowError(3520e46b33348bf6).(const QStringcxx . . $ QString# &errorText) |
| 99 | { |
| 100 | uiLcxx . . $ logDialog#uiL..logViewcxx . . $ Ui_logDialog#logView. -> setTextcxx . . $ QTextEdit#setText(3520e46b33348bf6).(errorText); |
| 101 | uiLcxx . . $ logDialog#uiL..button_nextcxx . . $ Ui_logDialog#button_next. -> setEnabledcxx . . $ QWidget#setEnabled(b45ddcbc8423892c).(false); |
| 102 | uiLcxx . . $ logDialog#uiL..button_previouscxx . . $ Ui_logDialog#button_previous. -> setEnabledcxx . . $ QWidget#setEnabled(b45ddcbc8423892c).(false); |
| 103 | uiLcxx . . $ logDialog#uiL..button_closecxx . . $ Ui_logDialog#button_close. -> setTextcxx . . $ QAbstractButton#setText(3520e46b33348bf6).(trcxx . . $ logDialog#tr(75d9f1c324b4579d).("close")); |
| 104 | uiLcxx . . $ logDialog#uiL..button_closecxx . . $ Ui_logDialog#button_close. -> setEnabledcxx . . $ QWidget#setEnabled(b45ddcbc8423892c).(true); |
| 105 | } |
| 106 | |
| 107 | // close button pressed===================================================================================================== |
| 108 | void logDialogcxx . . $ logDialog#::closeLogcxx . . $ logDialog#closeLog(49f6e7a06ebc5aa8).() |
| 109 | { |
| 110 | closecxx . . $ QWidget#close(c9857a73d68e59ba).(); //emmit a QcloseEvent |
| 111 | } |
| 112 | |
| 113 | // previous button pressed===================================================================================================== |
| 114 | void logDialogcxx . . $ logDialog#::prevErrorcxx . . $ logDialog#prevError(49f6e7a06ebc5aa8).() |
| 115 | { |
| 116 | errorCountcxx . . $ logDialog#errorCount.--; //decrease the current error by one |
| 117 | |
| 118 | if (errorCountcxx . . $ logDialog#errorCount. == 0 ) // if the current error is the first within the logfile disable the previous button |
| 119 | uiLcxx . . $ logDialog#uiL..button_previouscxx . . $ Ui_logDialog#button_previous. -> setEnabledcxx . . $ QWidget#setEnabled(b45ddcbc8423892c).(false); |
| 120 | |
| 121 | if (errorCountcxx . . $ logDialog#errorCount. < totalErrorscxx . . $ logDialog#totalErrors.-1) //if the current error is less than the last one within the logfile enable the next button |
| 122 | uiLcxx . . $ logDialog#uiL..button_nextcxx . . $ Ui_logDialog#button_next. -> setEnabledcxx . . $ QWidget#setEnabled(b45ddcbc8423892c).(true); |
| 123 | |
| 124 | uiLcxx . . $ logDialog#uiL..logViewcxx . . $ Ui_logDialog#logView. -> scrollToAnchorcxx . . $ QTextEdit#scrollToAnchor(3520e46b33348bf6).("error" +cxx . . $ operator+(c75c3ae4eb9af1a8). countStrcxx . . $ Global/countStr..setNumcxx . . $ QString#setNum(6483560ce2afa901).(errorCountcxx . . $ logDialog#errorCount.+1)); |
| 125 | } |
| 126 | |
| 127 | // next button pressed===================================================================================================== |
| 128 | void logDialogcxx . . $ logDialog#::nextErrorcxx . . $ logDialog#nextError(49f6e7a06ebc5aa8).() |
| 129 | { |
| 130 | if (!firstScrollcxx . . $ logDialog#firstScroll.) |
| 131 | errorCountcxx . . $ logDialog#errorCount.++; // increase the current error by one |
| 132 | firstScrollcxx . . $ logDialog#firstScroll. = false; |
| 133 | |
| 134 | if (errorCountcxx . . $ logDialog#errorCount. == totalErrorscxx . . $ logDialog#totalErrors.-1) // If the current error is the last within the logfile disable the next button |
| 135 | uiLcxx . . $ logDialog#uiL..button_nextcxx . . $ Ui_logDialog#button_next. -> setEnabledcxx . . $ QWidget#setEnabled(b45ddcbc8423892c).(false); |
| 136 | |
| 137 | if (errorCountcxx . . $ logDialog#errorCount. > 0) // if the current error is greater than the first one within the logfile enable the previous button |
| 138 | uiLcxx . . $ logDialog#uiL..button_previouscxx . . $ Ui_logDialog#button_previous. -> setEnabledcxx . . $ QWidget#setEnabled(b45ddcbc8423892c).(true); |
| 139 | |
| 140 | uiLcxx . . $ logDialog#uiL..logViewcxx . . $ Ui_logDialog#logView. -> scrollToAnchorcxx . . $ QTextEdit#scrollToAnchor(3520e46b33348bf6).("error" +cxx . . $ operator+(c75c3ae4eb9af1a8). countStrcxx . . $ Global/countStr..setNumcxx . . $ QString#setNum(6483560ce2afa901).(errorCountcxx . . $ logDialog#errorCount.+1)); //scroll to the current error |
| 141 | } |
| 142 | |
| 143 | // end of logDialog.cpp --------------------------------------------------------------------------- |
| 144 |