LCOV - code coverage report
Current view: top level - sfx2/source/dialog - passwd.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 1 104 1.0 %
Date: 2014-04-14 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/msgbox.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 :         ErrorBox aBox( this, SfxResId( MSG_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(Window* pParent, const OUString* pGroupText)
      87             :     : ModalDialog(pParent, "PasswordDialog", "sfx/ui/password.ui")
      88             :     , maMinLenPwdStr(SFX2_RESSTR(STR_PASSWD_MIN_LEN))
      89             :     , maEmptyPwdStr(SFX2_RESSTR(STR_PASSWD_EMPTY))
      90             :     , mnMinLen(5)
      91             :     , mnExtras(0)
      92           0 :     , mbAsciiOnly(false)
      93             : {
      94           0 :     get(mpPassword1Box, "password1frame");
      95           0 :     get(mpUserFT, "userft");
      96           0 :     get(mpUserED, "usered");
      97           0 :     get(mpPassword1FT, "pass1ft");
      98           0 :     get(mpPassword1ED, "pass1ed");
      99           0 :     get(mpConfirm1FT, "confirm1ft");
     100           0 :     get(mpConfirm1ED, "confirm1ed");
     101             : 
     102           0 :     get(mpPassword2Box, "password2frame");
     103           0 :     get(mpPassword2FT, "pass2ft");
     104           0 :     get(mpPassword2ED, "pass2ed");
     105           0 :     get(mpConfirm2FT, "confirm2ft");
     106           0 :     get(mpConfirm2ED, "confirm2ed");
     107             : 
     108           0 :     get(mpMinLengthFT, "minlenft");
     109             : 
     110           0 :     get(mpOKBtn, "ok");
     111             : 
     112           0 :     mpPassword1ED->SetAccessibleName(SFX2_RESSTR(STR_PASSWD));
     113             : 
     114           0 :     Link aLink = LINK( this, SfxPasswordDialog, EditModifyHdl );
     115           0 :     mpPassword1ED->SetModifyHdl( aLink );
     116           0 :     mpPassword2ED->SetModifyHdl( aLink );
     117           0 :     aLink = LINK( this, SfxPasswordDialog, OKHdl );
     118           0 :     mpOKBtn->SetClickHdl( aLink );
     119             : 
     120           0 :     if (pGroupText)
     121           0 :         mpPassword1Box->set_label(*pGroupText);
     122             : 
     123             :     //set the text to the password length
     124           0 :     SetPasswdText();
     125           0 : }
     126             : 
     127             : 
     128             : 
     129           0 : void SfxPasswordDialog::SetPasswdText( )
     130             : {
     131             : //set the new string to the minimum password length
     132           0 :     if( mnMinLen == 0 )
     133           0 :         mpMinLengthFT->SetText(maEmptyPwdStr);
     134             :     else
     135             :     {
     136           0 :         maMainPwdStr = maMinLenPwdStr;
     137           0 :         maMainPwdStr = maMainPwdStr.replaceAll( "$(MINLEN)", OUString::number((sal_Int32) mnMinLen ) );
     138           0 :         mpMinLengthFT->SetText(maMainPwdStr);
     139             :     }
     140           0 : }
     141             : 
     142             : 
     143             : 
     144           0 : void SfxPasswordDialog::SetMinLen( sal_uInt16 nLen )
     145             : {
     146           0 :     mnMinLen = nLen;
     147           0 :     SetPasswdText();
     148           0 :     EditModifyHdl( NULL );
     149           0 : }
     150             : 
     151           0 : void SfxPasswordDialog::ShowMinLengthText(bool bShow)
     152             : {
     153           0 :     mpMinLengthFT->Show(bShow);
     154           0 : }
     155             : 
     156             : 
     157             : 
     158           0 : short SfxPasswordDialog::Execute()
     159             : {
     160           0 :     mpUserFT->Hide();
     161           0 :     mpUserED->Hide();
     162           0 :     mpConfirm1FT->Hide();
     163           0 :     mpConfirm1ED->Hide();
     164           0 :     mpPassword1FT->Hide();
     165           0 :     mpPassword2Box->Hide();
     166           0 :     mpPassword2FT->Hide();
     167           0 :     mpPassword2ED->Hide();
     168           0 :     mpPassword2FT->Hide();
     169           0 :     mpConfirm2FT->Hide();
     170           0 :     mpConfirm2ED->Hide();
     171             : 
     172           0 :     if (mnExtras != SHOWEXTRAS_NONE)
     173           0 :         mpPassword1FT->Show();
     174           0 :     if (mnExtras & SHOWEXTRAS_USER)
     175             :     {
     176           0 :         mpUserFT->Show();
     177           0 :         mpUserED->Show();
     178             :     }
     179           0 :     if (mnExtras & SHOWEXTRAS_CONFIRM)
     180             :     {
     181           0 :         mpConfirm1FT->Show();
     182           0 :         mpConfirm1ED->Show();
     183             :     }
     184           0 :     if (mnExtras & SHOWEXTRAS_PASSWORD2)
     185             :     {
     186           0 :         mpPassword2Box->Show();
     187           0 :         mpPassword2FT->Show();
     188           0 :         mpPassword2ED->Show();
     189             :     }
     190           0 :     if (mnExtras & SHOWEXTRAS_CONFIRM2)
     191             :     {
     192           0 :         mpConfirm2FT->Show();
     193           0 :         mpConfirm2ED->Show();
     194             :     }
     195             : 
     196           0 :     return ModalDialog::Execute();
     197           3 : }
     198             : 
     199             : 
     200             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10