Bump version to 24.04.3.4
[LibreOffice.git] / fpicker / source / office / fpsmartcontent.hxx
blobef3329320b85cac32dd72a9278c81d58e1ef5dc1
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 #pragma once
22 #include "fpinteraction.hxx"
24 #include <com/sun/star/ucb/XCommandEnvironment.hpp>
25 #include <ucbhelper/content.hxx>
26 #include <rtl/ref.hxx>
27 #include <memory>
28 #include <optional>
31 namespace svt
35 //= SmartContent
37 /** a "smart content" which basically wraps a 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 a URL, and valid
48 INVALID // bound to a URL, and invalid
51 private:
52 OUString m_sURL;
53 std::optional<::ucbhelper::Content> m_oContent;
54 State m_eState;
55 css::uno::Reference < css::ucb::XCommandEnvironment > m_xCmdEnv;
56 rtl::Reference<::svt::OFilePickerInteractionHandler> m_xOwnInteraction;
58 private:
59 enum Type { Folder, Document };
60 /// checks if the currently bound content is a folder or document
61 bool implIs( const OUString& _rURL, Type _eType );
63 SmartContent( const SmartContent& _rSource ) = delete;
64 SmartContent& operator=( const SmartContent& _rSource ) = delete;
66 public:
67 SmartContent();
68 explicit SmartContent( const OUString& _rInitialURL );
69 ~SmartContent();
71 public:
73 /** create and set a specialized interaction handler at the internal used command environment.
75 @param eInterceptions
76 will be directly forwarded to OFilePickerInteractionHandler::enableInterceptions()
78 void enableOwnInteractionHandler(::svt::OFilePickerInteractionHandler::EInterceptedInteractions eInterceptions);
80 /** disable the specialized interaction handler and use the global UI interaction handler only.
82 void enableDefaultInteractionHandler();
84 /** return the internal used interaction handler object ...
85 Because this pointer will be valid only, if the uno object is hold
86 alive by its uno reference (and this reference is set on the
87 command environment) we must return NULL, in case this environment does
88 not exist!
90 ::svt::OFilePickerInteractionHandler* getOwnInteractionHandler() const;
92 /** describes different types of interaction handlers
94 enum InteractionHandlerType
96 IHT_NONE,
97 IHT_OWN,
98 IHT_DEFAULT
101 /** return the type of the internal used interaction handler object ...
103 @seealso InteractionHandlerType
105 InteractionHandlerType queryCurrentInteractionHandler() const;
107 /** disable internal used interaction handler object ...
109 void disableInteractionHandler();
111 /** returns the current state of the content
113 @seealso State
115 State getState( ) const { return m_eState; }
117 /** checks if the content is valid
118 <p>Note that "not (is valid)" is not the same as "is invalid"</p>
120 bool isValid( ) const { return VALID == getState(); }
122 /** checks if the content is valid
123 <p>Note that "not (is invalid)" is not the same as "is valid"</p>
125 bool isInvalid( ) const { return INVALID == getState(); }
127 /** checks if the content is bound
129 bool isBound( ) const { return NOT_BOUND != getState(); }
131 /** returns the URL of the content
133 OUString const & getURL() const { return m_oContent ? m_oContent->getURL() : m_sURL; }
135 /** (re)creates the content for the given URL
137 <p>Note that getState will return either UNKNOWN or INVALID after the call returns,
138 but never VALID. The reason is that there are content providers which allow to construct
139 content objects, even if the respective contents are not accessible. They tell about this
140 only upon working with the content object (e.g. when asking for the IsFolder).</p>
142 @postcond
143 <member>getState</member> does not return NOT_BOUND after the call returns
145 void bindTo( const OUString& _rURL );
147 /** retrieves the title of the content
148 @precond
149 the content is bound and not invalid
151 void getTitle( OUString& /* [out] */ _rTitle );
153 /** checks if the content has a parent folder
154 @precond
155 the content is bound and not invalid
157 bool hasParentFolder( );
159 /** checks if sub folders below the content can be created
160 @precond
161 the content is bound and not invalid
163 bool canCreateFolder( );
165 /** creates a new folder with the given title and return the corresponding URL.
167 @return
168 the URL of the created folder or an empty string
170 OUString createFolder( const OUString& _rTitle );
172 /** binds to the given URL, checks whether or not it refers to a folder
174 @postcond
175 the content is not in the state UNKNOWN
177 bool isFolder( const OUString& _rURL )
179 return implIs( _rURL, Folder );
182 /** checks if the content is existent (it is if and only if it is a document or a folder)
184 bool is( const OUString& _rURL )
186 return implIs( _rURL, Folder ) || implIs( _rURL, Document );
189 bool isFolder( ) { return isFolder( getURL() ); }
193 } // namespace svt
196 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */