LCOV - code coverage report
Current view: top level - cui/source/dialogs - passwdomdlg.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 69 0.0 %
Date: 2014-04-14 Functions: 0 12 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include "passwdomdlg.hxx"
      21             : 
      22             : #include "cuires.hrc"
      23             : #include "dialmgr.hxx"
      24             : 
      25             : #include <sfx2/tabdlg.hxx>
      26             : #include <vcl/fixed.hxx>
      27             : #include <vcl/edit.hxx>
      28             : #include <vcl/button.hxx>
      29             : #include <vcl/layout.hxx>
      30             : #include <vcl/settings.hxx>
      31             : #include <vcl/msgbox.hxx>
      32             : 
      33           0 : struct PasswordToOpenModifyDialog_Impl
      34             : {
      35             :     PasswordToOpenModifyDialog *    m_pParent;
      36             : 
      37             :     Edit*                       m_pPasswdToOpenED;
      38             :     Edit*                       m_pReenterPasswdToOpenED;
      39             :     VclExpander*                m_pOptionsExpander;
      40             :     OKButton*                   m_pOk;
      41             :     CheckBox*                   m_pOpenReadonlyCB;
      42             :     Edit*                       m_pPasswdToModifyED;
      43             :     Edit*                       m_pReenterPasswdToModifyED;
      44             : 
      45             :     OUString                    m_aOneMismatch;
      46             :     OUString                    m_aTwoMismatch;
      47             :     OUString                    m_aInvalidStateForOkButton;
      48             :     OUString                    m_aInvalidStateForOkButton_v2;
      49             : 
      50             :     bool                        m_bIsPasswordToModify;
      51             : 
      52             : 
      53             :     DECL_LINK( OkBtnClickHdl, OKButton * );
      54             : 
      55             :     PasswordToOpenModifyDialog_Impl( PasswordToOpenModifyDialog * pParent,
      56             :             sal_uInt16 nMinPasswdLen, sal_uInt16 nMaxPasswdLen, bool bIsPasswordToModify );
      57             : };
      58             : 
      59           0 : PasswordToOpenModifyDialog_Impl::PasswordToOpenModifyDialog_Impl(
      60             :         PasswordToOpenModifyDialog * pParent,
      61             :         sal_uInt16 nMinPasswdLen,
      62             :         sal_uInt16 nMaxPasswdLen,
      63             :         bool bIsPasswordToModify )
      64             :     : m_pParent( pParent )
      65           0 :     , m_aOneMismatch( CUI_RES( RID_SVXSTR_ONE_PASSWORD_MISMATCH ) )
      66           0 :     , m_aTwoMismatch( CUI_RES( RID_SVXSTR_TWO_PASSWORDS_MISMATCH ) )
      67           0 :     , m_aInvalidStateForOkButton( CUI_RES( RID_SVXSTR_INVALID_STATE_FOR_OK_BUTTON ) )
      68           0 :     , m_aInvalidStateForOkButton_v2( CUI_RES( RID_SVXSTR_INVALID_STATE_FOR_OK_BUTTON_V2 ) )
      69           0 :     , m_bIsPasswordToModify( bIsPasswordToModify )
      70             : {
      71           0 :     pParent->get(m_pPasswdToOpenED, "newpassEntry");
      72           0 :     pParent->get(m_pReenterPasswdToOpenED, "confirmpassEntry");
      73           0 :     pParent->get(m_pOk, "ok");
      74           0 :     pParent->get(m_pOpenReadonlyCB, "readonly");
      75           0 :     pParent->get(m_pPasswdToModifyED, "newpassroEntry");
      76           0 :     pParent->get(m_pReenterPasswdToModifyED, "confirmropassEntry");
      77           0 :     pParent->get(m_pOptionsExpander, "expander");
      78             : 
      79           0 :     m_pOk->SetClickHdl( LINK( this, PasswordToOpenModifyDialog_Impl, OkBtnClickHdl ) );
      80             : 
      81           0 :     if (nMaxPasswdLen)
      82             :     {
      83           0 :         m_pPasswdToOpenED->SetMaxTextLen( nMaxPasswdLen );
      84           0 :         m_pReenterPasswdToOpenED->SetMaxTextLen( nMaxPasswdLen );
      85           0 :         m_pPasswdToModifyED->SetMaxTextLen( nMaxPasswdLen );
      86           0 :         m_pReenterPasswdToModifyED->SetMaxTextLen( nMaxPasswdLen );
      87             :     }
      88             : 
      89             :     (void) nMinPasswdLen;   // currently not supported
      90             : 
      91           0 :     m_pPasswdToOpenED->GrabFocus();
      92             : 
      93           0 :     m_pOptionsExpander->Enable(bIsPasswordToModify);
      94           0 :     if (!bIsPasswordToModify)
      95           0 :         m_pOptionsExpander->Hide();
      96           0 : }
      97             : 
      98           0 : IMPL_LINK( PasswordToOpenModifyDialog_Impl, OkBtnClickHdl, OKButton *, EMPTYARG /*pBtn*/ )
      99             : {
     100           0 :     bool bInvalidState = !m_pOpenReadonlyCB->IsChecked() &&
     101           0 :             m_pPasswdToOpenED->GetText().isEmpty() &&
     102           0 :             m_pPasswdToModifyED->GetText().isEmpty();
     103           0 :     if (bInvalidState)
     104             :     {
     105             :         ErrorBox aErrorBox( m_pParent, WB_OK,
     106           0 :             m_bIsPasswordToModify? m_aInvalidStateForOkButton : m_aInvalidStateForOkButton_v2 );
     107           0 :         aErrorBox.Execute();
     108             :     }
     109             :     else // check for mismatched passwords...
     110             :     {
     111           0 :         const bool bToOpenMatch     = m_pPasswdToOpenED->GetText()   == m_pReenterPasswdToOpenED->GetText();
     112           0 :         const bool bToModifyMatch   = m_pPasswdToModifyED->GetText() == m_pReenterPasswdToModifyED->GetText();
     113           0 :         const int nMismatch = (bToOpenMatch? 0 : 1) + (bToModifyMatch? 0 : 1);
     114           0 :         if (nMismatch > 0)
     115             :         {
     116           0 :             ErrorBox aErrorBox( m_pParent, WB_OK, nMismatch == 1 ? m_aOneMismatch : m_aTwoMismatch );
     117           0 :             aErrorBox.Execute();
     118             : 
     119           0 :             Edit* pEdit = !bToOpenMatch ? m_pPasswdToOpenED : m_pPasswdToModifyED;
     120           0 :             Edit* pRepeatEdit = !bToOpenMatch? m_pReenterPasswdToOpenED : m_pReenterPasswdToModifyED;
     121           0 :             OUString aEmpty;
     122           0 :             if (nMismatch == 1)
     123             :             {
     124           0 :                 pEdit->SetText( aEmpty );
     125           0 :                 pRepeatEdit->SetText( aEmpty );
     126             :             }
     127           0 :             else if (nMismatch == 2)
     128             :             {
     129           0 :                 m_pPasswdToOpenED->SetText( aEmpty );
     130           0 :                 m_pReenterPasswdToOpenED->SetText( aEmpty );
     131           0 :                 m_pPasswdToModifyED->SetText( aEmpty );
     132           0 :                 m_pReenterPasswdToModifyED->SetText( aEmpty );
     133             :             }
     134           0 :             pEdit->GrabFocus();
     135             :         }
     136             :         else
     137             :         {
     138           0 :             m_pParent->EndDialog( RET_OK );
     139             :         }
     140             :     }
     141             : 
     142           0 :     return 0;
     143             : }
     144             : 
     145           0 : PasswordToOpenModifyDialog::PasswordToOpenModifyDialog(
     146             :     Window * pParent, sal_uInt16 nMinPasswdLen,
     147             :     sal_uInt16 nMaxPasswdLen, bool bIsPasswordToModify)
     148           0 :     : SfxModalDialog( pParent, "PasswordDialog", "cui/ui/password.ui" )
     149             : {
     150             :     m_pImpl.reset(new PasswordToOpenModifyDialog_Impl(this,
     151           0 :         nMinPasswdLen, nMaxPasswdLen, bIsPasswordToModify ) );
     152           0 : }
     153             : 
     154             : 
     155           0 : PasswordToOpenModifyDialog::~PasswordToOpenModifyDialog()
     156             : {
     157           0 : }
     158             : 
     159             : 
     160           0 : OUString PasswordToOpenModifyDialog::GetPasswordToOpen() const
     161             : {
     162             :     const bool bPasswdOk =
     163           0 :             !m_pImpl->m_pPasswdToOpenED->GetText().isEmpty() &&
     164           0 :             m_pImpl->m_pPasswdToOpenED->GetText() == m_pImpl->m_pReenterPasswdToOpenED->GetText();
     165           0 :     return bPasswdOk ? m_pImpl->m_pPasswdToOpenED->GetText() : OUString();
     166             : }
     167             : 
     168             : 
     169           0 : OUString PasswordToOpenModifyDialog::GetPasswordToModify() const
     170             : {
     171             :     const bool bPasswdOk =
     172           0 :             !m_pImpl->m_pPasswdToModifyED->GetText().isEmpty() &&
     173           0 :             m_pImpl->m_pPasswdToModifyED->GetText() == m_pImpl->m_pReenterPasswdToModifyED->GetText();
     174           0 :     return bPasswdOk ? m_pImpl->m_pPasswdToModifyED->GetText() : OUString();
     175             : }
     176             : 
     177             : 
     178           0 : bool PasswordToOpenModifyDialog::IsRecommendToOpenReadonly() const
     179             : {
     180           0 :     return m_pImpl->m_pOpenReadonlyCB->IsChecked();
     181           0 : }
     182             : 
     183             : 
     184             : 
     185             : 
     186             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10