Added icon to deployment manager
[public/netxms.git] / src / console / win32 / DeploymentView.cpp
CommitLineData
251659b6
VK
1// DeploymentView.cpp : implementation file
2//
3
4#include "stdafx.h"
5#include "nxcon.h"
6#include "DeploymentView.h"
7
8#ifdef _DEBUG
9#define new DEBUG_NEW
10#undef THIS_FILE
11static char THIS_FILE[] = __FILE__;
12#endif
13
094b9fa8
VK
14
15//
16// Constants
17//
18
19#define STATUS_HEIGHT 34
20#define PROGRESS_CTRL_TOP 20
21#define PROGRESS_CTRL_HEIGHT 9
22
23
251659b6
VK
24/////////////////////////////////////////////////////////////////////////////
25// CDeploymentView
26
27IMPLEMENT_DYNCREATE(CDeploymentView, CMDIChildWnd)
28
29CDeploymentView::CDeploymentView()
30{
094b9fa8
VK
31 m_dwRqId = 0;
32 m_bFinished = FALSE;
251659b6
VK
33}
34
35CDeploymentView::~CDeploymentView()
36{
37}
38
39
40BEGIN_MESSAGE_MAP(CDeploymentView, CMDIChildWnd)
41 //{{AFX_MSG_MAP(CDeploymentView)
e063dbf9 42 ON_WM_CREATE()
094b9fa8
VK
43 ON_WM_PAINT()
44 ON_WM_SIZE()
251659b6 45 //}}AFX_MSG_MAP
e063dbf9 46 ON_MESSAGE(WM_START_DEPLOYMENT, OnStartDeployment)
094b9fa8
VK
47 ON_MESSAGE(WM_DEPLOYMENT_INFO, OnDeploymentInfo)
48 ON_MESSAGE(WM_DEPLOYMENT_FINISHED, OnDeploymentFinished)
251659b6
VK
49END_MESSAGE_MAP()
50
51/////////////////////////////////////////////////////////////////////////////
52// CDeploymentView message handlers
e063dbf9
VK
53
54BOOL CDeploymentView::PreCreateWindow(CREATESTRUCT& cs)
55{
b602b111
VK
56 if (cs.lpszClass == NULL)
57 cs.lpszClass = AfxRegisterWndClass(CS_HREDRAW | CS_VREDRAW, NULL,
58 GetSysColorBrush(COLOR_WINDOW),
59 AfxGetApp()->LoadIcon(IDI_DEPLOY));
e063dbf9
VK
60 return CMDIChildWnd::PreCreateWindow(cs);
61}
62
63
64//
65// WM_CREATE message handler
66//
67
68int CDeploymentView::OnCreate(LPCREATESTRUCT lpCreateStruct)
69{
70 RECT rect;
71
72 if (CMDIChildWnd::OnCreate(lpCreateStruct) == -1)
73 return -1;
74
094b9fa8
VK
75 // Create font
76 m_font.CreateFont(-MulDiv(8, GetDeviceCaps(GetDC()->m_hDC, LOGPIXELSY), 72),
77 0, 0, 0, FW_BOLD, FALSE, FALSE, FALSE, ANSI_CHARSET,
78 OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, PROOF_QUALITY,
79 VARIABLE_PITCH | FF_DONTCARE, "Verdana");
80
81 // Create progress bar
82 GetClientRect(&rect);
83 rect.left += 4;
84 rect.right -= 4;
85 rect.top = PROGRESS_CTRL_TOP;
86 rect.bottom = rect.top + PROGRESS_CTRL_HEIGHT;
87 m_wndProgressCtrl.Create(WS_CHILD | WS_VISIBLE, rect, this, ID_PROGRESS_CTRL);
88
e063dbf9
VK
89 // Create list view inside window
90 GetClientRect(&rect);
094b9fa8 91 rect.top += STATUS_HEIGHT + 1;
e063dbf9
VK
92 m_wndListCtrl.Create(WS_CHILD | WS_VISIBLE | LVS_REPORT, rect, this, ID_LIST_VIEW);
93 m_wndListCtrl.InsertColumn(0, _T("Node"), LVCFMT_LEFT, 120);
94 m_wndListCtrl.InsertColumn(1, _T("Status"), LVCFMT_LEFT, 100);
95 m_wndListCtrl.InsertColumn(2, _T("Message"), LVCFMT_LEFT, 250);
094b9fa8 96 m_wndListCtrl.SetExtendedStyle(LVS_EX_GRIDLINES | LVS_EX_FULLROWSELECT);
9d3816ab
VK
97
98 m_imageList.Create(g_pObjectSmallImageList);
99 m_wndListCtrl.SetImageList(&m_imageList, LVSIL_SMALL);
e063dbf9
VK
100
101 return 0;
102}
103
104
105//
106// Deployment worker thread
107//
108
094b9fa8 109static DWORD WINAPI DeploymentThread(DEPLOYMENT_JOB *pJob)
e063dbf9
VK
110{
111 DWORD dwResult;
112
094b9fa8
VK
113 dwResult = NXCDeployPackage(g_hSession, pJob->dwPkgId, pJob->dwNumObjects,
114 pJob->pdwObjectList, pJob->pdwRqId);
115 PostMessage(pJob->hWnd, WM_DEPLOYMENT_FINISHED, 0, dwResult);
e063dbf9
VK
116 safe_free(pJob->pdwObjectList);
117 free(pJob);
094b9fa8 118 return 0;
e063dbf9
VK
119}
120
121
122//
123// WM_START_DEPLOYMENT message handler
124//
125
126void CDeploymentView::OnStartDeployment(WPARAM wParam, DEPLOYMENT_JOB *pJob)
127{
094b9fa8
VK
128 DWORD dwThreadId;
129 HANDLE hThread;
130
131 m_wndProgressCtrl.SetRange32(0, pJob->dwNumObjects);
132 m_wndProgressCtrl.SetStep(1);
133 m_wndProgressCtrl.SetPos(0);
134
e063dbf9 135 pJob->hWnd = m_hWnd;
094b9fa8
VK
136 pJob->pdwRqId = &m_dwRqId;
137 hThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)DeploymentThread,
138 pJob, 0, &dwThreadId);
139 if (hThread != NULL)
140 {
141 CloseHandle(hThread);
142 }
143}
144
145
146//
147// WM_DEPLOYMENT_INFO message handler
148//
149
150void CDeploymentView::OnDeploymentInfo(DWORD dwRqId, NXC_DEPLOYMENT_STATUS *pInfo)
151{
152 if (dwRqId == m_dwRqId)
153 {
154 LVFINDINFO lvfi;
155 int iItem;
156
157 // Find node's record
158 lvfi.flags = LVFI_PARAM;
159 lvfi.lParam = pInfo->dwNodeId;
160 iItem = m_wndListCtrl.FindItem(&lvfi, -1);
161 if (iItem == -1)
162 {
163 NXC_OBJECT *pObject;
164
165 // Create new record
166 pObject = NXCFindObjectById(g_hSession, pInfo->dwNodeId);
9d3816ab
VK
167 if (pObject != NULL)
168 {
169 iItem = m_wndListCtrl.InsertItem(0x7FFFFFFF, pObject->szName,
170 GetObjectImageIndex(pObject));
171 }
172 else
173 {
174 iItem = m_wndListCtrl.InsertItem(0x7FFFFFFF, _T("<invalid>"), -1);
175 }
094b9fa8
VK
176 m_wndListCtrl.SetItemData(iItem, pInfo->dwNodeId);
177 m_wndProgressCtrl.SetRange32(0, m_wndListCtrl.GetItemCount());
178 }
179 m_wndListCtrl.SetItemText(iItem, 1, g_szDeploymentStatus[pInfo->dwStatus]);
180 m_wndListCtrl.SetItemText(iItem, 2,
181 (pInfo->dwStatus == DEPLOYMENT_STATUS_FAILED) ? pInfo->pszErrorMessage : _T(""));
182
183 if ((pInfo->dwStatus == DEPLOYMENT_STATUS_FAILED) ||
184 (pInfo->dwStatus == DEPLOYMENT_STATUS_COMPLETED))
185 m_wndProgressCtrl.StepIt();
186 }
187}
188
189
190//
191// WM_PAINT message handler
192//
193
194void CDeploymentView::OnPaint()
195{
196 CPaintDC dc(this); // device context for painting
197 RECT rect;
198 CPen pen, *pOldPen;
199 CFont *pOldFont;
200
201 // Draw separator between status box and node list
202 pen.CreatePen(PS_SOLID, 0, RGB(127, 127, 127));
203 pOldPen = dc.SelectObject(&pen);
204
205 GetClientRect(&rect);
206 dc.MoveTo(0, STATUS_HEIGHT);
207 dc.LineTo(rect.right, STATUS_HEIGHT);
208
209 dc.SelectObject(pOldPen);
210
211 // Show current status
212 pOldFont = dc.SelectObject(&m_font);
213 dc.TextOut(4, 4, m_bFinished ? _T("Job finished") : _T("Job running "), 12);
214 dc.SelectObject(pOldFont);
215}
216
217
218//
219// WM_SIZE messahe handler
220//
221
222void CDeploymentView::OnSize(UINT nType, int cx, int cy)
223{
224 CMDIChildWnd::OnSize(nType, cx, cy);
225
226 m_wndProgressCtrl.SetWindowPos(NULL, 4, PROGRESS_CTRL_TOP, cx - 8, PROGRESS_CTRL_HEIGHT, SWP_NOZORDER);
227 m_wndListCtrl.SetWindowPos(NULL, 0, STATUS_HEIGHT + 1, cx, cy - STATUS_HEIGHT, SWP_NOZORDER);
228}
229
230
231//
232// WM_DEPLOYMENT_FINISHED message handler
233//
234
235void CDeploymentView::OnDeploymentFinished(WPARAM wParam, LPARAM lParam)
236{
237 m_bFinished = TRUE;
238 InvalidateRect(NULL);
239 if (lParam == RCC_SUCCESS)
240 MessageBox(_T("Deployment job finished successfully"), _T("Information"), MB_OK | MB_ICONINFORMATION);
241 else
242 theApp.ErrorBox(lParam, _T("Deployment job failed: %s"));
e063dbf9 243}