build fix
[LibreOffice.git] / fpicker / source / office / OfficeFolderPicker.cxx
blobec1f8a8e0f358b2b07655e02fab121b799e528ae
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 <cppuhelper/factory.hxx>
29 #include <cppuhelper/supportsservice.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()
42 SvtFolderPicker::~SvtFolderPicker()
46 void SAL_CALL SvtFolderPicker::setTitle( const OUString& _rTitle ) throw (RuntimeException, std::exception)
48 OCommonPicker::setTitle( _rTitle );
51 sal_Int16 SAL_CALL SvtFolderPicker::execute( ) throw (RuntimeException, std::exception)
53 return OCommonPicker::execute();
56 void SAL_CALL SvtFolderPicker::setDialogTitle( const OUString& _rTitle) throw (RuntimeException, std::exception)
58 setTitle( _rTitle );
61 void SAL_CALL SvtFolderPicker::startExecuteModal( const Reference< css::ui::dialogs::XDialogClosedListener >& xListener ) throw (RuntimeException, std::exception)
63 m_xListener = xListener;
64 prepareDialog();
65 prepareExecute();
66 getDialog()->EnableAutocompletion();
67 getDialog()->StartExecuteModal( LINK( this, SvtFolderPicker, DialogClosedHdl ) );
70 VclPtr<SvtFileDialog_Base> SvtFolderPicker::implCreateDialog( vcl::Window* _pParent )
72 return VclPtr<SvtFileDialog>::Create( _pParent, PickerFlags::PathDialog );
75 sal_Int16 SvtFolderPicker::implExecutePicker( )
77 prepareExecute();
79 // now we are ready to execute the dialog
80 getDialog()->EnableAutocompletion( false );
81 sal_Int16 nRet = getDialog()->Execute();
83 return nRet;
86 void SvtFolderPicker::prepareExecute()
88 // set the default directory
89 if ( !m_aDisplayDirectory.isEmpty() )
90 getDialog()->SetPath( m_aDisplayDirectory );
91 else
93 // Default-Standard-Dir setzen
94 INetURLObject aStdDirObj( SvtPathOptions().GetWorkPath() );
95 getDialog()->SetPath( aStdDirObj.GetMainURL( INetURLObject::DecodeMechanism::NONE) );
99 IMPL_LINK( SvtFolderPicker, DialogClosedHdl, Dialog&, rDlg, void )
101 if ( m_xListener.is() )
103 sal_Int16 nRet = static_cast< sal_Int16 >( rDlg.GetResult() );
104 css::ui::dialogs::DialogClosedEvent aEvent( *this, nRet );
105 m_xListener->dialogClosed( aEvent );
106 m_xListener.clear();
110 void SAL_CALL SvtFolderPicker::setDisplayDirectory( const OUString& aDirectory )
111 throw( IllegalArgumentException, RuntimeException, std::exception )
113 m_aDisplayDirectory = aDirectory;
116 OUString SAL_CALL SvtFolderPicker::getDisplayDirectory() throw( RuntimeException, std::exception )
118 if ( ! getDialog() )
119 return m_aDisplayDirectory;
121 std::vector<OUString> aPathList(getDialog()->GetPathList());
123 if(!aPathList.empty())
124 return aPathList[0];
126 return OUString();
129 OUString SAL_CALL SvtFolderPicker::getDirectory() throw( RuntimeException, std::exception )
131 if ( ! getDialog() )
132 return m_aDisplayDirectory;
134 std::vector<OUString> aPathList(getDialog()->GetPathList());
136 if(!aPathList.empty())
137 return aPathList[0];
139 return OUString();
142 void SAL_CALL SvtFolderPicker::setDescription( const OUString& aDescription )
143 throw( RuntimeException, std::exception )
145 m_aDescription = aDescription;
148 void SvtFolderPicker::cancel() throw (RuntimeException, std::exception)
150 OCommonPicker::cancel();
153 /* XServiceInfo */
154 OUString SAL_CALL SvtFolderPicker::getImplementationName() throw( RuntimeException, std::exception )
156 return impl_getStaticImplementationName();
159 /* XServiceInfo */
160 sal_Bool SAL_CALL SvtFolderPicker::supportsService( const OUString& sServiceName ) throw( RuntimeException, std::exception )
162 return cppu::supportsService(this, sServiceName);
165 /* XServiceInfo */
166 Sequence< OUString > SAL_CALL SvtFolderPicker::getSupportedServiceNames() throw( RuntimeException, std::exception )
168 return impl_getStaticSupportedServiceNames();
171 /* Helper for XServiceInfo */
172 Sequence< OUString > SvtFolderPicker::impl_getStaticSupportedServiceNames()
174 Sequence< OUString > seqServiceNames { "com.sun.star.ui.dialogs.OfficeFolderPicker" };
175 return seqServiceNames ;
178 /* Helper for XServiceInfo */
179 OUString SvtFolderPicker::impl_getStaticImplementationName()
181 return OUString( "com.sun.star.svtools.OfficeFolderPicker" );
184 /* Helper for registry */
185 Reference< XInterface > SAL_CALL SvtFolderPicker::impl_createInstance( const Reference< XComponentContext >& )
186 throw( Exception )
188 return Reference< XInterface >( *new SvtFolderPicker );
191 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */