bump product version to 4.1.6.2
[LibreOffice.git] / fpicker / source / office / OfficeFolderPicker.cxx
blob1cf1d052f938b7304bc0b6649e7e37578de327e2
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 "OfficeFolderPicker.hxx"
22 #include "iodlg.hxx"
24 #include <list>
25 #include <tools/urlobj.hxx>
26 #include <com/sun/star/container/XContentEnumerationAccess.hpp>
27 #include <com/sun/star/container/XSet.hpp>
28 #include <com/sun/star/uno/Any.hxx>
29 #include <cppuhelper/factory.hxx>
30 #include <com/sun/star/beans/XPropertySet.hpp>
31 #include <unotools/pathoptions.hxx>
33 using namespace ::com::sun::star::container;
34 using namespace ::com::sun::star::lang;
35 using namespace ::com::sun::star::uno;
36 using namespace ::com::sun::star::beans;
38 SvtFolderPicker::SvtFolderPicker( const Reference < XMultiServiceFactory >& _rxFactory )
39 :SvtFolderPicker_Base( _rxFactory )
43 SvtFolderPicker::~SvtFolderPicker()
47 void SAL_CALL SvtFolderPicker::setTitle( const OUString& _rTitle ) throw (RuntimeException)
49 OCommonPicker::setTitle( _rTitle );
52 sal_Int16 SAL_CALL SvtFolderPicker::execute( ) throw (RuntimeException)
54 return OCommonPicker::execute();
57 void SAL_CALL SvtFolderPicker::setDialogTitle( const OUString& _rTitle) throw (RuntimeException)
59 setTitle( _rTitle );
62 void SAL_CALL SvtFolderPicker::startExecuteModal( const Reference< ::com::sun::star::ui::dialogs::XDialogClosedListener >& xListener ) throw (RuntimeException)
64 m_xListener = xListener;
65 prepareDialog();
66 prepareExecute();
67 getDialog()->EnableAutocompletion( sal_True );
68 getDialog()->StartExecuteModal( LINK( this, SvtFolderPicker, DialogClosedHdl ) );
71 SvtFileDialog* SvtFolderPicker::implCreateDialog( Window* _pParent )
73 return new SvtFileDialog( _pParent, SFXWB_PATHDIALOG );
76 sal_Int16 SvtFolderPicker::implExecutePicker( )
78 prepareExecute();
80 // now we are ready to execute the dialog
81 getDialog()->EnableAutocompletion( sal_False );
82 sal_Int16 nRet = getDialog()->Execute();
84 return nRet;
87 void SvtFolderPicker::prepareExecute()
89 // set the default directory
90 if ( !m_aDisplayDirectory.isEmpty() )
91 getDialog()->SetPath( m_aDisplayDirectory );
92 else
94 // Default-Standard-Dir setzen
95 INetURLObject aStdDirObj( SvtPathOptions().GetWorkPath() );
96 getDialog()->SetPath( aStdDirObj.GetMainURL( INetURLObject::NO_DECODE) );
100 IMPL_LINK( SvtFolderPicker, DialogClosedHdl, Dialog*, pDlg )
102 if ( m_xListener.is() )
104 sal_Int16 nRet = static_cast< sal_Int16 >( pDlg->GetResult() );
105 ::com::sun::star::ui::dialogs::DialogClosedEvent aEvent( *this, nRet );
106 m_xListener->dialogClosed( aEvent );
107 m_xListener.clear();
109 return 0;
112 void SAL_CALL SvtFolderPicker::setDisplayDirectory( const OUString& aDirectory )
113 throw( IllegalArgumentException, RuntimeException )
115 m_aDisplayDirectory = aDirectory;
118 OUString SAL_CALL SvtFolderPicker::getDisplayDirectory() throw( RuntimeException )
120 if ( ! getDialog() )
121 return m_aDisplayDirectory;
123 std::vector<OUString> aPathList(getDialog()->GetPathList());
125 if(!aPathList.empty())
126 return aPathList[0];
128 return OUString();
131 OUString SAL_CALL SvtFolderPicker::getDirectory() throw( RuntimeException )
133 if ( ! getDialog() )
134 return m_aDisplayDirectory;
136 std::vector<OUString> aPathList(getDialog()->GetPathList());
138 if(!aPathList.empty())
139 return aPathList[0];
141 return OUString();
144 void SAL_CALL SvtFolderPicker::setDescription( const OUString& aDescription )
145 throw( RuntimeException )
147 m_aDescription = aDescription;
150 void SvtFolderPicker::cancel() throw (RuntimeException)
152 OCommonPicker::cancel();
155 /* XServiceInfo */
156 OUString SAL_CALL SvtFolderPicker::getImplementationName() throw( RuntimeException )
158 return impl_getStaticImplementationName();
161 /* XServiceInfo */
162 sal_Bool SAL_CALL SvtFolderPicker::supportsService( const OUString& sServiceName ) throw( RuntimeException )
164 Sequence< OUString > seqServiceNames = getSupportedServiceNames();
165 const OUString* pArray = seqServiceNames.getConstArray();
166 for ( sal_Int32 i = 0; i < seqServiceNames.getLength(); i++ )
168 if ( sServiceName == pArray[i] )
170 return sal_True ;
173 return sal_False ;
176 /* XServiceInfo */
177 Sequence< OUString > SAL_CALL SvtFolderPicker::getSupportedServiceNames() throw( RuntimeException )
179 return impl_getStaticSupportedServiceNames();
182 /* Helper for XServiceInfo */
183 Sequence< OUString > SvtFolderPicker::impl_getStaticSupportedServiceNames()
185 Sequence< OUString > seqServiceNames(1);
186 seqServiceNames[0] = OUString( "com.sun.star.ui.dialogs.OfficeFolderPicker" );
187 return seqServiceNames ;
190 /* Helper for XServiceInfo */
191 OUString SvtFolderPicker::impl_getStaticImplementationName()
193 return OUString( "com.sun.star.svtools.OfficeFolderPicker" );
196 /* Helper for registry */
197 Reference< XInterface > SAL_CALL SvtFolderPicker::impl_createInstance( const Reference< XComponentContext >& rxContext )
198 throw( Exception )
200 Reference< XMultiServiceFactory > xServiceManager (rxContext->getServiceManager(), UNO_QUERY_THROW);
201 return Reference< XInterface >( *new SvtFolderPicker( xServiceManager ) );
204 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */