Skip to content

Commit 5ea321e

Browse files
committed
Plugins::FtpServer: modify black and white filter list
1 parent e7efbf0 commit 5ea321e

File tree

3 files changed

+118
-21
lines changed

3 files changed

+118
-21
lines changed

Plugins/FtpServer/DlgSettings.cpp

Lines changed: 49 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,18 @@ CDlgSettings::CDlgSettings(QSharedPointer<CParameterFtpServer> para, QWidget *pa
5757
}
5858
}
5959

60+
m_szFilteListPrompt = tr("The IP address and the netmask must be separated by a slash (/).") + "\n\n"
61+
+ tr("ag:") + "\n"
62+
+ "- 123.123.123.123/n " + tr("where n is any value between 0 and 32") + "\n"
63+
+ "- 123.123.123.123/255.255.255.255" + "\n"
64+
+ "- <ipv6-address>/n " + tr("where n is any value between 0 and 128") + "\n\n"
65+
+ tr("For IP version 4, accepts as well missing trailing components") + "\n"
66+
+ tr("(i.e., less than 4 octets, like \"192.168.1\"), followed or not by a dot. ") + "\n"
67+
+ tr("If the netmask is also missing in that case,") + "\n"
68+
+ tr("it is set to the number of octets actually passed") + "\n"
69+
+ tr("(in the example above, it would be 24, for 3 octets).") + "\n\n"
70+
+ tr("Add IP address and the netmask:");
71+
6072
ui->lvBlacklist->setModel(&m_ModelBlack);
6173
check = connect(ui->lvBlacklist, SIGNAL(customContextMenuRequested(const QPoint&)),
6274
this, SLOT(slotBlackListContextMenuRequested(const QPoint&)));
@@ -137,17 +149,9 @@ void CDlgSettings::slotWhiteListContextMenuRequested(const QPoint& pos)
137149
QMenu m;
138150
QItemSelectionModel* pSelect = ui->lvWhtelist->selectionModel();
139151
QModelIndexList lstIndex = pSelect->selectedRows();
140-
m.addAction(tr("Add"), [this](){
141-
QString szIp = QInputDialog::getText(this, tr("Add whilte list"), tr("Add ip address:"));
142-
QStandardItem* item = new QStandardItem(szIp);
143-
m_ModelWhite.appendRow(item);
144-
});
152+
m.addAction(tr("Add"), this, SLOT(on_pbAddWhitelist_clicked()));
145153
if(!lstIndex.isEmpty()) {
146-
m.addAction(tr("Remove"), [this, lstIndex]() {
147-
foreach(auto idx, lstIndex) {
148-
m_ModelWhite.removeRow(idx.row());
149-
}
150-
});
154+
m.addAction(tr("Remove"), this, SLOT(on_pbDeleteWhitelist_clicked()));
151155
}
152156

153157
QPoint p = ui->lvWhtelist->mapToGlobal(pos);
@@ -159,19 +163,44 @@ void CDlgSettings::slotBlackListContextMenuRequested(const QPoint& pos)
159163
QMenu m;
160164
QItemSelectionModel* pSelect = ui->lvBlacklist->selectionModel();
161165
QModelIndexList lstIndex = pSelect->selectedRows();
162-
m.addAction(tr("Add"), [this](){
163-
QString szIp = QInputDialog::getText(this, tr("Add black list"), tr("Add ip address:"));
164-
QStandardItem* item = new QStandardItem(szIp);
165-
m_ModelBlack.appendRow(item);
166-
});
166+
m.addAction(tr("Add"), this, SLOT(on_pbAddBlacklist_clicked()));
167167
if(!lstIndex.isEmpty()) {
168-
m.addAction(tr("Remove"), [this, lstIndex]() {
169-
foreach(auto idx, lstIndex) {
170-
m_ModelBlack.removeRow(idx.row());
171-
}
172-
});
168+
m.addAction(tr("Remove"), this, SLOT(on_pbDeleteBlacklist_clicked()));
173169
}
174170

175171
QPoint p = ui->lvBlacklist->mapToGlobal(pos);
176172
m.exec(p);
177173
}
174+
175+
void CDlgSettings::on_pbAddWhitelist_clicked()
176+
{
177+
QString szIp = QInputDialog::getText(this, tr("Add whilte list"), m_szFilteListPrompt);
178+
QStandardItem* item = new QStandardItem(szIp);
179+
m_ModelWhite.appendRow(item);
180+
}
181+
182+
void CDlgSettings::on_pbDeleteWhitelist_clicked()
183+
{
184+
QItemSelectionModel* pSelect = ui->lvBlacklist->selectionModel();
185+
QModelIndexList lstIndex = pSelect->selectedRows();
186+
foreach(auto idx, lstIndex) {
187+
m_ModelWhite.removeRow(idx.row());
188+
}
189+
}
190+
191+
void CDlgSettings::on_pbAddBlacklist_clicked()
192+
{
193+
QString szIp = QInputDialog::getText(this, tr("Add black list"), m_szFilteListPrompt);
194+
QStandardItem* item = new QStandardItem(szIp);
195+
m_ModelBlack.appendRow(item);
196+
}
197+
198+
void CDlgSettings::on_pbDeleteBlacklist_clicked()
199+
{
200+
QItemSelectionModel* pSelect = ui->lvBlacklist->selectionModel();
201+
if(!pSelect) return;
202+
QModelIndexList lstIndex = pSelect->selectedRows();
203+
foreach(auto idx, lstIndex) {
204+
m_ModelBlack.removeRow(idx.row());
205+
}
206+
}

Plugins/FtpServer/DlgSettings.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,16 @@ private Q_SLOTS:
2727
void on_cbListenAll_checkStateChanged(const Qt::CheckState &arg1);
2828
void slotWhiteListContextMenuRequested(const QPoint& pos);
2929
void slotBlackListContextMenuRequested(const QPoint& pos);
30+
void on_pbAddWhitelist_clicked();
31+
void on_pbDeleteWhitelist_clicked();
32+
void on_pbAddBlacklist_clicked();
33+
void on_pbDeleteBlacklist_clicked();
34+
3035
private:
3136
Ui::CDlgSettings *ui;
3237
QSharedPointer<CParameterFtpServer> m_Para;
3338
QStandardItemModel m_ModelNetWorkInterface;
3439
QStandardItemModel m_ModelBlack;
3540
QStandardItemModel m_ModelWhite;
41+
QString m_szFilteListPrompt;
3642
};

Plugins/FtpServer/DlgSettings.ui

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,20 +163,82 @@
163163
</property>
164164
</widget>
165165
</item>
166+
<item row="1" column="0">
167+
<layout class="QHBoxLayout" name="horizontalLayout">
168+
<item>
169+
<spacer name="horizontalSpacer">
170+
<property name="orientation">
171+
<enum>Qt::Orientation::Horizontal</enum>
172+
</property>
173+
<property name="sizeHint" stdset="0">
174+
<size>
175+
<width>40</width>
176+
<height>20</height>
177+
</size>
178+
</property>
179+
</spacer>
180+
</item>
181+
<item>
182+
<widget class="QPushButton" name="pbAddWhitelist">
183+
<property name="text">
184+
<string>Add</string>
185+
</property>
186+
</widget>
187+
</item>
188+
<item>
189+
<widget class="QPushButton" name="pbDeleteWhitelist">
190+
<property name="text">
191+
<string>Delete</string>
192+
</property>
193+
</widget>
194+
</item>
195+
</layout>
196+
</item>
166197
</layout>
167198
</widget>
168199
<widget class="QWidget" name="tab_5">
169200
<attribute name="title">
170201
<string>Blacklist</string>
171202
</attribute>
172-
<layout class="QGridLayout" name="gridLayout_3">
203+
<layout class="QGridLayout" name="gridLayout_5">
173204
<item row="0" column="0">
174205
<widget class="QListView" name="lvBlacklist">
175206
<property name="contextMenuPolicy">
176207
<enum>Qt::ContextMenuPolicy::CustomContextMenu</enum>
177208
</property>
178209
</widget>
179210
</item>
211+
<item row="1" column="0">
212+
<layout class="QGridLayout" name="gridLayout_3">
213+
<item row="0" column="2">
214+
<widget class="QPushButton" name="pbDeleteBlacklist">
215+
<property name="text">
216+
<string>Delete</string>
217+
</property>
218+
</widget>
219+
</item>
220+
<item row="0" column="1">
221+
<widget class="QPushButton" name="pbAddBlacklist">
222+
<property name="text">
223+
<string>Add</string>
224+
</property>
225+
</widget>
226+
</item>
227+
<item row="0" column="0">
228+
<spacer name="horizontalSpacer_2">
229+
<property name="orientation">
230+
<enum>Qt::Orientation::Horizontal</enum>
231+
</property>
232+
<property name="sizeHint" stdset="0">
233+
<size>
234+
<width>40</width>
235+
<height>20</height>
236+
</size>
237+
</property>
238+
</spacer>
239+
</item>
240+
</layout>
241+
</item>
180242
</layout>
181243
</widget>
182244
</widget>

0 commit comments

Comments
 (0)