LCOV - code coverage report
Current view: top level - padmin/source - helper.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 135 0.0 %
Date: 2012-08-25 Functions: 0 13 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 0 -

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

Generated by: LCOV version 1.10