1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef INCLUDED_DP_GUI_DIALOG2_HXX
25 #define INCLUDED_DP_GUI_DIALOG2_HXX
26 
27 #include "vcl/dialog.hxx"
28 #include "vcl/button.hxx"
29 #include "vcl/fixed.hxx"
30 #include "vcl/timer.hxx"
31 
32 #include "svtools/fixedhyper.hxx"
33 #include "svtools/prgsbar.hxx"
34 #include "svtools/svmedit.hxx"
35 
36 #include "osl/conditn.hxx"
37 #include "osl/mutex.hxx"
38 
39 #include "rtl/ref.hxx"
40 #include "rtl/ustring.hxx"
41 
42 #include "cppuhelper/implbase1.hxx"
43 
44 #include "com/sun/star/awt/XWindow.hpp"
45 #include "com/sun/star/deployment/XPackage.hpp"
46 #include "com/sun/star/uno/XComponentContext.hpp"
47 #include "com/sun/star/ui/dialogs/XExecutableDialog.hpp"
48 #include "com/sun/star/util/XModifyListener.hpp"
49 
50 namespace dp_gui {
51 
52 //==============================================================================
53 class ExtBoxWithBtns_Impl;
54 class ExtensionBox_Impl;
55 class TheExtensionManager;
56 
57 //==============================================================================
58 class DialogHelper
59 {
60     ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > m_xContext;
61     Dialog*         m_pVCLWindow;
62     sal_uLong           m_nEventID;
63     bool            m_bIsBusy;
64 
65 public:
66                     DialogHelper( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > &,
67                                   Dialog *pWindow );
68     virtual        ~DialogHelper();
69 
70     void            openWebBrowser( const ::rtl::OUString & sURL, const ::rtl::OUString & sTitle ) const;
getWindow() const71     Dialog*         getWindow() const { return m_pVCLWindow; };
72     void            PostUserEvent( const Link& rLink, void* pCaller );
clearEventID()73     void            clearEventID() { m_nEventID = 0; }
74 
75     virtual void    showProgress( bool bStart ) = 0;
76     virtual void    updateProgress( const ::rtl::OUString &rText,
77                                     const ::com::sun::star::uno::Reference< ::com::sun::star::task::XAbortChannel > &xAbortChannel) = 0;
78     virtual void    updateProgress( const long nProgress ) = 0;
79 
80     virtual void    updatePackageInfo( const ::com::sun::star::uno::Reference< ::com::sun::star::deployment::XPackage > &xPackage ) = 0;
81     virtual long    addPackageToList( const ::com::sun::star::uno::Reference< ::com::sun::star::deployment::XPackage > &xPackage,
82                                       bool bLicenseMissing = false ) = 0;
83 
84     virtual void    prepareChecking() = 0;
85     virtual void    checkEntries() = 0;
86 
87     static ResId    getResId( sal_uInt16 nId );
88     static String   getResourceString( sal_uInt16 id );
89     static bool     IsSharedPkgMgr( const ::com::sun::star::uno::Reference< ::com::sun::star::deployment::XPackage > &);
90     static bool     continueOnSharedExtension( const ::com::sun::star::uno::Reference< ::com::sun::star::deployment::XPackage > &,
91                                                Window *pParent,
92                                                const sal_uInt16 nResID,
93                                                bool &bHadWarning );
94 
setBusy(const bool bBusy)95     void            setBusy( const bool bBusy ) { m_bIsBusy = bBusy; }
isBusy() const96     bool            isBusy() const { return m_bIsBusy; }
97     bool            installExtensionWarn( const ::rtl::OUString &rExtensionURL ) const;
98     bool            installForAllUsers( bool &bInstallForAll ) const;
99 };
100 
101 //==============================================================================
102 class ExtMgrDialog : public ModelessDialog,
103                      public DialogHelper
104 {
105     ExtBoxWithBtns_Impl *m_pExtensionBox;
106     PushButton           m_aAddBtn;
107     PushButton           m_aUpdateBtn;
108     OKButton             m_aCloseBtn;
109     HelpButton           m_aHelpBtn;
110     FixedLine            m_aDivider;
111     svt::FixedHyperlink  m_aGetExtensions;
112     FixedText            m_aProgressText;
113     ProgressBar          m_aProgressBar;
114     CancelButton         m_aCancelBtn;
115     const String         m_sAddPackages;
116     String               m_sProgressText;
117     String               m_sLastFolderURL;
118     ::osl::Mutex         m_aMutex;
119     bool                 m_bHasProgress;
120     bool                 m_bProgressChanged;
121     bool                 m_bStartProgress;
122     bool                 m_bStopProgress;
123     bool                 m_bUpdateWarning;
124     bool                 m_bEnableWarning;
125     bool                 m_bDisableWarning;
126     bool                 m_bDeleteWarning;
127     long                 m_nProgress;
128     Timer                m_aTimeoutTimer;
129     TheExtensionManager *m_pManager;
130 
131     ::com::sun::star::uno::Reference< ::com::sun::star::task::XAbortChannel > m_xAbortChannel;
132 
133     bool removeExtensionWarn( const ::rtl::OUString &rExtensionTitle ) const;
134 
135     DECL_DLLPRIVATE_LINK( HandleAddBtn, void * );
136     DECL_DLLPRIVATE_LINK( HandleUpdateBtn, void * );
137     DECL_DLLPRIVATE_LINK( HandleCancelBtn, void * );
138     DECL_DLLPRIVATE_LINK( HandleHyperlink, svt::FixedHyperlink * );
139     DECL_DLLPRIVATE_LINK( TimeOutHdl, Timer* );
140     DECL_DLLPRIVATE_LINK( startProgress, void * );
141 
142 public:
143                     ExtMgrDialog( Window * pParent, TheExtensionManager *pManager );
144     virtual        ~ExtMgrDialog();
145 
146     virtual void    Resize();
147     virtual long    Notify( NotifyEvent& rNEvt );
148 	virtual sal_Bool	Close();
149 
150     virtual void    showProgress( bool bStart );
151     virtual void    updateProgress( const ::rtl::OUString &rText,
152                                     const ::com::sun::star::uno::Reference< ::com::sun::star::task::XAbortChannel > &xAbortChannel);
153     virtual void    updateProgress( const long nProgress );
154 
155     virtual void    updatePackageInfo( const ::com::sun::star::uno::Reference< ::com::sun::star::deployment::XPackage > &xPackage );
156 
157     void            setGetExtensionsURL( const ::rtl::OUString &rURL );
158     virtual long    addPackageToList( const ::com::sun::star::uno::Reference< ::com::sun::star::deployment::XPackage > &,
159                                       bool bLicenseMissing = false );
160     bool enablePackage(const ::com::sun::star::uno::Reference< ::com::sun::star::deployment::XPackage > &xPackage,
161                         bool bEnable );
162     bool removePackage(const ::com::sun::star::uno::Reference< ::com::sun::star::deployment::XPackage > &xPackage );
163     bool updatePackage(const ::com::sun::star::uno::Reference< ::com::sun::star::deployment::XPackage > &xPackage );
164     bool acceptLicense(const ::com::sun::star::uno::Reference< ::com::sun::star::deployment::XPackage > &xPackage );
165 
166     virtual void    prepareChecking();
167     virtual void    checkEntries();
168 
169     ::com::sun::star::uno::Sequence< ::rtl::OUString > raiseAddPicker();
170 };
171 
172 //==============================================================================
173 class UpdateRequiredDialog : public ModalDialog,
174                              public DialogHelper
175 {
176     ExtensionBox_Impl   *m_pExtensionBox;
177     FixedText            m_aUpdateNeeded;
178     PushButton           m_aUpdateBtn;
179     PushButton           m_aCloseBtn;
180     HelpButton           m_aHelpBtn;
181     CancelButton         m_aCancelBtn;
182     FixedLine            m_aDivider;
183     FixedText            m_aProgressText;
184     ProgressBar          m_aProgressBar;
185     const String         m_sAddPackages;
186     const String         m_sCloseText;
187     String               m_sProgressText;
188     ::osl::Mutex         m_aMutex;
189     bool                 m_bHasProgress;
190     bool                 m_bProgressChanged;
191     bool                 m_bStartProgress;
192     bool                 m_bStopProgress;
193     bool                 m_bUpdateWarning;
194     bool                 m_bDisableWarning;
195     bool                 m_bHasLockedEntries;
196     long                 m_nProgress;
197     Timer                m_aTimeoutTimer;
198     TheExtensionManager *m_pManager;
199 
200     ::com::sun::star::uno::Reference< ::com::sun::star::task::XAbortChannel > m_xAbortChannel;
201 
202     DECL_DLLPRIVATE_LINK( HandleUpdateBtn, void * );
203     DECL_DLLPRIVATE_LINK( HandleCloseBtn, void * );
204     DECL_DLLPRIVATE_LINK( HandleCancelBtn, void * );
205     DECL_DLLPRIVATE_LINK( TimeOutHdl, Timer* );
206     DECL_DLLPRIVATE_LINK( startProgress, void * );
207     DECL_DLLPRIVATE_LINK( HandleHyperlink, svt::FixedHyperlink * );
208 
209     bool            isEnabled( const ::com::sun::star::uno::Reference< ::com::sun::star::deployment::XPackage > &xPackage ) const;
210     bool            checkDependencies( const ::com::sun::star::uno::Reference< ::com::sun::star::deployment::XPackage > &xPackage ) const;
211     bool            hasActiveEntries();
212     void            disableAllEntries();
213 
214 public:
215                     UpdateRequiredDialog( Window * pParent, TheExtensionManager *pManager );
216     virtual        ~UpdateRequiredDialog();
217 
218 	virtual short	Execute();
219     virtual void    Resize();
220 	virtual sal_Bool	Close();
221 //    virtual long    Notify( NotifyEvent& rNEvt );
222 
223     virtual void    showProgress( bool bStart );
224     virtual void    updateProgress( const ::rtl::OUString &rText,
225                                     const ::com::sun::star::uno::Reference< ::com::sun::star::task::XAbortChannel > &xAbortChannel);
226     virtual void    updateProgress( const long nProgress );
227 
228     virtual void    updatePackageInfo( const ::com::sun::star::uno::Reference< ::com::sun::star::deployment::XPackage > &xPackage );
229 
230     void            selectEntry( long nPos );
231     virtual long    addPackageToList( const ::com::sun::star::uno::Reference< ::com::sun::star::deployment::XPackage > &,
232                                       bool bLicenseMissing = false );
233     bool enablePackage( const ::com::sun::star::uno::Reference< ::com::sun::star::deployment::XPackage > &xPackage, bool bEnable );
234     bool updatePackage( const ::com::sun::star::uno::Reference< ::com::sun::star::deployment::XPackage > &xPackage );
235 
236     virtual void    prepareChecking();
237     virtual void    checkEntries();
238 
239     ::com::sun::star::uno::Sequence< ::rtl::OUString > raiseAddPicker();
240 
241     bool            installForAllUsers( bool &bInstallForAll ) const;
242     bool            installExtensionWarn( const ::rtl::OUString &rExtensionURL ) const;
243 };
244 
245 //==============================================================================
246 class ShowLicenseDialog : public ModalDialog
247 {
248     MultiLineEdit   m_aLicenseText;
249     OKButton        m_aCloseBtn;
250 
251 public:
252                     ShowLicenseDialog( Window * pParent,
253                                        const ::com::sun::star::uno::Reference< ::com::sun::star::deployment::XPackage > &xPackage );
254     virtual        ~ShowLicenseDialog();
255 
256     virtual void    Resize();
257 };
258 
259 //==============================================================================
260 class UpdateRequiredDialogService : public ::cppu::WeakImplHelper1< ::com::sun::star::ui::dialogs::XExecutableDialog >
261 {
262     ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > const m_xComponentContext;
263     ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow > m_xParent;
264     ::rtl::OUString m_sInitialTitle;
265 
266 public:
267     UpdateRequiredDialogService( ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any > const & args,
268                                  ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext> const & xComponentContext );
269 
270     // XExecutableDialog
271 	virtual void SAL_CALL         setTitle( rtl::OUString const & title ) throw ( ::com::sun::star::uno::RuntimeException );
272 	virtual sal_Int16 SAL_CALL    execute() throw ( ::com::sun::star::uno::RuntimeException );
273 };
274 
275 } // namespace dp_gui
276 
277 #endif
278