5#include <QLoggingCategory>
6#include <QStandardItem>
7#include <QNetworkInterface>
10#include "DlgSettings.h"
11#include "ui_DlgSettings.h"
13static Q_LOGGING_CATEGORY(log,
"FtpServer.DlgSettings")
23 ui->sbPort->setValue(m_Para->GetPort());
24 ui->leUser->setText(m_Para->GetUser());
25 ui->lePassword->setText(m_Para->GetPassword());
26 ui->leRoot->setText(m_Para->GetRoot());
27 ui->cbAnonmousLogin->setChecked(m_Para->GetAnonymousLogin());
28 ui->cbReadOnly->setChecked(m_Para->GetReadOnly());
29 ui->sbConnectCount->setValue(m_Para->GetConnectCount());
30 ui->sbConnectCount->setToolTip(tr(
"-1: Enable all\n 0: Disable all\n>0: Connect count"));
32 ui->cbListenAll->setChecked(m_Para->GetListenAll());
33 ui->lvListen->setModel(&m_ModelNetWorkInterface);
34 foreach(
auto iface, QNetworkInterface::allInterfaces()) {
36 auto entry = iface.addressEntries();
37 if(iface.flags() & QNetworkInterface::IsLoopBack)
41 foreach(
auto e, entry) {
42 if(!e.broadcast().isNull()) {
43 QStandardItem* item =
new QStandardItem(e.ip().toString());
44 item->setCheckable(
true);
45 m_ModelNetWorkInterface.appendRow(item);
49 foreach(
auto ip, m_Para->GetListen()) {
50 for (
int row = 0; row < m_ModelNetWorkInterface.rowCount(); row++) {
51 QModelIndex index = m_ModelNetWorkInterface.index(row, 0);
52 QString szIp = m_ModelNetWorkInterface.data(index).toString();
54 m_ModelNetWorkInterface.item(row)->setCheckState(Qt::Checked);
60 m_szFilteListPrompt = tr(
"The IP address and the netmask must be separated by a slash (/).") +
"\n\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:");
72 ui->lvBlacklist->setModel(&m_ModelBlack);
73 check = connect(ui->lvBlacklist, SIGNAL(customContextMenuRequested(
const QPoint&)),
74 this, SLOT(slotBlackListContextMenuRequested(
const QPoint&)));
76 foreach (
auto ip, m_Para->GetBlacklist()) {
77 m_ModelBlack.appendRow(
new QStandardItem(ip));
79 ui->lvWhtelist->setModel(&m_ModelWhite);
80 check = connect(ui->lvWhtelist, SIGNAL(customContextMenuRequested(
const QPoint&)),
81 this, SLOT(slotWhiteListContextMenuRequested(
const QPoint&)));
82 foreach (
auto ip, m_Para->GetWhitelist()) {
83 m_ModelWhite.appendRow(
new QStandardItem(ip));
88CDlgSettings::~CDlgSettings()
93void CDlgSettings::on_pbRoot_clicked()
95 QString szDir = QFileDialog::getExistingDirectory(
this, QString(), ui->leRoot->text());
98 ui->leRoot->setText(szDir);
101void CDlgSettings::accept()
103 m_Para->SetPort(ui->sbPort->value());
104 m_Para->SetUser(ui->leUser->text());
105 m_Para->SetPassword(ui->lePassword->text());
106 m_Para->SetRoot(ui->leRoot->text());
107 m_Para->SetAnonymousLogin(ui->cbAnonmousLogin->isChecked());
108 m_Para->SetReadOnly(ui->cbReadOnly->isChecked());
109 m_Para->SetConnectCount(ui->sbConnectCount->value());
111 m_Para->SetListenAll(ui->cbListenAll->isChecked());
112 QStringList lstInterface;
113 for (
int row = 0; row < m_ModelNetWorkInterface.rowCount(); row++) {
114 auto item = m_ModelNetWorkInterface.item(row);
115 if(item->checkState() == Qt::Checked) {
116 lstInterface << item->text();
119 m_Para->SetListen(lstInterface);
121 QStringList lstBlack;
122 for (
int i = 0; i < m_ModelBlack.rowCount(); ++i) {
123 lstBlack << m_ModelBlack.item(i)->text();
125 m_Para->SetBlacklist(lstBlack);
126 QStringList lstWhite;
127 for (
int i = 0; i < m_ModelWhite.rowCount(); ++i) {
128 lstWhite << m_ModelWhite.item(i)->text();
130 m_Para->SetWhitelist(lstWhite);
135void CDlgSettings::on_cbAnonmousLogin_checkStateChanged(
const Qt::CheckState &arg1)
137 bool bEnable = (Qt::Checked != arg1);
138 ui->lePassword->setEnabled(bEnable);
139 ui->leUser->setEnabled(bEnable);
142void CDlgSettings::on_cbListenAll_checkStateChanged(
const Qt::CheckState &arg1)
144 ui->lvListen->setEnabled(Qt::Checked != arg1);
147void CDlgSettings::slotWhiteListContextMenuRequested(
const QPoint& pos)
150 QItemSelectionModel* pSelect = ui->lvWhtelist->selectionModel();
151 QModelIndexList lstIndex = pSelect->selectedRows();
152 m.addAction(tr(
"Add"),
this, SLOT(on_pbAddWhitelist_clicked()));
153 if(!lstIndex.isEmpty()) {
154 m.addAction(tr(
"Delete"),
this, SLOT(on_pbDeleteWhitelist_clicked()));
157 QPoint p = ui->lvWhtelist->mapToGlobal(pos);
161void CDlgSettings::slotBlackListContextMenuRequested(
const QPoint& pos)
164 QItemSelectionModel* pSelect = ui->lvBlacklist->selectionModel();
165 QModelIndexList lstIndex = pSelect->selectedRows();
166 m.addAction(tr(
"Add"),
this, SLOT(on_pbAddBlacklist_clicked()));
167 if(!lstIndex.isEmpty()) {
168 m.addAction(tr(
"Delete"),
this, SLOT(on_pbDeleteBlacklist_clicked()));
171 QPoint p = ui->lvBlacklist->mapToGlobal(pos);
175void CDlgSettings::on_pbAddWhitelist_clicked()
177 QString szIp = QInputDialog::getText(
this, tr(
"Add whilte list"), m_szFilteListPrompt);
178 QStandardItem* item =
new QStandardItem(szIp);
179 m_ModelWhite.appendRow(item);
182void CDlgSettings::on_pbDeleteWhitelist_clicked()
184 QItemSelectionModel* pSelect = ui->lvBlacklist->selectionModel();
185 QModelIndexList lstIndex = pSelect->selectedRows();
186 foreach(
auto idx, lstIndex) {
187 m_ModelWhite.removeRow(idx.row());
191void CDlgSettings::on_pbAddBlacklist_clicked()
193 QString szIp = QInputDialog::getText(
this, tr(
"Add black list"), m_szFilteListPrompt);
194 QStandardItem* item =
new QStandardItem(szIp);
195 m_ModelBlack.appendRow(item);
198void CDlgSettings::on_pbDeleteBlacklist_clicked()
200 QItemSelectionModel* pSelect = ui->lvBlacklist->selectionModel();
202 QModelIndexList lstIndex = pSelect->selectedRows();
203 foreach(
auto idx, lstIndex) {
204 m_ModelBlack.removeRow(idx.row());