1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: helper.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
33 #ifndef _PAD_PADIALOG_HRC_
34 #include <padialog.hrc>
36 #include <osl/file.hxx>
37 #include <tools/urlobj.hxx>
38 #include <vcl/svapp.hxx>
39 #include <vcl/msgbox.hxx>
40 #include <tools/config.hxx>
41 #include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
42 #include <com/sun/star/ui/dialogs/XFolderPicker.hpp>
43 #include <com/sun/star/ui/dialogs/XControlAccess.hpp>
44 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
45 #include <comphelper/processfactory.hxx>
46 #include <tools/urlobj.hxx>
47 #include <unotools/confignode.hxx>
48 #include <vcl/unohelp.hxx>
49 #include <i18npool/mslangid.hxx>
50 #include <rtl/ustrbuf.hxx>
55 using namespace padmin
;
56 using namespace com::sun::star::uno
;
57 using namespace com::sun::star::lang
;
58 using namespace com::sun::star::ui::dialogs
;
66 ResId
padmin::PaResId( sal_uInt32 nId
)
68 static ResMgr
* pPaResMgr
= NULL
;
71 ::com::sun::star::lang::Locale aLocale
;
72 // LanguageType nLang = LANGUAGE_SYSTEM;
74 utl::OConfigurationNode aNode
=
75 utl::OConfigurationTreeRoot::tryCreateWithServiceFactory(
76 vcl::unohelper::GetMultiServiceFactory(),
77 OUString::createFromAscii( "org.openoffice.Setup/L10N" ) );
78 if ( aNode
.isValid() )
81 Any aValue
= aNode
.getNodeValue( OUString::createFromAscii( "ooLocale" ) );
84 // LanguageType nTmpLang = MsLangId::convertIsoStringToLanguage( aLoc );
85 // if( nTmpLang != LANGUAGE_DONTKNOW )
88 aLocale
.Language
= aLoc
.getToken( 0, '-', nIndex
);
89 aLocale
.Country
= aLoc
.getToken( 0, '-', nIndex
);
90 aLocale
.Variant
= aLoc
.getToken( 0, '-', nIndex
);
93 pPaResMgr
= ResMgr::SearchCreateResMgr( "spa", aLocale
);
94 AllSettings aSettings
= Application::GetSettings();
95 // aSettings.SetUILanguage( nLang );
96 aSettings
.SetUILocale( aLocale
);
97 Application::SetSettings( aSettings
);
99 return ResId( nId
, *pPaResMgr
);
106 void padmin::FindFiles( const String
& rDirectory
, ::std::list
< String
>& rResult
, const String
& rSuffixes
, bool bRecursive
)
111 ::osl::FileBase::getFileURLFromSystemPath( rDirectory
, aDirPath
);
112 Directory
aDir( aDirPath
);
113 if( aDir
.open() != FileBase::E_None
)
116 while( aDir
.getNextItem( aItem
) == FileBase::E_None
)
118 FileStatus
aStatus( FileStatusMask_FileName
|
121 if( aItem
.getFileStatus( aStatus
) == FileBase::E_None
)
123 if( aStatus
.getFileType() == FileStatus::Regular
||
124 aStatus
.getFileType() == FileStatus::Link
)
126 String aFileName
= aStatus
.getFileName();
127 int nToken
= rSuffixes
.GetTokenCount( ';' );
130 String aSuffix
= rSuffixes
.GetToken( nToken
, ';' );
131 if( aFileName
.Len() > aSuffix
.Len()+1 )
133 String aExtension
= aFileName
.Copy( aFileName
.Len()-aSuffix
.Len() );
134 if( aFileName
.GetChar( aFileName
.Len()-aSuffix
.Len()-1 ) == '.' &&
135 aExtension
.EqualsIgnoreCaseAscii( aSuffix
) )
137 rResult
.push_back( aFileName
);
143 else if( bRecursive
&& aStatus
.getFileType() == FileStatus::Directory
)
145 OUStringBuffer
aSubDir( rDirectory
);
146 aSubDir
.appendAscii( "/", 1 );
147 aSubDir
.append( aStatus
.getFileName() );
148 std::list
< String
> subfiles
;
149 FindFiles( aSubDir
.makeStringAndClear(), subfiles
, rSuffixes
, bRecursive
);
150 for( std::list
< String
>::const_iterator it
= subfiles
.begin(); it
!= subfiles
.end(); ++it
)
152 OUStringBuffer
aSubFile( aStatus
.getFileName() );
153 aSubFile
.appendAscii( "/", 1 );
154 aSubFile
.append( *it
);
155 rResult
.push_back( aSubFile
.makeStringAndClear() );
167 long DelMultiListBox::Notify( NotifyEvent
& rEvent
)
171 if( rEvent
.GetType() == EVENT_KEYINPUT
&&
172 rEvent
.GetKeyEvent()->GetKeyCode().GetCode() == KEY_DELETE
)
174 m_aDelPressedLink
.Call( this );
178 nRet
= MultiListBox::Notify( rEvent
);
187 long DelListBox::Notify( NotifyEvent
& rEvent
)
191 if( rEvent
.GetType() == EVENT_KEYINPUT
&&
192 rEvent
.GetKeyEvent()->GetKeyCode().GetCode() == KEY_DELETE
)
194 m_aDelPressedLink
.Call( this );
198 nRet
= ListBox::Notify( rEvent
);
207 QueryString::QueryString( Window
* pParent
, String
& rQuery
, String
& rRet
, const ::std::list
< String
>& rChoices
) :
208 ModalDialog( pParent
, PaResId( RID_STRINGQUERYDLG
) ),
209 m_aOKButton( this, PaResId( RID_STRQRY_BTN_OK
) ),
210 m_aCancelButton( this, PaResId( RID_STRQRY_BTN_CANCEL
) ),
211 m_aFixedText( this, PaResId( RID_STRQRY_TXT_RENAME
) ),
212 m_aEdit( this, PaResId( RID_STRQRY_EDT_NEWNAME
) ),
213 m_aComboBox( this, PaResId( RID_STRQRY_BOX_NEWNAME
) ),
214 m_rReturnValue( rRet
)
217 m_aOKButton
.SetClickHdl( LINK( this, QueryString
, ClickBtnHdl
) );
218 m_aFixedText
.SetText( rQuery
);
219 if( rChoices
.begin() != rChoices
.end() )
221 m_aComboBox
.SetText( m_rReturnValue
);
222 m_aComboBox
.InsertEntry( m_rReturnValue
);
223 for( ::std::list
<String
>::const_iterator it
= rChoices
.begin(); it
!= rChoices
.end(); ++it
)
224 m_aComboBox
.InsertEntry( *it
);
225 m_aEdit
.Show( FALSE
);
230 m_aEdit
.SetText( m_rReturnValue
);
231 m_aComboBox
.Show( FALSE
);
234 SetText( Application::GetDisplayName() );
237 QueryString::~QueryString()
241 IMPL_LINK( QueryString
, ClickBtnHdl
, Button
*, pButton
)
243 if( pButton
== &m_aOKButton
)
245 m_rReturnValue
= m_bUseEdit
? m_aEdit
.GetText() : m_aComboBox
.GetText();
257 BOOL
padmin::AreYouSure( Window
* pParent
, int nRid
)
261 QueryBox
aQueryBox( pParent
, WB_YES_NO
| WB_DEF_NO
,
262 String( PaResId( nRid
) ) );
263 return aQueryBox
.Execute() == RET_NO
? FALSE
: TRUE
;
270 static Config
* pRC
= NULL
;
272 Config
& padmin::getPadminRC()
276 static const char* pEnv
= getenv( "HOME" );
277 String
aFileName( pEnv
? pEnv
: "", osl_getThreadTextEncoding() );
278 aFileName
.AppendAscii( "/.padminrc" );
279 pRC
= new Config( aFileName
);
284 void padmin::freePadminRC()
287 delete pRC
, pRC
= NULL
;
290 bool padmin::chooseDirectory( String
& rInOutPath
)
293 Reference
< XMultiServiceFactory
> xFactory( ::comphelper::getProcessServiceFactory() );
296 Reference
< XFolderPicker
> xFolderPicker( xFactory
->createInstance( OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.ui.dialogs.FolderPicker" ) ) ), UNO_QUERY
);
297 if( xFolderPicker
.is() )
299 Reference
< XControlAccess
> xCA( xFolderPicker
, UNO_QUERY
);
305 aState
<<= sal_False
;
306 xCA
->setControlProperty( OUString( RTL_CONSTASCII_USTRINGPARAM( "HelpButton" ) ),
307 OUString( RTL_CONSTASCII_USTRINGPARAM( "Visible" ) ),
315 INetURLObject
aObj( rInOutPath
, INET_PROT_FILE
, INetURLObject::ENCODE_ALL
);
316 xFolderPicker
->setDisplayDirectory( aObj
.GetMainURL(INetURLObject::DECODE_TO_IURI
) );
317 if( xFolderPicker
->execute() == ExecutableDialogResults::OK
)
319 aObj
= INetURLObject( xFolderPicker
->getDirectory() );
320 rInOutPath
= aObj
.PathToFileName();
324 #if OSL_DEBUG_LEVEL > 1
326 fprintf( stderr
, "could not get FolderPicker service\n" );