2010-10-14 01:27:31 -05:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2001-05-08 05:56:39 -05:00
|
|
|
/*************************************************************************
|
|
|
|
*
|
2008-04-11 04:01:21 -05:00
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
2001-05-08 05:56:39 -05:00
|
|
|
*
|
2010-02-12 08:01:35 -06:00
|
|
|
* Copyright 2000, 2010 Oracle and/or its affiliates.
|
2001-05-08 05:56:39 -05:00
|
|
|
*
|
2008-04-11 04:01:21 -05:00
|
|
|
* OpenOffice.org - a multi-platform office productivity suite
|
2001-05-08 05:56:39 -05:00
|
|
|
*
|
2008-04-11 04:01:21 -05:00
|
|
|
* This file is part of OpenOffice.org.
|
2001-05-08 05:56:39 -05:00
|
|
|
*
|
2008-04-11 04:01:21 -05:00
|
|
|
* OpenOffice.org is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Lesser General Public License version 3
|
|
|
|
* only, as published by the Free Software Foundation.
|
2001-05-08 05:56:39 -05:00
|
|
|
*
|
2008-04-11 04:01:21 -05:00
|
|
|
* OpenOffice.org is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Lesser General Public License version 3 for more details
|
|
|
|
* (a copy is included in the LICENSE file that accompanied this code).
|
2001-05-08 05:56:39 -05:00
|
|
|
*
|
2008-04-11 04:01:21 -05:00
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* version 3 along with OpenOffice.org. If not, see
|
|
|
|
* <http://www.openoffice.org/license.html>
|
|
|
|
* for a copy of the LGPLv3 License.
|
2001-05-08 05:56:39 -05:00
|
|
|
*
|
|
|
|
************************************************************************/
|
|
|
|
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <helper.hxx>
|
|
|
|
#include <padialog.hrc>
|
|
|
|
#include <osl/file.hxx>
|
|
|
|
#include <tools/urlobj.hxx>
|
|
|
|
#include <vcl/svapp.hxx>
|
|
|
|
#include <vcl/msgbox.hxx>
|
|
|
|
#include <tools/config.hxx>
|
2001-09-04 10:24:50 -05:00
|
|
|
#include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
|
|
|
|
#include <com/sun/star/ui/dialogs/XFolderPicker.hpp>
|
2002-09-03 07:23:11 -05:00
|
|
|
#include <com/sun/star/ui/dialogs/XControlAccess.hpp>
|
2001-09-04 10:24:50 -05:00
|
|
|
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
|
|
|
|
#include <comphelper/processfactory.hxx>
|
|
|
|
#include <tools/urlobj.hxx>
|
2003-05-28 06:36:09 -05:00
|
|
|
#include <unotools/confignode.hxx>
|
|
|
|
#include <vcl/unohelp.hxx>
|
2006-04-07 08:26:03 -05:00
|
|
|
#include <i18npool/mslangid.hxx>
|
2004-03-30 06:46:06 -06:00
|
|
|
#include <rtl/ustrbuf.hxx>
|
2001-09-04 10:24:50 -05:00
|
|
|
|
2001-05-08 05:56:39 -05:00
|
|
|
|
|
|
|
using namespace osl;
|
|
|
|
using namespace padmin;
|
2001-09-04 10:24:50 -05:00
|
|
|
using namespace com::sun::star::uno;
|
|
|
|
using namespace com::sun::star::lang;
|
|
|
|
using namespace com::sun::star::ui::dialogs;
|
2001-05-08 05:56:39 -05:00
|
|
|
|
2011-02-27 08:25:42 -06:00
|
|
|
using ::rtl::OUString;
|
|
|
|
using ::rtl::OUStringBuffer;
|
|
|
|
|
2001-05-08 05:56:39 -05:00
|
|
|
#define MAX_PATH 1024
|
|
|
|
|
|
|
|
/*
|
|
|
|
* PaResId
|
|
|
|
*/
|
|
|
|
|
2006-03-31 02:34:39 -06:00
|
|
|
ResId padmin::PaResId( sal_uInt32 nId )
|
2001-05-08 05:56:39 -05:00
|
|
|
{
|
|
|
|
static ResMgr* pPaResMgr = NULL;
|
|
|
|
if( ! pPaResMgr )
|
|
|
|
{
|
2004-06-25 21:11:23 -05:00
|
|
|
::com::sun::star::lang::Locale aLocale;
|
2003-05-28 06:36:09 -05:00
|
|
|
|
|
|
|
utl::OConfigurationNode aNode =
|
|
|
|
utl::OConfigurationTreeRoot::tryCreateWithServiceFactory(
|
|
|
|
vcl::unohelper::GetMultiServiceFactory(),
|
2010-11-22 15:17:17 -06:00
|
|
|
OUString(RTL_CONSTASCII_USTRINGPARAM("org.openoffice.Setup/L10N")) );
|
2003-05-28 06:36:09 -05:00
|
|
|
if ( aNode.isValid() )
|
|
|
|
{
|
|
|
|
rtl::OUString aLoc;
|
2010-11-22 15:17:17 -06:00
|
|
|
Any aValue = aNode.getNodeValue( OUString(RTL_CONSTASCII_USTRINGPARAM("ooLocale")) );
|
2003-05-28 06:36:09 -05:00
|
|
|
if( aValue >>= aLoc )
|
|
|
|
{
|
2004-06-25 21:11:23 -05:00
|
|
|
sal_Int32 nIndex = 0;
|
|
|
|
aLocale.Language = aLoc.getToken( 0, '-', nIndex );
|
|
|
|
aLocale.Country = aLoc.getToken( 0, '-', nIndex );
|
|
|
|
aLocale.Variant = aLoc.getToken( 0, '-', nIndex );
|
2003-05-28 06:36:09 -05:00
|
|
|
}
|
|
|
|
}
|
2008-02-25 08:46:57 -06:00
|
|
|
pPaResMgr = ResMgr::SearchCreateResMgr( "spa", aLocale );
|
2001-07-04 08:06:14 -05:00
|
|
|
AllSettings aSettings = Application::GetSettings();
|
2004-06-25 21:11:23 -05:00
|
|
|
aSettings.SetUILocale( aLocale );
|
2001-07-04 08:06:14 -05:00
|
|
|
Application::SetSettings( aSettings );
|
2001-05-08 05:56:39 -05:00
|
|
|
}
|
2007-04-26 02:20:34 -05:00
|
|
|
return ResId( nId, *pPaResMgr );
|
2001-05-08 05:56:39 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* FindFiles
|
|
|
|
*/
|
|
|
|
|
2004-03-30 06:46:06 -06:00
|
|
|
void padmin::FindFiles( const String& rDirectory, ::std::list< String >& rResult, const String& rSuffixes, bool bRecursive )
|
2001-05-08 05:56:39 -05:00
|
|
|
{
|
|
|
|
rResult.clear();
|
|
|
|
|
|
|
|
OUString aDirPath;
|
2001-05-22 08:59:21 -05:00
|
|
|
::osl::FileBase::getFileURLFromSystemPath( rDirectory, aDirPath );
|
2001-05-08 05:56:39 -05:00
|
|
|
Directory aDir( aDirPath );
|
2004-03-30 06:46:06 -06:00
|
|
|
if( aDir.open() != FileBase::E_None )
|
|
|
|
return;
|
2001-05-08 05:56:39 -05:00
|
|
|
DirectoryItem aItem;
|
|
|
|
while( aDir.getNextItem( aItem ) == FileBase::E_None )
|
|
|
|
{
|
2011-04-13 13:52:55 -05:00
|
|
|
FileStatus aStatus( osl_FileStatus_Mask_FileName |
|
|
|
|
osl_FileStatus_Mask_Type
|
2001-05-08 05:56:39 -05:00
|
|
|
);
|
2008-06-25 08:46:57 -05:00
|
|
|
if( aItem.getFileStatus( aStatus ) == FileBase::E_None )
|
2001-05-08 05:56:39 -05:00
|
|
|
{
|
2008-06-25 08:46:57 -05:00
|
|
|
if( aStatus.getFileType() == FileStatus::Regular ||
|
|
|
|
aStatus.getFileType() == FileStatus::Link )
|
2001-05-08 05:56:39 -05:00
|
|
|
{
|
2008-06-25 08:46:57 -05:00
|
|
|
String aFileName = aStatus.getFileName();
|
|
|
|
int nToken = rSuffixes.GetTokenCount( ';' );
|
|
|
|
while( nToken-- )
|
2001-05-08 05:56:39 -05:00
|
|
|
{
|
2008-06-25 08:46:57 -05:00
|
|
|
String aSuffix = rSuffixes.GetToken( nToken, ';' );
|
|
|
|
if( aFileName.Len() > aSuffix.Len()+1 )
|
2002-09-11 09:57:15 -05:00
|
|
|
{
|
2008-06-25 08:46:57 -05:00
|
|
|
String aExtension = aFileName.Copy( aFileName.Len()-aSuffix.Len() );
|
|
|
|
if( aFileName.GetChar( aFileName.Len()-aSuffix.Len()-1 ) == '.' &&
|
|
|
|
aExtension.EqualsIgnoreCaseAscii( aSuffix ) )
|
|
|
|
{
|
|
|
|
rResult.push_back( aFileName );
|
|
|
|
break;
|
|
|
|
}
|
2002-09-11 09:57:15 -05:00
|
|
|
}
|
2001-05-08 05:56:39 -05:00
|
|
|
}
|
|
|
|
}
|
2008-06-25 08:46:57 -05:00
|
|
|
else if( bRecursive && aStatus.getFileType() == FileStatus::Directory )
|
2004-03-30 06:46:06 -06:00
|
|
|
{
|
2008-06-25 08:46:57 -05:00
|
|
|
OUStringBuffer aSubDir( rDirectory );
|
|
|
|
aSubDir.appendAscii( "/", 1 );
|
|
|
|
aSubDir.append( aStatus.getFileName() );
|
|
|
|
std::list< String > subfiles;
|
|
|
|
FindFiles( aSubDir.makeStringAndClear(), subfiles, rSuffixes, bRecursive );
|
|
|
|
for( std::list< String >::const_iterator it = subfiles.begin(); it != subfiles.end(); ++it )
|
|
|
|
{
|
|
|
|
OUStringBuffer aSubFile( aStatus.getFileName() );
|
|
|
|
aSubFile.appendAscii( "/", 1 );
|
|
|
|
aSubFile.append( *it );
|
|
|
|
rResult.push_back( aSubFile.makeStringAndClear() );
|
|
|
|
}
|
2004-03-30 06:46:06 -06:00
|
|
|
}
|
|
|
|
}
|
2001-05-08 05:56:39 -05:00
|
|
|
}
|
|
|
|
aDir.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* DelMultiListBox
|
|
|
|
*/
|
|
|
|
|
|
|
|
long DelMultiListBox::Notify( NotifyEvent& rEvent )
|
|
|
|
{
|
|
|
|
long nRet = 0;
|
|
|
|
|
|
|
|
if( rEvent.GetType() == EVENT_KEYINPUT &&
|
|
|
|
rEvent.GetKeyEvent()->GetKeyCode().GetCode() == KEY_DELETE )
|
|
|
|
{
|
|
|
|
m_aDelPressedLink.Call( this );
|
|
|
|
nRet = 1;
|
|
|
|
}
|
2001-06-19 07:47:44 -05:00
|
|
|
else
|
|
|
|
nRet = MultiListBox::Notify( rEvent );
|
2001-05-08 05:56:39 -05:00
|
|
|
|
|
|
|
return nRet;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* DelListBox
|
|
|
|
*/
|
|
|
|
|
|
|
|
long DelListBox::Notify( NotifyEvent& rEvent )
|
|
|
|
{
|
|
|
|
long nRet = 0;
|
|
|
|
|
|
|
|
if( rEvent.GetType() == EVENT_KEYINPUT &&
|
|
|
|
rEvent.GetKeyEvent()->GetKeyCode().GetCode() == KEY_DELETE )
|
|
|
|
{
|
|
|
|
m_aDelPressedLink.Call( this );
|
|
|
|
nRet = 1;
|
|
|
|
}
|
2001-06-19 07:47:44 -05:00
|
|
|
else
|
|
|
|
nRet = ListBox::Notify( rEvent );
|
2001-05-08 05:56:39 -05:00
|
|
|
|
|
|
|
return nRet;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* QueryString
|
|
|
|
*/
|
|
|
|
|
2001-06-26 13:27:24 -05:00
|
|
|
QueryString::QueryString( Window* pParent, String& rQuery, String& rRet, const ::std::list< String >& rChoices ) :
|
2001-05-08 05:56:39 -05:00
|
|
|
ModalDialog( pParent, PaResId( RID_STRINGQUERYDLG ) ),
|
|
|
|
m_aOKButton( this, PaResId( RID_STRQRY_BTN_OK ) ),
|
2004-03-17 03:44:38 -06:00
|
|
|
m_aCancelButton( this, PaResId( RID_STRQRY_BTN_CANCEL ) ),
|
|
|
|
m_aFixedText( this, PaResId( RID_STRQRY_TXT_RENAME ) ),
|
2001-05-08 05:56:39 -05:00
|
|
|
m_aEdit( this, PaResId( RID_STRQRY_EDT_NEWNAME ) ),
|
2001-06-26 13:27:24 -05:00
|
|
|
m_aComboBox( this, PaResId( RID_STRQRY_BOX_NEWNAME ) ),
|
2004-03-17 03:44:38 -06:00
|
|
|
m_rReturnValue( rRet )
|
2001-05-08 05:56:39 -05:00
|
|
|
{
|
2006-10-11 02:23:53 -05:00
|
|
|
FreeResource();
|
2001-05-08 05:56:39 -05:00
|
|
|
m_aOKButton.SetClickHdl( LINK( this, QueryString, ClickBtnHdl ) );
|
|
|
|
m_aFixedText.SetText( rQuery );
|
2001-06-26 13:27:24 -05:00
|
|
|
if( rChoices.begin() != rChoices.end() )
|
|
|
|
{
|
|
|
|
m_aComboBox.SetText( m_rReturnValue );
|
|
|
|
m_aComboBox.InsertEntry( m_rReturnValue );
|
|
|
|
for( ::std::list<String>::const_iterator it = rChoices.begin(); it != rChoices.end(); ++it )
|
|
|
|
m_aComboBox.InsertEntry( *it );
|
2011-01-14 08:09:57 -06:00
|
|
|
m_aEdit.Show( sal_False );
|
2001-06-26 13:27:24 -05:00
|
|
|
m_bUseEdit = false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_aEdit.SetText( m_rReturnValue );
|
2011-01-14 08:09:57 -06:00
|
|
|
m_aComboBox.Show( sal_False );
|
2001-06-26 13:27:24 -05:00
|
|
|
m_bUseEdit = true;
|
|
|
|
}
|
2001-05-08 05:56:39 -05:00
|
|
|
SetText( Application::GetDisplayName() );
|
|
|
|
}
|
|
|
|
|
|
|
|
QueryString::~QueryString()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
IMPL_LINK( QueryString, ClickBtnHdl, Button*, pButton )
|
|
|
|
{
|
|
|
|
if( pButton == &m_aOKButton )
|
|
|
|
{
|
2001-06-26 13:27:24 -05:00
|
|
|
m_rReturnValue = m_bUseEdit ? m_aEdit.GetText() : m_aComboBox.GetText();
|
2001-05-08 05:56:39 -05:00
|
|
|
EndDialog( 1 );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
EndDialog(0);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* AreYouSure
|
|
|
|
*/
|
|
|
|
|
2011-01-14 08:09:57 -06:00
|
|
|
sal_Bool padmin::AreYouSure( Window* pParent, int nRid )
|
2001-05-08 05:56:39 -05:00
|
|
|
{
|
|
|
|
if( nRid == -1 )
|
|
|
|
nRid = RID_YOU_SURE;
|
|
|
|
QueryBox aQueryBox( pParent, WB_YES_NO | WB_DEF_NO,
|
|
|
|
String( PaResId( nRid ) ) );
|
2011-01-14 08:09:57 -06:00
|
|
|
return aQueryBox.Execute() == RET_NO ? sal_False : sal_True;
|
2001-05-08 05:56:39 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* getPadminRC
|
|
|
|
*/
|
|
|
|
|
|
|
|
static Config* pRC = NULL;
|
|
|
|
|
|
|
|
Config& padmin::getPadminRC()
|
|
|
|
{
|
|
|
|
if( ! pRC )
|
|
|
|
{
|
|
|
|
static const char* pEnv = getenv( "HOME" );
|
2002-09-03 07:33:01 -05:00
|
|
|
String aFileName( pEnv ? pEnv : "", osl_getThreadTextEncoding() );
|
2001-05-08 05:56:39 -05:00
|
|
|
aFileName.AppendAscii( "/.padminrc" );
|
|
|
|
pRC = new Config( aFileName );
|
|
|
|
}
|
|
|
|
return *pRC;
|
|
|
|
}
|
|
|
|
|
|
|
|
void padmin::freePadminRC()
|
|
|
|
{
|
|
|
|
if( pRC )
|
|
|
|
delete pRC, pRC = NULL;
|
|
|
|
}
|
2001-09-04 10:24:50 -05:00
|
|
|
|
2006-06-19 06:15:46 -05:00
|
|
|
bool padmin::chooseDirectory( String& rInOutPath )
|
2001-09-04 10:24:50 -05:00
|
|
|
{
|
|
|
|
bool bRet = false;
|
|
|
|
Reference< XMultiServiceFactory > xFactory( ::comphelper::getProcessServiceFactory() );
|
|
|
|
if( xFactory.is() )
|
|
|
|
{
|
|
|
|
Reference< XFolderPicker > xFolderPicker( xFactory->createInstance( OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.ui.dialogs.FolderPicker" ) ) ), UNO_QUERY );
|
|
|
|
if( xFolderPicker.is() )
|
|
|
|
{
|
2002-09-03 07:23:11 -05:00
|
|
|
Reference< XControlAccess > xCA( xFolderPicker, UNO_QUERY );
|
|
|
|
if( xCA.is() )
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
Any aState;
|
|
|
|
aState <<= sal_False;
|
|
|
|
xCA->setControlProperty( OUString( RTL_CONSTASCII_USTRINGPARAM( "HelpButton" ) ),
|
|
|
|
OUString( RTL_CONSTASCII_USTRINGPARAM( "Visible" ) ),
|
|
|
|
aState );
|
|
|
|
|
|
|
|
}
|
|
|
|
catch( ... )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
2001-09-04 10:24:50 -05:00
|
|
|
INetURLObject aObj( rInOutPath, INET_PROT_FILE, INetURLObject::ENCODE_ALL );
|
2002-12-02 10:33:44 -06:00
|
|
|
xFolderPicker->setDisplayDirectory( aObj.GetMainURL(INetURLObject::DECODE_TO_IURI) );
|
2001-09-04 10:24:50 -05:00
|
|
|
if( xFolderPicker->execute() == ExecutableDialogResults::OK )
|
|
|
|
{
|
|
|
|
aObj = INetURLObject( xFolderPicker->getDirectory() );
|
|
|
|
rInOutPath = aObj.PathToFileName();
|
|
|
|
bRet = true;
|
|
|
|
}
|
|
|
|
}
|
2003-04-15 11:21:43 -05:00
|
|
|
#if OSL_DEBUG_LEVEL > 1
|
2001-09-04 10:24:50 -05:00
|
|
|
else
|
|
|
|
fprintf( stderr, "could not get FolderPicker service\n" );
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
return bRet;
|
|
|
|
}
|
2010-10-14 01:27:31 -05:00
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|