Building interface for crapLOG
This commit is contained in:
parent
f549c98783
commit
e3512b7dce
|
@ -0,0 +1,71 @@
|
|||
cmake_minimum_required(VERSION 3.5)
|
||||
|
||||
project(Craplog VERSION 6.0 LANGUAGES CXX)
|
||||
|
||||
set(CMAKE_INCLUDE_CURRENT_DIR ON)
|
||||
|
||||
set(CMAKE_AUTOUIC ON)
|
||||
set(CMAKE_AUTOMOC ON)
|
||||
set(CMAKE_AUTORCC ON)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets LinguistTools)
|
||||
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets LinguistTools)
|
||||
|
||||
set(TS_FILES
|
||||
Craplog_en_EN.ts
|
||||
Craplog_it_IT.ts
|
||||
)
|
||||
|
||||
set(PROJECT_SOURCES
|
||||
main.cpp
|
||||
mainwindow.cpp
|
||||
mainwindow.h
|
||||
mainwindow.ui
|
||||
window/craplog.h
|
||||
window/craplog.cpp
|
||||
${TS_FILES}
|
||||
)
|
||||
|
||||
if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
|
||||
qt_add_executable(Craplog
|
||||
MANUAL_FINALIZATION
|
||||
${PROJECT_SOURCES}
|
||||
)
|
||||
# Define target properties for Android with Qt 6 as:
|
||||
# set_property(TARGET Craplog APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR
|
||||
# ${CMAKE_CURRENT_SOURCE_DIR}/android)
|
||||
# For more information, see https://doc.qt.io/qt-6/qt-add-executable.html#target-creation
|
||||
|
||||
qt_create_translation(QM_FILES ${CMAKE_SOURCE_DIR} ${TS_FILES})
|
||||
else()
|
||||
if(ANDROID)
|
||||
add_library(Craplog SHARED
|
||||
${PROJECT_SOURCES}
|
||||
)
|
||||
# Define properties for Android with Qt 5 after find_package() calls as:
|
||||
# set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android")
|
||||
else()
|
||||
add_executable(Craplog
|
||||
${PROJECT_SOURCES}
|
||||
)
|
||||
endif()
|
||||
|
||||
qt5_create_translation(QM_FILES ${CMAKE_SOURCE_DIR} ${TS_FILES})
|
||||
endif()
|
||||
|
||||
target_link_libraries(Craplog PRIVATE Qt${QT_VERSION_MAJOR}::Widgets)
|
||||
|
||||
set_target_properties(Craplog PROPERTIES
|
||||
MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com
|
||||
MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
|
||||
MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
|
||||
MACOSX_BUNDLE TRUE
|
||||
WIN32_EXECUTABLE TRUE
|
||||
)
|
||||
|
||||
if(QT_VERSION_MAJOR EQUAL 6)
|
||||
qt_finalize_executable(Craplog)
|
||||
endif()
|
|
@ -1,4 +1,4 @@
|
|||
#include "craplog.h"
|
||||
#include "mainwindow.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QLocale>
|
||||
|
@ -17,7 +17,7 @@ int main(int argc, char *argv[])
|
|||
break;
|
||||
}
|
||||
}
|
||||
Craplog w;
|
||||
MainWindow w;
|
||||
w.show();
|
||||
return a.exec();
|
||||
}
|
||||
|
|
|
@ -1,15 +1,100 @@
|
|||
#include "craplog.h"
|
||||
#include "./ui_craplog.h"
|
||||
#include "mainwindow.h"
|
||||
#include "./ui_mainwindow.h"
|
||||
|
||||
Craplog::Craplog(QWidget *parent)
|
||||
MainWindow::MainWindow(QWidget *parent)
|
||||
: QMainWindow(parent)
|
||||
, ui(new Ui::Craplog)
|
||||
, ui(new Ui::MainWindow)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
//craplog.scanLogsDir();
|
||||
ui->listLogFiles->header()->resizeSection(0,160);
|
||||
ui->listLogFiles->header()->resizeSection(1,75);
|
||||
this->on_buttonRefreshList_clicked();
|
||||
}
|
||||
|
||||
Craplog::~Craplog()
|
||||
MainWindow::~MainWindow()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
//////////////
|
||||
//// LOGS ////
|
||||
//////////////
|
||||
// refresh the log files list
|
||||
void MainWindow::on_buttonRefreshList_clicked()
|
||||
{
|
||||
// clear the current tree
|
||||
this->ui->listLogFiles->clear();
|
||||
// grey color to use for the size column
|
||||
QColor grey = QColor(127,127,127,255);
|
||||
// iterate over elements of list
|
||||
for ( Craplog::LogFile& log_file : this->craplog.getLogsList(true) ) {
|
||||
// new entry for the tree widget
|
||||
QTreeWidgetItem * item = new QTreeWidgetItem();
|
||||
// set unchecked
|
||||
item->setCheckState(0, Qt::CheckState::Unchecked );
|
||||
// name to be showed
|
||||
item-> setText( 0, log_file.name );
|
||||
// size to be showed
|
||||
float size = (float)log_file.size / 1024;
|
||||
int n_decimals = 3;
|
||||
std::string sfx = " KiB";
|
||||
if (size > 1024) {
|
||||
size /= 1024;
|
||||
sfx = " MiB";
|
||||
}
|
||||
// cut decimals depending on how big the floor is
|
||||
std::string size_str = std::to_string( size );
|
||||
int point_i = size_str.find('.')+1;
|
||||
if ( point_i == 0 ) {
|
||||
point_i = size_str.find(',')+1;
|
||||
}
|
||||
if ( size >= 100 ) {
|
||||
n_decimals = 2;
|
||||
if ( size >= 1000 ) {
|
||||
n_decimals = 1;
|
||||
if ( size >= 10000 ) {
|
||||
n_decimals = 0;
|
||||
point_i --;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ( point_i >= 1 ) {
|
||||
for ( int i=0; i<n_decimals; i++ ) {
|
||||
if ( i >= size_str.size() ) {
|
||||
break;
|
||||
}
|
||||
point_i ++;
|
||||
}
|
||||
}
|
||||
// apply text and color
|
||||
item-> setText( 1, QString::fromStdString( size_str.substr(0,point_i) + sfx ) );
|
||||
item->setForeground(1, grey);
|
||||
// append the item (on top, forced)
|
||||
this->ui->listLogFiles->addTopLevelItem( item );
|
||||
}
|
||||
// sort the list alphabetically
|
||||
this->ui->listLogFiles->sortByColumn(0, Qt::SortOrder::AscendingOrder );
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::on_checkAllLogFiles_stateChanged(int arg1)
|
||||
{
|
||||
QTreeWidgetItemIterator i(this->ui->listLogFiles);
|
||||
while ( *i ) {
|
||||
(*i)->setCheckState( 0, Qt::CheckState::Checked );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::on_buttonViewFile_clicked()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::on_listLogFiles_itemDoubleClicked(QTreeWidgetItem *item, int column)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -1,21 +1,34 @@
|
|||
#ifndef CRAPLOG_H
|
||||
#define CRAPLOG_H
|
||||
#ifndef MAINWINDOW_H
|
||||
#define MAINWINDOW_H
|
||||
|
||||
#include <QMainWindow>
|
||||
|
||||
#include "./window/craplog.h"
|
||||
#include "qtreewidget.h"
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
namespace Ui { class Craplog; }
|
||||
namespace Ui { class MainWindow; }
|
||||
QT_END_NAMESPACE
|
||||
|
||||
class Craplog : public QMainWindow
|
||||
class MainWindow : public QMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
Craplog(QWidget *parent = nullptr);
|
||||
~Craplog();
|
||||
MainWindow(QWidget *parent = nullptr);
|
||||
~MainWindow();
|
||||
|
||||
private slots:
|
||||
void on_buttonViewFile_clicked();
|
||||
|
||||
void on_checkAllLogFiles_stateChanged(int arg1);
|
||||
|
||||
void on_buttonRefreshList_clicked();
|
||||
|
||||
void on_listLogFiles_itemDoubleClicked(QTreeWidgetItem *item, int column);
|
||||
|
||||
private:
|
||||
Ui::Craplog *ui;
|
||||
Ui::MainWindow *ui;
|
||||
Craplog craplog;
|
||||
};
|
||||
#endif // CRAPLOG_H
|
||||
#endif // MAINWINDOW_H
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>Craplog</class>
|
||||
<widget class="QMainWindow" name="Craplog">
|
||||
<class>MainWindow</class>
|
||||
<widget class="QMainWindow" name="MainWindow">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
|
@ -11,7 +11,7 @@
|
|||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||
<sizepolicy hsizetype="Maximum" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
|
@ -29,9 +29,14 @@
|
|||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<item>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QTabWidget" name="CrapTabs">
|
||||
<property name="font">
|
||||
<font>
|
||||
<pointsize>16</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
<property name="layoutDirection">
|
||||
<enum>Qt::LeftToRight</enum>
|
||||
</property>
|
||||
|
@ -42,7 +47,7 @@
|
|||
<enum>QTabWidget::West</enum>
|
||||
</property>
|
||||
<property name="currentIndex">
|
||||
<number>0</number>
|
||||
<number>3</number>
|
||||
</property>
|
||||
<property name="movable">
|
||||
<bool>true</bool>
|
||||
|
@ -58,7 +63,7 @@
|
|||
</sizepolicy>
|
||||
</property>
|
||||
<attribute name="title">
|
||||
<string>Logs</string>
|
||||
<string></string>
|
||||
</attribute>
|
||||
<attribute name="toolTip">
|
||||
<string>Parse logs to create statistics</string>
|
||||
|
@ -76,15 +81,15 @@
|
|||
<enum>Qt::NoFocus</enum>
|
||||
</property>
|
||||
<property name="currentIndex">
|
||||
<number>1</number>
|
||||
<number>0</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="LogFiles">
|
||||
<widget class="QWidget" name="LogBoxFiles">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>727</width>
|
||||
<height>419</height>
|
||||
<width>722</width>
|
||||
<height>404</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
|
@ -96,11 +101,70 @@
|
|||
<attribute name="label">
|
||||
<string>Files</string>
|
||||
</attribute>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="2" rowspan="2">
|
||||
<widget class="QTextBrowser" name="textBrowser">
|
||||
<property name="layoutDirection">
|
||||
<enum>Qt::LeftToRight</enum>
|
||||
<layout class="QGridLayout" name="gridLayout_2">
|
||||
<item row="0" column="0" colspan="2">
|
||||
<widget class="QCheckBox" name="checkAllLogFiles">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Toggle/untoggle selection for all files</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>All</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="2">
|
||||
<spacer name="horizontalSpacer_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeType">
|
||||
<enum>QSizePolicy::Fixed</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>90</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="0" column="3">
|
||||
<widget class="QPushButton" name="buttonViewFile">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>36</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="font">
|
||||
<font>
|
||||
<pointsize>15</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Inspect a log file</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string></string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="4" rowspan="3">
|
||||
<widget class="QTextBrowser" name="textLogFiles">
|
||||
<property name="acceptDrops">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="lineWrapMode">
|
||||
<enum>QTextEdit::NoWrap</enum>
|
||||
|
@ -110,68 +174,177 @@
|
|||
<html><head><meta name="qrichtext" content="1" /><meta charset="utf-8" /><style type="text/css">
|
||||
p, li { white-space: pre-wrap; }
|
||||
hr { height: 1px; border-width: 0; }
|
||||
</style></head><body style=" font-family:'Noto Sans'; font-size:13pt; font-weight:400; font-style:normal;">
|
||||
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p></body></html></string>
|
||||
</style></head><body style=" font-family:'Noto Sans'; font-size:16pt; font-weight:400; font-style:normal;">
|
||||
<p align="center" style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:13pt;"><br /></p>
|
||||
<p align="center" style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:14pt;"><br /></p>
|
||||
<p align="center" style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:14pt;"><br /></p>
|
||||
<p align="center" style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:13pt;"><br /></p>
|
||||
<p align="center" style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:13pt;"><br /></p>
|
||||
<p align="center" style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:13pt;"><br /></p>
|
||||
<p align="center" style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:13pt;"><br /></p>
|
||||
<p align="center" style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:14pt; color:#6d6d6d;">Select a file from the list</span></p>
|
||||
<p align="center" style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:14pt; color:#6d6d6d;">to inspect its content</span></p></body></html></string>
|
||||
</property>
|
||||
<property name="openLinks">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QCheckBox" name="checkBox">
|
||||
<property name="text">
|
||||
<string>All</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QTreeWidget" name="treeWidget">
|
||||
<item row="1" column="0" colspan="4">
|
||||
<widget class="QTreeWidget" name="listLogFiles">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>256</width>
|
||||
<height>16777215</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="tabKeyNavigation">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="selectionMode">
|
||||
<enum>QAbstractItemView::SingleSelection</enum>
|
||||
</property>
|
||||
<property name="selectionBehavior">
|
||||
<enum>QAbstractItemView::SelectRows</enum>
|
||||
</property>
|
||||
<property name="sortingEnabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="animated">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="columnCount">
|
||||
<number>2</number>
|
||||
</property>
|
||||
<attribute name="headerVisible">
|
||||
<attribute name="headerMinimumSectionSize">
|
||||
<number>75</number>
|
||||
</attribute>
|
||||
<attribute name="headerDefaultSectionSize">
|
||||
<number>150</number>
|
||||
</attribute>
|
||||
<attribute name="headerStretchLastSection">
|
||||
<bool>true</bool>
|
||||
</attribute>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>Select</string>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Select/Deselect a log file</string>
|
||||
</property>
|
||||
<property name="textAlignment">
|
||||
<set>AlignLeading|AlignVCenter</set>
|
||||
<string>Name</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>Log Files</string>
|
||||
<string>Size</string>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Names of the log files in your logs folder</string>
|
||||
<property name="font">
|
||||
<font>
|
||||
<italic>false</italic>
|
||||
</font>
|
||||
</property>
|
||||
</column>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string notr="true">access.log.1</string>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string notr="true"/>
|
||||
</property>
|
||||
<property name="statusTip">
|
||||
<string notr="true"/>
|
||||
</property>
|
||||
<property name="whatsThis">
|
||||
<string notr="true"/>
|
||||
</property>
|
||||
<property name="font">
|
||||
<font>
|
||||
<pointsize>13</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
<property name="checkState">
|
||||
<enum>Unchecked</enum>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string notr="true">13.7 MB</string>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string notr="true"/>
|
||||
</property>
|
||||
<property name="statusTip">
|
||||
<string notr="true"/>
|
||||
</property>
|
||||
<property name="whatsThis">
|
||||
<string notr="true"/>
|
||||
</property>
|
||||
<property name="font">
|
||||
<font>
|
||||
<pointsize>13</pointsize>
|
||||
<italic>true</italic>
|
||||
<underline>false</underline>
|
||||
<strikeout>false</strikeout>
|
||||
</font>
|
||||
</property>
|
||||
<property name="flags">
|
||||
<set>ItemIsSelectable|ItemIsDragEnabled|ItemIsUserCheckable|ItemIsEnabled</set>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QPushButton" name="buttonRefreshList">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>32</width>
|
||||
<height>32</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="font">
|
||||
<font>
|
||||
<pointsize>13</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Refresh the list</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string></string>
|
||||
</property>
|
||||
<property name="flat">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1" colspan="3">
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeType">
|
||||
<enum>QSizePolicy::Fixed</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>224</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="LogArgs">
|
||||
<widget class="QWidget" name="LogBoxArgs">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>727</width>
|
||||
<height>419</height>
|
||||
<width>722</width>
|
||||
<height>404</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
|
@ -184,13 +357,13 @@ hr { height: 1px; border-width: 0; }
|
|||
<string>Options</string>
|
||||
</attribute>
|
||||
</widget>
|
||||
<widget class="QWidget" name="LogStart">
|
||||
<widget class="QWidget" name="LogBoxStart">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>727</width>
|
||||
<height>419</height>
|
||||
<width>722</width>
|
||||
<height>404</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
|
@ -215,7 +388,7 @@ hr { height: 1px; border-width: 0; }
|
|||
</sizepolicy>
|
||||
</property>
|
||||
<attribute name="title">
|
||||
<string>Statistics</string>
|
||||
<string></string>
|
||||
</attribute>
|
||||
<attribute name="toolTip">
|
||||
<string>View your statisticsView your statistics</string>
|
||||
|
@ -239,7 +412,7 @@ hr { height: 1px; border-width: 0; }
|
|||
</sizepolicy>
|
||||
</property>
|
||||
<attribute name="title">
|
||||
<string>Update</string>
|
||||
<string></string>
|
||||
</attribute>
|
||||
<attribute name="toolTip">
|
||||
<string>Update Craplog</string>
|
||||
|
@ -253,7 +426,7 @@ hr { height: 1px; border-width: 0; }
|
|||
</sizepolicy>
|
||||
</property>
|
||||
<attribute name="title">
|
||||
<string>Settings</string>
|
||||
<string></string>
|
||||
</attribute>
|
||||
<attribute name="toolTip">
|
||||
<string>Configure Craplog</string>
|
||||
|
|
|
@ -0,0 +1,56 @@
|
|||
#include "craplog.h"
|
||||
|
||||
Craplog::Craplog()
|
||||
{
|
||||
this-> logs_path = "/var/log/apache2";
|
||||
//this-> readConfigs();
|
||||
this-> scanLogsDir();
|
||||
}
|
||||
|
||||
// return the list. rescan if fresh is true
|
||||
std::vector<Craplog::LogFile> Craplog::getLogsList( bool fresh )
|
||||
{
|
||||
if ( fresh == true ) {
|
||||
this->scanLogsDir();
|
||||
}
|
||||
return this-> logs_list;
|
||||
}
|
||||
|
||||
// return the path of the file matching the given name
|
||||
std::string Craplog::getLogFilePath( QString file_name )
|
||||
{
|
||||
std::string path;
|
||||
for ( Craplog::LogFile& item : this->logs_list ) {
|
||||
if ( item.name == file_name ) {
|
||||
path = item.path;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
// scan the logs path to update the log files list
|
||||
void Craplog::scanLogsDir()
|
||||
{
|
||||
this-> logs_list.clear();
|
||||
// iterate over entries in the logs folder
|
||||
for (auto const& dir_entry : std::filesystem::directory_iterator{this->logs_path}) {
|
||||
// get the attributes
|
||||
int size = dir_entry.file_size();
|
||||
std::string path = dir_entry.path().string();
|
||||
std::string name = dir_entry.path().filename().string();
|
||||
// match only files having ".log." in their name
|
||||
if ( ! dir_entry.is_regular_file()
|
||||
|| name.find(".log.") == -1 ) {
|
||||
continue;
|
||||
}
|
||||
// push in the list
|
||||
this-> logs_list.push_back(
|
||||
LogFile{
|
||||
.selected = false,
|
||||
.size = size,
|
||||
.name = QString::fromStdString( name ),
|
||||
.path = dir_entry.path().string(),
|
||||
});
|
||||
}
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
#ifndef CRAPLOG_H
|
||||
#define CRAPLOG_H
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <filesystem>
|
||||
|
||||
#include <QMainWindow>
|
||||
|
||||
|
||||
class Craplog
|
||||
{
|
||||
public:
|
||||
Craplog();
|
||||
|
||||
struct LogFile {
|
||||
bool selected;
|
||||
int size;
|
||||
QString name;
|
||||
std::string path;
|
||||
};
|
||||
std::vector<LogFile> getLogsList( bool fresh=false );
|
||||
std::string getLogFilePath( QString file_name );
|
||||
|
||||
private:
|
||||
std::string logs_path;
|
||||
std::vector<LogFile> logs_list;
|
||||
|
||||
void readConfigs();
|
||||
|
||||
void scanLogsDir();
|
||||
void loadFileContent();
|
||||
};
|
||||
|
||||
#endif // CRAPLOG_H
|
Loading…
Reference in New Issue