update emoji autocorrect entries from po-files
[LibreOffice.git] / uui / source / iahndl-ioexceptions.cxx
blob029ba1dd889582f05938020d8301cab7bee5e889
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>
24 #include "ids.hrc"
26 #include "iahndl.hxx"
28 using namespace com::sun::star;
30 namespace {
32 bool
33 getStringRequestArgument(uno::Sequence< uno::Any > const & rArguments,
34 OUString const & rKey,
35 OUString * pValue)
37 for (sal_Int32 i = 0; i < rArguments.getLength(); ++i)
39 beans::PropertyValue aProperty;
40 if ((rArguments[i] >>= aProperty) && aProperty.Name == rKey)
42 OUString aValue;
43 if (aProperty.Value >>= aValue)
45 if (pValue)
46 *pValue = aValue;
47 return true;
51 return false;
54 bool
55 getBoolRequestArgument(uno::Sequence< uno::Any > const & rArguments,
56 OUString const & rKey,
57 bool * pValue)
59 for (sal_Int32 i = 0; i < rArguments.getLength(); ++i)
61 beans::PropertyValue aProperty;
62 if ((rArguments[i] >>= aProperty) && aProperty.Name == rKey)
64 bool bValue;
65 if (aProperty.Value >>= bValue)
67 if (pValue)
68 *pValue = bValue;
69 return true;
73 return false;
76 bool
77 getResourceNameRequestArgument(uno::Sequence< uno::Any > const & rArguments,
78 OUString * pValue)
80 if (!getStringRequestArgument(rArguments, "Uri", pValue))
81 return false;
82 // Use the resource name only for file URLs, to avoid confusion:
83 //TODO! work with ucp locality concept instead of hardcoded "file"?
84 if (pValue
85 && pValue->matchIgnoreAsciiCase("file:"))
86 getStringRequestArgument(rArguments, "ResourceName", pValue);
87 return true;
90 } // namespace
92 bool
93 UUIInteractionHelper::handleInteractiveIOException(
94 uno::Reference< task::XInteractionRequest > const & rRequest,
95 bool bObtainErrorStringOnly,
96 bool & bHasErrorString,
97 OUString & rErrorString)
99 uno::Any aAnyRequest(rRequest->getRequest());
100 bHasErrorString = false;
102 ucb::InteractiveIOException aIoException;
103 if (aAnyRequest >>= aIoException)
105 uno::Sequence< uno::Any > aRequestArguments;
106 ucb::InteractiveAugmentedIOException aAugmentedIoException;
107 if (aAnyRequest >>= aAugmentedIoException)
108 aRequestArguments = aAugmentedIoException.Arguments;
110 ErrCode nErrorCode;
111 std::vector< OUString > aArguments;
112 static ErrCode const
113 aErrorCode[ucb::IOErrorCode_WRONG_VERSION + 1][2]
114 = { { ERRCODE_IO_ABORT, ERRCODE_UUI_IO_ABORT }, // ABORT
115 { ERRCODE_IO_ACCESSDENIED, ERRCODE_UUI_IO_ACCESSDENIED },
116 // ACCESS_DENIED
117 { ERRCODE_IO_ALREADYEXISTS,
118 ERRCODE_UUI_IO_ALREADYEXISTS }, // ALREADY_EXISTING
119 { ERRCODE_IO_BADCRC, ERRCODE_UUI_IO_BADCRC }, // BAD_CRC
120 { ERRCODE_IO_CANTCREATE, ERRCODE_UUI_IO_CANTCREATE },
121 // CANT_CREATE
122 { ERRCODE_IO_CANTREAD, ERRCODE_UUI_IO_CANTREAD },
123 // CANT_READ
124 { ERRCODE_IO_CANTSEEK, ERRCODE_UUI_IO_CANTSEEK },
125 // CANT_SEEK
126 { ERRCODE_IO_CANTTELL, ERRCODE_UUI_IO_CANTTELL },
127 // CANT_TELL
128 { ERRCODE_IO_CANTWRITE, ERRCODE_UUI_IO_CANTWRITE },
129 // CANT_WRITE
130 { ERRCODE_IO_CURRENTDIR, ERRCODE_UUI_IO_CURRENTDIR },
131 // CURRENT_DIRECTORY
132 { ERRCODE_IO_DEVICENOTREADY, ERRCODE_UUI_IO_NOTREADY },
133 // DEVICE_NOT_READY
134 { ERRCODE_IO_NOTSAMEDEVICE,
135 ERRCODE_UUI_IO_NOTSAMEDEVICE }, // DIFFERENT_DEVICES
136 { ERRCODE_IO_GENERAL, ERRCODE_UUI_IO_GENERAL }, // GENERAL
137 { ERRCODE_IO_INVALIDACCESS,
138 ERRCODE_UUI_IO_INVALIDACCESS }, // INVALID_ACCESS
139 { ERRCODE_IO_INVALIDCHAR, ERRCODE_UUI_IO_INVALIDCHAR },
140 // INVALID_CHARACTER
141 { ERRCODE_IO_INVALIDDEVICE,
142 ERRCODE_UUI_IO_INVALIDDEVICE }, // INVALID_DEVICE
143 { ERRCODE_IO_INVALIDLENGTH,
144 ERRCODE_UUI_IO_INVALIDLENGTH }, // INVALID_LENGTH
145 { ERRCODE_IO_INVALIDPARAMETER,
146 ERRCODE_UUI_IO_INVALIDPARAMETER }, // INVALID_PARAMETER
147 { ERRCODE_IO_ISWILDCARD, ERRCODE_UUI_IO_ISWILDCARD },
148 // IS_WILDCARD
149 { ERRCODE_IO_LOCKVIOLATION,
150 ERRCODE_UUI_IO_LOCKVIOLATION }, // LOCKING_VIOLATION
151 { ERRCODE_IO_MISPLACEDCHAR,
152 ERRCODE_UUI_IO_MISPLACEDCHAR }, // MISPLACED_CHARACTER
153 { ERRCODE_IO_NAMETOOLONG, ERRCODE_UUI_IO_NAMETOOLONG },
154 // NAME_TOO_LONG
155 { ERRCODE_IO_NOTEXISTS, ERRCODE_UUI_IO_NOTEXISTS },
156 // NOT_EXISTING
157 { ERRCODE_IO_NOTEXISTSPATH,
158 ERRCODE_UUI_IO_NOTEXISTSPATH }, // NOT_EXISTING_PATH
159 { ERRCODE_IO_NOTSUPPORTED, ERRCODE_UUI_IO_NOTSUPPORTED },
160 // NOT_SUPPORTED
161 { ERRCODE_IO_NOTADIRECTORY,
162 ERRCODE_UUI_IO_NOTADIRECTORY }, // NO_DIRECTORY
163 { ERRCODE_IO_NOTAFILE, ERRCODE_UUI_IO_NOTAFILE },
164 // NO_FILE
165 { ERRCODE_IO_OUTOFSPACE, ERRCODE_UUI_IO_OUTOFSPACE },
166 // OUT_OF_DISK_SPACE
167 { ERRCODE_IO_TOOMANYOPENFILES,
168 ERRCODE_UUI_IO_TOOMANYOPENFILES },
169 // OUT_OF_FILE_HANDLES
170 { ERRCODE_IO_OUTOFMEMORY, ERRCODE_UUI_IO_OUTOFMEMORY },
171 // OUT_OF_MEMORY
172 { ERRCODE_IO_PENDING, ERRCODE_UUI_IO_PENDING }, // PENDING
173 { ERRCODE_IO_RECURSIVE, ERRCODE_UUI_IO_RECURSIVE },
174 // RECURSIVE
175 { ERRCODE_IO_UNKNOWN, ERRCODE_UUI_IO_UNKNOWN }, // UNKNOWN
176 { ERRCODE_IO_WRITEPROTECTED,
177 ERRCODE_UUI_IO_WRITEPROTECTED }, // WRITE_PROTECTED
178 { ERRCODE_IO_WRONGFORMAT, ERRCODE_UUI_IO_WRONGFORMAT },
179 // WRONG_FORMAT
180 { ERRCODE_IO_WRONGVERSION,
181 ERRCODE_UUI_IO_WRONGVERSION } }; // WRONG_VERSION
182 switch (aIoException.Code)
184 case ucb::IOErrorCode_CANT_CREATE:
186 OUString aArgFolder;
187 if (getStringRequestArgument(aRequestArguments, "Folder", &aArgFolder))
189 OUString aArgUri;
190 if (getResourceNameRequestArgument(aRequestArguments,
191 &aArgUri))
193 nErrorCode = ERRCODE_UUI_IO_CANTCREATE;
194 aArguments.reserve(2);
195 aArguments.push_back(aArgUri);
196 aArguments.push_back(aArgFolder);
198 else
200 nErrorCode = ERRCODE_UUI_IO_CANTCREATE_NONAME;
201 aArguments.push_back(aArgFolder);
204 else
205 nErrorCode = aErrorCode[aIoException.Code][0];
206 break;
209 case ucb::IOErrorCode_DEVICE_NOT_READY:
211 OUString aArgUri;
212 if (getResourceNameRequestArgument(aRequestArguments,
213 &aArgUri))
215 OUString aResourceType;
216 getStringRequestArgument(aRequestArguments, "ResourceType", &aResourceType);
217 bool bRemovable = false;
218 getBoolRequestArgument(aRequestArguments, "Removable", &bRemovable);
219 nErrorCode = aResourceType == "volume"
220 ? (bRemovable
221 ? ERRCODE_UUI_IO_NOTREADY_VOLUME_REMOVABLE
222 : ERRCODE_UUI_IO_NOTREADY_VOLUME)
223 : (bRemovable
224 ? ERRCODE_UUI_IO_NOTREADY_REMOVABLE
225 : ERRCODE_UUI_IO_NOTREADY);
226 aArguments.push_back(aArgUri);
228 else
229 nErrorCode = aErrorCode[aIoException.Code][0];
230 break;
233 case ucb::IOErrorCode_DIFFERENT_DEVICES:
235 OUString aArgVolume;
236 OUString aArgOtherVolume;
237 if (getStringRequestArgument(aRequestArguments, "Volume", &aArgVolume)
238 && getStringRequestArgument(aRequestArguments, "OtherVolume",
239 &aArgOtherVolume))
241 nErrorCode = aErrorCode[aIoException.Code][1];
242 aArguments.reserve(2);
243 aArguments.push_back(aArgVolume);
244 aArguments.push_back(aArgOtherVolume);
246 else
247 nErrorCode = aErrorCode[aIoException.Code][0];
248 break;
251 case ucb::IOErrorCode_NOT_EXISTING:
253 OUString aArgUri;
254 if (getResourceNameRequestArgument(aRequestArguments,
255 &aArgUri))
257 OUString aResourceType;
258 getStringRequestArgument(aRequestArguments, "ResourceType",
259 &aResourceType);
260 nErrorCode = aResourceType == "volume"
261 ? ERRCODE_UUI_IO_NOTEXISTS_VOLUME
262 : (aResourceType == "folder"
263 ? ERRCODE_UUI_IO_NOTEXISTS_FOLDER
264 : ERRCODE_UUI_IO_NOTEXISTS);
265 aArguments.push_back(aArgUri);
267 else
268 nErrorCode = aErrorCode[aIoException.Code][0];
269 break;
272 default:
274 OUString aArgUri;
275 if (getResourceNameRequestArgument(aRequestArguments,
276 &aArgUri))
278 nErrorCode = aErrorCode[aIoException.Code][1];
279 aArguments.push_back(aArgUri);
281 else
282 nErrorCode = aErrorCode[aIoException.Code][0];
283 break;
287 handleErrorHandlerRequest(aIoException.Classification,
288 nErrorCode,
289 aArguments,
290 rRequest->getContinuations(),
291 bObtainErrorStringOnly,
292 bHasErrorString,
293 rErrorString);
294 return true;
296 return false;
299 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */