-
Notifications
You must be signed in to change notification settings - Fork 7
/
ResumeDialog.cpp
346 lines (297 loc) · 9.49 KB
/
ResumeDialog.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
// $Id: ResumeDialog.cpp 685 2012-02-15 17:09:07Z felfert $
//
// Copyright (C) 2006 The OpenNX team
// Author: Fritz Elfert
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU Library General Public License as
// published by the Free Software Foundation; either version 2 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU Library General Public
// License along with this program; if not, write to the
// Free Software Foundation, Inc.,
// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
#pragma implementation "ResumeDialog.h"
#endif
// For compilers that support precompilation, includes "wx/wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#ifndef WX_PRECOMP
#include "wx/wx.h"
#endif
////@begin includes
#include "wx/imaglist.h"
////@end includes
#include "ResumeDialog.h"
#include "Icon.h"
#include "opennxApp.h"
#include "trace.h"
ENABLE_TRACE;
////@begin XPM images
////@end XPM images
/*!
* ResumeDialog type definition
*/
IMPLEMENT_DYNAMIC_CLASS( ResumeDialog, wxDialog )
/*!
* ResumeDialog event table definition
*/
BEGIN_EVENT_TABLE( ResumeDialog, wxDialog )
////@begin ResumeDialog event table entries
EVT_LIST_ITEM_SELECTED( XRCID("ID_LISTCTRL_SESSIONS"), ResumeDialog::OnListctrlSessionsSelected )
EVT_BUTTON( wxID_REFRESH, ResumeDialog::OnRefreshClick )
EVT_BUTTON( XRCID("ID_BUTTON_TERMINATE"), ResumeDialog::OnButtonTerminateClick )
EVT_BUTTON( XRCID("ID_BUTTON_TAKEOVER"), ResumeDialog::OnButtonTakeoverClick )
EVT_BUTTON( XRCID("ID_BUTTON_RESUME"), ResumeDialog::OnButtonResumeClick )
////@end ResumeDialog event table entries
END_EVENT_TABLE()
/*!
* ResumeDialog constructors
*/
ResumeDialog::ResumeDialog( )
{
Init();
}
ResumeDialog::ResumeDialog( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
{
Init();
Create(parent, id, caption, pos, size, style);
}
/*!
* ResumeDialog creator
*/
bool ResumeDialog::Create( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
{
////@begin ResumeDialog creation
SetExtraStyle(wxWS_EX_BLOCK_EVENTS);
SetParent(parent);
CreateControls();
if (GetSizer())
{
GetSizer()->SetSizeHints(this);
}
Centre();
////@end ResumeDialog creation
wxUnusedVar(style);
wxUnusedVar(size);
wxUnusedVar(pos);
wxUnusedVar(caption);
wxUnusedVar(id);
return true;
}
/*!
* Member initialisation
*/
void ResumeDialog::Init()
{
////@begin ResumeDialog member initialisation
m_lActiveSession = -1;
m_eMode = New;
m_bShadow = false;
m_pCtrlSessions = NULL;
m_pCtrlTerminate = NULL;
m_pCtrlTakeover = NULL;
m_pCtrlResume = NULL;
m_pCtrlNew = NULL;
////@end ResumeDialog member initialisation
}
/*!
* Control creation for ResumeDialog
*/
void ResumeDialog::CreateControls()
{
////@begin ResumeDialog content construction
if (!wxXmlResource::Get()->LoadDialog(this, GetParent(), _T("ID_RESUMEDIALOG")))
wxLogError(wxT("Missing wxXmlResource::Get()->Load() in OnInit()?"));
m_pCtrlSessions = XRCCTRL(*this, "ID_LISTCTRL_SESSIONS", wxListCtrl);
m_pCtrlTerminate = XRCCTRL(*this, "ID_BUTTON_TERMINATE", wxButton);
m_pCtrlTakeover = XRCCTRL(*this, "ID_BUTTON_TAKEOVER", wxButton);
m_pCtrlResume = XRCCTRL(*this, "ID_BUTTON_RESUME", wxButton);
m_pCtrlNew = XRCCTRL(*this, "wxID_OK", wxButton);
////@end ResumeDialog content construction
// Create custom windows not generated automatically here.
////@begin ResumeDialog content initialisation
////@end ResumeDialog content initialisation
//
m_pCtrlSessions->InsertColumn(0, _("Name"));
m_pCtrlSessions->InsertColumn(1, _("User"));
m_pCtrlSessions->InsertColumn(2, _("State"));
m_pCtrlSessions->InsertColumn(3, _("Type"));
m_pCtrlSessions->InsertColumn(4, _("Screen"));
m_pCtrlSessions->InsertColumn(5, _("Port"));
m_pCtrlSessions->InsertColumn(6, _("Options"));
m_pCtrlSessions->InsertColumn(7, _("Session ID"));
for (int i = 0; i < m_pCtrlSessions->GetColumnCount(); i++)
m_pCtrlSessions->SetColumnWidth(i, wxLIST_AUTOSIZE);
}
void
ResumeDialog::AddSession(const wxString& name, const wxString& state, const wxString& type,
const wxString& size, const wxString& colors,
const wxString& port, const wxString& opts, const wxString& id, const wxString& user /* = wxT("") */)
{
long idx = m_pCtrlSessions->InsertItem(m_pCtrlSessions->GetItemCount(), name, 0);
if (0 <= idx) {
m_pCtrlSessions->SetItem(idx, 1, user);
m_pCtrlSessions->SetItem(idx, 2, state);
m_pCtrlSessions->SetItem(idx, 3, type);
if (size.IsSameAs(wxT("N/A")) && colors.IsSameAs(wxT("N/A")))
m_pCtrlSessions->SetItem(idx, 4, colors);
else
m_pCtrlSessions->SetItem(idx, 4, size + wxT("x") + colors);
m_pCtrlSessions->SetItem(idx, 5, port);
m_pCtrlSessions->SetItem(idx, 6, opts);
m_pCtrlSessions->SetItem(idx, 7, id);
//long lPort;
//port.ToLong(&lPort);
//m_pCtrlSessions->SetItemData(idx, lPort);
for (int i = 0; i < m_pCtrlSessions->GetColumnCount(); i++)
m_pCtrlSessions->SetColumnWidth(i, wxLIST_AUTOSIZE);
if ((m_lActiveSession < 0) || (name == m_sPreferredSession)) {
myLogTrace(MYTRACETAG, wxT("autoselect preferred=%d"), (int)idx);
wxListItem info;
info.m_itemId = idx;
info.m_mask = wxLIST_MASK_STATE;
info.m_state = wxLIST_STATE_FOCUSED|wxLIST_STATE_SELECTED;
info.m_stateMask = wxLIST_STATE_FOCUSED|wxLIST_STATE_SELECTED;
m_pCtrlSessions->SetItem(info);
m_sSelectedPort = port;
m_sSelectedName = name;
m_sSelectedType = type;
m_sSelectedId = id;
}
} else {
wxLogError(_("Could not add session list item"));
}
}
void
ResumeDialog::EnableNew(bool b)
{
m_pCtrlNew->Enable(b);
}
void
ResumeDialog::SetAttachMode(bool b)
{
m_bShadow = b;
m_pCtrlResume->SetLabel(b ? _("&Attach") : _("&Resume"));
m_pCtrlTakeover->SetLabel(b ? _("&View") : _("&Takeover"));
}
/*!
* wxEVT_COMMAND_LIST_ITEM_SELECTED event handler for ID_LISTCTRL_SESSIONS
*/
void ResumeDialog::OnListctrlSessionsSelected( wxListEvent& event )
{
m_lActiveSession = event.GetIndex();
myLogTrace(MYTRACETAG, wxT("clickselect=%d"), (int)m_lActiveSession);
wxListItem info;
info.SetId(m_lActiveSession);
info.SetMask(wxLIST_MASK_TEXT);
info.SetColumn(2);
m_pCtrlSessions->GetItem(info);
if (m_bShadow) {
if (info.GetText() == wxT("Suspended")) {
m_pCtrlResume->Enable(false);
m_pCtrlTakeover->Enable(false);
m_pCtrlTerminate->Enable(true);
} else {
m_pCtrlResume->Enable(true);
m_pCtrlTakeover->Enable(true);
m_pCtrlTerminate->Enable(false);
}
} else {
if (info.GetText() == wxT("Suspended")) {
m_pCtrlResume->Enable(true);
m_pCtrlTakeover->Enable(false);
m_pCtrlTerminate->Enable(true);
} else {
m_pCtrlResume->Enable(false);
m_pCtrlTakeover->Enable(true);
m_pCtrlTerminate->Enable(false);
}
}
info.SetColumn(0);
m_pCtrlSessions->GetItem(info);
m_sSelectedName = info.GetText();
info.SetColumn(3);
m_pCtrlSessions->GetItem(info);
m_sSelectedType = info.GetText();
info.SetColumn(5);
m_pCtrlSessions->GetItem(info);
m_sSelectedPort = info.GetText();
info.SetColumn(7);
m_pCtrlSessions->GetItem(info);
m_sSelectedId = info.GetText();
myLogTrace(MYTRACETAG, wxT("Selected session ID=%s"), VMB(m_sSelectedId));
event.Skip();
}
/*!
* wxEVT_COMMAND_BUTTON_CLICKED event handler for wxID_REFRESH
*/
void ResumeDialog::OnRefreshClick( wxCommandEvent& event )
{
wxUnusedVar(event);
m_eMode = Refresh;
EndModal(wxID_OK);
}
/*!
* wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_BUTTON_TAKEOVER
*/
void ResumeDialog::OnButtonTakeoverClick( wxCommandEvent& )
{
m_eMode = Takeover;
EndModal(wxID_OK);
}
/*!
* wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_BUTTON_RESUME
*/
void ResumeDialog::OnButtonResumeClick( wxCommandEvent& )
{
m_eMode = Resume;
EndModal(wxID_OK);
}
/*!
* wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_BUTTON_TERMINATE
*/
void ResumeDialog::OnButtonTerminateClick( wxCommandEvent& )
{
if (wxYES != ::wxMessageBox(_("Do you really want to terminate the selected session?"),
_("Terminate session - OpenNX"), wxYES_NO|wxICON_QUESTION, this))
return;
m_eMode = Terminate;
EndModal(wxID_OK);
}
/*!
* Should we show tooltips?
*/
bool ResumeDialog::ShowToolTips()
{
return true;
}
/*!
* Get bitmap resources
*/
wxBitmap ResumeDialog::GetBitmapResource( const wxString& name )
{
// Bitmap retrieval
return CreateBitmapFromFile(name);
}
/*!
* Get icon resources
*/
wxIcon ResumeDialog::GetIconResource( const wxString& name )
{
// Icon retrieval
return CreateIconFromFile(name);
}