Skip to content

Commit

Permalink
fix: vpn dialog open for a long time
Browse files Browse the repository at this point in the history
do not create a dialog pointer

Issue: linuxdeepin/developer-center#6312
Log:
  • Loading branch information
Decodetalkers committed Dec 7, 2023
1 parent 67d7722 commit aff43a7
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 37 deletions.
67 changes: 33 additions & 34 deletions dcc-network-plugin/window/editpage/connectionvpneditpage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,46 +41,14 @@ const QList<ConnectionVpnEditPage::VpnType> SupportedExportVpnList {
ConnectionVpnEditPage::ConnectionVpnEditPage(const QString &connUuid, QWidget *parent)
: ConnectionEditPage(ConnectionEditPage::ConnectionType::VpnConnection, QString(), connUuid, parent)
, m_exportButton(nullptr)
, m_saveConfig(new QFileDialog(this))
{
m_saveConfig->setAccessibleName("ConnectionVpnEditPage_saveConfig");
m_saveConfig->setModal(true);
m_saveConfig->setNameFilter("Config File (*.conf)");
m_saveConfig->setAcceptMode(QFileDialog::AcceptSave);
QStringList directory = QStandardPaths::standardLocations(QStandardPaths::HomeLocation);
if (!directory.isEmpty())
m_saveConfig->setDirectory(directory.first());

connect(m_saveConfig, &QFileDialog::finished, this, [ = ] (int result) {
Q_EMIT requestFrameAutoHide(true);
if (result == QFileDialog::Accepted) {
QString file = m_saveConfig->selectedFiles().first();
if (!file.endsWith(".conf"))
file.append(".conf");

const QString uuid = connectionUuid();
const auto args = QStringList() << "connection" << "export" << uuid << file;
qDebug() << Q_FUNC_INFO;

QProcess p;
p.start("nmcli", args);
p.waitForFinished();
qDebug() << p.readAllStandardOutput();
qDebug() << p.readAllStandardError();

// process ca
processConfigCA(file);
}
});
}

ConnectionVpnEditPage::~ConnectionVpnEditPage()
{
if (m_exportButton)
m_exportButton->deleteLater();

if (m_saveConfig)
m_saveConfig->deleteLater();
}

void ConnectionVpnEditPage::initSettingsWidget()
Expand Down Expand Up @@ -248,8 +216,39 @@ void ConnectionVpnEditPage::resetConnectionIdByType(ConnectionVpnEditPage::VpnTy
void ConnectionVpnEditPage::exportConnConfig()
{
Q_EMIT requestFrameAutoHide(false);
m_saveConfig->selectFile(this->m_connectionSettings->id());
m_saveConfig->show();
QFileDialog dialog;
dialog.selectFile(this->m_connectionSettings->id());
dialog.setAccessibleName("ConnectionVpnEditPage_saveConfig");
dialog.setModal(true);
dialog.setNameFilter("Config File (*.conf)");
dialog.setAcceptMode(QFileDialog::AcceptSave);
QStringList directory = QStandardPaths::standardLocations(QStandardPaths::HomeLocation);
if (!directory.isEmpty())
dialog.setDirectory(directory.first());
connect(&dialog, &QFileDialog::finished, this, [ &dialog, this ] (int result) {
Q_EMIT requestFrameAutoHide(true);
if (result == QFileDialog::Accepted) {
QString file = dialog.selectedFiles().first();
if (!file.endsWith(".conf"))
file.append(".conf");

const QString uuid = connectionUuid();
const auto args = QStringList() << "connection" << "export" << uuid << file;
qDebug() << Q_FUNC_INFO;

QProcess p;
p.start("nmcli", args);
p.waitForFinished();
qDebug() << p.readAllStandardOutput();
qDebug() << p.readAllStandardError();

// process ca
processConfigCA(file);
}
});

dialog.exec();

}

void ConnectionVpnEditPage::processConfigCA(const QString &file)
Expand Down
3 changes: 0 additions & 3 deletions dcc-network-plugin/window/editpage/connectionvpneditpage.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
#define ServiceTypeOpenConnect "org.freedesktop.NetworkManager.openconnect"
#define ServiceTypeSSTP "org.freedesktop.NetworkManager.sstp"

class QFileDialog;

class ConnectionVpnEditPage : public ConnectionEditPage
{
Q_OBJECT
Expand All @@ -42,7 +40,6 @@ class ConnectionVpnEditPage : public ConnectionEditPage

private:
QPushButton *m_exportButton;
QFileDialog *m_saveConfig;
};

#endif /* CONNECTIONVPNEDITPAGE_H */

0 comments on commit aff43a7

Please sign in to comment.