-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainwindow.cpp
135 lines (111 loc) · 3.17 KB
/
mainwindow.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
#include "mainwindow.h"
#include "./ui_mainwindow.h"
#include "./settingsdialog.h"
#include "./aboutdialog.h"
#include <string>
#include "./ClipboardXX.hpp"
#include <iostream>
#include <QDebug>
#include <QMessageBox>
using namespace std;
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
ui -> lEditProjectDirName -> setVisible(false);
initializeDefaultSettings();
}
MainWindow::~MainWindow()
{
delete ui;
delete settings;
}
void MainWindow::initializeDefaultSettings(){
qDebug("settings->loadSettings()[0] : %d\n", settings->loadSettings()[0]);
// if first run
if(!settings->loadSettings()[0]){
settings->saveSettings(true, false, true, true);
qDebug("Initialized default settings!");
}
else{
qDebug("Default settings already initialized!");
}
}
// button clicked events
void MainWindow::on_btnAnonymize_clicked()
{
validateAnonymize();
}
void MainWindow::on_btnCopyToClipboard_clicked()
{
copyTextToClipboard();
}
// menu action trigger events
void MainWindow::on_actionSettings_triggered()
{
SettingsDialog settingstDialog;
settingstDialog.setModal(true);
settingstDialog.exec();
}
void MainWindow::on_actionExit_triggered()
{
this -> close();
}
void MainWindow::on_actionAnonymize_triggered()
{
validateAnonymize();
}
void MainWindow::on_actionClear_triggered()
{
ui -> pTxtEditInput -> clear();
ui -> pTxtEditOutput -> clear();
}
void MainWindow::on_actionCopy_to_Clipboard_triggered()
{
copyTextToClipboard();
}
void MainWindow::on_actionAbout_triggered()
// checkbox state change events
{
AboutDialog aboutDialog;
aboutDialog.setModal(true);
aboutDialog.exec();
}
void MainWindow::on_cbHideProjectName_stateChanged(int cbState)
{
qDebug("cb state change %d", cbState);
if(cbState==2){
ui -> lEditProjectDirName -> setVisible(true);
}
else if(cbState == 0){
ui -> lEditProjectDirName -> setText("");
ui -> lEditProjectDirName -> setVisible(false);
}
}
// reusable UI methods
void MainWindow::showProjectNameEmptyErrorMessage(){
QMessageBox msgBox;
msgBox.setIcon(QMessageBox::Critical);
msgBox.setWindowTitle("Error");
msgBox.setText("Please fill in the project directory name");
msgBox.exec();
}
void MainWindow::copyTextToClipboard(){
CClipboardXX clipboard;
QString anonymizedLogText = ui -> pTxtEditOutput -> toPlainText();
string stdString = anonymizedLogText.toStdString();
clipboard << stdString;
qDebug("Following annonymized log were copied to the clipboard : \n %s", stdString.c_str());
}
void MainWindow::anonymizeInputDisplayOutput(){
string input = ui-> pTxtEditInput -> toPlainText().toStdString();
string projectName = ui -> lEditProjectDirName -> text().toStdString();
string output = anonymizer.anonymize(input, projectName);
ui -> pTxtEditOutput -> setPlainText(QString::fromStdString(output));
}
void MainWindow::validateAnonymize(){
(ui->cbHideProjectName -> isChecked() && ui->lEditProjectDirName -> text().isEmpty())?
showProjectNameEmptyErrorMessage():
anonymizeInputDisplayOutput();
}