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