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 #pragma once
21 
22 #include <vcl/timer.hxx>
23 #include <vcl/idle.hxx>
24 #include <vcl/locktoplevels.hxx>
25 #include <vcl/customweld.hxx>
26 #include <vcl/weld.hxx>
27 
28 #include <osl/mutex.hxx>
29 
30 #include <rtl/ustring.hxx>
31 
32 #include <cppuhelper/implbase.hxx>
33 
34 #include <com/sun/star/deployment/XPackage.hpp>
35 #include <com/sun/star/uno/XComponentContext.hpp>
36 #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
37 #include <com/sun/star/lang/XServiceInfo.hpp>
38 
39 struct ImplSVEvent;
40 
41 namespace dp_gui {
42 
43 class ExtBoxWithBtns_Impl;
44 class ExtensionBox_Impl;
45 class TheExtensionManager;
46 
47 class DialogHelper
48 {
49     css::uno::Reference< css::uno::XComponentContext > m_xContext;
50     weld::Window*   m_pWindow;
51     ImplSVEvent *   m_nEventID;
52     TopLevelWindowLocker m_aBusy;
53 
54 public:
55                     DialogHelper(const css::uno::Reference< css::uno::XComponentContext > &,
56                                  weld::Window* pWindow);
57     virtual        ~DialogHelper();
58 
59     void            openWebBrowser(const OUString& rURL, const OUString& rTitle);
getFrameWeld() const60     weld::Window*   getFrameWeld() const { return m_pWindow; }
61     void            PostUserEvent( const Link<void*,void>& rLink, void* pCaller );
clearEventID()62     void            clearEventID() { m_nEventID = nullptr; }
63 
64     virtual void    showProgress( bool bStart ) = 0;
65     virtual void    updateProgress( const OUString &rText,
66                                     const css::uno::Reference< css::task::XAbortChannel > &xAbortChannel) = 0;
67     virtual void    updateProgress( const tools::Long nProgress ) = 0;
68 
69     virtual void    updatePackageInfo( const css::uno::Reference< css::deployment::XPackage > &xPackage ) = 0;
70     virtual void    addPackageToList( const css::uno::Reference< css::deployment::XPackage > &xPackage,
71                                       bool bLicenseMissing = false ) = 0;
72 
73     virtual void    prepareChecking() = 0;
74     virtual void    checkEntries() = 0;
75 
76     static bool     IsSharedPkgMgr( const css::uno::Reference< css::deployment::XPackage > &);
77            bool     continueOnSharedExtension( const css::uno::Reference< css::deployment::XPackage > &,
78                                                weld::Widget* pParent,
79                                                const char* pResID,
80                                                bool &bHadWarning );
81 
incBusy()82     void            incBusy() { m_aBusy.incBusy(m_pWindow); }
decBusy()83     void            decBusy() { m_aBusy.decBusy(); }
isBusy() const84     bool            isBusy() const { return m_aBusy.isBusy(); }
85     bool            installExtensionWarn(std::u16string_view rExtensionURL);
86     bool            installForAllUsers(bool &bInstallForAll);
87 };
88 
89 class ExtMgrDialog : public weld::GenericDialogController
90                    , public DialogHelper
91 {
92     const OUString       m_sAddPackages;
93     OUString             m_sProgressText;
94     OUString             m_sLastFolderURL;
95     ::osl::Mutex         m_aMutex;
96     bool                 m_bHasProgress;
97     bool                 m_bProgressChanged;
98     bool                 m_bStartProgress;
99     bool                 m_bStopProgress;
100     bool                 m_bEnableWarning;
101     bool                 m_bDisableWarning;
102     bool                 m_bDeleteWarning;
103     bool                 m_bClosed;
104     tools::Long                 m_nProgress;
105     Idle                 m_aIdle;
106     TheExtensionManager *m_pManager;
107 
108     css::uno::Reference< css::task::XAbortChannel > m_xAbortChannel;
109 
110     std::unique_ptr<ExtBoxWithBtns_Impl> m_xExtensionBox;
111     std::unique_ptr<weld::CustomWeld> m_xExtensionBoxWnd;
112     std::unique_ptr<weld::Button> m_xOptionsBtn;
113     std::unique_ptr<weld::Button> m_xAddBtn;
114     std::unique_ptr<weld::Button> m_xRemoveBtn;
115     std::unique_ptr<weld::Button> m_xEnableBtn;
116     std::unique_ptr<weld::Button> m_xUpdateBtn;
117     std::unique_ptr<weld::Button> m_xCloseBtn;
118     std::unique_ptr<weld::CheckButton> m_xBundledCbx;
119     std::unique_ptr<weld::CheckButton> m_xSharedCbx;
120     std::unique_ptr<weld::CheckButton> m_xUserCbx;
121     std::unique_ptr<weld::LinkButton> m_xGetExtensions;
122     std::unique_ptr<weld::Label> m_xProgressText;
123     std::unique_ptr<weld::ProgressBar> m_xProgressBar;
124     std::unique_ptr<weld::Button> m_xCancelBtn;
125 
126     bool removeExtensionWarn(std::u16string_view rExtensionTitle);
127 
128     DECL_LINK( HandleOptionsBtn, weld::Button&, void );
129     DECL_LINK( HandleAddBtn, weld::Button&, void );
130     DECL_LINK( HandleRemoveBtn, weld::Button&, void );
131     DECL_LINK( HandleEnableBtn, weld::Button&, void );
132     DECL_LINK( HandleUpdateBtn, weld::Button&, void );
133     DECL_LINK( HandleCancelBtn, weld::Button&, void );
134     DECL_LINK( HandleCloseBtn, weld::Button&, void );
135     DECL_LINK( HandleExtTypeCbx, weld::Toggleable&, void );
136     DECL_LINK( TimeOutHdl, Timer *, void );
137     DECL_LINK( startProgress, void *, void );
138 
139 public:
140     ExtMgrDialog(weld::Window * pParent, TheExtensionManager *pManager);
141     virtual ~ExtMgrDialog() override;
142 
143     virtual void    showProgress( bool bStart ) override;
144     virtual void    updateProgress( const OUString &rText,
145                                     const css::uno::Reference< css::task::XAbortChannel > &xAbortChannel) override;
146     virtual void    updateProgress( const tools::Long nProgress ) override;
147 
148     virtual void    updatePackageInfo( const css::uno::Reference< css::deployment::XPackage > &xPackage ) override;
149 
150     void            setGetExtensionsURL( const OUString &rURL );
151     virtual void    addPackageToList( const css::uno::Reference< css::deployment::XPackage > &,
152                                       bool bLicenseMissing = false ) override;
153     void enablePackage(const css::uno::Reference< css::deployment::XPackage > &xPackage,
154                         bool bEnable );
155     void removePackage(const css::uno::Reference< css::deployment::XPackage > &xPackage );
156     void updatePackage(const css::uno::Reference< css::deployment::XPackage > &xPackage );
157     bool acceptLicense(const css::uno::Reference< css::deployment::XPackage > &xPackage );
158 
159     void Close();
160 
getExtensionManager() const161     TheExtensionManager*    getExtensionManager() const { return m_pManager; }
162 
163     virtual void    prepareChecking() override;
164     virtual void    checkEntries() override;
165 
166     css::uno::Sequence< OUString > raiseAddPicker();
167 
168     void enableOptionsButton( bool bEnable );
169     void enableRemoveButton( bool bEnable );
170     void enableEnableButton( bool bEnable );
171     /*
172      * Transform the button to "Enable", or to "Disable"
173      * based on the value of bEnable.
174      */
175     void enableButtontoEnable( bool bEnable );
176 };
177 
178 
179 class UpdateRequiredDialog : public weld::GenericDialogController
180                            , public DialogHelper
181 {
182     const OUString       m_sCloseText;
183     OUString             m_sProgressText;
184     ::osl::Mutex         m_aMutex;
185     bool                 m_bHasProgress;
186     bool                 m_bProgressChanged;
187     bool                 m_bStartProgress;
188     bool                 m_bStopProgress;
189     bool                 m_bHasLockedEntries;
190     tools::Long                 m_nProgress;
191     Idle                 m_aIdle;
192     TheExtensionManager *m_pManager;
193 
194     css::uno::Reference< css::task::XAbortChannel > m_xAbortChannel;
195 
196     std::unique_ptr<ExtensionBox_Impl> m_xExtensionBox;
197     std::unique_ptr<weld::CustomWeld> m_xExtensionBoxWnd;
198     std::unique_ptr<weld::Label> m_xUpdateNeeded;
199     std::unique_ptr<weld::Button> m_xUpdateBtn;
200     std::unique_ptr<weld::Button> m_xCloseBtn;
201     std::unique_ptr<weld::Button> m_xCancelBtn;
202     std::unique_ptr<weld::Label> m_xProgressText;
203     std::unique_ptr<weld::ProgressBar> m_xProgressBar;
204 
205     DECL_LINK( HandleUpdateBtn, weld::Button&, void );
206     DECL_LINK( HandleCloseBtn, weld::Button&, void );
207     DECL_LINK( HandleCancelBtn, weld::Button&, void );
208     DECL_LINK( TimeOutHdl, Timer *, void );
209     DECL_LINK( startProgress, void *, void );
210 
211     static bool     isEnabled( const css::uno::Reference< css::deployment::XPackage > &xPackage );
212     static bool     checkDependencies( const css::uno::Reference< css::deployment::XPackage > &xPackage );
213     bool            hasActiveEntries();
214     void            disableAllEntries();
215 
216 public:
217     UpdateRequiredDialog(weld::Window * pParent, TheExtensionManager *pManager);
218     virtual        ~UpdateRequiredDialog() override;
219 
220     virtual short   run() override;
221 
222     virtual void    showProgress( bool bStart ) override;
223     virtual void    updateProgress( const OUString &rText,
224                                     const css::uno::Reference< css::task::XAbortChannel > &xAbortChannel) override;
225     virtual void    updateProgress( const tools::Long nProgress ) override;
226 
227     virtual void    updatePackageInfo( const css::uno::Reference< css::deployment::XPackage > &xPackage ) override;
228 
229     virtual void    addPackageToList( const css::uno::Reference< css::deployment::XPackage > &,
230                                       bool bLicenseMissing = false ) override;
231 
232     virtual void    prepareChecking() override;
233     virtual void    checkEntries() override;
234 };
235 
236 
237 class ShowLicenseDialog : public weld::GenericDialogController
238 {
239     std::unique_ptr<weld::TextView> m_xLicenseText;
240 public:
241     ShowLicenseDialog(weld::Window * pParent, const css::uno::Reference< css::deployment::XPackage > &xPackage);
242     virtual ~ShowLicenseDialog() override;
243 };
244 
245 class UpdateRequiredDialogService : public ::cppu::WeakImplHelper< css::ui::dialogs::XExecutableDialog, css::lang::XServiceInfo >
246 {
247     css::uno::Reference< css::uno::XComponentContext > const m_xComponentContext;
248 public:
249     UpdateRequiredDialogService( css::uno::Sequence< css::uno::Any > const & args,
250                                  css::uno::Reference< css::uno::XComponentContext> const & xComponentContext );
251 
252     // XServiceInfo
253     virtual OUString SAL_CALL getImplementationName() override;
254     virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
255     virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
256 
257     // XExecutableDialog
258     virtual void SAL_CALL         setTitle( OUString const & title ) override;
259     virtual sal_Int16 SAL_CALL    execute() override;
260 };
261 
262 } // namespace dp_gui
263 
264 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
265