-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdialogdelete.cpp
More file actions
232 lines (193 loc) · 5.31 KB
/
Copy pathdialogdelete.cpp
File metadata and controls
232 lines (193 loc) · 5.31 KB
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
#include "dialogdelete.h"
/*!
* \brief DialogDelete::init_var
*
* Initilisation of DialogDelete variables
*/
void DialogDelete::init_var(){
if (DEBUG) cout << Q_FUNC_INFO << endl;
//Grid
grid = new QGridLayout;
//List
patient_list = new QListWidget(this);
//Button
button_load = new QPushButton(this);
button_delete = new QPushButton(this);
button_quit = new QPushButton(this);
//String
dir = EMPTY_STRING;
}
/*!
* \brief DialogDelete::init_win
*
* Initialisation of DialogDelete window
*/
void DialogDelete::init_win(){
if (DEBUG) cout << Q_FUNC_INFO << endl;
//Window
setWindowTitle(DIALOG_DELETE_TITLE);
//Button
button_load->setText(DIALOG_DELETE_LOAD);
button_delete->setText(DIALOG_DELETE_DELETE);
button_quit->setText(DIALOG_DELETE_QUIT);
//List
patient_list->setSelectionMode(QAbstractItemView::MultiSelection);
//Grid
setLayout(grid);
grid->addWidget(button_load);
grid->addWidget(patient_list);
grid->addWidget(button_delete);
grid->addWidget(button_quit);
}
/*!
* \brief DialogDelete::init_sig
*
* Initialisation of DialogDelete signals
*/
void DialogDelete::init_sig(){
if (DEBUG) cout << Q_FUNC_INFO << endl;
connect(button_load, SIGNAL(clicked()), this, SLOT(load_patients()));
connect(button_delete, SIGNAL(clicked()), this, SLOT(delete_patient()));
connect(button_quit, SIGNAL(clicked()), this, SLOT(quit()));
}
/*!
* \brief DialogDelete::init_css
*
* Initialisation of DialogDelete style sheet
*/
void DialogDelete::init_css(){
if (DEBUG) cout << Q_FUNC_INFO << endl;
setStyleSheet(CSS_DIALOG);
//Button
button_load->setStyleSheet(CSS_BUTTON);
button_delete->setStyleSheet(CSS_BUTTON);
button_quit->setStyleSheet(CSS_BUTTON);
}
/*!
* \brief DialogDelete::DialogDelete
* \param parent
*
* DialogDelete
*/
DialogDelete::DialogDelete(QWidget *parent) :
QDialog(parent)
{
if (DEBUG) cout << Q_FUNC_INFO << endl;
init_var();
init_win();
init_sig();
init_css();
}
/*!
* \brief DialogDelete::load_patients
*
* Load patients's list
*
* This function is only for connect to button_load. Refer to load_patients(QString dir_tmp)
*/
void DialogDelete::load_patients(){
if (DEBUG) cout << Q_FUNC_INFO << endl;
load_patients(EMPTY_STRING);
}
/*!
* \brief DialogDelete::load_patients
* \param dir_tmp Patients' directory
*
* Load patients' list
*
* LINUX/MACOS/WINDOWS
*/
void DialogDelete::load_patients(QString dir_tmp){
if (DEBUG) cout << Q_FUNC_INFO << endl;
if (dir_tmp.isEmpty()){
dir_tmp = QFileDialog::getExistingDirectory(this, DIALOG_DELETE_PATIENT_TXT, GLOBAL_DIR);
}
if (!dir_tmp.isEmpty()){
dir = QString(dir_tmp);
//Count and check
#ifdef LINUX_OS
QString command = "ls " + dir + " > " + QString(SYSTEM_DIR) + QString(DIALOG_DELETE_PATIENT_FILE);
#endif
#ifdef MAC_OS
QString command = "ls " + dir + " > " + QString(SYSTEM_DIR) + QString(DIALOG_DELETE_PATIENT_FILE);
#endif
#ifdef WIN_OS
dir.replace(UNIX_DIR_SEPARATOR, WINDOWS_DIR_SEPARATOR);
QString command = "dir /B /A:D " + dir + " > " + QString(SYSTEM_DIR) + QString(DIALOG_DELETE_PATIENT_FILE);
#endif
int res = system(command.toStdString().c_str());
if (res){
QMessageBox::critical(this, DELETE_ERROR_001_N, DELETE_ERROR_001);
}
QFile file(QString(SYSTEM_DIR) + QString(DIALOG_DELETE_PATIENT_FILE));
if (file.open(QIODevice::ReadOnly)){
while(!file.atEnd()){
QString tmp = file.readLine();
tmp.remove(UNIX_NEW_LINE).remove(WINDOWS_NEW_LINE);
if (!tmp.contains(CSV_EXTENSION)){
patient_list->addItem(tmp);
}
}
file.close();
}
else{
QMessageBox::critical(this, DELETE_ERROR_001_N, DELETE_ERROR_001);
}
}
}
/*!
* \brief DialogDelete::delete_patient
*
* Delete selected patient(s)
*
* LINUX/MACOS/WINDOWS
*/
void DialogDelete::delete_patient(){
if (DEBUG) cout << Q_FUNC_INFO << endl;
int n = patient_list->count();
for (int i = 0; i < n; i++){
if (patient_list->item(i)->isSelected()){
#ifdef LINUX_OS
QString command = "rm -r " + dir + DIR_SEPARATOR + patient_list->item(i)->text();
#endif
#ifdef MAC_OS
QString command = "rm -r " + dir + DIR_SEPARATOR + patient_list->item(i)->text();
#endif
#ifdef WIN_OS
QString command = "rmdir /S /Q " + dir + DIR_SEPARATOR + patient_list->item(i)->text();
#endif
int res = system(command.toStdString().c_str());
if (res){
QMessageBox::critical(this, DELETE_ERROR_002_N, DELETE_ERROR_002);
}
}
}
update();
}
/*!
* \brief DialogDelete::update
*
* Update patients' list
*/
void DialogDelete::update(){
if (DEBUG) cout << Q_FUNC_INFO << endl;
patient_list->clear();
load_patients(dir);
}
/*!
* \brief DialogDelete::quit
*
* Quit DialogDelete
*/
void DialogDelete::quit(){
if (DEBUG) cout << Q_FUNC_INFO << endl;
accept();
}
/*!
* \brief DialogDelete::closeEvent
*
* REIMPLEMENTED Quit DialogDelete by red-cross click
*/
void DialogDelete::closeEvent(QCloseEvent *){
if (DEBUG) cout << Q_FUNC_INFO << " -- REIMPLEMENTED" << endl;
}