Added fonts. Updated LogsFiles interface
This commit is contained in:
parent
e3512b7dce
commit
8db83079a1
|
@ -26,6 +26,7 @@ set(PROJECT_SOURCES
|
|||
mainwindow.ui
|
||||
window/craplog.h
|
||||
window/craplog.cpp
|
||||
resources/resources.qrc
|
||||
${TS_FILES}
|
||||
)
|
||||
|
||||
|
|
|
@ -5,10 +5,31 @@ MainWindow::MainWindow(QWidget *parent)
|
|||
: QMainWindow(parent)
|
||||
, ui(new Ui::MainWindow)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
//craplog.scanLogsDir();
|
||||
ui->listLogFiles->header()->resizeSection(0,160);
|
||||
ui->listLogFiles->header()->resizeSection(1,75);
|
||||
this->ui->setupUi(this);
|
||||
|
||||
// initialize the colors map
|
||||
this->COLORS["black"] = QColor(0,0,0,255);
|
||||
this->COLORS["grey"] = QColor(127,127,127,255);
|
||||
this->COLORS["white"] = QColor(255,255,255,255);
|
||||
|
||||
// define text sizes
|
||||
this->font_size = 13;
|
||||
this->font_size_big = 16;
|
||||
this->font_size_small = 10;
|
||||
// load the main font
|
||||
QString main_font_family = QFontDatabase::applicationFontFamilies(
|
||||
QFontDatabase::addApplicationFont(":/fonts/Metropolis")).at(0);
|
||||
// load the script font
|
||||
QString script_font_family = QFontDatabase::applicationFontFamilies(
|
||||
QFontDatabase::addApplicationFont(":/fonts/3270")).at(0);
|
||||
// initialize the fonts map
|
||||
this->FONTS["main"] = QFont( main_font_family, this->font_size );
|
||||
this->FONTS["main_italic"] = QFont( main_font_family, this->font_size, -1, true );
|
||||
this->FONTS["script"] = QFont( script_font_family, this->font_size );
|
||||
|
||||
// get a fresh list of log files
|
||||
this->ui->listLogFiles->header()->resizeSection(0,200);
|
||||
this->ui->listLogFiles->header()->resizeSection(1,100);
|
||||
this->on_buttonRefreshList_clicked();
|
||||
}
|
||||
|
||||
|
@ -25,8 +46,6 @@ 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
|
||||
|
@ -35,6 +54,7 @@ void MainWindow::on_buttonRefreshList_clicked()
|
|||
item->setCheckState(0, Qt::CheckState::Unchecked );
|
||||
// name to be showed
|
||||
item-> setText( 0, log_file.name );
|
||||
item->setFont( 0, this->FONTS["main"] );
|
||||
// size to be showed
|
||||
float size = (float)log_file.size / 1024;
|
||||
int n_decimals = 3;
|
||||
|
@ -68,8 +88,9 @@ void MainWindow::on_buttonRefreshList_clicked()
|
|||
}
|
||||
}
|
||||
// apply text and color
|
||||
item-> setText( 1, QString::fromStdString( size_str.substr(0,point_i) + sfx ) );
|
||||
item->setForeground(1, grey);
|
||||
item->setText( 1, QString::fromStdString( size_str.substr(0,point_i) + sfx ) );
|
||||
item->setForeground( 1, this->COLORS["grey"] );
|
||||
item->setFont( 1, this->FONTS["main_italic"] );
|
||||
// append the item (on top, forced)
|
||||
this->ui->listLogFiles->addTopLevelItem( item );
|
||||
}
|
||||
|
@ -80,9 +101,21 @@ void MainWindow::on_buttonRefreshList_clicked()
|
|||
|
||||
void MainWindow::on_checkAllLogFiles_stateChanged(int arg1)
|
||||
{
|
||||
Qt::CheckState new_state;
|
||||
if ( this->ui->checkAllLogFiles->checkState() == Qt::CheckState::Checked ) {
|
||||
// check all
|
||||
new_state = Qt::CheckState::Checked;
|
||||
} else if ( this->ui->checkAllLogFiles->checkState() == Qt::CheckState::Unchecked ) {
|
||||
// un-check all
|
||||
new_state = Qt::CheckState::Unchecked;
|
||||
} else {
|
||||
// do nothing
|
||||
return;
|
||||
}
|
||||
QTreeWidgetItemIterator i(this->ui->listLogFiles);
|
||||
while ( *i ) {
|
||||
(*i)->setCheckState( 0, Qt::CheckState::Checked );
|
||||
(*i)->setCheckState( 0, new_state );
|
||||
++i;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -95,6 +128,60 @@ void MainWindow::on_buttonViewFile_clicked()
|
|||
|
||||
void MainWindow::on_listLogFiles_itemDoubleClicked(QTreeWidgetItem *item, int column)
|
||||
{
|
||||
|
||||
this->on_buttonViewFile_clicked();
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::on_listLogFiles_itemChanged(QTreeWidgetItem *item, int column)
|
||||
{
|
||||
// control checked
|
||||
int n_checked = 0;
|
||||
QTreeWidgetItemIterator i(this->ui->listLogFiles);
|
||||
while ( *i ) {
|
||||
if ( (*i)->checkState(0) == Qt::CheckState::Checked ) {
|
||||
n_checked++;
|
||||
}
|
||||
++i;
|
||||
}
|
||||
if ( n_checked == 0 ) {
|
||||
this->ui->checkAllLogFiles->setCheckState(Qt::CheckState::Unchecked);
|
||||
} else if ( n_checked == this->craplog.getLogsListSize() ) {
|
||||
this->ui->checkAllLogFiles->setCheckState(Qt::CheckState::Checked);
|
||||
} else {
|
||||
this->ui->checkAllLogFiles->setCheckState(Qt::CheckState::PartiallyChecked);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool MainWindow::runCraplog()
|
||||
{
|
||||
// feed craplog with the checked values
|
||||
bool proceed = true;
|
||||
QTreeWidgetItemIterator i(this->ui->listLogFiles);
|
||||
while ( *i ) {
|
||||
if ( (*i)->checkState(0) == Qt::CheckState::Checked ) {
|
||||
// tell Craplog to set this file as selected
|
||||
if ( this->craplog.setLogFileSelected( (*i)->text(0) ) != 0 ) {
|
||||
// this shouldn't be, but...
|
||||
int response = QMessageBox::warning(this,
|
||||
QString("File selection failed"),
|
||||
QString("No file in the list matching this name:\n%1\n\nContinue?")
|
||||
.arg( (*i)->text(0) ),
|
||||
QMessageBox::Abort | QMessageBox::Ignore );
|
||||
if ( response == QMessageBox::Abort ) {
|
||||
proceed = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
++i;
|
||||
}
|
||||
if ( proceed == false ) {
|
||||
return proceed;
|
||||
}
|
||||
|
||||
|
||||
|
||||
return proceed;
|
||||
}
|
||||
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
#define MAINWINDOW_H
|
||||
|
||||
#include <QMainWindow>
|
||||
#include <QFontDatabase>
|
||||
#include <QMessageBox>
|
||||
|
||||
#include "./window/craplog.h"
|
||||
#include "qtreewidget.h"
|
||||
|
@ -27,8 +29,18 @@ private slots:
|
|||
|
||||
void on_listLogFiles_itemDoubleClicked(QTreeWidgetItem *item, int column);
|
||||
|
||||
void on_listLogFiles_itemChanged(QTreeWidgetItem *item, int column);
|
||||
|
||||
private:
|
||||
Ui::MainWindow *ui;
|
||||
Craplog craplog;
|
||||
|
||||
bool runCraplog();
|
||||
|
||||
std::unordered_map<std::string, QColor> COLORS;
|
||||
std::unordered_map<std::string, QFont> FONTS;
|
||||
QString font_name;
|
||||
int font_size, font_size_big, font_size_small;
|
||||
QFont main_font;
|
||||
};
|
||||
#endif // MAINWINDOW_H
|
||||
|
|
|
@ -47,7 +47,7 @@
|
|||
<enum>QTabWidget::West</enum>
|
||||
</property>
|
||||
<property name="currentIndex">
|
||||
<number>3</number>
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="movable">
|
||||
<bool>true</bool>
|
||||
|
@ -80,8 +80,8 @@
|
|||
<property name="focusPolicy">
|
||||
<enum>Qt::NoFocus</enum>
|
||||
</property>
|
||||
<property name="currentIndex">
|
||||
<number>0</number>
|
||||
<property name="tabSpacing">
|
||||
<number>9</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="LogBoxFiles">
|
||||
<property name="geometry">
|
||||
|
@ -89,7 +89,7 @@
|
|||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>722</width>
|
||||
<height>404</height>
|
||||
<height>395</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
|
@ -101,6 +101,9 @@
|
|||
<attribute name="label">
|
||||
<string>Files</string>
|
||||
</attribute>
|
||||
<attribute name="toolTip">
|
||||
<string>Select which log files to use</string>
|
||||
</attribute>
|
||||
<layout class="QGridLayout" name="gridLayout_2">
|
||||
<item row="0" column="0" colspan="2">
|
||||
<widget class="QCheckBox" name="checkAllLogFiles">
|
||||
|
@ -200,7 +203,7 @@ hr { height: 1px; border-width: 0; }
|
|||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>256</width>
|
||||
<width>320</width>
|
||||
<height>16777215</height>
|
||||
</size>
|
||||
</property>
|
||||
|
@ -232,6 +235,11 @@ hr { height: 1px; border-width: 0; }
|
|||
<property name="text">
|
||||
<string>Name</string>
|
||||
</property>
|
||||
<property name="font">
|
||||
<font>
|
||||
<pointsize>12</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
|
@ -239,6 +247,7 @@ hr { height: 1px; border-width: 0; }
|
|||
</property>
|
||||
<property name="font">
|
||||
<font>
|
||||
<pointsize>12</pointsize>
|
||||
<italic>false</italic>
|
||||
</font>
|
||||
</property>
|
||||
|
@ -258,7 +267,7 @@ hr { height: 1px; border-width: 0; }
|
|||
</property>
|
||||
<property name="font">
|
||||
<font>
|
||||
<pointsize>13</pointsize>
|
||||
<pointsize>12</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
<property name="checkState">
|
||||
|
@ -278,7 +287,7 @@ hr { height: 1px; border-width: 0; }
|
|||
</property>
|
||||
<property name="font">
|
||||
<font>
|
||||
<pointsize>13</pointsize>
|
||||
<pointsize>12</pointsize>
|
||||
<italic>true</italic>
|
||||
<underline>false</underline>
|
||||
<strikeout>false</strikeout>
|
||||
|
@ -330,7 +339,7 @@ hr { height: 1px; border-width: 0; }
|
|||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>224</width>
|
||||
<width>288</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
|
@ -344,7 +353,7 @@ hr { height: 1px; border-width: 0; }
|
|||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>722</width>
|
||||
<height>404</height>
|
||||
<height>395</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
|
@ -356,6 +365,9 @@ hr { height: 1px; border-width: 0; }
|
|||
<attribute name="label">
|
||||
<string>Options</string>
|
||||
</attribute>
|
||||
<attribute name="toolTip">
|
||||
<string>Define the options to apply while parsing logs</string>
|
||||
</attribute>
|
||||
</widget>
|
||||
<widget class="QWidget" name="LogBoxStart">
|
||||
<property name="geometry">
|
||||
|
@ -363,7 +375,7 @@ hr { height: 1px; border-width: 0; }
|
|||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>722</width>
|
||||
<height>404</height>
|
||||
<height>395</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
|
|
|
@ -2,9 +2,15 @@
|
|||
|
||||
Craplog::Craplog()
|
||||
{
|
||||
this-> logs_path = "/var/log/apache2";
|
||||
//this-> readConfigs();
|
||||
this-> scanLogsDir();
|
||||
this->logs_path = "/var/log/apache2";
|
||||
//this->readConfigs();
|
||||
this->scanLogsDir();
|
||||
}
|
||||
|
||||
|
||||
// return the size of the list
|
||||
int Craplog::getLogsListSize() {
|
||||
return this->logs_list.size();
|
||||
}
|
||||
|
||||
// return the list. rescan if fresh is true
|
||||
|
@ -13,9 +19,10 @@ std::vector<Craplog::LogFile> Craplog::getLogsList( bool fresh )
|
|||
if ( fresh == true ) {
|
||||
this->scanLogsDir();
|
||||
}
|
||||
return this-> logs_list;
|
||||
return this->logs_list;
|
||||
}
|
||||
|
||||
|
||||
// return the path of the file matching the given name
|
||||
std::string Craplog::getLogFilePath( QString file_name )
|
||||
{
|
||||
|
@ -29,10 +36,24 @@ std::string Craplog::getLogFilePath( QString file_name )
|
|||
return path;
|
||||
}
|
||||
|
||||
// set a file as selected
|
||||
int Craplog::setLogFileSelected( QString file_name )
|
||||
{
|
||||
int result = 1;
|
||||
for ( Craplog::LogFile& item : this->logs_list ) {
|
||||
if ( item.name == file_name ) {
|
||||
item.selected = true;
|
||||
result = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// scan the logs path to update the log files list
|
||||
void Craplog::scanLogsDir()
|
||||
{
|
||||
this-> logs_list.clear();
|
||||
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
|
||||
|
@ -45,7 +66,7 @@ void Craplog::scanLogsDir()
|
|||
continue;
|
||||
}
|
||||
// push in the list
|
||||
this-> logs_list.push_back(
|
||||
this->logs_list.push_back(
|
||||
LogFile{
|
||||
.selected = false,
|
||||
.size = size,
|
||||
|
|
|
@ -23,7 +23,9 @@ public:
|
|||
std::string path;
|
||||
};
|
||||
std::vector<LogFile> getLogsList( bool fresh=false );
|
||||
int getLogsListSize();
|
||||
std::string getLogFilePath( QString file_name );
|
||||
int setLogFileSelected( QString file_name );
|
||||
|
||||
private:
|
||||
std::string logs_path;
|
||||
|
|
Loading…
Reference in New Issue