LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/padmin/source - helper.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 132 0.0 %
Date: 2013-07-09 Functions: 0 15 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 <unistd.h>
      21             : #include <helper.hxx>
      22             : #include <padialog.hrc>
      23             : #include <osl/file.hxx>
      24             : #include <tools/urlobj.hxx>
      25             : #include <vcl/svapp.hxx>
      26             : #include <vcl/msgbox.hxx>
      27             : #include <tools/config.hxx>
      28             : #include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
      29             : #include <com/sun/star/ui/dialogs/FolderPicker.hpp>
      30             : #include <com/sun/star/ui/dialogs/XControlAccess.hpp>
      31             : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      32             : #include <comphelper/processfactory.hxx>
      33             : #include <comphelper/string.hxx>
      34             : #include <unotools/confignode.hxx>
      35             : #include <i18nlangtag/mslangid.hxx>
      36             : #include <rtl/ustrbuf.hxx>
      37             : 
      38             : 
      39             : using namespace osl;
      40             : using namespace padmin;
      41             : using namespace com::sun::star::uno;
      42             : using namespace com::sun::star::lang;
      43             : using namespace com::sun::star::ui::dialogs;
      44             : 
      45             : 
      46             : /*
      47             :  *  PaResId
      48             :  */
      49             : 
      50           0 : ResId padmin::PaResId( sal_uInt32 nId )
      51             : {
      52             :     static ResMgr* pPaResMgr = NULL;
      53           0 :     if( ! pPaResMgr )
      54             :     {
      55           0 :         LanguageTag aLanguageTag( LANGUAGE_SYSTEM);
      56             : 
      57             :         utl::OConfigurationNode aNode =
      58             :             utl::OConfigurationTreeRoot::tryCreateWithComponentContext(
      59             :                     comphelper::getProcessComponentContext(),
      60           0 :                     OUString("org.openoffice.Setup/L10N") );
      61           0 :         if ( aNode.isValid() )
      62             :         {
      63           0 :             OUString aLoc;
      64           0 :             Any aValue = aNode.getNodeValue( OUString("ooLocale") );
      65           0 :             if( aValue >>= aLoc )
      66             :             {
      67           0 :                 aLanguageTag.reset( aLoc);
      68           0 :             }
      69             :         }
      70           0 :         pPaResMgr = ResMgr::SearchCreateResMgr( "spa", aLanguageTag );
      71           0 :         AllSettings aSettings = Application::GetSettings();
      72           0 :         aSettings.SetUILanguageTag( aLanguageTag );
      73           0 :         Application::SetSettings( aSettings );
      74             :     }
      75           0 :     return ResId( nId, *pPaResMgr );
      76             : }
      77             : 
      78             : /*
      79             :  *  FindFiles
      80             :  */
      81             : 
      82           0 : void padmin::FindFiles( const OUString& rDirectory, ::std::list< String >& rResult, const OUString& rSuffixes, bool bRecursive )
      83             : {
      84           0 :     rResult.clear();
      85             : 
      86           0 :     OUString aDirPath;
      87           0 :     ::osl::FileBase::getFileURLFromSystemPath( rDirectory, aDirPath );
      88           0 :     Directory aDir( aDirPath );
      89           0 :     if( aDir.open() != FileBase::E_None )
      90           0 :         return;
      91           0 :     DirectoryItem aItem;
      92           0 :     while( aDir.getNextItem( aItem ) == FileBase::E_None )
      93             :     {
      94             :         FileStatus aStatus( osl_FileStatus_Mask_FileName            |
      95             :                             osl_FileStatus_Mask_Type
      96           0 :                             );
      97           0 :         if( aItem.getFileStatus( aStatus ) == FileBase::E_None )
      98             :         {
      99           0 :             if( aStatus.getFileType() == FileStatus::Regular ||
     100           0 :                 aStatus.getFileType() == FileStatus::Link )
     101             :             {
     102           0 :                 String aFileName = aStatus.getFileName();
     103           0 :                 int nToken = comphelper::string::getTokenCount(rSuffixes, ';');
     104           0 :                 while( nToken-- )
     105             :                 {
     106           0 :                     OUString aSuffix = rSuffixes.getToken( nToken, ';' );
     107           0 :                     if( aFileName.Len() > aSuffix.getLength()+1 )
     108             :                     {
     109           0 :                         String aExtension = aFileName.Copy( aFileName.Len()-aSuffix.getLength() );
     110           0 :                         if( aFileName.GetChar( aFileName.Len()-aSuffix.getLength()-1 ) == '.' &&
     111           0 :                             aExtension.EqualsIgnoreCaseAscii( aSuffix ) )
     112             :                         {
     113           0 :                             rResult.push_back( aFileName );
     114           0 :                             break;
     115           0 :                         }
     116             :                     }
     117           0 :                 }
     118             :             }
     119           0 :             else if( bRecursive && aStatus.getFileType() == FileStatus::Directory )
     120             :             {
     121           0 :                 OUStringBuffer aSubDir( rDirectory );
     122           0 :                 aSubDir.appendAscii( "/", 1 );
     123           0 :                 aSubDir.append( aStatus.getFileName() );
     124           0 :                 std::list< String > subfiles;
     125           0 :                 FindFiles( aSubDir.makeStringAndClear(), subfiles, rSuffixes, bRecursive );
     126           0 :                 for( std::list< String >::const_iterator it = subfiles.begin(); it != subfiles.end(); ++it )
     127             :                 {
     128           0 :                     OUStringBuffer aSubFile( aStatus.getFileName() );
     129           0 :                     aSubFile.appendAscii( "/", 1 );
     130           0 :                     aSubFile.append( *it );
     131           0 :                     rResult.push_back( aSubFile.makeStringAndClear() );
     132           0 :                 }
     133             :             }
     134             :         }
     135           0 :     }
     136           0 :     aDir.close();
     137             : }
     138             : 
     139             : /*
     140             :  *  DelMultiListBox
     141             :  */
     142             : 
     143           0 : long DelMultiListBox::Notify( NotifyEvent& rEvent )
     144             : {
     145           0 :     long nRet = 0;
     146             : 
     147           0 :     if( rEvent.GetType() == EVENT_KEYINPUT &&
     148           0 :         rEvent.GetKeyEvent()->GetKeyCode().GetCode() == KEY_DELETE )
     149             :     {
     150           0 :         m_aDelPressedLink.Call( this );
     151           0 :         nRet = 1;
     152             :     }
     153             :     else
     154           0 :         nRet = MultiListBox::Notify( rEvent );
     155             : 
     156           0 :     return nRet;
     157             : }
     158             : 
     159             : /*
     160             :  *  DelListBox
     161             :  */
     162             : 
     163           0 : long DelListBox::Notify( NotifyEvent& rEvent )
     164             : {
     165           0 :     long nRet = 0;
     166             : 
     167           0 :     if( rEvent.GetType() == EVENT_KEYINPUT &&
     168           0 :         rEvent.GetKeyEvent()->GetKeyCode().GetCode() == KEY_DELETE )
     169             :     {
     170           0 :         m_aDelPressedLink.Call( this );
     171           0 :         nRet = 1;
     172             :     }
     173             :     else
     174           0 :         nRet = ListBox::Notify( rEvent );
     175             : 
     176           0 :     return nRet;
     177             : }
     178             : 
     179             : /*
     180             :  *  QueryString
     181             :  */
     182             : 
     183           0 : QueryString::QueryString( Window* pParent, String& rQuery, String& rRet, const ::std::list< String >& rChoices ) :
     184             :         ModalDialog( pParent, PaResId( RID_STRINGQUERYDLG ) ),
     185             :         m_aOKButton( this, PaResId( RID_STRQRY_BTN_OK ) ),
     186             :         m_aCancelButton( this, PaResId( RID_STRQRY_BTN_CANCEL ) ),
     187             :         m_aFixedText( this, PaResId( RID_STRQRY_TXT_RENAME ) ),
     188             :         m_aEdit( this, PaResId( RID_STRQRY_EDT_NEWNAME ) ),
     189             :         m_aComboBox( this, PaResId( RID_STRQRY_BOX_NEWNAME ) ),
     190           0 :         m_rReturnValue( rRet )
     191             : {
     192           0 :     FreeResource();
     193           0 :     m_aOKButton.SetClickHdl( LINK( this, QueryString, ClickBtnHdl ) );
     194           0 :     m_aFixedText.SetText( rQuery );
     195           0 :     if( rChoices.begin() != rChoices.end() )
     196             :     {
     197           0 :         m_aComboBox.SetText( m_rReturnValue );
     198           0 :         m_aComboBox.InsertEntry( m_rReturnValue );
     199           0 :         for( ::std::list<String>::const_iterator it = rChoices.begin(); it != rChoices.end(); ++it )
     200           0 :             m_aComboBox.InsertEntry( *it );
     201           0 :         m_aEdit.Show( sal_False );
     202           0 :         m_bUseEdit = false;
     203             :     }
     204             :     else
     205             :     {
     206           0 :         m_aEdit.SetText( m_rReturnValue );
     207           0 :         m_aComboBox.Show( sal_False );
     208           0 :         m_bUseEdit = true;
     209             :     }
     210           0 :     SetText( Application::GetDisplayName() );
     211           0 : }
     212             : 
     213           0 : QueryString::~QueryString()
     214             : {
     215           0 : }
     216             : 
     217           0 : IMPL_LINK( QueryString, ClickBtnHdl, Button*, pButton )
     218             : {
     219           0 :     if( pButton == &m_aOKButton )
     220             :     {
     221           0 :         m_rReturnValue = m_bUseEdit ? m_aEdit.GetText() : m_aComboBox.GetText();
     222           0 :         EndDialog( 1 );
     223             :     }
     224             :     else
     225           0 :         EndDialog(0);
     226           0 :     return 0;
     227             : }
     228             : 
     229             : /*
     230             :  *  AreYouSure
     231             :  */
     232             : 
     233           0 : sal_Bool padmin::AreYouSure( Window* pParent, int nRid )
     234             : {
     235           0 :     if( nRid == -1 )
     236           0 :         nRid = RID_YOU_SURE;
     237             :     QueryBox aQueryBox( pParent, WB_YES_NO | WB_DEF_NO,
     238           0 :                         String( PaResId( nRid ) ) );
     239           0 :     return aQueryBox.Execute() == RET_NO ? sal_False : sal_True;
     240             : }
     241             : 
     242             : /*
     243             :  *  getPadminRC
     244             :  */
     245             : 
     246             : static Config* pRC = NULL;
     247             : 
     248           0 : Config& padmin::getPadminRC()
     249             : {
     250           0 :     if( ! pRC )
     251             :     {
     252           0 :         static const char* pEnv = getenv( "HOME" );
     253           0 :         OUString aFileName;
     254           0 :         if( pEnv )
     255           0 :             aFileName = OUString::createFromAscii( pEnv ) + "/.padminrc";
     256             :         else
     257           0 :             aFileName += OStringToOUString( "", osl_getThreadTextEncoding() ) + "/.padminrc";
     258             : 
     259           0 :         pRC = new Config( aFileName );
     260             :     }
     261           0 :     return *pRC;
     262             : }
     263             : 
     264           0 : void padmin::freePadminRC()
     265             : {
     266           0 :     if( pRC )
     267           0 :         delete pRC, pRC = NULL;
     268           0 : }
     269             : 
     270           0 : bool padmin::chooseDirectory( OUString& rInOutPath )
     271             : {
     272           0 :     bool bRet = false;
     273           0 :     Reference< XComponentContext > xContext( ::comphelper::getProcessComponentContext() );
     274           0 :     Reference< XFolderPicker2 > xFolderPicker = FolderPicker::create(xContext);;
     275           0 :     Reference< XControlAccess > xCA( xFolderPicker, UNO_QUERY );
     276           0 :     if( xCA.is() )
     277             :     {
     278             :         try
     279             :         {
     280           0 :             Any aState;
     281           0 :             aState <<= sal_False;
     282           0 :             xCA->setControlProperty( OUString(  "HelpButton"  ),
     283             :                                      OUString(  "Visible"  ),
     284           0 :                                      aState );
     285             : 
     286             :         }
     287           0 :         catch( ... )
     288             :         {
     289             :         }
     290             :     }
     291           0 :     INetURLObject aObj( rInOutPath, INET_PROT_FILE, INetURLObject::ENCODE_ALL );
     292           0 :     xFolderPicker->setDisplayDirectory( aObj.GetMainURL(INetURLObject::DECODE_TO_IURI) );
     293           0 :     if( xFolderPicker->execute() == ExecutableDialogResults::OK )
     294             :     {
     295           0 :         aObj = INetURLObject( xFolderPicker->getDirectory() );
     296           0 :         rInOutPath = aObj.PathToFileName();
     297           0 :         bRet = true;
     298             :     }
     299             : #if OSL_DEBUG_LEVEL > 1
     300             :     else
     301             :         fprintf( stderr, "could not get FolderPicker service\n" );
     302             : #endif
     303           0 :     return bRet;
     304           0 : }
     305             : 
     306             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10