Add AppsColumn.

This commit is contained in:
Nodir Temirkhodjaev 2017-09-02 17:52:39 +05:00
parent 15ae2c10b0
commit a89354f0ea
12 changed files with 219 additions and 31 deletions

View File

@ -7,6 +7,10 @@
class AppGroup : public QObject class AppGroup : public QObject
{ {
Q_OBJECT Q_OBJECT
Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged)
Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
Q_PROPERTY(QString blockText READ blockText WRITE setBlockText NOTIFY blockTextChanged)
Q_PROPERTY(QString allowText READ allowText WRITE setAllowText NOTIFY allowTextChanged)
public: public:
explicit AppGroup(QObject *parent = nullptr); explicit AppGroup(QObject *parent = nullptr);

View File

@ -85,6 +85,13 @@ void FirewallConf::addAppGroup(AppGroup *appGroup, int to)
emit appGroupsChanged(); emit appGroupsChanged();
} }
void FirewallConf::addAppGroupByName(const QString &name)
{
AppGroup *appGroup = new AppGroup();
appGroup->setName(name);
addAppGroup(appGroup);
}
void FirewallConf::moveAppGroup(int from, int to) void FirewallConf::moveAppGroup(int from, int to)
{ {
m_appGroups.move(from, to); m_appGroups.move(from, to);
@ -94,7 +101,9 @@ void FirewallConf::moveAppGroup(int from, int to)
void FirewallConf::removeAppGroup(int from, int to) void FirewallConf::removeAppGroup(int from, int to)
{ {
for (int i = to; i >= from; --i) { for (int i = to; i >= from; --i) {
delete m_appGroups.at(i); AppGroup *appGroup = m_appGroups.at(i);
appGroup->deleteLater();
m_appGroups.removeAt(i); m_appGroups.removeAt(i);
} }
emit appGroupsChanged(); emit appGroupsChanged();

View File

@ -44,10 +44,6 @@ public:
const QList<AppGroup *> &appGroupsList() const { return m_appGroups; } const QList<AppGroup *> &appGroupsList() const { return m_appGroups; }
QQmlListProperty<AppGroup> appGroups(); QQmlListProperty<AppGroup> appGroups();
void addAppGroup(AppGroup *appGroup, int to = -1);
void moveAppGroup(int from, int to);
void removeAppGroup(int from, int to);
QVariant toVariant() const; QVariant toVariant() const;
void fromVariant(const QVariant &v); void fromVariant(const QVariant &v);
@ -59,6 +55,10 @@ signals:
void appGroupsChanged(); void appGroupsChanged();
public slots: public slots:
void addAppGroup(AppGroup *appGroup, int to = -1);
void addAppGroupByName(const QString &name);
void moveAppGroup(int from, int to);
void removeAppGroup(int from, int to);
private: private:
uint m_filterEnabled : 1; uint m_filterEnabled : 1;

View File

@ -1,5 +1,6 @@
<RCC> <RCC>
<qresource prefix="/"> <qresource prefix="/">
<file>qml/controls/TextAreaFrame.qml</file>
<file>qml/main.qml</file> <file>qml/main.qml</file>
<file>qml/pages/ActivityPage.qml</file> <file>qml/pages/ActivityPage.qml</file>
<file>qml/pages/AddressesPage.qml</file> <file>qml/pages/AddressesPage.qml</file>
@ -7,5 +8,7 @@
<file>qml/pages/BasePage.qml</file> <file>qml/pages/BasePage.qml</file>
<file>qml/pages/OptionsPage.qml</file> <file>qml/pages/OptionsPage.qml</file>
<file>qml/pages/addresses/AddressesColumn.qml</file> <file>qml/pages/addresses/AddressesColumn.qml</file>
<file>qml/pages/apps/AppsColumn.qml</file>
<file>qml/pages/apps/AppsTextColumn.qml</file>
</qresource> </qresource>
</RCC> </RCC>

View File

@ -79,10 +79,10 @@ bool FortManager::saveConf()
void FortManager::handleClosedWindow() void FortManager::handleClosedWindow()
{ {
m_engine->deleteLater(); m_engine->deleteLater();
m_engine = 0; m_engine = nullptr;
if (m_firewallConfToEdit && m_firewallConfToEdit != m_firewallConf) { if (m_firewallConfToEdit && m_firewallConfToEdit != m_firewallConf) {
m_firewallConfToEdit->deleteLater(); m_firewallConfToEdit->deleteLater();
m_firewallConfToEdit = 0; m_firewallConfToEdit = nullptr;
} }
} }

View File

@ -0,0 +1,21 @@
import QtQuick 2.9
import QtQuick.Controls 2.2
Frame {
id: frame
signal editingFinished() // Workaround for QTBUG-59908
readonly property alias textArea: textArea
padding: 0
ScrollView {
anchors.fill: parent
TextArea {
id: textArea
onEditingFinished: frame.editingFinished()
}
}
}

View File

@ -13,8 +13,8 @@ ApplicationWindow {
width: 800 width: 800
height: 600 height: 600
minimumWidth: 400 minimumWidth: 540
minimumHeight: 300 minimumHeight: 500
font.pixelSize: 16 font.pixelSize: 16

View File

@ -1,19 +1,45 @@
import QtQuick 2.9 import QtQuick 2.9
import QtQuick.Layouts 1.3 import QtQuick.Layouts 1.3
import QtQuick.Controls 2.2 import QtQuick.Controls 2.2
import "apps"
import com.fortfirewall 1.0 import com.fortfirewall 1.0
BasePage { BasePage {
readonly property var appGroups: firewallConf.appGroups
function resetGroupName() {
editGroupName.text = "";
editGroupName.forceActiveFocus();
}
ColumnLayout { ColumnLayout {
anchors.fill: parent anchors.fill: parent
RowLayout { RowLayout {
Button { TextField {
text: QT_TRANSLATE_NOOP("qml", "Add Group") enabled: rptAppGroups.count < 16
id: editGroupName
placeholderText: QT_TRANSLATE_NOOP("qml", "Group Name")
} }
Button { Button {
text: QT_TRANSLATE_NOOP("qml", "Remove Group") enabled: editGroupName.text
text: QT_TRANSLATE_NOOP("qml", "Add Group")
onClicked: {
const lastIndex = appGroups.length;
firewallConf.addAppGroupByName(editGroupName.text);
barGroups.currentIndex = lastIndex;
resetGroupName();
}
}
Button {
enabled: appsColumn.enabled
text: QT_TRANSLATE_NOOP("qml", "Rename Group")
onClicked: {
const appGroup = appsColumn.appGroup;
appGroup.name = editGroupName.text;
resetGroupName();
}
} }
Item { Item {
@ -22,24 +48,53 @@ BasePage {
CheckBox { CheckBox {
text: QT_TRANSLATE_NOOP("qml", "Block All") text: QT_TRANSLATE_NOOP("qml", "Block All")
checked: firewallConf.appBlockAll
onToggled: {
firewallConf.appBlockAll = checked;
}
} }
CheckBox { CheckBox {
text: QT_TRANSLATE_NOOP("qml", "Allow All") text: QT_TRANSLATE_NOOP("qml", "Allow All")
checked: firewallConf.appAllowAll
onToggled: {
firewallConf.appAllowAll = checked;
}
} }
} }
TabBar { TabBar {
id: barGroups id: barGroups
Layout.fillWidth: true Layout.fillWidth: true
clip: true
Repeater {
id: rptAppGroups
model: appGroups
TabButton { TabButton {
text: QT_TRANSLATE_NOOP("qml", "Options") width: Math.max(70, implicitWidth)
text: appGroup.name
readonly property AppGroup appGroup: modelData
}
} }
} }
Item { AppsColumn {
id: appsColumn
Layout.fillWidth: true Layout.fillWidth: true
Layout.fillHeight: true Layout.fillHeight: true
enabled: index >= 0
opacity: enabled ? 1.0 : 0
Behavior on opacity { NumberAnimation { duration: 150 } }
index: barGroups.currentIndex
appGroup: enabled ? barGroups.currentItem.appGroup
: nullAppGroup
readonly property AppGroup nullAppGroup: AppGroup {}
} }
} }
} }

View File

@ -2,5 +2,4 @@ import QtQuick 2.9
import QtQuick.Controls 2.2 import QtQuick.Controls 2.2
Frame { Frame {
} }

View File

@ -1,6 +1,7 @@
import QtQuick 2.9 import QtQuick 2.9
import QtQuick.Layouts 1.3 import QtQuick.Layouts 1.3
import QtQuick.Controls 2.2 import QtQuick.Controls 2.2
import "../../controls"
import com.fortfirewall 1.0 import com.fortfirewall 1.0
ColumnLayout { ColumnLayout {
@ -8,8 +9,8 @@ ColumnLayout {
Layout.fillWidth: true Layout.fillWidth: true
Layout.fillHeight: true Layout.fillHeight: true
property alias title: title readonly property alias title: title
property alias checkBoxAll: checkBoxAll readonly property alias checkBoxAll: checkBoxAll
property AddressGroup addressGroup property AddressGroup addressGroup
@ -27,16 +28,11 @@ ColumnLayout {
} }
} }
Frame { TextAreaFrame {
Layout.fillWidth: true Layout.fillWidth: true
Layout.fillHeight: true Layout.fillHeight: true
padding: 0 textArea {
ScrollView {
anchors.fill: parent
TextArea {
placeholderText: " placeholderText: "
10.0.0.0/24 10.0.0.0/24
127.0.0.0/24 127.0.0.0/24
@ -45,10 +41,10 @@ ColumnLayout {
192.168.0.0/16 192.168.0.0/16
" "
text: addressGroup.text text: addressGroup.text
}
onEditingFinished: { onEditingFinished: {
addressGroup.text = text; addressGroup.text = textArea.text;
}
}
} }
} }
} }

View File

@ -0,0 +1,72 @@
import QtQuick 2.9
import QtQuick.Layouts 1.3
import QtQuick.Controls 2.2
import com.fortfirewall 1.0
ColumnLayout {
property int index
property AppGroup appGroup
RowLayout {
Button {
text: QT_TRANSLATE_NOOP("qml", "Remove Group")
onClicked: {
firewallConf.removeAppGroup(index, index);
}
}
Item {
Layout.fillWidth: true
}
CheckBox {
text: QT_TRANSLATE_NOOP("qml", "Enabled")
checked: appGroup.enabled
onToggled: {
appGroup.enabled = checked;
}
}
}
RowLayout {
Layout.fillWidth: true
Layout.fillHeight: true
spacing: 10
AppsTextColumn {
title {
text: QT_TRANSLATE_NOOP("qml", "Block")
}
textArea {
placeholderText: "
System
C:\\Program Files\\Internet Explorer\\iexplore.exe
"
text: appGroup.blockText
}
onEditingFinished: {
appGroup.blockText = textArea.text;
}
}
AppsTextColumn {
title {
text: QT_TRANSLATE_NOOP("qml", "Allow")
}
textArea {
placeholderText: "
C:\\Program Files\\Skype\\Phone\\Skype.exe
"
text: appGroup.allowText
}
onEditingFinished: {
appGroup.allowText = textArea.text;
}
}
}
}

View File

@ -0,0 +1,29 @@
import QtQuick 2.9
import QtQuick.Layouts 1.3
import QtQuick.Controls 2.2
import "../../controls"
import com.fortfirewall 1.0
ColumnLayout {
id: container
Layout.preferredWidth: 100
Layout.fillWidth: true
Layout.fillHeight: true
signal editingFinished() // Workaround for QTBUG-59908
readonly property alias title: title
readonly property alias textArea: textAreaFrame.textArea
Label {
id: title
}
TextAreaFrame {
id: textAreaFrame
Layout.fillWidth: true
Layout.fillHeight: true
onEditingFinished: container.editingFinished()
}
}