Sites page fix
This commit is contained in:
parent
8f23970ccc
commit
495e74e2f0
3 changed files with 139 additions and 31 deletions
|
@ -98,27 +98,32 @@ void SitesLogic::onPushButtonAddCustomSitesClicked()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SitesLogic::onPushButtonSitesDeleteClicked(int row)
|
void SitesLogic::onPushButtonSitesDeleteClicked(QStringList items)
|
||||||
{
|
{
|
||||||
Settings::RouteMode mode = m_settings.routeMode();
|
Settings::RouteMode mode = m_settings.routeMode();
|
||||||
|
|
||||||
auto siteModel = qobject_cast<SitesModel*> (tableViewSitesModel());
|
auto siteModel = qobject_cast<SitesModel*> (tableViewSitesModel());
|
||||||
if (!siteModel) {
|
if (!siteModel || items.isEmpty()) {
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (row < 0 || row >= siteModel->rowCount()) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
QStringList sites;
|
||||||
QStringList sites;
|
QStringList ips;
|
||||||
|
|
||||||
|
for (const QString &s: items) {
|
||||||
|
bool ok;
|
||||||
|
int row = s.toInt(&ok);
|
||||||
|
if (!ok || row < 0 || row >= siteModel->rowCount()) return;
|
||||||
sites.append(siteModel->data(row, 0).toString());
|
sites.append(siteModel->data(row, 0).toString());
|
||||||
m_settings.removeVpnSites(mode, sites);
|
|
||||||
|
if (uiLogic()->m_vpnConnection->connectionState() == VpnProtocol::Connected) {
|
||||||
|
ips.append(siteModel->data(row, 1).toString());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_settings.removeVpnSites(mode, sites);
|
||||||
|
|
||||||
if (uiLogic()->m_vpnConnection->connectionState() == VpnProtocol::Connected) {
|
if (uiLogic()->m_vpnConnection->connectionState() == VpnProtocol::Connected) {
|
||||||
QStringList ips;
|
|
||||||
ips.append(siteModel->data(row, 1).toString());
|
|
||||||
uiLogic()->m_vpnConnection->deleteRoutes(ips);
|
uiLogic()->m_vpnConnection->deleteRoutes(ips);
|
||||||
uiLogic()->m_vpnConnection->flushDns();
|
uiLogic()->m_vpnConnection->flushDns();
|
||||||
}
|
}
|
||||||
|
@ -156,3 +161,16 @@ void SitesLogic::onPushButtonSitesImportClicked(const QString& fileName)
|
||||||
onUpdatePage();
|
onUpdatePage();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SitesLogic::onPushButtonSitesExportClicked()
|
||||||
|
{
|
||||||
|
Settings::RouteMode mode = m_settings.routeMode();
|
||||||
|
|
||||||
|
QVariantMap sites = m_settings.vpnSites(mode);
|
||||||
|
|
||||||
|
QString data;
|
||||||
|
for (auto s : sites.keys()) {
|
||||||
|
data += s + "\t" + sites.value(s).toString() + "\n";
|
||||||
|
}
|
||||||
|
uiLogic()->saveTextFile("Sites", ".txt", data);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,8 +18,10 @@ public:
|
||||||
Q_INVOKABLE void onUpdatePage() override;
|
Q_INVOKABLE void onUpdatePage() override;
|
||||||
|
|
||||||
Q_INVOKABLE void onPushButtonAddCustomSitesClicked();
|
Q_INVOKABLE void onPushButtonAddCustomSitesClicked();
|
||||||
Q_INVOKABLE void onPushButtonSitesDeleteClicked(int row);
|
Q_INVOKABLE void onPushButtonSitesDeleteClicked(QStringList items);
|
||||||
Q_INVOKABLE void onPushButtonSitesImportClicked(const QString &fileName);
|
Q_INVOKABLE void onPushButtonSitesImportClicked(const QString &fileName);
|
||||||
|
Q_INVOKABLE void onPushButtonSitesExportClicked();
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit SitesLogic(UiLogic *uiLogic, QObject *parent = nullptr);
|
explicit SitesLogic(UiLogic *uiLogic, QObject *parent = nullptr);
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import QtQuick 2.12
|
import QtQuick 2.15
|
||||||
import QtQuick.Controls 2.12
|
import QtQuick.Controls 2.15
|
||||||
|
import QtQml.Models 2.15
|
||||||
import Qt.labs.platform 1.0
|
import Qt.labs.platform 1.0
|
||||||
import QtQuick.Dialogs 1.0
|
import QtQuick.Dialogs 1.0
|
||||||
import PageEnum 1.0
|
import PageEnum 1.0
|
||||||
|
@ -12,6 +13,8 @@ PageBase {
|
||||||
page: PageEnum.Sites
|
page: PageEnum.Sites
|
||||||
logic: SitesLogic
|
logic: SitesLogic
|
||||||
|
|
||||||
|
property int lastIndex: 0
|
||||||
|
|
||||||
BackButton {
|
BackButton {
|
||||||
id: back
|
id: back
|
||||||
}
|
}
|
||||||
|
@ -104,20 +107,27 @@ PageBase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ListView {
|
DelegateModel {
|
||||||
id: tb
|
id: visualModel
|
||||||
x: 20
|
|
||||||
anchors.top: sites_add.bottom
|
|
||||||
anchors.topMargin: 10
|
|
||||||
width: parent.width - 40
|
|
||||||
anchors.bottom: sites_delete.top
|
|
||||||
anchors.bottomMargin: 10
|
|
||||||
spacing: 1
|
|
||||||
clip: true
|
|
||||||
property int currentRow: -1
|
|
||||||
model: SitesLogic.tableViewSitesModel
|
model: SitesLogic.tableViewSitesModel
|
||||||
|
groups: [
|
||||||
delegate: Item {
|
DelegateModelGroup {
|
||||||
|
id : delegateModelGroup
|
||||||
|
name: "multiSelect"
|
||||||
|
function removeAll(){
|
||||||
|
var count = delegateModelGroup.count;
|
||||||
|
if (count !== 0){
|
||||||
|
delegateModelGroup.remove(0,count);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
delegate: Rectangle {
|
||||||
|
id: item
|
||||||
|
focus: true
|
||||||
|
height: 25
|
||||||
|
width: root.width
|
||||||
|
color: item.DelegateModel.inMultiSelect ? '#63b4fb' : 'transparent'
|
||||||
implicitWidth: 170 * 2
|
implicitWidth: 170 * 2
|
||||||
implicitHeight: 30
|
implicitHeight: 30
|
||||||
Item {
|
Item {
|
||||||
|
@ -171,23 +181,101 @@ PageBase {
|
||||||
}
|
}
|
||||||
MouseArea {
|
MouseArea {
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
onClicked: {
|
acceptedButtons: Qt.LeftButton | Qt.RightButton
|
||||||
tb.currentRow = index
|
onClicked:{
|
||||||
|
tb.focus = true
|
||||||
|
if(mouse.button === Qt.RightButton){
|
||||||
|
//copyPasteMenu.popup()
|
||||||
|
console.log("RightButton")
|
||||||
|
}
|
||||||
|
if(mouse.button === Qt.LeftButton){
|
||||||
|
switch(mouse.modifiers){
|
||||||
|
case Qt.ControlModifier :
|
||||||
|
item.DelegateModel.inMultiSelect = !item.DelegateModel.inMultiSelect
|
||||||
|
break;
|
||||||
|
case Qt.ShiftModifier :
|
||||||
|
delegateModelGroup.removeAll();
|
||||||
|
var start = lastIndex <= index? lastIndex: index;
|
||||||
|
var end = lastIndex >= index? lastIndex: index;
|
||||||
|
for(var i = start;i <= end;i++){
|
||||||
|
visualModel.items.get(i).inMultiSelect = true
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
delegateModelGroup.removeAll();
|
||||||
|
item.DelegateModel.inMultiSelect = true
|
||||||
|
lastIndex = index
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ListView {
|
||||||
|
id: tb
|
||||||
|
x: 20
|
||||||
|
anchors.top: sites_add.bottom
|
||||||
|
anchors.topMargin: 10
|
||||||
|
width: parent.width - 40
|
||||||
|
anchors.bottom: sites_delete.top
|
||||||
|
anchors.bottomMargin: 10
|
||||||
|
spacing: 1
|
||||||
|
clip: true
|
||||||
|
focus: true
|
||||||
|
activeFocusOnTab: true
|
||||||
|
keyNavigationEnabled: true
|
||||||
|
property int currentRow: -1
|
||||||
|
//model: SitesLogic.tableViewSitesModel
|
||||||
|
model: visualModel
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
BlueButtonType {
|
BlueButtonType {
|
||||||
id: sites_delete
|
id: sites_delete
|
||||||
anchors.bottom: parent.bottom
|
anchors.bottom: select_all.top
|
||||||
anchors.bottomMargin: 20
|
anchors.bottomMargin: 10
|
||||||
anchors.horizontalCenter: parent.horizontalCenter
|
anchors.horizontalCenter: parent.horizontalCenter
|
||||||
height: 31
|
height: 31
|
||||||
font.pixelSize: 16
|
font.pixelSize: 16
|
||||||
text: qsTr("Delete selected")
|
text: qsTr("Delete selected")
|
||||||
onClicked: {
|
onClicked: {
|
||||||
SitesLogic.onPushButtonSitesDeleteClicked(tb.currentRow)
|
var items = []
|
||||||
|
for(var i = 0; i < visualModel.count; i++){
|
||||||
|
if (visualModel.items.get(i).inMultiSelect) items.push(i)
|
||||||
|
}
|
||||||
|
|
||||||
|
console.debug(items)
|
||||||
|
SitesLogic.onPushButtonSitesDeleteClicked(items)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
BlueButtonType {
|
||||||
|
id: select_all
|
||||||
|
anchors.bottom: sites_export.top
|
||||||
|
anchors.bottomMargin: 10
|
||||||
|
anchors.horizontalCenter: parent.horizontalCenter
|
||||||
|
height: 31
|
||||||
|
font.pixelSize: 16
|
||||||
|
text: qsTr("Select all")
|
||||||
|
onClicked: {
|
||||||
|
for(var i = 0; i < visualModel.count; i++){
|
||||||
|
visualModel.items.get(i).inMultiSelect = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
BlueButtonType {
|
||||||
|
id: sites_export
|
||||||
|
anchors.bottom: parent.bottom
|
||||||
|
anchors.bottomMargin: 20
|
||||||
|
anchors.horizontalCenter: parent.horizontalCenter
|
||||||
|
height: 31
|
||||||
|
font.pixelSize: 16
|
||||||
|
text: qsTr("Export all")
|
||||||
|
onClicked: {
|
||||||
|
SitesLogic.onPushButtonSitesExportClicked()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue