LCOV - code coverage report
Current view: top level - sfx2/source/dialog - passwd.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 1 106 0.9 %
Date: 2014-11-03 Functions: 2 11 18.2 %
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_INLINE_START( 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           0 : IMPL_LINK_INLINE_END(SfxPasswordDialog, EditModifyHdl, Edit *, pEdit)
      63             : 
      64             : 
      65             : 
      66           0 : IMPL_LINK_NOARG(SfxPasswordDialog, OKHdl)
      67             : {
      68           0 :     bool bConfirmFailed = ( ( mnExtras & SHOWEXTRAS_CONFIRM ) == SHOWEXTRAS_CONFIRM ) &&
      69           0 :                             ( GetConfirm() != GetPassword() );
      70           0 :     if( ( mnExtras & SHOWEXTRAS_CONFIRM2 ) == SHOWEXTRAS_CONFIRM2 && ( GetConfirm2() != GetPassword2() ) )
      71           0 :         bConfirmFailed = true;
      72           0 :     if ( bConfirmFailed )
      73             :     {
      74           0 :         MessageDialog aBox(this, SfxResId(STR_ERROR_WRONG_CONFIRM));
      75           0 :         aBox.Execute();
      76           0 :         mpConfirm1ED->SetText( OUString() );
      77           0 :         mpConfirm1ED->GrabFocus();
      78             :     }
      79             :     else
      80           0 :         EndDialog( RET_OK );
      81           0 :     return 0;
      82             : }
      83             : 
      84             : // CTOR / DTOR -----------------------------------------------------------
      85             : 
      86           0 : SfxPasswordDialog::SfxPasswordDialog(vcl::Window* pParent, const OUString* pGroupText)
      87             :     : ModalDialog(pParent, "PasswordDialog", "sfx/ui/password.ui")
      88             :     , maMinLenPwdStr(SFX2_RESSTR(STR_PASSWD_MIN_LEN))
      89             :     , maMinLenPwdStr1(SFX2_RESSTR(STR_PASSWD_MIN_LEN1))
      90             :     , maEmptyPwdStr(SFX2_RESSTR(STR_PASSWD_EMPTY))
      91             :     , mnMinLen(5)
      92             :     , mnExtras(0)
      93           0 :     , mbAsciiOnly(false)
      94             : {
      95           0 :     get(mpPassword1Box, "password1frame");
      96           0 :     get(mpUserFT, "userft");
      97           0 :     get(mpUserED, "usered");
      98           0 :     get(mpPassword1FT, "pass1ft");
      99           0 :     get(mpPassword1ED, "pass1ed");
     100           0 :     get(mpConfirm1FT, "confirm1ft");
     101           0 :     get(mpConfirm1ED, "confirm1ed");
     102             : 
     103           0 :     get(mpPassword2Box, "password2frame");
     104           0 :     get(mpPassword2FT, "pass2ft");
     105           0 :     get(mpPassword2ED, "pass2ed");
     106           0 :     get(mpConfirm2FT, "confirm2ft");
     107           0 :     get(mpConfirm2ED, "confirm2ed");
     108             : 
     109           0 :     get(mpMinLengthFT, "minlenft");
     110             : 
     111           0 :     get(mpOKBtn, "ok");
     112             : 
     113           0 :     mpPassword1ED->SetAccessibleName(SFX2_RESSTR(STR_PASSWD));
     114             : 
     115           0 :     Link aLink = LINK( this, SfxPasswordDialog, EditModifyHdl );
     116           0 :     mpPassword1ED->SetModifyHdl( aLink );
     117           0 :     mpPassword2ED->SetModifyHdl( aLink );
     118           0 :     aLink = LINK( this, SfxPasswordDialog, OKHdl );
     119           0 :     mpOKBtn->SetClickHdl( aLink );
     120             : 
     121           0 :     if (pGroupText)
     122           0 :         mpPassword1Box->set_label(*pGroupText);
     123             : 
     124             :     //set the text to the password length
     125           0 :     SetPasswdText();
     126           0 : }
     127             : 
     128             : 
     129             : 
     130           0 : void SfxPasswordDialog::SetPasswdText( )
     131             : {
     132             : //set the new string to the minimum password length
     133           0 :     if( mnMinLen == 0 )
     134           0 :         mpMinLengthFT->SetText(maEmptyPwdStr);
     135             :     else
     136             :     {
     137           0 :         if( mnMinLen == 1 )
     138           0 :             mpMinLengthFT->SetText(maMinLenPwdStr1);
     139             :         else
     140             :         {
     141           0 :             maMainPwdStr = maMinLenPwdStr;
     142           0 :             maMainPwdStr = maMainPwdStr.replaceAll( "$(MINLEN)", OUString::number((sal_Int32) mnMinLen ) );
     143           0 :             mpMinLengthFT->SetText(maMainPwdStr);
     144             :         }
     145             :     }
     146           0 : }
     147             : 
     148             : 
     149             : 
     150           0 : void SfxPasswordDialog::SetMinLen( sal_uInt16 nLen )
     151             : {
     152           0 :     mnMinLen = nLen;
     153           0 :     SetPasswdText();
     154           0 :     EditModifyHdl( NULL );
     155           0 : }
     156             : 
     157           0 : void SfxPasswordDialog::ShowMinLengthText(bool bShow)
     158             : {
     159           0 :     mpMinLengthFT->Show(bShow);
     160           0 : }
     161             : 
     162             : 
     163             : 
     164           0 : short SfxPasswordDialog::Execute()
     165             : {
     166           0 :     mpUserFT->Hide();
     167           0 :     mpUserED->Hide();
     168           0 :     mpConfirm1FT->Hide();
     169           0 :     mpConfirm1ED->Hide();
     170           0 :     mpPassword1FT->Hide();
     171           0 :     mpPassword2Box->Hide();
     172           0 :     mpPassword2FT->Hide();
     173           0 :     mpPassword2ED->Hide();
     174           0 :     mpPassword2FT->Hide();
     175           0 :     mpConfirm2FT->Hide();
     176           0 :     mpConfirm2ED->Hide();
     177             : 
     178           0 :     if (mnExtras != SHOWEXTRAS_NONE)
     179           0 :         mpPassword1FT->Show();
     180           0 :     if (mnExtras & SHOWEXTRAS_USER)
     181             :     {
     182           0 :         mpUserFT->Show();
     183           0 :         mpUserED->Show();
     184             :     }
     185           0 :     if (mnExtras & SHOWEXTRAS_CONFIRM)
     186             :     {
     187           0 :         mpConfirm1FT->Show();
     188           0 :         mpConfirm1ED->Show();
     189             :     }
     190           0 :     if (mnExtras & SHOWEXTRAS_PASSWORD2)
     191             :     {
     192           0 :         mpPassword2Box->Show();
     193           0 :         mpPassword2FT->Show();
     194           0 :         mpPassword2ED->Show();
     195             :     }
     196           0 :     if (mnExtras & SHOWEXTRAS_CONFIRM2)
     197             :     {
     198           0 :         mpConfirm2FT->Show();
     199           0 :         mpConfirm2ED->Show();
     200             :     }
     201             : 
     202           0 :     return ModalDialog::Execute();
     203         951 : }
     204             : 
     205             : 
     206             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10