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