1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 #include <com/sun/star/beans/NamedValue.hpp>
29 #include <com/sun/star/beans/XPropertySet.hpp>
30 #include <com/sun/star/task/XInteractionHandler.hpp>
31 #include <com/sun/star/uno/XComponentContext.hpp>
33 #include <osl/conditn.hxx>
34 #include <osl/thread.hxx>
35 #include <rtl/instance.hxx>
36 #include <salhelper/refobj.hxx>
38 #include "updateinfo.hxx"
39 #include "updatecheckconfiglistener.hxx"
40 #include "actionlistener.hxx"
41 #include "updatehdl.hxx"
42 #include "download.hxx"
46 class UpdateCheckConfig
;
48 class UpdateCheckInitData
{
51 inline rtl::Reference
< UpdateCheck
> SAL_CALL
operator() () const;
54 class WorkerThread
: public osl::Thread
57 virtual void SAL_CALL
cancel() = 0;
61 public UpdateCheckConfigListener
,
62 public IActionListener
,
63 public DownloadInteractionHandler
,
64 public salhelper::ReferenceObject
,
65 public rtl::StaticWithInit
< rtl::Reference
< UpdateCheck
>, UpdateCheckInitData
>
67 UpdateCheck() : m_eState(NOT_INITIALIZED
), m_eUpdateState(UPDATESTATES_COUNT
), m_pThread(NULL
) {};
70 inline SAL_CALL
operator rtl::Reference
< UpdateCheckConfigListener
> ()
71 { return static_cast< UpdateCheckConfigListener
* > (this); }
73 void initialize(const com::sun::star::uno::Sequence
<com::sun::star::beans::NamedValue
>& rValues
,
74 const com::sun::star::uno::Reference
<com::sun::star::uno::XComponentContext
>& xContext
);
76 /* Returns an instance of the specified service obtained from the specified
80 static com::sun::star::uno::Reference
< com::sun::star::uno::XInterface
> createService(
81 const rtl::OUString
& aServiceName
,
82 const com::sun::star::uno::Reference
<com::sun::star::uno::XComponentContext
>& xContext
);
84 // Update internal update info member
85 void setUpdateInfo(const UpdateInfo
& aInfo
);
87 /* This method turns on the menubar icon, triggers the bubble window or
88 * updates the dialog text when appropriate
90 void setUIState(UpdateState eState
, bool suppressBubble
= false);
92 // Returns the UI state that matches rInfo best
93 static UpdateState
getUIState(const UpdateInfo
& rInfo
);
95 // Check for updates failed
96 void setCheckFailedState();
98 // Executes the update check dialog for manual checks and downloads interaction
99 void showDialog(bool forceCheck
= false);
101 // Returns true if the update dialog is currently showing
102 bool isDialogShowing() const;
103 bool shouldShowExtUpdDlg() const { return ( m_bShowExtUpdDlg
&& m_bHasExtensionUpdate
); }
104 void showExtensionDialog();
105 void setHasExtensionUpdates( bool bHasUpdates
) { m_bHasExtensionUpdate
= bHasUpdates
; }
106 bool hasOfficeUpdate() const { return (m_aUpdateInfo
.BuildId
.getLength() > 0); }
108 // DownloadInteractionHandler
109 virtual bool downloadTargetExists(const rtl::OUString
& rFileName
);
110 virtual void downloadStalled(const rtl::OUString
& rErrorMessage
);
111 virtual void downloadProgressAt(sal_Int8 nProcent
);
112 virtual void downloadStarted(const rtl::OUString
& rLocalFileName
, sal_Int64 nFileSize
);
113 virtual void downloadFinished(const rtl::OUString
& rLocalFileName
);
114 // checks if the download target already exists and asks user what to do next
115 virtual bool checkDownloadDestination( const rtl::OUString
& rFile
);
117 // Cancels the download action (and resumes checking if enabled)
118 void cancelDownload();
120 // Returns the XInteractionHandler of the UpdateHandler instance if present (and visible)
121 com::sun::star::uno::Reference
< com::sun::star::task::XInteractionHandler
> getInteractionHandler() const;
123 // UpdateCheckConfigListener
124 virtual void autoCheckStatusChanged(bool enabled
);
125 virtual void autoCheckIntervalChanged();
133 void closeAfterFailure();
136 virtual oslInterlockedCount SAL_CALL
acquire() SAL_THROW(());
137 virtual oslInterlockedCount SAL_CALL
release() SAL_THROW(());
141 // Schedules or cancels next automatic check for updates
142 void enableAutoCheck(bool enable
);
144 // Starts/resumes or stops a download
145 void enableDownload(bool enable
, bool paused
=false);
147 // Shuts down the currently running thread
148 void shutdownThread(bool join
);
150 // Returns the update handler instance
151 rtl::Reference
<UpdateHandler
> getUpdateHandler();
153 // Open the given URL in a browser
154 void showReleaseNote(const rtl::OUString
& rURL
) const;
156 // stores the release note url on disk to be used by setup app
157 static bool storeReleaseNote(sal_Int8 nNum
, const rtl::OUString
&rURL
);
159 /* This method turns on the menubar icon and triggers the bubble window
161 void handleMenuBarUI( rtl::Reference
< UpdateHandler
> rUpdateHandler
,
162 UpdateState
& eState
, bool suppressBubble
);
172 UpdateState m_eUpdateState
;
174 mutable osl::Mutex m_aMutex
;
175 WorkerThread
*m_pThread
;
176 osl::Condition m_aCondition
;
178 UpdateInfo m_aUpdateInfo
;
179 rtl::OUString m_aImageName
;
180 bool m_bHasExtensionUpdate
;
181 bool m_bShowExtUpdDlg
;
183 rtl::Reference
<UpdateHandler
> m_aUpdateHandler
;
184 com::sun::star::uno::Reference
<com::sun::star::beans::XPropertySet
> m_xMenuBarUI
;
185 com::sun::star::uno::Reference
<com::sun::star::uno::XComponentContext
> m_xContext
;
187 friend class UpdateCheckInitData
;
190 inline rtl::Reference
< UpdateCheck
> SAL_CALL
191 UpdateCheckInitData::operator() () const
193 return rtl::Reference
< UpdateCheck
> (new UpdateCheck());