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