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

Generated by: LCOV version 1.10