1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir #ifndef SVTOOLS_SOURCE_FILEPICKER_FPSMARTCONTENT_HXX
29*cdf0e10cSrcweir #define SVTOOLS_SOURCE_FILEPICKER_FPSMARTCONTENT_HXX
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include "fpinteraction.hxx"
32*cdf0e10cSrcweir 
33*cdf0e10cSrcweir /** === begin UNO includes === **/
34*cdf0e10cSrcweir #include <com/sun/star/ucb/XCommandEnvironment.hpp>
35*cdf0e10cSrcweir #include <com/sun/star/task/XInteractionHandler.hpp>
36*cdf0e10cSrcweir /** === end UNO includes === **/
37*cdf0e10cSrcweir #include <ucbhelper/content.hxx>
38*cdf0e10cSrcweir 
39*cdf0e10cSrcweir //........................................................................
40*cdf0e10cSrcweir namespace svt
41*cdf0e10cSrcweir {
42*cdf0e10cSrcweir //........................................................................
43*cdf0e10cSrcweir 
44*cdf0e10cSrcweir     //====================================================================
45*cdf0e10cSrcweir     //= SmartContent
46*cdf0e10cSrcweir     //====================================================================
47*cdf0e10cSrcweir     /** a "smart content" which basically wraps an UCB content, but caches some informations
48*cdf0e10cSrcweir         so that repeatedly recreating it may be faster
49*cdf0e10cSrcweir     */
50*cdf0e10cSrcweir     class SmartContent
51*cdf0e10cSrcweir     {
52*cdf0e10cSrcweir     public:
53*cdf0e10cSrcweir         enum State
54*cdf0e10cSrcweir         {
55*cdf0e10cSrcweir             NOT_BOUND,  // never bound
56*cdf0e10cSrcweir             UNKNOWN,    // bound, but validity is unknown
57*cdf0e10cSrcweir             VALID,      // bound to an URL, and valid
58*cdf0e10cSrcweir             INVALID     // bound to an URL, and invalid
59*cdf0e10cSrcweir         };
60*cdf0e10cSrcweir 
61*cdf0e10cSrcweir     private:
62*cdf0e10cSrcweir         ::rtl::OUString                                                                  m_sURL;
63*cdf0e10cSrcweir         ::ucbhelper::Content*                                                                  m_pContent;
64*cdf0e10cSrcweir         State                                                                            m_eState;
65*cdf0e10cSrcweir         ::com::sun::star::uno::Reference < ::com::sun::star::ucb::XCommandEnvironment >  m_xCmdEnv;
66*cdf0e10cSrcweir         ::com::sun::star::uno::Reference < ::com::sun::star::task::XInteractionHandler > m_xOwnInteraction;
67*cdf0e10cSrcweir         ::svt::OFilePickerInteractionHandler*                                            m_pOwnInteraction;
68*cdf0e10cSrcweir 
69*cdf0e10cSrcweir     private:
70*cdf0e10cSrcweir         enum Type { Folder, Document };
71*cdf0e10cSrcweir         /// checks if the currently bound content is a folder or document
72*cdf0e10cSrcweir         sal_Bool implIs( const ::rtl::OUString& _rURL, Type _eType );
73*cdf0e10cSrcweir 
74*cdf0e10cSrcweir         SmartContent( const SmartContent& _rSource );               // never implemented
75*cdf0e10cSrcweir         SmartContent& operator=( const SmartContent& _rSource );    // never implemented
76*cdf0e10cSrcweir 
77*cdf0e10cSrcweir     public:
78*cdf0e10cSrcweir         SmartContent();
79*cdf0e10cSrcweir         SmartContent( const ::rtl::OUString& _rInitialURL );
80*cdf0e10cSrcweir         ~SmartContent();
81*cdf0e10cSrcweir 
82*cdf0e10cSrcweir     public:
83*cdf0e10cSrcweir 
84*cdf0e10cSrcweir         /** create and set a specialized interaction handler at the internal used command environment.
85*cdf0e10cSrcweir 
86*cdf0e10cSrcweir             @param eInterceptions
87*cdf0e10cSrcweir                     will be directly forwarded to OFilePickerInteractionHandler::enableInterceptions()
88*cdf0e10cSrcweir         */
89*cdf0e10cSrcweir         void enableOwnInteractionHandler(::svt::OFilePickerInteractionHandler::EInterceptedInteractions eInterceptions);
90*cdf0e10cSrcweir 
91*cdf0e10cSrcweir         /** disable the specialized interaction handler and use the global UI interaction handler only.
92*cdf0e10cSrcweir         */
93*cdf0e10cSrcweir         void enableDefaultInteractionHandler();
94*cdf0e10cSrcweir 
95*cdf0e10cSrcweir         /** return the internal used interaction handler object ...
96*cdf0e10cSrcweir             Because this pointer will be valid only, if the uno object is hold
97*cdf0e10cSrcweir             alive by it's uno reference (and this reference is set on the
98*cdf0e10cSrcweir             command environment) we must return NULL, in case this environment does
99*cdf0e10cSrcweir             not exist!
100*cdf0e10cSrcweir         */
101*cdf0e10cSrcweir         ::svt::OFilePickerInteractionHandler* getOwnInteractionHandler() const;
102*cdf0e10cSrcweir 
103*cdf0e10cSrcweir         /** describes different types of interaction handlers
104*cdf0e10cSrcweir          */
105*cdf0e10cSrcweir         enum InteractionHandlerType
106*cdf0e10cSrcweir         {
107*cdf0e10cSrcweir             IHT_NONE,
108*cdf0e10cSrcweir             IHT_OWN,
109*cdf0e10cSrcweir             IHT_DEFAULT
110*cdf0e10cSrcweir         };
111*cdf0e10cSrcweir 
112*cdf0e10cSrcweir         /** return the type of the internal used interaction handler object ...
113*cdf0e10cSrcweir 
114*cdf0e10cSrcweir             @seealso InteractionHandlerType
115*cdf0e10cSrcweir         */
116*cdf0e10cSrcweir         InteractionHandlerType queryCurrentInteractionHandler() const;
117*cdf0e10cSrcweir 
118*cdf0e10cSrcweir         /** disable internal used interaction handler object ...
119*cdf0e10cSrcweir          */
120*cdf0e10cSrcweir         void disableInteractionHandler();
121*cdf0e10cSrcweir 
122*cdf0e10cSrcweir         /** returns the current state of the content
123*cdf0e10cSrcweir 
124*cdf0e10cSrcweir             @seealso State
125*cdf0e10cSrcweir         */
126*cdf0e10cSrcweir         inline  State       getState( ) const { return m_eState; }
127*cdf0e10cSrcweir 
128*cdf0e10cSrcweir         /** checks if the content is valid
129*cdf0e10cSrcweir             <p>Note that "not (is valid)" is not the same as "is invalid"</p>
130*cdf0e10cSrcweir         */
131*cdf0e10cSrcweir         inline  sal_Bool    isValid( ) const { return VALID == getState(); }
132*cdf0e10cSrcweir 
133*cdf0e10cSrcweir         /** checks if the content is valid
134*cdf0e10cSrcweir             <p>Note that "not (is invalid)" is not the same as "is valid"</p>
135*cdf0e10cSrcweir         */
136*cdf0e10cSrcweir         inline  sal_Bool    isInvalid( ) const { return INVALID == getState(); }
137*cdf0e10cSrcweir 
138*cdf0e10cSrcweir         /** checks if the content is bound
139*cdf0e10cSrcweir         */
140*cdf0e10cSrcweir         inline  sal_Bool    isBound( ) const { return NOT_BOUND != getState(); }
141*cdf0e10cSrcweir 
142*cdf0e10cSrcweir         /** returns the URL of the content
143*cdf0e10cSrcweir         */
144*cdf0e10cSrcweir         inline ::rtl::OUString  getURL() const { return m_pContent ? m_pContent->getURL() : m_sURL; }
145*cdf0e10cSrcweir 
146*cdf0e10cSrcweir         /** (re)creates the content for the given URL
147*cdf0e10cSrcweir 
148*cdf0e10cSrcweir             <p>Note that getState will return either UNKNOWN or INVALID after the call returns,
149*cdf0e10cSrcweir             but never VALID. The reason is that there are content providers which allow to construct
150*cdf0e10cSrcweir             content objects, even if the respective contents are not accessible. They tell about this
151*cdf0e10cSrcweir             only upon working with the content object (e.g. when asking for the IsFolder).</p>
152*cdf0e10cSrcweir 
153*cdf0e10cSrcweir             @postcond
154*cdf0e10cSrcweir                 <member>getState</member> does not return NOT_BOUND after the call returns
155*cdf0e10cSrcweir         */
156*cdf0e10cSrcweir         void    bindTo( const ::rtl::OUString& _rURL );
157*cdf0e10cSrcweir 
158*cdf0e10cSrcweir         /** retrieves the title of the content
159*cdf0e10cSrcweir             @precond
160*cdf0e10cSrcweir                 the content is bound and not invalid
161*cdf0e10cSrcweir         */
162*cdf0e10cSrcweir         void    getTitle( ::rtl::OUString& /* [out] */ _rTitle );
163*cdf0e10cSrcweir 
164*cdf0e10cSrcweir         /** checks if the content has a parent folder
165*cdf0e10cSrcweir             @precond
166*cdf0e10cSrcweir                 the content is bound and not invalid
167*cdf0e10cSrcweir         */
168*cdf0e10cSrcweir         sal_Bool    hasParentFolder( );
169*cdf0e10cSrcweir 
170*cdf0e10cSrcweir         /** checks if sub folders below the content can be created
171*cdf0e10cSrcweir             @precond
172*cdf0e10cSrcweir                 the content is bound and not invalid
173*cdf0e10cSrcweir         */
174*cdf0e10cSrcweir         sal_Bool    canCreateFolder( );
175*cdf0e10cSrcweir 
176*cdf0e10cSrcweir         /** binds to the given URL, checks whether or not it refers to a folder
177*cdf0e10cSrcweir 
178*cdf0e10cSrcweir             @postcond
179*cdf0e10cSrcweir                 the content is not in the state UNKNOWN
180*cdf0e10cSrcweir         */
181*cdf0e10cSrcweir         inline  sal_Bool    isFolder( const ::rtl::OUString& _rURL )
182*cdf0e10cSrcweir         {
183*cdf0e10cSrcweir             return implIs( _rURL, Folder );
184*cdf0e10cSrcweir         }
185*cdf0e10cSrcweir 
186*cdf0e10cSrcweir         /** binds to the given URL, checks whether or not it refers to a document
187*cdf0e10cSrcweir 
188*cdf0e10cSrcweir             @postcond
189*cdf0e10cSrcweir                 the content is not in the state UNKNOWN
190*cdf0e10cSrcweir         */
191*cdf0e10cSrcweir         inline  sal_Bool    isDocument(  const ::rtl::OUString& _rURL )
192*cdf0e10cSrcweir         {
193*cdf0e10cSrcweir             return implIs( _rURL, Document );
194*cdf0e10cSrcweir         }
195*cdf0e10cSrcweir 
196*cdf0e10cSrcweir         /** checks if the content is existent (it is if and only if it is a document or a folder)
197*cdf0e10cSrcweir         */
198*cdf0e10cSrcweir         inline  sal_Bool    is( const ::rtl::OUString& _rURL )
199*cdf0e10cSrcweir         {
200*cdf0e10cSrcweir             return  implIs( _rURL, Folder ) || implIs( _rURL, Document );
201*cdf0e10cSrcweir         }
202*cdf0e10cSrcweir 
203*cdf0e10cSrcweir         inline  sal_Bool    isFolder( )     { return isFolder( getURL() ); }
204*cdf0e10cSrcweir         inline  sal_Bool    isDocument( )   { return isDocument( getURL() ); }
205*cdf0e10cSrcweir         inline  sal_Bool    is( )           { return is( getURL() ); }
206*cdf0e10cSrcweir     };
207*cdf0e10cSrcweir 
208*cdf0e10cSrcweir //........................................................................
209*cdf0e10cSrcweir } // namespace svt
210*cdf0e10cSrcweir //........................................................................
211*cdf0e10cSrcweir 
212*cdf0e10cSrcweir #endif // SVTOOLS_SOURCE_FILEPICKER_FPSMARTCONTENT_HXX
213