File: | home/maarten/src/libreoffice/core/include/rtl/ref.hxx |
Warning: | line 192, column 9 Use of memory after it is freed |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ | |||
2 | /* | |||
3 | * This file is part of the LibreOffice project. | |||
4 | * | |||
5 | * This Source Code Form is subject to the terms of the Mozilla Public | |||
6 | * License, v. 2.0. If a copy of the MPL was not distributed with this | |||
7 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. | |||
8 | * | |||
9 | * This file incorporates work covered by the following license notice: | |||
10 | * | |||
11 | * Licensed to the Apache Software Foundation (ASF) under one or more | |||
12 | * contributor license agreements. See the NOTICE file distributed | |||
13 | * with this work for additional information regarding copyright | |||
14 | * ownership. The ASF licenses this file to you under the Apache | |||
15 | * License, Version 2.0 (the "License"); you may not use this file | |||
16 | * except in compliance with the License. You may obtain a copy of | |||
17 | * the License at http://www.apache.org/licenses/LICENSE-2.0 . | |||
18 | */ | |||
19 | ||||
20 | #include <config_extensions.h> | |||
21 | ||||
22 | #include <strings.hrc> | |||
23 | #include <helpids.h> | |||
24 | ||||
25 | #include "dp_gui.h" | |||
26 | #include "dp_gui_dialog2.hxx" | |||
27 | #include "dp_gui_extlistbox.hxx" | |||
28 | #include <dp_shared.hxx> | |||
29 | #include "dp_gui_theextmgr.hxx" | |||
30 | #include "dp_gui_extensioncmdqueue.hxx" | |||
31 | #include <dp_misc.h> | |||
32 | #include <dp_update.hxx> | |||
33 | #include <dp_identifier.hxx> | |||
34 | ||||
35 | #include <fpicker/strings.hrc> | |||
36 | ||||
37 | #include <vcl/commandevent.hxx> | |||
38 | #include <vcl/svapp.hxx> | |||
39 | ||||
40 | #include <osl/mutex.hxx> | |||
41 | #include <sal/log.hxx> | |||
42 | #include <rtl/ustrbuf.hxx> | |||
43 | ||||
44 | #include <svtools/restartdialog.hxx> | |||
45 | ||||
46 | #include <sfx2/filedlghelper.hxx> | |||
47 | #include <sfx2/sfxdlg.hxx> | |||
48 | ||||
49 | #include <comphelper/anytostring.hxx> | |||
50 | #include <cppuhelper/exc_hlp.hxx> | |||
51 | #include <cppuhelper/supportsservice.hxx> | |||
52 | ||||
53 | #include <comphelper/processfactory.hxx> | |||
54 | #include <tools/diagnose_ex.h> | |||
55 | #include <unotools/configmgr.hxx> | |||
56 | ||||
57 | #include <com/sun/star/deployment/DeploymentException.hpp> | |||
58 | #include <com/sun/star/lang/IllegalArgumentException.hpp> | |||
59 | #include <com/sun/star/system/SystemShellExecuteFlags.hpp> | |||
60 | #include <com/sun/star/system/SystemShellExecute.hpp> | |||
61 | ||||
62 | #include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp> | |||
63 | #include <com/sun/star/ui/dialogs/TemplateDescription.hpp> | |||
64 | #include <com/sun/star/ui/dialogs/XFilePicker3.hpp> | |||
65 | ||||
66 | #include <officecfg/Office/ExtensionManager.hxx> | |||
67 | ||||
68 | #include <map> | |||
69 | #include <memory> | |||
70 | #include <vector> | |||
71 | ||||
72 | using namespace ::com::sun::star; | |||
73 | using namespace ::com::sun::star::system; | |||
74 | ||||
75 | ||||
76 | namespace dp_gui { | |||
77 | ||||
78 | #define USER_PACKAGE_MANAGER"user" "user" | |||
79 | #define SHARED_PACKAGE_MANAGER"shared" "shared" | |||
80 | #define BUNDLED_PACKAGE_MANAGER"bundled" "bundled" | |||
81 | ||||
82 | namespace { | |||
83 | ||||
84 | struct StrAllFiles : public rtl::StaticWithInit< OUString, StrAllFiles > | |||
85 | { | |||
86 | OUString operator () () { | |||
87 | const SolarMutexGuard guard; | |||
88 | std::locale loc = Translate::Create("fps"); | |||
89 | return Translate::get(STR_FILTERNAME_ALLreinterpret_cast<char const *>("STR_FILTERNAME_ALL" "\004" u8"All files"), loc); | |||
90 | } | |||
91 | }; | |||
92 | ||||
93 | } | |||
94 | ||||
95 | // ExtBoxWithBtns_Impl | |||
96 | class ExtBoxWithBtns_Impl : public ExtensionBox_Impl | |||
97 | { | |||
98 | bool m_bInterfaceLocked; | |||
99 | ||||
100 | ExtMgrDialog* m_pParent; | |||
101 | ||||
102 | void SetButtonStatus( const TEntry_Impl& rEntry ); | |||
103 | OString ShowPopupMenu( const Point &rPos, const long nPos ); | |||
104 | ||||
105 | public: | |||
106 | explicit ExtBoxWithBtns_Impl(std::unique_ptr<weld::ScrolledWindow> xScroll); | |||
107 | ||||
108 | void InitFromDialog(ExtMgrDialog *pParentDialog); | |||
109 | ||||
110 | virtual bool MouseButtonDown( const MouseEvent& rMEvt ) override; | |||
111 | virtual bool Command( const CommandEvent& rCEvt ) override; | |||
112 | ||||
113 | virtual void RecalcAll() override; | |||
114 | virtual void selectEntry( const long nPos ) override; | |||
115 | ||||
116 | void enableButtons( bool bEnable ); | |||
117 | }; | |||
118 | ||||
119 | ExtBoxWithBtns_Impl::ExtBoxWithBtns_Impl(std::unique_ptr<weld::ScrolledWindow> xScroll) | |||
120 | : ExtensionBox_Impl(std::move(xScroll)) | |||
121 | , m_bInterfaceLocked(false) | |||
122 | , m_pParent(nullptr) | |||
123 | { | |||
124 | } | |||
125 | ||||
126 | void ExtBoxWithBtns_Impl::InitFromDialog(ExtMgrDialog *pParentDialog) | |||
127 | { | |||
128 | setExtensionManager(pParentDialog->getExtensionManager()); | |||
129 | ||||
130 | m_pParent = pParentDialog; | |||
131 | } | |||
132 | ||||
133 | void ExtBoxWithBtns_Impl::RecalcAll() | |||
134 | { | |||
135 | const sal_Int32 nActive = getSelIndex(); | |||
136 | ||||
137 | if ( nActive != ExtensionBox_Impl::ENTRY_NOTFOUND ) | |||
138 | { | |||
139 | SetButtonStatus( GetEntryData( nActive) ); | |||
140 | } | |||
141 | else | |||
142 | { | |||
143 | m_pParent->enableOptionsButton( false ); | |||
144 | m_pParent->enableRemoveButton( false ); | |||
145 | m_pParent->enableEnableButton( false ); | |||
146 | } | |||
147 | ||||
148 | ExtensionBox_Impl::RecalcAll(); | |||
149 | } | |||
150 | ||||
151 | ||||
152 | //This function may be called with nPos < 0 | |||
153 | void ExtBoxWithBtns_Impl::selectEntry( const long nPos ) | |||
154 | { | |||
155 | if ( HasActive() && ( nPos == getSelIndex() ) ) | |||
156 | return; | |||
157 | ||||
158 | ExtensionBox_Impl::selectEntry( nPos ); | |||
159 | } | |||
160 | ||||
161 | void ExtBoxWithBtns_Impl::SetButtonStatus(const TEntry_Impl& rEntry) | |||
162 | { | |||
163 | bool bShowOptionBtn = true; | |||
164 | ||||
165 | rEntry->m_bHasButtons = false; | |||
166 | if ( ( rEntry->m_eState == REGISTERED ) || ( rEntry->m_eState == NOT_AVAILABLE ) ) | |||
167 | { | |||
168 | m_pParent->enableButtontoEnable( false ); | |||
169 | } | |||
170 | else | |||
171 | { | |||
172 | m_pParent->enableButtontoEnable( true ); | |||
173 | bShowOptionBtn = false; | |||
174 | } | |||
175 | ||||
176 | if ( ( !rEntry->m_bUser || ( rEntry->m_eState == NOT_AVAILABLE ) || rEntry->m_bMissingDeps ) | |||
177 | && !rEntry->m_bMissingLic ) | |||
178 | { | |||
179 | m_pParent->enableEnableButton( false ); | |||
180 | } | |||
181 | else | |||
182 | { | |||
183 | m_pParent->enableEnableButton( !rEntry->m_bLocked ); | |||
184 | rEntry->m_bHasButtons = true; | |||
185 | } | |||
186 | ||||
187 | if ( rEntry->m_bHasOptions && bShowOptionBtn ) | |||
188 | { | |||
189 | m_pParent->enableOptionsButton( true ); | |||
190 | rEntry->m_bHasButtons = true; | |||
191 | } | |||
192 | else | |||
193 | { | |||
194 | m_pParent->enableOptionsButton( false ); | |||
195 | } | |||
196 | ||||
197 | if ( rEntry->m_bUser || rEntry->m_bShared ) | |||
198 | { | |||
199 | m_pParent->enableRemoveButton( !rEntry->m_bLocked ); | |||
200 | rEntry->m_bHasButtons = true; | |||
201 | } | |||
202 | else | |||
203 | { | |||
204 | m_pParent->enableRemoveButton( false ); | |||
205 | } | |||
206 | } | |||
207 | ||||
208 | bool ExtBoxWithBtns_Impl::Command(const CommandEvent& rCEvt) | |||
209 | { | |||
210 | if (rCEvt.GetCommand() != CommandEventId::ContextMenu) | |||
211 | return ExtensionBox_Impl::Command(rCEvt); | |||
212 | ||||
213 | const Point aMousePos(rCEvt.GetMousePosPixel()); | |||
214 | const auto nPos = PointToPos(aMousePos); | |||
215 | OString sCommand = ShowPopupMenu(aMousePos, nPos); | |||
216 | ||||
217 | if (sCommand == "CMD_ENABLE") | |||
218 | m_pParent->enablePackage( GetEntryData( nPos )->m_xPackage, true ); | |||
219 | else if (sCommand == "CMD_DISABLE") | |||
220 | m_pParent->enablePackage( GetEntryData( nPos )->m_xPackage, false ); | |||
221 | else if (sCommand == "CMD_UPDATE") | |||
222 | m_pParent->updatePackage( GetEntryData( nPos )->m_xPackage ); | |||
223 | else if (sCommand == "CMD_REMOVE") | |||
224 | m_pParent->removePackage( GetEntryData( nPos )->m_xPackage ); | |||
225 | else if (sCommand == "CMD_SHOW_LICENSE") | |||
226 | { | |||
227 | m_pParent->incBusy(); | |||
228 | ShowLicenseDialog aLicenseDlg(m_pParent->getDialog(), GetEntryData(nPos)->m_xPackage); | |||
229 | aLicenseDlg.run(); | |||
230 | m_pParent->decBusy(); | |||
231 | } | |||
232 | ||||
233 | return true; | |||
234 | } | |||
235 | ||||
236 | OString ExtBoxWithBtns_Impl::ShowPopupMenu( const Point & rPos, const long nPos ) | |||
237 | { | |||
238 | if ( nPos >= static_cast<long>(getItemCount()) ) | |||
239 | return "CMD_NONE"; | |||
240 | ||||
241 | std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(nullptr, "desktop/ui/extensionmenu.ui")); | |||
242 | std::unique_ptr<weld::Menu> xPopup(xBuilder->weld_menu("menu")); | |||
243 | ||||
244 | #if ENABLE_EXTENSION_UPDATE1 | |||
245 | xPopup->append("CMD_UPDATE", DpResId( RID_CTX_ITEM_CHECK_UPDATEreinterpret_cast<char const *>("RID_CTX_ITEM_CHECK_UPDATE" "\004" u8"~Update...") ) ); | |||
246 | #endif | |||
247 | ||||
248 | if ( ! GetEntryData( nPos )->m_bLocked ) | |||
249 | { | |||
250 | if ( GetEntryData( nPos )->m_bUser ) | |||
251 | { | |||
252 | if ( GetEntryData( nPos )->m_eState == REGISTERED ) | |||
253 | xPopup->append("CMD_DISABLE", DpResId(RID_CTX_ITEM_DISABLEreinterpret_cast<char const *>("RID_CTX_ITEM_DISABLE" "\004" u8"~Disable"))); | |||
254 | else if ( GetEntryData( nPos )->m_eState != NOT_AVAILABLE ) | |||
255 | xPopup->append("CMD_ENABLE", DpResId(RID_CTX_ITEM_ENABLEreinterpret_cast<char const *>("RID_CTX_ITEM_ENABLE" "\004" u8"~Enable"))); | |||
256 | } | |||
257 | if (!officecfg::Office::ExtensionManager::ExtensionSecurity::DisableExtensionRemoval::get()) | |||
258 | { | |||
259 | xPopup->append("CMD_REMOVE", DpResId(RID_CTX_ITEM_REMOVEreinterpret_cast<char const *>("RID_CTX_ITEM_REMOVE" "\004" u8"~Remove"))); | |||
260 | } | |||
261 | } | |||
262 | ||||
263 | if ( !GetEntryData( nPos )->m_sLicenseText.isEmpty() ) | |||
264 | xPopup->append("CMD_SHOW_LICENSE", DpResId(RID_STR_SHOW_LICENSE_CMDreinterpret_cast<char const *>("RID_STR_SHOW_LICENSE_CMD" "\004" u8"Show license"))); | |||
265 | ||||
266 | return xPopup->popup_at_rect(GetDrawingArea(), tools::Rectangle(rPos, Size(1, 1))); | |||
267 | } | |||
268 | ||||
269 | bool ExtBoxWithBtns_Impl::MouseButtonDown( const MouseEvent& rMEvt ) | |||
270 | { | |||
271 | if (m_bInterfaceLocked) | |||
272 | return false; | |||
273 | return ExtensionBox_Impl::MouseButtonDown(rMEvt); | |||
274 | } | |||
275 | ||||
276 | void ExtBoxWithBtns_Impl::enableButtons( bool bEnable ) | |||
277 | { | |||
278 | m_bInterfaceLocked = ! bEnable; | |||
279 | ||||
280 | if ( bEnable ) | |||
281 | { | |||
282 | sal_Int32 nIndex = getSelIndex(); | |||
283 | if ( nIndex != ExtensionBox_Impl::ENTRY_NOTFOUND ) | |||
284 | SetButtonStatus( GetEntryData( nIndex ) ); | |||
285 | } | |||
286 | else | |||
287 | { | |||
288 | m_pParent->enableEnableButton( false ); | |||
289 | m_pParent->enableOptionsButton( false ); | |||
290 | m_pParent->enableRemoveButton( false ); | |||
291 | } | |||
292 | } | |||
293 | ||||
294 | // DialogHelper | |||
295 | ||||
296 | DialogHelper::DialogHelper(const uno::Reference< uno::XComponentContext > &xContext, | |||
297 | weld::Window* pWindow) | |||
298 | : m_pWindow(pWindow) | |||
299 | , m_nEventID(nullptr) | |||
300 | { | |||
301 | m_xContext = xContext; | |||
302 | } | |||
303 | ||||
304 | DialogHelper::~DialogHelper() | |||
305 | { | |||
306 | if ( m_nEventID ) | |||
307 | Application::RemoveUserEvent( m_nEventID ); | |||
308 | } | |||
309 | ||||
310 | ||||
311 | bool DialogHelper::IsSharedPkgMgr( const uno::Reference< deployment::XPackage > &xPackage ) | |||
312 | { | |||
313 | return xPackage->getRepositoryName() == SHARED_PACKAGE_MANAGER"shared"; | |||
314 | } | |||
315 | ||||
316 | bool DialogHelper::continueOnSharedExtension( const uno::Reference< deployment::XPackage > &xPackage, | |||
317 | weld::Widget* pParent, | |||
318 | const char* pResID, | |||
319 | bool &bHadWarning ) | |||
320 | { | |||
321 | if ( !bHadWarning && IsSharedPkgMgr( xPackage ) ) | |||
322 | { | |||
323 | const SolarMutexGuard guard; | |||
324 | incBusy(); | |||
325 | std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(pParent, | |||
326 | VclMessageType::Warning, VclButtonsType::OkCancel, DpResId(pResID))); | |||
327 | bHadWarning = true; | |||
328 | ||||
329 | bool bRet = RET_OK == xBox->run(); | |||
330 | xBox.reset(); | |||
331 | decBusy(); | |||
332 | return bRet; | |||
333 | } | |||
334 | else | |||
335 | return true; | |||
336 | } | |||
337 | ||||
338 | void DialogHelper::openWebBrowser(const OUString& sURL, const OUString& sTitle) | |||
339 | { | |||
340 | if ( sURL.isEmpty() ) // Nothing to do, when the URL is empty | |||
341 | return; | |||
342 | ||||
343 | try | |||
344 | { | |||
345 | uno::Reference< XSystemShellExecute > xSystemShellExecute( | |||
346 | SystemShellExecute::create(m_xContext)); | |||
347 | //throws css::lang::IllegalArgumentException, css::system::SystemShellExecuteException | |||
348 | xSystemShellExecute->execute( sURL, OUString(), SystemShellExecuteFlags::URIS_ONLY ); | |||
349 | } | |||
350 | catch ( const uno::Exception& ) | |||
351 | { | |||
352 | uno::Any exc( ::cppu::getCaughtException() ); | |||
353 | OUString msg( ::comphelper::anyToString( exc ) ); | |||
354 | const SolarMutexGuard guard; | |||
355 | incBusy(); | |||
356 | std::unique_ptr<weld::MessageDialog> xErrorBox(Application::CreateMessageDialog(getFrameWeld(), | |||
357 | VclMessageType::Warning, VclButtonsType::Ok, msg)); | |||
358 | xErrorBox->set_title(sTitle); | |||
359 | xErrorBox->run(); | |||
360 | xErrorBox.reset(); | |||
361 | decBusy(); | |||
362 | } | |||
363 | } | |||
364 | ||||
365 | bool DialogHelper::installExtensionWarn(const OUString &rExtensionName) | |||
366 | { | |||
367 | const SolarMutexGuard guard; | |||
368 | ||||
369 | // Check if extension installation is disabled in the expert configurations | |||
370 | if (officecfg::Office::ExtensionManager::ExtensionSecurity::DisableExtensionInstallation::get()) | |||
371 | { | |||
372 | incBusy(); | |||
373 | std::unique_ptr<weld::MessageDialog> xWarnBox(Application::CreateMessageDialog(getFrameWeld(), | |||
374 | VclMessageType::Warning, VclButtonsType::Ok, | |||
375 | DpResId(RID_STR_WARNING_INSTALL_EXTENSION_DISABLEDreinterpret_cast<char const *>("RID_STR_WARNING_INSTALL_EXTENSION_DISABLED" "\004" u8"Extension installation is currently disabled. " "Please consult your system administrator for more information." )))); | |||
376 | xWarnBox->run(); | |||
377 | xWarnBox.reset(); | |||
378 | decBusy(); | |||
379 | ||||
380 | return false; | |||
381 | } | |||
382 | ||||
383 | incBusy(); | |||
384 | std::unique_ptr<weld::MessageDialog> xInfoBox(Application::CreateMessageDialog(getFrameWeld(), | |||
385 | VclMessageType::Warning, VclButtonsType::OkCancel, | |||
386 | DpResId(RID_STR_WARNING_INSTALL_EXTENSIONreinterpret_cast<char const *>("RID_STR_WARNING_INSTALL_EXTENSION" "\004" u8"You are about to install the extension '%NAME'.\n" "Click 'OK' to proceed with the installation.\n" "Click 'Cancel' to stop the installation." )))); | |||
387 | OUString sText(xInfoBox->get_primary_text()); | |||
388 | sText = sText.replaceAll("%NAME", rExtensionName); | |||
389 | xInfoBox->set_primary_text(sText); | |||
390 | ||||
391 | bool bRet = RET_OK == xInfoBox->run(); | |||
392 | xInfoBox.reset(); | |||
393 | decBusy(); | |||
394 | return bRet; | |||
395 | } | |||
396 | ||||
397 | bool DialogHelper::installForAllUsers(bool &bInstallForAll) | |||
398 | { | |||
399 | const SolarMutexGuard guard; | |||
400 | incBusy(); | |||
401 | std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(getFrameWeld(), "desktop/ui/installforalldialog.ui")); | |||
402 | std::unique_ptr<weld::MessageDialog> xQuery(xBuilder->weld_message_dialog("InstallForAllDialog")); | |||
403 | short nRet = xQuery->run(); | |||
404 | xQuery.reset(); | |||
405 | decBusy(); | |||
406 | if (nRet == RET_CANCEL) | |||
407 | return false; | |||
408 | ||||
409 | bInstallForAll = ( nRet == RET_NO ); | |||
410 | return true; | |||
411 | } | |||
412 | ||||
413 | void DialogHelper::PostUserEvent( const Link<void*,void>& rLink, void* pCaller ) | |||
414 | { | |||
415 | if ( m_nEventID ) | |||
416 | Application::RemoveUserEvent( m_nEventID ); | |||
417 | ||||
418 | m_nEventID = Application::PostUserEvent(rLink, pCaller); | |||
419 | } | |||
420 | ||||
421 | // ExtMgrDialog | |||
422 | ExtMgrDialog::ExtMgrDialog(weld::Window *pParent, TheExtensionManager *pManager) | |||
423 | : GenericDialogController(pParent, "desktop/ui/extensionmanager.ui", "ExtensionManagerDialog") | |||
424 | , DialogHelper(pManager->getContext(), m_xDialog.get()) | |||
425 | , m_sAddPackages(DpResId(RID_STR_ADD_PACKAGESreinterpret_cast<char const *>("RID_STR_ADD_PACKAGES" "\004" u8"Add Extension(s)"))) | |||
426 | , m_bHasProgress(false) | |||
427 | , m_bProgressChanged(false) | |||
428 | , m_bStartProgress(false) | |||
429 | , m_bStopProgress(false) | |||
430 | , m_bEnableWarning(false) | |||
431 | , m_bDisableWarning(false) | |||
432 | , m_bDeleteWarning(false) | |||
433 | , m_bClosed(false) | |||
434 | , m_nProgress(0) | |||
435 | , m_pManager(pManager) | |||
436 | , m_xExtensionBox(new ExtBoxWithBtns_Impl(m_xBuilder->weld_scrolled_window("scroll", true))) | |||
437 | , m_xExtensionBoxWnd(new weld::CustomWeld(*m_xBuilder, "extensions", *m_xExtensionBox)) | |||
438 | , m_xOptionsBtn(m_xBuilder->weld_button("optionsbtn")) | |||
439 | , m_xAddBtn(m_xBuilder->weld_button("addbtn")) | |||
440 | , m_xRemoveBtn(m_xBuilder->weld_button("removebtn")) | |||
441 | , m_xEnableBtn(m_xBuilder->weld_button("enablebtn")) | |||
442 | , m_xUpdateBtn(m_xBuilder->weld_button("updatebtn")) | |||
443 | , m_xCloseBtn(m_xBuilder->weld_button("close")) | |||
444 | , m_xBundledCbx(m_xBuilder->weld_check_button("bundled")) | |||
445 | , m_xSharedCbx(m_xBuilder->weld_check_button("shared")) | |||
446 | , m_xUserCbx(m_xBuilder->weld_check_button("user")) | |||
447 | , m_xGetExtensions(m_xBuilder->weld_link_button("getextensions")) | |||
448 | , m_xProgressText(m_xBuilder->weld_label("progressft")) | |||
449 | , m_xProgressBar(m_xBuilder->weld_progress_bar("progressbar")) | |||
450 | , m_xCancelBtn(m_xBuilder->weld_button("cancel")) | |||
451 | { | |||
452 | m_xExtensionBox->InitFromDialog(this); | |||
453 | ||||
454 | m_xEnableBtn->set_help_id(HID_EXTENSION_MANAGER_LISTBOX_ENABLE"DESKTOP_HID_EXTENSION_MANAGER_LISTBOX_ENABLE"); | |||
455 | ||||
456 | m_xOptionsBtn->connect_clicked( LINK( this, ExtMgrDialog, HandleOptionsBtn )::tools::detail::makeLink( ::tools::detail::castTo<ExtMgrDialog *>(this), &ExtMgrDialog::LinkStubHandleOptionsBtn) ); | |||
457 | m_xAddBtn->connect_clicked( LINK( this, ExtMgrDialog, HandleAddBtn )::tools::detail::makeLink( ::tools::detail::castTo<ExtMgrDialog *>(this), &ExtMgrDialog::LinkStubHandleAddBtn) ); | |||
458 | m_xRemoveBtn->connect_clicked( LINK( this, ExtMgrDialog, HandleRemoveBtn )::tools::detail::makeLink( ::tools::detail::castTo<ExtMgrDialog *>(this), &ExtMgrDialog::LinkStubHandleRemoveBtn) ); | |||
459 | m_xEnableBtn->connect_clicked( LINK( this, ExtMgrDialog, HandleEnableBtn )::tools::detail::makeLink( ::tools::detail::castTo<ExtMgrDialog *>(this), &ExtMgrDialog::LinkStubHandleEnableBtn) ); | |||
460 | m_xCloseBtn->connect_clicked( LINK( this, ExtMgrDialog, HandleCloseBtn )::tools::detail::makeLink( ::tools::detail::castTo<ExtMgrDialog *>(this), &ExtMgrDialog::LinkStubHandleCloseBtn) ); | |||
461 | ||||
462 | m_xCancelBtn->connect_clicked( LINK( this, ExtMgrDialog, HandleCancelBtn )::tools::detail::makeLink( ::tools::detail::castTo<ExtMgrDialog *>(this), &ExtMgrDialog::LinkStubHandleCancelBtn) ); | |||
463 | ||||
464 | m_xBundledCbx->connect_clicked( LINK( this, ExtMgrDialog, HandleExtTypeCbx )::tools::detail::makeLink( ::tools::detail::castTo<ExtMgrDialog *>(this), &ExtMgrDialog::LinkStubHandleExtTypeCbx) ); | |||
465 | m_xSharedCbx->connect_clicked( LINK( this, ExtMgrDialog, HandleExtTypeCbx )::tools::detail::makeLink( ::tools::detail::castTo<ExtMgrDialog *>(this), &ExtMgrDialog::LinkStubHandleExtTypeCbx) ); | |||
466 | m_xUserCbx->connect_clicked( LINK( this, ExtMgrDialog, HandleExtTypeCbx )::tools::detail::makeLink( ::tools::detail::castTo<ExtMgrDialog *>(this), &ExtMgrDialog::LinkStubHandleExtTypeCbx) ); | |||
467 | ||||
468 | m_xBundledCbx->set_active(true); | |||
469 | m_xSharedCbx->set_active(true); | |||
470 | m_xUserCbx->set_active(true); | |||
471 | ||||
472 | m_xProgressBar->hide(); | |||
473 | ||||
474 | #if ENABLE_EXTENSION_UPDATE1 | |||
475 | m_xUpdateBtn->connect_clicked( LINK( this, ExtMgrDialog, HandleUpdateBtn )::tools::detail::makeLink( ::tools::detail::castTo<ExtMgrDialog *>(this), &ExtMgrDialog::LinkStubHandleUpdateBtn) ); | |||
476 | m_xUpdateBtn->set_sensitive(false); | |||
477 | #else | |||
478 | m_xUpdateBtn->hide(); | |||
479 | #endif | |||
480 | ||||
481 | if (officecfg::Office::ExtensionManager::ExtensionSecurity::DisableExtensionInstallation::get()) | |||
482 | { | |||
483 | m_xAddBtn->set_sensitive(false); | |||
484 | m_xAddBtn->set_tooltip_text(DpResId(RID_STR_WARNING_INSTALL_EXTENSION_DISABLEDreinterpret_cast<char const *>("RID_STR_WARNING_INSTALL_EXTENSION_DISABLED" "\004" u8"Extension installation is currently disabled. " "Please consult your system administrator for more information." ))); | |||
485 | } | |||
486 | if (officecfg::Office::ExtensionManager::ExtensionSecurity::DisableExtensionRemoval::get()) | |||
487 | { | |||
488 | m_xRemoveBtn->set_sensitive(false); | |||
489 | m_xRemoveBtn->set_tooltip_text(DpResId(RID_STR_WARNING_REMOVE_EXTENSION_DISABLEDreinterpret_cast<char const *>("RID_STR_WARNING_REMOVE_EXTENSION_DISABLED" "\004" u8"Extension removal is currently disabled. " "Please consult your system administrator for more information." ))); | |||
490 | } | |||
491 | ||||
492 | m_aIdle.SetPriority(TaskPriority::LOWEST); | |||
493 | m_aIdle.SetDebugName( "ExtMgrDialog m_aIdle TimeOutHdl" ); | |||
494 | m_aIdle.SetInvokeHandler( LINK( this, ExtMgrDialog, TimeOutHdl )::tools::detail::makeLink( ::tools::detail::castTo<ExtMgrDialog *>(this), &ExtMgrDialog::LinkStubTimeOutHdl) ); | |||
495 | } | |||
496 | ||||
497 | ExtMgrDialog::~ExtMgrDialog() | |||
498 | { | |||
499 | m_aIdle.Stop(); | |||
500 | } | |||
501 | ||||
502 | void ExtMgrDialog::setGetExtensionsURL( const OUString &rURL ) | |||
503 | { | |||
504 | m_xGetExtensions->set_uri( rURL ); | |||
505 | } | |||
506 | ||||
507 | void ExtMgrDialog::addPackageToList( const uno::Reference< deployment::XPackage > &xPackage, | |||
508 | bool bLicenseMissing ) | |||
509 | { | |||
510 | const SolarMutexGuard aGuard; | |||
511 | m_xUpdateBtn->set_sensitive(true); | |||
512 | ||||
513 | if (m_xBundledCbx->get_active() && (xPackage->getRepositoryName() == BUNDLED_PACKAGE_MANAGER"bundled") ) | |||
514 | { | |||
515 | m_xExtensionBox->addEntry( xPackage, bLicenseMissing ); | |||
516 | } | |||
517 | else if (m_xSharedCbx->get_active() && (xPackage->getRepositoryName() == SHARED_PACKAGE_MANAGER"shared") ) | |||
518 | { | |||
519 | m_xExtensionBox->addEntry( xPackage, bLicenseMissing ); | |||
520 | } | |||
521 | else if (m_xUserCbx->get_active() && (xPackage->getRepositoryName() == USER_PACKAGE_MANAGER"user" )) | |||
522 | { | |||
523 | m_xExtensionBox->addEntry( xPackage, bLicenseMissing ); | |||
524 | } | |||
525 | } | |||
526 | ||||
527 | void ExtMgrDialog::prepareChecking() | |||
528 | { | |||
529 | m_xExtensionBox->prepareChecking(); | |||
530 | } | |||
531 | ||||
532 | void ExtMgrDialog::checkEntries() | |||
533 | { | |||
534 | const SolarMutexGuard guard; | |||
535 | m_xExtensionBox->checkEntries(); | |||
536 | } | |||
537 | ||||
538 | bool ExtMgrDialog::removeExtensionWarn(const OUString &rExtensionName) | |||
539 | { | |||
540 | const SolarMutexGuard guard; | |||
541 | incBusy(); | |||
542 | std::unique_ptr<weld::MessageDialog> xInfoBox(Application::CreateMessageDialog(m_xDialog.get(), | |||
543 | VclMessageType::Warning, VclButtonsType::OkCancel, | |||
544 | DpResId(RID_STR_WARNING_REMOVE_EXTENSIONreinterpret_cast<char const *>("RID_STR_WARNING_REMOVE_EXTENSION" "\004" u8"You are about to remove the extension '%NAME'.\n" "Click 'OK' to remove the extension.\n" "Click 'Cancel' to stop removing the extension.")))); | |||
545 | ||||
546 | OUString sText(xInfoBox->get_primary_text()); | |||
547 | sText = sText.replaceAll("%NAME", rExtensionName); | |||
548 | xInfoBox->set_primary_text(sText); | |||
549 | ||||
550 | bool bRet = RET_OK == xInfoBox->run(); | |||
551 | xInfoBox.reset(); | |||
552 | decBusy(); | |||
553 | ||||
554 | return bRet; | |||
555 | } | |||
556 | ||||
557 | void ExtMgrDialog::enablePackage( const uno::Reference< deployment::XPackage > &xPackage, | |||
558 | bool bEnable ) | |||
559 | { | |||
560 | if ( !xPackage.is() ) | |||
561 | return; | |||
562 | ||||
563 | if ( bEnable ) | |||
564 | { | |||
565 | if (!continueOnSharedExtension(xPackage, m_xDialog.get(), RID_STR_WARNING_ENABLE_SHARED_EXTENSIONreinterpret_cast<char const *>("RID_STR_WARNING_ENABLE_SHARED_EXTENSION" "\004" u8"Make sure that no further users are working with the same " "%PRODUCTNAME, when changing shared extensions in a multi user environment.\n" "Click 'OK' to enable the extension.\n" "Click 'Cancel' to stop enabling the extension." ), m_bEnableWarning)) | |||
566 | return; | |||
567 | } | |||
568 | else | |||
569 | { | |||
570 | if (!continueOnSharedExtension(xPackage, m_xDialog.get(), RID_STR_WARNING_DISABLE_SHARED_EXTENSIONreinterpret_cast<char const *>("RID_STR_WARNING_DISABLE_SHARED_EXTENSION" "\004" u8"Make sure that no further users are working with the same " "%PRODUCTNAME, when changing shared extensions in a multi user environment.\n" "Click 'OK' to disable the extension.\n" "Click 'Cancel' to stop disabling the extension." ), m_bDisableWarning)) | |||
571 | return; | |||
572 | } | |||
573 | ||||
574 | m_pManager->getCmdQueue()->enableExtension( xPackage, bEnable ); | |||
575 | } | |||
576 | ||||
577 | ||||
578 | void ExtMgrDialog::removePackage( const uno::Reference< deployment::XPackage > &xPackage ) | |||
579 | { | |||
580 | if ( !xPackage.is() ) | |||
581 | return; | |||
582 | ||||
583 | if ( !IsSharedPkgMgr( xPackage ) || m_bDeleteWarning ) | |||
584 | { | |||
585 | if ( ! removeExtensionWarn( xPackage->getDisplayName() ) ) | |||
586 | return; | |||
587 | } | |||
588 | ||||
589 | if (!continueOnSharedExtension(xPackage, m_xDialog.get(), RID_STR_WARNING_REMOVE_SHARED_EXTENSIONreinterpret_cast<char const *>("RID_STR_WARNING_REMOVE_SHARED_EXTENSION" "\004" u8"Make sure that no further users are working with the same " "%PRODUCTNAME, when changing shared extensions in a multi user environment.\n" "Click 'OK' to remove the extension.\n" "Click 'Cancel' to stop removing the extension." ), m_bDeleteWarning)) | |||
590 | return; | |||
591 | ||||
592 | m_pManager->getCmdQueue()->removeExtension( xPackage ); | |||
593 | } | |||
594 | ||||
595 | ||||
596 | void ExtMgrDialog::updatePackage( const uno::Reference< deployment::XPackage > &xPackage ) | |||
597 | { | |||
598 | if ( !xPackage.is() ) | |||
599 | return; | |||
600 | ||||
601 | // get the extension with highest version | |||
602 | uno::Sequence<uno::Reference<deployment::XPackage> > seqExtensions = | |||
603 | m_pManager->getExtensionManager()->getExtensionsWithSameIdentifier( | |||
604 | dp_misc::getIdentifier(xPackage), xPackage->getName(), uno::Reference<ucb::XCommandEnvironment>()); | |||
605 | uno::Reference<deployment::XPackage> extension = | |||
606 | dp_misc::getExtensionWithHighestVersion(seqExtensions); | |||
607 | OSL_ASSERT(extension.is())do { if (true && (!(extension.is()))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/desktop/source/deployment/gui/dp_gui_dialog2.cxx" ":" "607" ": "), "OSL_ASSERT: %s", "extension.is()"); } } while (false); | |||
608 | std::vector< css::uno::Reference< css::deployment::XPackage > > vEntries; | |||
609 | vEntries.push_back(extension); | |||
610 | ||||
611 | m_pManager->getCmdQueue()->checkForUpdates( vEntries ); | |||
612 | } | |||
613 | ||||
614 | ||||
615 | bool ExtMgrDialog::acceptLicense( const uno::Reference< deployment::XPackage > &xPackage ) | |||
616 | { | |||
617 | if ( !xPackage.is() ) | |||
618 | return false; | |||
619 | ||||
620 | m_pManager->getCmdQueue()->acceptLicense( xPackage ); | |||
621 | ||||
622 | return true; | |||
623 | } | |||
624 | ||||
625 | ||||
626 | uno::Sequence< OUString > ExtMgrDialog::raiseAddPicker() | |||
627 | { | |||
628 | sfx2::FileDialogHelper aDlgHelper(ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE, FileDialogFlags::NONE, m_xDialog.get()); | |||
629 | const uno::Reference<ui::dialogs::XFilePicker3>& xFilePicker = aDlgHelper.GetFilePicker(); | |||
630 | xFilePicker->setTitle( m_sAddPackages ); | |||
631 | ||||
632 | if ( !m_sLastFolderURL.isEmpty() ) | |||
633 | xFilePicker->setDisplayDirectory( m_sLastFolderURL ); | |||
634 | ||||
635 | // collect and set filter list: | |||
636 | typedef std::map< OUString, OUString > t_string2string; | |||
637 | t_string2string title2filter; | |||
638 | OUStringBuffer supportedFilters; | |||
639 | ||||
640 | const uno::Sequence< uno::Reference< deployment::XPackageTypeInfo > > packageTypes( | |||
641 | m_pManager->getExtensionManager()->getSupportedPackageTypes() ); | |||
642 | ||||
643 | for ( uno::Reference< deployment::XPackageTypeInfo > const & xPackageType : packageTypes ) | |||
644 | { | |||
645 | const OUString filter( xPackageType->getFileFilter() ); | |||
646 | if (!filter.isEmpty()) | |||
647 | { | |||
648 | const OUString title( xPackageType->getShortDescription() ); | |||
649 | const std::pair< t_string2string::iterator, bool > insertion( | |||
650 | title2filter.emplace( title, filter ) ); | |||
651 | if (!supportedFilters.isEmpty()) | |||
652 | supportedFilters.append(';'); | |||
653 | supportedFilters.append(filter); | |||
654 | if ( ! insertion.second ) | |||
655 | { // already existing, append extensions: | |||
656 | OUStringBuffer buf; | |||
657 | buf.append( insertion.first->second ); | |||
658 | buf.append( ';' ); | |||
659 | buf.append( filter ); | |||
660 | insertion.first->second = buf.makeStringAndClear(); | |||
661 | } | |||
662 | } | |||
663 | } | |||
664 | ||||
665 | // All files at top: | |||
666 | xFilePicker->appendFilter( StrAllFiles::get(), "*.*" ); | |||
667 | xFilePicker->appendFilter( DpResId(RID_STR_ALL_SUPPORTEDreinterpret_cast<char const *>("RID_STR_PACKAGE_BUNDLE" "\004" u8"All supported files")), supportedFilters.makeStringAndClear() ); | |||
668 | // then supported ones: | |||
669 | for (auto const& elem : title2filter) | |||
670 | { | |||
671 | try | |||
672 | { | |||
673 | xFilePicker->appendFilter( elem.first, elem.second ); | |||
674 | } | |||
675 | catch (const lang::IllegalArgumentException &) | |||
676 | { | |||
677 | TOOLS_WARN_EXCEPTION( "desktop", "" )do { css::uno::Any tools_warn_exception( DbgGetCaughtException () ); do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_WARN , "desktop")) { 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), ("desktop"), ("/home/maarten/src/libreoffice/core/desktop/source/deployment/gui/dp_gui_dialog2.cxx" ":" "677" ": "), ::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 ), ("desktop"), ("/home/maarten/src/libreoffice/core/desktop/source/deployment/gui/dp_gui_dialog2.cxx" ":" "677" ": "), 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), ( "desktop"), ("/home/maarten/src/libreoffice/core/desktop/source/deployment/gui/dp_gui_dialog2.cxx" ":" "677" ": "), ::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 ), ("desktop"), ("/home/maarten/src/libreoffice/core/desktop/source/deployment/gui/dp_gui_dialog2.cxx" ":" "677" ": "), sal_detail_stream, 0); }; std::abort(); break ; } } } while (false); } while (false); | |||
678 | } | |||
679 | } | |||
680 | xFilePicker->setCurrentFilter( DpResId(RID_STR_ALL_SUPPORTEDreinterpret_cast<char const *>("RID_STR_PACKAGE_BUNDLE" "\004" u8"All supported files")) ); | |||
681 | ||||
682 | if ( xFilePicker->execute() != ui::dialogs::ExecutableDialogResults::OK ) | |||
683 | return uno::Sequence<OUString>(); // cancelled | |||
684 | ||||
685 | m_sLastFolderURL = xFilePicker->getDisplayDirectory(); | |||
686 | uno::Sequence< OUString > files( xFilePicker->getSelectedFiles() ); | |||
687 | OSL_ASSERT( files.hasElements() )do { if (true && (!(files.hasElements()))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/desktop/source/deployment/gui/dp_gui_dialog2.cxx" ":" "687" ": "), "OSL_ASSERT: %s", "files.hasElements()"); } } while (false); | |||
688 | return files; | |||
689 | } | |||
690 | ||||
691 | void ExtMgrDialog::enableOptionsButton( bool bEnable ) | |||
692 | { | |||
693 | m_xOptionsBtn->set_sensitive( bEnable ); | |||
694 | } | |||
695 | ||||
696 | void ExtMgrDialog::enableRemoveButton( bool bEnable ) | |||
697 | { | |||
698 | m_xRemoveBtn->set_sensitive( bEnable && !officecfg::Office::ExtensionManager::ExtensionSecurity::DisableExtensionRemoval::get()); | |||
699 | ||||
700 | if (officecfg::Office::ExtensionManager::ExtensionSecurity::DisableExtensionRemoval::get()) | |||
701 | { | |||
702 | m_xRemoveBtn->set_tooltip_text(DpResId(RID_STR_WARNING_REMOVE_EXTENSION_DISABLEDreinterpret_cast<char const *>("RID_STR_WARNING_REMOVE_EXTENSION_DISABLED" "\004" u8"Extension removal is currently disabled. " "Please consult your system administrator for more information." ))); | |||
703 | } | |||
704 | else | |||
705 | { | |||
706 | m_xRemoveBtn->set_tooltip_text(""); | |||
707 | } | |||
708 | } | |||
709 | ||||
710 | void ExtMgrDialog::enableEnableButton( bool bEnable ) | |||
711 | { | |||
712 | m_xEnableBtn->set_sensitive( bEnable ); | |||
713 | } | |||
714 | ||||
715 | void ExtMgrDialog::enableButtontoEnable( bool bEnable ) | |||
716 | { | |||
717 | if (bEnable) | |||
718 | { | |||
719 | m_xEnableBtn->set_label( DpResId( RID_CTX_ITEM_ENABLEreinterpret_cast<char const *>("RID_CTX_ITEM_ENABLE" "\004" u8"~Enable") ) ); | |||
720 | m_xEnableBtn->set_help_id( HID_EXTENSION_MANAGER_LISTBOX_ENABLE"DESKTOP_HID_EXTENSION_MANAGER_LISTBOX_ENABLE" ); | |||
721 | } | |||
722 | else | |||
723 | { | |||
724 | m_xEnableBtn->set_label( DpResId( RID_CTX_ITEM_DISABLEreinterpret_cast<char const *>("RID_CTX_ITEM_DISABLE" "\004" u8"~Disable") ) ); | |||
725 | m_xEnableBtn->set_help_id( HID_EXTENSION_MANAGER_LISTBOX_DISABLE"DESKTOP_HID_EXTENSION_MANAGER_LISTBOX_DISABLE" ); | |||
726 | } | |||
727 | } | |||
728 | ||||
729 | IMPL_LINK_NOARG(ExtMgrDialog, HandleCancelBtn, weld::Button&, void)void ExtMgrDialog::LinkStubHandleCancelBtn(void * instance, weld ::Button& data) { return static_cast<ExtMgrDialog *> (instance)->HandleCancelBtn(data); } void ExtMgrDialog::HandleCancelBtn (__attribute__ ((unused)) weld::Button&) | |||
730 | { | |||
731 | if ( m_xAbortChannel.is() ) | |||
732 | { | |||
733 | try | |||
734 | { | |||
735 | m_xAbortChannel->sendAbort(); | |||
736 | } | |||
737 | catch ( const uno::RuntimeException & ) | |||
738 | { | |||
739 | OSL_FAIL( "### unexpected RuntimeException!" )do { if (true && (((sal_Bool)1))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/desktop/source/deployment/gui/dp_gui_dialog2.cxx" ":" "739" ": "), "%s", "### unexpected RuntimeException!"); } } while (false); | |||
740 | } | |||
741 | } | |||
742 | } | |||
743 | ||||
744 | IMPL_LINK_NOARG(ExtMgrDialog, HandleCloseBtn, weld::Button&, void)void ExtMgrDialog::LinkStubHandleCloseBtn(void * instance, weld ::Button& data) { return static_cast<ExtMgrDialog *> (instance)->HandleCloseBtn(data); } void ExtMgrDialog::HandleCloseBtn (__attribute__ ((unused)) weld::Button&) | |||
745 | { | |||
746 | bool bCallClose = true; | |||
747 | ||||
748 | //only suggest restart if modified and this is the first close attempt | |||
749 | if (!m_bClosed && m_pManager->isModified()) | |||
750 | { | |||
751 | m_pManager->clearModified(); | |||
752 | ||||
753 | //only suggest restart if we're actually running, e.g. not from standalone unopkg gui | |||
754 | if (dp_misc::office_is_running()) | |||
755 | { | |||
756 | SolarMutexGuard aGuard; | |||
757 | bCallClose = !::svtools::executeRestartDialog(comphelper::getProcessComponentContext(), | |||
758 | m_xDialog.get(), | |||
759 | svtools::RESTART_REASON_EXTENSION_INSTALL); | |||
760 | } | |||
761 | } | |||
762 | ||||
763 | if (bCallClose) | |||
764 | m_xDialog->response(RET_CANCEL); | |||
765 | } | |||
766 | ||||
767 | IMPL_LINK( ExtMgrDialog, startProgress, void*, _bLockInterface, void )void ExtMgrDialog::LinkStubstartProgress(void * instance, void * data) { return static_cast<ExtMgrDialog *>(instance)-> startProgress(data); } void ExtMgrDialog::startProgress(void* _bLockInterface) | |||
768 | { | |||
769 | ::osl::MutexGuard aGuard( m_aMutex ); | |||
770 | bool bLockInterface = static_cast<bool>(_bLockInterface); | |||
771 | ||||
772 | if ( m_bStartProgress && !m_bHasProgress ) | |||
773 | m_aIdle.Start(); | |||
774 | ||||
775 | if ( m_bStopProgress ) | |||
776 | { | |||
777 | if ( m_xProgressBar->get_visible() ) | |||
778 | m_xProgressBar->set_percentage( 100 ); | |||
779 | m_xAbortChannel.clear(); | |||
780 | ||||
781 | SAL_INFO( "desktop.deployment", " startProgress handler: stop" )do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_INFO , "desktop.deployment")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail ::getResult( ::sal::detail::StreamStart() << " startProgress handler: stop" ) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("desktop.deployment" ), ("/home/maarten/src/libreoffice/core/desktop/source/deployment/gui/dp_gui_dialog2.cxx" ":" "781" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << " startProgress handler: stop"), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << " startProgress handler: stop"; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("desktop.deployment"), ("/home/maarten/src/libreoffice/core/desktop/source/deployment/gui/dp_gui_dialog2.cxx" ":" "781" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << " startProgress handler: stop") == 1) { ::sal_detail_log ( (::SAL_DETAIL_LOG_LEVEL_INFO), ("desktop.deployment"), ("/home/maarten/src/libreoffice/core/desktop/source/deployment/gui/dp_gui_dialog2.cxx" ":" "781" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << " startProgress handler: stop"), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << " startProgress handler: stop"; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("desktop.deployment"), ("/home/maarten/src/libreoffice/core/desktop/source/deployment/gui/dp_gui_dialog2.cxx" ":" "781" ": "), sal_detail_stream, 0); }; std::abort(); break ; } } } while (false); | |||
782 | } | |||
783 | else | |||
784 | { | |||
785 | SAL_INFO( "desktop.deployment", " startProgress handler: start" )do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_INFO , "desktop.deployment")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail ::getResult( ::sal::detail::StreamStart() << " startProgress handler: start" ) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("desktop.deployment" ), ("/home/maarten/src/libreoffice/core/desktop/source/deployment/gui/dp_gui_dialog2.cxx" ":" "785" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << " startProgress handler: start"), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << " startProgress handler: start"; ::sal::detail::log ( (::SAL_DETAIL_LOG_LEVEL_INFO), ("desktop.deployment"), ("/home/maarten/src/libreoffice/core/desktop/source/deployment/gui/dp_gui_dialog2.cxx" ":" "785" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << " startProgress handler: start") == 1) { ::sal_detail_log ( (::SAL_DETAIL_LOG_LEVEL_INFO), ("desktop.deployment"), ("/home/maarten/src/libreoffice/core/desktop/source/deployment/gui/dp_gui_dialog2.cxx" ":" "785" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << " startProgress handler: start"), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << " startProgress handler: start"; ::sal::detail::log ( (::SAL_DETAIL_LOG_LEVEL_INFO), ("desktop.deployment"), ("/home/maarten/src/libreoffice/core/desktop/source/deployment/gui/dp_gui_dialog2.cxx" ":" "785" ": "), sal_detail_stream, 0); }; std::abort(); break ; } } } while (false); | |||
786 | } | |||
787 | ||||
788 | m_xCancelBtn->set_sensitive( bLockInterface ); | |||
789 | m_xAddBtn->set_sensitive( !bLockInterface && !officecfg::Office::ExtensionManager::ExtensionSecurity::DisableExtensionInstallation::get()); | |||
790 | if (officecfg::Office::ExtensionManager::ExtensionSecurity::DisableExtensionInstallation::get()) | |||
791 | { | |||
792 | m_xAddBtn->set_tooltip_text(DpResId(RID_STR_WARNING_INSTALL_EXTENSION_DISABLEDreinterpret_cast<char const *>("RID_STR_WARNING_INSTALL_EXTENSION_DISABLED" "\004" u8"Extension installation is currently disabled. " "Please consult your system administrator for more information." ))); | |||
793 | } | |||
794 | else | |||
795 | { | |||
796 | m_xAddBtn->set_tooltip_text(""); | |||
797 | } | |||
798 | ||||
799 | m_xUpdateBtn->set_sensitive( !bLockInterface && m_xExtensionBox->getItemCount() ); | |||
800 | m_xExtensionBox->enableButtons( !bLockInterface ); | |||
801 | ||||
802 | clearEventID(); | |||
803 | } | |||
804 | ||||
805 | ||||
806 | void ExtMgrDialog::showProgress( bool _bStart ) | |||
807 | { | |||
808 | ::osl::MutexGuard aGuard( m_aMutex ); | |||
809 | ||||
810 | bool bStart = _bStart; | |||
811 | ||||
812 | if ( bStart ) | |||
813 | { | |||
814 | m_nProgress = 0; | |||
815 | m_bStartProgress = true; | |||
816 | SAL_INFO( "desktop.deployment", "showProgress start" )do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_INFO , "desktop.deployment")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail ::getResult( ::sal::detail::StreamStart() << "showProgress start" ) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("desktop.deployment" ), ("/home/maarten/src/libreoffice/core/desktop/source/deployment/gui/dp_gui_dialog2.cxx" ":" "816" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << "showProgress start"), 0); } else { :: std::ostringstream sal_detail_stream; sal_detail_stream << "showProgress start"; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO ), ("desktop.deployment"), ("/home/maarten/src/libreoffice/core/desktop/source/deployment/gui/dp_gui_dialog2.cxx" ":" "816" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << "showProgress start") == 1) { ::sal_detail_log( ( ::SAL_DETAIL_LOG_LEVEL_INFO), ("desktop.deployment"), ("/home/maarten/src/libreoffice/core/desktop/source/deployment/gui/dp_gui_dialog2.cxx" ":" "816" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << "showProgress start"), 0); } else { :: std::ostringstream sal_detail_stream; sal_detail_stream << "showProgress start"; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO ), ("desktop.deployment"), ("/home/maarten/src/libreoffice/core/desktop/source/deployment/gui/dp_gui_dialog2.cxx" ":" "816" ": "), sal_detail_stream, 0); }; std::abort(); break ; } } } while (false); | |||
817 | } | |||
818 | else | |||
819 | { | |||
820 | m_nProgress = 100; | |||
821 | m_bStopProgress = true; | |||
822 | SAL_INFO( "desktop.deployment", "showProgress stop!" )do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_INFO , "desktop.deployment")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail ::getResult( ::sal::detail::StreamStart() << "showProgress stop!" ) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("desktop.deployment" ), ("/home/maarten/src/libreoffice/core/desktop/source/deployment/gui/dp_gui_dialog2.cxx" ":" "822" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << "showProgress stop!"), 0); } else { :: std::ostringstream sal_detail_stream; sal_detail_stream << "showProgress stop!"; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO ), ("desktop.deployment"), ("/home/maarten/src/libreoffice/core/desktop/source/deployment/gui/dp_gui_dialog2.cxx" ":" "822" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << "showProgress stop!") == 1) { ::sal_detail_log( ( ::SAL_DETAIL_LOG_LEVEL_INFO), ("desktop.deployment"), ("/home/maarten/src/libreoffice/core/desktop/source/deployment/gui/dp_gui_dialog2.cxx" ":" "822" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << "showProgress stop!"), 0); } else { :: std::ostringstream sal_detail_stream; sal_detail_stream << "showProgress stop!"; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO ), ("desktop.deployment"), ("/home/maarten/src/libreoffice/core/desktop/source/deployment/gui/dp_gui_dialog2.cxx" ":" "822" ": "), sal_detail_stream, 0); }; std::abort(); break ; } } } while (false); | |||
823 | } | |||
824 | ||||
825 | DialogHelper::PostUserEvent( LINK( this, ExtMgrDialog, startProgress )::tools::detail::makeLink( ::tools::detail::castTo<ExtMgrDialog *>(this), &ExtMgrDialog::LinkStubstartProgress), reinterpret_cast<void*>(bStart) ); | |||
826 | m_aIdle.Start(); | |||
827 | } | |||
828 | ||||
829 | ||||
830 | void ExtMgrDialog::updateProgress( const long nProgress ) | |||
831 | { | |||
832 | if ( m_nProgress != nProgress ) | |||
833 | { | |||
834 | ::osl::MutexGuard aGuard( m_aMutex ); | |||
835 | m_nProgress = nProgress; | |||
836 | m_aIdle.Start(); | |||
837 | } | |||
838 | } | |||
839 | ||||
840 | ||||
841 | void ExtMgrDialog::updateProgress( const OUString &rText, | |||
842 | const uno::Reference< task::XAbortChannel > &xAbortChannel) | |||
843 | { | |||
844 | ::osl::MutexGuard aGuard( m_aMutex ); | |||
845 | ||||
846 | m_xAbortChannel = xAbortChannel; | |||
847 | m_sProgressText = rText; | |||
848 | m_bProgressChanged = true; | |||
849 | m_aIdle.Start(); | |||
850 | } | |||
851 | ||||
852 | ||||
853 | void ExtMgrDialog::updatePackageInfo( const uno::Reference< deployment::XPackage > &xPackage ) | |||
854 | { | |||
855 | const SolarMutexGuard aGuard; | |||
856 | m_xExtensionBox->updateEntry( xPackage ); | |||
857 | } | |||
858 | ||||
859 | IMPL_LINK_NOARG(ExtMgrDialog, HandleOptionsBtn, weld::Button&, void)void ExtMgrDialog::LinkStubHandleOptionsBtn(void * instance, weld ::Button& data) { return static_cast<ExtMgrDialog *> (instance)->HandleOptionsBtn(data); } void ExtMgrDialog::HandleOptionsBtn (__attribute__ ((unused)) weld::Button&) | |||
| ||||
860 | { | |||
861 | const sal_Int32 nActive = m_xExtensionBox->getSelIndex(); | |||
862 | ||||
863 | if ( nActive != ExtensionBox_Impl::ENTRY_NOTFOUND ) | |||
864 | { | |||
865 | SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create(); | |||
866 | ||||
867 | OUString sExtensionId = m_xExtensionBox->GetEntryData( nActive )->m_xPackage->getIdentifier().Value; | |||
868 | ScopedVclPtr<VclAbstractDialog> pDlg(pFact->CreateOptionsDialog(m_xDialog.get(), sExtensionId)); | |||
869 | ||||
870 | pDlg->Execute(); | |||
871 | } | |||
872 | } | |||
873 | ||||
874 | IMPL_LINK_NOARG(ExtMgrDialog, HandleAddBtn, weld::Button&, void)void ExtMgrDialog::LinkStubHandleAddBtn(void * instance, weld ::Button& data) { return static_cast<ExtMgrDialog *> (instance)->HandleAddBtn(data); } void ExtMgrDialog::HandleAddBtn (__attribute__ ((unused)) weld::Button&) | |||
875 | { | |||
876 | incBusy(); | |||
877 | ||||
878 | uno::Sequence< OUString > aFileList = raiseAddPicker(); | |||
879 | ||||
880 | if ( aFileList.hasElements() ) | |||
881 | { | |||
882 | m_pManager->installPackage( aFileList[0] ); | |||
883 | } | |||
884 | ||||
885 | decBusy(); | |||
886 | } | |||
887 | ||||
888 | IMPL_LINK_NOARG(ExtMgrDialog, HandleRemoveBtn, weld::Button&, void)void ExtMgrDialog::LinkStubHandleRemoveBtn(void * instance, weld ::Button& data) { return static_cast<ExtMgrDialog *> (instance)->HandleRemoveBtn(data); } void ExtMgrDialog::HandleRemoveBtn (__attribute__ ((unused)) weld::Button&) | |||
889 | { | |||
890 | const sal_Int32 nActive = m_xExtensionBox->getSelIndex(); | |||
891 | ||||
892 | if ( nActive != ExtensionBox_Impl::ENTRY_NOTFOUND ) | |||
893 | { | |||
894 | TEntry_Impl pEntry = m_xExtensionBox->GetEntryData( nActive ); | |||
895 | removePackage( pEntry->m_xPackage ); | |||
896 | } | |||
897 | } | |||
898 | ||||
899 | IMPL_LINK_NOARG(ExtMgrDialog, HandleEnableBtn, weld::Button&, void)void ExtMgrDialog::LinkStubHandleEnableBtn(void * instance, weld ::Button& data) { return static_cast<ExtMgrDialog *> (instance)->HandleEnableBtn(data); } void ExtMgrDialog::HandleEnableBtn (__attribute__ ((unused)) weld::Button&) | |||
900 | { | |||
901 | const sal_Int32 nActive = m_xExtensionBox->getSelIndex(); | |||
902 | ||||
903 | if ( nActive != ExtensionBox_Impl::ENTRY_NOTFOUND ) | |||
904 | { | |||
905 | TEntry_Impl pEntry = m_xExtensionBox->GetEntryData( nActive ); | |||
906 | ||||
907 | if ( pEntry->m_bMissingLic ) | |||
908 | acceptLicense( pEntry->m_xPackage ); | |||
909 | else | |||
910 | { | |||
911 | const bool bEnable( pEntry->m_eState != REGISTERED ); | |||
912 | enablePackage( pEntry->m_xPackage, bEnable ); | |||
913 | } | |||
914 | } | |||
915 | } | |||
916 | ||||
917 | IMPL_LINK_NOARG(ExtMgrDialog, HandleExtTypeCbx, weld::Button&, void)void ExtMgrDialog::LinkStubHandleExtTypeCbx(void * instance, weld ::Button& data) { return static_cast<ExtMgrDialog *> (instance)->HandleExtTypeCbx(data); } void ExtMgrDialog::HandleExtTypeCbx (__attribute__ ((unused)) weld::Button&) | |||
918 | { | |||
919 | // re-creates the list of packages with addEntry selecting the packages | |||
920 | prepareChecking(); | |||
921 | m_pManager->createPackageList(); | |||
922 | checkEntries(); | |||
923 | } | |||
924 | ||||
925 | IMPL_LINK_NOARG(ExtMgrDialog, HandleUpdateBtn, weld::Button&, void)void ExtMgrDialog::LinkStubHandleUpdateBtn(void * instance, weld ::Button& data) { return static_cast<ExtMgrDialog *> (instance)->HandleUpdateBtn(data); } void ExtMgrDialog::HandleUpdateBtn (__attribute__ ((unused)) weld::Button&) | |||
926 | { | |||
927 | #if ENABLE_EXTENSION_UPDATE1 | |||
928 | m_pManager->checkUpdates(); | |||
929 | #else | |||
930 | (void) this; | |||
931 | #endif | |||
932 | } | |||
933 | ||||
934 | IMPL_LINK_NOARG(ExtMgrDialog, TimeOutHdl, Timer *, void)void ExtMgrDialog::LinkStubTimeOutHdl(void * instance, Timer * data) { return static_cast<ExtMgrDialog *>(instance)-> TimeOutHdl(data); } void ExtMgrDialog::TimeOutHdl(__attribute__ ((unused)) Timer *) | |||
935 | { | |||
936 | if ( m_bStopProgress ) | |||
937 | { | |||
938 | m_bHasProgress = false; | |||
939 | m_bStopProgress = false; | |||
940 | m_xProgressText->hide(); | |||
941 | m_xProgressBar->hide(); | |||
942 | m_xCancelBtn->hide(); | |||
943 | } | |||
944 | else | |||
945 | { | |||
946 | if ( m_bProgressChanged ) | |||
947 | { | |||
948 | m_bProgressChanged = false; | |||
949 | m_xProgressText->set_label(m_sProgressText); | |||
950 | } | |||
951 | ||||
952 | if ( m_bStartProgress ) | |||
953 | { | |||
954 | m_bStartProgress = false; | |||
955 | m_bHasProgress = true; | |||
956 | m_xProgressBar->show(); | |||
957 | m_xProgressText->show(); | |||
958 | m_xCancelBtn->set_sensitive(true); | |||
959 | m_xCancelBtn->show(); | |||
960 | } | |||
961 | ||||
962 | if ( m_xProgressBar->get_visible() ) | |||
963 | m_xProgressBar->set_percentage( static_cast<sal_uInt16>(m_nProgress) ); | |||
964 | } | |||
965 | } | |||
966 | ||||
967 | void ExtMgrDialog::Close() | |||
968 | { | |||
969 | m_pManager->terminateDialog(); | |||
970 | m_bClosed = true; | |||
971 | } | |||
972 | ||||
973 | //UpdateRequiredDialog | |||
974 | UpdateRequiredDialog::UpdateRequiredDialog(weld::Window *pParent, TheExtensionManager *pManager) | |||
975 | : GenericDialogController(pParent, "desktop/ui/updaterequireddialog.ui", "UpdateRequiredDialog") | |||
976 | , DialogHelper(pManager->getContext(), m_xDialog.get()) | |||
977 | , m_sCloseText(DpResId(RID_STR_CLOSE_BTNreinterpret_cast<char const *>("RID_STR_CLOSE_BTN" "\004" u8"Close"))) | |||
978 | , m_bHasProgress(false) | |||
979 | , m_bProgressChanged(false) | |||
980 | , m_bStartProgress(false) | |||
981 | , m_bStopProgress(false) | |||
982 | , m_bHasLockedEntries(false) | |||
983 | , m_nProgress(0) | |||
984 | , m_pManager(pManager) | |||
985 | , m_xExtensionBox(new ExtensionBox_Impl(m_xBuilder->weld_scrolled_window("scroll", true))) | |||
986 | , m_xExtensionBoxWnd(new weld::CustomWeld(*m_xBuilder, "extensions", *m_xExtensionBox)) | |||
987 | , m_xUpdateNeeded(m_xBuilder->weld_label("updatelabel")) | |||
988 | , m_xUpdateBtn(m_xBuilder->weld_button("ok")) | |||
989 | , m_xCloseBtn(m_xBuilder->weld_button("disable")) | |||
990 | , m_xCancelBtn(m_xBuilder->weld_button("cancel")) | |||
991 | , m_xProgressText(m_xBuilder->weld_label("progresslabel")) | |||
992 | , m_xProgressBar(m_xBuilder->weld_progress_bar("progress")) | |||
993 | { | |||
994 | m_xExtensionBox->setExtensionManager(pManager); | |||
995 | ||||
996 | m_xUpdateBtn->connect_clicked( LINK( this, UpdateRequiredDialog, HandleUpdateBtn )::tools::detail::makeLink( ::tools::detail::castTo<UpdateRequiredDialog *>(this), &UpdateRequiredDialog::LinkStubHandleUpdateBtn ) ); | |||
997 | m_xCloseBtn->connect_clicked( LINK( this, UpdateRequiredDialog, HandleCloseBtn )::tools::detail::makeLink( ::tools::detail::castTo<UpdateRequiredDialog *>(this), &UpdateRequiredDialog::LinkStubHandleCloseBtn ) ); | |||
998 | m_xCancelBtn->connect_clicked( LINK( this, UpdateRequiredDialog, HandleCancelBtn )::tools::detail::makeLink( ::tools::detail::castTo<UpdateRequiredDialog *>(this), &UpdateRequiredDialog::LinkStubHandleCancelBtn ) ); | |||
999 | ||||
1000 | OUString aText = m_xUpdateNeeded->get_label(); | |||
1001 | aText = aText.replaceAll( | |||
1002 | "%PRODUCTNAME", utl::ConfigManager::getProductName()); | |||
1003 | m_xUpdateNeeded->set_label(aText); | |||
1004 | ||||
1005 | m_xProgressBar->hide(); | |||
1006 | m_xUpdateBtn->set_sensitive( false ); | |||
1007 | m_xCloseBtn->grab_focus(); | |||
1008 | ||||
1009 | m_aIdle.SetPriority( TaskPriority::LOWEST ); | |||
1010 | m_aIdle.SetDebugName( "UpdateRequiredDialog m_aIdle TimeOutHdl" ); | |||
1011 | m_aIdle.SetInvokeHandler( LINK( this, UpdateRequiredDialog, TimeOutHdl )::tools::detail::makeLink( ::tools::detail::castTo<UpdateRequiredDialog *>(this), &UpdateRequiredDialog::LinkStubTimeOutHdl) ); | |||
1012 | } | |||
1013 | ||||
1014 | UpdateRequiredDialog::~UpdateRequiredDialog() | |||
1015 | { | |||
1016 | m_aIdle.Stop(); | |||
1017 | } | |||
1018 | ||||
1019 | void UpdateRequiredDialog::addPackageToList( const uno::Reference< deployment::XPackage > &xPackage, | |||
1020 | bool bLicenseMissing ) | |||
1021 | { | |||
1022 | // We will only add entries to the list with unsatisfied dependencies | |||
1023 | if ( !bLicenseMissing && !checkDependencies( xPackage ) ) | |||
1024 | { | |||
1025 | m_bHasLockedEntries |= m_pManager->isReadOnly( xPackage ); | |||
1026 | const SolarMutexGuard aGuard; | |||
1027 | m_xUpdateBtn->set_sensitive(true); | |||
1028 | m_xExtensionBox->addEntry( xPackage ); | |||
1029 | } | |||
1030 | } | |||
1031 | ||||
1032 | ||||
1033 | void UpdateRequiredDialog::prepareChecking() | |||
1034 | { | |||
1035 | m_xExtensionBox->prepareChecking(); | |||
1036 | } | |||
1037 | ||||
1038 | ||||
1039 | void UpdateRequiredDialog::checkEntries() | |||
1040 | { | |||
1041 | const SolarMutexGuard guard; | |||
1042 | m_xExtensionBox->checkEntries(); | |||
1043 | ||||
1044 | if ( ! hasActiveEntries() ) | |||
1045 | { | |||
1046 | m_xCloseBtn->set_label( m_sCloseText ); | |||
1047 | m_xCloseBtn->grab_focus(); | |||
1048 | } | |||
1049 | } | |||
1050 | ||||
1051 | ||||
1052 | IMPL_LINK_NOARG(UpdateRequiredDialog, HandleCancelBtn, weld::Button&, void)void UpdateRequiredDialog::LinkStubHandleCancelBtn(void * instance , weld::Button& data) { return static_cast<UpdateRequiredDialog *>(instance)->HandleCancelBtn(data); } void UpdateRequiredDialog ::HandleCancelBtn(__attribute__ ((unused)) weld::Button&) | |||
1053 | { | |||
1054 | if ( m_xAbortChannel.is() ) | |||
1055 | { | |||
1056 | try | |||
1057 | { | |||
1058 | m_xAbortChannel->sendAbort(); | |||
1059 | } | |||
1060 | catch ( const uno::RuntimeException & ) | |||
1061 | { | |||
1062 | OSL_FAIL( "### unexpected RuntimeException!" )do { if (true && (((sal_Bool)1))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/desktop/source/deployment/gui/dp_gui_dialog2.cxx" ":" "1062" ": "), "%s", "### unexpected RuntimeException!"); } } while (false); | |||
1063 | } | |||
1064 | } | |||
1065 | } | |||
1066 | ||||
1067 | ||||
1068 | IMPL_LINK( UpdateRequiredDialog, startProgress, void*, _bLockInterface, void )void UpdateRequiredDialog::LinkStubstartProgress(void * instance , void* data) { return static_cast<UpdateRequiredDialog *> (instance)->startProgress(data); } void UpdateRequiredDialog ::startProgress(void* _bLockInterface) | |||
1069 | { | |||
1070 | ::osl::MutexGuard aGuard( m_aMutex ); | |||
1071 | bool bLockInterface = static_cast<bool>(_bLockInterface); | |||
1072 | ||||
1073 | if ( m_bStartProgress && !m_bHasProgress ) | |||
1074 | m_aIdle.Start(); | |||
1075 | ||||
1076 | if ( m_bStopProgress ) | |||
1077 | { | |||
1078 | if ( m_xProgressBar->get_visible() ) | |||
1079 | m_xProgressBar->set_percentage( 100 ); | |||
1080 | m_xAbortChannel.clear(); | |||
1081 | SAL_INFO( "desktop.deployment", " startProgress handler: stop" )do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_INFO , "desktop.deployment")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail ::getResult( ::sal::detail::StreamStart() << " startProgress handler: stop" ) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("desktop.deployment" ), ("/home/maarten/src/libreoffice/core/desktop/source/deployment/gui/dp_gui_dialog2.cxx" ":" "1081" ": "), ::sal::detail::unwrapStream( ::sal::detail ::StreamStart() << " startProgress handler: stop"), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << " startProgress handler: stop"; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("desktop.deployment"), ("/home/maarten/src/libreoffice/core/desktop/source/deployment/gui/dp_gui_dialog2.cxx" ":" "1081" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << " startProgress handler: stop") == 1) { ::sal_detail_log ( (::SAL_DETAIL_LOG_LEVEL_INFO), ("desktop.deployment"), ("/home/maarten/src/libreoffice/core/desktop/source/deployment/gui/dp_gui_dialog2.cxx" ":" "1081" ": "), ::sal::detail::unwrapStream( ::sal::detail ::StreamStart() << " startProgress handler: stop"), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << " startProgress handler: stop"; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("desktop.deployment"), ("/home/maarten/src/libreoffice/core/desktop/source/deployment/gui/dp_gui_dialog2.cxx" ":" "1081" ": "), sal_detail_stream, 0); }; std::abort(); break ; } } } while (false); | |||
1082 | } | |||
1083 | else | |||
1084 | { | |||
1085 | SAL_INFO( "desktop.deployment", " startProgress handler: start" )do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_INFO , "desktop.deployment")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail ::getResult( ::sal::detail::StreamStart() << " startProgress handler: start" ) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("desktop.deployment" ), ("/home/maarten/src/libreoffice/core/desktop/source/deployment/gui/dp_gui_dialog2.cxx" ":" "1085" ": "), ::sal::detail::unwrapStream( ::sal::detail ::StreamStart() << " startProgress handler: start"), 0) ; } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << " startProgress handler: start"; ::sal::detail::log ( (::SAL_DETAIL_LOG_LEVEL_INFO), ("desktop.deployment"), ("/home/maarten/src/libreoffice/core/desktop/source/deployment/gui/dp_gui_dialog2.cxx" ":" "1085" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << " startProgress handler: start") == 1) { ::sal_detail_log ( (::SAL_DETAIL_LOG_LEVEL_INFO), ("desktop.deployment"), ("/home/maarten/src/libreoffice/core/desktop/source/deployment/gui/dp_gui_dialog2.cxx" ":" "1085" ": "), ::sal::detail::unwrapStream( ::sal::detail ::StreamStart() << " startProgress handler: start"), 0) ; } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << " startProgress handler: start"; ::sal::detail::log ( (::SAL_DETAIL_LOG_LEVEL_INFO), ("desktop.deployment"), ("/home/maarten/src/libreoffice/core/desktop/source/deployment/gui/dp_gui_dialog2.cxx" ":" "1085" ": "), sal_detail_stream, 0); }; std::abort(); break ; } } } while (false); | |||
1086 | } | |||
1087 | ||||
1088 | m_xCancelBtn->set_sensitive( bLockInterface ); | |||
1089 | m_xUpdateBtn->set_sensitive( false ); | |||
1090 | clearEventID(); | |||
1091 | } | |||
1092 | ||||
1093 | ||||
1094 | void UpdateRequiredDialog::showProgress( bool _bStart ) | |||
1095 | { | |||
1096 | ::osl::MutexGuard aGuard( m_aMutex ); | |||
1097 | ||||
1098 | bool bStart = _bStart; | |||
1099 | ||||
1100 | if ( bStart ) | |||
1101 | { | |||
1102 | m_nProgress = 0; | |||
1103 | m_bStartProgress = true; | |||
1104 | SAL_INFO( "desktop.deployment", "showProgress start" )do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_INFO , "desktop.deployment")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail ::getResult( ::sal::detail::StreamStart() << "showProgress start" ) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("desktop.deployment" ), ("/home/maarten/src/libreoffice/core/desktop/source/deployment/gui/dp_gui_dialog2.cxx" ":" "1104" ": "), ::sal::detail::unwrapStream( ::sal::detail ::StreamStart() << "showProgress start"), 0); } else { :: std::ostringstream sal_detail_stream; sal_detail_stream << "showProgress start"; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO ), ("desktop.deployment"), ("/home/maarten/src/libreoffice/core/desktop/source/deployment/gui/dp_gui_dialog2.cxx" ":" "1104" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << "showProgress start") == 1) { ::sal_detail_log( ( ::SAL_DETAIL_LOG_LEVEL_INFO), ("desktop.deployment"), ("/home/maarten/src/libreoffice/core/desktop/source/deployment/gui/dp_gui_dialog2.cxx" ":" "1104" ": "), ::sal::detail::unwrapStream( ::sal::detail ::StreamStart() << "showProgress start"), 0); } else { :: std::ostringstream sal_detail_stream; sal_detail_stream << "showProgress start"; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO ), ("desktop.deployment"), ("/home/maarten/src/libreoffice/core/desktop/source/deployment/gui/dp_gui_dialog2.cxx" ":" "1104" ": "), sal_detail_stream, 0); }; std::abort(); break ; } } } while (false); | |||
1105 | } | |||
1106 | else | |||
1107 | { | |||
1108 | m_nProgress = 100; | |||
1109 | m_bStopProgress = true; | |||
1110 | SAL_INFO( "desktop.deployment", "showProgress stop!" )do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_INFO , "desktop.deployment")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail ::getResult( ::sal::detail::StreamStart() << "showProgress stop!" ) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("desktop.deployment" ), ("/home/maarten/src/libreoffice/core/desktop/source/deployment/gui/dp_gui_dialog2.cxx" ":" "1110" ": "), ::sal::detail::unwrapStream( ::sal::detail ::StreamStart() << "showProgress stop!"), 0); } else { :: std::ostringstream sal_detail_stream; sal_detail_stream << "showProgress stop!"; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO ), ("desktop.deployment"), ("/home/maarten/src/libreoffice/core/desktop/source/deployment/gui/dp_gui_dialog2.cxx" ":" "1110" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << "showProgress stop!") == 1) { ::sal_detail_log( ( ::SAL_DETAIL_LOG_LEVEL_INFO), ("desktop.deployment"), ("/home/maarten/src/libreoffice/core/desktop/source/deployment/gui/dp_gui_dialog2.cxx" ":" "1110" ": "), ::sal::detail::unwrapStream( ::sal::detail ::StreamStart() << "showProgress stop!"), 0); } else { :: std::ostringstream sal_detail_stream; sal_detail_stream << "showProgress stop!"; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO ), ("desktop.deployment"), ("/home/maarten/src/libreoffice/core/desktop/source/deployment/gui/dp_gui_dialog2.cxx" ":" "1110" ": "), sal_detail_stream, 0); }; std::abort(); break ; } } } while (false); | |||
1111 | } | |||
1112 | ||||
1113 | DialogHelper::PostUserEvent( LINK( this, UpdateRequiredDialog, startProgress )::tools::detail::makeLink( ::tools::detail::castTo<UpdateRequiredDialog *>(this), &UpdateRequiredDialog::LinkStubstartProgress ), reinterpret_cast<void*>(bStart) ); | |||
1114 | m_aIdle.Start(); | |||
1115 | } | |||
1116 | ||||
1117 | ||||
1118 | void UpdateRequiredDialog::updateProgress( const long nProgress ) | |||
1119 | { | |||
1120 | if ( m_nProgress != nProgress ) | |||
1121 | { | |||
1122 | ::osl::MutexGuard aGuard( m_aMutex ); | |||
1123 | m_nProgress = nProgress; | |||
1124 | m_aIdle.Start(); | |||
1125 | } | |||
1126 | } | |||
1127 | ||||
1128 | ||||
1129 | void UpdateRequiredDialog::updateProgress( const OUString &rText, | |||
1130 | const uno::Reference< task::XAbortChannel > &xAbortChannel) | |||
1131 | { | |||
1132 | ::osl::MutexGuard aGuard( m_aMutex ); | |||
1133 | ||||
1134 | m_xAbortChannel = xAbortChannel; | |||
1135 | m_sProgressText = rText; | |||
1136 | m_bProgressChanged = true; | |||
1137 | m_aIdle.Start(); | |||
1138 | } | |||
1139 | ||||
1140 | ||||
1141 | void UpdateRequiredDialog::updatePackageInfo( const uno::Reference< deployment::XPackage > &xPackage ) | |||
1142 | { | |||
1143 | // We will remove all updated packages with satisfied dependencies, but | |||
1144 | // we will show all disabled entries so the user sees the result | |||
1145 | // of the 'disable all' button | |||
1146 | const SolarMutexGuard aGuard; | |||
1147 | if ( isEnabled( xPackage ) && checkDependencies( xPackage ) ) | |||
1148 | m_xExtensionBox->removeEntry( xPackage ); | |||
1149 | else | |||
1150 | m_xExtensionBox->updateEntry( xPackage ); | |||
1151 | ||||
1152 | if ( ! hasActiveEntries() ) | |||
1153 | { | |||
1154 | m_xCloseBtn->set_label( m_sCloseText ); | |||
1155 | m_xCloseBtn->grab_focus(); | |||
1156 | } | |||
1157 | } | |||
1158 | ||||
1159 | ||||
1160 | IMPL_LINK_NOARG(UpdateRequiredDialog, HandleUpdateBtn, weld::Button&, void)void UpdateRequiredDialog::LinkStubHandleUpdateBtn(void * instance , weld::Button& data) { return static_cast<UpdateRequiredDialog *>(instance)->HandleUpdateBtn(data); } void UpdateRequiredDialog ::HandleUpdateBtn(__attribute__ ((unused)) weld::Button&) | |||
1161 | { | |||
1162 | ::osl::ClearableMutexGuard aGuard( m_aMutex ); | |||
1163 | ||||
1164 | std::vector< uno::Reference< deployment::XPackage > > vUpdateEntries; | |||
1165 | sal_Int32 nCount = m_xExtensionBox->GetEntryCount(); | |||
1166 | ||||
1167 | for ( sal_Int32 i = 0; i < nCount; ++i ) | |||
1168 | { | |||
1169 | TEntry_Impl pEntry = m_xExtensionBox->GetEntryData( i ); | |||
1170 | vUpdateEntries.push_back( pEntry->m_xPackage ); | |||
1171 | } | |||
1172 | ||||
1173 | aGuard.clear(); | |||
1174 | ||||
1175 | m_pManager->getCmdQueue()->checkForUpdates( vUpdateEntries ); | |||
1176 | } | |||
1177 | ||||
1178 | ||||
1179 | IMPL_LINK_NOARG(UpdateRequiredDialog, HandleCloseBtn, weld::Button&, void)void UpdateRequiredDialog::LinkStubHandleCloseBtn(void * instance , weld::Button& data) { return static_cast<UpdateRequiredDialog *>(instance)->HandleCloseBtn(data); } void UpdateRequiredDialog ::HandleCloseBtn(__attribute__ ((unused)) weld::Button&) | |||
1180 | { | |||
1181 | ::osl::MutexGuard aGuard( m_aMutex ); | |||
1182 | ||||
1183 | if ( !isBusy() ) | |||
1184 | { | |||
1185 | if ( m_bHasLockedEntries ) | |||
1186 | m_xDialog->response(-1); | |||
1187 | else if ( hasActiveEntries() ) | |||
1188 | disableAllEntries(); | |||
1189 | else | |||
1190 | m_xDialog->response(RET_CANCEL); | |||
1191 | } | |||
1192 | } | |||
1193 | ||||
1194 | ||||
1195 | IMPL_LINK_NOARG(UpdateRequiredDialog, TimeOutHdl, Timer *, void)void UpdateRequiredDialog::LinkStubTimeOutHdl(void * instance , Timer * data) { return static_cast<UpdateRequiredDialog * >(instance)->TimeOutHdl(data); } void UpdateRequiredDialog ::TimeOutHdl(__attribute__ ((unused)) Timer *) | |||
1196 | { | |||
1197 | if ( m_bStopProgress ) | |||
1198 | { | |||
1199 | m_bHasProgress = false; | |||
1200 | m_bStopProgress = false; | |||
1201 | m_xProgressText->hide(); | |||
1202 | m_xProgressBar->hide(); | |||
1203 | m_xCancelBtn->hide(); | |||
1204 | } | |||
1205 | else | |||
1206 | { | |||
1207 | if ( m_bProgressChanged ) | |||
1208 | { | |||
1209 | m_bProgressChanged = false; | |||
1210 | m_xProgressText->set_label( m_sProgressText ); | |||
1211 | } | |||
1212 | ||||
1213 | if ( m_bStartProgress ) | |||
1214 | { | |||
1215 | m_bStartProgress = false; | |||
1216 | m_bHasProgress = true; | |||
1217 | m_xProgressBar->show(); | |||
1218 | m_xProgressText->show(); | |||
1219 | m_xCancelBtn->set_sensitive(true); | |||
1220 | m_xCancelBtn->show(); | |||
1221 | } | |||
1222 | ||||
1223 | if (m_xProgressBar->get_visible()) | |||
1224 | m_xProgressBar->set_percentage(m_nProgress); | |||
1225 | } | |||
1226 | } | |||
1227 | ||||
1228 | // VCL::Dialog | |||
1229 | short UpdateRequiredDialog::run() | |||
1230 | { | |||
1231 | //ToDo | |||
1232 | //I believe m_bHasLockedEntries was used to prevent showing extensions which cannot | |||
1233 | //be disabled because they are in a read only repository. However, disabling extensions | |||
1234 | //is now always possible because the registration data of all repositories | |||
1235 | //are in the user installation. | |||
1236 | //Therefore all extensions could be displayed and all the handling around m_bHasLockedEntries | |||
1237 | //could be removed. | |||
1238 | if ( m_bHasLockedEntries ) | |||
1239 | { | |||
1240 | // Set other text, disable update btn, remove not shared entries from list; | |||
1241 | m_xUpdateNeeded->set_label( DpResId( RID_STR_NO_ADMIN_PRIVILEGEreinterpret_cast<char const *>("RID_STR_NO_ADMIN_PRIVILEGE" "\004" u8"%PRODUCTNAME has been updated to a new version. " "Some shared %PRODUCTNAME extensions are not compatible with this version and need to be updated before %PRODUCTNAME can be started.\n\n" "Updating of shared extension requires administrator privileges. Contact your system administrator to update the following shared extensions:" ) ) ); | |||
1242 | m_xCloseBtn->set_label( DpResId( RID_STR_EXIT_BTNreinterpret_cast<char const *>("RID_STR_EXIT_BTN" "\004" u8"Quit") ) ); | |||
1243 | m_xUpdateBtn->set_sensitive( false ); | |||
1244 | m_xExtensionBox->RemoveUnlocked(); | |||
1245 | } | |||
1246 | ||||
1247 | return GenericDialogController::run(); | |||
1248 | } | |||
1249 | ||||
1250 | // Check dependencies of all packages | |||
1251 | ||||
1252 | bool UpdateRequiredDialog::isEnabled( const uno::Reference< deployment::XPackage > &xPackage ) | |||
1253 | { | |||
1254 | bool bRegistered = false; | |||
1255 | try { | |||
1256 | beans::Optional< beans::Ambiguous< sal_Bool > > option( xPackage->isRegistered( uno::Reference< task::XAbortChannel >(), | |||
1257 | uno::Reference< ucb::XCommandEnvironment >() ) ); | |||
1258 | if ( option.IsPresent ) | |||
1259 | { | |||
1260 | ::beans::Ambiguous< sal_Bool > const & reg = option.Value; | |||
1261 | if ( reg.IsAmbiguous ) | |||
1262 | bRegistered = false; | |||
1263 | else | |||
1264 | bRegistered = reg.Value; | |||
1265 | } | |||
1266 | else | |||
1267 | bRegistered = false; | |||
1268 | } | |||
1269 | catch ( const uno::RuntimeException & ) { throw; } | |||
1270 | catch (const uno::Exception & ) { | |||
1271 | TOOLS_WARN_EXCEPTION( "desktop", "" )do { css::uno::Any tools_warn_exception( DbgGetCaughtException () ); do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_WARN , "desktop")) { 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), ("desktop"), ("/home/maarten/src/libreoffice/core/desktop/source/deployment/gui/dp_gui_dialog2.cxx" ":" "1271" ": "), ::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 ), ("desktop"), ("/home/maarten/src/libreoffice/core/desktop/source/deployment/gui/dp_gui_dialog2.cxx" ":" "1271" ": "), 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), ( "desktop"), ("/home/maarten/src/libreoffice/core/desktop/source/deployment/gui/dp_gui_dialog2.cxx" ":" "1271" ": "), ::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 ), ("desktop"), ("/home/maarten/src/libreoffice/core/desktop/source/deployment/gui/dp_gui_dialog2.cxx" ":" "1271" ": "), sal_detail_stream, 0); }; std::abort(); break ; } } } while (false); } while (false); | |||
1272 | bRegistered = false; | |||
1273 | } | |||
1274 | ||||
1275 | return bRegistered; | |||
1276 | } | |||
1277 | ||||
1278 | // Checks the dependencies no matter if the extension is enabled or disabled! | |||
1279 | bool UpdateRequiredDialog::checkDependencies( const uno::Reference< deployment::XPackage > &xPackage ) | |||
1280 | { | |||
1281 | bool bDependenciesValid = false; | |||
1282 | try { | |||
1283 | bDependenciesValid = xPackage->checkDependencies( uno::Reference< ucb::XCommandEnvironment >() ); | |||
1284 | } | |||
1285 | catch ( const deployment::DeploymentException & ) {} | |||
1286 | return bDependenciesValid; | |||
1287 | } | |||
1288 | ||||
1289 | ||||
1290 | bool UpdateRequiredDialog::hasActiveEntries() | |||
1291 | { | |||
1292 | ::osl::MutexGuard aGuard( m_aMutex ); | |||
1293 | ||||
1294 | bool bRet = false; | |||
1295 | long nCount = m_xExtensionBox->GetEntryCount(); | |||
1296 | for ( long nIndex = 0; nIndex < nCount; nIndex++ ) | |||
1297 | { | |||
1298 | TEntry_Impl pEntry = m_xExtensionBox->GetEntryData( nIndex ); | |||
1299 | ||||
1300 | if ( isEnabled(pEntry->m_xPackage) && !checkDependencies( pEntry->m_xPackage ) ) | |||
1301 | { | |||
1302 | bRet = true; | |||
1303 | break; | |||
1304 | } | |||
1305 | } | |||
1306 | ||||
1307 | return bRet; | |||
1308 | } | |||
1309 | ||||
1310 | ||||
1311 | void UpdateRequiredDialog::disableAllEntries() | |||
1312 | { | |||
1313 | ::osl::MutexGuard aGuard( m_aMutex ); | |||
1314 | ||||
1315 | incBusy(); | |||
1316 | ||||
1317 | long nCount = m_xExtensionBox->GetEntryCount(); | |||
1318 | for ( long nIndex = 0; nIndex < nCount; nIndex++ ) | |||
1319 | { | |||
1320 | TEntry_Impl pEntry = m_xExtensionBox->GetEntryData( nIndex ); | |||
1321 | m_pManager->getCmdQueue()->enableExtension( pEntry->m_xPackage, false ); | |||
1322 | } | |||
1323 | ||||
1324 | decBusy(); | |||
1325 | ||||
1326 | if ( ! hasActiveEntries() ) | |||
1327 | m_xCloseBtn->set_label( m_sCloseText ); | |||
1328 | } | |||
1329 | ||||
1330 | // ShowLicenseDialog | |||
1331 | ShowLicenseDialog::ShowLicenseDialog(weld::Window* pParent, | |||
1332 | const uno::Reference< deployment::XPackage> &xPackage) | |||
1333 | : GenericDialogController(pParent, "desktop/ui/showlicensedialog.ui", "ShowLicenseDialog") | |||
1334 | , m_xLicenseText(m_xBuilder->weld_text_view("textview")) | |||
1335 | { | |||
1336 | m_xLicenseText->set_size_request(m_xLicenseText->get_approximate_digit_width() * 72, | |||
1337 | m_xLicenseText->get_height_rows(21)); | |||
1338 | m_xLicenseText->set_text(xPackage->getLicenseText()); | |||
1339 | } | |||
1340 | ||||
1341 | ShowLicenseDialog::~ShowLicenseDialog() | |||
1342 | { | |||
1343 | } | |||
1344 | ||||
1345 | // UpdateRequiredDialogService | |||
1346 | ||||
1347 | UpdateRequiredDialogService::UpdateRequiredDialogService( SAL_UNUSED_PARAMETER__attribute__ ((unused)) uno::Sequence< uno::Any > const&, | |||
1348 | uno::Reference< uno::XComponentContext > const& xComponentContext ) | |||
1349 | : m_xComponentContext( xComponentContext ) | |||
1350 | { | |||
1351 | } | |||
1352 | ||||
1353 | // XServiceInfo | |||
1354 | OUString UpdateRequiredDialogService::getImplementationName() | |||
1355 | { | |||
1356 | return "com.sun.star.comp.deployment.ui.UpdateRequiredDialog"; | |||
1357 | } | |||
1358 | ||||
1359 | sal_Bool UpdateRequiredDialogService::supportsService( const OUString& ServiceName ) | |||
1360 | { | |||
1361 | return cppu::supportsService(this, ServiceName); | |||
1362 | } | |||
1363 | ||||
1364 | css::uno::Sequence< OUString > UpdateRequiredDialogService::getSupportedServiceNames() | |||
1365 | { | |||
1366 | return { "com.sun.star.deployment.ui.UpdateRequiredDialog" }; | |||
1367 | } | |||
1368 | ||||
1369 | ||||
1370 | // XExecutableDialog | |||
1371 | ||||
1372 | void UpdateRequiredDialogService::setTitle( OUString const & ) | |||
1373 | { | |||
1374 | } | |||
1375 | ||||
1376 | ||||
1377 | sal_Int16 UpdateRequiredDialogService::execute() | |||
1378 | { | |||
1379 | ::rtl::Reference< ::dp_gui::TheExtensionManager > xManager( TheExtensionManager::get( | |||
1380 | m_xComponentContext) ); | |||
1381 | xManager->createDialog( true ); | |||
1382 | sal_Int16 nRet = xManager->execute(); | |||
1383 | ||||
1384 | return nRet; | |||
1385 | } | |||
1386 | ||||
1387 | ||||
1388 | } //namespace dp_gui | |||
1389 | ||||
1390 | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |
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 | |
36 | class VclReferenceBase; |
37 | |
38 | namespace vcl::detail { |
39 | |
40 | template<typename> |
41 | constexpr bool isIncompleteOrDerivedFromVclReferenceBase(...) { return true; } |
42 | |
43 | template<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 | */ |
56 | template <class reference_type> |
57 | class 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 | |
66 | public: |
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(); |
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 | |
218 | template<typename T1, typename T2> |
219 | inline bool operator ==(VclPtr<T1> const & p1, VclPtr<T2> const & p2) { |
220 | return p1.get() == p2.get(); |
221 | } |
222 | |
223 | template<typename T> inline bool operator ==(VclPtr<T> const & p1, T const * p2) |
224 | { |
225 | return p1.get() == p2; |
226 | } |
227 | |
228 | template<typename T> inline bool operator ==(VclPtr<T> const & p1, T * p2) { |
229 | return p1.get() == p2; |
230 | } |
231 | |
232 | template<typename T> inline bool operator ==(T const * p1, VclPtr<T> const & p2) |
233 | { |
234 | return p1 == p2.get(); |
235 | } |
236 | |
237 | template<typename T> inline bool operator ==(T * p1, VclPtr<T> const & p2) { |
238 | return p1 == p2.get(); |
239 | } |
240 | |
241 | template<typename T1, typename T2> |
242 | inline bool operator !=(VclPtr<T1> const & p1, VclPtr<T2> const & p2) { |
243 | return !(p1 == p2); |
244 | } |
245 | |
246 | template<typename T> inline bool operator !=(VclPtr<T> const & p1, T const * p2) |
247 | { |
248 | return !(p1 == p2); |
249 | } |
250 | |
251 | template<typename T> inline bool operator !=(VclPtr<T> const & p1, T * p2) { |
252 | return !(p1 == p2); |
253 | } |
254 | |
255 | template<typename T> inline bool operator !=(T const * p1, VclPtr<T> const & p2) |
256 | { |
257 | return !(p1 == p2); |
258 | } |
259 | |
260 | template<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 | */ |
274 | template <class reference_type> |
275 | class SAL_WARN_UNUSED__attribute__((warn_unused)) VclPtrInstance final : public VclPtr<reference_type> |
276 | { |
277 | public: |
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 | |
290 | template <class reference_type> |
291 | class ScopedVclPtr : public VclPtr<reference_type> |
292 | { |
293 | public: |
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) |
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 | |
378 | private: |
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 | |
387 | protected: |
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 |
406 | template <class reference_type> |
407 | class SAL_WARN_UNUSED__attribute__((warn_unused)) ScopedVclPtrInstance final : public ScopedVclPtr<reference_type> |
408 | { |
409 | public: |
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 | |
421 | private: |
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: */ |
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 | |||||||||
34 | namespace rtl | ||||||||
35 | { | ||||||||
36 | |||||||||
37 | /** Template reference class for reference type. | ||||||||
38 | */ | ||||||||
39 | template <class reference_type> | ||||||||
40 | class Reference | ||||||||
41 | { | ||||||||
42 | /** The <b>reference_type</b> body pointer. | ||||||||
43 | */ | ||||||||
44 | reference_type * m_pBody; | ||||||||
45 | |||||||||
46 | |||||||||
47 | public: | ||||||||
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) | ||||||||
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
| ||||||||
113 | m_pBody->release(); | ||||||||
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; | ||||||||
| |||||||||
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 | ||||||||
277 | namespace 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 | */ | ||||||||
286 | template<typename T> | ||||||||
287 | struct 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: */ |
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 | |
25 | class VCL_DLLPUBLIC__attribute__ ((visibility("default"))) VclReferenceBase |
26 | { |
27 | mutable oslInterlockedCount mnRefCnt; |
28 | |
29 | template<typename T> friend class VclPtr; |
30 | |
31 | public: |
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) |
40 | delete this; |
41 | } |
42 | #ifdef DBG_UTIL |
43 | #ifndef _WIN32 |
44 | sal_Int32 getRefCount() const { return mnRefCnt; } |
45 | #endif |
46 | #endif |
47 | |
48 | |
49 | private: |
50 | VclReferenceBase(const VclReferenceBase&) = delete; |
51 | VclReferenceBase& operator=(const VclReferenceBase&) = delete; |
52 | |
53 | bool mbDisposed : 1; |
54 | |
55 | protected: |
56 | VclReferenceBase(); |
57 | protected: |
58 | virtual ~VclReferenceBase(); |
59 | |
60 | protected: |
61 | virtual void dispose(); |
62 | |
63 | public: |
64 | void disposeOnce(); |
65 | bool isDisposed() const { return mbDisposed; } |
66 | |
67 | }; |
68 | #endif |