1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
22 #include <sal/config.h>
24 #include <string_view>
26 #include <osl/mutex.hxx>
27 #include <com/sun/star/uno/Any.h>
28 #include <com/sun/star/uno/Reference.h>
29 #include <com/sun/star/uno/XComponentContext.hpp>
30 #include <com/sun/star/awt/Rectangle.hpp>
31 #include <com/sun/star/awt/XActionListener.hpp>
32 #include <com/sun/star/awt/XControlModel.hpp>
33 #include <com/sun/star/awt/XDialog.hpp>
34 #include <com/sun/star/awt/XTopWindowListener.hpp>
35 #include <com/sun/star/beans/NamedValue.hpp>
36 #include <com/sun/star/frame/XTerminateListener.hpp>
37 #include <com/sun/star/task/XInteractionHandler.hpp>
38 #include <cppuhelper/implbase.hxx>
39 #include <unotools/resmgr.hxx>
40 #include <rtl/ref.hxx>
42 #include "actionlistener.hxx"
58 UPDATESTATE_CHECKING
= 0,
59 UPDATESTATE_ERROR_CHECKING
,
60 UPDATESTATE_NO_UPDATE_AVAIL
,
61 UPDATESTATE_UPDATE_AVAIL
,
62 UPDATESTATE_UPDATE_NO_DOWNLOAD
,
63 UPDATESTATE_AUTO_START
,
64 UPDATESTATE_DOWNLOADING
,
65 UPDATESTATE_DOWNLOAD_PAUSED
,
66 UPDATESTATE_ERROR_DOWNLOADING
,
67 UPDATESTATE_DOWNLOAD_AVAIL
,
68 UPDATESTATE_EXT_UPD_AVAIL
,
72 class UpdateHandler
: public cppu::WeakImplHelper
< css::awt::XActionListener
,
73 css::awt::XTopWindowListener
,
74 css::task::XInteractionHandler
,
75 css::frame::XTerminateListener
>
78 css::uno::Reference
< css::uno::XComponentContext
> mxContext
;
79 css::uno::Reference
< css::awt::XDialog
> mxUpdDlg
;
80 css::uno::Reference
< css::task::XInteractionHandler
> mxInteractionHdl
;
81 rtl::Reference
< IActionListener
> mxActionListener
;
83 UpdateState meCurState
;
84 UpdateState meLastState
;
86 short mnLastCtrlState
;
87 bool mbDownloadBtnHasDots
;
92 mutable bool mbShowsMessageBox
;
96 OUString msNextVersion
;
97 OUString msDownloadPath
;
98 OUString msDownloadFile
;
99 OUString msDescriptionMsg
;
100 OUString msChecking
; // RID_UPDATE_STR_CHECKING
101 OUString msCheckingError
; // RID_UPDATE_STR_CHECKING_ERR
102 OUString msNoUpdFound
; // RID_UPDATE_STR_NO_UPD_FOUND
103 OUString msUpdFound
; // RID_UPDATE_STR_UPD_FOUND
104 OUString msDlgTitle
; // RID_UPDATE_STR_DLG_TITLE
105 OUString msDownloadPause
; // RID_UPDATE_STR_DOWNLOAD_PAUSE
106 OUString msDownloadError
; // RID_UPDATE_STR_DOWNLOAD_ERR
107 OUString msDownloadWarning
; // RID_UPDATE_STR_DOWNLOAD_WARN
108 OUString msDownloadDescr
; // RID_UPDATE_STR_DOWNLOAD_WARN
109 OUString msDownloadNotAvail
; // RID_UPDATE_STR_DOWNLOAD_UNAVAIL
110 OUString msDownloading
; // RID_UPDATE_STR_DOWNLOADING
111 OUString msReady2Install
; // RID_UPDATE_STR_READY_INSTALL
112 OUString msCancelMessage
; // RID_UPDATE_STR_CANCEL_DOWNLOAD
113 OUString msOverwriteWarning
; // RID_UPDATE_STR_OVERWRITE_WARNING
114 OUString msPercent
; // RID_UPDATE_STR_PERCENT
115 OUString msReloadWarning
; // RID_UPDATE_STR_OVERWRITE_WARNING
116 OUString msReloadReload
; // RID_UPDATE_STR_OVERWRITE_WARNING
117 OUString msReloadContinue
; // RID_UPDATE_STR_OVERWRITE_WARNING
118 OUString msStatusFL
; // RID_UPDATE_FT_STATUS
119 OUString msDescription
; // RID_UPDATE_FT_DESCRIPTION
120 OUString msClose
; // RID_UPDATE_BTN_CLOSE
121 OUString msDownload
; // RID_UPDATE_BTN_DOWNLOAD
122 OUString msPauseBtn
; // RID_UPDATE_BTN_PAUSE
123 OUString msResumeBtn
; // RID_UPDATE_BTN_RESUME
124 OUString msCancelBtn
; // RID_UPDATE_BTN_CANCEL
125 OUString msButtonIDs
[ BUTTON_COUNT
];
126 OUString msBubbleTexts
[ UPDATESTATES_COUNT
];
127 OUString msBubbleTitles
[ UPDATESTATES_COUNT
];
130 void updateState( UpdateState eNewState
);
131 void startThrobber( bool bStart
= true );
132 void setControlProperty( const OUString
&rCtrlName
,
133 const OUString
&rPropName
,
134 const css::uno::Any
&rPropValue
);
135 void showControl( const OUString
&rCtrlName
, bool bShow
= true );
136 void showControls( short nControls
);
137 void focusControl( DialogControls eID
);
138 void enableControls( short nCtrlState
);
139 void setDownloadBtnLabel( bool bAppendDots
);
141 static OUString
loadString(const std::locale
& rLocale
,
142 TranslateId pResourceId
);
143 OUString
substVariables( const OUString
&rSource
) const;
144 static void insertControlModel( css::uno::Reference
< css::awt::XControlModel
> const & rxDialogModel
,
145 OUString
const & rServiceName
,
146 OUString
const & rControlName
,
147 css::awt::Rectangle
const & rPosSize
,
148 css::uno::Sequence
< css::beans::NamedValue
> const & rProps
);
150 void setFullVersion( OUString
& rString
);
153 UpdateHandler( const css::uno::Reference
< css::uno::XComponentContext
> & rxContext
,
154 const rtl::Reference
< IActionListener
> & rxActionListener
);
155 virtual ~UpdateHandler() override
;
156 UpdateHandler(const UpdateHandler
&) = delete;
157 UpdateHandler
& operator=(const UpdateHandler
&) = delete;
159 bool isVisible() const;
160 bool isMinimized() const { return mbMinimized
; }
161 void setVisible( bool bVisible
= true );
162 void setProgress( sal_Int32 nPercent
);
163 void setNextVersion( const OUString
&rNextVersion
) { msNextVersion
= rNextVersion
; }
164 void setDownloadPath( const OUString
&rPath
) { msDownloadPath
= rPath
; }
165 void setDownloadFile( std::u16string_view rPath
);
166 void setErrorMessage( const OUString
&rErrorMsg
);
167 void setDescription( const OUString
&rDescription
){ msDescriptionMsg
= rDescription
; }
169 void setState( UpdateState eState
);
170 OUString
getBubbleText( UpdateState eState
);
171 OUString
getBubbleTitle( UpdateState eState
);
172 bool showWarning( const OUString
&rWarning
) const;
173 bool showWarning( const OUString
&rWarning
, const OUString
& rBtnText_1
, const OUString
& rBtnText_2
) const;
174 bool showOverwriteWarning( std::u16string_view rFileName
) const;
175 bool showOverwriteWarning() const;
177 // Allows runtime exceptions to be thrown by const methods
178 operator css::uno::Reference
< css::uno::XInterface
> () const
179 { return const_cast< cppu::OWeakObject
* > (static_cast< cppu::OWeakObject
const * > (this)); };
182 virtual void SAL_CALL
disposing( const css::lang::EventObject
&rObj
) override
;
183 virtual void SAL_CALL
actionPerformed( css::awt::ActionEvent
const & rEvent
) override
;
185 // XTopWindowListener
186 virtual void SAL_CALL
windowOpened( const css::lang::EventObject
& e
) override
;
187 virtual void SAL_CALL
windowClosing( const css::lang::EventObject
& e
) override
;
188 virtual void SAL_CALL
windowClosed( const css::lang::EventObject
& e
) override
;
189 virtual void SAL_CALL
windowMinimized( const css::lang::EventObject
& e
) override
;
190 virtual void SAL_CALL
windowNormalized( const css::lang::EventObject
& e
) override
;
191 virtual void SAL_CALL
windowActivated( const css::lang::EventObject
& e
) override
;
192 virtual void SAL_CALL
windowDeactivated( const css::lang::EventObject
& e
) override
;
194 // XInteractionHandler
195 virtual void SAL_CALL
handle( const css::uno::Reference
< css::task::XInteractionRequest
>& Request
) override
;
197 // XTerminateListener
198 virtual void SAL_CALL
queryTermination( const css::lang::EventObject
& e
) override
;
199 virtual void SAL_CALL
notifyTermination( const css::lang::EventObject
& e
) override
;
202 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */