update credits
[LibreOffice.git] / fpicker / source / office / fpsmartcontent.hxx
blob07c5d0393b0dbd83a45d2c1d26046feab3d0a53b
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef SVTOOLS_SOURCE_FILEPICKER_FPSMARTCONTENT_HXX
21 #define SVTOOLS_SOURCE_FILEPICKER_FPSMARTCONTENT_HXX
23 #include "fpinteraction.hxx"
25 #include <com/sun/star/ucb/XCommandEnvironment.hpp>
26 #include <com/sun/star/task/XInteractionHandler.hpp>
27 #include <ucbhelper/content.hxx>
29 //........................................................................
30 namespace svt
32 //........................................................................
34 //====================================================================
35 //= SmartContent
36 //====================================================================
37 /** a "smart content" which basically wraps an UCB content, but caches some information
38 so that repeatedly recreating it may be faster
40 class SmartContent
42 public:
43 enum State
45 NOT_BOUND, // never bound
46 UNKNOWN, // bound, but validity is unknown
47 VALID, // bound to an URL, and valid
48 INVALID // bound to an URL, and invalid
51 private:
52 OUString m_sURL;
53 ::ucbhelper::Content* m_pContent;
54 State m_eState;
55 ::com::sun::star::uno::Reference < ::com::sun::star::ucb::XCommandEnvironment > m_xCmdEnv;
56 ::com::sun::star::uno::Reference < ::com::sun::star::task::XInteractionHandler > m_xOwnInteraction;
57 ::svt::OFilePickerInteractionHandler* m_pOwnInteraction;
59 private:
60 enum Type { Folder, Document };
61 /// checks if the currently bound content is a folder or document
62 sal_Bool implIs( const OUString& _rURL, Type _eType );
64 SmartContent( const SmartContent& _rSource ); // never implemented
65 SmartContent& operator=( const SmartContent& _rSource ); // never implemented
67 public:
68 SmartContent();
69 SmartContent( const OUString& _rInitialURL );
70 ~SmartContent();
72 public:
74 /** create and set a specialized interaction handler at the internal used command environment.
76 @param eInterceptions
77 will be directly forwarded to OFilePickerInteractionHandler::enableInterceptions()
79 void enableOwnInteractionHandler(::svt::OFilePickerInteractionHandler::EInterceptedInteractions eInterceptions);
81 /** disable the specialized interaction handler and use the global UI interaction handler only.
83 void enableDefaultInteractionHandler();
85 /** return the internal used interaction handler object ...
86 Because this pointer will be valid only, if the uno object is hold
87 alive by it's uno reference (and this reference is set on the
88 command environment) we must return NULL, in case this environment does
89 not exist!
91 ::svt::OFilePickerInteractionHandler* getOwnInteractionHandler() const;
93 /** describes different types of interaction handlers
95 enum InteractionHandlerType
97 IHT_NONE,
98 IHT_OWN,
99 IHT_DEFAULT
102 /** return the type of the internal used interaction handler object ...
104 @seealso InteractionHandlerType
106 InteractionHandlerType queryCurrentInteractionHandler() const;
108 /** disable internal used interaction handler object ...
110 void disableInteractionHandler();
112 /** returns the current state of the content
114 @seealso State
116 inline State getState( ) const { return m_eState; }
118 /** checks if the content is valid
119 <p>Note that "not (is valid)" is not the same as "is invalid"</p>
121 inline sal_Bool isValid( ) const { return VALID == getState(); }
123 /** checks if the content is valid
124 <p>Note that "not (is invalid)" is not the same as "is valid"</p>
126 inline sal_Bool isInvalid( ) const { return INVALID == getState(); }
128 /** checks if the content is bound
130 inline sal_Bool isBound( ) const { return NOT_BOUND != getState(); }
132 /** returns the URL of the content
134 inline OUString getURL() const { return m_pContent ? m_pContent->getURL() : m_sURL; }
136 /** (re)creates the content for the given URL
138 <p>Note that getState will return either UNKNOWN or INVALID after the call returns,
139 but never VALID. The reason is that there are content providers which allow to construct
140 content objects, even if the respective contents are not accessible. They tell about this
141 only upon working with the content object (e.g. when asking for the IsFolder).</p>
143 @postcond
144 <member>getState</member> does not return NOT_BOUND after the call returns
146 void bindTo( const OUString& _rURL );
148 /** retrieves the title of the content
149 @precond
150 the content is bound and not invalid
152 void getTitle( OUString& /* [out] */ _rTitle );
154 /** checks if the content has a parent folder
155 @precond
156 the content is bound and not invalid
158 sal_Bool hasParentFolder( );
160 /** checks if sub folders below the content can be created
161 @precond
162 the content is bound and not invalid
164 sal_Bool canCreateFolder( );
166 /** creates a new folder with the given title and return the corresponding URL.
168 @return
169 the URL of the created folder or an empty string
171 OUString createFolder( const OUString& _rTitle );
173 /** binds to the given URL, checks whether or not it refers to a folder
175 @postcond
176 the content is not in the state UNKNOWN
178 inline sal_Bool isFolder( const OUString& _rURL )
180 return implIs( _rURL, Folder );
183 /** binds to the given URL, checks whether or not it refers to a document
185 @postcond
186 the content is not in the state UNKNOWN
188 inline sal_Bool isDocument( const OUString& _rURL )
190 return implIs( _rURL, Document );
193 /** checks if the content is existent (it is if and only if it is a document or a folder)
195 inline sal_Bool is( const OUString& _rURL )
197 return implIs( _rURL, Folder ) || implIs( _rURL, Document );
200 inline sal_Bool isFolder( ) { return isFolder( getURL() ); }
201 inline sal_Bool isDocument( ) { return isDocument( getURL() ); }
202 inline sal_Bool is( ) { return is( getURL() ); }
205 //........................................................................
206 } // namespace svt
207 //........................................................................
209 #endif // SVTOOLS_SOURCE_FILEPICKER_FPSMARTCONTENT_HXX
211 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */