1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 #include <com/sun/star/ucb/NameClashResolveRequest.hpp>
21 #include <com/sun/star/ucb/XInteractionSupplyName.hpp>
22 #include <cppuhelper/typeprovider.hxx>
23 #include <cppuhelper/queryinterface.hxx>
24 #include <ucbhelper/simplenameclashresolverequest.hxx>
26 using namespace com::sun::star
;
31 * This class implements a standard interaction continuation, namely the
32 * interface XInteractionSupplyName. Instances of this class can be passed
33 * along with an interaction request to indicate the possibility to
36 class InteractionSupplyName
: public InteractionContinuation
,
37 public com::sun::star::lang::XTypeProvider
,
38 public com::sun::star::ucb::XInteractionSupplyName
43 InteractionSupplyName( InteractionRequest
* pRequest
)
44 : InteractionContinuation( pRequest
) {}
47 virtual com::sun::star::uno::Any SAL_CALL
48 queryInterface( const com::sun::star::uno::Type
& rType
)
49 throw( com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
50 virtual void SAL_CALL
acquire()
52 virtual void SAL_CALL
release()
56 virtual com::sun::star::uno::Sequence
< com::sun::star::uno::Type
> SAL_CALL
58 throw( com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
59 virtual com::sun::star::uno::Sequence
< sal_Int8
> SAL_CALL
61 throw( com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
63 // XInteractionContinuation
64 virtual void SAL_CALL
select()
65 throw( com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
67 // XInteractionSupplyName
68 virtual void SAL_CALL
setName( const OUString
& Name
)
69 throw ( com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
71 // Non-interface methods.
74 * This method returns the name that was supplied by the interaction
79 const OUString
& getName() const { return m_aName
; }
82 void SAL_CALL
InteractionSupplyName::acquire()
85 OWeakObject::acquire();
88 void SAL_CALL
InteractionSupplyName::release()
91 OWeakObject::release();
95 InteractionSupplyName::queryInterface( const uno::Type
& rType
)
96 throw ( uno::RuntimeException
, std::exception
)
98 uno::Any aRet
= cppu::queryInterface( rType
,
99 static_cast< lang::XTypeProvider
* >( this ),
100 static_cast< task::XInteractionContinuation
* >( this ),
101 static_cast< ucb::XInteractionSupplyName
* >( this ) );
103 return aRet
.hasValue()
104 ? aRet
: InteractionContinuation::queryInterface( rType
);
107 uno::Sequence
< sal_Int8
> SAL_CALL
InteractionSupplyName::getImplementationId()
108 throw( uno::RuntimeException
, std::exception
)
110 return css::uno::Sequence
<sal_Int8
>();
113 uno::Sequence
< uno::Type
> SAL_CALL
InteractionSupplyName::getTypes()
114 throw( uno::RuntimeException
, std::exception
)
116 static cppu::OTypeCollection
* pCollection
= 0;
119 osl::Guard
< osl::Mutex
> aGuard( osl::Mutex::getGlobalMutex() );
122 static cppu::OTypeCollection
collection(
123 cppu::UnoType
<lang::XTypeProvider
>::get(),
124 cppu::UnoType
<ucb::XInteractionSupplyName
>::get() );
125 pCollection
= &collection
;
128 return (*pCollection
).getTypes();
131 void SAL_CALL
InteractionSupplyName::select()
132 throw( uno::RuntimeException
, std::exception
)
138 InteractionSupplyName::setName( const OUString
& Name
)
139 throw( uno::RuntimeException
, std::exception
)
144 SimpleNameClashResolveRequest::~SimpleNameClashResolveRequest() {}
146 SimpleNameClashResolveRequest::SimpleNameClashResolveRequest(
147 const OUString
& rTargetFolderURL
,
148 const OUString
& rClashingName
,
149 const OUString
& rProposedNewName
,
150 bool bSupportsOverwriteData
)
153 ucb::NameClashResolveRequest aRequest
;
154 // aRequest.Message = // OUString
155 // aRequest.Context = // XInterface
156 aRequest
.Classification
= task::InteractionClassification_QUERY
;
157 aRequest
.TargetFolderURL
= rTargetFolderURL
;
158 aRequest
.ClashingName
= rClashingName
;
159 aRequest
.ProposedNewName
= rProposedNewName
;
161 setRequest( uno::makeAny( aRequest
) );
163 // Fill continuations...
164 m_xNameSupplier
= new InteractionSupplyName( this );
166 uno::Sequence
< uno::Reference
< task::XInteractionContinuation
> >
167 aContinuations( bSupportsOverwriteData
? 3 : 2 );
168 aContinuations
[ 0 ] = new InteractionAbort( this );
169 aContinuations
[ 1 ] = m_xNameSupplier
.get();
171 if ( bSupportsOverwriteData
)
172 aContinuations
[ 2 ] = new InteractionReplaceExistingData( this );
174 setContinuations( aContinuations
);
177 const OUString
SimpleNameClashResolveRequest::getNewName() const
179 return m_xNameSupplier
->getName();
184 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */