1 // This file is part of BOINC.
2 // http://boinc.berkeley.edu
3 // Copyright (C) 2008 University of California
4 //
5 // BOINC is free software; you can redistribute it and/or modify it
6 // under the terms of the GNU Lesser General Public License
7 // as published by the Free Software Foundation,
8 // either version 3 of the License, or (at your option) any later version.
9 //
10 // BOINC is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 // See the GNU Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public License
16 // along with BOINC.  If not, see <http://www.gnu.org/licenses/>.
17 //
18 #if defined(__GNUG__) && !defined(__APPLE__)
19 #pragma implementation "CompletionPage.h"
20 #endif
21 
22 #include "stdwx.h"
23 #include "diagnostics.h"
24 #include "util.h"
25 #include "mfile.h"
26 #include "miofile.h"
27 #include "parse.h"
28 #include "error_numbers.h"
29 #include "wizardex.h"
30 #include "error_numbers.h"
31 #include "BOINCGUIApp.h"
32 #include "SkinManager.h"
33 #include "MainDocument.h"
34 #include "BOINCBaseWizard.h"
35 #include "WizardAttach.h"
36 #include "CompletionPage.h"
37 #include "AccountInfoPage.h"
38 
39 
40 /*!
41  * CCompletionPage type definition
42  */
43 
IMPLEMENT_DYNAMIC_CLASS(CCompletionPage,wxWizardPageEx)44 IMPLEMENT_DYNAMIC_CLASS( CCompletionPage, wxWizardPageEx )
45 
46 /*!
47  * CCompletionPage event table definition
48  */
49 
50 BEGIN_EVENT_TABLE( CCompletionPage, wxWizardPageEx )
51 
52 ////@begin CCompletionPage event table entries
53     EVT_WIZARDEX_PAGE_CHANGED( -1, CCompletionPage::OnPageChanged )
54     EVT_WIZARDEX_CANCEL( -1, CCompletionPage::OnCancel )
55     EVT_WIZARDEX_FINISHED( ID_COMPLETIONPAGE, CCompletionPage::OnFinished )
56 ////@end CCompletionPage event table entries
57 
58 END_EVENT_TABLE()
59 
60 /*!
61  * CCompletionPage constructors
62  */
63 
64 CCompletionPage::CCompletionPage( )
65 {
66 }
67 
CCompletionPage(CBOINCBaseWizard * parent)68 CCompletionPage::CCompletionPage( CBOINCBaseWizard* parent )
69 {
70     Create( parent );
71 }
72 
73 /*!
74  * CCompletionPage creator
75  */
76 
Create(CBOINCBaseWizard * parent)77 bool CCompletionPage::Create( CBOINCBaseWizard* parent )
78 {
79 ////@begin CCompletionPage member initialisation
80     m_pCompletionTitle = NULL;
81     m_pCompletionWelcome = NULL;
82     m_pCompletionBrandedMessage = NULL;
83     m_pCompletionMessage = NULL;
84 ////@end CCompletionPage member initialisation
85 
86 ////@begin CCompletionPage creation
87     wxWizardPageEx::Create( parent, ID_COMPLETIONPAGE );
88 
89     CreateControls();
90     GetSizer()->Fit(this);
91 ////@end CCompletionPage creation
92 
93     return TRUE;
94 }
95 
96 /*!
97  * Control creation for CCompletionPage
98  */
99 
CreateControls()100 void CCompletionPage::CreateControls()
101 {
102 ////@begin CCompletionPage content construction
103     CCompletionPage* itemWizardPage79 = this;
104 
105     wxBoxSizer* itemBoxSizer80 = new wxBoxSizer(wxVERTICAL);
106     itemWizardPage79->SetSizer(itemBoxSizer80);
107 
108     m_pCompletionTitle = new wxStaticText;
109     m_pCompletionTitle->Create( itemWizardPage79, wxID_STATIC, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
110     m_pCompletionTitle->SetFont(wxFont(12, wxSWISS, wxNORMAL, wxBOLD, FALSE, wxT("Verdana")));
111     itemBoxSizer80->Add(m_pCompletionTitle, 0, wxALIGN_LEFT|wxALL, 5);
112 
113     m_pCompletionWelcome = new wxStaticText;
114     m_pCompletionWelcome->Create( itemWizardPage79, wxID_STATIC, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
115     m_pCompletionWelcome->SetFont(wxFont(10, wxSWISS, wxNORMAL, wxBOLD, FALSE));
116     itemBoxSizer80->Add(m_pCompletionWelcome, 0, wxALIGN_LEFT|wxALL, 5);
117 
118     m_pCompletionBrandedMessage = new wxStaticText;
119     m_pCompletionBrandedMessage->Create( itemWizardPage79, wxID_STATIC, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
120     itemBoxSizer80->Add(m_pCompletionBrandedMessage, 0, wxALIGN_LEFT|wxALL, 5);
121 
122     m_pCompletionMessage = new wxStaticText;
123     m_pCompletionMessage->Create( itemWizardPage79, wxID_STATIC, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
124     itemBoxSizer80->Add(m_pCompletionMessage, 0, wxALIGN_LEFT|wxALL, 5);
125 
126 #ifdef __WXMAC__
127     //Accessibility
128     HIViewRef textView = (HIViewRef)m_pCompletionTitle->GetHandle();
129     HIObjectRef   theObject = (HIObjectRef)HIViewGetSuperview(textView);
130     HIObjectSetAccessibilityIgnored(theObject, true);
131 #endif
132     ////@end CCompletionPage content construction
133 }
134 
135 /*!
136  * Gets the previous page.
137  */
138 
GetPrev() const139 wxWizardPageEx* CCompletionPage::GetPrev() const
140 {
141     return NULL;
142 }
143 
144 /*!
145  * Gets the next page.
146  */
147 
GetNext() const148 wxWizardPageEx* CCompletionPage::GetNext() const
149 {
150     return NULL;
151 }
152 
153 /*!
154  * Should we show tooltips?
155  */
156 
ShowToolTips()157 bool CCompletionPage::ShowToolTips()
158 {
159     return TRUE;
160 }
161 
162 /*!
163  * Get bitmap resources
164  */
165 
GetBitmapResource(const wxString & WXUNUSED (name))166 wxBitmap CCompletionPage::GetBitmapResource( const wxString& WXUNUSED(name) )
167 {
168     // Bitmap retrieval
169 ////@begin CCompletionPage bitmap retrieval
170     return wxNullBitmap;
171 ////@end CCompletionPage bitmap retrieval
172 }
173 
174 /*!
175  * Get icon resources
176  */
177 
GetIconResource(const wxString & WXUNUSED (name))178 wxIcon CCompletionPage::GetIconResource( const wxString& WXUNUSED(name) )
179 {
180     // Icon retrieval
181 ////@begin CCompletionPage icon retrieval
182     return wxNullIcon;
183 ////@end CCompletionPage icon retrieval
184 }
185 
186 /*!
187  * wxEVT_WIZARD_PAGE_CHANGED event handler for ID_COMPLETIONPAGE
188  */
189 
OnPageChanged(wxWizardExEvent & event)190 void CCompletionPage::OnPageChanged( wxWizardExEvent& event ) {
191     if (event.GetDirection() == false) return;
192 
193     CWizardAttach* pWAP = ((CWizardAttach*)GetParent());
194     CSkinAdvanced* pSkinAdvanced = wxGetApp().GetSkinManager()->GetAdvanced();
195 
196 
197     wxASSERT(pSkinAdvanced);
198     wxASSERT(m_pCompletionTitle);
199     wxASSERT(m_pCompletionWelcome);
200     wxASSERT(m_pCompletionBrandedMessage);
201     wxASSERT(m_pCompletionMessage);
202     wxASSERT(wxDynamicCast(pSkinAdvanced, CSkinAdvanced));
203 
204 
205     if (IS_ATTACHTOPROJECTWIZARD()) {
206         m_pCompletionTitle->SetLabel(
207             _("Project added")
208         );
209 
210         m_pCompletionWelcome->Hide();
211 
212         m_pCompletionBrandedMessage->SetLabel(
213             _("This project has been successfully added.")
214         );
215 
216         if (pWAP->m_AccountInfoPage->m_pAccountCreateCtrl->GetValue()) {
217             m_pCompletionMessage->SetLabel(
218                 _("When you click Finish, your web browser will go to a page where\nyou can set your account name and preferences.")
219             );
220         } else {
221             m_pCompletionMessage->SetLabel(
222                 _("Click Finish to close.")
223             );
224         }
225     } else if (IS_ACCOUNTMANAGERWIZARD()) {
226 
227         if (IS_ACCOUNTMANAGERUPDATEWIZARD()) {
228             // Update completed
229             wxString strTitle;
230             if (pSkinAdvanced->IsBranded()) {
231                 strTitle.Printf(
232                     _("Update from %s completed."),
233                     pWAP->GetProjectName().c_str()
234                 );
235             } else {
236                 strTitle = _("Update completed.");
237             }
238 
239             m_pCompletionTitle->SetLabel( strTitle );
240 
241             m_pCompletionMessage->SetLabel(
242                 _("Click Finish to close.")
243             );
244 
245         } else {
246             // Attach Completed
247             m_pCompletionTitle->SetLabel(_("Now using account manager"));
248 
249             if (pSkinAdvanced->IsBranded()) {
250                 wxString strWelcome;
251                 strWelcome.Printf(
252                     _("Welcome to %s!"),
253                     pWAP->GetProjectName().c_str()
254                 );
255 
256                 m_pCompletionWelcome->Show();
257                 m_pCompletionWelcome->SetLabel( strWelcome );
258             }
259 
260             wxString strBrandedMessage;
261             if (pSkinAdvanced->IsBranded()) {
262                 strBrandedMessage.Printf(
263                     _("You are now using %s to manage accounts."),
264                     pWAP->GetProjectName().c_str()
265                 );
266             } else {
267                 strBrandedMessage = _("You are now using this account manager.");
268             }
269 
270             m_pCompletionBrandedMessage->SetLabel( strBrandedMessage );
271 
272             m_pCompletionMessage->SetLabel(
273                 _("Click Finish to close.")
274             );
275         }
276     }
277 
278     Fit();
279     int x, y, x1, y1, w, h;
280     GetPosition(&x, &y);
281     m_pCompletionBrandedMessage->GetPosition(&x1, &y1);
282     pWAP->GetSize(&w, &h);
283     m_pCompletionBrandedMessage->Wrap(w - x - x1 - 5);
284     Fit();
285 
286     // Is this supposed to be completely automated?
287     // If so, then go ahead and close the wizard down now.
288     if (pWAP->IsCloseWhenCompleted()) {
289         pWAP->SimulateNextButton();
290     }
291 }
292 
293 /*!
294  * wxEVT_WIZARD_CANCEL event handler for ID_COMPLETIONPAGE
295  */
296 
OnCancel(wxWizardExEvent & event)297 void CCompletionPage::OnCancel( wxWizardExEvent& event ) {
298     PROCESS_CANCELEVENT(event);
299 }
300 
301 /*!
302  * wxEVT_WIZARD_FINISHED event handler for ID_COMPLETIONPAGE
303  */
304 
OnFinished(wxWizardExEvent & event)305 void CCompletionPage::OnFinished( wxWizardExEvent& event ) {
306     event.Skip();
307 }
308 
309