1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: fpsmartcontent.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_fpicker.hxx"
33 #include "fpsmartcontent.hxx"
35 /** === begin UNO includes === **/
36 #include <com/sun/star/ucb/XContentCreator.hpp>
37 #include <com/sun/star/container/XChild.hpp>
38 #include <com/sun/star/ucb/ContentInfoAttribute.hpp>
39 /** === end UNO includes === **/
41 #ifndef _UNOTOOLS_PROCESSFACTORY_HXX
42 #include <comphelper/processfactory.hxx>
44 #include <ucbhelper/commandenvironment.hxx>
45 #include <tools/solar.h>
46 #include <tools/debug.hxx>
47 #include <tools/string.hxx>
49 //........................................................................
52 //........................................................................
54 using namespace ::com::sun::star::uno
;
55 using namespace ::com::sun::star::task
;
56 using namespace ::com::sun::star::ucb
;
57 using namespace ::com::sun::star::lang
;
58 using namespace ::com::sun::star::container
;
60 //====================================================================
62 //====================================================================
63 //--------------------------------------------------------------------
64 SmartContent::SmartContent()
66 ,m_eState( NOT_BOUND
)
67 ,m_pOwnInteraction( NULL
)
71 //--------------------------------------------------------------------
72 SmartContent::SmartContent( const ::rtl::OUString
& _rInitialURL
)
74 ,m_eState( NOT_BOUND
)
76 bindTo( _rInitialURL
);
79 //--------------------------------------------------------------------
80 SmartContent::~SmartContent()
82 //Do not delete the content. Because the content will be used by the cache.
83 //DELETEZ( m_pContent );
86 //--------------------------------------------------------------------
87 void SmartContent::enableOwnInteractionHandler(::svt::OFilePickerInteractionHandler::EInterceptedInteractions eInterceptions
)
89 Reference
< XMultiServiceFactory
> xFactory
= ::comphelper::getProcessServiceFactory();
90 Reference
< XInteractionHandler
> xGlobalInteractionHandler
= Reference
< XInteractionHandler
>(
91 xFactory
->createInstance( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.task.InteractionHandler") ) ), UNO_QUERY
);
93 m_pOwnInteraction
= new ::svt::OFilePickerInteractionHandler(xGlobalInteractionHandler
);
94 m_pOwnInteraction
->enableInterceptions(eInterceptions
);
95 m_xOwnInteraction
= m_pOwnInteraction
;
97 m_xCmdEnv
= new ::ucbhelper::CommandEnvironment( m_xOwnInteraction
, Reference
< XProgressHandler
>() );
100 //--------------------------------------------------------------------
101 void SmartContent::enableDefaultInteractionHandler()
103 // Don't free the memory here! It will be done by the next
104 // call automaticly - releasing of the uno reference ...
105 m_pOwnInteraction
= NULL
;
106 m_xOwnInteraction
= Reference
< XInteractionHandler
>();
108 Reference
< XMultiServiceFactory
> xFactory
= ::comphelper::getProcessServiceFactory();
109 Reference
< XInteractionHandler
> xGlobalInteractionHandler
= Reference
< XInteractionHandler
>(
110 xFactory
->createInstance( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.task.InteractionHandler") ) ), UNO_QUERY
);
111 m_xCmdEnv
= new ucbhelper::CommandEnvironment( xGlobalInteractionHandler
, Reference
< XProgressHandler
>() );
114 //--------------------------------------------------------------------
115 ::svt::OFilePickerInteractionHandler
* SmartContent::getOwnInteractionHandler() const
117 if (!m_xOwnInteraction
.is())
119 return m_pOwnInteraction
;
122 //--------------------------------------------------------------------
123 SmartContent::InteractionHandlerType
SmartContent::queryCurrentInteractionHandler() const
125 if (m_xOwnInteraction
.is())
134 //--------------------------------------------------------------------
135 void SmartContent::disableInteractionHandler()
137 // Don't free the memory here! It will be done by the next
138 // call automaticly - releasing of the uno reference ...
139 m_pOwnInteraction
= NULL
;
140 m_xOwnInteraction
.clear();
145 //--------------------------------------------------------------------
146 void SmartContent::bindTo( const ::rtl::OUString
& _rURL
)
148 if ( getURL() == _rURL
)
149 // nothing to do, regardless of the state
152 DELETEZ( m_pContent
);
153 m_eState
= INVALID
; // default to INVALID
156 if ( m_sURL
.getLength() )
160 m_pContent
= new ::ucbhelper::Content( _rURL
, m_xCmdEnv
);
162 // from now on, the state is unknown -> we cannot know for sure if the content
163 // is really valid (some UCP's only tell this when asking for properties, not upon
166 catch( ContentCreationException
& )
171 DBG_ERROR( "SmartContent::bindTo: unexpected exception caught!" );
176 m_eState
= NOT_BOUND
;
180 // don't forget to reset the may internal used interaction handler ...
181 // But do it only for our own specialized interaction helper!
182 ::svt::OFilePickerInteractionHandler
* pHandler
= getOwnInteractionHandler();
185 pHandler
->resetUseState();
186 pHandler
->forgetRequest();
190 //--------------------------------------------------------------------
191 sal_Bool
SmartContent::implIs( const ::rtl::OUString
& _rURL
, Type _eType
)
193 // bind to this content
196 // did we survive this?
197 if ( isInvalid() || !isBound() )
200 DBG_ASSERT( m_pContent
, "SmartContent::implIs: inconsistence!" );
201 // if, after an bindTo, we don't have a content, then we should be INVALID, or at least
202 // NOT_BOUND (the latter happens, for example, if somebody tries to ask for an empty URL)
204 sal_Bool bIs
= sal_False
;
207 if ( Folder
== _eType
)
208 bIs
= m_pContent
->isFolder();
210 bIs
= m_pContent
->isDocument();
212 // from here on, we definately know that the content is valid
217 // now we're definately invalid
223 //--------------------------------------------------------------------
224 void SmartContent::getTitle( ::rtl::OUString
& /* [out] */ _rTitle
)
226 if ( !isBound() || isInvalid() )
231 ::rtl::OUString sTitle
;
232 m_pContent
->getPropertyValue( ::rtl::OUString::createFromAscii( "Title" ) ) >>= sTitle
;
235 // from here on, we definately know that the content is valid
238 catch( ::com::sun::star::uno::Exception
& )
240 // now we're definately invalid
245 //--------------------------------------------------------------------
246 sal_Bool
SmartContent::hasParentFolder( )
248 if ( !isBound() || isInvalid() )
251 sal_Bool bRet
= sal_False
;
254 Reference
< XChild
> xChild( m_pContent
->get(), UNO_QUERY
);
257 Reference
< XContent
> xParent( xChild
->getParent(), UNO_QUERY
);
260 String aParentURL
= String( xParent
->getIdentifier()->getContentIdentifier() );
261 bRet
= ( aParentURL
.Len() > 0 && aParentURL
!= (String
)(m_pContent
->getURL()) );
263 // now we're definately valid
268 catch( const Exception
& )
270 // now we're definately invalid
276 //--------------------------------------------------------------------
277 sal_Bool
SmartContent::canCreateFolder( )
279 if ( !isBound() || isInvalid() )
282 sal_Bool bRet
= sal_False
;
285 Reference
< XContentCreator
> xCreator
= Reference
< XContentCreator
>( m_pContent
->get(), UNO_QUERY
);
288 Sequence
< ContentInfo
> aInfo
= xCreator
->queryCreatableContentsInfo();
289 const ContentInfo
* pInfo
= aInfo
.getConstArray();
290 sal_Int32 nCount
= aInfo
.getLength();
291 for ( sal_Int32 i
= 0; i
< nCount
; ++i
, ++pInfo
)
293 // Simply look for the first KIND_FOLDER...
294 if ( pInfo
->Attributes
& ContentInfoAttribute::KIND_FOLDER
)
301 // now we're definately valid
307 // now we're definately invalid
313 //........................................................................
315 //........................................................................