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 <unotools/confignode.hxx>
35 #include <i18nlangtag/mslangid.hxx>
36 #include <rtl/ustrbuf.hxx>
40 using namespace padmin
;
41 using namespace com::sun::star::uno
;
42 using namespace com::sun::star::lang
;
43 using namespace com::sun::star::ui::dialogs
;
50 ResId
padmin::PaResId( sal_uInt32 nId
)
52 static ResMgr
* pPaResMgr
= NULL
;
55 LanguageTag
aLanguageTag( LANGUAGE_SYSTEM
);
57 utl::OConfigurationNode aNode
=
58 utl::OConfigurationTreeRoot::tryCreateWithComponentContext(
59 comphelper::getProcessComponentContext(),
60 OUString("org.openoffice.Setup/L10N") );
61 if ( aNode
.isValid() )
64 Any aValue
= aNode
.getNodeValue( OUString("ooLocale") );
67 aLanguageTag
.reset( aLoc
);
70 pPaResMgr
= ResMgr::SearchCreateResMgr( "spa", aLanguageTag
);
71 AllSettings aSettings
= Application::GetSettings();
72 aSettings
.SetUILanguageTag( aLanguageTag
);
73 Application::SetSettings( aSettings
);
75 return ResId( nId
, *pPaResMgr
);
82 void padmin::FindFiles( const OUString
& rDirectory
, ::std::list
< String
>& rResult
, const OUString
& rSuffixes
, bool bRecursive
)
87 ::osl::FileBase::getFileURLFromSystemPath( rDirectory
, aDirPath
);
88 Directory
aDir( aDirPath
);
89 if( aDir
.open() != FileBase::E_None
)
92 while( aDir
.getNextItem( aItem
) == FileBase::E_None
)
94 FileStatus
aStatus( osl_FileStatus_Mask_FileName
|
95 osl_FileStatus_Mask_Type
97 if( aItem
.getFileStatus( aStatus
) == FileBase::E_None
)
99 if( aStatus
.getFileType() == FileStatus::Regular
||
100 aStatus
.getFileType() == FileStatus::Link
)
102 String aFileName
= aStatus
.getFileName();
103 int nToken
= comphelper::string::getTokenCount(rSuffixes
, ';');
106 OUString aSuffix
= rSuffixes
.getToken( nToken
, ';' );
107 if( aFileName
.Len() > aSuffix
.getLength()+1 )
109 String aExtension
= aFileName
.Copy( aFileName
.Len()-aSuffix
.getLength() );
110 if( aFileName
.GetChar( aFileName
.Len()-aSuffix
.getLength()-1 ) == '.' &&
111 aExtension
.EqualsIgnoreCaseAscii( aSuffix
) )
113 rResult
.push_back( aFileName
);
119 else if( bRecursive
&& aStatus
.getFileType() == FileStatus::Directory
)
121 OUStringBuffer
aSubDir( rDirectory
);
122 aSubDir
.appendAscii( "/", 1 );
123 aSubDir
.append( aStatus
.getFileName() );
124 std::list
< String
> subfiles
;
125 FindFiles( aSubDir
.makeStringAndClear(), subfiles
, rSuffixes
, bRecursive
);
126 for( std::list
< String
>::const_iterator it
= subfiles
.begin(); it
!= subfiles
.end(); ++it
)
128 OUStringBuffer
aSubFile( aStatus
.getFileName() );
129 aSubFile
.appendAscii( "/", 1 );
130 aSubFile
.append( *it
);
131 rResult
.push_back( aSubFile
.makeStringAndClear() );
143 long DelMultiListBox::Notify( NotifyEvent
& rEvent
)
147 if( rEvent
.GetType() == EVENT_KEYINPUT
&&
148 rEvent
.GetKeyEvent()->GetKeyCode().GetCode() == KEY_DELETE
)
150 m_aDelPressedLink
.Call( this );
154 nRet
= MultiListBox::Notify( rEvent
);
163 long DelListBox::Notify( NotifyEvent
& rEvent
)
167 if( rEvent
.GetType() == EVENT_KEYINPUT
&&
168 rEvent
.GetKeyEvent()->GetKeyCode().GetCode() == KEY_DELETE
)
170 m_aDelPressedLink
.Call( this );
174 nRet
= ListBox::Notify( rEvent
);
183 QueryString::QueryString( Window
* pParent
, String
& rQuery
, String
& rRet
, const ::std::list
< String
>& rChoices
) :
184 ModalDialog( pParent
, PaResId( RID_STRINGQUERYDLG
) ),
185 m_aOKButton( this, PaResId( RID_STRQRY_BTN_OK
) ),
186 m_aCancelButton( this, PaResId( RID_STRQRY_BTN_CANCEL
) ),
187 m_aFixedText( this, PaResId( RID_STRQRY_TXT_RENAME
) ),
188 m_aEdit( this, PaResId( RID_STRQRY_EDT_NEWNAME
) ),
189 m_aComboBox( this, PaResId( RID_STRQRY_BOX_NEWNAME
) ),
190 m_rReturnValue( rRet
)
193 m_aOKButton
.SetClickHdl( LINK( this, QueryString
, ClickBtnHdl
) );
194 m_aFixedText
.SetText( rQuery
);
195 if( rChoices
.begin() != rChoices
.end() )
197 m_aComboBox
.SetText( m_rReturnValue
);
198 m_aComboBox
.InsertEntry( m_rReturnValue
);
199 for( ::std::list
<String
>::const_iterator it
= rChoices
.begin(); it
!= rChoices
.end(); ++it
)
200 m_aComboBox
.InsertEntry( *it
);
201 m_aEdit
.Show( sal_False
);
206 m_aEdit
.SetText( m_rReturnValue
);
207 m_aComboBox
.Show( sal_False
);
210 SetText( Application::GetDisplayName() );
213 QueryString::~QueryString()
217 IMPL_LINK( QueryString
, ClickBtnHdl
, Button
*, pButton
)
219 if( pButton
== &m_aOKButton
)
221 m_rReturnValue
= m_bUseEdit
? m_aEdit
.GetText() : m_aComboBox
.GetText();
233 sal_Bool
padmin::AreYouSure( Window
* pParent
, int nRid
)
237 QueryBox
aQueryBox( pParent
, WB_YES_NO
| WB_DEF_NO
,
238 String( PaResId( nRid
) ) );
239 return aQueryBox
.Execute() == RET_NO
? sal_False
: sal_True
;
246 static Config
* pRC
= NULL
;
248 Config
& padmin::getPadminRC()
252 static const char* pEnv
= getenv( "HOME" );
253 String
aFileName( pEnv
? pEnv
: "", osl_getThreadTextEncoding() );
254 aFileName
.AppendAscii( "/.padminrc" );
255 pRC
= new Config( aFileName
);
260 void padmin::freePadminRC()
263 delete pRC
, pRC
= NULL
;
266 bool padmin::chooseDirectory( OUString
& rInOutPath
)
269 Reference
< XComponentContext
> xContext( ::comphelper::getProcessComponentContext() );
270 Reference
< XFolderPicker2
> xFolderPicker
= FolderPicker::create(xContext
);;
271 Reference
< XControlAccess
> xCA( xFolderPicker
, UNO_QUERY
);
277 aState
<<= sal_False
;
278 xCA
->setControlProperty( OUString( "HelpButton" ),
279 OUString( "Visible" ),
287 INetURLObject
aObj( rInOutPath
, INET_PROT_FILE
, INetURLObject::ENCODE_ALL
);
288 xFolderPicker
->setDisplayDirectory( aObj
.GetMainURL(INetURLObject::DECODE_TO_IURI
) );
289 if( xFolderPicker
->execute() == ExecutableDialogResults::OK
)
291 aObj
= INetURLObject( xFolderPicker
->getDirectory() );
292 rInOutPath
= aObj
.PathToFileName();
295 #if OSL_DEBUG_LEVEL > 1
297 fprintf( stderr
, "could not get FolderPicker service\n" );
302 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */