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

Generated by: LCOV version 1.11