diff --git a/kded/passworddialog.h b/kded/passworddialog.h --- a/kded/passworddialog.h +++ b/kded/passworddialog.h @@ -37,33 +37,31 @@ { Q_OBJECT public: - explicit PasswordDialog(const NMVariantMapMap &connection, + explicit PasswordDialog(const NetworkManager::ConnectionSettings::Ptr &connectionSettings, NetworkManager::SecretAgent::GetSecretsFlags flags, const QString &setting_name, QWidget *parent = 0); ~PasswordDialog(); - void setupGenericUi(const NetworkManager::ConnectionSettings &connectionSettings); - void setupVpnUi(const NetworkManager::ConnectionSettings &connectionSettings); bool hasError() const; NetworkManager::SecretAgent::Error error() const; QString errorMessage() const; NMVariantMapMap secrets() const; -private Q_SLOTS: - void showPassword(bool show); - private: - Ui::PasswordDialog *ui; - SettingWidget *vpnWidget; - NMVariantMapMap m_connection; - NetworkManager::SecretAgent::GetSecretsFlags m_flags; + void initializeUi(); + + Ui::PasswordDialog *m_ui; + bool m_hasError; + QString m_errorMessage; QString m_settingName; QStringList m_neededSecrets; - bool m_hasError; + NetworkManager::ConnectionSettings::Ptr m_connectionSettings; NetworkManager::SecretAgent::Error m_error; - QString m_errorMessage; + NetworkManager::SecretAgent::GetSecretsFlags m_flags; + SettingWidget *m_vpnWidget; + }; #endif // PLASMA_NM_PASSWORD_DIALOG_H diff --git a/kded/passworddialog.cpp b/kded/passworddialog.cpp --- a/kded/passworddialog.cpp +++ b/kded/passworddialog.cpp @@ -22,6 +22,7 @@ #include "debug.h" #include "passworddialog.h" #include "ui_passworddialog.h" +#include "uiutils.h" #include @@ -33,100 +34,104 @@ #include #include +#include using namespace NetworkManager; -PasswordDialog::PasswordDialog(const NMVariantMapMap &connection, SecretAgent::GetSecretsFlags flags, +PasswordDialog::PasswordDialog(const NetworkManager::ConnectionSettings::Ptr &connectionSettings, SecretAgent::GetSecretsFlags flags, const QString &setting_name, QWidget *parent) : QDialog(parent), - ui(0), - vpnWidget(0), - m_connection(connection), - m_flags(flags), - m_settingName(setting_name), + m_ui(0), m_hasError(false), - m_error(SecretAgent::NoSecrets) + m_settingName(setting_name), + m_connectionSettings(connectionSettings), + m_error(SecretAgent::NoSecrets), + m_flags(flags), + m_vpnWidget(0) { setWindowIcon(QIcon::fromTheme(QStringLiteral("dialog-password"))); + + initializeUi(); } PasswordDialog::~PasswordDialog() { - delete ui; + delete m_ui; } -void PasswordDialog::setupGenericUi(const ConnectionSettings &connectionSettings) +void PasswordDialog::initializeUi() { - Setting::Ptr setting = connectionSettings.setting(m_settingName); - - ui = new Ui::PasswordDialog; - ui->setupUi(this); + m_ui = new Ui::PasswordDialog; + m_ui->setupUi(this); // TODO fix this for high DPI - ui->labelIcon->setPixmap(QIcon::fromTheme(QStringLiteral("dialog-password")).pixmap(KIconLoader::SizeMedium)); - - m_neededSecrets = setting->needSecrets(m_flags & SecretAgent::RequestNew); - if (m_neededSecrets.isEmpty()) { - qCWarning(PLASMA_NM) << "list of secrets is empty!!!"; - m_hasError = true; - m_error = SecretAgent::InternalError; - m_errorMessage = QLatin1String("No secrets were requested"); - return; - } + m_ui->labelIcon->setPixmap(QIcon::fromTheme(QStringLiteral("dialog-password")).pixmap(KIconLoader::SizeHuge)); + m_ui->labelHeadline->setText(i18n("Authenticate %1", m_connectionSettings->id())); - WirelessSetting::Ptr wifi = connectionSettings.setting(Setting::Wireless).dynamicCast(); + connect(m_ui->buttonBox, &QDialogButtonBox::accepted, this, &PasswordDialog::accept); + connect(m_ui->buttonBox, &QDialogButtonBox::rejected, this, &PasswordDialog::reject); - Setting::SettingType connectionType = setting->type(); - if (wifi && (connectionType == Setting::WirelessSecurity || connectionType == Setting::Security8021x)) { - const QString ssid = QString::fromUtf8(wifi->ssid()); - ui->labelText->setText(i18n("For accessing the wireless network '%1' you need to provide a password below", ssid)); - } else { - ui->labelText->setText(i18n("Please provide the password for activating connection '%1'", connectionSettings.id())); - } + if (m_connectionSettings->connectionType() != NetworkManager::ConnectionSettings::Vpn) { + NetworkManager::Setting::Ptr setting = m_connectionSettings->setting(m_settingName); + m_neededSecrets = setting->needSecrets(m_flags & SecretAgent::RequestNew); - ui->password->setFocus(); - connect(ui->showPassword, &QCheckBox::toggled, this, &PasswordDialog::showPassword); - connect(ui->buttonBox, &QDialogButtonBox::accepted, this, &PasswordDialog::accept); - connect(ui->buttonBox, &QDialogButtonBox::rejected, this, &PasswordDialog::reject); -} + if (m_neededSecrets.isEmpty()) { + qCWarning(PLASMA_NM) << "list of secrets is empty!!!"; + m_hasError = true; + m_error = SecretAgent::InternalError; + m_errorMessage = QLatin1String("No secrets were requested"); + return; + } -void PasswordDialog::setupVpnUi(const ConnectionSettings &connectionSettings) -{ - NetworkManager::VpnSetting::Ptr vpnSetting = connectionSettings.setting(Setting::Vpn).dynamicCast(); - if (!vpnSetting) { - qCWarning(PLASMA_NM) << "Missing VPN setting!"; - m_hasError = true; - m_error = SecretAgent::InternalError; - m_errorMessage = QLatin1String("VPN settings are missing"); - } else { - VpnUiPlugin *vpnUiPlugin; - QString error; - const QString serviceType = vpnSetting->serviceType(); - // qCDebug(PLASMA_NM) << "Agent loading VPN plugin" << serviceType << "from DBUS" << calledFromDBus(); - // vpnSetting->printSetting(); - vpnUiPlugin = KServiceTypeTrader::createInstanceFromQuery(QLatin1String("PlasmaNetworkManagement/VpnUiPlugin"), - QString::fromLatin1("[X-NetworkManager-Services]=='%1'").arg(serviceType), - this, QVariantList(), &error); - if (vpnUiPlugin && error.isEmpty()) { - const QString shortName = serviceType.section('.', -1); - setWindowTitle(i18n("VPN secrets (%1)", shortName)); - vpnWidget = vpnUiPlugin->askUser(vpnSetting, this); - QDialogButtonBox * box; - if (shortName != QLatin1String("openconnect")) { - box = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, this); - connect(box, &QDialogButtonBox::accepted, this, &PasswordDialog::accept); - } else { - box = new QDialogButtonBox(QDialogButtonBox::Cancel, Qt::Horizontal, this); - } - connect(box, &QDialogButtonBox::rejected, this, &PasswordDialog::reject); - QVBoxLayout * layout = new QVBoxLayout(this); - layout->addWidget(vpnWidget); - layout->addWidget(box); - setLayout(layout); + WirelessSetting::Ptr wifi = m_connectionSettings->setting(Setting::Wireless).dynamicCast(); + Setting::SettingType connectionType = setting->type(); + if (wifi && (connectionType == Setting::WirelessSecurity || connectionType == Setting::Security8021x)) { + const QString ssid = QString::fromUtf8(wifi->ssid()); + m_ui->labelText->setText(i18n("For accessing the wireless network %1 you need to provide a password below:", ssid)); } else { - qCWarning(PLASMA_NM) << error << ", serviceType == " << serviceType; + m_ui->labelText->setText(i18n("Please provide the password for activating connection %1:", m_connectionSettings->id())); + } + + QString connectionLabel; + UiUtils::iconAndTitleForConnectionSettingsType(m_connectionSettings->connectionType(), connectionLabel); + m_ui->password->setFocus(); + setWindowTitle(i18n("%1 password dialog", connectionLabel)); + } else { + NetworkManager::VpnSetting::Ptr vpnSetting = m_connectionSettings->setting(Setting::Vpn).dynamicCast(); + qWarning() << "VPN Setting " << *vpnSetting; + if (!vpnSetting) { + qCWarning(PLASMA_NM) << "Missing VPN setting!"; m_hasError = true; m_error = SecretAgent::InternalError; - m_errorMessage = error; + m_errorMessage = QLatin1String("VPN settings are missing"); + } else { + VpnUiPlugin *vpnUiPlugin; + QString error; + const QString serviceType = vpnSetting->serviceType(); + vpnUiPlugin = KServiceTypeTrader::createInstanceFromQuery(QLatin1String("PlasmaNetworkManagement/VpnUiPlugin"), + QString::fromLatin1("[X-NetworkManager-Services]=='%1'").arg(serviceType), + this, QVariantList(), &error); + if (vpnUiPlugin && error.isEmpty()) { + const QString shortName = serviceType.section('.', -1); + m_vpnWidget = vpnUiPlugin->askUser(vpnSetting, this); + QVBoxLayout *layout = new QVBoxLayout(); + layout->addWidget(m_vpnWidget); + m_ui->vpnWidget->setLayout(layout); + m_ui->labelText->setText(i18n("For accessing the vpn connection %1 you need to provide secrets below:", m_connectionSettings->id())); + setWindowTitle(i18n("VPN secrets (%1) dialog", shortName)); + + // Hide generic password field and OK button in case of openconnect dialog + m_ui->labelPass->setVisible(false); + m_ui->password->setVisible(false); + if (shortName == QLatin1String("openconnect")) { + QAbstractButton *button = m_ui->buttonBox->button(QDialogButtonBox::Ok); + m_ui->buttonBox->removeButton(button); + } + } else { + qCWarning(PLASMA_NM) << error << ", serviceType == " << serviceType; + m_hasError = true; + m_error = SecretAgent::InternalError; + m_errorMessage = error; + } } } } @@ -148,23 +153,15 @@ NMVariantMapMap PasswordDialog::secrets() const { - NMVariantMapMap ret = m_connection; + NMVariantMapMap ret = m_connectionSettings->toMap(); QVariantMap result; - if (vpnWidget) { - result = vpnWidget->setting(); - } else if (!ui->password->text().isEmpty() && !m_neededSecrets.isEmpty()) { - result.insert(m_neededSecrets.first(), ui->password->text()); + if (m_vpnWidget) { + result = m_vpnWidget->setting(); + } else if (!m_ui->password->text().isEmpty() && !m_neededSecrets.isEmpty()) { + result.insert(m_neededSecrets.first(), m_ui->password->text()); } ret.insert(m_settingName, result); return ret; } - -void PasswordDialog::showPassword(bool show) -{ - if (show) - ui->password->setEchoMode(QLineEdit::Normal); - else - ui->password->setEchoMode(QLineEdit::Password); -} diff --git a/kded/passworddialog.ui b/kded/passworddialog.ui --- a/kded/passworddialog.ui +++ b/kded/passworddialog.ui @@ -6,71 +6,134 @@ 0 0 - 415 - 127 + 480 + 147 + + + 0 + 0 + + + + + 480 + 16777215 + + Password dialog - - - - - QFormLayout::ExpandingFieldsGrow + + + + + 1 + + + IconLabel + + + 8 - - 0 + + -1 - + + + + + + + + font-weight: bold + + + TextLabel + + + + + + + 0 + 0 + + + + + 16777215 + 16777215 + + TextLabel + + true + - + + + + + Password: - - + + 64 - - QLineEdit::Password - - - - - - - Show password + + true - - - - TextLabel + + + + Qt::Vertical - + + QSizePolicy::Preferred + + + + 20 + 40 + + + - + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + PasswordField + QLineEdit +
passwordfield.h
+
+
diff --git a/kded/secretagent.cpp b/kded/secretagent.cpp --- a/kded/secretagent.cpp +++ b/kded/secretagent.cpp @@ -350,9 +350,8 @@ return false; } - NetworkManager::ConnectionSettings connectionSettings(request.connection); - - NetworkManager::Setting::Ptr setting = connectionSettings.setting(request.setting_name); + NetworkManager::ConnectionSettings::Ptr connectionSettings = NetworkManager::ConnectionSettings::Ptr(new NetworkManager::ConnectionSettings(request.connection)); + NetworkManager::Setting::Ptr setting = connectionSettings->setting(request.setting_name); const bool requestNew = request.flags & RequestNew; const bool userRequested = request.flags & UserRequested; @@ -363,7 +362,7 @@ if (!requestNew && useWallet()) { if (m_wallet->isOpen()) { if (m_wallet->hasFolder("Network Management") && m_wallet->setFolder("Network Management")) { - QString key = QLatin1Char('{') % connectionSettings.uuid() % QLatin1Char('}') % QLatin1Char(';') % request.setting_name; + QString key = QLatin1Char('{') % connectionSettings->uuid() % QLatin1Char('}') % QLatin1Char(';') % request.setting_name; m_wallet->readMap(key, secretsMap); } } else { @@ -383,14 +382,9 @@ } if (requestNew || (allowInteraction && !setting->needSecrets(requestNew).isEmpty()) || (allowInteraction && userRequested) || (isVpn && allowInteraction)) { - m_dialog = new PasswordDialog(request.connection, request.flags, request.setting_name); + m_dialog = new PasswordDialog(connectionSettings, request.flags, request.setting_name); connect(m_dialog, &PasswordDialog::accepted, this, &SecretAgent::dialogAccepted); connect(m_dialog, &PasswordDialog::rejected, this, &SecretAgent::dialogRejected); - if (isVpn) { - m_dialog->setupVpnUi(connectionSettings); - } else { - m_dialog->setupGenericUi(connectionSettings); - } if (m_dialog->hasError()) { sendError(m_dialog->error(), @@ -401,16 +395,16 @@ return true; } else { request.dialog = m_dialog; - request.saveSecretsWithoutReply = !connectionSettings.permissions().isEmpty(); + request.saveSecretsWithoutReply = !connectionSettings->permissions().isEmpty(); m_dialog->show(); KWindowSystem::setState(m_dialog->winId(), NET::KeepAbove); KWindowSystem::forceActiveWindow(m_dialog->winId()); return false; } } else if (isVpn && userRequested) { // just return what we have NMVariantMapMap result; NetworkManager::VpnSetting::Ptr vpnSetting; - vpnSetting = connectionSettings.setting(NetworkManager::Setting::Vpn).dynamicCast(); + vpnSetting = connectionSettings->setting(NetworkManager::Setting::Vpn).dynamicCast(); //FIXME workaround when NM is asking for secrets which should be system-stored, if we send an empty map it // won't ask for additional secrets with AllowInteraction flag which would display the authentication dialog if (vpnSetting->secretsToMap().isEmpty()) { diff --git a/vpn/openconnect/openconnectauth.ui b/vpn/openconnect/openconnectauth.ui --- a/vpn/openconnect/openconnectauth.ui +++ b/vpn/openconnect/openconnectauth.ui @@ -10,6 +10,12 @@ 297
+ + + 0 + 0 + + 0 diff --git a/vpn/ssh/sshauth.ui b/vpn/ssh/sshauth.ui --- a/vpn/ssh/sshauth.ui +++ b/vpn/ssh/sshauth.ui @@ -29,13 +29,13 @@ - + Password: - + true diff --git a/vpn/sstp/sstpauth.ui b/vpn/sstp/sstpauth.ui --- a/vpn/sstp/sstpauth.ui +++ b/vpn/sstp/sstpauth.ui @@ -29,13 +29,13 @@ - + Password: - + true @@ -55,13 +55,13 @@
- - PasswordField QLineEdit
passwordfield.h
+ + diff --git a/vpn/strongswan/strongswanauth.ui b/vpn/strongswan/strongswanauth.ui --- a/vpn/strongswan/strongswanauth.ui +++ b/vpn/strongswan/strongswanauth.ui @@ -29,13 +29,13 @@ - + Password: - + true