sites list reimplement
This commit is contained in:
parent
65961d8d2e
commit
c683884868
3 changed files with 84 additions and 71 deletions
|
@ -1,6 +1,7 @@
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QClipboard>
|
#include <QClipboard>
|
||||||
#include <QDesktopServices>
|
#include <QDesktopServices>
|
||||||
|
#include <QHBoxLayout>
|
||||||
#include <QJsonDocument>
|
#include <QJsonDocument>
|
||||||
#include <QJsonObject>
|
#include <QJsonObject>
|
||||||
#include <QKeyEvent>
|
#include <QKeyEvent>
|
||||||
|
@ -61,12 +62,6 @@ MainWindow::MainWindow(QWidget *parent) :
|
||||||
setupTray();
|
setupTray();
|
||||||
setupUiConnections();
|
setupUiConnections();
|
||||||
|
|
||||||
customSitesModel = new QStringListModel();
|
|
||||||
ui->listView_sites_custom->setModel(customSitesModel);
|
|
||||||
|
|
||||||
connect(ui->listView_sites_custom, &QListView::doubleClicked, [&](const QModelIndex &index){
|
|
||||||
QDesktopServices::openUrl("https://" + index.data().toString());
|
|
||||||
});
|
|
||||||
connect(ui->lineEdit_sites_add_custom, &QLineEdit::returnPressed, [&](){
|
connect(ui->lineEdit_sites_add_custom, &QLineEdit::returnPressed, [&](){
|
||||||
ui->pushButton_sites_add_custom->click();
|
ui->pushButton_sites_add_custom->click();
|
||||||
});
|
});
|
||||||
|
@ -569,7 +564,6 @@ void MainWindow::setupUiConnections()
|
||||||
connect(ui->pushButton_back_from_share, &QPushButton::clicked, this, [this](){ goToPage(Page::GeneralSettings); });
|
connect(ui->pushButton_back_from_share, &QPushButton::clicked, this, [this](){ goToPage(Page::GeneralSettings); });
|
||||||
|
|
||||||
connect(ui->pushButton_sites_add_custom, &QPushButton::clicked, this, [this](){ onPushButtonAddCustomSitesClicked(); });
|
connect(ui->pushButton_sites_add_custom, &QPushButton::clicked, this, [this](){ onPushButtonAddCustomSitesClicked(); });
|
||||||
connect(ui->pushButton_sites_delete_custom, &QPushButton::clicked, this, [this](){ onPushButtonDeleteCustomSiteClicked(); });
|
|
||||||
|
|
||||||
connect(ui->radioButton_mode_selected_sites, &QRadioButton::toggled, ui->pushButton_vpn_add_site, &QPushButton::setEnabled);
|
connect(ui->radioButton_mode_selected_sites, &QRadioButton::toggled, ui->pushButton_vpn_add_site, &QPushButton::setEnabled);
|
||||||
|
|
||||||
|
@ -741,11 +735,8 @@ void MainWindow::onPushButtonAddCustomSitesClicked()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::onPushButtonDeleteCustomSiteClicked()
|
void MainWindow::onPushButtonDeleteCustomSiteClicked(const QString &siteToDelete)
|
||||||
{
|
{
|
||||||
QModelIndex index = ui->listView_sites_custom->currentIndex();
|
|
||||||
QString siteToDelete = index.data(Qt::DisplayRole).toString();
|
|
||||||
|
|
||||||
if (siteToDelete.isEmpty()) {
|
if (siteToDelete.isEmpty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -762,7 +753,6 @@ void MainWindow::onPushButtonDeleteCustomSiteClicked()
|
||||||
qDebug() << "Deleted custom ip:" << ipToDelete;
|
qDebug() << "Deleted custom ip:" << ipToDelete;
|
||||||
m_settings.setCustomIps(customIps);
|
m_settings.setCustomIps(customIps);
|
||||||
|
|
||||||
|
|
||||||
updateSettings();
|
updateSettings();
|
||||||
|
|
||||||
if (m_vpnConnection->connectionState() == VpnProtocol::ConnectionState::Connected) {
|
if (m_vpnConnection->connectionState() == VpnProtocol::ConnectionState::Connected) {
|
||||||
|
@ -773,7 +763,6 @@ void MainWindow::onPushButtonDeleteCustomSiteClicked()
|
||||||
|
|
||||||
void MainWindow::updateSettings()
|
void MainWindow::updateSettings()
|
||||||
{
|
{
|
||||||
customSitesModel->setStringList(m_settings.customSites());
|
|
||||||
ui->radioButton_mode_selected_sites->setChecked(m_settings.customRouting());
|
ui->radioButton_mode_selected_sites->setChecked(m_settings.customRouting());
|
||||||
ui->pushButton_vpn_add_site->setEnabled(m_settings.customRouting());
|
ui->pushButton_vpn_add_site->setEnabled(m_settings.customRouting());
|
||||||
|
|
||||||
|
@ -782,6 +771,12 @@ void MainWindow::updateSettings()
|
||||||
|
|
||||||
ui->lineEdit_network_settings_dns1->setText(m_settings.primaryDns());
|
ui->lineEdit_network_settings_dns1->setText(m_settings.primaryDns());
|
||||||
ui->lineEdit_network_settings_dns2->setText(m_settings.secondaryDns());
|
ui->lineEdit_network_settings_dns2->setText(m_settings.secondaryDns());
|
||||||
|
|
||||||
|
|
||||||
|
ui->listWidget_sites->clear();
|
||||||
|
for(const QString &site : m_settings.customSites()) {
|
||||||
|
makeSitesListItem(ui->listWidget_sites, site);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::updateShareCode()
|
void MainWindow::updateShareCode()
|
||||||
|
@ -797,3 +792,32 @@ void MainWindow::updateShareCode()
|
||||||
|
|
||||||
//qDebug() << "Share code" << QJsonDocument(o).toJson();
|
//qDebug() << "Share code" << QJsonDocument(o).toJson();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::makeSitesListItem(QListWidget *listWidget, const QString &address)
|
||||||
|
{
|
||||||
|
QSize size(330, 25);
|
||||||
|
QWidget* widget = new QWidget;
|
||||||
|
widget->resize(size);
|
||||||
|
|
||||||
|
QLabel *label = new QLabel(address, widget);
|
||||||
|
label->resize(size);
|
||||||
|
|
||||||
|
QPushButton* btn = new QPushButton(widget);
|
||||||
|
btn->resize(size);
|
||||||
|
|
||||||
|
QPushButton* btn1 = new QPushButton(widget);
|
||||||
|
btn1->resize(30, 25);
|
||||||
|
btn1->move(300, 0);
|
||||||
|
btn1->setCursor(QCursor(Qt::PointingHandCursor));
|
||||||
|
|
||||||
|
connect(btn1, &QPushButton::clicked, this, [this, label]() {
|
||||||
|
onPushButtonDeleteCustomSiteClicked(label->text());
|
||||||
|
return;
|
||||||
|
});
|
||||||
|
|
||||||
|
QListWidgetItem* item = new QListWidgetItem(listWidget);
|
||||||
|
item->setSizeHint(size);
|
||||||
|
listWidget->setItemWidget(item, widget);
|
||||||
|
|
||||||
|
widget->setStyleSheet(styleSheet());
|
||||||
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#define MAINWINDOW_H
|
#define MAINWINDOW_H
|
||||||
|
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
|
#include <QListWidget>
|
||||||
#include <QMainWindow>
|
#include <QMainWindow>
|
||||||
#include <QProgressBar>
|
#include <QProgressBar>
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
|
@ -53,7 +54,7 @@ private slots:
|
||||||
void onPushButtonForgetServer(bool);
|
void onPushButtonForgetServer(bool);
|
||||||
|
|
||||||
void onPushButtonAddCustomSitesClicked();
|
void onPushButtonAddCustomSitesClicked();
|
||||||
void onPushButtonDeleteCustomSiteClicked();
|
void onPushButtonDeleteCustomSiteClicked(const QString &siteToDelete);
|
||||||
|
|
||||||
void onTrayActionConnect(); // connect from context menu
|
void onTrayActionConnect(); // connect from context menu
|
||||||
void setTrayState(VpnProtocol::ConnectionState state);
|
void setTrayState(VpnProtocol::ConnectionState state);
|
||||||
|
@ -78,7 +79,7 @@ private:
|
||||||
void updateSettings();
|
void updateSettings();
|
||||||
|
|
||||||
void updateShareCode();
|
void updateShareCode();
|
||||||
|
void makeSitesListItem(QListWidget* listWidget, const QString &address);
|
||||||
|
|
||||||
Ui::MainWindow *ui;
|
Ui::MainWindow *ui;
|
||||||
VpnConnection* m_vpnConnection;
|
VpnConnection* m_vpnConnection;
|
||||||
|
@ -90,7 +91,6 @@ private:
|
||||||
QSystemTrayIcon m_tray;
|
QSystemTrayIcon m_tray;
|
||||||
QMenu* m_menu;
|
QMenu* m_menu;
|
||||||
|
|
||||||
QStringListModel *customSitesModel = nullptr;
|
|
||||||
QRegExpValidator m_ipAddressValidator;
|
QRegExpValidator m_ipAddressValidator;
|
||||||
|
|
||||||
bool canMove = false;
|
bool canMove = false;
|
||||||
|
|
|
@ -254,7 +254,7 @@ QPushButton:hover {
|
||||||
<string notr="true"/>
|
<string notr="true"/>
|
||||||
</property>
|
</property>
|
||||||
<property name="currentIndex">
|
<property name="currentIndex">
|
||||||
<number>8</number>
|
<number>3</number>
|
||||||
</property>
|
</property>
|
||||||
<widget class="QWidget" name="page_start">
|
<widget class="QWidget" name="page_start">
|
||||||
<widget class="QLabel" name="label_23">
|
<widget class="QLabel" name="label_23">
|
||||||
|
@ -1175,22 +1175,6 @@ background: rgba(167, 167, 167, 0.1);
|
||||||
color: #181922;
|
color: #181922;
|
||||||
}</string>
|
}</string>
|
||||||
</property>
|
</property>
|
||||||
<widget class="QListView" name="listView_sites">
|
|
||||||
<property name="geometry">
|
|
||||||
<rect>
|
|
||||||
<x>0</x>
|
|
||||||
<y>0</y>
|
|
||||||
<width>381</width>
|
|
||||||
<height>0</height>
|
|
||||||
</rect>
|
|
||||||
</property>
|
|
||||||
<property name="cursor" stdset="0">
|
|
||||||
<cursorShape>PointingHandCursor</cursorShape>
|
|
||||||
</property>
|
|
||||||
<property name="editTriggers">
|
|
||||||
<set>QAbstractItemView::NoEditTriggers</set>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
<widget class="QPushButton" name="pushButton_back_from_sites">
|
<widget class="QPushButton" name="pushButton_back_from_sites">
|
||||||
<property name="geometry">
|
<property name="geometry">
|
||||||
<rect>
|
<rect>
|
||||||
|
@ -1273,22 +1257,6 @@ color: #100A44;
|
||||||
<bool>true</bool>
|
<bool>true</bool>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
<widget class="QListView" name="listView_sites_custom">
|
|
||||||
<property name="geometry">
|
|
||||||
<rect>
|
|
||||||
<x>20</x>
|
|
||||||
<y>200</y>
|
|
||||||
<width>341</width>
|
|
||||||
<height>361</height>
|
|
||||||
</rect>
|
|
||||||
</property>
|
|
||||||
<property name="cursor" stdset="0">
|
|
||||||
<cursorShape>PointingHandCursor</cursorShape>
|
|
||||||
</property>
|
|
||||||
<property name="editTriggers">
|
|
||||||
<set>QAbstractItemView::NoEditTriggers</set>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
<widget class="QLineEdit" name="lineEdit_sites_add_custom">
|
<widget class="QLineEdit" name="lineEdit_sites_add_custom">
|
||||||
<property name="geometry">
|
<property name="geometry">
|
||||||
<rect>
|
<rect>
|
||||||
|
@ -1354,28 +1322,6 @@ background: #211966;
|
||||||
<string>+</string>
|
<string>+</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
<widget class="QPushButton" name="pushButton_sites_delete_custom">
|
|
||||||
<property name="enabled">
|
|
||||||
<bool>true</bool>
|
|
||||||
</property>
|
|
||||||
<property name="geometry">
|
|
||||||
<rect>
|
|
||||||
<x>90</x>
|
|
||||||
<y>584</y>
|
|
||||||
<width>201</width>
|
|
||||||
<height>21</height>
|
|
||||||
</rect>
|
|
||||||
</property>
|
|
||||||
<property name="cursor">
|
|
||||||
<cursorShape>PointingHandCursor</cursorShape>
|
|
||||||
</property>
|
|
||||||
<property name="styleSheet">
|
|
||||||
<string notr="true">color: #181922;</string>
|
|
||||||
</property>
|
|
||||||
<property name="text">
|
|
||||||
<string>Delete selected site</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
<widget class="QLabel" name="label_3">
|
<widget class="QLabel" name="label_3">
|
||||||
<property name="geometry">
|
<property name="geometry">
|
||||||
<rect>
|
<rect>
|
||||||
|
@ -1401,6 +1347,49 @@ color: #333333;</string>
|
||||||
<string>Web site or hostname or IP address</string>
|
<string>Web site or hostname or IP address</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
|
<widget class="QListWidget" name="listWidget_sites">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>20</x>
|
||||||
|
<y>200</y>
|
||||||
|
<width>340</width>
|
||||||
|
<height>400</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="styleSheet">
|
||||||
|
<string notr="true">QWidget {
|
||||||
|
margin: 0px;
|
||||||
|
padding: 0px;
|
||||||
|
}
|
||||||
|
|
||||||
|
QPushButton:hover {
|
||||||
|
image: url(:/images/close.png);
|
||||||
|
image-position: right center;
|
||||||
|
}
|
||||||
|
|
||||||
|
QListView {
|
||||||
|
show-decoration-selected: 1; /* make the selection span the entire width of the view */
|
||||||
|
}
|
||||||
|
|
||||||
|
QListView::item:selected:!active {
|
||||||
|
background: transparent;
|
||||||
|
border: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
QListView::item:selected:active {
|
||||||
|
background: transparent;
|
||||||
|
border: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
QListView::item:hover {
|
||||||
|
background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
|
||||||
|
stop: 0 #FAFBFE, stop: 1 #ECEEFF);
|
||||||
|
}</string>
|
||||||
|
</property>
|
||||||
|
<property name="selectionMode">
|
||||||
|
<enum>QAbstractItemView::NoSelection</enum>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
</widget>
|
</widget>
|
||||||
<widget class="QWidget" name="page_general_settings">
|
<widget class="QWidget" name="page_general_settings">
|
||||||
<widget class="QPushButton" name="pushButton_back_from_settings">
|
<widget class="QPushButton" name="pushButton_back_from_settings">
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue