LibreOffice Module extensions (master) 1
updatecheckui.cxx
Go to the documentation of this file.
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
23#include <com/sun/star/lang/XServiceInfo.hpp>
24#include <com/sun/star/document/XDocumentEventListener.hpp>
25#include <com/sun/star/document/XDocumentEventBroadcaster.hpp>
26#include <com/sun/star/beans/XPropertySet.hpp>
27#include <com/sun/star/frame/theGlobalEventBroadcaster.hpp>
28#include <com/sun/star/graphic/GraphicProvider.hpp>
29#include <com/sun/star/graphic/XGraphicProvider.hpp>
30#include <com/sun/star/task/XJob.hpp>
33#include <unotools/resmgr.hxx>
34#include <vcl/image.hxx>
36#include <vcl/svapp.hxx>
37#include <vcl/weld.hxx>
38#include <sfx2/strings.hrc>
39
40#include <bitmaps.hlst>
41
42constexpr OUStringLiteral PROPERTY_TITLE = u"BubbleHeading";
43constexpr OUStringLiteral PROPERTY_TEXT = u"BubbleText";
44constexpr OUStringLiteral PROPERTY_IMAGE = u"BubbleImageURL";
45constexpr OUStringLiteral PROPERTY_SHOW_BUBBLE = u"BubbleVisible";
46constexpr OUStringLiteral PROPERTY_CLICK_HDL = u"MenuClickHDL";
47constexpr OUStringLiteral PROPERTY_SHOW_MENUICON = u"MenuIconVisible";
48
49using namespace ::com::sun::star;
50
51
52namespace
53{
54
55class UpdateCheckUI : public ::cppu::WeakImplHelper
56 < lang::XServiceInfo, document::XDocumentEventListener, beans::XPropertySet >
57{
58 uno::Reference< uno::XComponentContext > m_xContext;
59 uno::Reference< task::XJob > mrJob;
60 OUString maBubbleImageURL;
61 MenuBarUpdateIconManager maBubbleManager;
62 std::locale maSfxLocale;
63
64private:
65 DECL_LINK(ClickHdl, LinkParamNone*, void);
66
67 Image GetBubbleImage( OUString const &rURL );
68
69public:
70 explicit UpdateCheckUI(const uno::Reference<uno::XComponentContext>&);
71
72 // XServiceInfo
73 virtual OUString SAL_CALL getImplementationName() override;
74 virtual sal_Bool SAL_CALL supportsService(OUString const & serviceName) override;
75 virtual uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
76
77 // XDocumentEventListener
78 virtual void SAL_CALL documentEventOccured(const document::DocumentEvent& Event) override;
79 virtual void SAL_CALL disposing(const lang::EventObject& Event) override;
80
81 //XPropertySet
82 virtual uno::Reference< beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() override;
83 virtual void SAL_CALL setPropertyValue(const OUString& PropertyName, const uno::Any& aValue) override;
84 virtual uno::Any SAL_CALL getPropertyValue(const OUString& PropertyName) override;
85 virtual void SAL_CALL addPropertyChangeListener(const OUString& PropertyName,
86 const uno::Reference< beans::XPropertyChangeListener > & aListener) override;
87 virtual void SAL_CALL removePropertyChangeListener(const OUString& PropertyName,
88 const uno::Reference< beans::XPropertyChangeListener > & aListener) override;
89 virtual void SAL_CALL addVetoableChangeListener(const OUString& PropertyName,
90 const uno::Reference< beans::XVetoableChangeListener > & aListener) override;
91 virtual void SAL_CALL removeVetoableChangeListener(const OUString& PropertyName,
92 const uno::Reference< beans::XVetoableChangeListener > & aListener) override;
93};
94
95UpdateCheckUI::UpdateCheckUI(const uno::Reference<uno::XComponentContext>& xContext)
96 : m_xContext(xContext)
97{
98 maSfxLocale = Translate::Create("sfx");
99
100 uno::Reference< document::XDocumentEventBroadcaster > xBroadcaster( frame::theGlobalEventBroadcaster::get(m_xContext) );
101 xBroadcaster->addDocumentEventListener( this );
102
103 SolarMutexGuard aGuard;
104
105 maBubbleManager.SetBubbleImage(GetBubbleImage(maBubbleImageURL));
106 maBubbleManager.SetClickHdl(LINK(this, UpdateCheckUI, ClickHdl));
107}
108
109OUString SAL_CALL
110UpdateCheckUI::getImplementationName()
111{
112 return "vnd.sun.UpdateCheckUI";
113}
114
115uno::Sequence< OUString > SAL_CALL
116UpdateCheckUI::getSupportedServiceNames()
117{
118 return { "com.sun.star.setup.UpdateCheckUI" };
119}
120
121sal_Bool SAL_CALL
122UpdateCheckUI::supportsService( OUString const & serviceName )
123{
124 return cppu::supportsService(this, serviceName);
125}
126
127Image UpdateCheckUI::GetBubbleImage( OUString const &rURL )
128{
129 Image aImage;
130
131 if ( !maBubbleImageURL.isEmpty() )
132 {
133 uno::Reference< uno::XComponentContext > xContext = ::comphelper::getProcessComponentContext();
134
135 if( !xContext.is() )
136 throw uno::RuntimeException(
137 "UpdateCheckUI: unable to obtain service manager from component context" );
138
139 try
140 {
141 uno::Reference< graphic::XGraphicProvider > xGraphProvider(graphic::GraphicProvider::create(xContext));
142 uno::Sequence< beans::PropertyValue > aMediaProps{ comphelper::makePropertyValue("URL",
143 rURL) };
144 uno::Reference< graphic::XGraphic > xGraphic = xGraphProvider->queryGraphic( aMediaProps );
145 if ( xGraphic.is() )
146 {
147 aImage = Image( xGraphic );
148 }
149 }
150 catch( const uno::Exception& )
151 {
152 }
153 }
154
155 if ( aImage.GetSizePixel().Width() == 0 )
156 aImage = Image(StockImage::Yes, SV_RESID_BITMAP_INFOBOX);
157
158 return aImage;
159}
160
161void SAL_CALL UpdateCheckUI::documentEventOccured(const document::DocumentEvent& rEvent)
162{
163 SolarMutexGuard aGuard;
164
165 if( rEvent.EventName == "OnPrepareViewClosing" )
166 maBubbleManager.RemoveBubbleWindow();
167}
168
169void SAL_CALL UpdateCheckUI::disposing(const lang::EventObject&)
170{
171}
172
173uno::Reference< beans::XPropertySetInfo > UpdateCheckUI::getPropertySetInfo()
174{
175 return nullptr;
176}
177
178void UpdateCheckUI::setPropertyValue(const OUString& rPropertyName,
179 const uno::Any& rValue)
180{
181 SolarMutexGuard aGuard;
182
183 OUString aString;
184
185 if( rPropertyName == PROPERTY_TITLE ) {
186 rValue >>= aString;
187 maBubbleManager.SetBubbleTitle(aString);
188 }
189 else if( rPropertyName == PROPERTY_TEXT ) {
190 rValue >>= aString;
191 maBubbleManager.SetBubbleText(aString);
192 }
193 else if( rPropertyName == PROPERTY_IMAGE ) {
194 rValue >>= aString;
195 if ( aString != maBubbleImageURL ) {
196 maBubbleImageURL = aString;
197 maBubbleManager.SetBubbleImage(GetBubbleImage(maBubbleImageURL));
198 }
199 }
200 else if( rPropertyName == PROPERTY_SHOW_BUBBLE ) {
201 bool bShowBubble= false;
202 rValue >>= bShowBubble;
203 maBubbleManager.SetShowBubble(bShowBubble);
204 }
205 else if( rPropertyName == PROPERTY_CLICK_HDL ) {
206 uno::Reference< task::XJob > aJob;
207 rValue >>= aJob;
208 if ( !aJob.is() )
209 throw lang::IllegalArgumentException();
210 mrJob = aJob;
211 }
212 else if (rPropertyName == PROPERTY_SHOW_MENUICON ) {
213 bool bShowMenuIcon = false;
214 rValue >>= bShowMenuIcon;
215 maBubbleManager.SetShowMenuIcon(bShowMenuIcon);
216 }
217 else
218 throw beans::UnknownPropertyException(rPropertyName);
219}
220
221uno::Any UpdateCheckUI::getPropertyValue(const OUString& rPropertyName)
222{
223 SolarMutexGuard aGuard;
224
225 uno::Any aRet;
226
227 if( rPropertyName == PROPERTY_TITLE )
228 aRet <<= maBubbleManager.GetBubbleTitle();
229 else if( rPropertyName == PROPERTY_TEXT )
230 aRet <<= maBubbleManager.GetBubbleText();
231 else if( rPropertyName == PROPERTY_SHOW_BUBBLE )
232 aRet <<= maBubbleManager.GetShowBubble();
233 else if( rPropertyName == PROPERTY_IMAGE )
234 aRet <<= maBubbleImageURL;
235 else if( rPropertyName == PROPERTY_CLICK_HDL )
236 aRet <<= mrJob;
237 else if( rPropertyName == PROPERTY_SHOW_MENUICON )
238 aRet <<= maBubbleManager.GetShowMenuIcon();
239 else
240 throw beans::UnknownPropertyException(rPropertyName);
241
242 return aRet;
243}
244
245
246void UpdateCheckUI::addPropertyChangeListener( const OUString& /*aPropertyName*/,
247 const uno::Reference< beans::XPropertyChangeListener > & /*aListener*/)
248{
249 //no bound properties
250}
251
252
253void UpdateCheckUI::removePropertyChangeListener( const OUString& /*aPropertyName*/,
254 const uno::Reference< beans::XPropertyChangeListener > & /*aListener*/)
255{
256 //no bound properties
257}
258
259void UpdateCheckUI::addVetoableChangeListener( const OUString& /*aPropertyName*/,
260 const uno::Reference< beans::XVetoableChangeListener > & /*aListener*/)
261{
262 //no vetoable properties
263}
264
265void UpdateCheckUI::removeVetoableChangeListener( const OUString& /*aPropertyName*/,
266 const uno::Reference< beans::XVetoableChangeListener > & /*aListener*/)
267{
268 //no vetoable properties
269}
270
271IMPL_LINK_NOARG(UpdateCheckUI, ClickHdl, LinkParamNone*, void)
272{
273 SolarMutexGuard aGuard;
274
275 if ( mrJob.is() )
276 {
277 try {
278 uno::Sequence<beans::NamedValue> aEmpty;
279 mrJob->execute( aEmpty );
280 }
281 catch(const uno::Exception&) {
282 std::unique_ptr<weld::MessageDialog> xErrorBox(Application::CreateMessageDialog(nullptr,
283 VclMessageType::Warning, VclButtonsType::Ok,
284 Translate::get(STR_NO_WEBBROWSER_FOUND, maSfxLocale)));
285 xErrorBox->run();
286 }
287 }
288}
289
290} // anonymous namespace
291
292
293extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
295 css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any> const&)
296{
297 SolarMutexGuard aGuard;
298 return cppu::acquire(new UpdateCheckUI(context));
299}
300
301
302
303
304/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static weld::MessageDialog * CreateMessageDialog(weld::Widget *pParent, VclMessageType eMessageType, VclButtonsType eButtonType, const OUString &rPrimaryMessage, const ILibreOfficeKitNotifier *pNotifier=nullptr)
Size GetSizePixel() const
constexpr tools::Long Width() const
DECL_LINK(CheckNameHdl, SvxNameDialog &, bool)
float u
Reference< XComponentContext > m_xContext
Definition: filehandler.cxx:78
std::locale Create(std::string_view aPrefixName, const LanguageTag &rLocale)
OUString get(TranslateId sContextAndId, const std::locale &loc)
IMPL_LINK_NOARG(FinalPage, OnEntryNameModified, weld::Entry &, void)
css::beans::PropertyValue makePropertyValue(const OUString &rName, T &&rValue)
css::uno::Sequence< OUString > getSupportedServiceNames()
OUString getImplementationName()
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
VBAHELPER_DLLPUBLIC bool setPropertyValue(css::uno::Sequence< css::beans::PropertyValue > &aProp, const OUString &aName, const css::uno::Any &aValue)
bool getPropertyValue(ValueType &rValue, css::uno::Reference< css::beans::XPropertySet > const &xPropSet, OUString const &propName)
unsigned char sal_Bool
constexpr OUStringLiteral PROPERTY_TITLE
constexpr OUStringLiteral PROPERTY_IMAGE
constexpr OUStringLiteral PROPERTY_TEXT
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * extensions_update_UpdateCheckUI_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)
constexpr OUStringLiteral PROPERTY_CLICK_HDL
constexpr OUStringLiteral PROPERTY_SHOW_BUBBLE
constexpr OUStringLiteral PROPERTY_SHOW_MENUICON