kylin-nm/plugins/proxy/aptproxydialog.cpp

126 lines
3.3 KiB
C++
Raw Normal View History

2022-09-24 17:08:28 +08:00
#include "aptproxydialog.h"
#include <QDebug>
#include <QLineEdit>
#include <QSpacerItem>
#include <QLabel>
#include <QPushButton>
#include "proxy.h"
AptProxyDialog::AptProxyDialog(QWidget *parent ):
QDialog(parent)
{
initUi();
setupComponent();
initConnect();
}
AptProxyDialog::~AptProxyDialog()
{
}
void AptProxyDialog::initUi()
{
setWindowTitle(tr("Set Apt Proxy"));
2022-11-04 17:51:50 +08:00
this->setFixedSize(480, 204);
2022-09-24 17:08:28 +08:00
QVBoxLayout *mAptProxyLyt = new QVBoxLayout(this);
mAptProxyLyt->setContentsMargins(24, 24, 24, 24);
2022-11-04 17:51:50 +08:00
mAptProxyLyt->setSpacing(8);
2022-09-24 17:08:28 +08:00
QFrame *mHostFrame = new QFrame(this);
2022-11-04 17:51:50 +08:00
mHostFrame->setFixedWidth(432);
2022-09-24 17:08:28 +08:00
mHostFrame->setFrameShape(QFrame::NoFrame);
QHBoxLayout *mLyt_1= new QHBoxLayout(mHostFrame);
mLyt_1->setContentsMargins(0, 0, 0, 0);
mLyt_1->setSpacing(8);
FixLabel *mSetHostLabel = new FixLabel(mHostFrame);
2022-11-04 17:51:50 +08:00
mSetHostLabel->setFixedWidth(92);
2022-09-24 17:08:28 +08:00
mSetHostLabel->setText(tr("Server Address"));
mHostEdit = new QLineEdit(mHostFrame);
mHostEdit->setAttribute(Qt::WA_InputMethodEnabled, false); //限制中文输入法
2022-11-04 17:51:50 +08:00
mHostEdit->setFixedWidth(332);
2022-09-24 17:08:28 +08:00
mHostEdit->installEventFilter(this);
mLyt_1->addWidget(mSetHostLabel);
mLyt_1->addWidget(mHostEdit);
QFrame *mPortFrame = new QFrame(this);
2022-11-04 17:51:50 +08:00
mPortFrame->setFixedWidth(432);
2022-09-24 17:08:28 +08:00
mPortFrame->setFrameShape(QFrame::NoFrame);
QHBoxLayout *mLyt_2= new QHBoxLayout(mPortFrame);
mLyt_2->setContentsMargins(0, 0, 0, 0);
mLyt_2->setSpacing(8);
QLabel *mSetPortLabel = new QLabel(tr("Port") ,mPortFrame);
2022-11-04 17:51:50 +08:00
mSetPortLabel->setFixedWidth(92);
2022-09-24 17:08:28 +08:00
mPortEdit = new QLineEdit(mPortFrame);
mPortEdit->setAttribute(Qt::WA_InputMethodEnabled, false); //限制中文输入法
2022-11-04 17:51:50 +08:00
mPortEdit->setFixedWidth(332);
2022-09-24 17:08:28 +08:00
mPortEdit->installEventFilter(this);
mLyt_2->addWidget(mSetPortLabel);
mLyt_2->addWidget(mPortEdit);
QFrame *mChooseFrame = new QFrame(this);
mChooseFrame->setFixedWidth(432);
mChooseFrame->setFrameShape(QFrame::NoFrame);
QHBoxLayout *mLyt_3= new QHBoxLayout(mChooseFrame);
mLyt_3->setContentsMargins(0, 0, 0, 0);
mLyt_3->setSpacing(16);
mCancelBtn = new QPushButton(mChooseFrame);
mCancelBtn->setText(tr("Cancel"));
mConfirmBtn = new QPushButton(mChooseFrame);
mConfirmBtn->setText(tr("Confirm"));
mLyt_3->addStretch();
mLyt_3->addWidget(mCancelBtn);
mLyt_3->addWidget(mConfirmBtn);
mAptProxyLyt->addWidget(mHostFrame);
mAptProxyLyt->addWidget(mPortFrame);
2022-11-04 17:51:50 +08:00
mAptProxyLyt->addStretch();
2022-09-24 17:08:28 +08:00
mAptProxyLyt->addWidget(mChooseFrame);
}
void AptProxyDialog::initConnect()
{
connect(mHostEdit, &QLineEdit::textEdited, this, [=]() {
if (mHostEdit->text().isEmpty()) {
mConfirmBtn->setEnabled(false);
} else {
mConfirmBtn->setEnabled(true);
}
});
connect(mCancelBtn, &QPushButton::clicked, this, [=]() {
this->close();
});
connect(mConfirmBtn, &QPushButton::clicked, this, [=]() {
Proxy::setAptProxy(mHostEdit->text() , mPortEdit->text() , true);
this->close();
});
}
void AptProxyDialog::setupComponent()
{
QString host = Proxy::getAptProxy()["ip"].toString();
QString port = Proxy::getAptProxy()["port"].toString();;
mHostEdit->setText(host);
mPortEdit->setText(port);
if (host.isEmpty()) {
mConfirmBtn->setEnabled(false);
}
}