1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: updatecheck.hxx,v $
10 * $Revision: 1.6.70.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #include <com/sun/star/beans/NamedValue.hpp>
32 #include <com/sun/star/beans/XPropertySet.hpp>
33 #include <com/sun/star/task/XInteractionHandler.hpp>
34 #include <com/sun/star/uno/XComponentContext.hpp>
36 #include <osl/conditn.hxx>
37 #include <osl/thread.hxx>
38 #include <rtl/instance.hxx>
39 #include <salhelper/refobj.hxx>
41 #include "updateinfo.hxx"
42 #include "updatecheckconfiglistener.hxx"
43 #include "actionlistener.hxx"
44 #include "updatehdl.hxx"
45 #include "download.hxx"
49 class UpdateCheckConfig
;
51 class UpdateCheckInitData
{
54 inline rtl::Reference
< UpdateCheck
> SAL_CALL
operator() () const;
57 class WorkerThread
: public osl::Thread
60 virtual void SAL_CALL
cancel() = 0;
64 public UpdateCheckConfigListener
,
65 public IActionListener
,
66 public DownloadInteractionHandler
,
67 public salhelper::ReferenceObject
,
68 public rtl::StaticWithInit
< rtl::Reference
< UpdateCheck
>, UpdateCheckInitData
>
70 UpdateCheck() : m_eState(NOT_INITIALIZED
), m_eUpdateState(UPDATESTATES_COUNT
), m_pThread(NULL
) {};
73 inline SAL_CALL
operator rtl::Reference
< UpdateCheckConfigListener
> ()
74 { return static_cast< UpdateCheckConfigListener
* > (this); }
76 void initialize(const com::sun::star::uno::Sequence
<com::sun::star::beans::NamedValue
>& rValues
,
77 const com::sun::star::uno::Reference
<com::sun::star::uno::XComponentContext
>& xContext
);
79 /* Returns an instance of the specified service obtained from the specified
83 static com::sun::star::uno::Reference
< com::sun::star::uno::XInterface
> createService(
84 const rtl::OUString
& aServiceName
,
85 const com::sun::star::uno::Reference
<com::sun::star::uno::XComponentContext
>& xContext
);
87 // Update internal update info member
88 void setUpdateInfo(const UpdateInfo
& aInfo
);
90 /* This method turns on the menubar icon, triggers the bubble window or
91 * updates the dialog text when appropriate
93 void setUIState(UpdateState eState
, bool suppressBubble
= false);
95 // Returns the UI state that matches rInfo best
96 static UpdateState
getUIState(const UpdateInfo
& rInfo
);
98 // Check for updates failed
99 void setCheckFailedState();
101 // Executes the update check dialog for manual checks and downloads interaction
102 void showDialog(bool forceCheck
= false);
104 // Returns true if the update dialog is currently showing
105 bool isDialogShowing() const;
106 bool shouldShowExtUpdDlg() const { return ( m_bShowExtUpdDlg
&& m_bHasExtensionUpdate
); }
107 void showExtensionDialog();
108 void setHasExtensionUpdates( bool bHasUpdates
) { m_bHasExtensionUpdate
= bHasUpdates
; }
109 bool hasOfficeUpdate() const { return (m_aUpdateInfo
.BuildId
.getLength() > 0); }
111 // DownloadInteractionHandler
112 virtual bool downloadTargetExists(const rtl::OUString
& rFileName
);
113 virtual void downloadStalled(const rtl::OUString
& rErrorMessage
);
114 virtual void downloadProgressAt(sal_Int8 nProcent
);
115 virtual void downloadStarted(const rtl::OUString
& rLocalFileName
, sal_Int64 nFileSize
);
116 virtual void downloadFinished(const rtl::OUString
& rLocalFileName
);
118 // Cancels the download action (and resumes checking if enabled)
119 void cancelDownload();
121 // Returns the XInteractionHandler of the UpdateHandler instance if present (and visible)
122 com::sun::star::uno::Reference
< com::sun::star::task::XInteractionHandler
> getInteractionHandler() const;
124 // UpdateCheckConfigListener
125 virtual void autoCheckStatusChanged(bool enabled
);
126 virtual void autoCheckIntervalChanged();
134 void closeAfterFailure();
137 virtual oslInterlockedCount SAL_CALL
acquire() SAL_THROW(());
138 virtual oslInterlockedCount SAL_CALL
release() SAL_THROW(());
142 // Schedules or cancels next automatic check for updates
143 void enableAutoCheck(bool enable
);
145 // Starts/resumes or stops a download
146 void enableDownload(bool enable
, bool paused
=false);
148 // Shuts down the currently running thread
149 void shutdownThread(bool join
);
151 // Returns the update handler instance
152 rtl::Reference
<UpdateHandler
> getUpdateHandler();
154 // Open the given URL in a browser
155 void showReleaseNote(const rtl::OUString
& rURL
) const;
157 // stores the release note url on disk to be used by setup app
158 static bool storeReleaseNote(sal_Int8 nNum
, const rtl::OUString
&rURL
);
160 /* This method turns on the menubar icon and triggers the bubble window
162 void handleMenuBarUI( rtl::Reference
< UpdateHandler
> rUpdateHandler
,
163 UpdateState
& eState
, bool suppressBubble
);
173 UpdateState m_eUpdateState
;
175 mutable osl::Mutex m_aMutex
;
176 WorkerThread
*m_pThread
;
177 osl::Condition m_aCondition
;
179 UpdateInfo m_aUpdateInfo
;
180 rtl::OUString m_aImageName
;
181 bool m_bHasExtensionUpdate
;
182 bool m_bShowExtUpdDlg
;
184 rtl::Reference
<UpdateHandler
> m_aUpdateHandler
;
185 com::sun::star::uno::Reference
<com::sun::star::beans::XPropertySet
> m_xMenuBarUI
;
186 com::sun::star::uno::Reference
<com::sun::star::uno::XComponentContext
> m_xContext
;
188 friend class UpdateCheckInitData
;
191 inline rtl::Reference
< UpdateCheck
> SAL_CALL
192 UpdateCheckInitData::operator() () const
194 return rtl::Reference
< UpdateCheck
> (new UpdateCheck());