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