Version 6.1.4.1, tag libreoffice-6.1.4.1
[LibreOffice.git] / uui / source / iahndl-ioexceptions.cxx
blobbd85abbdcb1eb9ddb8daedecd56cc128cf9cce82
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 #include <com/sun/star/beans/PropertyValue.hpp>
21 #include <com/sun/star/task/XInteractionRequest.hpp>
22 #include <com/sun/star/ucb/InteractiveAugmentedIOException.hpp>
23 #include <comphelper/fileurl.hxx>
25 #include <ids.hxx>
27 #include "iahndl.hxx"
29 using namespace com::sun::star;
31 namespace {
33 bool
34 getStringRequestArgument(uno::Sequence< uno::Any > const & rArguments,
35 OUString const & rKey,
36 OUString * pValue)
38 for (sal_Int32 i = 0; i < rArguments.getLength(); ++i)
40 beans::PropertyValue aProperty;
41 if ((rArguments[i] >>= aProperty) && aProperty.Name == rKey)
43 OUString aValue;
44 if (aProperty.Value >>= aValue)
46 if (pValue)
47 *pValue = aValue;
48 return true;
52 return false;
55 bool
56 getBoolRequestArgument(uno::Sequence< uno::Any > const & rArguments,
57 OUString const & rKey,
58 bool * pValue)
60 for (sal_Int32 i = 0; i < rArguments.getLength(); ++i)
62 beans::PropertyValue aProperty;
63 if ((rArguments[i] >>= aProperty) && aProperty.Name == rKey)
65 bool bValue;
66 if (aProperty.Value >>= bValue)
68 if (pValue)
69 *pValue = bValue;
70 return true;
74 return false;
77 bool
78 getResourceNameRequestArgument(uno::Sequence< uno::Any > const & rArguments,
79 OUString * pValue)
81 if (!getStringRequestArgument(rArguments, "Uri", pValue))
82 return false;
83 // Use the resource name only for file URLs, to avoid confusion:
84 if (pValue && comphelper::isFileUrl(*pValue))
85 getStringRequestArgument(rArguments, "ResourceName", pValue);
86 return true;
89 } // namespace
91 bool
92 UUIInteractionHelper::handleInteractiveIOException(
93 uno::Reference< task::XInteractionRequest > const & rRequest,
94 bool bObtainErrorStringOnly,
95 bool & bHasErrorString,
96 OUString & rErrorString)
98 uno::Any aAnyRequest(rRequest->getRequest());
99 bHasErrorString = false;
101 ucb::InteractiveIOException aIoException;
102 if (aAnyRequest >>= aIoException)
104 uno::Sequence< uno::Any > aRequestArguments;
105 ucb::InteractiveAugmentedIOException aAugmentedIoException;
106 if (aAnyRequest >>= aAugmentedIoException)
107 aRequestArguments = aAugmentedIoException.Arguments;
109 ErrCode nErrorCode;
110 std::vector< OUString > aArguments;
111 static ErrCode const
112 aErrorCode[sal_Int32(ucb::IOErrorCode_WRONG_VERSION) + 1][2]
113 = { { ERRCODE_IO_ABORT, ERRCODE_UUI_IO_ABORT }, // ABORT
114 { ERRCODE_IO_ACCESSDENIED, ERRCODE_UUI_IO_ACCESSDENIED },
115 // ACCESS_DENIED
116 { ERRCODE_IO_ALREADYEXISTS,
117 ERRCODE_UUI_IO_ALREADYEXISTS }, // ALREADY_EXISTING
118 { ERRCODE_IO_BADCRC, ERRCODE_UUI_IO_BADCRC }, // BAD_CRC
119 { ERRCODE_IO_CANTCREATE, ERRCODE_UUI_IO_CANTCREATE },
120 // CANT_CREATE
121 { ERRCODE_IO_CANTREAD, ERRCODE_UUI_IO_CANTREAD },
122 // CANT_READ
123 { ERRCODE_IO_CANTSEEK, ERRCODE_UUI_IO_CANTSEEK },
124 // CANT_SEEK
125 { ERRCODE_IO_CANTTELL, ERRCODE_UUI_IO_CANTTELL },
126 // CANT_TELL
127 { ERRCODE_IO_CANTWRITE, ERRCODE_UUI_IO_CANTWRITE },
128 // CANT_WRITE
129 { ERRCODE_IO_CURRENTDIR, ERRCODE_UUI_IO_CURRENTDIR },
130 // CURRENT_DIRECTORY
131 { ERRCODE_IO_DEVICENOTREADY, ERRCODE_UUI_IO_NOTREADY },
132 // DEVICE_NOT_READY
133 { ERRCODE_IO_NOTSAMEDEVICE,
134 ERRCODE_UUI_IO_NOTSAMEDEVICE }, // DIFFERENT_DEVICES
135 { ERRCODE_IO_GENERAL, ERRCODE_UUI_IO_GENERAL }, // GENERAL
136 { ERRCODE_IO_INVALIDACCESS,
137 ERRCODE_UUI_IO_INVALIDACCESS }, // INVALID_ACCESS
138 { ERRCODE_IO_INVALIDCHAR, ERRCODE_UUI_IO_INVALIDCHAR },
139 // INVALID_CHARACTER
140 { ERRCODE_IO_INVALIDDEVICE,
141 ERRCODE_UUI_IO_INVALIDDEVICE }, // INVALID_DEVICE
142 { ERRCODE_IO_INVALIDLENGTH,
143 ERRCODE_UUI_IO_INVALIDLENGTH }, // INVALID_LENGTH
144 { ERRCODE_IO_INVALIDPARAMETER,
145 ERRCODE_UUI_IO_INVALIDPARAMETER }, // INVALID_PARAMETER
146 { ERRCODE_IO_ISWILDCARD, ERRCODE_UUI_IO_ISWILDCARD },
147 // IS_WILDCARD
148 { ERRCODE_IO_LOCKVIOLATION,
149 ERRCODE_UUI_IO_LOCKVIOLATION }, // LOCKING_VIOLATION
150 { ERRCODE_IO_MISPLACEDCHAR,
151 ERRCODE_UUI_IO_MISPLACEDCHAR }, // MISPLACED_CHARACTER
152 { ERRCODE_IO_NAMETOOLONG, ERRCODE_UUI_IO_NAMETOOLONG },
153 // NAME_TOO_LONG
154 { ERRCODE_IO_NOTEXISTS, ERRCODE_UUI_IO_NOTEXISTS },
155 // NOT_EXISTING
156 { ERRCODE_IO_NOTEXISTSPATH,
157 ERRCODE_UUI_IO_NOTEXISTSPATH }, // NOT_EXISTING_PATH
158 { ERRCODE_IO_NOTSUPPORTED, ERRCODE_UUI_IO_NOTSUPPORTED },
159 // NOT_SUPPORTED
160 { ERRCODE_IO_NOTADIRECTORY,
161 ERRCODE_UUI_IO_NOTADIRECTORY }, // NO_DIRECTORY
162 { ERRCODE_IO_NOTAFILE, ERRCODE_UUI_IO_NOTAFILE },
163 // NO_FILE
164 { ERRCODE_IO_OUTOFSPACE, ERRCODE_UUI_IO_OUTOFSPACE },
165 // OUT_OF_DISK_SPACE
166 { ERRCODE_IO_TOOMANYOPENFILES,
167 ERRCODE_UUI_IO_TOOMANYOPENFILES },
168 // OUT_OF_FILE_HANDLES
169 { ERRCODE_IO_OUTOFMEMORY, ERRCODE_UUI_IO_OUTOFMEMORY },
170 // OUT_OF_MEMORY
171 { ERRCODE_IO_PENDING, ERRCODE_UUI_IO_PENDING }, // PENDING
172 { ERRCODE_IO_RECURSIVE, ERRCODE_UUI_IO_RECURSIVE },
173 // RECURSIVE
174 { ERRCODE_IO_UNKNOWN, ERRCODE_UUI_IO_UNKNOWN }, // UNKNOWN
175 { ERRCODE_IO_WRITEPROTECTED,
176 ERRCODE_UUI_IO_WRITEPROTECTED }, // WRITE_PROTECTED
177 { ERRCODE_IO_WRONGFORMAT, ERRCODE_UUI_IO_WRONGFORMAT },
178 // WRONG_FORMAT
179 { ERRCODE_IO_WRONGVERSION,
180 ERRCODE_UUI_IO_WRONGVERSION } }; // WRONG_VERSION
181 switch (aIoException.Code)
183 case ucb::IOErrorCode_CANT_CREATE:
185 OUString aArgFolder;
186 if (getStringRequestArgument(aRequestArguments, "Folder", &aArgFolder))
188 OUString aArgUri;
189 if (getResourceNameRequestArgument(aRequestArguments,
190 &aArgUri))
192 nErrorCode = ERRCODE_UUI_IO_CANTCREATE;
193 aArguments.reserve(2);
194 aArguments.push_back(aArgUri);
195 aArguments.push_back(aArgFolder);
197 else
199 nErrorCode = ERRCODE_UUI_IO_CANTCREATE_NONAME;
200 aArguments.push_back(aArgFolder);
203 else
204 nErrorCode = aErrorCode[static_cast<sal_Int32>(aIoException.Code)][0];
205 break;
208 case ucb::IOErrorCode_DEVICE_NOT_READY:
210 OUString aArgUri;
211 if (getResourceNameRequestArgument(aRequestArguments,
212 &aArgUri))
214 OUString aResourceType;
215 getStringRequestArgument(aRequestArguments, "ResourceType", &aResourceType);
216 bool bRemovable = false;
217 getBoolRequestArgument(aRequestArguments, "Removable", &bRemovable);
218 nErrorCode = aResourceType == "volume"
219 ? (bRemovable
220 ? ERRCODE_UUI_IO_NOTREADY_VOLUME_REMOVABLE
221 : ERRCODE_UUI_IO_NOTREADY_VOLUME)
222 : (bRemovable
223 ? ERRCODE_UUI_IO_NOTREADY_REMOVABLE
224 : ERRCODE_UUI_IO_NOTREADY);
225 aArguments.push_back(aArgUri);
227 else
228 nErrorCode = aErrorCode[static_cast<sal_Int32>(aIoException.Code)][0];
229 break;
232 case ucb::IOErrorCode_DIFFERENT_DEVICES:
234 OUString aArgVolume;
235 OUString aArgOtherVolume;
236 if (getStringRequestArgument(aRequestArguments, "Volume", &aArgVolume)
237 && getStringRequestArgument(aRequestArguments, "OtherVolume",
238 &aArgOtherVolume))
240 nErrorCode = aErrorCode[static_cast<sal_Int32>(aIoException.Code)][1];
241 aArguments.reserve(2);
242 aArguments.push_back(aArgVolume);
243 aArguments.push_back(aArgOtherVolume);
245 else
246 nErrorCode = aErrorCode[static_cast<sal_Int32>(aIoException.Code)][0];
247 break;
250 case ucb::IOErrorCode_NOT_EXISTING:
252 OUString aArgUri;
253 if (getResourceNameRequestArgument(aRequestArguments,
254 &aArgUri))
256 OUString aResourceType;
257 getStringRequestArgument(aRequestArguments, "ResourceType",
258 &aResourceType);
259 nErrorCode = aResourceType == "volume"
260 ? ERRCODE_UUI_IO_NOTEXISTS_VOLUME
261 : (aResourceType == "folder"
262 ? ERRCODE_UUI_IO_NOTEXISTS_FOLDER
263 : ERRCODE_UUI_IO_NOTEXISTS);
264 aArguments.push_back(aArgUri);
266 else
267 nErrorCode = aErrorCode[static_cast<sal_Int32>(aIoException.Code)][0];
268 break;
271 default:
273 OUString aArgUri;
274 if (getResourceNameRequestArgument(aRequestArguments,
275 &aArgUri))
277 nErrorCode = aErrorCode[static_cast<sal_Int32>(aIoException.Code)][1];
278 aArguments.push_back(aArgUri);
280 else
281 nErrorCode = aErrorCode[static_cast<sal_Int32>(aIoException.Code)][0];
282 break;
286 handleErrorHandlerRequest(aIoException.Classification,
287 nErrorCode,
288 aArguments,
289 rRequest->getContinuations(),
290 bObtainErrorStringOnly,
291 bHasErrorString,
292 rErrorString);
293 return true;
295 return false;
298 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */