[kde-doc-english] [kdelibs] kdeui/dialogs: kdeui: Streamline KPasswordDialog.

Michael Pyne mpyne at kde.org
Mon Oct 14 20:47:05 UTC 2013


Git commit f04f6abf8e556fa98e838becaf5ca19e316b779c by Michael Pyne.
Committed on 14/10/2013 at 19:10.
Pushed by mpyne into branch 'master'.

kdeui: Streamline KPasswordDialog.

A user reported a couple of years ago that the "Anonymous login"
checkbox is badly placed in KPasswordDialog, appearing in between the
user and password fields and sticking out like a sore thumb.

Instead of just moving the checkbox, I took the opportunity to make the
U/I match the underlying code. Since "Anonymous" mode makes the existing
U/I set both username and password fields to be read-only, it's really a
separate authentication scheme and should be treated as such, especially
since it is hard to tell visually that the Anonymous checkbox is
responsible for disabling the line edits above and below it.

The existing code relies somewhat on the widgets that are present in the
U/I file, so instead of trying to merge the new radio buttons with the
existing widgets I separated out the "anonymous" radio button and its
new counterpart, and left the rest of the existing widgets parented
under a hidden widget to minimize code churn and the risk of introducing
bugs.

Tested with a handy FTP server, and with the included KPasswordDialog
test suite.

BUG:272313
FIXED-IN:4.12
DIGEST:Improvements to KPasswordDialog
GUI:

M  +29   -27   kdeui/dialogs/kpassworddialog.cpp
M  +107  -73   kdeui/dialogs/kpassworddialog.ui

http://commits.kde.org/kdelibs/f04f6abf8e556fa98e838becaf5ca19e316b779c

diff --git a/kdeui/dialogs/kpassworddialog.cpp b/kdeui/dialogs/kpassworddialog.cpp
index fc4f229..6245ce4 100644
--- a/kdeui/dialogs/kpassworddialog.cpp
+++ b/kdeui/dialogs/kpassworddialog.cpp
@@ -82,20 +82,12 @@ KPasswordDialog::~KPasswordDialog()
 
 void KPasswordDialog::KPasswordDialogPrivate::updateFields()
 {
-    if (q->anonymousMode())
-    {
-        ui.userEdit->setEnabled( false );
-        ui.domainEdit->setEnabled( false );
-        ui.passEdit->setEnabled( false );
-    	ui.keepCheckBox->setEnabled( false );
-    }
-    else
-    {
-        ui.userEdit->setEnabled(!( m_flags & KPasswordDialog::UsernameReadOnly ));
-        ui.domainEdit->setEnabled(!( m_flags & KPasswordDialog::DomainReadOnly ));
-        ui.passEdit->setEnabled( true );
-    	ui.keepCheckBox->setEnabled( true );
+    if (m_flags & KPasswordDialog::UsernameReadOnly) {
+        ui.userEdit->setReadOnly(true);
+        ui.credentialsGroup->setFocusProxy(ui.passEdit);
     }
+    ui.domainEdit->setReadOnly(( m_flags & KPasswordDialog::DomainReadOnly ));
+    ui.credentialsGroup->setEnabled( !q->anonymousMode() );
 }
 
 void KPasswordDialog::KPasswordDialogPrivate::init()
@@ -106,6 +98,7 @@ void KPasswordDialog::KPasswordDialogPrivate::init()
     // Row 4: Username field
     if ( m_flags & KPasswordDialog::ShowUsernameLine ) {
         ui.userEdit->setFocus();
+        ui.credentialsGroup->setFocusProxy( ui.userEdit );
         QObject::connect( ui.userEdit, SIGNAL(returnPressed()), ui.passEdit, SLOT(setFocus()) );
     } else {
         ui.userNameLabel->hide();
@@ -113,15 +106,13 @@ void KPasswordDialog::KPasswordDialogPrivate::init()
         ui.domainLabel->hide();
         ui.domainEdit->hide();
         ui.passEdit->setFocus();
+        ui.credentialsGroup->setFocusProxy( ui.passEdit );
     }
 
     if ( !( m_flags & KPasswordDialog::ShowAnonymousLoginCheckBox ) )
     {
-        ui.anonymousCheckBox->hide();
-    }
-    else
-    {
-        QObject::connect( ui.anonymousCheckBox, SIGNAL(stateChanged(int)), q, SLOT(updateFields()) );
+        ui.anonymousRadioButton->hide();
+        ui.usePasswordButton->hide();
     }
 
     if ( !( m_flags & KPasswordDialog::ShowDomainLine ) )
@@ -200,12 +191,21 @@ QString KPasswordDialog::domain() const
 
 void KPasswordDialog::setAnonymousMode(bool anonymous)
 {
-    d->ui.anonymousCheckBox->setChecked( anonymous );
+    if (anonymous && !(d->m_flags & KPasswordDialog::ShowAnonymousLoginCheckBox)) {
+        // This is an error case, but we can at least let user see what's about
+        // to happen if they proceed.
+        d->ui.anonymousRadioButton->setVisible( true );
+
+        d->ui.usePasswordButton->setVisible( true );
+        d->ui.usePasswordButton->setEnabled( false );
+    }
+
+    d->ui.anonymousRadioButton->setChecked( anonymous );
 }
 
 bool KPasswordDialog::anonymousMode() const
 {
-    return d->ui.anonymousCheckBox->isChecked();
+    return d->ui.anonymousRadioButton->isChecked();
 }
 
 
@@ -342,17 +342,19 @@ void KPasswordDialog::setKnownLogins( const QMap<QString, QString>& knownLogins
 
     Q_ASSERT( !d->ui.userEdit->isReadOnly() );
     if ( !d->userEditCombo ) {
+        int row = -1;
+        QFormLayout::ItemRole userEditRole = QFormLayout::FieldRole;
+
+        d->ui.formLayout->getWidgetPosition(d->ui.userEdit, &row, &userEditRole);
         d->ui.formLayout->removeWidget(d->ui.userEdit);
         delete d->ui.userEdit;
-        d->userEditCombo = new KComboBox( true, mainWidget() );
+        d->userEditCombo = new KComboBox( true, d->ui.credentialsGroup );
         d->ui.userEdit = d->userEditCombo->lineEdit();
-//        QSize s = d->userEditCombo->sizeHint();
-//        d->ui.userEditCombo->setFixedHeight( s.height() );
-//        d->ui.userEditCombo->setMinimumWidth( s.width() );
         d->ui.userNameLabel->setBuddy( d->userEditCombo );
-        d->ui.formLayout->setWidget( d->commentRow, QFormLayout::FieldRole, d->userEditCombo );
-        setTabOrder( d->ui.userEdit, d->ui.anonymousCheckBox );
-        setTabOrder( d->ui.anonymousCheckBox, d->ui.domainEdit );
+        d->ui.formLayout->setWidget( row > -1 ? row : 0, userEditRole, d->userEditCombo );
+
+        setTabOrder( d->ui.userEdit, d->ui.anonymousRadioButton );
+        setTabOrder( d->ui.anonymousRadioButton, d->ui.domainEdit );
         setTabOrder( d->ui.domainEdit, d->ui.passEdit );
         setTabOrder( d->ui.passEdit, d->ui.keepCheckBox );
         connect( d->ui.userEdit, SIGNAL(returnPressed()), d->ui.passEdit, SLOT(setFocus()) );
diff --git a/kdeui/dialogs/kpassworddialog.ui b/kdeui/dialogs/kpassworddialog.ui
index 2649870..4232e88 100644
--- a/kdeui/dialogs/kpassworddialog.ui
+++ b/kdeui/dialogs/kpassworddialog.ui
@@ -7,7 +7,7 @@
     <x>0</x>
     <y>0</y>
     <width>400</width>
-    <height>194</height>
+    <height>227</height>
    </rect>
   </property>
   <layout class="QVBoxLayout">
@@ -15,10 +15,7 @@
     <number>0</number>
    </property>
    <item>
-    <layout class="QHBoxLayout">
-     <property name="margin">
-      <number>0</number>
-     </property>
+    <layout class="QHBoxLayout" name="hboxLayout">
      <item>
       <widget class="QLabel" name="prompt">
        <property name="sizePolicy">
@@ -63,90 +60,127 @@
     <widget class="KTitleWidget" name="errorMessage"/>
    </item>
    <item>
-    <layout class="QFormLayout" name="formLayout">
-     <property name="margin">
-      <number>0</number>
+    <widget class="QRadioButton" name="anonymousRadioButton">
+     <property name="text">
+      <string>No password, use anonymous (or guest) login</string>
      </property>
-     <item row="0" column="0">
-      <widget class="QLabel" name="userNameLabel">
-       <property name="text">
-        <string>Username:</string>
-       </property>
-       <property name="buddy">
-        <cstring>userEdit</cstring>
-       </property>
-      </widget>
-     </item>
-     <item row="0" column="1">
-      <widget class="QLineEdit" name="userEdit"/>
-     </item>
-     <item row="1" column="0">
-      <widget class="QCheckBox" name="anonymousCheckBox">
-       <property name="text">
-        <string>Anonymous</string>
-       </property>
-      </widget>
-     </item>
-     <item row="2" column="0">
-      <widget class="QLabel" name="domainLabel">
-       <property name="text">
-        <string>Domain:</string>
-       </property>
-       <property name="buddy">
-        <cstring>domainEdit</cstring>
-       </property>
-      </widget>
-     </item>
-     <item row="2" column="1">
-      <widget class="KLineEdit" name="domainEdit"/>
-     </item>
-     <item row="3" column="0">
-      <widget class="QLabel" name="passwordLabel">
-       <property name="text">
-        <string>Password:</string>
-       </property>
-       <property name="buddy">
-        <cstring>passEdit</cstring>
-       </property>
-      </widget>
-     </item>
-     <item row="3" column="1">
-      <widget class="KLineEdit" name="passEdit">
-       <property name="passwordMode">
-        <bool>true</bool>
-       </property>
-      </widget>
-     </item>
-     <item row="4" column="1">
-      <widget class="QCheckBox" name="keepCheckBox">
-       <property name="text">
-        <string>Remember password</string>
-       </property>
-      </widget>
-     </item>
-    </layout>
+    </widget>
+   </item>
+   <item>
+    <widget class="QRadioButton" name="usePasswordButton">
+     <property name="text">
+      <string>Use this password:</string>
+     </property>
+     <property name="checked">
+      <bool>true</bool>
+     </property>
+    </widget>
+   </item>
+   <item>
+    <widget class="QWidget" name="credentialsGroup" native="true">
+     <layout class="QFormLayout" name="formLayout">
+      <property name="margin">
+       <number>1</number>
+      </property>
+      <item row="1" column="0">
+       <widget class="QLabel" name="userNameLabel">
+        <property name="text">
+         <string>Username:</string>
+        </property>
+       </widget>
+      </item>
+      <item row="1" column="1">
+       <widget class="QLineEdit" name="userEdit"/>
+      </item>
+      <item row="3" column="0">
+       <widget class="QLabel" name="domainLabel">
+        <property name="text">
+         <string>Domain:</string>
+        </property>
+       </widget>
+      </item>
+      <item row="3" column="1">
+       <widget class="KLineEdit" name="domainEdit"/>
+      </item>
+      <item row="4" column="0">
+       <widget class="QLabel" name="passwordLabel">
+        <property name="text">
+         <string>Password:</string>
+        </property>
+       </widget>
+      </item>
+      <item row="4" column="1">
+       <widget class="KLineEdit" name="passEdit">
+        <property name="passwordMode">
+         <bool>true</bool>
+        </property>
+       </widget>
+      </item>
+      <item row="5" column="1">
+       <widget class="QCheckBox" name="keepCheckBox">
+        <property name="text">
+         <string>Remember password</string>
+        </property>
+       </widget>
+      </item>
+     </layout>
+    </widget>
    </item>
   </layout>
  </widget>
  <customwidgets>
   <customwidget>
-   <class>KTitleWidget</class>
-   <extends>QWidget</extends>
-   <header>ktitlewidget.h</header>
-  </customwidget>
-  <customwidget>
    <class>KLineEdit</class>
    <extends>QLineEdit</extends>
    <header>klineedit.h</header>
   </customwidget>
+  <customwidget>
+   <class>KTitleWidget</class>
+   <extends>QWidget</extends>
+   <header>ktitlewidget.h</header>
+  </customwidget>
  </customwidgets>
  <tabstops>
+  <tabstop>anonymousRadioButton</tabstop>
+  <tabstop>usePasswordButton</tabstop>
   <tabstop>userEdit</tabstop>
-  <tabstop>anonymousCheckBox</tabstop>
   <tabstop>domainEdit</tabstop>
   <tabstop>passEdit</tabstop>
   <tabstop>keepCheckBox</tabstop>
  </tabstops>
  <resources/>
- <connections/>
+ <connections>
+  <connection>
+   <sender>usePasswordButton</sender>
+   <signal>toggled(bool)</signal>
+   <receiver>credentialsGroup</receiver>
+   <slot>setEnabled(bool)</slot>
+   <hints>
+    <hint type="sourcelabel">
+     <x>77</x>
+     <y>92</y>
+    </hint>
+    <hint type="destinationlabel">
+     <x>50</x>
+     <y>216</y>
+    </hint>
+   </hints>
+  </connection>
+  <connection>
+   <sender>usePasswordButton</sender>
+   <signal>clicked()</signal>
+   <receiver>credentialsGroup</receiver>
+   <slot>setFocus()</slot>
+   <hints>
+    <hint type="sourcelabel">
+     <x>84</x>
+     <y>93</y>
+    </hint>
+    <hint type="destinationlabel">
+     <x>29</x>
+     <y>219</y>
+    </hint>
+   </hints>
+  </connection>
+ </connections>
 </ui>


More information about the kde-doc-english mailing list