1*46dbaceeSAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*46dbaceeSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*46dbaceeSAndrew Rist * or more contributor license agreements. See the NOTICE file
5*46dbaceeSAndrew Rist * distributed with this work for additional information
6*46dbaceeSAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*46dbaceeSAndrew Rist * to you under the Apache License, Version 2.0 (the
8*46dbaceeSAndrew Rist * "License"); you may not use this file except in compliance
9*46dbaceeSAndrew Rist * with the License. You may obtain a copy of the License at
10*46dbaceeSAndrew Rist *
11*46dbaceeSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*46dbaceeSAndrew Rist *
13*46dbaceeSAndrew Rist * Unless required by applicable law or agreed to in writing,
14*46dbaceeSAndrew Rist * software distributed under the License is distributed on an
15*46dbaceeSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*46dbaceeSAndrew Rist * KIND, either express or implied. See the License for the
17*46dbaceeSAndrew Rist * specific language governing permissions and limitations
18*46dbaceeSAndrew Rist * under the License.
19*46dbaceeSAndrew Rist *
20*46dbaceeSAndrew Rist *************************************************************/
21*46dbaceeSAndrew Rist
22*46dbaceeSAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir #include <com/sun/star/beans/NamedValue.hpp>
25cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp>
26cdf0e10cSrcweir #include <com/sun/star/task/XInteractionHandler.hpp>
27cdf0e10cSrcweir #include <com/sun/star/uno/XComponentContext.hpp>
28cdf0e10cSrcweir
29cdf0e10cSrcweir #include <osl/conditn.hxx>
30cdf0e10cSrcweir #include <osl/thread.hxx>
31cdf0e10cSrcweir #include <rtl/instance.hxx>
32cdf0e10cSrcweir #include <salhelper/refobj.hxx>
33cdf0e10cSrcweir
34cdf0e10cSrcweir #include "updateinfo.hxx"
35cdf0e10cSrcweir #include "updatecheckconfiglistener.hxx"
36cdf0e10cSrcweir #include "actionlistener.hxx"
37cdf0e10cSrcweir #include "updatehdl.hxx"
38cdf0e10cSrcweir #include "download.hxx"
39cdf0e10cSrcweir
40cdf0e10cSrcweir
41cdf0e10cSrcweir class UpdateCheck;
42cdf0e10cSrcweir class UpdateCheckConfig;
43cdf0e10cSrcweir
44cdf0e10cSrcweir class UpdateCheckInitData {
45cdf0e10cSrcweir
46cdf0e10cSrcweir public:
47cdf0e10cSrcweir inline rtl::Reference< UpdateCheck > SAL_CALL operator() () const;
48cdf0e10cSrcweir };
49cdf0e10cSrcweir
50cdf0e10cSrcweir class WorkerThread : public osl::Thread
51cdf0e10cSrcweir {
52cdf0e10cSrcweir public:
53cdf0e10cSrcweir virtual void SAL_CALL cancel() = 0;
54cdf0e10cSrcweir };
55cdf0e10cSrcweir
56cdf0e10cSrcweir class UpdateCheck :
57cdf0e10cSrcweir public UpdateCheckConfigListener,
58cdf0e10cSrcweir public IActionListener,
59cdf0e10cSrcweir public DownloadInteractionHandler,
60cdf0e10cSrcweir public salhelper::ReferenceObject,
61cdf0e10cSrcweir public rtl::StaticWithInit< rtl::Reference< UpdateCheck >, UpdateCheckInitData >
62cdf0e10cSrcweir {
UpdateCheck()63cdf0e10cSrcweir UpdateCheck() : m_eState(NOT_INITIALIZED), m_eUpdateState(UPDATESTATES_COUNT), m_pThread(NULL) {};
64cdf0e10cSrcweir
65cdf0e10cSrcweir public:
operator rtl::Reference<UpdateCheckConfigListener>()66cdf0e10cSrcweir inline SAL_CALL operator rtl::Reference< UpdateCheckConfigListener > ()
67cdf0e10cSrcweir { return static_cast< UpdateCheckConfigListener * > (this); }
68cdf0e10cSrcweir
69cdf0e10cSrcweir void initialize(const com::sun::star::uno::Sequence<com::sun::star::beans::NamedValue>& rValues,
70cdf0e10cSrcweir const com::sun::star::uno::Reference<com::sun::star::uno::XComponentContext>& xContext);
71cdf0e10cSrcweir
72cdf0e10cSrcweir /* Returns an instance of the specified service obtained from the specified
73cdf0e10cSrcweir * component context
74cdf0e10cSrcweir */
75cdf0e10cSrcweir
76cdf0e10cSrcweir static com::sun::star::uno::Reference< com::sun::star::uno::XInterface > createService(
77cdf0e10cSrcweir const rtl::OUString& aServiceName,
78cdf0e10cSrcweir const com::sun::star::uno::Reference<com::sun::star::uno::XComponentContext>& xContext);
79cdf0e10cSrcweir
80cdf0e10cSrcweir // Update internal update info member
81cdf0e10cSrcweir void setUpdateInfo(const UpdateInfo& aInfo);
82cdf0e10cSrcweir
83cdf0e10cSrcweir /* This method turns on the menubar icon, triggers the bubble window or
84cdf0e10cSrcweir * updates the dialog text when appropriate
85cdf0e10cSrcweir */
86cdf0e10cSrcweir void setUIState(UpdateState eState, bool suppressBubble = false);
87cdf0e10cSrcweir
88cdf0e10cSrcweir // Returns the UI state that matches rInfo best
89cdf0e10cSrcweir static UpdateState getUIState(const UpdateInfo& rInfo);
90cdf0e10cSrcweir
91cdf0e10cSrcweir // Check for updates failed
92cdf0e10cSrcweir void setCheckFailedState();
93cdf0e10cSrcweir
94cdf0e10cSrcweir // Executes the update check dialog for manual checks and downloads interaction
95cdf0e10cSrcweir void showDialog(bool forceCheck = false);
96cdf0e10cSrcweir
97cdf0e10cSrcweir // Returns true if the update dialog is currently showing
98cdf0e10cSrcweir bool isDialogShowing() const;
shouldShowExtUpdDlg() const99cdf0e10cSrcweir bool shouldShowExtUpdDlg() const { return ( m_bShowExtUpdDlg && m_bHasExtensionUpdate ); }
100cdf0e10cSrcweir void showExtensionDialog();
setHasExtensionUpdates(bool bHasUpdates)101cdf0e10cSrcweir void setHasExtensionUpdates( bool bHasUpdates ) { m_bHasExtensionUpdate = bHasUpdates; }
hasOfficeUpdate() const102cdf0e10cSrcweir bool hasOfficeUpdate() const { return (m_aUpdateInfo.BuildId.getLength() > 0); }
103cdf0e10cSrcweir
104cdf0e10cSrcweir // DownloadInteractionHandler
105cdf0e10cSrcweir virtual bool downloadTargetExists(const rtl::OUString& rFileName);
106cdf0e10cSrcweir virtual void downloadStalled(const rtl::OUString& rErrorMessage);
107cdf0e10cSrcweir virtual void downloadProgressAt(sal_Int8 nProcent);
108cdf0e10cSrcweir virtual void downloadStarted(const rtl::OUString& rLocalFileName, sal_Int64 nFileSize);
109cdf0e10cSrcweir virtual void downloadFinished(const rtl::OUString& rLocalFileName);
110cdf0e10cSrcweir // checks if the download target already exists and asks user what to do next
111cdf0e10cSrcweir virtual bool checkDownloadDestination( const rtl::OUString& rFile );
112cdf0e10cSrcweir
113cdf0e10cSrcweir // Cancels the download action (and resumes checking if enabled)
114cdf0e10cSrcweir void cancelDownload();
115cdf0e10cSrcweir
116cdf0e10cSrcweir // Returns the XInteractionHandler of the UpdateHandler instance if present (and visible)
117cdf0e10cSrcweir com::sun::star::uno::Reference< com::sun::star::task::XInteractionHandler > getInteractionHandler() const;
118cdf0e10cSrcweir
119cdf0e10cSrcweir // UpdateCheckConfigListener
120cdf0e10cSrcweir virtual void autoCheckStatusChanged(bool enabled);
121cdf0e10cSrcweir virtual void autoCheckIntervalChanged();
122cdf0e10cSrcweir
123cdf0e10cSrcweir // IActionListener
124cdf0e10cSrcweir void cancel();
125cdf0e10cSrcweir void download();
126cdf0e10cSrcweir void install();
127cdf0e10cSrcweir void pause();
128cdf0e10cSrcweir void resume();
129cdf0e10cSrcweir void closeAfterFailure();
130cdf0e10cSrcweir
131cdf0e10cSrcweir // rtl::IReference
132cdf0e10cSrcweir virtual oslInterlockedCount SAL_CALL acquire() SAL_THROW(());
133cdf0e10cSrcweir virtual oslInterlockedCount SAL_CALL release() SAL_THROW(());
134cdf0e10cSrcweir
135cdf0e10cSrcweir private:
136cdf0e10cSrcweir
137cdf0e10cSrcweir // Schedules or cancels next automatic check for updates
138cdf0e10cSrcweir void enableAutoCheck(bool enable);
139cdf0e10cSrcweir
140cdf0e10cSrcweir // Starts/resumes or stops a download
141cdf0e10cSrcweir void enableDownload(bool enable, bool paused=false);
142cdf0e10cSrcweir
143cdf0e10cSrcweir // Shuts down the currently running thread
144cdf0e10cSrcweir void shutdownThread(bool join);
145cdf0e10cSrcweir
146cdf0e10cSrcweir // Returns the update handler instance
147cdf0e10cSrcweir rtl::Reference<UpdateHandler> getUpdateHandler();
148cdf0e10cSrcweir
149cdf0e10cSrcweir // Open the given URL in a browser
150cdf0e10cSrcweir void showReleaseNote(const rtl::OUString& rURL) const;
151cdf0e10cSrcweir
152cdf0e10cSrcweir // stores the release note url on disk to be used by setup app
153cdf0e10cSrcweir static bool storeReleaseNote(sal_Int8 nNum, const rtl::OUString &rURL);
154cdf0e10cSrcweir
155cdf0e10cSrcweir /* This method turns on the menubar icon and triggers the bubble window
156cdf0e10cSrcweir */
157cdf0e10cSrcweir void handleMenuBarUI( rtl::Reference< UpdateHandler > rUpdateHandler,
158cdf0e10cSrcweir UpdateState& eState, bool suppressBubble );
159cdf0e10cSrcweir enum State {
160cdf0e10cSrcweir NOT_INITIALIZED,
161cdf0e10cSrcweir DISABLED,
162cdf0e10cSrcweir CHECK_SCHEDULED,
163cdf0e10cSrcweir DOWNLOADING,
164cdf0e10cSrcweir DOWNLOAD_PAUSED
165cdf0e10cSrcweir };
166cdf0e10cSrcweir
167cdf0e10cSrcweir State m_eState;
168cdf0e10cSrcweir UpdateState m_eUpdateState;
169cdf0e10cSrcweir
170cdf0e10cSrcweir mutable osl::Mutex m_aMutex;
171cdf0e10cSrcweir WorkerThread *m_pThread;
172cdf0e10cSrcweir osl::Condition m_aCondition;
173cdf0e10cSrcweir
174cdf0e10cSrcweir UpdateInfo m_aUpdateInfo;
175cdf0e10cSrcweir rtl::OUString m_aImageName;
176cdf0e10cSrcweir bool m_bHasExtensionUpdate;
177cdf0e10cSrcweir bool m_bShowExtUpdDlg;
178cdf0e10cSrcweir
179cdf0e10cSrcweir rtl::Reference<UpdateHandler> m_aUpdateHandler;
180cdf0e10cSrcweir com::sun::star::uno::Reference<com::sun::star::beans::XPropertySet> m_xMenuBarUI;
181cdf0e10cSrcweir com::sun::star::uno::Reference<com::sun::star::uno::XComponentContext> m_xContext;
182cdf0e10cSrcweir
183cdf0e10cSrcweir friend class UpdateCheckInitData;
184cdf0e10cSrcweir };
185cdf0e10cSrcweir
186cdf0e10cSrcweir inline rtl::Reference< UpdateCheck > SAL_CALL
operator ()() const187cdf0e10cSrcweir UpdateCheckInitData::operator() () const
188cdf0e10cSrcweir {
189cdf0e10cSrcweir return rtl::Reference< UpdateCheck > (new UpdateCheck());
190cdf0e10cSrcweir }
191