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 <condition_variable>
27 #include <com/sun/star/beans/NamedValue.hpp>
28 #include <com/sun/star/beans/XPropertySet.hpp>
29 #include <com/sun/star/task/XInteractionHandler.hpp>
30 #include <com/sun/star/uno/XComponentContext.hpp>
32 #include <osl/conditn.hxx>
33 #include <osl/thread.hxx>
34 #include <rtl/instance.hxx>
36 #include "updateinfo.hxx"
37 #include "updatecheckconfiglistener.hxx"
38 #include "actionlistener.hxx"
39 #include "updatehdl.hxx"
40 #include "download.hxx"
45 class UpdateCheckInitData
{
48 inline rtl::Reference
< UpdateCheck
> operator() () const;
51 class WorkerThread
: public osl::Thread
54 virtual void cancel() = 0;
58 public UpdateCheckConfigListener
,
59 public IActionListener
,
60 public DownloadInteractionHandler
,
61 public rtl::StaticWithInit
< rtl::Reference
< UpdateCheck
>, UpdateCheckInitData
>
65 virtual ~UpdateCheck() override
;
68 operator rtl::Reference
< UpdateCheckConfigListener
> ()
69 { return static_cast< UpdateCheckConfigListener
* > (this); }
71 void initialize(const css::uno::Sequence
<css::beans::NamedValue
>& rValues
,
72 const css::uno::Reference
<css::uno::XComponentContext
>& xContext
);
74 // Update internal update info member
75 void setUpdateInfo(const UpdateInfo
& aInfo
);
77 /* This method turns on the menubar icon, triggers the bubble window or
78 * updates the dialog text when appropriate
80 void setUIState(UpdateState eState
, bool suppressBubble
= false);
82 // Returns the UI state that matches rInfo best
83 static UpdateState
getUIState(const UpdateInfo
& rInfo
);
85 // Check for updates failed
86 void setCheckFailedState();
88 // Executes the update check dialog for manual checks and downloads interaction
89 void showDialog(bool forceCheck
= false);
91 // Returns true if the update dialog is currently showing
92 bool isDialogShowing() const;
93 bool shouldShowExtUpdDlg() const { return ( m_bShowExtUpdDlg
&& m_bHasExtensionUpdate
); }
94 void showExtensionDialog();
95 void setHasExtensionUpdates( bool bHasUpdates
) { m_bHasExtensionUpdate
= bHasUpdates
; }
96 bool hasOfficeUpdate() const;
98 // DownloadInteractionHandler
99 virtual bool downloadTargetExists(const OUString
& rFileName
) override
;
100 virtual void downloadStalled(const OUString
& rErrorMessage
) override
;
101 virtual void downloadProgressAt(sal_Int8 nProcent
) override
;
102 virtual void downloadStarted(const OUString
& rLocalFileName
, sal_Int64 nFileSize
) override
;
103 virtual void downloadFinished(const OUString
& rLocalFileName
) override
;
104 // checks if the download target already exists and asks user what to do next
105 virtual bool checkDownloadDestination( const OUString
& rFile
) override
;
107 // Cancels the download action (and resumes checking if enabled)
108 void cancelDownload();
110 // Returns the XInteractionHandler of the UpdateHandler instance if present (and visible)
111 css::uno::Reference
< css::task::XInteractionHandler
> getInteractionHandler() const;
113 // UpdateCheckConfigListener
114 virtual void autoCheckStatusChanged(bool enabled
) override
;
115 virtual void autoCheckIntervalChanged() override
;
118 void cancel() override
;
119 void download() override
;
120 void pause() override
;
121 void resume() override
;
122 void closeAfterFailure() override
;
124 void notifyUpdateCheckFinished();
126 void waitForUpdateCheckFinished();
130 // Schedules or cancels next automatic check for updates
131 void enableAutoCheck(bool enable
);
133 // Starts/resumes or stops a download
134 void enableDownload(bool enable
, bool paused
=false);
136 // Shuts down the currently running thread
137 void shutdownThread(bool join
);
139 // Returns the update handler instance
140 rtl::Reference
<UpdateHandler
> getUpdateHandler();
142 // Open the given URL in a browser
143 void showReleaseNote(const OUString
& rURL
) const;
145 // stores the release note url on disk to be used by setup app
146 static bool storeReleaseNote(sal_Int8 nNum
, const OUString
&rURL
);
148 /* This method turns on the menubar icon and triggers the bubble window
150 void handleMenuBarUI( const rtl::Reference
< UpdateHandler
>& rUpdateHandler
,
151 UpdateState
& eState
, bool suppressBubble
);
161 UpdateState m_eUpdateState
;
163 mutable std::recursive_mutex m_aMutex
;
164 WorkerThread
*m_pThread
;
165 osl::Condition m_aCondition
;
167 UpdateInfo m_aUpdateInfo
;
168 OUString m_aImageName
;
169 bool m_bHasExtensionUpdate
;
170 bool m_bShowExtUpdDlg
;
172 rtl::Reference
<UpdateHandler
> m_aUpdateHandler
;
173 css::uno::Reference
<css::beans::XPropertySet
> m_xMenuBarUI
;
174 css::uno::Reference
<css::uno::XComponentContext
> m_xContext
;
176 bool m_updateCheckRunning
= false;
177 std::condition_variable_any m_updateCheckFinished
;
179 friend class UpdateCheckInitData
;
182 inline rtl::Reference
< UpdateCheck
>
183 UpdateCheckInitData::operator() () const
185 return rtl::Reference
< UpdateCheck
> (new UpdateCheck());
188 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */