~ubuntu-branches/ubuntu/precise/boinc/precise

« back to all changes in this revision

Viewing changes to clientgui/DlgSelectComputer.cpp

Tags: 6.12.8+dfsg-1
* New upstream release.
* Simplified debian/rules

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// Berkeley Open Infrastructure for Network Computing
2
 
// http://boinc.berkeley.edu
3
 
// Copyright (C) 2005 University of California
4
 
//
5
 
// This is free software; you can redistribute it and/or
6
 
// modify it under the terms of the GNU Lesser General Public
7
 
// License as published by the Free Software Foundation;
8
 
// either version 2.1 of the License, or (at your option) any later version.
9
 
//
10
 
// This software 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
 
// To view the GNU Lesser General Public License visit
16
 
// http://www.gnu.org/copyleft/lesser.html
17
 
// or write to the Free Software Foundation, Inc.,
18
 
// 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
19
 
//
20
 
#if defined(__GNUG__) && !defined(__APPLE__)
21
 
#pragma implementation "DlgSelectComputer.h"
22
 
#endif
23
 
 
24
 
#include "stdwx.h"
25
 
#include "diagnostics.h"
26
 
#include "util.h"
27
 
#include "mfile.h"
28
 
#include "miofile.h"
29
 
#include "parse.h"
30
 
#include "LogBOINC.h"
31
 
#include "BOINCGUIApp.h"
32
 
#include "MainDocument.h"
33
 
#include "SkinManager.h"
34
 
 
35
 
////@begin includes
36
 
////@end includes
37
 
 
38
 
#include "DlgSelectComputer.h"
39
 
 
40
 
////@begin XPM images
41
 
////@end XPM images
42
 
 
43
 
/*!
44
 
 * CDlgSelectComputer type definition
45
 
 */
46
 
 
47
 
IMPLEMENT_DYNAMIC_CLASS( CDlgSelectComputer, wxDialog )
48
 
 
49
 
/*!
50
 
 * CDlgSelectComputer event table definition
51
 
 */
52
 
 
53
 
BEGIN_EVENT_TABLE( CDlgSelectComputer, wxDialog )
54
 
 
55
 
////@begin CDlgSelectComputer event table entries
56
 
    EVT_TEXT( ID_SELECTCOMPUTERNAME, CDlgSelectComputer::OnComputerNameUpdated )
57
 
 
58
 
////@end CDlgSelectComputer event table entries
59
 
 
60
 
END_EVENT_TABLE()
61
 
 
62
 
/*!
63
 
 * CDlgSelectComputer constructors
64
 
 */
65
 
 
66
 
CDlgSelectComputer::CDlgSelectComputer( )
67
 
{
68
 
}
69
 
 
70
 
CDlgSelectComputer::CDlgSelectComputer( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
71
 
{
72
 
    Create(parent, id, caption, pos, size, style);
73
 
}
74
 
 
75
 
/*!
76
 
 * CDlgSelectComputer creator
77
 
 */
78
 
 
79
 
bool CDlgSelectComputer::Create( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
80
 
{
81
 
////@begin CDlgSelectComputer member initialisation
82
 
    m_ComputerNameCtrl = NULL;
83
 
    m_ComputerPasswordCtrl = NULL;
84
 
////@end CDlgSelectComputer member initialisation
85
 
 
86
 
    wxString strCaption = caption;
87
 
    if (strCaption.IsEmpty()) {
88
 
        CSkinAdvanced* pSkinAdvanced = wxGetApp().GetSkinManager()->GetAdvanced();
89
 
        wxASSERT(pSkinAdvanced);
90
 
        wxASSERT(wxDynamicCast(pSkinAdvanced, CSkinAdvanced));
91
 
 
92
 
        strCaption.Printf(_("%s - Select Computer"), pSkinAdvanced->GetApplicationName().c_str());
93
 
    }
94
 
 
95
 
////@begin CDlgSelectComputer creation
96
 
    SetExtraStyle(GetExtraStyle()|wxWS_EX_BLOCK_EVENTS);
97
 
    wxDialog::Create( parent, id, strCaption, pos, size, style );
98
 
 
99
 
    CreateControls();
100
 
    GetSizer()->Fit(this);
101
 
    GetSizer()->SetSizeHints(this);
102
 
    Centre();
103
 
////@end CDlgSelectComputer creation
104
 
    return TRUE;
105
 
}
106
 
 
107
 
/*!
108
 
 * Control creation for CDlgSelectComputer
109
 
 */
110
 
 
111
 
void CDlgSelectComputer::CreateControls()
112
 
{    
113
 
////@begin CDlgSelectComputer content construction
114
 
    CDlgSelectComputer* itemDialog1 = this;
115
 
 
116
 
    wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
117
 
    itemDialog1->SetSizer(itemBoxSizer2);
118
 
 
119
 
    wxFlexGridSizer* itemFlexGridSizer3 = new wxFlexGridSizer(1, 2, 0, 0);
120
 
    itemBoxSizer2->Add(itemFlexGridSizer3, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
121
 
 
122
 
    wxBoxSizer* itemBoxSizer4 = new wxBoxSizer(wxVERTICAL);
123
 
    itemFlexGridSizer3->Add(itemBoxSizer4, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 5);
124
 
 
125
 
    wxFlexGridSizer* itemFlexGridSizer5 = new wxFlexGridSizer(2, 2, 0, 0);
126
 
    itemBoxSizer4->Add(itemFlexGridSizer5, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
127
 
 
128
 
    wxStaticText* itemStaticText6 = new wxStaticText;
129
 
    itemStaticText6->Create( itemDialog1, wxID_STATIC, _("Host name:"), wxDefaultPosition, wxDefaultSize, 0 );
130
 
    itemFlexGridSizer5->Add(itemStaticText6, 0, wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL|wxALL, 5);
131
 
 
132
 
    wxString* m_ComputerNameCtrlStrings = NULL;
133
 
    m_ComputerNameCtrl = new wxComboBox;
134
 
    m_ComputerNameCtrl->Create( itemDialog1, ID_SELECTCOMPUTERNAME, _T(""), wxDefaultPosition, wxSize(250, -1), 0, m_ComputerNameCtrlStrings, wxCB_DROPDOWN );
135
 
    itemFlexGridSizer5->Add(m_ComputerNameCtrl, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 5);
136
 
 
137
 
    wxStaticText* itemStaticText8 = new wxStaticText;
138
 
    itemStaticText8->Create( itemDialog1, wxID_STATIC, _("Password:"), wxDefaultPosition, wxDefaultSize, 0 );
139
 
    itemFlexGridSizer5->Add(itemStaticText8, 0, wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL|wxALL, 5);
140
 
 
141
 
    m_ComputerPasswordCtrl = new wxTextCtrl;
142
 
    m_ComputerPasswordCtrl->Create( itemDialog1, ID_SELECTCOMPUTERPASSWORD, _T(""), wxDefaultPosition, wxSize(250, -1), wxTE_PASSWORD );
143
 
    itemFlexGridSizer5->Add(m_ComputerPasswordCtrl, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 5);
144
 
 
145
 
    wxBoxSizer* itemBoxSizer10 = new wxBoxSizer(wxVERTICAL);
146
 
    itemFlexGridSizer3->Add(itemBoxSizer10, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_TOP|wxALL, 5);
147
 
 
148
 
    wxButton* itemButton11 = new wxButton;
149
 
    itemButton11->Create( itemDialog1, wxID_OK, _("&OK"), wxDefaultPosition, wxDefaultSize, 0 );
150
 
    itemButton11->SetDefault();
151
 
    itemBoxSizer10->Add(itemButton11, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
152
 
 
153
 
    wxButton* itemButton12 = new wxButton;
154
 
    itemButton12->Create( itemDialog1, wxID_CANCEL, _("&Cancel"), wxDefaultPosition, wxDefaultSize, 0 );
155
 
    itemBoxSizer10->Add(itemButton12, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
156
 
 
157
 
    // Set validators
158
 
    m_ComputerNameCtrl->SetValidator( wxGenericValidator(& m_strComputerName) );
159
 
    m_ComputerPasswordCtrl->SetValidator( wxGenericValidator(& m_strComputerPassword) );
160
 
////@end CDlgSelectComputer content construction
161
 
}
162
 
 
163
 
/*!
164
 
 * Should we show tooltips?
165
 
 */
166
 
 
167
 
bool CDlgSelectComputer::ShowToolTips(){
168
 
    return TRUE;
169
 
}
170
 
 
171
 
/*!
172
 
 * Get bitmap resources
173
 
 */
174
 
 
175
 
wxBitmap CDlgSelectComputer::GetBitmapResource( const wxString& WXUNUSED(name) )
176
 
{
177
 
    // Bitmap retrieval
178
 
////@begin CDlgSelectComputer bitmap retrieval
179
 
    return wxNullBitmap;
180
 
////@end CDlgSelectComputer bitmap retrieval
181
 
}
182
 
 
183
 
/*!
184
 
 * Get icon resources
185
 
 */
186
 
 
187
 
wxIcon CDlgSelectComputer::GetIconResource( const wxString& WXUNUSED(name) )
188
 
{
189
 
    // Icon retrieval
190
 
////@begin CDlgSelectComputer icon retrieval
191
 
    return wxNullIcon;
192
 
////@end CDlgSelectComputer icon retrieval
193
 
}
194
 
 
195
 
/*!
196
 
 * wxEVT_COMMAND_TEXT_UPDATED event handler for ID_SELECTCOMPUTERNAME
197
 
 */
198
 
 
199
 
void CDlgSelectComputer::OnComputerNameUpdated( wxCommandEvent& WXUNUSED(event) )
200
 
{
201
 
    wxString       strPassword = wxEmptyString;
202
 
    CMainDocument* pDoc        = wxGetApp().GetDocument();
203
 
 
204
 
    wxASSERT(pDoc);
205
 
    wxASSERT(wxDynamicCast(pDoc, CMainDocument));
206
 
 
207
 
    wxString name = m_ComputerNameCtrl->GetValue();
208
 
    if (pDoc->IsComputerNameLocal(name)) {
209
 
        pDoc->m_pNetworkConnection->GetLocalPassword(strPassword);
210
 
        m_ComputerPasswordCtrl->SetValue(strPassword);
211
 
    }
212
 
}
213
 
 
214
 
const char *BOINC_RCSID_28d78701f5="$Id: DlgSelectComputer.cpp 13804 2007-10-09 11:35:47Z fthomas $";
 
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 "DlgSelectComputer.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 "LogBOINC.h"
 
29
#include "BOINCGUIApp.h"
 
30
#include "MainDocument.h"
 
31
#include "SkinManager.h"
 
32
 
 
33
////@begin includes
 
34
////@end includes
 
35
 
 
36
#include "DlgSelectComputer.h"
 
37
 
 
38
////@begin XPM images
 
39
////@end XPM images
 
40
 
 
41
/*!
 
42
 * CDlgSelectComputer type definition
 
43
 */
 
44
 
 
45
IMPLEMENT_DYNAMIC_CLASS( CDlgSelectComputer, wxDialog )
 
46
 
 
47
/*!
 
48
 * CDlgSelectComputer event table definition
 
49
 */
 
50
 
 
51
BEGIN_EVENT_TABLE( CDlgSelectComputer, wxDialog )
 
52
 
 
53
////@begin CDlgSelectComputer event table entries
 
54
    EVT_TEXT( ID_SELECTCOMPUTERNAME, CDlgSelectComputer::OnComputerNameUpdated )
 
55
 
 
56
////@end CDlgSelectComputer event table entries
 
57
 
 
58
END_EVENT_TABLE()
 
59
 
 
60
/*!
 
61
 * CDlgSelectComputer constructors
 
62
 */
 
63
 
 
64
CDlgSelectComputer::CDlgSelectComputer( )
 
65
{
 
66
}
 
67
 
 
68
CDlgSelectComputer::CDlgSelectComputer( wxWindow* parent, bool required, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
 
69
{
 
70
    Create(parent, required, id, caption, pos, size, style);
 
71
}
 
72
 
 
73
/*!
 
74
 * CDlgSelectComputer creator
 
75
 */
 
76
 
 
77
bool CDlgSelectComputer::Create( wxWindow* parent, bool required, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
 
78
{
 
79
////@begin CDlgSelectComputer member initialisation
 
80
    m_ComputerNameCtrl = NULL;
 
81
    m_ComputerPasswordCtrl = NULL;
 
82
////@end CDlgSelectComputer member initialisation
 
83
 
 
84
    wxString strCaption = caption;
 
85
    if (strCaption.IsEmpty()) {
 
86
        CSkinAdvanced* pSkinAdvanced = wxGetApp().GetSkinManager()->GetAdvanced();
 
87
        wxASSERT(pSkinAdvanced);
 
88
        wxASSERT(wxDynamicCast(pSkinAdvanced, CSkinAdvanced));
 
89
 
 
90
        strCaption.Printf(_("%s - Select Computer"), pSkinAdvanced->GetApplicationName().c_str());
 
91
    }
 
92
 
 
93
////@begin CDlgSelectComputer creation
 
94
    SetExtraStyle(GetExtraStyle()|wxWS_EX_BLOCK_EVENTS);
 
95
    wxDialog::Create( parent, id, strCaption, pos, size, style );
 
96
 
 
97
    CreateControls(required);
 
98
    GetSizer()->Fit(this);
 
99
    GetSizer()->SetSizeHints(this);
 
100
    Centre();
 
101
////@end CDlgSelectComputer creation
 
102
    return TRUE;
 
103
}
 
104
 
 
105
/*!
 
106
 * Control creation for CDlgSelectComputer
 
107
 */
 
108
 
 
109
void CDlgSelectComputer::CreateControls(bool required)
 
110
{    
 
111
////@begin CDlgSelectComputer content construction
 
112
    CDlgSelectComputer* itemDialog1 = this;
 
113
 
 
114
    wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
 
115
    itemDialog1->SetSizer(itemBoxSizer2);
 
116
 
 
117
    if (required) {
 
118
        CSkinAdvanced* pSkinAdvanced = wxGetApp().GetSkinManager()->GetAdvanced();
 
119
        wxASSERT(pSkinAdvanced);
 
120
        wxASSERT(wxDynamicCast(pSkinAdvanced, CSkinAdvanced));
 
121
 
 
122
        wxString strInfo = wxEmptyString;
 
123
        strInfo.Printf(
 
124
            _("Another instance of %s is already running \non this computer.  Please select a client to monitor."), 
 
125
            pSkinAdvanced->GetApplicationName().c_str()
 
126
        );
 
127
        wxStaticText* itemStaticText1 = new wxStaticText;
 
128
        itemStaticText1->Create( itemDialog1, wxID_STATIC, strInfo, wxDefaultPosition, wxDefaultSize, 0);
 
129
        itemBoxSizer2->Add(itemStaticText1, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 5);
 
130
    }
 
131
    
 
132
    wxFlexGridSizer* itemFlexGridSizer3 = new wxFlexGridSizer(1, 2, 0, 0);
 
133
    itemBoxSizer2->Add(itemFlexGridSizer3, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
 
134
 
 
135
    wxBoxSizer* itemBoxSizer4 = new wxBoxSizer(wxVERTICAL);
 
136
    itemFlexGridSizer3->Add(itemBoxSizer4, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 5);
 
137
 
 
138
    wxFlexGridSizer* itemFlexGridSizer5 = new wxFlexGridSizer(2, 2, 0, 0);
 
139
    itemBoxSizer4->Add(itemFlexGridSizer5, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
 
140
 
 
141
    wxStaticText* itemStaticText6 = new wxStaticText;
 
142
    itemStaticText6->Create( itemDialog1, wxID_STATIC, _("Host name:"), wxDefaultPosition, wxDefaultSize, 0 );
 
143
    itemFlexGridSizer5->Add(itemStaticText6, 0, wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL|wxALL, 5);
 
144
 
 
145
    wxString* m_ComputerNameCtrlStrings = NULL;
 
146
    m_ComputerNameCtrl = new wxComboBox;
 
147
    m_ComputerNameCtrl->Create( itemDialog1, ID_SELECTCOMPUTERNAME, _T(""), wxDefaultPosition, wxSize(250, -1), 0, m_ComputerNameCtrlStrings, wxCB_DROPDOWN );
 
148
    itemFlexGridSizer5->Add(m_ComputerNameCtrl, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 5);
 
149
 
 
150
    wxStaticText* itemStaticText8 = new wxStaticText;
 
151
    itemStaticText8->Create( itemDialog1, wxID_STATIC, _("Password:"), wxDefaultPosition, wxDefaultSize, 0 );
 
152
    itemFlexGridSizer5->Add(itemStaticText8, 0, wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL|wxALL, 5);
 
153
 
 
154
    m_ComputerPasswordCtrl = new wxTextCtrl;
 
155
    m_ComputerPasswordCtrl->Create( itemDialog1, ID_SELECTCOMPUTERPASSWORD, _T(""), wxDefaultPosition, wxSize(250, -1), wxTE_PASSWORD );
 
156
    itemFlexGridSizer5->Add(m_ComputerPasswordCtrl, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 5);
 
157
 
 
158
    wxBoxSizer* itemBoxSizer10 = new wxBoxSizer(wxVERTICAL);
 
159
    itemFlexGridSizer3->Add(itemBoxSizer10, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_TOP|wxALL, 5);
 
160
 
 
161
    wxButton* itemButton11 = new wxButton;
 
162
    itemButton11->Create( itemDialog1, wxID_OK, _("&OK"), wxDefaultPosition, wxDefaultSize, 0 );
 
163
    itemButton11->SetDefault();
 
164
    itemBoxSizer10->Add(itemButton11, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
 
165
 
 
166
    wxButton* itemButton12 = new wxButton;
 
167
    itemButton12->Create( itemDialog1, wxID_CANCEL, _("&Cancel"), wxDefaultPosition, wxDefaultSize, 0 );
 
168
    itemBoxSizer10->Add(itemButton12, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
 
169
 
 
170
    // Set validators
 
171
    m_ComputerNameCtrl->SetValidator( wxGenericValidator(& m_strComputerName) );
 
172
    m_ComputerPasswordCtrl->SetValidator( wxGenericValidator(& m_strComputerPassword) );
 
173
////@end CDlgSelectComputer content construction
 
174
}
 
175
 
 
176
/*!
 
177
 * Should we show tooltips?
 
178
 */
 
179
 
 
180
bool CDlgSelectComputer::ShowToolTips(){
 
181
    return TRUE;
 
182
}
 
183
 
 
184
/*!
 
185
 * Get bitmap resources
 
186
 */
 
187
 
 
188
wxBitmap CDlgSelectComputer::GetBitmapResource( const wxString& WXUNUSED(name) )
 
189
{
 
190
    // Bitmap retrieval
 
191
////@begin CDlgSelectComputer bitmap retrieval
 
192
    return wxNullBitmap;
 
193
////@end CDlgSelectComputer bitmap retrieval
 
194
}
 
195
 
 
196
/*!
 
197
 * Get icon resources
 
198
 */
 
199
 
 
200
wxIcon CDlgSelectComputer::GetIconResource( const wxString& WXUNUSED(name) )
 
201
{
 
202
    // Icon retrieval
 
203
////@begin CDlgSelectComputer icon retrieval
 
204
    return wxNullIcon;
 
205
////@end CDlgSelectComputer icon retrieval
 
206
}
 
207
 
 
208
/*!
 
209
 * wxEVT_COMMAND_TEXT_UPDATED event handler for ID_SELECTCOMPUTERNAME
 
210
 */
 
211
 
 
212
void CDlgSelectComputer::OnComputerNameUpdated( wxCommandEvent& WXUNUSED(event) )
 
213
{
 
214
    wxString       strPassword = wxEmptyString;
 
215
    CMainDocument* pDoc        = wxGetApp().GetDocument();
 
216
 
 
217
    wxASSERT(pDoc);
 
218
    wxASSERT(wxDynamicCast(pDoc, CMainDocument));
 
219
 
 
220
    wxString name = m_ComputerNameCtrl->GetValue();
 
221
    if (pDoc->IsComputerNameLocal(name)) {
 
222
        pDoc->m_pNetworkConnection->GetLocalPassword(strPassword);
 
223
        m_ComputerPasswordCtrl->SetValue(strPassword);
 
224
    }
 
225
}
 
226