Line data Source code
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 <ucbhelper/simplenameclashresolverequest.hxx>
24 :
25 : using namespace com::sun::star;
26 :
27 : namespace ucbhelper {
28 :
29 : /**
30 : * This class implements a standard interaction continuation, namely the
31 : * interface XInteractionSupplyName. Instances of this class can be passed
32 : * along with an interaction request to indicate the possibility to
33 : * supply a new name.
34 : */
35 0 : class InteractionSupplyName : public InteractionContinuation,
36 : public com::sun::star::lang::XTypeProvider,
37 : public com::sun::star::ucb::XInteractionSupplyName
38 : {
39 : OUString m_aName;
40 :
41 : public:
42 0 : InteractionSupplyName( InteractionRequest * pRequest )
43 0 : : InteractionContinuation( pRequest ) {}
44 :
45 : // XInterface
46 : virtual com::sun::star::uno::Any SAL_CALL
47 : queryInterface( const com::sun::star::uno::Type & rType )
48 : throw( com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
49 : virtual void SAL_CALL acquire()
50 : throw() SAL_OVERRIDE;
51 : virtual void SAL_CALL release()
52 : throw() SAL_OVERRIDE;
53 :
54 : // XTypeProvider
55 : virtual com::sun::star::uno::Sequence< com::sun::star::uno::Type > SAL_CALL
56 : getTypes()
57 : throw( com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
58 : virtual com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL
59 : getImplementationId()
60 : throw( com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
61 :
62 : // XInteractionContinuation
63 : virtual void SAL_CALL select()
64 : throw( com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
65 :
66 : // XInteractionSupplyName
67 : virtual void SAL_CALL setName( const OUString& Name )
68 : throw ( com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
69 :
70 : // Non-interface methods.
71 :
72 : /**
73 : * This method returns the name that was supplied by the interaction
74 : * handler.
75 : *
76 : * @return the name.
77 : */
78 0 : const OUString & getName() const { return m_aName; }
79 : };
80 :
81 0 : void SAL_CALL InteractionSupplyName::acquire()
82 : throw()
83 : {
84 0 : OWeakObject::acquire();
85 0 : }
86 :
87 0 : void SAL_CALL InteractionSupplyName::release()
88 : throw()
89 : {
90 0 : OWeakObject::release();
91 0 : }
92 :
93 : uno::Any SAL_CALL
94 0 : InteractionSupplyName::queryInterface( const uno::Type & rType )
95 : throw ( uno::RuntimeException, std::exception )
96 : {
97 : uno::Any aRet = cppu::queryInterface( rType,
98 : static_cast< lang::XTypeProvider * >( this ),
99 : static_cast< task::XInteractionContinuation * >( this ),
100 0 : static_cast< ucb::XInteractionSupplyName * >( this ) );
101 :
102 0 : return aRet.hasValue()
103 0 : ? aRet : InteractionContinuation::queryInterface( rType );
104 : }
105 :
106 0 : uno::Sequence< sal_Int8 > SAL_CALL InteractionSupplyName::getImplementationId()
107 : throw( uno::RuntimeException, std::exception )
108 : {
109 0 : return css::uno::Sequence<sal_Int8>();
110 : }
111 :
112 0 : uno::Sequence< uno::Type > SAL_CALL InteractionSupplyName::getTypes()
113 : throw( uno::RuntimeException, std::exception )
114 : {
115 : static cppu::OTypeCollection* pCollection = 0;
116 0 : if ( !pCollection )
117 : {
118 0 : osl::Guard< osl::Mutex > aGuard( osl::Mutex::getGlobalMutex() );
119 0 : if ( !pCollection )
120 : {
121 : static cppu::OTypeCollection collection(
122 0 : cppu::UnoType<lang::XTypeProvider>::get(),
123 0 : cppu::UnoType<ucb::XInteractionSupplyName>::get() );
124 0 : pCollection = &collection;
125 0 : }
126 : }
127 0 : return (*pCollection).getTypes();
128 : }
129 :
130 0 : void SAL_CALL InteractionSupplyName::select()
131 : throw( uno::RuntimeException, std::exception )
132 : {
133 0 : recordSelection();
134 0 : }
135 :
136 : void SAL_CALL
137 0 : InteractionSupplyName::setName( const OUString& Name )
138 : throw( uno::RuntimeException, std::exception )
139 : {
140 0 : m_aName = Name;
141 0 : }
142 :
143 0 : SimpleNameClashResolveRequest::~SimpleNameClashResolveRequest() {}
144 :
145 0 : SimpleNameClashResolveRequest::SimpleNameClashResolveRequest(
146 : const OUString & rTargetFolderURL,
147 : const OUString & rClashingName,
148 : const OUString & rProposedNewName,
149 0 : bool bSupportsOverwriteData )
150 : {
151 : // Fill request...
152 0 : ucb::NameClashResolveRequest aRequest;
153 : // aRequest.Message = // OUString
154 : // aRequest.Context = // XInterface
155 0 : aRequest.Classification = task::InteractionClassification_QUERY;
156 0 : aRequest.TargetFolderURL = rTargetFolderURL;
157 0 : aRequest.ClashingName = rClashingName;
158 0 : aRequest.ProposedNewName = rProposedNewName;
159 :
160 0 : setRequest( uno::makeAny( aRequest ) );
161 :
162 : // Fill continuations...
163 0 : m_xNameSupplier = new InteractionSupplyName( this );
164 :
165 : uno::Sequence< uno::Reference< task::XInteractionContinuation > >
166 0 : aContinuations( bSupportsOverwriteData ? 3 : 2 );
167 0 : aContinuations[ 0 ] = new InteractionAbort( this );
168 0 : aContinuations[ 1 ] = m_xNameSupplier.get();
169 :
170 0 : if ( bSupportsOverwriteData )
171 0 : aContinuations[ 2 ] = new InteractionReplaceExistingData( this );
172 :
173 0 : setContinuations( aContinuations );
174 0 : }
175 :
176 0 : const OUString SimpleNameClashResolveRequest::getNewName() const
177 : {
178 0 : return m_xNameSupplier->getName();
179 : }
180 :
181 : }
182 :
183 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|