-
Notifications
You must be signed in to change notification settings - Fork 0
/
settingsdialog.cpp
143 lines (132 loc) · 4.32 KB
/
settingsdialog.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
//------------------------------------------------------------------------------
// Home Office
// Nürnberg, Germany
// E-Mail: sergej1@email.ua
//
// Copyright (C) 2017/2018 free Project Crypto. All rights reserved.
//------------------------------------------------------------------------------
// Project: Crypto - Advanced File Encryptor, based on simple XOR and
// reliable AES methods
//------------------------------------------------------------------------------
/**
* @file settingsdialog.cpp
*
* @brief This file contains the definition of methods and interfaces of the SettingsDialog class.
*/
//------------------------------------------------------------------------------
// Includes
//------------------------------------------------------------------------------
#include "settingsdialog.h"
#include "ui_settingsdialog.h"
#include <QLoggingCategory>
//------------------------------------------------------------------------------
// Types
//------------------------------------------------------------------------------
Q_LOGGING_CATEGORY(logSettingsDialog, "settings")
/**
* @brief The constructor of the class SettingsDialog
*
* Sets default user interface parameters or uses saved values as parameters.
*
* @param parent of the type QWidget*
*/
SettingsDialog::SettingsDialog( QWidget *parent ) :
QDialog( parent ),
ui( new Ui::SettingsDialog )
{
Q_ASSERT( parent != nullptr );
ui->setupUi( this );
this->fillSettings();
ui->logBrowser->setLineWrapMode(QTextEdit::NoWrap);
ui->logBrowser->setStyleSheet( QString("font: 14px; color: blue") );
}
/**
* @brief The destructor of the class SettingsDialog
*/
SettingsDialog::~SettingsDialog()
{
delete ui;
}
/**
* @brief get-function for the settings
*
* @return *currentSettings of the type Settings*
*/
Settings* SettingsDialog::getSettings( void )
{
return &(this->currentSettings);
}
/**
* @brief The updateSettings function.
*
* This function updates the settings from the user interface in the Settings.
*/
void SettingsDialog::updateSettings( void )
{
//! @todo Alternative method to set default data!
this->currentSettings.enableLog = ui->enableLog->isChecked();
this->currentSettings.pathToLog = ui->logFile->text();
this->currentSettings.maxSizeLog = ui->maxSizeLog->text().toULong();
}
/**
* @brief The fillSettings function.
*
* @note Filling data from the configuration file. Alternative approach. Now it is disabled.
*/
void SettingsDialog::fillSettings( void )
{
//! @todo The method of checking and reading from the configuration file.
}
/**
* @brief The fillSettingsUi function.
*
* The function fills the Ui parameters that it takes from the Settings.
*/
void SettingsDialog::fillSettingsUi( void )
{
//! @todo Validation method for configuration data.
ui->enableLog->setChecked( currentSettings.enableLog );
ui->logFile->setText( currentSettings.pathToLog );
ui->logFile->setEnabled( currentSettings.enableLog );
ui->maxSizeLog->setText( QString::number(currentSettings.maxSizeLog) );
ui->maxSizeLog->setEnabled( currentSettings.enableLog );
ui->logBox->setTitle( QString( "Log file %1").arg( currentSettings.pathToLog ));
ui->logBrowser->setEnabled( currentSettings.enableLog );
if ( ui->logBrowser->source().isEmpty())
{
ui->logBrowser->setSource( QUrl::fromLocalFile( currentSettings.pathToLog ));
}
else if ( currentSettings.enableLog )
{
ui->logBrowser->reload();
}
}
/**
* @brief Slot on_buttonBox_accepted for confirmation and acceptance of changes in settings.
*/
void SettingsDialog::on_buttonBox_accepted( void )
{
if ( !ui->enableLog->isChecked() && currentSettings.enableLog )
{
qInfo( logSettingsDialog ) << "logging disabled";
}
else if ( ui->enableLog->isChecked() && !currentSettings.enableLog )
{
qInfo( logSettingsDialog ) << "logging enabled";
}
this->updateSettings();
this->hide();
}
/**
* @brief The on_enableLog_clicked slot for controlling user interface parameters.
*
* The other setting parameters are then hidden.
*
* @param checked of type bool. Checks whether logging is enabled.
*/
void SettingsDialog::on_enableLog_clicked( bool checked )
{
ui->logFile->setEnabled( checked );
ui->logBrowser->setEnabled( checked );
ui->maxSizeLog->setEnabled( checked );
}