LCOV - code coverage report
Current view: top level - uui/source - logindlg.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 0 108 0.0 %
Date: 2014-04-11 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 <comphelper/string.hxx>
      21             : #include <vcl/msgbox.hxx>
      22             : #include "logindlg.hxx"
      23             : 
      24             : #include "ids.hrc"
      25             : #include <tools/resid.hxx>
      26             : #include <osl/file.hxx>
      27             : 
      28             : #ifdef UNX
      29             : #include <limits.h>
      30             : #define _MAX_PATH PATH_MAX
      31             : #endif
      32             : 
      33             : #include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
      34             : #include <com/sun/star/ui/dialogs/FolderPicker.hpp>
      35             : #include <comphelper/processfactory.hxx>
      36             : 
      37             : using namespace com::sun::star;
      38             : 
      39           0 : void LoginDialog::HideControls_Impl( sal_uInt16 nFlags )
      40             : {
      41           0 :     if ( ( nFlags & LF_NO_PATH ) == LF_NO_PATH )
      42             :     {
      43           0 :         m_pPathFT->Hide();
      44           0 :         m_pPathED->Hide();
      45           0 :         m_pPathBtn->Hide();
      46             :     }
      47           0 :     else if ( ( nFlags & LF_PATH_READONLY ) == LF_PATH_READONLY )
      48             :     {
      49           0 :         m_pPathED->Enable( false );
      50           0 :         m_pPathBtn->Enable( false );
      51             :     }
      52             : 
      53           0 :     if ( ( nFlags & LF_NO_USERNAME ) == LF_NO_USERNAME )
      54             :     {
      55           0 :         m_pNameFT->Hide();
      56           0 :         m_pNameED->Hide();
      57             :     }
      58           0 :     else if ( ( nFlags & LF_USERNAME_READONLY ) == LF_USERNAME_READONLY )
      59             :     {
      60           0 :         m_pNameED->Enable( false );
      61             :     }
      62             : 
      63           0 :     if ( ( nFlags & LF_NO_PASSWORD ) == LF_NO_PASSWORD )
      64             :     {
      65           0 :         m_pPasswordFT->Hide();
      66           0 :         m_pPasswordED->Hide();
      67             :     }
      68             : 
      69           0 :     if ( ( nFlags & LF_NO_SAVEPASSWORD ) == LF_NO_SAVEPASSWORD )
      70           0 :         m_pSavePasswdBtn->Hide();
      71             : 
      72           0 :     if ( ( nFlags & LF_NO_ERRORTEXT ) == LF_NO_ERRORTEXT )
      73             :     {
      74           0 :         m_pErrorInfo->Hide();
      75           0 :         m_pErrorFT->Hide();
      76             :     }
      77             : 
      78           0 :     if ( ( nFlags & LF_NO_ACCOUNT ) == LF_NO_ACCOUNT )
      79             :     {
      80           0 :         m_pAccountFT->Hide();
      81           0 :         m_pAccountED->Hide();
      82             :     }
      83             : 
      84           0 :     if ( ( nFlags & LF_NO_USESYSCREDS ) == LF_NO_USESYSCREDS )
      85             :     {
      86           0 :         m_pUseSysCredsCB->Hide();
      87             :     }
      88           0 : }
      89             : 
      90           0 : void LoginDialog::EnableUseSysCredsControls_Impl( sal_Bool bUseSysCredsEnabled )
      91             : {
      92           0 :     m_pErrorInfo->Enable( !bUseSysCredsEnabled );
      93           0 :     m_pErrorFT->Enable( !bUseSysCredsEnabled );
      94           0 :     m_pRequestInfo->Enable( !bUseSysCredsEnabled );
      95           0 :     m_pPathFT->Enable( !bUseSysCredsEnabled );
      96           0 :     m_pPathED->Enable( !bUseSysCredsEnabled );
      97           0 :     m_pPathBtn->Enable( !bUseSysCredsEnabled );
      98           0 :     m_pNameFT->Enable( !bUseSysCredsEnabled );
      99           0 :     m_pNameED->Enable( !bUseSysCredsEnabled );
     100           0 :     m_pPasswordFT->Enable( !bUseSysCredsEnabled );
     101           0 :     m_pPasswordED->Enable( !bUseSysCredsEnabled );
     102           0 :     m_pAccountFT->Enable( !bUseSysCredsEnabled );
     103           0 :     m_pAccountED->Enable( !bUseSysCredsEnabled );
     104           0 : }
     105             : 
     106           0 : IMPL_LINK_NOARG(LoginDialog, OKHdl_Impl)
     107             : {
     108             :     // trim the strings
     109           0 :     m_pNameED->SetText(comphelper::string::strip(m_pNameED->GetText(), ' '));
     110           0 :     m_pPasswordED->SetText(comphelper::string::strip(m_pPasswordED->GetText(), ' '));
     111           0 :     EndDialog( RET_OK );
     112           0 :     return 1;
     113             : }
     114             : 
     115           0 : IMPL_LINK_NOARG(LoginDialog, PathHdl_Impl)
     116             : {
     117             :     try
     118             :     {
     119           0 :         uno::Reference<ui::dialogs::XFolderPicker2> xFolderPicker = ui::dialogs::FolderPicker::create(comphelper::getProcessComponentContext());
     120             : 
     121           0 :         OUString aPath( m_pPathED->GetText() );
     122           0 :         osl::FileBase::getFileURLFromSystemPath( aPath, aPath );
     123           0 :         xFolderPicker->setDisplayDirectory( aPath );
     124             : 
     125           0 :         if (xFolderPicker->execute() == ui::dialogs::ExecutableDialogResults::OK)
     126             :         {
     127           0 :             osl::FileBase::getSystemPathFromFileURL( xFolderPicker->getDirectory(), aPath );
     128           0 :             m_pPathED->SetText( aPath );
     129           0 :         }
     130             :     }
     131           0 :     catch (uno::Exception & e)
     132             :     {
     133             :         SAL_WARN("uui", "LoginDialog::PathHdl_Impl: caught UNO exception: " << e.Message);
     134             :     }
     135             : 
     136           0 :     return 1;
     137             : }
     138             : 
     139           0 : IMPL_LINK_NOARG(LoginDialog, UseSysCredsHdl_Impl)
     140             : {
     141           0 :     EnableUseSysCredsControls_Impl( m_pUseSysCredsCB->IsChecked() );
     142           0 :     return 1;
     143             : }
     144             : 
     145           0 : LoginDialog::LoginDialog(Window* pParent, sal_uInt16 nFlags,
     146             :     const OUString& rServer, const OUString& rRealm)
     147           0 :     : ModalDialog(pParent, "LoginDialog", "uui/ui/logindialog.ui")
     148             : {
     149           0 :     get(m_pErrorFT, "errorft");
     150           0 :     get(m_pErrorInfo, "errorinfo");
     151           0 :     get(m_pRequestInfo, "requestinfo");
     152           0 :     get(m_pPathFT, "pathft");
     153           0 :     get(m_pPathED, "pathed");
     154           0 :     get(m_pPathBtn, "pathbtn");
     155           0 :     get(m_pNameFT, "nameft");
     156           0 :     get(m_pNameED, "nameed");
     157           0 :     get(m_pPasswordFT, "passwordft");
     158           0 :     get(m_pPasswordED, "passworded");
     159           0 :     get(m_pAccountFT, "accountft");
     160           0 :     get(m_pAccountED, "accounted");
     161           0 :     get(m_pSavePasswdBtn, "remember");
     162           0 :     get(m_pUseSysCredsCB, "syscreds");
     163           0 :     get(m_pOKBtn, "ok");
     164             : 
     165           0 :     OUString aRequest;
     166           0 :     if ((nFlags & LF_NO_ACCOUNT) != 0 && !rRealm.isEmpty())
     167             :     {
     168           0 :         aRequest = get<FixedText>("loginrealm")->GetText();
     169           0 :         aRequest = aRequest.replaceAll("%2", rRealm);
     170             :     }
     171             :     else
     172           0 :         aRequest = m_pRequestInfo->GetText();
     173             : 
     174           0 :     if ( !( ( nFlags & LF_NO_USESYSCREDS ) == LF_NO_USESYSCREDS ) )
     175           0 :       EnableUseSysCredsControls_Impl( m_pUseSysCredsCB->IsChecked() );
     176             : 
     177           0 :     aRequest = aRequest.replaceAll("%1", rServer);
     178           0 :     m_pRequestInfo->SetText(aRequest);
     179             : 
     180           0 :     m_pPathED->SetMaxTextLen( _MAX_PATH );
     181           0 :     m_pNameED->SetMaxTextLen( _MAX_PATH );
     182             : 
     183           0 :     m_pOKBtn->SetClickHdl( LINK( this, LoginDialog, OKHdl_Impl ) );
     184           0 :     m_pPathBtn->SetClickHdl( LINK( this, LoginDialog, PathHdl_Impl ) );
     185           0 :     m_pUseSysCredsCB->SetClickHdl( LINK( this, LoginDialog, UseSysCredsHdl_Impl ) );
     186             : 
     187           0 :     HideControls_Impl( nFlags );
     188           0 : }
     189             : 
     190           0 : void LoginDialog::SetUseSystemCredentials( sal_Bool bUse )
     191             : {
     192           0 :     if ( m_pUseSysCredsCB->IsVisible() )
     193             :     {
     194           0 :         m_pUseSysCredsCB->Check( bUse );
     195           0 :         EnableUseSysCredsControls_Impl( bUse );
     196             :     }
     197           0 : }
     198             : 
     199           0 : void LoginDialog::ClearPassword()
     200             : {
     201           0 :     m_pPasswordED->SetText( OUString() );
     202             : 
     203           0 :     if ( m_pNameED->GetText().isEmpty() )
     204           0 :         m_pNameED->GrabFocus();
     205             :     else
     206           0 :         m_pPasswordED->GrabFocus();
     207           0 : }
     208             : 
     209           0 : void LoginDialog::ClearAccount()
     210             : {
     211           0 :     m_pAccountED->SetText( OUString() );
     212           0 :     m_pAccountED->GrabFocus();
     213           0 : }
     214             : 
     215             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10