remove code that was commented out long time ago
[LibreOffice.git] / padmin / source / helper.cxx
bloba65915047f3b5e07add14555f95ff0e53595fc37
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
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/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>
39 using namespace osl;
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;
47 * PaResId
50 ResId padmin::PaResId( sal_uInt32 nId )
52 static ResMgr* pPaResMgr = NULL;
53 if( ! pPaResMgr )
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() )
63 OUString aLoc;
64 Any aValue = aNode.getNodeValue( OUString("ooLocale") );
65 if( aValue >>= aLoc )
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 );
79 * FindFiles
82 void padmin::FindFiles( const OUString& rDirectory, ::std::list< String >& rResult, const OUString& rSuffixes, bool bRecursive )
84 rResult.clear();
86 OUString aDirPath;
87 ::osl::FileBase::getFileURLFromSystemPath( rDirectory, aDirPath );
88 Directory aDir( aDirPath );
89 if( aDir.open() != FileBase::E_None )
90 return;
91 DirectoryItem aItem;
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, ';');
104 while( nToken-- )
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 );
114 break;
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() );
136 aDir.close();
140 * DelMultiListBox
143 long DelMultiListBox::Notify( NotifyEvent& rEvent )
145 long nRet = 0;
147 if( rEvent.GetType() == EVENT_KEYINPUT &&
148 rEvent.GetKeyEvent()->GetKeyCode().GetCode() == KEY_DELETE )
150 m_aDelPressedLink.Call( this );
151 nRet = 1;
153 else
154 nRet = MultiListBox::Notify( rEvent );
156 return nRet;
160 * DelListBox
163 long DelListBox::Notify( NotifyEvent& rEvent )
165 long nRet = 0;
167 if( rEvent.GetType() == EVENT_KEYINPUT &&
168 rEvent.GetKeyEvent()->GetKeyCode().GetCode() == KEY_DELETE )
170 m_aDelPressedLink.Call( this );
171 nRet = 1;
173 else
174 nRet = ListBox::Notify( rEvent );
176 return nRet;
180 * QueryString
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 )
192 FreeResource();
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 );
202 m_bUseEdit = false;
204 else
206 m_aEdit.SetText( m_rReturnValue );
207 m_aComboBox.Show( sal_False );
208 m_bUseEdit = true;
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();
222 EndDialog( 1 );
224 else
225 EndDialog(0);
226 return 0;
230 * AreYouSure
233 sal_Bool padmin::AreYouSure( Window* pParent, int nRid )
235 if( nRid == -1 )
236 nRid = RID_YOU_SURE;
237 QueryBox aQueryBox( pParent, WB_YES_NO | WB_DEF_NO,
238 String( PaResId( nRid ) ) );
239 return aQueryBox.Execute() == RET_NO ? sal_False : sal_True;
243 * getPadminRC
246 static Config* pRC = NULL;
248 Config& padmin::getPadminRC()
250 if( ! pRC )
252 static const char* pEnv = getenv( "HOME" );
253 OUString aFileName;
254 if( pEnv )
255 aFileName = OUString::createFromAscii( pEnv ) + "/.padminrc";
256 else
257 aFileName += OStringToOUString( "", osl_getThreadTextEncoding() ) + "/.padminrc";
259 pRC = new Config( aFileName );
261 return *pRC;
264 void padmin::freePadminRC()
266 if( pRC )
267 delete pRC, pRC = NULL;
270 bool padmin::chooseDirectory( OUString& rInOutPath )
272 bool bRet = false;
273 Reference< XComponentContext > xContext( ::comphelper::getProcessComponentContext() );
274 Reference< XFolderPicker2 > xFolderPicker = FolderPicker::create(xContext);;
275 Reference< XControlAccess > xCA( xFolderPicker, UNO_QUERY );
276 if( xCA.is() )
280 Any aState;
281 aState <<= sal_False;
282 xCA->setControlProperty( OUString( "HelpButton" ),
283 OUString( "Visible" ),
284 aState );
287 catch( ... )
291 INetURLObject aObj( rInOutPath, INET_PROT_FILE, INetURLObject::ENCODE_ALL );
292 xFolderPicker->setDisplayDirectory( aObj.GetMainURL(INetURLObject::DECODE_TO_IURI) );
293 if( xFolderPicker->execute() == ExecutableDialogResults::OK )
295 aObj = INetURLObject( xFolderPicker->getDirectory() );
296 rInOutPath = aObj.PathToFileName();
297 bRet = true;
299 #if OSL_DEBUG_LEVEL > 1
300 else
301 fprintf( stderr, "could not get FolderPicker service\n" );
302 #endif
303 return bRet;
306 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */