|
4 | 4 |
|
5 | 5 | cRenamerWindow::cRenamerWindow() |
6 | 6 | { |
7 | | - lstFiles = new cListWidget; |
8 | | - ckbRegex = new QCheckBox(tr("Use Regex")); |
9 | | - ckbRegex->setChecked(true); |
10 | | - layMain = new QGridLayout; |
11 | | - layBtns = new QHBoxLayout; |
12 | | - lblReplace = new QLabel(tr("Replace:")); |
13 | | - lblSearch = new QLabel(tr("Search:")); |
14 | | - lblStatus = new QLabel(tr("Drag and drop files/folders into the area above" |
15 | | - " to add them to your selection.")); |
16 | | - lblStatus->setWordWrap(true); |
17 | | - lblStatus->setAlignment(Qt::AlignHCenter); |
18 | | - txtReplace = new QLineEdit; |
19 | | - txtReplace->setAcceptDrops(false); |
20 | | - txtSearch = new QLineEdit; |
21 | | - txtSearch->setAcceptDrops(false); |
22 | | - btnClear = new QPushButton(tr("Clear List")); |
23 | | - btnReplace = new QPushButton(tr("Search and Replace")); |
| 7 | + lstFiles = new cListWidget; |
| 8 | + ckbRegex = new QCheckBox(tr("Use Regex")); |
| 9 | + ckbRegex->setChecked(true); |
| 10 | + layMain = new QGridLayout; |
| 11 | + layBtns = new QHBoxLayout; |
| 12 | + lblReplace = new QLabel(tr("Replace:")); |
| 13 | + lblSearch = new QLabel(tr("Search:")); |
| 14 | + lblStatus = new QLabel(tr("Drag and drop files/folders into the area above" |
| 15 | + " to add them to your selection.")); |
| 16 | + lblStatus->setWordWrap(true); |
| 17 | + lblStatus->setAlignment(Qt::AlignHCenter); |
| 18 | + txtReplace = new QLineEdit; |
| 19 | + txtReplace->setAcceptDrops(false); |
| 20 | + txtSearch = new QLineEdit; |
| 21 | + txtSearch->setAcceptDrops(false); |
| 22 | + btnClear = new QPushButton(tr("Clear List")); |
| 23 | + btnReplace = new QPushButton(tr("Search and Replace")); |
24 | 24 |
|
25 | | - connect(btnClear, SIGNAL(pressed()), lstFiles, SLOT(removeAll())); |
26 | | - connect(btnReplace, SIGNAL(pressed()), this, SLOT(replace())); |
| 25 | + connect(btnClear, SIGNAL(pressed()), lstFiles, SLOT(removeAll())); |
| 26 | + connect(btnReplace, SIGNAL(pressed()), this, SLOT(replace())); |
27 | 27 |
|
28 | | - layBtns->addWidget(ckbRegex); |
29 | | - layBtns->addStretch(); |
30 | | - layBtns->addWidget(btnClear); |
31 | | - layBtns->addWidget(btnReplace); |
| 28 | + layBtns->addWidget(ckbRegex); |
| 29 | + layBtns->addStretch(); |
| 30 | + layBtns->addWidget(btnClear); |
| 31 | + layBtns->addWidget(btnReplace); |
32 | 32 |
|
33 | | - layMain->addWidget(lstFiles, 0, 0, 1, 2); |
34 | | - layMain->addWidget(lblStatus, 1, 0, 1, 2); |
35 | | - layMain->addWidget(lblSearch); |
36 | | - layMain->addWidget(txtSearch); |
37 | | - layMain->addWidget(lblReplace); |
38 | | - layMain->addWidget(txtReplace); |
39 | | - layMain->addLayout(layBtns, 4, 0, 1, 2); |
| 33 | + layMain->addWidget(lstFiles, 0, 0, 1, 2); |
| 34 | + layMain->addWidget(lblStatus, 1, 0, 1, 2); |
| 35 | + layMain->addWidget(lblSearch); |
| 36 | + layMain->addWidget(txtSearch); |
| 37 | + layMain->addWidget(lblReplace); |
| 38 | + layMain->addWidget(txtReplace); |
| 39 | + layMain->addLayout(layBtns, 4, 0, 1, 2); |
40 | 40 |
|
41 | | - setLayout(layMain); |
42 | | - setWindowTitle(tr("Multi-File Renamer - v1.3")); |
43 | | - this->resize(600, 420); |
| 41 | + setLayout(layMain); |
| 42 | + setWindowTitle(tr("Multi-File Renamer - v1.3.1")); |
| 43 | + this->resize(600, 420); |
44 | 44 | } |
45 | 45 |
|
46 | 46 | void cRenamerWindow::replace() |
47 | 47 | { |
48 | | - QRegExp rxReplace(txtSearch->text(), Qt::CaseSensitive, QRegExp::RegExp); |
49 | | - if (!ckbRegex->checkState()) |
50 | | - rxReplace.setPatternSyntax(QRegExp::FixedString); |
51 | | - else if (!rxReplace.isValid()) { |
52 | | - lblStatus->setText(tr("There was an error in your regular expression" |
53 | | - " syntax. Please review it, and try again.")); |
54 | | - return; |
55 | | - } // if / else/if |
56 | | - QDir dir(tr("/")); |
57 | | - QString path, name, name2; |
58 | | - int i, size = lstFiles->rowCount(), errors = 0; |
59 | | - for (i = 0; i < size; ++i) { |
60 | | - name = name2 = lstFiles->item(i, 0)->text(); |
61 | | - if (rxReplace.indexIn(name) < 0) |
62 | | - continue; |
63 | | - path = lstFiles->item(i, 1)->text(); |
64 | | - name2.replace(rxReplace, txtReplace->text()); |
65 | | - if (name == name2) |
66 | | - continue; |
67 | | - dir.setPath(path); |
68 | | - if (dir.rename(path + name, path + name2)) |
69 | | - lstFiles->item(i, 0)->setText(name2); // also check if flagged for errors? |
70 | | - else { |
71 | | - ++errors; |
72 | | - // set error color/status |
73 | | - } // if / else |
74 | | - } // for |
75 | | - if (errors > 0) |
76 | | - lblStatus->setText(tr("There were unspecified errors durring the rename" |
77 | | - " process.")); |
78 | | - else |
79 | | - lblStatus->setText(tr("Rename operation completed successfully.")); |
80 | | - lstFiles->resizeColumnsToContents(); |
81 | | - lstFiles->resizeRowsToContents(); |
82 | | - lstFiles->horizontalHeader()->setStretchLastSection(true); |
| 48 | + QRegExp rxReplace(txtSearch->text(), Qt::CaseSensitive, QRegExp::RegExp); |
| 49 | + if (!ckbRegex->checkState()) |
| 50 | + rxReplace.setPatternSyntax(QRegExp::FixedString); |
| 51 | + else if (!rxReplace.isValid()) { |
| 52 | + lblStatus->setText(tr("There was an error in your regular expression" |
| 53 | + " syntax. Please review it, and try again.")); |
| 54 | + return; |
| 55 | + } // if / else/if |
| 56 | + QDir dir(tr("/")); |
| 57 | + QString path, name, name2; |
| 58 | + int i, size = lstFiles->rowCount(), errors = 0; |
| 59 | + for (i = 0; i < size; ++i) { |
| 60 | + name = name2 = lstFiles->item(i, 0)->text(); |
| 61 | + if (rxReplace.indexIn(name) < 0) |
| 62 | + continue; |
| 63 | + path = lstFiles->item(i, 1)->text(); |
| 64 | + name2.replace(rxReplace, txtReplace->text()); |
| 65 | + if (name == name2) |
| 66 | + continue; |
| 67 | + dir.setPath(path); |
| 68 | + if (dir.rename(path + name, path + name2)) |
| 69 | + lstFiles->item(i, 0)->setText(name2); // also check if flagged for errors? |
| 70 | + else { |
| 71 | + ++errors; |
| 72 | + // set error color/status |
| 73 | + } // if / else |
| 74 | + } // for |
| 75 | + if (errors > 0) |
| 76 | + lblStatus->setText(tr("There were unspecified errors durring the rename" |
| 77 | + " process.")); |
| 78 | + else |
| 79 | + lblStatus->setText(tr("Rename operation completed successfully.")); |
| 80 | + lstFiles->resizeColumnsToContents(); |
| 81 | + lstFiles->resizeRowsToContents(); |
| 82 | + lstFiles->horizontalHeader()->setStretchLastSection(true); |
83 | 83 | } |
84 | 84 |
|
85 | 85 | void cRenamerWindow::keyPressEvent(QKeyEvent *event) |
86 | 86 | { |
87 | | - switch (event->key()) { |
88 | | - case Qt::Key_Enter: |
89 | | - replace(); |
90 | | - break; |
91 | | - case Qt::Key_Delete: |
92 | | - lstFiles->removeSelected(); |
93 | | - break; |
94 | | - case Qt::Key_Escape: |
95 | | - close(); |
96 | | - break; |
97 | | - default: |
98 | | - return; |
99 | | - } // switch |
100 | | - event->accept(); |
| 87 | + switch (event->key()) { |
| 88 | + case Qt::Key_Enter: // enter key on number pad |
| 89 | + case Qt::Key_Return: // main enter/return key |
| 90 | + replace(); |
| 91 | + break; |
| 92 | + case Qt::Key_Delete: |
| 93 | + lstFiles->removeSelected(); |
| 94 | + break; |
| 95 | + case Qt::Key_Escape: |
| 96 | + close(); |
| 97 | + break; |
| 98 | + default: |
| 99 | + return; |
| 100 | + } // switch |
| 101 | + event->accept(); |
101 | 102 | } |
0 commit comments