-
Notifications
You must be signed in to change notification settings - Fork 12
/
ContentListView.cpp
623 lines (474 loc) · 14.3 KB
/
ContentListView.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
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
// ContentListView.cpp : implementation file
//
#include "stdafx.h"
#include "MyGet.h"
#include "ContentListView.h"
#include "MainFrm.h"
#include "ListItem.h"
#include "DownloadHttpJet.h"
#include "CommonUtils.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CContentListView
IMPLEMENT_DYNCREATE(CContentListView, CListView)
CContentListView::CContentListView()
{
m_iOldParentIndex = -1;
m_pCurListItem = NULL;
}
CContentListView::~CContentListView()
{
}
BEGIN_MESSAGE_MAP(CContentListView, CListView)
//{{AFX_MSG_MAP(CContentListView)
ON_WM_SIZE()
ON_NOTIFY_REFLECT(NM_CUSTOMDRAW, OnCustomDraw)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CContentListView drawing
void CContentListView::OnDraw(CDC* pDC)
{
CDocument* pDoc = GetDocument();
// TODO: add draw code here
}
/////////////////////////////////////////////////////////////////////////////
// CContentListView diagnostics
#ifdef _DEBUG
void CContentListView::AssertValid() const
{
CListView::AssertValid();
}
void CContentListView::Dump(CDumpContext& dc) const
{
CListView::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CContentListView message handlers
void CContentListView::RefreshView()
{
CMainFrame *pMainFrame = (CMainFrame *)AfxGetApp()->m_pMainWnd;
ASSERT(pMainFrame != NULL);
CIndexTreeView *pIndexTreeView = pMainFrame->m_pIndexTreeView;
HTREEITEM hTreeItem = pIndexTreeView->GetTreeCtrl().GetSelectedItem();
if (!hTreeItem)
{
return;
}
int iParentIndex;
iParentIndex = pIndexTreeView->GetTreeCtrl().GetItemData(hTreeItem);
if (m_iOldParentIndex != iParentIndex)
{
m_iOldParentIndex = iParentIndex;
prv_SetupView();
ReloadResource();
}
CItemListView *pItemListView = pMainFrame->m_pItemListView;
ASSERT(pItemListView != NULL);
int iFocusedItem = pItemListView->GetFocusedItem();
CListItem *pListItem;
if (iFocusedItem == -1)
{
pListItem = NULL;
}
else
{
pListItem = (CListItem *)pItemListView->GetListCtrl().GetItemData(iFocusedItem);
}
SetRedraw(FALSE);
prv_RefreshView(pListItem);
SetRedraw(TRUE);
}
void CContentListView::prv_SetupView()
{
CListCtrl &ListCtrl = GetListCtrl();
int nColumnCount = ListCtrl.GetHeaderCtrl()->GetItemCount();
// Delete all of the columns.
for (int i=0; i < nColumnCount; i++)
{
GetListCtrl().DeleteColumn(0);
}
ListCtrl.DeleteAllItems();
m_ProgressChart.ShowWindow(SW_HIDE);
ModifyStyle (LVS_TYPEMASK, LVS_REPORT);
switch(m_iOldParentIndex)
{
case CHART_CONTENT_TYPE: //图表/日志
//显示图表ProgressChart,并且缺省设置。
ModifyStyle (LVS_REPORT, 0);
m_ProgressChart.ShowWindow(SW_SHOW);
break;
case INFO_CONTENT_TYPE: //详细信息
ListCtrl.SetExtendedStyle(ListCtrl.GetExtendedStyle() | LVS_EX_GRIDLINES);
ListCtrl.InsertColumn(0, "Name", LVCFMT_LEFT, 100);
ListCtrl.InsertColumn(1, "Value", LVCFMT_LEFT, 600);
break;
case LINK_CONTENT_TYPE: //链接
ListCtrl.SetExtendedStyle(ListCtrl.GetExtendedStyle() & ~LVS_EX_GRIDLINES);
ListCtrl.InsertColumn(0, "Name", LVCFMT_LEFT, 100);
ListCtrl.InsertColumn(1, "URL", LVCFMT_LEFT, 600);
break;
default: //Jet10-Jet17
ListCtrl.SetExtendedStyle(ListCtrl.GetExtendedStyle() & ~LVS_EX_GRIDLINES);
ListCtrl.InsertColumn(0, "Time", LVCFMT_LEFT, 150);
ListCtrl.InsertColumn(1, "Info", LVCFMT_LEFT, 550);
break;
}
}
void CContentListView::prv_RefreshView(CListItem *pListItem)
{
CListCtrl &ListCtrl = GetListCtrl();
switch(m_iOldParentIndex)
{
case 1: //图表/日志
prv_FillChart(pListItem);
break;
case 3: //详细信息
prv_FillDetailInformation(pListItem);
break;
case 4: //链接
break;
default: //Jet10-Jet17
prv_FillJetInfo(pListItem);
break;
}
}
void CContentListView::OnInitialUpdate()
{
CListView::OnInitialUpdate();
ModifyStyle (LVS_TYPEMASK, LVS_REPORT);
GetListCtrl().SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES);
m_ImageList.Create(IDB_CONTENT_ITEM_ICON, 16, 5, CLR_DEFAULT);
GetListCtrl().SetImageList(&m_ImageList, LVSIL_SMALL);
CRect rect;
GetWindowRect(rect);
ScreenToClient(rect);
m_ProgressChart.Create(WS_CHILD | WS_VSCROLL | WS_TABSTOP, rect, this, IDC_PROGRESS_CHART);
}
void CContentListView::prv_FillDetailInformation(CListItem *pListItem)
{
CListCtrl &ListCtrl = GetListCtrl();
// ListCtrl.SetRedraw(FALSE);
ListCtrl.DeleteAllItems();
if (pListItem == NULL)
{
return;
}
LVITEM lvItem;
int iIndex = 0;
lvItem.mask = LVIF_IMAGE | LVIF_TEXT;
lvItem.iSubItem = 0;
lvItem.iImage = 4;
//Set URL
lvItem.iItem = iIndex;
lvItem.pszText = (char *)"URL";
lvItem.cchTextMax = strlen(lvItem.pszText);
ListCtrl.InsertItem(&lvItem);
ListCtrl.SetItemText(iIndex, 1, pListItem->GetURL());
//Set Comment
lvItem.iItem = ++iIndex;
lvItem.pszText = (char *)"Comment";
lvItem.cchTextMax = strlen(lvItem.pszText);
ListCtrl.InsertItem(&lvItem);
ListCtrl.SetItemText(iIndex, 1, pListItem->GetComment());
//Set REF
lvItem.iItem = ++iIndex;
lvItem.pszText = (char *)"Reference";
lvItem.cchTextMax = strlen(lvItem.pszText);
ListCtrl.InsertItem(&lvItem);
ListCtrl.SetItemText(iIndex, 1, pListItem->GetREF());
//Set Resume Supported
lvItem.iItem = ++iIndex;
lvItem.pszText = (char *)"Resume";
lvItem.cchTextMax = strlen(lvItem.pszText);
ListCtrl.InsertItem(&lvItem);
switch(pListItem->IsSupportResumed())
{
case -1:
ListCtrl.SetItemText(iIndex, 1, "");
break;
case 0:
ListCtrl.SetItemText(iIndex, 1, "Yes");
break;
case 1:
ListCtrl.SetItemText(iIndex, 1, "No");
break;
}
//Set Local location.
lvItem.iItem = ++iIndex;
lvItem.pszText = (char *)"Local File";
lvItem.cchTextMax = strlen(lvItem.pszText);
ListCtrl.InsertItem(&lvItem);
ListCtrl.SetItemText(iIndex, 1, CString(pListItem->GetDownloadedFolder()) + pListItem->GetRename());
//Set File original time.
lvItem.iItem = ++iIndex;
lvItem.pszText = (char *)"Date";
lvItem.cchTextMax = strlen(lvItem.pszText);
ListCtrl.InsertItem(&lvItem);
CTime timeFile;
timeFile = pListItem->GetFileTime();
ListCtrl.SetItemText(iIndex, 1, timeFile.Format("%A, %B %d, %Y %H:%M:%S"));
//Set File Size;
lvItem.iItem = ++iIndex;
lvItem.pszText = (char *)"Size";
lvItem.cchTextMax = strlen(lvItem.pszText);
ListCtrl.InsertItem(&lvItem);
TCHAR szFileSize[21];
pListItem->GetFileTotalLengthByString(szFileSize, 20);
ListCtrl.SetItemText(iIndex, 1, szFileSize);
//Set File Completed Size;
lvItem.iItem = ++iIndex;
lvItem.pszText = (char *)"Completed Size";
lvItem.cchTextMax = strlen(lvItem.pszText);
ListCtrl.InsertItem(&lvItem);
int iFileDownloadedSize = pListItem->GetFileDownloadedSize();
if (iFileDownloadedSize > 0)
{
CString strDownloadedSize;
strDownloadedSize.Format("%d", iFileDownloadedSize);
ListCtrl.SetItemText(iIndex, 1, strDownloadedSize);
}
//Set totoal downloading time cost.
lvItem.iItem = ++iIndex;
lvItem.pszText = (char *)"Time costed";
lvItem.cchTextMax = strlen(lvItem.pszText);
ListCtrl.InsertItem(&lvItem);
int iTimeCosted = pListItem->GetDownloadingTimeCosted();
if (iTimeCosted > 0)
{
CString strTimeCosted;
int iHour = iTimeCosted / 3600;
int iMin = iTimeCosted / 60 - iHour * 60;
int iSec = iTimeCosted % 60;
strTimeCosted.Format("%02d:%02d:%02d", iHour, iMin, iSec);
ListCtrl.SetItemText(iIndex, 1, strTimeCosted);
}
//set average speed.
lvItem.iItem = ++iIndex;
lvItem.pszText = (char *)"Average Speed";
lvItem.cchTextMax = strlen(lvItem.pszText);
ListCtrl.InsertItem(&lvItem);
if ((iFileDownloadedSize > 0)
&& (iTimeCosted > 0))
{
CString strAverageSpeed;
strAverageSpeed.Format("%.2f KB/S", ((float)(iFileDownloadedSize) / iTimeCosted / 1024));
ListCtrl.SetItemText(iIndex, 1, strAverageSpeed);
}
//Set Local File Create time.
lvItem.iItem = ++iIndex;
lvItem.pszText = (char *)"Created at";
lvItem.cchTextMax = strlen(lvItem.pszText);
ListCtrl.InsertItem(&lvItem);
timeFile = pListItem->GetLocalFileCreatedTime();
ListCtrl.SetItemText(iIndex, 1, timeFile.Format("%A, %B %d, %Y %H:%M:%S"));
//Set File complete time.
lvItem.iItem = ++iIndex;
lvItem.pszText = (char *)"Completed at";
lvItem.cchTextMax = strlen(lvItem.pszText);
ListCtrl.InsertItem(&lvItem);
timeFile = pListItem->GetLocalFileCompletedTime();
ListCtrl.SetItemText(iIndex, 1, timeFile.Format("%A, %B %d, %Y %H:%M:%S"));
// ListCtrl.SetRedraw(TRUE);
}
void CContentListView::prv_FillChart(CListItem *pListItem)
{
// m_ProgressChart.SetRedraw(FALSE);
if (pListItem == NULL)
{
m_pCurListItem = pListItem;
m_ProgressChart.SetTotalBlocks(0, 0);
m_ProgressChart.ResetBlocks();
return;
}
int iFileSize = pListItem->GetFileSize();
int iCountOfBlocks = (iFileSize + BLOCK_BYTE_SIZE - 1) / BLOCK_BYTE_SIZE;
if (m_pCurListItem != pListItem || iCountOfBlocks != m_ProgressChart.GetTotalBlocks() )
{
m_pCurListItem = pListItem;
m_ProgressChart.SetTotalBlocks(iCountOfBlocks, 0);
m_ProgressChart.ResetBlocks();
}
int iBreaksCount = pListItem->GetCountOfBreaks();
int iBeginPos, iEndPos;
for (int i = 0; i < iBreaksCount; i++)
{
PBREAKPOSITION pBrkPos = pListItem->GetBreakPos(i);
iBeginPos = (pListItem->GetBreakPos(i)->iStart + BLOCK_BYTE_SIZE - 1) / BLOCK_BYTE_SIZE;
ASSERT(pListItem->GetBreakPos(i)->iEnd <= iFileSize);
if (pListItem->GetBreakPos(i)->iEnd == iFileSize)
{
iEndPos = (pListItem->GetBreakPos(i)->iEnd + BLOCK_BYTE_SIZE - 1) / BLOCK_BYTE_SIZE;
}
else
{
iEndPos = (pListItem->GetBreakPos(i)->iEnd) / BLOCK_BYTE_SIZE;
}
for (int j = iBeginPos; j < iEndPos; j++)
{
m_ProgressChart.SetBlock(j, BLOCK_COMPLETED);
}
if (iEndPos < iCountOfBlocks && m_ProgressChart.GetBlock(iEndPos) != BLOCK_COMPLETED)
{
if (pListItem->GetStatus() == ITEM_STATUS_DOWNLOADING)
{
m_ProgressChart.SetBlock(iEndPos, BLOCK_DOWNLOADING);
}
else
{
m_ProgressChart.SetBlock(iEndPos, BLOCK_UNCOMPLETED);
}
}
}
// m_ProgressChart.SetRedraw(TRUE);
}
void CContentListView::OnSize(UINT nType, int cx, int cy)
{
CListView::OnSize(nType, cx, cy);
// TODO: Add your message handler code here
m_ProgressChart.Resize();
}
void CContentListView::prv_FillJetInfo(CListItem *pListItem)
{
CListCtrl &ListCtrl = GetListCtrl();
// ListCtrl.SetRedraw(FALSE);
// ListCtrl.DeleteAllItems();
//Get the index of Jet.
ASSERT(m_iOldParentIndex > JETLOG_CONTENT_TYPE_BASE && m_iOldParentIndex <= JETLOG_CONTENT_TYPE_BASE + 8);
if (pListItem == NULL)
{
ListCtrl.DeleteAllItems();
return;
}
CString strJetInfo = pListItem->GetJetInfo(m_iOldParentIndex - JETLOG_CONTENT_TYPE_BASE - 1);
int iBlockPos = strJetInfo.Find('\t');
int iPos;
CString strMsgBlock;
int iStateIndex;
CTime time;
CString strTime;
int iOldLineCount = ListCtrl.GetItemCount();
int iLineIndex = 0;
while (iBlockPos != -1)
{
int i = strJetInfo.GetLength();
strMsgBlock = strJetInfo.Left(iBlockPos);
strJetInfo = strJetInfo.Mid(iBlockPos + 1);
//first, Get the state index;
iPos = strMsgBlock.Find(':');
iStateIndex = atoi(strMsgBlock.Left(iPos));
strMsgBlock = strMsgBlock.Mid(iPos + 1);
//second, get time
iPos = strMsgBlock.Find(':');
time = (time_t)(ULONG)atoi(strMsgBlock.Left(iPos));
strTime = time.Format("%a %b %d %H:%I:%M %Y");
strMsgBlock = strMsgBlock.Mid(iPos + 1);
iPos = strMsgBlock.Find("\r\n");
CString strLine;
while(iPos != -1)
{
strLine = strMsgBlock.Left(iPos);
strMsgBlock = strMsgBlock.Mid(iPos + 2);
if (!strLine.IsEmpty())
{
if (iLineIndex >= iOldLineCount)
{
LVITEM lvItem;
lvItem.mask = TVIF_IMAGE | TVIF_PARAM;
lvItem.iItem = iLineIndex;
lvItem.iSubItem = 0;
lvItem.iImage = iStateIndex;
lvItem.lParam = iStateIndex;
ListCtrl.InsertItem(&lvItem);
ListCtrl.SetItemText(iLineIndex, 0, strTime);
ListCtrl.SetItemText(iLineIndex, 1, strLine);
}
iLineIndex++;
}
iPos = strMsgBlock.Find("\r\n");
}
iBlockPos = strJetInfo.Find('\t');
}
// ListCtrl.SetRedraw(TRUE);
}
void CContentListView::OnCustomDraw(NMHDR* pNMHDR, LRESULT* pResult)
{
if (m_iOldParentIndex <= JETLOG_CONTENT_TYPE_BASE)
{
*pResult = 0;
return;
}
// first, lets extract data from
// the message for ease of use later
NMLVCUSTOMDRAW* pNMLVCUSTOMDRAW = (NMLVCUSTOMDRAW*)pNMHDR;
// here is the item info
// note that we don't get the subitem
// number here, as this may not be
// valid data except when we are
// handling a sub item notification
// so we'll do that separately in
// the appropriate case statements
// below.
int nItem = pNMLVCUSTOMDRAW->nmcd.dwItemSpec;
LPARAM lParam = pNMLVCUSTOMDRAW->nmcd.lItemlParam;
//temporily use the hardcode value,
//later will be replaced by registry.
if (pNMLVCUSTOMDRAW->nmcd.dwDrawStage == CDDS_ITEMPREPAINT)
{
switch(lParam)
{
case STATE_MSG:
pNMLVCUSTOMDRAW->clrTextBk = 0x98fb98;
break;
case COMMAND_MSG:
pNMLVCUSTOMDRAW->clrTextBk = 0xeeeeaf;
break;
case ERROR_MSG:
pNMLVCUSTOMDRAW->clrTextBk = 0xcbc0ff;
break;
case SERVER_MSG:
pNMLVCUSTOMDRAW->clrTextBk = 0xfae6e6;
break;
}
}
*pResult = CDRF_NOTIFYITEMDRAW;
}
void CContentListView::ReloadResource()
{
CComposedStrings ComposedStrings;
switch(m_iOldParentIndex)
{
case INFO_CONTENT_TYPE: //详细信息
{
//ComposedStrings.SetComposedStrings(APP_GET_RSCSTR("String", 61302));
ComposedStrings.SetComposedStrings(61302);
ASSERT(ComposedStrings.GetSubStringCount() == 2);
GetListCtrl().InsertColumn(0, ComposedStrings.GetSubString(0), LVCFMT_LEFT, 100);
GetListCtrl().InsertColumn(1, ComposedStrings.GetSubString(1), LVCFMT_LEFT, 600);
}
break;
case LINK_CONTENT_TYPE: //链接
{
//ComposedStrings.SetComposedStrings(APP_GET_RSCSTR("String", 61310));
ComposedStrings.SetComposedStrings(61310);
ASSERT(ComposedStrings.GetSubStringCount() == 2);
GetListCtrl().InsertColumn(0, ComposedStrings.GetSubString(0), LVCFMT_LEFT, 100);
GetListCtrl().InsertColumn(1, ComposedStrings.GetSubString(1), LVCFMT_LEFT, 600);
}
break;
default: //Jet10-Jet17
{
//ComposedStrings.SetComposedStrings(APP_GET_RSCSTR("String", 61301));
ComposedStrings.SetComposedStrings(61301);
ASSERT(ComposedStrings.GetSubStringCount() == 2);
GetListCtrl().InsertColumn(0, ComposedStrings.GetSubString(0), LVCFMT_LEFT, 150);
GetListCtrl().InsertColumn(1, ComposedStrings.GetSubString(1), LVCFMT_LEFT, 550);
}
break;
}
}