Bug Summary

File:home/maarten/src/libreoffice/core/include/rtl/ref.hxx
Warning:line 192, column 9
Use of memory after it is freed

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-unknown-linux-gnu -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name AdditionsDialog.cxx -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 2 -mframe-pointer=all -fmath-errno -fno-rounding-math -mconstructor-aliases -munwind-tables -target-cpu x86-64 -fno-split-dwarf-inlining -debugger-tuning=gdb -resource-dir /usr/lib64/clang/11.0.0 -isystem /usr/include/libxml2 -D BOOST_ERROR_CODE_HEADER_ONLY -D BOOST_SYSTEM_NO_DEPRECATED -D CPPU_ENV=gcc3 -D LINUX -D OSL_DEBUG_LEVEL=1 -D SAL_LOG_INFO -D SAL_LOG_WARN -D UNIX -D UNX -D X86_64 -D _PTHREADS -D _REENTRANT -D CUI_DLLIMPLEMENTATION -D SYSTEM_LIBXML -D EXCEPTIONS_ON -D LIBO_INTERNAL_ONLY -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/epoxy/include -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/qrcodegen/cpp/ -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/liborcus/include -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/liborcus/include -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/icu/source -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/icu/source/i18n -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/icu/source/common -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/curl/include -I /home/maarten/src/libreoffice/core/external/clew/source/include -I /home/maarten/src/libreoffice/core/external/boost/include -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/boost -I /home/maarten/src/libreoffice/core/include -I /usr/lib/jvm/java-11-openjdk-11.0.9.10-0.0.ea.fc33.x86_64/include -I /usr/lib/jvm/java-11-openjdk-11.0.9.10-0.0.ea.fc33.x86_64/include/linux -I /home/maarten/src/libreoffice/core/config_host -I /home/maarten/src/libreoffice/core/cui/inc -I /home/maarten/src/libreoffice/core/cui/source/inc -I /home/maarten/src/libreoffice/core/workdir/CustomTarget/officecfg/registry -I /home/maarten/src/libreoffice/core/workdir/UnoApiHeadersTarget/udkapi/normal -I /home/maarten/src/libreoffice/core/workdir/UnoApiHeadersTarget/offapi/normal -internal-isystem /usr/bin/../lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10 -internal-isystem /usr/bin/../lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10/x86_64-redhat-linux -internal-isystem /usr/bin/../lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10/backward -internal-isystem /usr/local/include -internal-isystem /usr/lib64/clang/11.0.0/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -O0 -Wno-missing-braces -std=c++17 -fdeprecated-macro -fdebug-compilation-dir /home/maarten/src/libreoffice/core -ferror-limit 19 -fvisibility hidden -fvisibility-inlines-hidden -stack-protector 2 -fgnuc-version=4.2.1 -fcxx-exceptions -fexceptions -debug-info-kind=constructor -analyzer-output=html -faddrsig -o /home/maarten/tmp/wis/scan-build-libreoffice/output/report/2020-10-07-141433-9725-1 -x c++ /home/maarten/src/libreoffice/core/cui/source/dialogs/AdditionsDialog.cxx

/home/maarten/src/libreoffice/core/cui/source/dialogs/AdditionsDialog.cxx

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 */
10#include <config_folders.h>
11
12#include <AdditionsDialog.hxx>
13
14#include <sal/log.hxx>
15
16#include <com/sun/star/graphic/GraphicProvider.hpp>
17#include <com/sun/star/graphic/XGraphicProvider.hpp>
18#include <com/sun/star/ucb/SimpleFileAccess.hpp>
19#include <osl/file.hxx>
20#include <rtl/bootstrap.hxx>
21#include <tools/urlobj.hxx>
22#include <tools/stream.hxx>
23#include <tools/diagnose_ex.h>
24#include <comphelper/processfactory.hxx>
25#include <vcl/virdev.hxx>
26#include <vcl/svapp.hxx>
27#include <vcl/graphicfilter.hxx>
28#include <cppuhelper/exc_hlp.hxx>
29
30#include <com/sun/star/util/SearchFlags.hpp>
31#include <com/sun/star/util/SearchAlgorithms2.hpp>
32#include <unotools/textsearch.hxx>
33
34#include <ucbhelper/content.hxx>
35
36#include <com/sun/star/deployment/DeploymentException.hpp>
37#include <com/sun/star/lang/WrappedTargetRuntimeException.hpp>
38#include <com/sun/star/ucb/CommandAbortedException.hpp>
39#include <com/sun/star/ucb/CommandFailedException.hpp>
40
41#include <com/sun/star/task/XInteractionApprove.hpp>
42
43//cURL
44#include <curl/curl.h>
45#include <orcus/json_document_tree.hpp>
46#include <orcus/config.hpp>
47#include <orcus/pstring.hpp>
48
49// FIXME
50// This preprocessor command is written to prevent the error caused by "css::util::SearchAlgorithms2::ABSOLUTE" in the AdditionsDialog().
51#ifdef ABSOLUTE
52#undef ABSOLUTE
53#endif
54
55#define PAGE_SIZE30 30
56
57using namespace css;
58using ::com::sun::star::uno::Reference;
59using ::com::sun::star::uno::XComponentContext;
60using ::com::sun::star::uno::UNO_QUERY_THROW;
61using ::com::sun::star::uno::Exception;
62using ::com::sun::star::graphic::GraphicProvider;
63using ::com::sun::star::graphic::XGraphicProvider;
64using ::com::sun::star::uno::Sequence;
65using ::com::sun::star::beans::PropertyValue;
66using ::com::sun::star::graphic::XGraphic;
67
68using namespace com::sun::star;
69using namespace ::com::sun::star::uno;
70using namespace ::com::sun::star::ucb;
71using namespace ::com::sun::star::beans;
72
73#ifdef UNX1
74const char kUserAgent[] = "LibreOffice AdditionsDownloader/1.0 (Linux)";
75#else
76const char kUserAgent[] = "LibreOffice AdditionsDownloader/1.0 (unknown platform)";
77#endif
78
79namespace
80{
81size_t WriteCallback(void* ptr, size_t size, size_t nmemb, void* userp)
82{
83 if (!userp)
84 return 0;
85
86 std::string* response = static_cast<std::string*>(userp);
87 size_t real_size = size * nmemb;
88 response->append(static_cast<char*>(ptr), real_size);
89 return real_size;
90}
91
92// Callback to get the response data from server to a file.
93size_t WriteCallbackFile(void* ptr, size_t size, size_t nmemb, void* userp)
94{
95 if (!userp)
96 return 0;
97
98 SvStream* response = static_cast<SvStream*>(userp);
99 size_t real_size = size * nmemb;
100 response->WriteBytes(ptr, real_size);
101 return real_size;
102}
103
104// Gets the content of the given URL and returns as a standard string
105std::string curlGet(const OString& rURL)
106{
107 CURL* curl = curl_easy_init();
108
109 if (!curl)
110 return std::string();
111
112 curl_easy_setopt(curl, CURLOPT_URL, rURL.getStr())curl_easy_setopt(curl,CURLOPT_URL,rURL.getStr());
113
114 std::string response_body;
115
116 curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback)curl_easy_setopt(curl,CURLOPT_WRITEFUNCTION,WriteCallback);
117 curl_easy_setopt(curl, CURLOPT_WRITEDATA, static_cast<void*>(&response_body))curl_easy_setopt(curl,CURLOPT_WRITEDATA,static_cast<void*>
(&response_body))
;
118
119 CURLcode cc = curl_easy_perform(curl);
120 long http_code = 0;
121 curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &http_code)curl_easy_getinfo(curl,CURLINFO_RESPONSE_CODE,&http_code);
122
123 if (http_code != 200)
124 {
125 SAL_WARN("cui.dialogs", "Download failed. Error code: " << http_code)do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_WARN
, "cui.dialogs")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break;
case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult
( ::sal::detail::StreamStart() << "Download failed. Error code: "
<< http_code) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN
), ("cui.dialogs"), ("/home/maarten/src/libreoffice/core/cui/source/dialogs/AdditionsDialog.cxx"
":" "125" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "Download failed. Error code: " <<
http_code), 0); } else { ::std::ostringstream sal_detail_stream
; sal_detail_stream << "Download failed. Error code: " <<
http_code; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN)
, ("cui.dialogs"), ("/home/maarten/src/libreoffice/core/cui/source/dialogs/AdditionsDialog.cxx"
":" "125" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "Download failed. Error code: " << http_code
) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("cui.dialogs"
), ("/home/maarten/src/libreoffice/core/cui/source/dialogs/AdditionsDialog.cxx"
":" "125" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "Download failed. Error code: " <<
http_code), 0); } else { ::std::ostringstream sal_detail_stream
; sal_detail_stream << "Download failed. Error code: " <<
http_code; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN)
, ("cui.dialogs"), ("/home/maarten/src/libreoffice/core/cui/source/dialogs/AdditionsDialog.cxx"
":" "125" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false)
;
126 }
127
128 if (cc != CURLE_OK)
129 {
130 SAL_WARN("cui.dialogs", "curl error: " << cc)do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_WARN
, "cui.dialogs")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break;
case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult
( ::sal::detail::StreamStart() << "curl error: " <<
cc) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN),
("cui.dialogs"), ("/home/maarten/src/libreoffice/core/cui/source/dialogs/AdditionsDialog.cxx"
":" "130" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "curl error: " << cc), 0); } else
{ ::std::ostringstream sal_detail_stream; sal_detail_stream <<
"curl error: " << cc; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN
), ("cui.dialogs"), ("/home/maarten/src/libreoffice/core/cui/source/dialogs/AdditionsDialog.cxx"
":" "130" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "curl error: " << cc) == 1) { ::sal_detail_log
( (::SAL_DETAIL_LOG_LEVEL_WARN), ("cui.dialogs"), ("/home/maarten/src/libreoffice/core/cui/source/dialogs/AdditionsDialog.cxx"
":" "130" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "curl error: " << cc), 0); } else
{ ::std::ostringstream sal_detail_stream; sal_detail_stream <<
"curl error: " << cc; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN
), ("cui.dialogs"), ("/home/maarten/src/libreoffice/core/cui/source/dialogs/AdditionsDialog.cxx"
":" "130" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false)
;
131 }
132
133 return response_body;
134}
135
136// Downloads and saves the file at the given rURL to a local path (sFileURL)
137void curlDownload(const OString& rURL, const OUString& sFileURL)
138{
139 CURL* curl = curl_easy_init();
140 SvFileStream aFile(sFileURL, StreamMode::WRITE);
141
142 if (!curl)
143 return;
144
145 curl_easy_setopt(curl, CURLOPT_URL, rURL.getStr())curl_easy_setopt(curl,CURLOPT_URL,rURL.getStr());
146 curl_easy_setopt(curl, CURLOPT_USERAGENT, kUserAgent)curl_easy_setopt(curl,CURLOPT_USERAGENT,kUserAgent);
147
148 curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallbackFile)curl_easy_setopt(curl,CURLOPT_WRITEFUNCTION,WriteCallbackFile
)
;
149 curl_easy_setopt(curl, CURLOPT_WRITEDATA, static_cast<void*>(&aFile))curl_easy_setopt(curl,CURLOPT_WRITEDATA,static_cast<void*>
(&aFile))
;
150
151 CURLcode cc = curl_easy_perform(curl);
152 long http_code = 0;
153 curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &http_code)curl_easy_getinfo(curl,CURLINFO_RESPONSE_CODE,&http_code);
154
155 if (http_code != 200)
156 {
157 SAL_WARN("cui.dialogs", "Download failed. Error code: " << http_code)do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_WARN
, "cui.dialogs")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break;
case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult
( ::sal::detail::StreamStart() << "Download failed. Error code: "
<< http_code) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN
), ("cui.dialogs"), ("/home/maarten/src/libreoffice/core/cui/source/dialogs/AdditionsDialog.cxx"
":" "157" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "Download failed. Error code: " <<
http_code), 0); } else { ::std::ostringstream sal_detail_stream
; sal_detail_stream << "Download failed. Error code: " <<
http_code; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN)
, ("cui.dialogs"), ("/home/maarten/src/libreoffice/core/cui/source/dialogs/AdditionsDialog.cxx"
":" "157" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "Download failed. Error code: " << http_code
) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("cui.dialogs"
), ("/home/maarten/src/libreoffice/core/cui/source/dialogs/AdditionsDialog.cxx"
":" "157" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "Download failed. Error code: " <<
http_code), 0); } else { ::std::ostringstream sal_detail_stream
; sal_detail_stream << "Download failed. Error code: " <<
http_code; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN)
, ("cui.dialogs"), ("/home/maarten/src/libreoffice/core/cui/source/dialogs/AdditionsDialog.cxx"
":" "157" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false)
;
158 }
159
160 if (cc != CURLE_OK)
161 {
162 SAL_WARN("cui.dialogs", "curl error: " << cc)do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_WARN
, "cui.dialogs")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break;
case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult
( ::sal::detail::StreamStart() << "curl error: " <<
cc) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN),
("cui.dialogs"), ("/home/maarten/src/libreoffice/core/cui/source/dialogs/AdditionsDialog.cxx"
":" "162" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "curl error: " << cc), 0); } else
{ ::std::ostringstream sal_detail_stream; sal_detail_stream <<
"curl error: " << cc; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN
), ("cui.dialogs"), ("/home/maarten/src/libreoffice/core/cui/source/dialogs/AdditionsDialog.cxx"
":" "162" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "curl error: " << cc) == 1) { ::sal_detail_log
( (::SAL_DETAIL_LOG_LEVEL_WARN), ("cui.dialogs"), ("/home/maarten/src/libreoffice/core/cui/source/dialogs/AdditionsDialog.cxx"
":" "162" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "curl error: " << cc), 0); } else
{ ::std::ostringstream sal_detail_stream; sal_detail_stream <<
"curl error: " << cc; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN
), ("cui.dialogs"), ("/home/maarten/src/libreoffice/core/cui/source/dialogs/AdditionsDialog.cxx"
":" "162" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false)
;
163 }
164}
165
166void parseResponse(const std::string& rResponse, std::vector<AdditionInfo>& aAdditions)
167{
168 orcus::json::document_tree aJsonDoc;
169 orcus::json_config aConfig;
170
171 if (rResponse.empty())
172 return;
173
174 aJsonDoc.load(rResponse, aConfig);
175
176 auto aDocumentRoot = aJsonDoc.get_document_root();
177 if (aDocumentRoot.type() != orcus::json::node_t::object)
178 {
179 SAL_WARN("cui.dialogs", "invalid root entries: " << rResponse)do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_WARN
, "cui.dialogs")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break;
case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult
( ::sal::detail::StreamStart() << "invalid root entries: "
<< rResponse) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN
), ("cui.dialogs"), ("/home/maarten/src/libreoffice/core/cui/source/dialogs/AdditionsDialog.cxx"
":" "179" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "invalid root entries: " << rResponse
), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "invalid root entries: " << rResponse; ::sal::
detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("cui.dialogs"), (
"/home/maarten/src/libreoffice/core/cui/source/dialogs/AdditionsDialog.cxx"
":" "179" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "invalid root entries: " << rResponse) == 1
) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("cui.dialogs"
), ("/home/maarten/src/libreoffice/core/cui/source/dialogs/AdditionsDialog.cxx"
":" "179" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "invalid root entries: " << rResponse
), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "invalid root entries: " << rResponse; ::sal::
detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("cui.dialogs"), (
"/home/maarten/src/libreoffice/core/cui/source/dialogs/AdditionsDialog.cxx"
":" "179" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false)
;
180 return;
181 }
182
183 auto resultsArray = aDocumentRoot.child("extension");
184
185 for (size_t i = 0; i < resultsArray.child_count(); ++i)
186 {
187 auto arrayElement = resultsArray.child(i);
188
189 try
190 {
191 AdditionInfo aNewAddition = {
192 OStringToOUString(OString(arrayElement.child("id").string_value().get()),
193 RTL_TEXTENCODING_UTF8(((rtl_TextEncoding) 76))),
194 OStringToOUString(OString(arrayElement.child("name").string_value().get()),
195 RTL_TEXTENCODING_UTF8(((rtl_TextEncoding) 76))),
196 OStringToOUString(OString(arrayElement.child("author").string_value().get()),
197 RTL_TEXTENCODING_UTF8(((rtl_TextEncoding) 76))),
198 OStringToOUString(OString(arrayElement.child("url").string_value().get()),
199 RTL_TEXTENCODING_UTF8(((rtl_TextEncoding) 76))),
200 OStringToOUString(OString(arrayElement.child("screenshotURL").string_value().get()),
201 RTL_TEXTENCODING_UTF8(((rtl_TextEncoding) 76))),
202 OStringToOUString(
203 OString(arrayElement.child("extensionIntroduction").string_value().get()),
204 RTL_TEXTENCODING_UTF8(((rtl_TextEncoding) 76))),
205 OStringToOUString(
206 OString(arrayElement.child("extensionDescription").string_value().get()),
207 RTL_TEXTENCODING_UTF8(((rtl_TextEncoding) 76))),
208 OStringToOUString(OString(arrayElement.child("releases")
209 .child(0)
210 .child("compatibility")
211 .string_value()
212 .get()),
213 RTL_TEXTENCODING_UTF8(((rtl_TextEncoding) 76))),
214 OStringToOUString(OString(arrayElement.child("releases")
215 .child(0)
216 .child("releaseName")
217 .string_value()
218 .get()),
219 RTL_TEXTENCODING_UTF8(((rtl_TextEncoding) 76))),
220 OStringToOUString(OString(arrayElement.child("releases")
221 .child(0)
222 .child("license")
223 .string_value()
224 .get()),
225 RTL_TEXTENCODING_UTF8(((rtl_TextEncoding) 76))),
226 OStringToOUString(OString(arrayElement.child("commentNumber").string_value().get()),
227 RTL_TEXTENCODING_UTF8(((rtl_TextEncoding) 76))),
228 OStringToOUString(OString(arrayElement.child("commentURL").string_value().get()),
229 RTL_TEXTENCODING_UTF8(((rtl_TextEncoding) 76))),
230 OStringToOUString(OString(arrayElement.child("rating").string_value().get()),
231 RTL_TEXTENCODING_UTF8(((rtl_TextEncoding) 76))),
232 OStringToOUString(
233 OString(arrayElement.child("downloadNumber").string_value().get()),
234 RTL_TEXTENCODING_UTF8(((rtl_TextEncoding) 76))),
235 OStringToOUString(OString(arrayElement.child("releases")
236 .child(0)
237 .child("downloadURL")
238 .string_value()
239 .get()),
240 RTL_TEXTENCODING_UTF8(((rtl_TextEncoding) 76)))
241 };
242
243 aAdditions.push_back(aNewAddition);
244 }
245 catch (orcus::json::document_error& e)
246 {
247 // This usually happens when one of the values is null (type() == orcus::json::node_t::null)
248 // TODO: Allow null values in additions.
249 SAL_WARN("cui.dialogs", "Additions JSON parse error: " << e.what())do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_WARN
, "cui.dialogs")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break;
case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult
( ::sal::detail::StreamStart() << "Additions JSON parse error: "
<< e.what()) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN
), ("cui.dialogs"), ("/home/maarten/src/libreoffice/core/cui/source/dialogs/AdditionsDialog.cxx"
":" "249" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "Additions JSON parse error: " <<
e.what()), 0); } else { ::std::ostringstream sal_detail_stream
; sal_detail_stream << "Additions JSON parse error: " <<
e.what(); ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN),
("cui.dialogs"), ("/home/maarten/src/libreoffice/core/cui/source/dialogs/AdditionsDialog.cxx"
":" "249" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "Additions JSON parse error: " << e.what())
== 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("cui.dialogs"
), ("/home/maarten/src/libreoffice/core/cui/source/dialogs/AdditionsDialog.cxx"
":" "249" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "Additions JSON parse error: " <<
e.what()), 0); } else { ::std::ostringstream sal_detail_stream
; sal_detail_stream << "Additions JSON parse error: " <<
e.what(); ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN),
("cui.dialogs"), ("/home/maarten/src/libreoffice/core/cui/source/dialogs/AdditionsDialog.cxx"
":" "249" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false)
;
250 }
251 }
252}
253
254bool getPreviewFile(const AdditionInfo& aAdditionInfo, OUString& sPreviewFile)
255{
256 uno::Reference<ucb::XSimpleFileAccess3> xFileAccess
257 = ucb::SimpleFileAccess::create(comphelper::getProcessComponentContext());
258
259 // copy the images to the user's additions folder
260 OUString userFolder = "${$BRAND_BASE_DIR/" LIBO_ETC_FOLDER"program"
261 "/" SAL_CONFIGFILE("bootstrap")"bootstrap" "rc" "::UserInstallation}";
262 rtl::Bootstrap::expandMacros(userFolder);
263 userFolder += "/user/additions/" + aAdditionInfo.sExtensionID + "/";
264
265 OUString aPreviewFile(INetURLObject(aAdditionInfo.sScreenshotURL).getName());
266 OString aPreviewURL = OUStringToOString(aAdditionInfo.sScreenshotURL, RTL_TEXTENCODING_UTF8(((rtl_TextEncoding) 76)));
267
268 try
269 {
270 osl::Directory::createPath(userFolder);
271
272 if (!xFileAccess->exists(userFolder + aPreviewFile))
273 curlDownload(aPreviewURL, userFolder + aPreviewFile);
274 }
275 catch (const uno::Exception&)
276 {
277 return false;
278 }
279 sPreviewFile = userFolder + aPreviewFile;
280 return true;
281}
282
283void LoadImage(const OUString& rPreviewFile, std::shared_ptr<AdditionsItem> pCurrentItem)
284{
285 SolarMutexGuard aGuard;
286
287 GraphicFilter aFilter;
288 Graphic aGraphic;
289
290 INetURLObject aURLObj(rPreviewFile);
291
292 // for VCL to be able to create bitmaps / do visual changes in the thread
293 aFilter.ImportGraphic(aGraphic, aURLObj);
294 BitmapEx aBmp = aGraphic.GetBitmapEx();
295
296 ScopedVclPtr<VirtualDevice> xVirDev = pCurrentItem->m_xImageScreenshot->create_virtual_device();
16
Calling constructor for 'ScopedVclPtr<VirtualDevice>'
23
Returning from constructor for 'ScopedVclPtr<VirtualDevice>'
24
Calling implicit destructor for 'VclPtr<VirtualDevice>'
25
Calling '~Reference'
32
Returning from '~Reference'
33
Returning from destructor for 'VclPtr<VirtualDevice>'
297 xVirDev->SetOutputSizePixel(aBmp.GetSizePixel());
34
Calling 'VclPtr::operator->'
298 xVirDev->DrawBitmapEx(Point(0, 0), aBmp);
299
300 pCurrentItem->m_xImageScreenshot->set_image(xVirDev.get());
301 xVirDev.disposeAndClear();
302}
303
304} // End of the anonymous namespace
305
306SearchAndParseThread::SearchAndParseThread(AdditionsDialog* pDialog, const bool& isFirstLoading)
307 : Thread("cuiAdditionsSearchThread")
308 , m_pAdditionsDialog(pDialog)
309 , m_bExecute(true)
310 , m_bIsFirstLoading(isFirstLoading)
311{
312}
313
314SearchAndParseThread::~SearchAndParseThread() {}
315
316void SearchAndParseThread::Append(AdditionInfo& additionInfo)
317{
318 if (!m_bExecute)
12
Assuming the condition is false
13
Taking false branch
319 return;
320 OUString aPreviewFile;
321 bool bResult = getPreviewFile(additionInfo, aPreviewFile); // info vector json data
322
323 if (!bResult
13.1
'bResult' is true
13.1
'bResult' is true
13.1
'bResult' is true
13.1
'bResult' is true
)
14
Taking false branch
324 {
325 SAL_INFO("cui.dialogs", "Couldn't get the preview file. Skipping: " << aPreviewFile)do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_INFO
, "cui.dialogs")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break;
case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult
( ::sal::detail::StreamStart() << "Couldn't get the preview file. Skipping: "
<< aPreviewFile) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO
), ("cui.dialogs"), ("/home/maarten/src/libreoffice/core/cui/source/dialogs/AdditionsDialog.cxx"
":" "325" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "Couldn't get the preview file. Skipping: "
<< aPreviewFile), 0); } else { ::std::ostringstream sal_detail_stream
; sal_detail_stream << "Couldn't get the preview file. Skipping: "
<< aPreviewFile; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO
), ("cui.dialogs"), ("/home/maarten/src/libreoffice/core/cui/source/dialogs/AdditionsDialog.cxx"
":" "325" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "Couldn't get the preview file. Skipping: " <<
aPreviewFile) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO
), ("cui.dialogs"), ("/home/maarten/src/libreoffice/core/cui/source/dialogs/AdditionsDialog.cxx"
":" "325" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "Couldn't get the preview file. Skipping: "
<< aPreviewFile), 0); } else { ::std::ostringstream sal_detail_stream
; sal_detail_stream << "Couldn't get the preview file. Skipping: "
<< aPreviewFile; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO
), ("cui.dialogs"), ("/home/maarten/src/libreoffice/core/cui/source/dialogs/AdditionsDialog.cxx"
":" "325" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false)
;
326 return;
327 }
328
329 SolarMutexGuard aGuard;
330
331 auto newItem = std::make_shared<AdditionsItem>(m_pAdditionsDialog->m_xContentGrid.get(),
332 m_pAdditionsDialog, additionInfo);
333 m_pAdditionsDialog->m_aAdditionsItems.push_back(newItem);
334 std::shared_ptr<AdditionsItem> aCurrentItem = m_pAdditionsDialog->m_aAdditionsItems.back();
335
336 LoadImage(aPreviewFile, aCurrentItem);
15
Calling 'LoadImage'
337 m_pAdditionsDialog->m_nCurrentListItemCount++;
338
339 if (m_pAdditionsDialog->m_nCurrentListItemCount == m_pAdditionsDialog->m_nMaxItemCount)
340 {
341 if (m_pAdditionsDialog->m_nCurrentListItemCount
342 != m_pAdditionsDialog->m_aAllExtensionsVector.size())
343 aCurrentItem->m_xButtonShowMore->set_visible(true);
344 }
345}
346
347void SearchAndParseThread::Search()
348{
349 m_pAdditionsDialog->m_searchOptions.searchString
350 = m_pAdditionsDialog->m_xEntrySearch->get_text();
351 utl::TextSearch textSearch(m_pAdditionsDialog->m_searchOptions);
352
353 size_t nIteration = 0;
354 for (auto& rInfo : m_pAdditionsDialog->m_aAllExtensionsVector)
355 {
356 if (m_pAdditionsDialog->m_nCurrentListItemCount == m_pAdditionsDialog->m_nMaxItemCount)
5
Assuming field 'm_nCurrentListItemCount' is not equal to field 'm_nMaxItemCount'
6
Taking false branch
357 break;
358
359 OUString sExtensionName = rInfo.sName;
360 OUString sExtensionDescription = rInfo.sDescription;
361
362 if (!m_pAdditionsDialog->m_xEntrySearch->get_text().isEmpty()
8
Taking false branch
363 && !textSearch.searchForward(sExtensionName)
7
Assuming the condition is false
364 && !textSearch.searchForward(sExtensionDescription))
365 {
366 continue;
367 }
368 else
369 {
370 if (nIteration >= m_pAdditionsDialog->m_nCurrentListItemCount)
9
Assuming 'nIteration' is >= field 'm_nCurrentListItemCount'
10
Taking true branch
371 Append(rInfo);
11
Calling 'SearchAndParseThread::Append'
372 nIteration++;
373 }
374 }
375 CheckInstalledExtensions();
376}
377
378void SearchAndParseThread::CheckInstalledExtensions()
379{
380 uno::Sequence<uno::Sequence<uno::Reference<deployment::XPackage>>> xAllPackages
381 = m_pAdditionsDialog->getInstalledExtensions();
382
383 if (!xAllPackages.hasElements())
384 return;
385
386 OUString currentExtensionName;
387
388 for (auto& package : xAllPackages)
389 {
390 for (auto& extensionVersion : package)
391 {
392 if (extensionVersion.is())
393 {
394 currentExtensionName = extensionVersion->getName();
395 if (currentExtensionName.isEmpty())
396 continue;
397
398 m_pAdditionsDialog->m_searchOptions.searchString = currentExtensionName;
399 utl::TextSearch textSearch(m_pAdditionsDialog->m_searchOptions);
400
401 for (auto& rInfo : m_pAdditionsDialog->m_aAdditionsItems)
402 {
403 OUString sExtensionDownloadURL = rInfo->m_sDownloadURL;
404
405 if (!textSearch.searchForward(sExtensionDownloadURL))
406 {
407 continue;
408 }
409 else
410 {
411 rInfo->m_xButtonInstall->set_sensitive(false);
412 rInfo->m_xButtonInstall->set_label(
413 CuiResId(RID_SVXSTR_ADDITIONS_INSTALLEDBUTTONreinterpret_cast<char const *>("RID_SVXSTR_ADDITIONS_INSTALLEDBUTTON"
"\004" u8"Installed")
));
414 }
415 }
416 }
417 }
418 }
419}
420
421void SearchAndParseThread::execute()
422{
423 OUString sProgress;
424 if (m_bIsFirstLoading)
1
Assuming field 'm_bIsFirstLoading' is false
2
Taking false branch
425 sProgress = CuiResId(RID_SVXSTR_ADDITIONS_LOADINGreinterpret_cast<char const *>("RID_SVXSTR_ADDITIONS_LOADING"
"\004" u8"Loading...")
);
426 else
427 sProgress = CuiResId(RID_SVXSTR_ADDITIONS_SEARCHINGreinterpret_cast<char const *>("RID_SVXSTR_ADDITIONS_SEARCHING"
"\004" u8"Searching...")
);
428
429 m_pAdditionsDialog->SetProgress(
430 sProgress); // Loading or searching according to being first call or not
431
432 if (m_bIsFirstLoading
2.1
Field 'm_bIsFirstLoading' is false
2.1
Field 'm_bIsFirstLoading' is false
2.1
Field 'm_bIsFirstLoading' is false
2.1
Field 'm_bIsFirstLoading' is false
)
3
Taking false branch
433 {
434 std::string sResponse = curlGet(m_pAdditionsDialog->m_sURL);
435 parseResponse(sResponse, m_pAdditionsDialog->m_aAllExtensionsVector);
436 std::sort(m_pAdditionsDialog->m_aAllExtensionsVector.begin(),
437 m_pAdditionsDialog->m_aAllExtensionsVector.end(),
438 AdditionsDialog::sortByDownload);
439 Search();
440 }
441 else // Searching
442 {
443 Search();
4
Calling 'SearchAndParseThread::Search'
444 }
445
446 if (!m_bExecute)
447 return;
448
449 SolarMutexGuard aGuard;
450 sProgress.clear();
451 m_pAdditionsDialog->SetProgress(sProgress);
452}
453
454AdditionsDialog::AdditionsDialog(weld::Window* pParent, const OUString& sAdditionsTag)
455 : GenericDialogController(pParent, "cui/ui/additionsdialog.ui", "AdditionsDialog")
456 , m_aSearchDataTimer("SearchDataTimer")
457 , m_xEntrySearch(m_xBuilder->weld_entry("entrySearch"))
458 , m_xButtonClose(m_xBuilder->weld_button("buttonClose"))
459 , m_xMenuButtonSettings(m_xBuilder->weld_menu_button("buttonGear"))
460 , m_xContentWindow(m_xBuilder->weld_scrolled_window("contentWindow"))
461 , m_xContentGrid(m_xBuilder->weld_container("contentGrid"))
462 , m_xLabelProgress(m_xBuilder->weld_label("labelProgress"))
463 , m_xGearBtn(m_xBuilder->weld_menu_button("buttonGear"))
464{
465 m_xGearBtn->connect_selected(LINK(this, AdditionsDialog, GearHdl)::tools::detail::makeLink( ::tools::detail::castTo<AdditionsDialog
*>(this), &AdditionsDialog::LinkStubGearHdl)
);
466 m_xGearBtn->set_item_active("gear_sort_voting", true);
467
468 m_aSearchDataTimer.SetInvokeHandler(LINK(this, AdditionsDialog, ImplUpdateDataHdl)::tools::detail::makeLink( ::tools::detail::castTo<AdditionsDialog
*>(this), &AdditionsDialog::LinkStubImplUpdateDataHdl
)
);
469 m_aSearchDataTimer.SetDebugName("AdditionsDialog SearchDataTimer");
470 m_aSearchDataTimer.SetTimeout(EDIT_UPDATEDATA_TIMEOUT350);
471
472 m_xEntrySearch->connect_changed(LINK(this, AdditionsDialog, SearchUpdateHdl)::tools::detail::makeLink( ::tools::detail::castTo<AdditionsDialog
*>(this), &AdditionsDialog::LinkStubSearchUpdateHdl)
);
473 m_xEntrySearch->connect_focus_out(LINK(this, AdditionsDialog, FocusOut_Impl)::tools::detail::makeLink( ::tools::detail::castTo<AdditionsDialog
*>(this), &AdditionsDialog::LinkStubFocusOut_Impl)
);
474 m_xButtonClose->connect_clicked(LINK(this, AdditionsDialog, CloseButtonHdl)::tools::detail::makeLink( ::tools::detail::castTo<AdditionsDialog
*>(this), &AdditionsDialog::LinkStubCloseButtonHdl)
);
475
476 m_sTag = OUStringToOString(sAdditionsTag, RTL_TEXTENCODING_UTF8(((rtl_TextEncoding) 76)));
477 m_nMaxItemCount = PAGE_SIZE30; // Dialog initialization item count
478 m_nCurrentListItemCount = 0; // First, there is no item on the list.
479
480 OUString titlePrefix = CuiResId(RID_SVXSTR_ADDITIONS_DIALOG_TITLE_PREFIXreinterpret_cast<char const *>("RID_SVXSTR_ADDITIONS_DIALOG_TITLE_PREFIX"
"\004" u8"Extensions")
);
481 if (!m_sTag.isEmpty())
482 {
483 this->set_title(titlePrefix + ": " + sAdditionsTag);
484 }
485 else
486 {
487 this->set_title(titlePrefix);
488 m_sTag = "allextensions"; // Means empty parameter
489 }
490 //FIXME: Temporary URL
491 OString sPrefixURL = "https://yusufketen.com/api/";
492 OString sSuffixURL = ".json";
493 OString rURL = sPrefixURL + m_sTag + sSuffixURL;
494 m_sURL = rURL;
495
496 m_xExtensionManager
497 = deployment::ExtensionManager::get(::comphelper::getProcessComponentContext());
498
499 //Initialize search util
500 m_searchOptions.AlgorithmType2 = css::util::SearchAlgorithms2::ABSOLUTE;
501 m_searchOptions.transliterateFlags |= TransliterationFlags::IGNORE_CASE;
502 m_searchOptions.searchFlag |= (css::util::SearchFlags::REG_NOT_BEGINOFLINE
503 | css::util::SearchFlags::REG_NOT_ENDOFLINE);
504 m_pSearchThread = new SearchAndParseThread(this, true);
505 m_pSearchThread->launch();
506}
507
508AdditionsDialog::~AdditionsDialog()
509{
510 if (m_pSearchThread.is())
511 {
512 m_pSearchThread->StopExecution();
513 // Release the solar mutex, so the thread is not affected by the race
514 // when it's after the m_bExecute check but before taking the solar
515 // mutex.
516 SolarMutexReleaser aReleaser;
517 m_pSearchThread->join();
518 }
519}
520
521uno::Sequence<uno::Sequence<uno::Reference<deployment::XPackage>>>
522AdditionsDialog::getInstalledExtensions()
523{
524 uno::Sequence<uno::Sequence<uno::Reference<deployment::XPackage>>> xAllPackages;
525
526 try
527 {
528 xAllPackages = m_xExtensionManager->getAllExtensions(
529 uno::Reference<task::XAbortChannel>(), uno::Reference<ucb::XCommandEnvironment>());
530 }
531 catch (const deployment::DeploymentException&)
532 {
533 TOOLS_WARN_EXCEPTION("cui.dialogs", "")do { css::uno::Any tools_warn_exception( DbgGetCaughtException
() ); do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_WARN
, "cui.dialogs")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break;
case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult
( ::sal::detail::StreamStart() << "" << " " <<
exceptionToString(tools_warn_exception)) == 1) { ::sal_detail_log
( (::SAL_DETAIL_LOG_LEVEL_WARN), ("cui.dialogs"), ("/home/maarten/src/libreoffice/core/cui/source/dialogs/AdditionsDialog.cxx"
":" "533" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "" << " " << exceptionToString
(tools_warn_exception)), 0); } else { ::std::ostringstream sal_detail_stream
; sal_detail_stream << "" << " " << exceptionToString
(tools_warn_exception); ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN
), ("cui.dialogs"), ("/home/maarten/src/libreoffice/core/cui/source/dialogs/AdditionsDialog.cxx"
":" "533" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "" << " " << exceptionToString(tools_warn_exception
)) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), (
"cui.dialogs"), ("/home/maarten/src/libreoffice/core/cui/source/dialogs/AdditionsDialog.cxx"
":" "533" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "" << " " << exceptionToString
(tools_warn_exception)), 0); } else { ::std::ostringstream sal_detail_stream
; sal_detail_stream << "" << " " << exceptionToString
(tools_warn_exception); ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN
), ("cui.dialogs"), ("/home/maarten/src/libreoffice/core/cui/source/dialogs/AdditionsDialog.cxx"
":" "533" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false); } while (false)
;
534 }
535 catch (const ucb::CommandFailedException&)
536 {
537 TOOLS_WARN_EXCEPTION("cui.dialogs", "")do { css::uno::Any tools_warn_exception( DbgGetCaughtException
() ); do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_WARN
, "cui.dialogs")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break;
case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult
( ::sal::detail::StreamStart() << "" << " " <<
exceptionToString(tools_warn_exception)) == 1) { ::sal_detail_log
( (::SAL_DETAIL_LOG_LEVEL_WARN), ("cui.dialogs"), ("/home/maarten/src/libreoffice/core/cui/source/dialogs/AdditionsDialog.cxx"
":" "537" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "" << " " << exceptionToString
(tools_warn_exception)), 0); } else { ::std::ostringstream sal_detail_stream
; sal_detail_stream << "" << " " << exceptionToString
(tools_warn_exception); ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN
), ("cui.dialogs"), ("/home/maarten/src/libreoffice/core/cui/source/dialogs/AdditionsDialog.cxx"
":" "537" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "" << " " << exceptionToString(tools_warn_exception
)) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), (
"cui.dialogs"), ("/home/maarten/src/libreoffice/core/cui/source/dialogs/AdditionsDialog.cxx"
":" "537" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "" << " " << exceptionToString
(tools_warn_exception)), 0); } else { ::std::ostringstream sal_detail_stream
; sal_detail_stream << "" << " " << exceptionToString
(tools_warn_exception); ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN
), ("cui.dialogs"), ("/home/maarten/src/libreoffice/core/cui/source/dialogs/AdditionsDialog.cxx"
":" "537" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false); } while (false)
;
538 }
539 catch (const ucb::CommandAbortedException&)
540 {
541 TOOLS_WARN_EXCEPTION("cui.dialogs", "")do { css::uno::Any tools_warn_exception( DbgGetCaughtException
() ); do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_WARN
, "cui.dialogs")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break;
case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult
( ::sal::detail::StreamStart() << "" << " " <<
exceptionToString(tools_warn_exception)) == 1) { ::sal_detail_log
( (::SAL_DETAIL_LOG_LEVEL_WARN), ("cui.dialogs"), ("/home/maarten/src/libreoffice/core/cui/source/dialogs/AdditionsDialog.cxx"
":" "541" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "" << " " << exceptionToString
(tools_warn_exception)), 0); } else { ::std::ostringstream sal_detail_stream
; sal_detail_stream << "" << " " << exceptionToString
(tools_warn_exception); ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN
), ("cui.dialogs"), ("/home/maarten/src/libreoffice/core/cui/source/dialogs/AdditionsDialog.cxx"
":" "541" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "" << " " << exceptionToString(tools_warn_exception
)) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), (
"cui.dialogs"), ("/home/maarten/src/libreoffice/core/cui/source/dialogs/AdditionsDialog.cxx"
":" "541" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "" << " " << exceptionToString
(tools_warn_exception)), 0); } else { ::std::ostringstream sal_detail_stream
; sal_detail_stream << "" << " " << exceptionToString
(tools_warn_exception); ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN
), ("cui.dialogs"), ("/home/maarten/src/libreoffice/core/cui/source/dialogs/AdditionsDialog.cxx"
":" "541" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false); } while (false)
;
542 }
543 catch (const lang::IllegalArgumentException& e)
544 {
545 css::uno::Any anyEx = cppu::getCaughtException();
546 throw css::lang::WrappedTargetRuntimeException(e.Message, e.Context, anyEx);
547 }
548 return xAllPackages;
549}
550
551void AdditionsDialog::SetProgress(const OUString& rProgress)
552{
553 if (rProgress.isEmpty())
554 m_xLabelProgress->hide();
555 else
556 {
557 SolarMutexGuard aGuard;
558 m_xLabelProgress->show();
559 m_xLabelProgress->set_label(rProgress);
560 m_xDialog->resize_to_request(); //TODO
561 }
562}
563
564void AdditionsDialog::ClearList()
565{
566 // for VCL to be able to destroy bitmaps
567 SolarMutexGuard aGuard;
568
569 for (auto& item : this->m_aAdditionsItems)
570 {
571 item->m_xContainer->hide();
572 }
573 this->m_aAdditionsItems.clear();
574}
575
576void AdditionsDialog::RefreshUI()
577{
578 if (m_pSearchThread.is())
579 m_pSearchThread->StopExecution();
580 ClearList();
581 m_nCurrentListItemCount = 0;
582 m_nMaxItemCount = PAGE_SIZE30;
583 m_pSearchThread = new SearchAndParseThread(this, false);
584 m_pSearchThread->launch();
585}
586
587bool AdditionsDialog::sortByRating(const AdditionInfo& a, const AdditionInfo& b)
588{
589 return a.sRating.toDouble() > b.sRating.toDouble();
590}
591
592bool AdditionsDialog::sortByComment(const AdditionInfo& a, const AdditionInfo& b)
593{
594 return a.sCommentNumber.toUInt32() > b.sCommentNumber.toUInt32();
595}
596
597bool AdditionsDialog::sortByDownload(const AdditionInfo& a, const AdditionInfo& b)
598{
599 return a.sDownloadNumber.toUInt32() > b.sDownloadNumber.toUInt32();
600}
601
602AdditionsItem::AdditionsItem(weld::Widget* pParent, AdditionsDialog* pParentDialog,
603 const AdditionInfo& additionInfo)
604 : m_xBuilder(Application::CreateBuilder(pParent, "cui/ui/additionsfragment.ui"))
605 , m_xContainer(m_xBuilder->weld_widget("additionsEntry"))
606 , m_xImageScreenshot(m_xBuilder->weld_image("imageScreenshot"))
607 , m_xButtonInstall(m_xBuilder->weld_button("buttonInstall"))
608 , m_xLinkButtonName(m_xBuilder->weld_link_button("linkButtonName"))
609 , m_xLabelAuthor(m_xBuilder->weld_label("labelAuthor"))
610 , m_xLabelDesc(m_xBuilder->weld_label("labelDesc")) // no change (print description)
611 , m_xLabelDescription(m_xBuilder->weld_label("labelDescription"))
612 , m_xLabelLicense(m_xBuilder->weld_label("labelLicense"))
613 , m_xLabelVersion(m_xBuilder->weld_label("labelVersion"))
614 , m_xLabelComments(m_xBuilder->weld_label("labelComments")) // no change
615 , m_xLinkButtonComments(m_xBuilder->weld_link_button("linkButtonComments"))
616 , m_xImageVoting1(m_xBuilder->weld_image("imageVoting1"))
617 , m_xImageVoting2(m_xBuilder->weld_image("imageVoting2"))
618 , m_xImageVoting3(m_xBuilder->weld_image("imageVoting3"))
619 , m_xImageVoting4(m_xBuilder->weld_image("imageVoting4"))
620 , m_xImageVoting5(m_xBuilder->weld_image("imageVoting5"))
621 , m_xLabelNoVoting(m_xBuilder->weld_label("votingLabel"))
622 , m_xImageDownloadNumber(m_xBuilder->weld_image("imageDownloadNumber"))
623 , m_xLabelDownloadNumber(m_xBuilder->weld_label("labelDownloadNumber"))
624 , m_xButtonShowMore(m_xBuilder->weld_button("buttonShowMore"))
625 , m_pParentDialog(pParentDialog)
626 , m_sDownloadURL("")
627 , m_sExtensionID("")
628{
629 SolarMutexGuard aGuard;
630
631 // AdditionsItem set location
632 m_xContainer->set_grid_left_attach(0);
633 m_xContainer->set_grid_top_attach(pParentDialog->m_aAdditionsItems.size() - 1);
634
635 // Set maximum length of the extension title
636 OUString sExtensionName;
637 const sal_Int32 maxExtensionNameLength = 30;
638
639 if (additionInfo.sName.getLength() > maxExtensionNameLength)
640 {
641 OUString sShortName = additionInfo.sName.copy(0, maxExtensionNameLength - 3);
642 sExtensionName = sShortName + "...";
643 }
644 else
645 {
646 sExtensionName = additionInfo.sName;
647 }
648
649 m_xLinkButtonName->set_label(sExtensionName);
650
651 double aExtensionRating = additionInfo.sRating.toDouble();
652 switch (int(aExtensionRating))
653 {
654 case 5:
655 m_xImageVoting5->show();
656 [[fallthrough]];
657 case 4:
658 m_xImageVoting4->show();
659 [[fallthrough]];
660 case 3:
661 m_xImageVoting3->show();
662 [[fallthrough]];
663 case 2:
664 m_xImageVoting2->show();
665 [[fallthrough]];
666 case 1:
667 m_xImageVoting1->show();
668 break;
669 case 0:
670 m_xLabelNoVoting->show();
671 break;
672 }
673
674 m_xLinkButtonName->set_uri(additionInfo.sExtensionURL);
675 m_xLabelDescription->set_label(additionInfo.sIntroduction);
676
677 if (!additionInfo.sAuthorName.equalsIgnoreAsciiCase("null"))
678 m_xLabelAuthor->set_label(additionInfo.sAuthorName);
679
680 m_xButtonInstall->set_label(CuiResId(RID_SVXSTR_ADDITIONS_INSTALLBUTTONreinterpret_cast<char const *>("RID_SVXSTR_ADDITIONS_INSTALLBUTTON"
"\004" u8"Install")
));
681 OUString sLicenseString = CuiResId(RID_SVXSTR_ADDITIONS_LICENCEreinterpret_cast<char const *>("RID_SVXSTR_ADDITIONS_LICENCE"
"\004" u8"License:")
) + additionInfo.sLicense;
682 m_xLabelLicense->set_label(sLicenseString);
683 OUString sVersionString
684 = CuiResId(RID_SVXSTR_ADDITIONS_REQUIREDVERSIONreinterpret_cast<char const *>("RID_SVXSTR_ADDITIONS_REQUIREDVERSION"
"\004" u8"Required version: >=")
) + additionInfo.sCompatibleVersion;
685 m_xLabelVersion->set_label(sVersionString);
686 m_xLinkButtonComments->set_label(additionInfo.sCommentNumber);
687 m_xLinkButtonComments->set_uri(additionInfo.sCommentURL);
688 m_xLabelDownloadNumber->set_label(additionInfo.sDownloadNumber);
689 m_pParentDialog = pParentDialog;
690 m_sDownloadURL = additionInfo.sDownloadURL;
691 m_sExtensionID = additionInfo.sExtensionID;
692
693 m_xButtonShowMore->connect_clicked(LINK(this, AdditionsItem, ShowMoreHdl)::tools::detail::makeLink( ::tools::detail::castTo<AdditionsItem
*>(this), &AdditionsItem::LinkStubShowMoreHdl)
);
694 m_xButtonInstall->connect_clicked(LINK(this, AdditionsItem, InstallHdl)::tools::detail::makeLink( ::tools::detail::castTo<AdditionsItem
*>(this), &AdditionsItem::LinkStubInstallHdl)
);
695}
696
697bool AdditionsItem::getExtensionFile(OUString& sExtensionFile)
698{
699 uno::Reference<ucb::XSimpleFileAccess3> xFileAccess
700 = ucb::SimpleFileAccess::create(comphelper::getProcessComponentContext());
701
702 // copy the extensions' files to the user's additions folder
703 OUString userFolder = "${$BRAND_BASE_DIR/" LIBO_ETC_FOLDER"program"
704 "/" SAL_CONFIGFILE("bootstrap")"bootstrap" "rc" "::UserInstallation}";
705 rtl::Bootstrap::expandMacros(userFolder);
706 userFolder += "/user/additions/" + m_sExtensionID + "/";
707
708 OUString aExtesionsFile(INetURLObject(m_sDownloadURL).getName());
709 OString aExtesionsURL = OUStringToOString(m_sDownloadURL, RTL_TEXTENCODING_UTF8(((rtl_TextEncoding) 76)));
710
711 try
712 {
713 osl::Directory::createPath(userFolder);
714
715 if (!xFileAccess->exists(userFolder + aExtesionsFile))
716 curlDownload(aExtesionsURL, userFolder + aExtesionsFile);
717 }
718 catch (const uno::Exception&)
719 {
720 return false;
721 }
722 sExtensionFile = userFolder + aExtesionsFile;
723 return true;
724}
725
726IMPL_LINK_NOARG(AdditionsDialog, ImplUpdateDataHdl, Timer*, void)void AdditionsDialog::LinkStubImplUpdateDataHdl(void * instance
, Timer* data) { return static_cast<AdditionsDialog *>(
instance)->ImplUpdateDataHdl(data); } void AdditionsDialog
::ImplUpdateDataHdl(__attribute__ ((unused)) Timer*)
{ RefreshUI(); }
727
728IMPL_LINK_NOARG(AdditionsDialog, SearchUpdateHdl, weld::Entry&, void)void AdditionsDialog::LinkStubSearchUpdateHdl(void * instance
, weld::Entry& data) { return static_cast<AdditionsDialog
*>(instance)->SearchUpdateHdl(data); } void AdditionsDialog
::SearchUpdateHdl(__attribute__ ((unused)) weld::Entry&)
729{
730 m_aSearchDataTimer.Start();
731}
732
733IMPL_LINK_NOARG(AdditionsDialog, FocusOut_Impl, weld::Widget&, void)void AdditionsDialog::LinkStubFocusOut_Impl(void * instance, weld
::Widget& data) { return static_cast<AdditionsDialog *
>(instance)->FocusOut_Impl(data); } void AdditionsDialog
::FocusOut_Impl(__attribute__ ((unused)) weld::Widget&)
734{
735 if (m_aSearchDataTimer.IsActive())
736 {
737 m_aSearchDataTimer.Stop();
738 m_aSearchDataTimer.Invoke();
739 }
740}
741
742IMPL_LINK_NOARG(AdditionsDialog, CloseButtonHdl, weld::Button&, void)void AdditionsDialog::LinkStubCloseButtonHdl(void * instance,
weld::Button& data) { return static_cast<AdditionsDialog
*>(instance)->CloseButtonHdl(data); } void AdditionsDialog
::CloseButtonHdl(__attribute__ ((unused)) weld::Button&)
743{
744 if (m_pSearchThread.is())
745 m_pSearchThread->StopExecution();
746 this->response(RET_CLOSE);
747}
748
749IMPL_LINK_NOARG(AdditionsItem, ShowMoreHdl, weld::Button&, void)void AdditionsItem::LinkStubShowMoreHdl(void * instance, weld
::Button& data) { return static_cast<AdditionsItem *>
(instance)->ShowMoreHdl(data); } void AdditionsItem::ShowMoreHdl
(__attribute__ ((unused)) weld::Button&)
750{
751 this->m_xButtonShowMore->set_visible(false);
752 m_pParentDialog->m_nMaxItemCount += PAGE_SIZE30;
753 if (m_pParentDialog->m_pSearchThread.is())
754 m_pParentDialog->m_pSearchThread->StopExecution();
755 m_pParentDialog->m_pSearchThread = new SearchAndParseThread(m_pParentDialog, false);
756 m_pParentDialog->m_pSearchThread->launch();
757}
758
759IMPL_LINK_NOARG(AdditionsItem, InstallHdl, weld::Button&, void)void AdditionsItem::LinkStubInstallHdl(void * instance, weld::
Button& data) { return static_cast<AdditionsItem *>
(instance)->InstallHdl(data); } void AdditionsItem::InstallHdl
(__attribute__ ((unused)) weld::Button&)
760{
761 m_xButtonInstall->set_label(CuiResId(RID_SVXSTR_ADDITIONS_INSTALLINGreinterpret_cast<char const *>("RID_SVXSTR_ADDITIONS_INSTALLING"
"\004" u8"Installing")
));
762 m_xButtonInstall->set_sensitive(false);
763 OUString aExtensionFile;
764 bool bResult = getExtensionFile(aExtensionFile); // info vector json data
765
766 if (!bResult)
767 {
768 m_xButtonInstall->set_label(CuiResId(RID_SVXSTR_ADDITIONS_INSTALLBUTTONreinterpret_cast<char const *>("RID_SVXSTR_ADDITIONS_INSTALLBUTTON"
"\004" u8"Install")
));
769 m_xButtonInstall->set_sensitive(true);
770
771 SAL_INFO("cui.dialogs", "Couldn't get the extension file.")do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_INFO
, "cui.dialogs")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break;
case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult
( ::sal::detail::StreamStart() << "Couldn't get the extension file."
) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("cui.dialogs"
), ("/home/maarten/src/libreoffice/core/cui/source/dialogs/AdditionsDialog.cxx"
":" "771" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "Couldn't get the extension file."), 0
); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "Couldn't get the extension file."; ::sal::detail::
log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("cui.dialogs"), ("/home/maarten/src/libreoffice/core/cui/source/dialogs/AdditionsDialog.cxx"
":" "771" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "Couldn't get the extension file.") == 1) { ::sal_detail_log
( (::SAL_DETAIL_LOG_LEVEL_INFO), ("cui.dialogs"), ("/home/maarten/src/libreoffice/core/cui/source/dialogs/AdditionsDialog.cxx"
":" "771" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "Couldn't get the extension file."), 0
); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "Couldn't get the extension file."; ::sal::detail::
log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("cui.dialogs"), ("/home/maarten/src/libreoffice/core/cui/source/dialogs/AdditionsDialog.cxx"
":" "771" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false)
;
772 return;
773 }
774
775 TmpRepositoryCommandEnv* pCmdEnv = new TmpRepositoryCommandEnv();
776 uno::Reference<ucb::XCommandEnvironment> xCmdEnv(static_cast<cppu::OWeakObject*>(pCmdEnv),
777 uno::UNO_QUERY);
778 uno::Reference<task::XAbortChannel> xAbortChannel;
779 try
780 {
781 m_pParentDialog->m_xExtensionManager->addExtension(
782 aExtensionFile, uno::Sequence<beans::NamedValue>(), "user", xAbortChannel, xCmdEnv);
783 m_xButtonInstall->set_label(CuiResId(RID_SVXSTR_ADDITIONS_INSTALLEDBUTTONreinterpret_cast<char const *>("RID_SVXSTR_ADDITIONS_INSTALLEDBUTTON"
"\004" u8"Installed")
));
784 }
785 catch (const ucb::CommandFailedException)
786 {
787 TOOLS_WARN_EXCEPTION("cui.dialogs", "")do { css::uno::Any tools_warn_exception( DbgGetCaughtException
() ); do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_WARN
, "cui.dialogs")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break;
case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult
( ::sal::detail::StreamStart() << "" << " " <<
exceptionToString(tools_warn_exception)) == 1) { ::sal_detail_log
( (::SAL_DETAIL_LOG_LEVEL_WARN), ("cui.dialogs"), ("/home/maarten/src/libreoffice/core/cui/source/dialogs/AdditionsDialog.cxx"
":" "787" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "" << " " << exceptionToString
(tools_warn_exception)), 0); } else { ::std::ostringstream sal_detail_stream
; sal_detail_stream << "" << " " << exceptionToString
(tools_warn_exception); ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN
), ("cui.dialogs"), ("/home/maarten/src/libreoffice/core/cui/source/dialogs/AdditionsDialog.cxx"
":" "787" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "" << " " << exceptionToString(tools_warn_exception
)) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), (
"cui.dialogs"), ("/home/maarten/src/libreoffice/core/cui/source/dialogs/AdditionsDialog.cxx"
":" "787" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "" << " " << exceptionToString
(tools_warn_exception)), 0); } else { ::std::ostringstream sal_detail_stream
; sal_detail_stream << "" << " " << exceptionToString
(tools_warn_exception); ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN
), ("cui.dialogs"), ("/home/maarten/src/libreoffice/core/cui/source/dialogs/AdditionsDialog.cxx"
":" "787" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false); } while (false)
;
788 m_xButtonInstall->set_label(CuiResId(RID_SVXSTR_ADDITIONS_INSTALLBUTTONreinterpret_cast<char const *>("RID_SVXSTR_ADDITIONS_INSTALLBUTTON"
"\004" u8"Install")
));
789 m_xButtonInstall->set_sensitive(true);
790 }
791 catch (const ucb::CommandAbortedException)
792 {
793 TOOLS_WARN_EXCEPTION("cui.dialogs", "")do { css::uno::Any tools_warn_exception( DbgGetCaughtException
() ); do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_WARN
, "cui.dialogs")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break;
case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult
( ::sal::detail::StreamStart() << "" << " " <<
exceptionToString(tools_warn_exception)) == 1) { ::sal_detail_log
( (::SAL_DETAIL_LOG_LEVEL_WARN), ("cui.dialogs"), ("/home/maarten/src/libreoffice/core/cui/source/dialogs/AdditionsDialog.cxx"
":" "793" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "" << " " << exceptionToString
(tools_warn_exception)), 0); } else { ::std::ostringstream sal_detail_stream
; sal_detail_stream << "" << " " << exceptionToString
(tools_warn_exception); ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN
), ("cui.dialogs"), ("/home/maarten/src/libreoffice/core/cui/source/dialogs/AdditionsDialog.cxx"
":" "793" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "" << " " << exceptionToString(tools_warn_exception
)) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), (
"cui.dialogs"), ("/home/maarten/src/libreoffice/core/cui/source/dialogs/AdditionsDialog.cxx"
":" "793" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "" << " " << exceptionToString
(tools_warn_exception)), 0); } else { ::std::ostringstream sal_detail_stream
; sal_detail_stream << "" << " " << exceptionToString
(tools_warn_exception); ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN
), ("cui.dialogs"), ("/home/maarten/src/libreoffice/core/cui/source/dialogs/AdditionsDialog.cxx"
":" "793" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false); } while (false)
;
794 m_xButtonInstall->set_label(CuiResId(RID_SVXSTR_ADDITIONS_INSTALLBUTTONreinterpret_cast<char const *>("RID_SVXSTR_ADDITIONS_INSTALLBUTTON"
"\004" u8"Install")
));
795 m_xButtonInstall->set_sensitive(true);
796 }
797 catch (const deployment::DeploymentException)
798 {
799 TOOLS_WARN_EXCEPTION("cui.dialogs", "")do { css::uno::Any tools_warn_exception( DbgGetCaughtException
() ); do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_WARN
, "cui.dialogs")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break;
case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult
( ::sal::detail::StreamStart() << "" << " " <<
exceptionToString(tools_warn_exception)) == 1) { ::sal_detail_log
( (::SAL_DETAIL_LOG_LEVEL_WARN), ("cui.dialogs"), ("/home/maarten/src/libreoffice/core/cui/source/dialogs/AdditionsDialog.cxx"
":" "799" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "" << " " << exceptionToString
(tools_warn_exception)), 0); } else { ::std::ostringstream sal_detail_stream
; sal_detail_stream << "" << " " << exceptionToString
(tools_warn_exception); ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN
), ("cui.dialogs"), ("/home/maarten/src/libreoffice/core/cui/source/dialogs/AdditionsDialog.cxx"
":" "799" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "" << " " << exceptionToString(tools_warn_exception
)) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), (
"cui.dialogs"), ("/home/maarten/src/libreoffice/core/cui/source/dialogs/AdditionsDialog.cxx"
":" "799" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "" << " " << exceptionToString
(tools_warn_exception)), 0); } else { ::std::ostringstream sal_detail_stream
; sal_detail_stream << "" << " " << exceptionToString
(tools_warn_exception); ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN
), ("cui.dialogs"), ("/home/maarten/src/libreoffice/core/cui/source/dialogs/AdditionsDialog.cxx"
":" "799" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false); } while (false)
;
800 m_xButtonInstall->set_label(CuiResId(RID_SVXSTR_ADDITIONS_INSTALLBUTTONreinterpret_cast<char const *>("RID_SVXSTR_ADDITIONS_INSTALLBUTTON"
"\004" u8"Install")
));
801 m_xButtonInstall->set_sensitive(true);
802 }
803 catch (const lang::IllegalArgumentException)
804 {
805 TOOLS_WARN_EXCEPTION("cui.dialogs", "")do { css::uno::Any tools_warn_exception( DbgGetCaughtException
() ); do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_WARN
, "cui.dialogs")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break;
case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult
( ::sal::detail::StreamStart() << "" << " " <<
exceptionToString(tools_warn_exception)) == 1) { ::sal_detail_log
( (::SAL_DETAIL_LOG_LEVEL_WARN), ("cui.dialogs"), ("/home/maarten/src/libreoffice/core/cui/source/dialogs/AdditionsDialog.cxx"
":" "805" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "" << " " << exceptionToString
(tools_warn_exception)), 0); } else { ::std::ostringstream sal_detail_stream
; sal_detail_stream << "" << " " << exceptionToString
(tools_warn_exception); ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN
), ("cui.dialogs"), ("/home/maarten/src/libreoffice/core/cui/source/dialogs/AdditionsDialog.cxx"
":" "805" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "" << " " << exceptionToString(tools_warn_exception
)) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), (
"cui.dialogs"), ("/home/maarten/src/libreoffice/core/cui/source/dialogs/AdditionsDialog.cxx"
":" "805" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "" << " " << exceptionToString
(tools_warn_exception)), 0); } else { ::std::ostringstream sal_detail_stream
; sal_detail_stream << "" << " " << exceptionToString
(tools_warn_exception); ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN
), ("cui.dialogs"), ("/home/maarten/src/libreoffice/core/cui/source/dialogs/AdditionsDialog.cxx"
":" "805" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false); } while (false)
;
806 m_xButtonInstall->set_label(CuiResId(RID_SVXSTR_ADDITIONS_INSTALLBUTTONreinterpret_cast<char const *>("RID_SVXSTR_ADDITIONS_INSTALLBUTTON"
"\004" u8"Install")
));
807 m_xButtonInstall->set_sensitive(true);
808 }
809 catch (const css::uno::Exception)
810 {
811 TOOLS_WARN_EXCEPTION("cui.dialogs", "")do { css::uno::Any tools_warn_exception( DbgGetCaughtException
() ); do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_WARN
, "cui.dialogs")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break;
case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult
( ::sal::detail::StreamStart() << "" << " " <<
exceptionToString(tools_warn_exception)) == 1) { ::sal_detail_log
( (::SAL_DETAIL_LOG_LEVEL_WARN), ("cui.dialogs"), ("/home/maarten/src/libreoffice/core/cui/source/dialogs/AdditionsDialog.cxx"
":" "811" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "" << " " << exceptionToString
(tools_warn_exception)), 0); } else { ::std::ostringstream sal_detail_stream
; sal_detail_stream << "" << " " << exceptionToString
(tools_warn_exception); ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN
), ("cui.dialogs"), ("/home/maarten/src/libreoffice/core/cui/source/dialogs/AdditionsDialog.cxx"
":" "811" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "" << " " << exceptionToString(tools_warn_exception
)) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), (
"cui.dialogs"), ("/home/maarten/src/libreoffice/core/cui/source/dialogs/AdditionsDialog.cxx"
":" "811" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "" << " " << exceptionToString
(tools_warn_exception)), 0); } else { ::std::ostringstream sal_detail_stream
; sal_detail_stream << "" << " " << exceptionToString
(tools_warn_exception); ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN
), ("cui.dialogs"), ("/home/maarten/src/libreoffice/core/cui/source/dialogs/AdditionsDialog.cxx"
":" "811" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false); } while (false)
;
812 m_xButtonInstall->set_label(CuiResId(RID_SVXSTR_ADDITIONS_INSTALLBUTTONreinterpret_cast<char const *>("RID_SVXSTR_ADDITIONS_INSTALLBUTTON"
"\004" u8"Install")
));
813 m_xButtonInstall->set_sensitive(true);
814 }
815}
816
817// TmpRepositoryCommandEnv
818
819TmpRepositoryCommandEnv::TmpRepositoryCommandEnv() {}
820
821TmpRepositoryCommandEnv::~TmpRepositoryCommandEnv() {}
822// XCommandEnvironment
823
824uno::Reference<task::XInteractionHandler> TmpRepositoryCommandEnv::getInteractionHandler()
825{
826 return this;
827}
828
829uno::Reference<ucb::XProgressHandler> TmpRepositoryCommandEnv::getProgressHandler() { return this; }
830
831// XInteractionHandler
832void TmpRepositoryCommandEnv::handle(uno::Reference<task::XInteractionRequest> const& xRequest)
833{
834 OSL_ASSERT(xRequest->getRequest().getValueTypeClass() == uno::TypeClass_EXCEPTION)do { if (true && (!(xRequest->getRequest().getValueTypeClass
() == uno::TypeClass_EXCEPTION))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN
), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/cui/source/dialogs/AdditionsDialog.cxx"
":" "834" ": "), "OSL_ASSERT: %s", "xRequest->getRequest().getValueTypeClass() == uno::TypeClass_EXCEPTION"
); } } while (false)
;
835
836 bool approve = true;
837
838 // select:
839 uno::Sequence<Reference<task::XInteractionContinuation>> conts(xRequest->getContinuations());
840 Reference<task::XInteractionContinuation> const* pConts = conts.getConstArray();
841 sal_Int32 len = conts.getLength();
842 for (sal_Int32 pos = 0; pos < len; ++pos)
843 {
844 if (approve)
845 {
846 uno::Reference<task::XInteractionApprove> xInteractionApprove(pConts[pos],
847 uno::UNO_QUERY);
848 if (xInteractionApprove.is())
849 {
850 xInteractionApprove->select();
851 // don't query again for ongoing continuations:
852 approve = false;
853 }
854 }
855 }
856}
857
858// XProgressHandler
859void TmpRepositoryCommandEnv::push(uno::Any const& /*Status*/) {}
860
861void TmpRepositoryCommandEnv::update(uno::Any const& /*Status */) {}
862
863void TmpRepositoryCommandEnv::pop() {}
864
865IMPL_LINK(AdditionsDialog, GearHdl, const OString&, rIdent, void)void AdditionsDialog::LinkStubGearHdl(void * instance, const OString
& data) { return static_cast<AdditionsDialog *>(instance
)->GearHdl(data); } void AdditionsDialog::GearHdl(const OString
& rIdent)
866{
867 if (rIdent == "gear_sort_voting")
868 {
869 std::sort(m_aAllExtensionsVector.begin(), m_aAllExtensionsVector.end(), sortByRating);
870 }
871 else if (rIdent == "gear_sort_comments")
872 {
873 std::sort(m_aAllExtensionsVector.begin(), m_aAllExtensionsVector.end(), sortByComment);
874 }
875 else if (rIdent == "gear_sort_downloads")
876 {
877 std::sort(m_aAllExtensionsVector.begin(), m_aAllExtensionsVector.end(), sortByDownload);
878 }
879 // After the sorting, UI will be refreshed to update extension list.
880 RefreshUI();
881}
882/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

/home/maarten/src/libreoffice/core/include/vcl/vclptr.hxx

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#ifndef INCLUDED_VCL_PTR_HXX
21#define INCLUDED_VCL_PTR_HXX
22
23#include <sal/config.h>
24
25#include <rtl/ref.hxx>
26
27#include <utility>
28#include <type_traits>
29
30#ifdef DBG_UTIL
31#ifndef _WIN32
32#include <vcl/vclmain.hxx>
33#endif
34#endif
35
36class VclReferenceBase;
37
38namespace vcl::detail {
39
40template<typename>
41constexpr bool isIncompleteOrDerivedFromVclReferenceBase(...) { return true; }
42
43template<typename T> constexpr bool isIncompleteOrDerivedFromVclReferenceBase(
44 int (*)[sizeof(T)])
45{ return std::is_base_of<VclReferenceBase, T>::value; }
46
47} // namespace vcl::detail
48
49/**
50 * A thin wrapper around rtl::Reference to implement the acquire and dispose semantics we want for references to vcl::Window subclasses.
51 *
52 * For more details on the design please see vcl/README.lifecycle
53 *
54 * @param reference_type must be a subclass of vcl::Window
55 */
56template <class reference_type>
57class VclPtr
58{
59 static_assert(
60 vcl::detail::isIncompleteOrDerivedFromVclReferenceBase<reference_type>(
61 nullptr),
62 "template argument type must be derived from VclReferenceBase");
63
64 ::rtl::Reference<reference_type> m_rInnerRef;
65
66public:
67 /** Constructor...
68 */
69 VclPtr()
70 : m_rInnerRef()
71 {}
72
73 /** Constructor...
74 */
75 VclPtr (reference_type * pBody)
76 : m_rInnerRef(pBody)
77 {}
78
79 /** Constructor... that doesn't take a ref.
80 */
81 VclPtr (reference_type * pBody, __sal_NoAcquire)
82 : m_rInnerRef(pBody, SAL_NO_ACQUIRE)
83 {}
84
85 /** Up-casting conversion constructor: Copies interface reference.
86
87 Does not work for up-casts to ambiguous bases. For the special case of
88 up-casting to Reference< XInterface >, see the corresponding conversion
89 operator.
90
91 @param rRef another reference
92 */
93 template< class derived_type >
94 VclPtr(
95 const VclPtr< derived_type > & rRef,
96 typename std::enable_if<
97 std::is_base_of<reference_type, derived_type>::value, int>::type
98 = 0 )
99 : m_rInnerRef( static_cast<reference_type*>(rRef) )
100 {
101 }
102
103#if defined(DBG_UTIL) && !defined(_WIN32)
104 virtual ~VclPtr()
105 {
106 assert(m_rInnerRef.get() == nullptr || vclmain::isAlive())(static_cast <bool> (m_rInnerRef.get() == nullptr || vclmain
::isAlive()) ? void (0) : __assert_fail ("m_rInnerRef.get() == nullptr || vclmain::isAlive()"
, "/home/maarten/src/libreoffice/core/include/vcl/vclptr.hxx"
, 106, __extension__ __PRETTY_FUNCTION__))
;
107 // We can be one of the intermediate counts, but if we are the last
108 // VclPtr keeping this object alive, then something forgot to call dispose().
109 assert((!m_rInnerRef.get() || m_rInnerRef->isDisposed() || m_rInnerRef->getRefCount() > 1)(static_cast <bool> ((!m_rInnerRef.get() || m_rInnerRef
->isDisposed() || m_rInnerRef->getRefCount() > 1) &&
"someone forgot to call dispose()") ? void (0) : __assert_fail
("(!m_rInnerRef.get() || m_rInnerRef->isDisposed() || m_rInnerRef->getRefCount() > 1) && \"someone forgot to call dispose()\""
, "/home/maarten/src/libreoffice/core/include/vcl/vclptr.hxx"
, 110, __extension__ __PRETTY_FUNCTION__))
110 && "someone forgot to call dispose()")(static_cast <bool> ((!m_rInnerRef.get() || m_rInnerRef
->isDisposed() || m_rInnerRef->getRefCount() > 1) &&
"someone forgot to call dispose()") ? void (0) : __assert_fail
("(!m_rInnerRef.get() || m_rInnerRef->isDisposed() || m_rInnerRef->getRefCount() > 1) && \"someone forgot to call dispose()\""
, "/home/maarten/src/libreoffice/core/include/vcl/vclptr.hxx"
, 110, __extension__ __PRETTY_FUNCTION__))
;
111 }
112 VclPtr(VclPtr const &) = default;
113 VclPtr(VclPtr &&) = default;
114 VclPtr & operator =(VclPtr const &) = default;
115 VclPtr & operator =(VclPtr &&) = default;
116#endif
117
118 /**
119 * A construction helper for VclPtr. Since VclPtr types are created
120 * with a reference-count of one - to help fit into the existing
121 * code-flow; this helps us to construct them easily.
122 *
123 * For more details on the design please see vcl/README.lifecycle
124 *
125 * @tparam reference_type must be a subclass of vcl::Window
126 */
127 template<typename... Arg> [[nodiscard]] static VclPtr< reference_type > Create(Arg &&... arg)
128 {
129 return VclPtr< reference_type >( new reference_type(std::forward<Arg>(arg)...), SAL_NO_ACQUIRE );
130 }
131
132 /** Probably most common used: handle->someBodyOp().
133 */
134 reference_type * operator->() const
135 {
136 return m_rInnerRef.get();
35
Calling 'Reference::get'
137 }
138
139 /** Get the body. Can be used instead of operator->().
140 I.e. handle->someBodyOp() and handle.get()->someBodyOp()
141 are the same.
142 */
143 reference_type * get() const
144 {
145 return m_rInnerRef.get();
146 }
147
148 void set(reference_type *pBody)
149 {
150 m_rInnerRef.set(pBody);
151 }
152
153 void reset(reference_type *pBody)
154 {
155 m_rInnerRef.set(pBody);
156 }
157
158 /** Up-casting copy assignment operator.
159
160 Does not work for up-casts to ambiguous bases.
161
162 @param rRef another reference
163 */
164 template<typename derived_type>
165 typename std::enable_if<
166 std::is_base_of<reference_type, derived_type>::value,
167 VclPtr &>::type
168 operator =(VclPtr<derived_type> const & rRef)
169 {
170 m_rInnerRef.set(rRef.get());
171 return *this;
172 }
173
174 VclPtr & operator =(reference_type * pBody)
175 {
176 m_rInnerRef.set(pBody);
177 return *this;
178 }
179
180 operator reference_type * () const
181 {
182 return m_rInnerRef.get();
183 }
184
185 explicit operator bool () const
186 {
187 return m_rInnerRef.get() != nullptr;
188 }
189
190 void clear()
191 {
192 m_rInnerRef.clear();
193 }
194
195 void reset()
196 {
197 m_rInnerRef.clear();
198 }
199
200 void disposeAndClear()
201 {
202 // hold it alive for the lifetime of this method
203 ::rtl::Reference<reference_type> aTmp(m_rInnerRef);
204 m_rInnerRef.clear(); // we should use some 'swap' method ideally ;-)
205 if (aTmp.get()) {
206 aTmp->disposeOnce();
207 }
208 }
209
210 /** Needed to place VclPtr's into STL collection.
211 */
212 bool operator< (const VclPtr<reference_type> & handle) const
213 {
214 return (m_rInnerRef < handle.m_rInnerRef);
215 }
216}; // class VclPtr
217
218template<typename T1, typename T2>
219inline bool operator ==(VclPtr<T1> const & p1, VclPtr<T2> const & p2) {
220 return p1.get() == p2.get();
221}
222
223template<typename T> inline bool operator ==(VclPtr<T> const & p1, T const * p2)
224{
225 return p1.get() == p2;
226}
227
228template<typename T> inline bool operator ==(VclPtr<T> const & p1, T * p2) {
229 return p1.get() == p2;
230}
231
232template<typename T> inline bool operator ==(T const * p1, VclPtr<T> const & p2)
233{
234 return p1 == p2.get();
235}
236
237template<typename T> inline bool operator ==(T * p1, VclPtr<T> const & p2) {
238 return p1 == p2.get();
239}
240
241template<typename T1, typename T2>
242inline bool operator !=(VclPtr<T1> const & p1, VclPtr<T2> const & p2) {
243 return !(p1 == p2);
244}
245
246template<typename T> inline bool operator !=(VclPtr<T> const & p1, T const * p2)
247{
248 return !(p1 == p2);
249}
250
251template<typename T> inline bool operator !=(VclPtr<T> const & p1, T * p2) {
252 return !(p1 == p2);
253}
254
255template<typename T> inline bool operator !=(T const * p1, VclPtr<T> const & p2)
256{
257 return !(p1 == p2);
258}
259
260template<typename T> inline bool operator !=(T * p1, VclPtr<T> const & p2) {
261 return !(p1 == p2);
262}
263
264/**
265 * A construction helper for a temporary VclPtr. Since VclPtr types
266 * are created with a reference-count of one - to help fit into
267 * the existing code-flow; this helps us to construct them easily.
268 * see also VclPtr::Create and ScopedVclPtr
269 *
270 * For more details on the design please see vcl/README.lifecycle
271 *
272 * @param reference_type must be a subclass of vcl::Window
273 */
274template <class reference_type>
275class SAL_WARN_UNUSED__attribute__((warn_unused)) VclPtrInstance final : public VclPtr<reference_type>
276{
277public:
278 template<typename... Arg> VclPtrInstance(Arg &&... arg)
279 : VclPtr<reference_type>( new reference_type(std::forward<Arg>(arg)...), SAL_NO_ACQUIRE )
280 {
281 }
282
283 /**
284 * Override and disallow this, to prevent people accidentally calling it and actually
285 * getting VclPtr::Create and getting a naked VclPtr<> instance
286 */
287 template<typename... Arg> static VclPtrInstance< reference_type > Create(Arg &&... ) = delete;
288};
289
290template <class reference_type>
291class ScopedVclPtr : public VclPtr<reference_type>
292{
293public:
294 /** Constructor...
295 */
296 ScopedVclPtr()
297 : VclPtr<reference_type>()
298 {}
299
300 /** Constructor
301 */
302 ScopedVclPtr (reference_type * pBody)
303 : VclPtr<reference_type>(pBody)
304 {}
305
306 /** Copy constructor...
307 */
308 ScopedVclPtr (const VclPtr<reference_type> & handle)
309 : VclPtr<reference_type>(handle)
17
Calling implicit copy constructor for 'VclPtr<VirtualDevice>'
18
Calling copy constructor for 'Reference<VirtualDevice>'
21
Returning from copy constructor for 'Reference<VirtualDevice>'
22
Returning from copy constructor for 'VclPtr<VirtualDevice>'
310 {}
311
312 /**
313 Assignment that releases the last reference.
314 */
315 void disposeAndReset(reference_type *pBody)
316 {
317 if (pBody != this->get()) {
318 VclPtr<reference_type>::disposeAndClear();
319 VclPtr<reference_type>::set(pBody);
320 }
321 }
322
323 /**
324 Assignment that releases the last reference.
325 */
326 ScopedVclPtr<reference_type>& operator = (reference_type * pBody)
327 {
328 disposeAndReset(pBody);
329 return *this;
330 }
331
332 /** Up-casting conversion constructor: Copies interface reference.
333
334 Does not work for up-casts to ambiguous bases. For the special case of
335 up-casting to Reference< XInterface >, see the corresponding conversion
336 operator.
337
338 @param rRef another reference
339 */
340 template< class derived_type >
341 ScopedVclPtr(
342 const VclPtr< derived_type > & rRef,
343 typename std::enable_if<
344 std::is_base_of<reference_type, derived_type>::value, int>::type
345 = 0 )
346 : VclPtr<reference_type>( rRef )
347 {
348 }
349
350 /** Up-casting assignment operator.
351
352 Does not work for up-casts to ambiguous bases.
353
354 @param rRef another VclPtr
355 */
356 template<typename derived_type>
357 typename std::enable_if<
358 std::is_base_of<reference_type, derived_type>::value,
359 ScopedVclPtr &>::type
360 operator =(VclPtr<derived_type> const & rRef)
361 {
362 disposeAndReset(rRef.get());
363 return *this;
364 }
365
366 /**
367 * Override and disallow this, to prevent people accidentally calling it and actually
368 * getting VclPtr::Create and getting a naked VclPtr<> instance
369 */
370 template<typename... Arg> static ScopedVclPtr< reference_type > Create(Arg &&... ) = delete;
371
372 ~ScopedVclPtr()
373 {
374 VclPtr<reference_type>::disposeAndClear();
375 assert(VclPtr<reference_type>::get() == nullptr)(static_cast <bool> (VclPtr<reference_type>::get(
) == nullptr) ? void (0) : __assert_fail ("VclPtr<reference_type>::get() == nullptr"
, "/home/maarten/src/libreoffice/core/include/vcl/vclptr.hxx"
, 375, __extension__ __PRETTY_FUNCTION__))
; // make sure there are no lingering references
376 }
377
378private:
379 // Most likely we don't want this default copy-constructor.
380 ScopedVclPtr (const ScopedVclPtr<reference_type> &) = delete;
381 // And certainly we don't want a default assignment operator.
382 ScopedVclPtr<reference_type>& operator = (const ScopedVclPtr<reference_type> &) = delete;
383 // And disallow reset as that doesn't call disposeAndClear on the original reference
384 void reset() = delete;
385 void reset(reference_type *pBody) = delete;
386
387protected:
388 ScopedVclPtr (reference_type * pBody, __sal_NoAcquire)
389 : VclPtr<reference_type>(pBody, SAL_NO_ACQUIRE)
390 {}
391};
392
393/**
394 * A construction helper for ScopedVclPtr. Since VclPtr types are created
395 * with a reference-count of one - to help fit into the existing
396 * code-flow; this helps us to construct them easily.
397 *
398 * For more details on the design please see vcl/README.lifecycle
399 *
400 * @param reference_type must be a subclass of vcl::Window
401 */
402#if defined _MSC_VER
403#pragma warning(push)
404#pragma warning(disable: 4521) // " multiple copy constructors specified"
405#endif
406template <class reference_type>
407class SAL_WARN_UNUSED__attribute__((warn_unused)) ScopedVclPtrInstance final : public ScopedVclPtr<reference_type>
408{
409public:
410 template<typename... Arg> ScopedVclPtrInstance(Arg &&... arg)
411 : ScopedVclPtr<reference_type>( new reference_type(std::forward<Arg>(arg)...), SAL_NO_ACQUIRE )
412 {
413 }
414
415 /**
416 * Override and disallow this, to prevent people accidentally calling it and actually
417 * getting VclPtr::Create and getting a naked VclPtr<> instance
418 */
419 template<typename... Arg> static ScopedVclPtrInstance< reference_type > Create(Arg &&...) = delete;
420
421private:
422 // Prevent the above perfect forwarding ctor from hijacking (accidental)
423 // attempts at ScopedVclPtrInstance copy construction (where the hijacking
424 // would typically lead to somewhat obscure error messages); both non-const
425 // and const variants are needed here, as the ScopedVclPtr base class has a
426 // const--variant copy ctor, so the implicitly declared copy ctor for
427 // ScopedVclPtrInstance would also be the const variant, so non-const copy
428 // construction attempts would be hijacked by the perfect forwarding ctor;
429 // but if we only declared a non-const variant here, the const variant would
430 // no longer be implicitly declared (as there would already be an explicitly
431 // declared copy ctor), so const copy construction attempts would then be
432 // hijacked by the perfect forwarding ctor:
433 ScopedVclPtrInstance(ScopedVclPtrInstance &) = delete;
434 ScopedVclPtrInstance(ScopedVclPtrInstance const &) = delete;
435};
436#if defined _MSC_VER
437#pragma warning(pop)
438#endif
439
440#endif // INCLUDED_VCL_PTR_HXX
441
442/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

/home/maarten/src/libreoffice/core/include/rtl/ref.hxx

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#ifndef INCLUDED_RTL_REF_HXX
21#define INCLUDED_RTL_REF_HXX
22
23#include "sal/config.h"
24
25#include <cassert>
26#include <cstddef>
27#include <functional>
28#ifdef LIBO_INTERNAL_ONLY1
29#include <type_traits>
30#endif
31
32#include "sal/types.h"
33
34namespace rtl
35{
36
37/** Template reference class for reference type.
38*/
39template <class reference_type>
40class Reference
41{
42 /** The <b>reference_type</b> body pointer.
43 */
44 reference_type * m_pBody;
45
46
47public:
48 /** Constructor...
49 */
50 Reference()
51 : m_pBody (NULL__null)
52 {}
53
54
55 /** Constructor...
56 */
57 Reference (reference_type * pBody, __sal_NoAcquire)
58 : m_pBody (pBody)
59 {
60 }
61
62 /** Constructor...
63 */
64 Reference (reference_type * pBody)
65 : m_pBody (pBody)
66 {
67 if (m_pBody)
68 m_pBody->acquire();
69 }
70
71 /** Copy constructor...
72 */
73 Reference (const Reference<reference_type> & handle)
74 : m_pBody (handle.m_pBody)
75 {
76 if (m_pBody)
19
Assuming field 'm_pBody' is non-null
20
Taking true branch
77 m_pBody->acquire();
78 }
79
80#ifdef LIBO_INTERNAL_ONLY1
81 /** Move constructor...
82 */
83 Reference (Reference<reference_type> && handle) noexcept
84 : m_pBody (handle.m_pBody)
85 {
86 handle.m_pBody = nullptr;
87 }
88#endif
89
90#if defined LIBO_INTERNAL_ONLY1
91 /** Up-casting conversion constructor: Copies interface reference.
92
93 Does not work for up-casts to ambiguous bases.
94
95 @param rRef another reference
96 */
97 template< class derived_type >
98 inline Reference(
99 const Reference< derived_type > & rRef,
100 std::enable_if_t<std::is_base_of_v<reference_type, derived_type>, int> = 0 )
101 : m_pBody (rRef.get())
102 {
103 if (m_pBody)
104 m_pBody->acquire();
105 }
106#endif
107
108 /** Destructor...
109 */
110 ~Reference() COVERITY_NOEXCEPT_FALSE
111 {
112 if (m_pBody
25.1
Field 'm_pBody' is non-null
25.1
Field 'm_pBody' is non-null
25.1
Field 'm_pBody' is non-null
25.1
Field 'm_pBody' is non-null
)
26
Taking true branch
113 m_pBody->release();
27
Calling 'VclReferenceBase::release'
31
Returning; memory was released
114 }
115
116 /** Set...
117 Similar to assignment.
118 */
119 Reference<reference_type> &
120 SAL_CALL set (reference_type * pBody)
121 {
122 if (pBody)
123 pBody->acquire();
124 reference_type * const pOld = m_pBody;
125 m_pBody = pBody;
126 if (pOld)
127 pOld->release();
128 return *this;
129 }
130
131 /** Assignment.
132 Unbinds this instance from its body (if bound) and
133 bind it to the body represented by the handle.
134 */
135 Reference<reference_type> &
136 SAL_CALL operator= (const Reference<reference_type> & handle)
137 {
138 return set( handle.m_pBody );
139 }
140
141#ifdef LIBO_INTERNAL_ONLY1
142 /** Assignment.
143 * Unbinds this instance from its body (if bound),
144 * bind it to the body represented by the handle, and
145 * set the body represented by the handle to nullptr.
146 */
147 Reference<reference_type> &
148 operator= (Reference<reference_type> && handle)
149 {
150 // self-movement guts ourself
151 if (m_pBody)
152 m_pBody->release();
153 m_pBody = handle.m_pBody;
154 handle.m_pBody = nullptr;
155 return *this;
156 }
157#endif
158
159 /** Assignment...
160 */
161 Reference<reference_type> &
162 SAL_CALL operator= (reference_type * pBody)
163 {
164 return set( pBody );
165 }
166
167 /** Unbind the body from this handle.
168 Note that for a handle representing a large body,
169 "handle.clear().set(new body());" _might_
170 perform a little bit better than "handle.set(new body());",
171 since in the second case two large objects exist in memory
172 (the old body and the new body).
173 */
174 Reference<reference_type> & SAL_CALL clear()
175 {
176 if (m_pBody)
177 {
178 reference_type * const pOld = m_pBody;
179 m_pBody = NULL__null;
180 pOld->release();
181 }
182 return *this;
183 }
184
185
186 /** Get the body. Can be used instead of operator->().
187 I.e. handle->someBodyOp() and handle.get()->someBodyOp()
188 are the same.
189 */
190 reference_type * SAL_CALL get() const
191 {
192 return m_pBody;
36
Use of memory after it is freed
193 }
194
195
196 /** Probably most common used: handle->someBodyOp().
197 */
198 reference_type * SAL_CALL operator->() const
199 {
200 assert(m_pBody != NULL)(static_cast <bool> (m_pBody != __null) ? void (0) : __assert_fail
("m_pBody != NULL", "/home/maarten/src/libreoffice/core/include/rtl/ref.hxx"
, 200, __extension__ __PRETTY_FUNCTION__))
;
201 return m_pBody;
202 }
203
204
205 /** Allows (*handle).someBodyOp().
206 */
207 reference_type & SAL_CALL operator*() const
208 {
209 assert(m_pBody != NULL)(static_cast <bool> (m_pBody != __null) ? void (0) : __assert_fail
("m_pBody != NULL", "/home/maarten/src/libreoffice/core/include/rtl/ref.hxx"
, 209, __extension__ __PRETTY_FUNCTION__))
;
210 return *m_pBody;
211 }
212
213
214 /** Returns True if the handle does point to a valid body.
215 */
216 bool SAL_CALL is() const
217 {
218 return (m_pBody != NULL__null);
219 }
220
221#if defined LIBO_INTERNAL_ONLY1
222 /** Returns True if the handle does point to a valid body.
223 */
224 explicit operator bool() const
225 {
226 return is();
227 }
228#endif
229
230 /** Returns True if this points to pBody.
231 */
232 bool SAL_CALL operator== (const reference_type * pBody) const
233 {
234 return (m_pBody == pBody);
235 }
236
237
238 /** Returns True if handle points to the same body.
239 */
240 bool
241 SAL_CALL operator== (const Reference<reference_type> & handle) const
242 {
243 return (m_pBody == handle.m_pBody);
244 }
245
246
247 /** Needed to place References into STL collection.
248 */
249 bool
250 SAL_CALL operator!= (const Reference<reference_type> & handle) const
251 {
252 return (m_pBody != handle.m_pBody);
253 }
254
255
256 /** Needed to place References into STL collection.
257 */
258 bool
259 SAL_CALL operator< (const Reference<reference_type> & handle) const
260 {
261 return (m_pBody < handle.m_pBody);
262 }
263
264
265 /** Needed to place References into STL collection.
266 */
267 bool
268 SAL_CALL operator> (const Reference<reference_type> & handle) const
269 {
270 return (m_pBody > handle.m_pBody);
271 }
272};
273
274} // namespace rtl
275
276#if defined LIBO_INTERNAL_ONLY1
277namespace std
278{
279
280/// @cond INTERNAL
281/**
282 Make rtl::Reference hashable by default for use in STL containers.
283
284 @since LibreOffice 6.3
285*/
286template<typename T>
287struct hash<::rtl::Reference<T>>
288{
289 std::size_t operator()(::rtl::Reference<T> const & s) const
290 { return std::size_t(s.get()); }
291};
292/// @endcond
293
294}
295
296#endif
297
298#endif /* ! INCLUDED_RTL_REF_HXX */
299
300/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

/home/maarten/src/libreoffice/core/include/vcl/vclreferencebase.hxx

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#ifndef INCLUDED_VCL_Reference_HXX
20#define INCLUDED_VCL_Reference_HXX
21
22#include <vcl/dllapi.h>
23#include <osl/interlck.h>
24
25class VCL_DLLPUBLIC__attribute__ ((visibility("default"))) VclReferenceBase
26{
27 mutable oslInterlockedCount mnRefCnt;
28
29 template<typename T> friend class VclPtr;
30
31public:
32 void acquire() const
33 {
34 osl_atomic_increment(&mnRefCnt)__sync_add_and_fetch((&mnRefCnt), 1);
35 }
36
37 void release() const
38 {
39 if (osl_atomic_decrement(&mnRefCnt)__sync_sub_and_fetch((&mnRefCnt), 1) == 0)
28
Assuming the condition is true
29
Taking true branch
40 delete this;
30
Memory is released
41 }
42#ifdef DBG_UTIL
43#ifndef _WIN32
44 sal_Int32 getRefCount() const { return mnRefCnt; }
45#endif
46#endif
47
48
49private:
50 VclReferenceBase(const VclReferenceBase&) = delete;
51 VclReferenceBase& operator=(const VclReferenceBase&) = delete;
52
53 bool mbDisposed : 1;
54
55protected:
56 VclReferenceBase();
57protected:
58 virtual ~VclReferenceBase();
59
60protected:
61 virtual void dispose();
62
63public:
64 void disposeOnce();
65 bool isDisposed() const { return mbDisposed; }
66
67};
68#endif