1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_fpicker.hxx"
30 #include "fpsmartcontent.hxx"
32 /** === begin UNO includes === **/
33 #include <com/sun/star/container/XChild.hpp>
34 #include <com/sun/star/ucb/ContentInfo.hpp>
35 #include <com/sun/star/ucb/ContentInfoAttribute.hpp>
36 #include <com/sun/star/ucb/XContent.hpp>
37 /** === end UNO includes === **/
39 #include <comphelper/processfactory.hxx>
40 #include <ucbhelper/commandenvironment.hxx>
41 #include <tools/solar.h>
42 #include <tools/debug.hxx>
43 #include <tools/string.hxx>
45 //........................................................................
48 //........................................................................
50 using namespace ::com::sun::star::uno
;
51 using namespace ::com::sun::star::task
;
52 using namespace ::com::sun::star::ucb
;
53 using namespace ::com::sun::star::lang
;
54 using namespace ::com::sun::star::container
;
56 //====================================================================
58 //====================================================================
59 //--------------------------------------------------------------------
60 SmartContent::SmartContent()
62 ,m_eState( NOT_BOUND
)
63 ,m_pOwnInteraction( NULL
)
67 //--------------------------------------------------------------------
68 SmartContent::SmartContent( const ::rtl::OUString
& _rInitialURL
)
70 ,m_eState( NOT_BOUND
)
72 bindTo( _rInitialURL
);
75 //--------------------------------------------------------------------
76 SmartContent::~SmartContent()
78 //Do not delete the content. Because the content will be used by the cache.
79 //DELETEZ( m_pContent );
82 //--------------------------------------------------------------------
83 void SmartContent::enableOwnInteractionHandler(::svt::OFilePickerInteractionHandler::EInterceptedInteractions eInterceptions
)
85 Reference
< XMultiServiceFactory
> xFactory
= ::comphelper::getProcessServiceFactory();
86 Reference
< XInteractionHandler
> xGlobalInteractionHandler
= Reference
< XInteractionHandler
>(
87 xFactory
->createInstance( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.task.InteractionHandler") ) ), UNO_QUERY
);
89 m_pOwnInteraction
= new ::svt::OFilePickerInteractionHandler(xGlobalInteractionHandler
);
90 m_pOwnInteraction
->enableInterceptions(eInterceptions
);
91 m_xOwnInteraction
= m_pOwnInteraction
;
93 m_xCmdEnv
= new ::ucbhelper::CommandEnvironment( m_xOwnInteraction
, Reference
< XProgressHandler
>() );
96 //--------------------------------------------------------------------
97 void SmartContent::enableDefaultInteractionHandler()
99 // Don't free the memory here! It will be done by the next
100 // call automaticly - releasing of the uno reference ...
101 m_pOwnInteraction
= NULL
;
102 m_xOwnInteraction
= Reference
< XInteractionHandler
>();
104 Reference
< XMultiServiceFactory
> xFactory
= ::comphelper::getProcessServiceFactory();
105 Reference
< XInteractionHandler
> xGlobalInteractionHandler
= Reference
< XInteractionHandler
>(
106 xFactory
->createInstance( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.task.InteractionHandler") ) ), UNO_QUERY
);
107 m_xCmdEnv
= new ucbhelper::CommandEnvironment( xGlobalInteractionHandler
, Reference
< XProgressHandler
>() );
110 //--------------------------------------------------------------------
111 ::svt::OFilePickerInteractionHandler
* SmartContent::getOwnInteractionHandler() const
113 if (!m_xOwnInteraction
.is())
115 return m_pOwnInteraction
;
118 //--------------------------------------------------------------------
119 SmartContent::InteractionHandlerType
SmartContent::queryCurrentInteractionHandler() const
121 if (m_xOwnInteraction
.is())
130 //--------------------------------------------------------------------
131 void SmartContent::disableInteractionHandler()
133 // Don't free the memory here! It will be done by the next
134 // call automaticly - releasing of the uno reference ...
135 m_pOwnInteraction
= NULL
;
136 m_xOwnInteraction
.clear();
141 //--------------------------------------------------------------------
142 void SmartContent::bindTo( const ::rtl::OUString
& _rURL
)
144 if ( getURL() == _rURL
)
145 // nothing to do, regardless of the state
148 DELETEZ( m_pContent
);
149 m_eState
= INVALID
; // default to INVALID
152 if ( m_sURL
.getLength() )
156 m_pContent
= new ::ucbhelper::Content( _rURL
, m_xCmdEnv
);
158 // from now on, the state is unknown -> we cannot know for sure if the content
159 // is really valid (some UCP's only tell this when asking for properties, not upon
162 catch( ContentCreationException
& )
167 DBG_ERROR( "SmartContent::bindTo: unexpected exception caught!" );
172 m_eState
= NOT_BOUND
;
176 // don't forget to reset the may internal used interaction handler ...
177 // But do it only for our own specialized interaction helper!
178 ::svt::OFilePickerInteractionHandler
* pHandler
= getOwnInteractionHandler();
181 pHandler
->resetUseState();
182 pHandler
->forgetRequest();
186 //--------------------------------------------------------------------
187 sal_Bool
SmartContent::implIs( const ::rtl::OUString
& _rURL
, Type _eType
)
189 // bind to this content
192 // did we survive this?
193 if ( isInvalid() || !isBound() )
196 DBG_ASSERT( m_pContent
, "SmartContent::implIs: inconsistence!" );
197 // if, after an bindTo, we don't have a content, then we should be INVALID, or at least
198 // NOT_BOUND (the latter happens, for example, if somebody tries to ask for an empty URL)
200 sal_Bool bIs
= sal_False
;
203 if ( Folder
== _eType
)
204 bIs
= m_pContent
->isFolder();
206 bIs
= m_pContent
->isDocument();
208 // from here on, we definately know that the content is valid
213 // now we're definately invalid
219 //--------------------------------------------------------------------
220 void SmartContent::getTitle( ::rtl::OUString
& /* [out] */ _rTitle
)
222 if ( !isBound() || isInvalid() )
227 ::rtl::OUString sTitle
;
228 m_pContent
->getPropertyValue( ::rtl::OUString::createFromAscii( "Title" ) ) >>= sTitle
;
231 // from here on, we definately know that the content is valid
234 catch( ::com::sun::star::uno::Exception
& )
236 // now we're definately invalid
241 //--------------------------------------------------------------------
242 sal_Bool
SmartContent::hasParentFolder( )
244 if ( !isBound() || isInvalid() )
247 sal_Bool bRet
= sal_False
;
250 Reference
< XChild
> xChild( m_pContent
->get(), UNO_QUERY
);
253 Reference
< XContent
> xParent( xChild
->getParent(), UNO_QUERY
);
256 String aParentURL
= String( xParent
->getIdentifier()->getContentIdentifier() );
257 bRet
= ( aParentURL
.Len() > 0 && aParentURL
!= (String
)(m_pContent
->getURL()) );
259 // now we're definately valid
264 catch( const Exception
& )
266 // now we're definately invalid
272 //--------------------------------------------------------------------
273 sal_Bool
SmartContent::canCreateFolder( )
275 if ( !isBound() || isInvalid() )
278 sal_Bool bRet
= sal_False
;
281 Sequence
< ContentInfo
> aInfo
= m_pContent
->queryCreatableContentsInfo();
282 const ContentInfo
* pInfo
= aInfo
.getConstArray();
283 sal_Int32 nCount
= aInfo
.getLength();
284 for ( sal_Int32 i
= 0; i
< nCount
; ++i
, ++pInfo
)
286 // Simply look for the first KIND_FOLDER...
287 if ( pInfo
->Attributes
& ContentInfoAttribute::KIND_FOLDER
)
294 // now we're definately valid
299 // now we're definately invalid
305 //........................................................................
307 //........................................................................