LCOV - code coverage report
Current view: top level - uui/source - passworddlg.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 1 56 1.8 %
Date: 2015-06-13 12:38:46 Functions: 2 8 25.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 "passworddlg.hxx"
      21             : #include "ids.hrc"
      22             : 
      23             : #include <vcl/layout.hxx>
      24             : 
      25             : using namespace ::com::sun::star;
      26             : 
      27           0 : PasswordDialog::PasswordDialog(vcl::Window* _pParent,
      28             :     task::PasswordRequestMode nDlgMode, ResMgr * pResMgr,
      29             :     const OUString& aDocURL, bool bOpenToModify, bool bIsSimplePasswordRequest)
      30             :     : ModalDialog(_pParent, "PasswordDialog", "uui/ui/password.ui")
      31             :     , nMinLen(1)
      32             :     , aPasswdMismatch(ResId(STR_PASSWORD_MISMATCH, *pResMgr))
      33             :     , nDialogMode(nDlgMode)
      34           0 :     , pResourceMgr(pResMgr)
      35             : {
      36           0 :     get(m_pFTPassword, "newpassFT");
      37           0 :     get(m_pEDPassword, "newpassEntry");
      38           0 :     get(m_pFTConfirmPassword, "confirmpassFT");
      39           0 :     get(m_pEDConfirmPassword, "confirmpassEntry");
      40           0 :     get(m_pOKBtn, "ok");
      41             : 
      42           0 :     if( nDialogMode == task::PasswordRequestMode_PASSWORD_REENTER )
      43             :     {
      44           0 :         const sal_uInt16 nOpenToModifyErrStrId = bOpenToModify ? STR_ERROR_PASSWORD_TO_MODIFY_WRONG : STR_ERROR_PASSWORD_TO_OPEN_WRONG;
      45           0 :         const sal_uInt16 nErrStrId = bIsSimplePasswordRequest ? STR_ERROR_SIMPLE_PASSWORD_WRONG : nOpenToModifyErrStrId;
      46           0 :         OUString aErrorMsg(ResId(nErrStrId, *pResourceMgr).toString());
      47           0 :         ScopedVclPtrInstance< MessageDialog > aErrorBox(GetParent(), aErrorMsg);
      48           0 :         aErrorBox->Execute();
      49             :     }
      50             : 
      51             :     // default settings for enter password or reenter passwd...
      52           0 :     OUString aTitle(ResId(STR_TITLE_ENTER_PASSWORD, *pResourceMgr).toString());
      53           0 :     m_pFTConfirmPassword->Hide();
      54           0 :     m_pEDConfirmPassword->Hide();
      55           0 :     m_pFTConfirmPassword->Enable( false );
      56           0 :     m_pEDConfirmPassword->Enable( false );
      57             : 
      58             :     // settings for create password
      59           0 :     if (nDialogMode == task::PasswordRequestMode_PASSWORD_CREATE)
      60             :     {
      61           0 :         aTitle = ResId(STR_TITLE_CREATE_PASSWORD, *pResourceMgr).toString();
      62             : 
      63           0 :         m_pFTConfirmPassword->SetText(ResId(STR_CONFIRM_SIMPLE_PASSWORD, *pResourceMgr).toString());
      64             : 
      65           0 :         m_pFTConfirmPassword->Show();
      66           0 :         m_pEDConfirmPassword->Show();
      67           0 :         m_pFTConfirmPassword->Enable( true );
      68           0 :         m_pEDConfirmPassword->Enable( true );
      69             :     }
      70             : 
      71           0 :     SetText( aTitle );
      72             : 
      73           0 :     sal_uInt16 nStrId = bOpenToModify ? STR_ENTER_PASSWORD_TO_MODIFY : STR_ENTER_PASSWORD_TO_OPEN;
      74           0 :     m_pFTPassword->SetText(ResId(nStrId, *pResourceMgr).toString());
      75           0 :     m_pFTPassword->SetText( m_pFTPassword->GetText() + aDocURL );
      76           0 :     if (bIsSimplePasswordRequest)
      77             :     {
      78             :         DBG_ASSERT( aDocURL.isEmpty(), "A simple password request should not have a document URL! Use document password request instead." );
      79           0 :         m_pFTPassword->SetText(ResId(STR_ENTER_SIMPLE_PASSWORD, *pResourceMgr).toString());
      80             :     }
      81             : 
      82           0 :     m_pOKBtn->SetClickHdl( LINK( this, PasswordDialog, OKHdl_Impl ) );
      83           0 : }
      84             : 
      85           0 : PasswordDialog::~PasswordDialog()
      86             : {
      87           0 :     disposeOnce();
      88           0 : }
      89             : 
      90           0 : void PasswordDialog::dispose()
      91             : {
      92           0 :     m_pFTPassword.clear();
      93           0 :     m_pEDPassword.clear();
      94           0 :     m_pFTConfirmPassword.clear();
      95           0 :     m_pEDConfirmPassword.clear();
      96           0 :     m_pOKBtn.clear();
      97           0 :     ModalDialog::dispose();
      98           0 : }
      99             : 
     100           0 : IMPL_LINK_NOARG(PasswordDialog, OKHdl_Impl)
     101             : {
     102           0 :     bool bEDPasswdValid = m_pEDPassword->GetText().getLength() >= nMinLen;
     103           0 :     bool bPasswdMismatch = m_pEDConfirmPassword->GetText() != m_pEDPassword->GetText();
     104           0 :     bool bValid = (!m_pEDConfirmPassword->IsVisible() && bEDPasswdValid) ||
     105           0 :             (m_pEDConfirmPassword->IsVisible() && bEDPasswdValid && !bPasswdMismatch);
     106             : 
     107           0 :     if (m_pEDConfirmPassword->IsVisible() && bPasswdMismatch)
     108             :     {
     109           0 :         ScopedVclPtrInstance< MessageDialog > aErrorBox(this, aPasswdMismatch);
     110           0 :         aErrorBox->Execute();
     111             :     }
     112           0 :     else if (bValid)
     113           0 :         EndDialog( RET_OK );
     114             : 
     115           0 :     return 1;
     116         159 : }
     117             : 
     118             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
     119             : 

Generated by: LCOV version 1.11