1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
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>
25
26 using namespace com::sun::star;
27
28 namespace ucbhelper {
29
30 /**
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
34 * supply a new name.
35 */
36 class InteractionSupplyName : public InteractionContinuation,
37 public css::lang::XTypeProvider,
38 public css::ucb::XInteractionSupplyName
39 {
40 OUString m_aName;
41
42 public:
InteractionSupplyName(InteractionRequest * pRequest)43 explicit InteractionSupplyName( InteractionRequest * pRequest )
44 : InteractionContinuation( pRequest ) {}
45
46 // XInterface
47 virtual css::uno::Any SAL_CALL
48 queryInterface( const css::uno::Type & rType ) override;
49 virtual void SAL_CALL acquire()
50 throw() override;
51 virtual void SAL_CALL release()
52 throw() override;
53
54 // XTypeProvider
55 virtual css::uno::Sequence< css::uno::Type > SAL_CALL
56 getTypes() override;
57 virtual css::uno::Sequence< sal_Int8 > SAL_CALL
58 getImplementationId() override;
59
60 // XInteractionContinuation
61 virtual void SAL_CALL select() override;
62
63 // XInteractionSupplyName
64 virtual void SAL_CALL setName( const OUString& Name ) override;
65
66 // Non-interface methods.
67
68 /**
69 * This method returns the name that was supplied by the interaction
70 * handler.
71 *
72 * @return the name.
73 */
getName() const74 const OUString & getName() const { return m_aName; }
75 };
76
acquire()77 void SAL_CALL InteractionSupplyName::acquire()
78 throw()
79 {
80 OWeakObject::acquire();
81 }
82
release()83 void SAL_CALL InteractionSupplyName::release()
84 throw()
85 {
86 OWeakObject::release();
87 }
88
89 uno::Any SAL_CALL
queryInterface(const uno::Type & rType)90 InteractionSupplyName::queryInterface( const uno::Type & rType )
91 {
92 uno::Any aRet = cppu::queryInterface( rType,
93 static_cast< lang::XTypeProvider * >( this ),
94 static_cast< task::XInteractionContinuation * >( this ),
95 static_cast< ucb::XInteractionSupplyName * >( this ) );
96
97 return aRet.hasValue()
98 ? aRet : InteractionContinuation::queryInterface( rType );
99 }
100
getImplementationId()101 uno::Sequence< sal_Int8 > SAL_CALL InteractionSupplyName::getImplementationId()
102 {
103 return css::uno::Sequence<sal_Int8>();
104 }
105
getTypes()106 uno::Sequence< uno::Type > SAL_CALL InteractionSupplyName::getTypes()
107 {
108 static cppu::OTypeCollection s_aCollection(
109 cppu::UnoType<lang::XTypeProvider>::get(),
110 cppu::UnoType<ucb::XInteractionSupplyName>::get() );
111
112 return s_aCollection.getTypes();
113 }
114
select()115 void SAL_CALL InteractionSupplyName::select()
116 {
117 recordSelection();
118 }
119
120 void SAL_CALL
setName(const OUString & Name)121 InteractionSupplyName::setName( const OUString& Name )
122 {
123 m_aName = Name;
124 }
125
~SimpleNameClashResolveRequest()126 SimpleNameClashResolveRequest::~SimpleNameClashResolveRequest() {}
127
SimpleNameClashResolveRequest(const OUString & rTargetFolderURL,const OUString & rClashingName)128 SimpleNameClashResolveRequest::SimpleNameClashResolveRequest(
129 const OUString & rTargetFolderURL,
130 const OUString & rClashingName )
131 {
132 // Fill request...
133 ucb::NameClashResolveRequest aRequest;
134 // aRequest.Message = // OUString
135 // aRequest.Context = // XInterface
136 aRequest.Classification = task::InteractionClassification_QUERY;
137 aRequest.TargetFolderURL = rTargetFolderURL;
138 aRequest.ClashingName = rClashingName;
139 aRequest.ProposedNewName = OUString();
140
141 setRequest( uno::makeAny( aRequest ) );
142
143 // Fill continuations...
144 m_xNameSupplier = new InteractionSupplyName( this );
145
146 uno::Sequence< uno::Reference< task::XInteractionContinuation > >
147 aContinuations( 3 );
148 aContinuations[ 0 ] = new InteractionAbort( this );
149 aContinuations[ 1 ] = m_xNameSupplier.get();
150 aContinuations[ 2 ] = new InteractionReplaceExistingData( this );
151
152 setContinuations( aContinuations );
153 }
154
getNewName() const155 OUString const & SimpleNameClashResolveRequest::getNewName() const
156 {
157 return m_xNameSupplier->getName();
158 }
159
160 }
161
162 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
163