-
Notifications
You must be signed in to change notification settings - Fork 0
/
mw.cpp
487 lines (470 loc) · 16 KB
/
mw.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
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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
#include "mw.h"
#include "ui_mw.h"
#include "about.h"
#include <QPushButton>
#include <QMessageBox>
#include <QTableWidget>
MW::MW(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MW)
{
//Set windows looking
ui->setupUi(this);
setWindowTitle("FreeSubtitleAssistant 0.1");
ui->RenameBtn->setStyleSheet("color:blue");
ui->LeftBrowser->setRowCount(100);
ui->RightBrowser->setRowCount(100);
ui->LeftBrowser->setColumnWidth(0, 200);
ui->LeftBrowser->setColumnWidth(1, 110);
ui->LeftBrowser->setColumnWidth(3, 100);
ui->RightBrowser->setColumnWidth(0, 200);
ui->RightBrowser->setColumnWidth(1, 110);
ui->RightBrowser->setColumnWidth(3, 100);
//select file and fill table
connect(ui->LeftOpenBtn, &QPushButton::clicked, [ = ]()
{
LeftFileList = QFileDialog::getOpenFileNames(this, "select file");
getLeftFileInfo();
FillLeftTable();
});
connect(ui->RightOpenBtn, &QPushButton::clicked, [ = ]()
{
RightFileList = QFileDialog::getOpenFileNames(this, "select file");
getRightFileInfo();
FillRightTable();
});
//check if table select
connect(ui->LeftBrowser, &QTableWidget::itemClicked, [ = ]()
{
LeftRow = ui->LeftBrowser->currentRow();
});
connect(ui->RightBrowser, &QTableWidget::itemClicked, [ = ]()
{
RightRow = ui->RightBrowser->currentRow();
});
//adjust file sequence
connect(ui->LeftUpBtn, &QPushButton::clicked, [ = ]()
{
UpLeftFile();
FillLeftTable();
});
connect(ui->LeftDnBtn, &QPushButton::clicked, [ = ]()
{
DownLeftFile();
FillLeftTable();
});
connect(ui->LeftReBtn, &QPushButton::clicked, [ = ]()
{
DelLeftFile();
FillLeftTable();
});
connect(ui->RightUpBtn, &QPushButton::clicked, [ = ]()
{
UpRightFile();
FillRightTable();
});
connect(ui->RightDnBtn, &QPushButton::clicked, [ = ]()
{
DownRightFile();
FillRightTable();
});
connect(ui->RightReBtn, &QPushButton::clicked, [ = ]()
{
DelRightFile();
FillRightTable();
});
//Clean selection
connect(ui->LeftCleanBtn, &QPushButton::clicked, [ = ]()
{
CleanLeft();
});
connect(ui->RightCleanBtn, &QPushButton::clicked, [ = ]()
{
CleanRight();
});
//Cover file name from left to right
connect(ui->RenameBtn, &QPushButton::clicked, [ = ]()
{
reName();
});
//show about window
connect(ui->About, &QAction::triggered, this, [ = ]()
{
about* aboutw = new about;
aboutw->show();
});
}
MW::~MW()
{
delete ui;
}
//---------------------------------------function area below---------------------------------//
void MW::getLeftFileInfo()
{
//traverse "LEFT" QStringList using iterator
for(QList<QString>::iterator i = LeftFileList.begin(); i != LeftFileList.end(); i++)
{
LeftFileInfo = QFileInfo(*i);
//acquire file FULL name
LeftFileFNames.push_back(LeftFileInfo.fileName());
//acquire file name before the last "."
LeftFileNames.push_back(LeftFileInfo.completeBaseName());
//acquire absolute path without file name
LeftFilePath.push_back(LeftFileInfo.absolutePath());
LeftFileSizes.push_back(QString::number(LeftFileInfo.size() / 1024) + "K");
LeftFileDates.push_back(LeftFileInfo.lastModified().toLocalTime());
}
}
void MW::getRightFileInfo()
{
for(QList<QString>::iterator i = RightFileList.begin(); i != RightFileList.end(); i++)
{
RightFileInfo = QFileInfo(*i);
//acquire file FULL name
RightFileFNames.push_back(RightFileInfo.fileName());
//acquire file extension name after the last "."
RightSuffix.push_back(RightFileInfo.suffix());
//acquire file name and absolute path
RightAbsFilePath.push_back(RightFileInfo.absoluteFilePath());
RightFileSizes.push_back(QString::number(RightFileInfo.size() / 1024) + "K");
RightFileDates.push_back(RightFileInfo.lastModified());
}
}
void MW::FillLeftTable()
{
// ui->LeftBrowser->setRowCount(LeftFileFNames.size());
//set table in-editable
ui->LeftBrowser->setEditTriggers(QAbstractItemView::NoEditTriggers);
for(int li = 0; li < LeftFileFNames.size(); li++)
{
ui->LeftBrowser->setItem(li, 0, new QTableWidgetItem(LeftFileFNames.at(li)));
ui->LeftBrowser->setItem(li, 1, new QTableWidgetItem(LeftFileDates.at(li).toString("yy/MM/dd hh:mm")));
ui->LeftBrowser->setItem(li, 2, new QTableWidgetItem(LeftFileSizes.at(li)));
}
}
void MW::FillRightTable()
{
// ui->RightBrowser->setRowCount(RightFileFNames.size());
//set table in-editable
ui->RightBrowser->setEditTriggers(QAbstractItemView::NoEditTriggers);
for(int ri = 0; ri < RightFileFNames.size(); ri++)
{
ui->RightBrowser->setItem(ri, 0, new QTableWidgetItem(RightFileFNames.at(ri)));
ui->RightBrowser->setItem(ri, 1, new QTableWidgetItem(RightFileDates.at(ri).toString("yy/MM/dd hh:mm")));
ui->RightBrowser->setItem(ri, 2, new QTableWidgetItem(RightFileSizes.at(ri)));
}
}
void MW::UpLeftFile()
{
//check if list if empty
if(LeftFileFNames.size() == 0)
{
//QMessageBox::critical(this, "Warning!", "Are you sure you selected any files? ", QMessageBox::Ok);
return;
}
//check if clicked
else if(LeftRow == -1)
{
//QMessageBox::critical(this, "Warning!", "Are you sure you selected any files? ", QMessageBox::Ok);
return;
}
//check if list is too short or reach the top
else if(LeftFileFNames.size() == 1 || LeftRow == 0 || LeftRow >= LeftFileFNames.size())
{
return;
}
else
{
//swap file full name
ltemStr = LeftFileFNames.at(LeftRow);
LeftFileFNames.replace(LeftRow, LeftFileFNames.at(LeftRow - 1));
LeftFileFNames.replace(LeftRow - 1, ltemStr);
//swap file base name
ltemStr = LeftFileNames.at(LeftRow);
LeftFileNames.replace(LeftRow, LeftFileNames.at(LeftRow - 1));
LeftFileNames.replace(LeftRow - 1, ltemStr);
//swap file path
ltemStr = LeftFilePath.at(LeftRow);
LeftFilePath.replace(LeftRow, LeftFilePath.at(LeftRow - 1));
LeftFilePath.replace(LeftRow - 1, ltemStr);
//swap file date
ltemDat = LeftFileDates.at(LeftRow);
LeftFileDates.replace(LeftRow, LeftFileDates.at(LeftRow - 1));
LeftFileDates.replace(LeftRow - 1, ltemDat);
//swap file size
ltemStr = LeftFileSizes.at(LeftRow);
LeftFileSizes.replace(LeftRow, LeftFileSizes.at(LeftRow - 1));
LeftFileSizes.replace(LeftRow - 1, ltemStr);
LeftRow--;
}
}
void MW::DownLeftFile()
{
//check if list if empty
if(LeftFileFNames.size() == 0)
{
//QMessageBox::critical(this, "Warning!", "Are you sure you selected any files? ", QMessageBox::Ok);
return;
}
//check if clicked
else if(LeftRow == -1)
{
//QMessageBox::critical(this, "Warning!", "Are you sure you selected any files? ", QMessageBox::Ok);
return;
}
//check if list is too short or reach the top
else if(LeftFileFNames.size() == 1 || LeftRow == LeftFileFNames.size() - 1 || LeftRow >= LeftFileFNames.size())
{
return;
}
else
{
//swap file full name
ltemStr = LeftFileFNames.at(LeftRow);
LeftFileFNames.replace(LeftRow, LeftFileFNames.at(LeftRow + 1));
LeftFileFNames.replace(LeftRow + 1, ltemStr);
//swap file base name
ltemStr = LeftFileNames.at(LeftRow);
LeftFileNames.replace(LeftRow, LeftFileNames.at(LeftRow + 1));
LeftFileNames.replace(LeftRow + 1, ltemStr);
//swap file path
ltemStr = LeftFilePath.at(LeftRow);
LeftFilePath.replace(LeftRow, LeftFilePath.at(LeftRow + 1));
LeftFilePath.replace(LeftRow + 1, ltemStr);
//swap file date
ltemDat = LeftFileDates.at(LeftRow);
LeftFileDates.replace(LeftRow, LeftFileDates.at(LeftRow + 1));
LeftFileDates.replace(LeftRow + 1, ltemDat);
//swap file size
ltemStr = LeftFileSizes.at(LeftRow);
LeftFileSizes.replace(LeftRow, LeftFileSizes.at(LeftRow + 1));
LeftFileSizes.replace(LeftRow + 1, ltemStr);
LeftRow++;
}
}
void MW::DelLeftFile()
{
//check if list if empty
if(LeftFileFNames.size() == 0)
{
//QMessageBox::critical(this, "Warning!", "Are you sure you selected any files? ", QMessageBox::Ok);
return;
}
//check if clicked
else if(LeftRow == -1 || LeftRow >= LeftFileFNames.size())
{
//QMessageBox::critical(this, "Warning!", "Are you sure you selected any files? ", QMessageBox::Ok);
return;
}
//check if list is too short
else if(LeftFileFNames.size() == 1)
{
CleanLeft();
return;
}
else
{
//remove file full name
LeftFileFNames.remove(LeftRow);
//remove file base name
LeftFileNames.remove(LeftRow);
//remove file path
LeftFilePath.remove(LeftRow);
//remove file date
LeftFileDates.remove(LeftRow);
//remove file size
LeftFileSizes.remove(LeftRow);
//remove the last row in file table
ui->LeftBrowser->removeRow(LeftFileFNames.size());
LeftRow = -1;
// qDebug()<<"right now the size is"<<LeftFileNames.size()<<endl;
}
}
void MW::UpRightFile()
{
//check if list if empty
if(RightFileFNames.size() == 0)
{
//QMessageBox::critical(this, "Warning!", "Are you sure you selected any files? ", QMessageBox::Ok);
return;
}
//check if clicked
else if(RightRow == -1)
{
//QMessageBox::critical(this, "Warning!", "Are you sure you selected any files? ", QMessageBox::Ok);
return;
}
//check if list is too short or reach the top
else if(RightFileFNames.size() == 1 || RightRow == 0 || RightRow >= RightFileFNames.size())
{
return;
}
else
{
//swap file full name
rtemStr = RightFileFNames.at(RightRow);
RightFileFNames.replace(RightRow, RightFileFNames.at(RightRow - 1));
RightFileFNames.replace(RightRow - 1, rtemStr);
//swap file extension name
rtemStr = RightSuffix.at(RightRow);
RightSuffix.replace(RightRow, RightSuffix.at(RightRow - 1));
RightSuffix.replace(RightRow - 1, rtemStr);
//swap file absolute file path
rtemStr = RightAbsFilePath.at(RightRow);
RightAbsFilePath.replace(RightRow, RightAbsFilePath.at(RightRow - 1));
RightAbsFilePath.replace(RightRow - 1, rtemStr);
//swap file date
rtemDat = RightFileDates.at(RightRow);
RightFileDates.replace(RightRow, RightFileDates.at(RightRow - 1));
RightFileDates.replace(RightRow - 1, rtemDat);
//swap file size
rtemStr = RightFileSizes.at(RightRow);
RightFileSizes.replace(RightRow, RightFileSizes.at(RightRow - 1));
RightFileSizes.replace(RightRow - 1, rtemStr);
RightRow--;
}
}
void MW::DownRightFile()
{
//check if list if empty
if(RightFileFNames.size() == 0)
{
//QMessageBox::critical(this, "Warning!", "Are you sure you selected any files? ", QMessageBox::Ok);
return;
}
//check if clicked
else if(RightRow == -1)
{
//QMessageBox::critical(this, "Warning!", "Are you sure you selected any files? ", QMessageBox::Ok);
return;
}
//check if list is too short or reach the top
else if(RightFileFNames.size() == 1 || RightRow == RightFileFNames.size() - 1 || RightRow >= RightFileFNames.size())
{
return;
}
else
{
//swap file full name
rtemStr = RightFileFNames.at(RightRow);
RightFileFNames.replace(RightRow, RightFileFNames.at(RightRow + 1));
RightFileFNames.replace(RightRow + 1, rtemStr);
//swap file extension name
rtemStr = RightSuffix.at(RightRow);
RightSuffix.replace(RightRow, RightSuffix.at(RightRow + 1));
RightSuffix.replace(RightRow + 1, rtemStr);
//swap file absolute file path
rtemStr = RightAbsFilePath.at(RightRow);
RightAbsFilePath.replace(RightRow, RightAbsFilePath.at(RightRow + 1));
RightAbsFilePath.replace(RightRow + 1, rtemStr);
//swap file date
rtemDat = RightFileDates.at(RightRow);
RightFileDates.replace(RightRow, RightFileDates.at(RightRow + 1));
RightFileDates.replace(RightRow + 1, rtemDat);
//swap file size
rtemStr = RightFileSizes.at(RightRow);
RightFileSizes.replace(RightRow, RightFileSizes.at(RightRow + 1));
RightFileSizes.replace(RightRow + 1, rtemStr);
RightRow++;
}
}
void MW::DelRightFile()
{
//check if list if empty
if(RightFileFNames.size() == 0)
{
//QMessageBox::critical(this, "Warning!", "Are you sure you selected any files? ", QMessageBox::Ok);
return;
}
//check if clicked
else if(RightRow == -1 || RightRow >= RightFileFNames.size())
{
//QMessageBox::critical(this, "Warning!", "Are you sure you selected any files? ", QMessageBox::Ok);
return;
}
//check if list is too short
else if(RightFileFNames.size() == 1)
{
CleanRight();
return;
}
else
{
//remove file full name
RightFileFNames.remove(RightRow);
//remove file Extension name
RightSuffix.remove(RightRow);
//remove absolute file path
RightAbsFilePath.remove(RightRow);
//remove file date
RightFileDates.remove(RightRow);
//remove file size
RightFileSizes.remove(RightRow);
//remove the last row in file table
ui->RightBrowser->removeRow(RightFileFNames.size());
RightRow = -1;
// qDebug()<<"right now the size is"<<LeftFileNames.size()<<endl;
}
}
void MW::CleanLeft()
{
ui->LeftBrowser->clearContents();
LeftFileList.clear();
LeftFileFNames.clear();
LeftFileNames.clear();
LeftFilePath.clear();
LeftFileSizes.clear();
LeftFileDates.clear();
LeftRow = -1;
}
void MW::CleanRight()
{
ui->RightBrowser->clearContents();
RightFileList.clear();
RightFileFNames.clear();
RightSuffix.clear();
RightAbsFilePath.clear();
RightFileSizes.clear();
RightFileDates.clear();
RightRow = -1;
}
void MW::reName()
{
//qDebug()<<"the list is"<<LeftFileFNames.size()<<endl;
//check if both list empty
if(LeftFileFNames.empty() && RightFileFNames.empty())
{
QMessageBox::critical(this, "Warning!", "Are you sure you selected any files? ", QMessageBox::Ok);
return;
}
//check if file quantites of both lists as same
else if(LeftFileFNames.size() != RightFileFNames.size())
{
QMessageBox::critical(this, "Warning!", "You have to select same quantity files! ", QMessageBox::Ok);
return;
}
else
{
for(int i = 0; i < LeftFileFNames.size(); i++)
{
QFile f((RightAbsFilePath.at(i)));
qDebug() << RightAbsFilePath.at(i);
renamebool = f.rename(LeftFilePath.at(i) + "/" + LeftFileNames.at(i) + "." + RightSuffix.at(i));
qDebug() << renamebool << Qt::endl;
}
if(renamebool == true)
{
QMessageBox::about(this, "Done!", "Renaming completed!");
CleanLeft();
CleanRight();
return;
}
else
{
QMessageBox::critical(this, "Warning!", "Looks not working...");
CleanLeft();
CleanRight();
return;
}
}
}