LCOV - code coverage report
Current view: top level - sfx2/source/dialog - passwd.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 1 125 0.8 %
Date: 2015-06-13 12:38:46 Functions: 2 14 14.3 %
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             : 
      21             : // Include ---------------------------------------------------------------
      22             : #include <vcl/layout.hxx>
      23             : 
      24             : #include <sfx2/passwd.hxx>
      25             : #include "sfxtypes.hxx"
      26             : #include <sfx2/sfxresid.hxx>
      27             : 
      28             : #include "dialog.hrc"
      29             : 
      30             : 
      31             : 
      32           0 : IMPL_LINK( SfxPasswordDialog, EditModifyHdl, Edit *, pEdit )
      33             : {
      34           0 :     if (mbAsciiOnly && (pEdit == mpPassword1ED || pEdit == mpPassword2ED))
      35             :     {
      36           0 :         OUString aTest( pEdit->GetText() );
      37           0 :         const sal_Unicode* pTest = aTest.getStr();
      38           0 :         sal_Int32 nLen = aTest.getLength();
      39           0 :         OUStringBuffer aFilter( nLen );
      40           0 :         bool bReset = false;
      41           0 :         for( sal_Int32 i = 0; i < nLen; i++ )
      42             :         {
      43           0 :             if( *pTest > 0x007f )
      44           0 :                 bReset = true;
      45             :             else
      46           0 :                 aFilter.append( *pTest );
      47           0 :             pTest++;
      48             :         }
      49           0 :         if( bReset )
      50             :         {
      51           0 :             pEdit->SetSelection( Selection( 0, nLen ) );
      52           0 :             pEdit->ReplaceSelected( aFilter.makeStringAndClear() );
      53           0 :         }
      54             : 
      55             :     }
      56           0 :     bool bEnable = mpPassword1ED->GetText().getLength() >= mnMinLen;
      57           0 :     if( mpPassword2ED->IsVisible() )
      58           0 :         bEnable = (bEnable && (mpPassword2ED->GetText().getLength() >= mnMinLen));
      59           0 :     mpOKBtn->Enable( bEnable );
      60           0 :     return 0;
      61             : }
      62             : 
      63           0 : IMPL_LINK_NOARG(SfxPasswordDialog, OKHdl)
      64             : {
      65           0 :     bool bConfirmFailed = bool( mnExtras & SfxShowExtras::CONFIRM ) &&
      66           0 :                           ( GetConfirm() != GetPassword() );
      67           0 :     if( ( mnExtras & SfxShowExtras::CONFIRM2 ) && ( GetConfirm2() != GetPassword2() ) )
      68           0 :         bConfirmFailed = true;
      69           0 :     if ( bConfirmFailed )
      70             :     {
      71           0 :         ScopedVclPtrInstance< MessageDialog > aBox(this, SfxResId(STR_ERROR_WRONG_CONFIRM));
      72           0 :         aBox->Execute();
      73           0 :         mpConfirm1ED->SetText( OUString() );
      74           0 :         mpConfirm1ED->GrabFocus();
      75             :     }
      76             :     else
      77           0 :         EndDialog( RET_OK );
      78           0 :     return 0;
      79             : }
      80             : 
      81             : // CTOR / DTOR -----------------------------------------------------------
      82             : 
      83           0 : SfxPasswordDialog::SfxPasswordDialog(vcl::Window* pParent, const OUString* pGroupText)
      84             :     : ModalDialog(pParent, "PasswordDialog", "sfx/ui/password.ui")
      85             :     , maMinLenPwdStr(SFX2_RESSTR(STR_PASSWD_MIN_LEN))
      86             :     , maMinLenPwdStr1(SFX2_RESSTR(STR_PASSWD_MIN_LEN1))
      87             :     , maEmptyPwdStr(SFX2_RESSTR(STR_PASSWD_EMPTY))
      88             :     , mnMinLen(5)
      89             :     , mnExtras(SfxShowExtras::NONE)
      90           0 :     , mbAsciiOnly(false)
      91             : {
      92           0 :     get(mpPassword1Box, "password1frame");
      93           0 :     get(mpUserFT, "userft");
      94           0 :     get(mpUserED, "usered");
      95           0 :     get(mpPassword1FT, "pass1ft");
      96           0 :     get(mpPassword1ED, "pass1ed");
      97           0 :     get(mpConfirm1FT, "confirm1ft");
      98           0 :     get(mpConfirm1ED, "confirm1ed");
      99             : 
     100           0 :     get(mpPassword2Box, "password2frame");
     101           0 :     get(mpPassword2FT, "pass2ft");
     102           0 :     get(mpPassword2ED, "pass2ed");
     103           0 :     get(mpConfirm2FT, "confirm2ft");
     104           0 :     get(mpConfirm2ED, "confirm2ed");
     105             : 
     106           0 :     get(mpMinLengthFT, "minlenft");
     107             : 
     108           0 :     get(mpOKBtn, "ok");
     109             : 
     110           0 :     mpPassword1ED->SetAccessibleName(SFX2_RESSTR(STR_PASSWD));
     111             : 
     112           0 :     Link<> aLink = LINK( this, SfxPasswordDialog, EditModifyHdl );
     113           0 :     mpPassword1ED->SetModifyHdl( aLink );
     114           0 :     mpPassword2ED->SetModifyHdl( aLink );
     115           0 :     aLink = LINK( this, SfxPasswordDialog, OKHdl );
     116           0 :     mpOKBtn->SetClickHdl( aLink );
     117             : 
     118           0 :     if (pGroupText)
     119           0 :         mpPassword1Box->set_label(*pGroupText);
     120             : 
     121             :     //set the text to the password length
     122           0 :     SetPasswdText();
     123           0 : }
     124             : 
     125           0 : SfxPasswordDialog::~SfxPasswordDialog()
     126             : {
     127           0 :     disposeOnce();
     128           0 : }
     129             : 
     130           0 : void SfxPasswordDialog::dispose()
     131             : {
     132           0 :     mpPassword1Box.clear();
     133           0 :     mpUserFT.clear();
     134           0 :     mpUserED.clear();
     135           0 :     mpPassword1FT.clear();
     136           0 :     mpPassword1ED.clear();
     137           0 :     mpConfirm1FT.clear();
     138           0 :     mpConfirm1ED.clear();
     139           0 :     mpPassword2Box.clear();
     140           0 :     mpPassword2FT.clear();
     141           0 :     mpPassword2ED.clear();
     142           0 :     mpConfirm2FT.clear();
     143           0 :     mpConfirm2ED.clear();
     144           0 :     mpMinLengthFT.clear();
     145           0 :     mpOKBtn.clear();
     146           0 :     ModalDialog::dispose();
     147           0 : }
     148             : 
     149           0 : void SfxPasswordDialog::SetPasswdText( )
     150             : {
     151             : //set the new string to the minimum password length
     152           0 :     if( mnMinLen == 0 )
     153           0 :         mpMinLengthFT->SetText(maEmptyPwdStr);
     154             :     else
     155             :     {
     156           0 :         if( mnMinLen == 1 )
     157           0 :             mpMinLengthFT->SetText(maMinLenPwdStr1);
     158             :         else
     159             :         {
     160           0 :             maMainPwdStr = maMinLenPwdStr;
     161           0 :             maMainPwdStr = maMainPwdStr.replaceAll( "$(MINLEN)", OUString::number((sal_Int32) mnMinLen ) );
     162           0 :             mpMinLengthFT->SetText(maMainPwdStr);
     163             :         }
     164             :     }
     165           0 : }
     166             : 
     167             : 
     168             : 
     169           0 : void SfxPasswordDialog::SetMinLen( sal_uInt16 nLen )
     170             : {
     171           0 :     mnMinLen = nLen;
     172           0 :     SetPasswdText();
     173           0 :     EditModifyHdl( NULL );
     174           0 : }
     175             : 
     176           0 : void SfxPasswordDialog::ShowMinLengthText(bool bShow)
     177             : {
     178           0 :     mpMinLengthFT->Show(bShow);
     179           0 : }
     180             : 
     181             : 
     182             : 
     183           0 : short SfxPasswordDialog::Execute()
     184             : {
     185           0 :     mpUserFT->Hide();
     186           0 :     mpUserED->Hide();
     187           0 :     mpConfirm1FT->Hide();
     188           0 :     mpConfirm1ED->Hide();
     189           0 :     mpPassword1FT->Hide();
     190           0 :     mpPassword2Box->Hide();
     191           0 :     mpPassword2FT->Hide();
     192           0 :     mpPassword2ED->Hide();
     193           0 :     mpPassword2FT->Hide();
     194           0 :     mpConfirm2FT->Hide();
     195           0 :     mpConfirm2ED->Hide();
     196             : 
     197           0 :     if (mnExtras != SfxShowExtras::NONE)
     198           0 :         mpPassword1FT->Show();
     199           0 :     if (mnExtras & SfxShowExtras::USER)
     200             :     {
     201           0 :         mpUserFT->Show();
     202           0 :         mpUserED->Show();
     203             :     }
     204           0 :     if (mnExtras & SfxShowExtras::CONFIRM)
     205             :     {
     206           0 :         mpConfirm1FT->Show();
     207           0 :         mpConfirm1ED->Show();
     208             :     }
     209           0 :     if (mnExtras & SfxShowExtras::PASSWORD2)
     210             :     {
     211           0 :         mpPassword2Box->Show();
     212           0 :         mpPassword2FT->Show();
     213           0 :         mpPassword2ED->Show();
     214             :     }
     215           0 :     if (mnExtras & SfxShowExtras::CONFIRM2)
     216             :     {
     217           0 :         mpConfirm2FT->Show();
     218           0 :         mpConfirm2ED->Show();
     219             :     }
     220             : 
     221           0 :     return ModalDialog::Execute();
     222         648 : }
     223             : 
     224             : 
     225             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11