1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
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>
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
;
47 using ::rtl::OUString
;
48 using ::rtl::OUStringBuffer
;
56 ResId
padmin::PaResId( sal_uInt32 nId
)
58 static ResMgr
* pPaResMgr
= NULL
;
61 ::com::sun::star::lang::Locale aLocale
;
63 utl::OConfigurationNode aNode
=
64 utl::OConfigurationTreeRoot::tryCreateWithComponentContext(
65 comphelper::getProcessComponentContext(),
66 OUString("org.openoffice.Setup/L10N") );
67 if ( aNode
.isValid() )
70 Any aValue
= aNode
.getNodeValue( OUString("ooLocale") );
73 /* FIXME-BCP47: handle language tags! */
75 aLocale
.Language
= aLoc
.getToken( 0, '-', nIndex
);
76 aLocale
.Country
= aLoc
.getToken( 0, '-', nIndex
);
77 aLocale
.Variant
= aLoc
.getToken( 0, '-', nIndex
);
80 pPaResMgr
= ResMgr::SearchCreateResMgr( "spa", aLocale
);
81 AllSettings aSettings
= Application::GetSettings();
82 aSettings
.SetUILanguageTag( LanguageTag( aLocale
) );
83 Application::SetSettings( aSettings
);
85 return ResId( nId
, *pPaResMgr
);
92 void padmin::FindFiles( const String
& rDirectory
, ::std::list
< String
>& rResult
, const String
& rSuffixes
, bool bRecursive
)
97 ::osl::FileBase::getFileURLFromSystemPath( rDirectory
, aDirPath
);
98 Directory
aDir( aDirPath
);
99 if( aDir
.open() != FileBase::E_None
)
102 while( aDir
.getNextItem( aItem
) == FileBase::E_None
)
104 FileStatus
aStatus( osl_FileStatus_Mask_FileName
|
105 osl_FileStatus_Mask_Type
107 if( aItem
.getFileStatus( aStatus
) == FileBase::E_None
)
109 if( aStatus
.getFileType() == FileStatus::Regular
||
110 aStatus
.getFileType() == FileStatus::Link
)
112 String aFileName
= aStatus
.getFileName();
113 int nToken
= comphelper::string::getTokenCount(rSuffixes
, ';');
116 String aSuffix
= rSuffixes
.GetToken( nToken
, ';' );
117 if( aFileName
.Len() > aSuffix
.Len()+1 )
119 String aExtension
= aFileName
.Copy( aFileName
.Len()-aSuffix
.Len() );
120 if( aFileName
.GetChar( aFileName
.Len()-aSuffix
.Len()-1 ) == '.' &&
121 aExtension
.EqualsIgnoreCaseAscii( aSuffix
) )
123 rResult
.push_back( aFileName
);
129 else if( bRecursive
&& aStatus
.getFileType() == FileStatus::Directory
)
131 OUStringBuffer
aSubDir( rDirectory
);
132 aSubDir
.appendAscii( "/", 1 );
133 aSubDir
.append( aStatus
.getFileName() );
134 std::list
< String
> subfiles
;
135 FindFiles( aSubDir
.makeStringAndClear(), subfiles
, rSuffixes
, bRecursive
);
136 for( std::list
< String
>::const_iterator it
= subfiles
.begin(); it
!= subfiles
.end(); ++it
)
138 OUStringBuffer
aSubFile( aStatus
.getFileName() );
139 aSubFile
.appendAscii( "/", 1 );
140 aSubFile
.append( *it
);
141 rResult
.push_back( aSubFile
.makeStringAndClear() );
153 long DelMultiListBox::Notify( NotifyEvent
& rEvent
)
157 if( rEvent
.GetType() == EVENT_KEYINPUT
&&
158 rEvent
.GetKeyEvent()->GetKeyCode().GetCode() == KEY_DELETE
)
160 m_aDelPressedLink
.Call( this );
164 nRet
= MultiListBox::Notify( rEvent
);
173 long DelListBox::Notify( NotifyEvent
& rEvent
)
177 if( rEvent
.GetType() == EVENT_KEYINPUT
&&
178 rEvent
.GetKeyEvent()->GetKeyCode().GetCode() == KEY_DELETE
)
180 m_aDelPressedLink
.Call( this );
184 nRet
= ListBox::Notify( rEvent
);
193 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 m_rReturnValue( rRet
)
203 m_aOKButton
.SetClickHdl( LINK( this, QueryString
, ClickBtnHdl
) );
204 m_aFixedText
.SetText( rQuery
);
205 if( rChoices
.begin() != rChoices
.end() )
207 m_aComboBox
.SetText( m_rReturnValue
);
208 m_aComboBox
.InsertEntry( m_rReturnValue
);
209 for( ::std::list
<String
>::const_iterator it
= rChoices
.begin(); it
!= rChoices
.end(); ++it
)
210 m_aComboBox
.InsertEntry( *it
);
211 m_aEdit
.Show( sal_False
);
216 m_aEdit
.SetText( m_rReturnValue
);
217 m_aComboBox
.Show( sal_False
);
220 SetText( Application::GetDisplayName() );
223 QueryString::~QueryString()
227 IMPL_LINK( QueryString
, ClickBtnHdl
, Button
*, pButton
)
229 if( pButton
== &m_aOKButton
)
231 m_rReturnValue
= m_bUseEdit
? m_aEdit
.GetText() : m_aComboBox
.GetText();
243 sal_Bool
padmin::AreYouSure( Window
* pParent
, int nRid
)
247 QueryBox
aQueryBox( pParent
, WB_YES_NO
| WB_DEF_NO
,
248 String( PaResId( nRid
) ) );
249 return aQueryBox
.Execute() == RET_NO
? sal_False
: sal_True
;
256 static Config
* pRC
= NULL
;
258 Config
& padmin::getPadminRC()
262 static const char* pEnv
= getenv( "HOME" );
263 String
aFileName( pEnv
? pEnv
: "", osl_getThreadTextEncoding() );
264 aFileName
.AppendAscii( "/.padminrc" );
265 pRC
= new Config( aFileName
);
270 void padmin::freePadminRC()
273 delete pRC
, pRC
= NULL
;
276 bool padmin::chooseDirectory( String
& rInOutPath
)
279 Reference
< XComponentContext
> xContext( ::comphelper::getProcessComponentContext() );
280 Reference
< XFolderPicker2
> xFolderPicker
= FolderPicker::create(xContext
);;
281 Reference
< XControlAccess
> xCA( xFolderPicker
, UNO_QUERY
);
287 aState
<<= sal_False
;
288 xCA
->setControlProperty( OUString( "HelpButton" ),
289 OUString( "Visible" ),
297 INetURLObject
aObj( rInOutPath
, INET_PROT_FILE
, INetURLObject::ENCODE_ALL
);
298 xFolderPicker
->setDisplayDirectory( aObj
.GetMainURL(INetURLObject::DECODE_TO_IURI
) );
299 if( xFolderPicker
->execute() == ExecutableDialogResults::OK
)
301 aObj
= INetURLObject( xFolderPicker
->getDirectory() );
302 rInOutPath
= aObj
.PathToFileName();
305 #if OSL_DEBUG_LEVEL > 1
307 fprintf( stderr
, "could not get FolderPicker service\n" );
312 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */