-
Notifications
You must be signed in to change notification settings - Fork 0
/
NEWSVIEW.CPP
4801 lines (3940 loc) · 129 KB
/
NEWSVIEW.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
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// newsview.cpp: implementation file
//
#include "stdafx.h"
#include "inetnav.h"
#include "percent.h"
#include "dialogs.h"
#include <stdio.h>
#include "resource.h"
#include "propshts.h"
#include "mail.h"
#include "news.h"
#include "wizards.h"
#ifdef _DEBUG
#undef THIS_FILE
static char BASED_CODE THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CNewsView
IMPLEMENT_DYNCREATE(CNewsView, CFormView)
BEGIN_MESSAGE_MAP(CNewsView, CFormView)
//{{AFX_MSG_MAP(CNewsView)
ON_BN_CLICKED(IDC_MAIL_MANAGER, OnMailManager)
ON_BN_CLICKED(IDC_HELPINFO, OnHelpinfo)
ON_BN_CLICKED(IDC_NEWSGROUPS_SETUP, OnNewsgroupsSetup)
ON_UPDATE_COMMAND_UI(ID_FILE_PRINT, OnUpdateFilePrint)
ON_UPDATE_COMMAND_UI(ID_FILE_PRINT_PREVIEW, OnUpdateFilePrintPreview)
ON_BN_CLICKED(IDC_GROUP_MANAGER, OnGroupManager)
ON_COMMAND(ID_ARTICLE_ADD, OnArticleAdd)
ON_BN_CLICKED(IDC_COMPOSE_ARTICLE, OnArticleAdd)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CNewsView construction/destruction
CNewsView::CNewsView()
: CFormView(CNewsView::IDD)
{
//{{AFX_DATA_INIT(CNewsView)
m_pDoc = NULL;
//}}AFX_DATA_INIT
m_pApp = (CInternetNavApp*)AfxGetApp();
}
CNewsView::~CNewsView()
{
}
void CNewsView::DoDataExchange(CDataExchange* pDX)
{
CFormView::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CNewsView)
DDX_Control(pDX, IDC_MAIL_MANAGER, m_btnPostOffice);
DDX_Control(pDX, IDC_COMPOSE_ARTICLE, m_btnCompose);
DDX_Control(pDX, IDC_GROUP_MANAGER, m_btnGroupMan);
DDX_Control(pDX, IDC_HELPINFO, m_btnHelp);
DDX_Control(pDX, IDC_NEWSGROUPS_SETUP, m_btnSetup);
//}}AFX_DATA_MAP
if (pDX->m_bSaveAndValidate)
UpdateData(FALSE);
}
void CNewsView::OnInitialUpdate()
{
m_pDoc = GetDocument(); // pointer to document data, including
// server addresses
((CNewsWnd*)GetParentFrame())->OnUpdateFrameTitle(TRUE);
// We will set the bitmaps for the buttons in this area.
m_btnPostOffice.LoadBitmaps("POFFICEU", "POFFICED", "POFFICEF", "POFFICEX");
m_btnCompose.LoadBitmaps("NEWSU", "NEWSD", "NEWSF", "NEWSX");
m_btnSetup.LoadBitmaps("NEWSU", "NEWSD", "NEWSF", "NEWSX");
m_btnGroupMan.LoadBitmaps("GROUPMANU", "GROUPMAND", "GROUPMANF", "GROUPMANX");
m_btnHelp.LoadBitmaps("HELPINFOU", "HELPINFOD", "HELPINFOF",
"HELPINFOX");
CFormView::OnInitialUpdate();
// Now resize each button so that its size matches its bitmap image.
m_btnPostOffice.SizeToContent();
m_btnCompose.SizeToContent();
m_btnSetup.SizeToContent();
m_btnGroupMan.SizeToContent();
m_btnHelp.SizeToContent();
// Now subclass with CTL3D so this area looks good
Ctl3dSubclassDlgEx(m_hWnd, CTL3D_ALL);
m_btnCompose.EnableWindow(m_pDoc->CanPost());
// Tell the caller of this function that we're done.
#ifdef _DEBUG
afxDump << "Internet Newsgroups area is coming online." << "\r\n";
#endif
return;
}
/////////////////////////////////////////////////////////////////////////////
// CNewsView diagnostics
#ifdef _DEBUG
void CNewsView::AssertValid() const
{
CFormView::AssertValid();
}
void CNewsView::Dump(CDumpContext& dc) const
{
CFormView::Dump(dc);
}
CNewsDoc* CNewsView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CNewsDoc)));
return (CNewsDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CNewsView message handlers
void CNewsView::OnNewsgroupsSetup()
{
// Show the Newsgroups Settings dialog box
m_pDoc->OnNewsgroupsSetup();
}
void CNewsView::OnMailManager()
{
m_pApp->OnPlacesPostOffice();
return;
}
void CNewsView::OnHelpinfo()
{
// Show help on this window
CWnd::OnHelp();
}
void CNewsView::OnGroupManager()
{
CWaitCursor wait;
// Show the m_pApp->m_pNewsgroupsManager template using the same document
CNewsgroupsManagerWnd* pFrame;
CMultiDocTemplate* pTempl = m_pApp->GetNewsgroupsManager();
pFrame = (CNewsgroupsManagerWnd*)pTempl->CreateNewFrame(m_pDoc, NULL);
if (pFrame == NULL)
{
MessageBeep(-1);
AfxMessageBox(IDP_FAILED_OPEN_WINDOW, MB_ICONSTOP|MB_OK);
return;
}
// We've now successfully created the frame window for the Newsgroups
// Manager, so let's now initialize it. The below function call also
// calls CNewsgroupsManager::OnInitialUpdate()
pTempl->InitialUpdateFrame(pFrame, m_pDoc, TRUE);
}
void CNewsView::OnUpdateFilePrint(CCmdUI* pCmdUI)
{
// we don't want the user to be able to print anything -- to them, this
// is just another area of Internet Navigator.
pCmdUI->Enable(FALSE);
}
void CNewsView::OnUpdateFilePrintPreview(CCmdUI* pCmdUI)
{
// we don't want the user to be able to print anything -- to them, this
// is just another area of Internet Navigator.
pCmdUI->Enable(FALSE);
}
void CNewsView::OnArticleAdd()
{
CArticleComposeWnd* pFrame =
(CArticleComposeWnd*)m_pApp->GetCNA()->CreateNewFrame(m_pDoc, NULL);
if (pFrame == NULL)
{
MessageBeep(-1);
AfxMessageBox(IDP_FAILED_OPEN_WINDOW, MB_ICONSTOP|MB_OK);
return;
}
m_pApp->GetCNA()->InitialUpdateFrame(pFrame, m_pDoc, TRUE);
}
/////////////////////////////////////////////////////////////////////////////
// CNewsgroupsManager
IMPLEMENT_DYNCREATE(CNewsgroupsManager, CFormView)
CNewsgroupsManager::CNewsgroupsManager()
: CFormView(CNewsgroupsManager::IDD)
{
//{{AFX_DATA_INIT(CNewsgroupsManager)
m_pDoc = NULL;
//}}AFX_DATA_INIT
m_pApp = (CInternetNavApp*)AfxGetApp();
m_pStatusBar = m_pApp->GetMainFrame()->GetStatusBar();
m_pPercentDialog = NULL;
}
CNewsgroupsManager::~CNewsgroupsManager()
{
// If necessary, delete the percent gauge dialog box
if (m_pPercentDialog && IsWindow(m_pPercentDialog->GetSafeHwnd()))
{
m_pPercentDialog->ShowWindow(SW_HIDE);
m_pPercentDialog->UpdateWindow();
m_pPercentDialog->DestroyWindow();
}
}
void CNewsgroupsManager::DoDataExchange(CDataExchange* pDX)
{
CFormView::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CNewsgroupsManager)
DDX_Control(pDX, IDC_NEWSGROUPS_LIST, m_ctlGroupList);
DDX_LBString(pDX, IDC_NEWSGROUPS_LIST, m_strSelection);
//}}AFX_DATA_MAP
if (pDX->m_bSaveAndValidate)
UpdateData(FALSE);
}
BEGIN_MESSAGE_MAP(CNewsgroupsManager, CFormView)
//{{AFX_MSG_MAP(CNewsgroupsManager)
ON_COMMAND(ID_GROUP_ADD, OnGroupAdd)
ON_LBN_ERRSPACE(IDC_NEWSGROUPS_LIST, OnListOutOfSpace)
ON_COMMAND(ID_GROUP_REMOVE, OnGroupRemove)
ON_UPDATE_COMMAND_UI(ID_GROUP_REMOVE, OnUpdateGroupRemove)
ON_COMMAND(ID_GROUP_OPEN, OnGroupOpen)
ON_UPDATE_COMMAND_UI(ID_GROUP_OPEN, OnUpdateGroupOpen)
ON_LBN_DBLCLK(IDC_NEWSGROUPS_LIST, OnGroupOpen)
ON_COMMAND(ID_ARTICLE_AGE, OnArticleAge)
//}}AFX_MSG_MAP
// Standard Help command
ON_COMMAND(ID_HELP, CWnd::OnHelp)
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
// Idle ON_UPDATE_COMMAND_UI invoke message
ON_MESSAGE(WM_IDLEUPDATECMDUI, OnIdleUpdateCmdUI)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CNewsgroupsManager update handlers
void CNewsgroupsManager::OnInitialUpdate()
{
m_pDoc = GetDocument();
((CNewsgroupsManagerWnd*)GetParentFrame())->OnUpdateFrameTitle(TRUE);
CFormView::OnInitialUpdate();
if (m_pApp->IsUseCTL3D())
Ctl3dSubclassDlgEx(m_hWnd, CTL3D_ALL);
// We need to load the subscribed newsgroup list in from the document
// here.
if (m_pDoc->m_strGroupsArray.GetSize() == 0) return;
for (int i = 0;i < m_pDoc->m_strGroupsArray.GetSize();i++)
{
m_ctlGroupList.AddString(m_pDoc->m_strGroupsArray[i]);
}
return; // return for now
}
void CNewsgroupsManager::OnUpdate(CView*, LPARAM, CObject*)
{
// Just update the data in this view
if (!UpdateData(FALSE))
AfxMessageBox(AFX_IDP_INTERNAL_FAILURE, MB_ICONSTOP|MB_OK);
return;
}
/////////////////////////////////////////////////////////////////////////////
// CNewsgroupsManager printing
// Here's how we're going to implement printing for this view:
// What to print: The newsgroup list
// How to do it: Iterate through the array in the document
// and insert each newsgroup name into a mega string which
// we draw on the printer with CDC::DrawText(). Between each
// of the newsgroup names we insert a CRLF pair so they are
// broken into lines.
BOOL CNewsgroupsManager::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
pInfo->m_nNumPreviewPages = 2;
pInfo->SetMaxPage(0xFFFF);
return DoPreparePrinting(pInfo);
}
void CNewsgroupsManager::OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo)
{
CFormView::OnBeginPrinting(pDC, pInfo);
}
void CNewsgroupsManager::OnPrint(CDC* pDC, CPrintInfo* pInfo)
{
if (m_pDoc->m_strGroupsArray.GetSize() == 0)
return;
// Form and print an informational header first
CString strHeader = "Internet Newsgroups: Subscribed Newsgroups List";
PrintPageHeader(pDC, pInfo, strHeader);
// Now prepare the mega-string
CString strList = m_pDoc->m_strGroupsArray[0] + "\r\n";
if (m_pDoc->m_strGroupsArray.GetSize() > 1)
{
for (int i = 0;i < m_pDoc->m_strGroupsArray.GetSize();i++)
{
strList += m_pDoc->m_strGroupsArray[i] + "\r\n";
}
}
// Now draw the list on the printer device context with
// CDC::DrawText()
pDC->DrawText(strList, -1, pInfo->m_rectDraw,
DT_LEFT|DT_WORDBREAK);
// we're done with printing!
return;
}
void CNewsgroupsManager::OnEndPrinting(CDC* pDC, CPrintInfo* pInfo)
{
CFormView::OnEndPrinting(pDC, pInfo);
}
void CNewsgroupsManager::PrintPageHeader(CDC* pDC, CPrintInfo* pInfo,
CString& strHeader)
{
// Print a page header consisting of the name of
// the document and a horizontal line
pDC->TextOut(0, 25, strHeader); // 1/4 inch down
// Draw a line across the page, below the header
TEXTMETRIC textMetric;
pDC->GetTextMetrics(&textMetric);
int y = 35 + textMetric.tmHeight; // line 1/10th inch below text
pDC->MoveTo(0, y); // from left margin
pDC->LineTo(pInfo->m_rectDraw.right, y); // to right margin
// Subtract out from the drawing rectange the space used by the header.
y += 25; // space 1/4 inch below (top of) line
pInfo->m_rectDraw.top += y;
return;
}
/////////////////////////////////////////////////////////////////////////////
// CNewsgroupsManager diagnostics
#ifdef _DEBUG
CNewsDoc* CNewsgroupsManager::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CNewsDoc)));
return (CNewsDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CNewsgroupsManager idle button update
LRESULT CNewsgroupsManager::OnIdleUpdateCmdUI(WPARAM wParam, LPARAM lParam)
{
// Update controls and buttons in this window
UpdateDialogControls(this, TRUE);
return 0;
}
/////////////////////////////////////////////////////////////////////////////
// CNewsgroupsManager message handlers
void CNewsgroupsManager::OnGroupAdd()
{
QSocket* pSocket = m_pDoc->GetSocket();
if (pSocket == NULL)
{
AfxMessageBox(IDP_CONNECTION_BUSY,
MB_ICONASTERISK|MB_OK);
return;
}
CGroupSubscribe theDialog(AfxGetMainWnd(), pSocket);
theDialog.m_pDoc = m_pDoc;
if (theDialog.DoModal() == IDOK)
{
m_pDoc->m_strGroupsArray.Add(theDialog.m_strNewsgroup);
// We've changed the document's data, so mark the document as
// modified
m_pDoc->SetModifiedFlag();
m_ctlGroupList.AddString(theDialog.m_strNewsgroup);
m_pDoc->ReleaseSocket(); // make our socket available again
return;
}
if (!m_pDoc->DoSave(m_pDoc->m_strPathName, TRUE))
{
MessageBeep(-1);
AfxMessageBox(AFX_IDP_FAILED_TO_SAVE_DOC, MB_ICONSTOP);
m_pDoc->ReleaseSocket();
return;
}
m_pDoc->ReleaseSocket(); // make our socket available again
return;
}
void CNewsgroupsManager::OnGroupRemove()
{
//if (m_pApp->m_bNewsAskBeforeRemove) (a future Preference)
CString strMsg = "Are you sure you want to remove this group from the ";
strMsg += "list?";
if (AfxMessageBox(strMsg, MB_YESNO|MB_ICONQUESTION) == IDNO)
return;
// We want to remove the selected group from the list box and
// the m_sttrGroupsArray array.
UpdateData(TRUE);
int nCurSel = m_ctlGroupList.GetCurSel();
m_pStatusBar->SetText("Removing " + m_strSelection + "...");
// Use nCurSel as the zero-based index into the array, since the indexing
// systems of the list box and the array are the same
// First, remove the newsgroup name from the newsgroups array
m_pDoc->m_strGroupsArray.RemoveAt(nCurSel);
m_pDoc->SetModifiedFlag();
// Next, remove the group name from the list
m_ctlGroupList.DeleteString(nCurSel);
m_ctlGroupList.UpdateWindow();
m_pStatusBar->ShowIdleMessage();
return;
}
void CNewsgroupsManager::OnArticleAge()
{
CArticleAge theDlg(m_pApp->GetMainFrame());
m_pApp->Serialize(FALSE);
theDlg.m_lDays = m_pApp->GetArticleDays();
theDlg.m_nHours = m_pApp->GetArticleHours();
theDlg.m_nMinutes = m_pApp->GetArticleMinutes();
theDlg.m_nSeconds = m_pApp->GetArticleSeconds();
if (theDlg.DoModal() == IDOK)
{
m_pApp->SetArticleDays(theDlg.m_lDays);
m_pApp->SetArticleHours(theDlg.m_nHours);
m_pApp->SetArticleMinutes(theDlg.m_nMinutes);
m_pApp->SetArticleSeconds(theDlg.m_nSeconds);
m_pApp->Serialize(TRUE);
}
return;
}
void CNewsgroupsManager::OnUpdateGroupRemove(CCmdUI* pCmdUI)
{
// Enable this command only if the list box has more than 0 items
// and one of the items is selected.
pCmdUI->Enable((m_pDoc->m_strGroupsArray.GetSize() > 0) &&
(m_ctlGroupList.GetCurSel() >= 0));
}
void CNewsgroupsManager::OnGroupOpen()
{
if (!m_pApp->IsOnline())
{
AfxMessageBox(IDP_INETNAV_SIGN_ON, MB_ICONSTOP|MB_OK);
return;
}
if (!UpdateData(TRUE))
{
AfxMessageBox(AFX_IDP_INTERNAL_FAILURE, MB_ICONSTOP|MB_OK);
return;
}
// Open a window which will have the same title as the name of the
// selected group, plus a list of the group's articles
if (!m_pDoc->IsSocketAvailable())
{
AfxMessageBox(IDP_CONNECTION_BUSY,
MB_ICONASTERISK|MB_OK);
return;
}
int nIndex = m_ctlGroupList.GetCurSel();
if (nIndex < 0)
{
// User hasn't selected a group -- use the first one.
m_ctlGroupList.SetCurSel(0);
nIndex = 0;
UpdateData(TRUE);
}
CString strText = "Opening " + m_strSelection + "... Please wait.";
m_pStatusBar->SetText(strText);
CArticleSelectionWnd* pFrame =
(CArticleSelectionWnd*)m_pApp->GetNewsgroup()->CreateNewFrame(m_pDoc, NULL);
if (pFrame == NULL)
{
MessageBeep(-1);
AfxMessageBox(IDP_FAILED_OPEN_WINDOW, MB_ICONSTOP|MB_OK);
return;
}
m_pStatusBar->ShowIdleMessage();
pFrame->m_strGroup = m_strSelection;
m_pApp->GetNewsgroup()->InitialUpdateFrame(pFrame, m_pDoc, TRUE);
pFrame->ActivateFrame(SW_RESTORE);
return;
}
void CNewsgroupsManager::OnUpdateGroupOpen(CCmdUI* pCmdUI)
{
// Enable this command only if the list box has more than 0 items
// and one of the items is selected.
pCmdUI->Enable((m_pDoc->m_strGroupsArray.GetSize() > 0) &&
(m_ctlGroupList.GetCurSel() >= 0) &&
m_pApp->IsOnline());
}
void CNewsgroupsManager::OnListOutOfSpace()
{
// Tell the user there's not enough space left in the listbox for any
// more group names
AfxMessageBox("Can't add more newsgroup names, no space left in listbox.",
MB_ICONSTOP|MB_OK, AFX_IDP_FAILED_MEMORY_ALLOC);
return;
}
/////////////////////////////////////////////////////////////////////////////
// CArticleSelectionView
IMPLEMENT_DYNCREATE(CArticleSelectionView, CFormView)
BEGIN_MESSAGE_MAP(CArticleSelectionView, CFormView)
//{{AFX_MSG_MAP(CArticleSelectionView)
ON_COMMAND(ID_WINDOW_ARTICLE_REFRESH, OnWindowRefresh)
ON_COMMAND(ID_ARTICLE_OPEN, OnArticleOpen)
ON_UPDATE_COMMAND_UI(ID_ARTICLE_OPEN, OnUpdateArticleOpen)
ON_COMMAND(ID_ARTICLE_AGE, OnArticleAge)
ON_BN_CLICKED(IDC_WINDOW_REFRESH, OnWindowRefresh)
ON_LBN_DBLCLK(IDC_ARTICLES_LIST, OnArticleOpen)
ON_BN_CLICKED(ID_ARTICLE_ADD, OnArticleAdd)
//}}AFX_MSG_MAP
ON_COMMAND(ID_HELP, CWnd::OnHelp)
ON_COMMAND(ID_ARTICLE_ADD, OnArticleAdd)
// Idle Button Update
ON_MESSAGE(WM_IDLEUPDATECMDUI, OnIdleUpdateCmdUI)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CArticleSelectionView construction/destruction
CArticleSelectionView::CArticleSelectionView()
: CFormView(CArticleSelectionView::IDD)
{
//{{AFX_DATA_INIT(CArticleSelectionView)
m_strSelection = "";
m_strGroupLabel = "";
//}}AFX_DATA_INIT
m_pPercentDialog = NULL;
m_pDoc = NULL;
m_pApp = (CInternetNavApp*)AfxGetApp();
m_pStatusBar = m_pApp->GetMainFrame()->GetStatusBar();
}
CArticleSelectionView::~CArticleSelectionView()
{
// If necessary, delete the percent gauge dialog box
if (m_pPercentDialog && IsWindow(m_pPercentDialog->GetSafeHwnd()))
{
m_pPercentDialog->ShowWindow(SW_HIDE);
m_pPercentDialog->UpdateWindow();
m_pPercentDialog->DestroyWindow();
}
}
void CArticleSelectionView::DoDataExchange(CDataExchange* pDX)
{
CFormView::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CArticleSelectionView)
DDX_Control(pDX, IDC_ARTICLES_LIST, m_ctlArticleList);
DDX_LBString(pDX, IDC_ARTICLES_LIST, m_strSelection);
DDX_Text(pDX, IDC_ARTICLES_LABEL, m_strGroupLabel);
//}}AFX_DATA_MAP
if (pDX->m_bSaveAndValidate)
UpdateData(FALSE);
}
/////////////////////////////////////////////////////////////////////////////
// CArticleSelectionView update
void CArticleSelectionView::OnInitialUpdate()
{
m_pDoc = GetDocument();
m_strGroup = ((CArticleSelectionWnd*)GetParentFrame())->m_strGroup;
((CArticleSelectionWnd*)GetParentFrame())->OnUpdateFrameTitle(TRUE);
// Set the title of this window to be the group name
GetParentFrame()->SetWindowText(m_strGroup);
m_strGroupLabel = "&Articles in " + m_strGroup + ":";
CFormView::OnInitialUpdate();
if (m_pApp->IsUseCTL3D())
Ctl3dSubclassDlgEx(m_hWnd, CTL3D_ALL);
m_ctlArticleList.SetTabStops(160); // dialog units
m_ctlArticleList.SetHorizontalExtent(LOWORD(GetDialogBaseUnits())*80);
DoFillListBox();
return;
}
void CArticleSelectionView::OnUpdate(CView*, LPARAM, CObject*)
{
if (!UpdateData(FALSE))
AfxMessageBox(AFX_IDP_INTERNAL_FAILURE, MB_ICONSTOP|MB_OK);
return;
}
/////////////////////////////////////////////////////////////////////////////
// CArticleSelectionView operations
void CArticleSelectionView::DoFillListBox()
{
CWaitCursor wait;
QSocket* pSocket = m_pDoc->GetSocket();
CString strResponse = "";
int nLength;
if (pSocket == NULL)
{
// Socket is busy
MessageBeep(-1);
AfxMessageBox(IDP_CONNECTION_BUSY,
MB_ICONINFORMATION|MB_OK);
return;
}
// make sure the newsgroups server knows which group we're interested
// in
m_pStatusBar->SetText(IDS_REQUESTING_ATTENTION);
pSocket->SetReceiveTarget(NULL, 0);
CString strText = "Please wait while we attempt to open the ";
strText += "selected group on the server.";
m_pStatusBar->SetText(strText);
// send the GROUP command
pSocket->Send("GROUP " + m_strGroup + "\r\n");
m_pStatusBar->SetText(IDS_WAITING_RESPONSE);
strResponse = pSocket->GetLine();
#ifdef _DEBUG
afxDump << strResponse;
#endif
int nArticles, nMaxArticles;
int nResponseCode = atoi(strResponse.Left(3));
if (nResponseCode == 500)
{
// the news server doesn't understand or implement the
// GROUP command; that's OK, we can still handle it
nMaxArticles = 0;
}
else if (nResponseCode != 211)
{
// invalid group -- stop right here
m_pStatusBar->ShowIdleMessage();
m_pDoc->DisplayNNTPError(nResponseCode);
MessageBeep(-1);
AfxMessageBox(IDP_NEWSGROUP_INVALID, MB_ICONSTOP);
// Release the connection we have with the server back to the
// area
m_pDoc->ReleaseSocket();
return;
}
else
{
// valid group -- get number of articles
// Chop off '211 '
strResponse = strResponse.Right(strResponse.GetLength() - 4);
// Get the first number right after the '211 ' -- according to
// the RFC, this should be the number of articles in this group
int nSpace = strResponse.Find(' ');
strResponse = strResponse.Left(nSpace);
nArticles = atoi(strResponse);
}
if (nArticles == 0)
{
MessageBeep(-1);
AfxMessageBox(IDP_NEWSGROUP_EMPTY, MB_ICONSTOP);
m_pStatusBar->ShowIdleMessage();
m_pDoc->ReleaseSocket();
return;
}
if (nArticles < 100 && nMaxArticles == 0)
{
nMaxArticles = 0;
nArticles = 0;
}
else if (nArticles < 100)
{
nMaxArticles = nArticles;
}
else if (nArticles >= 100)
{
nMaxArticles = 100;
}
m_pStatusBar->ShowIdleMessage();
m_pStatusBar->SetText("Clearing old article lists... Please wait.");
m_pDoc->DeleteArrays();
m_pStatusBar->ShowIdleMessage();
m_pStatusBar->SetText(IDS_REQUESTING_ATTENTION);
CTime curTime = CTime::GetCurrentTime() -
CTimeSpan(m_pApp->GetArticleDays(),
m_pApp->GetArticleHours(),
m_pApp->GetArticleMinutes(),
m_pApp->GetArticleSeconds());
CString strCommand = "";
strCommand= "NEWNEWS ";
strCommand += m_strGroup;
strCommand += " ";
strCommand += curTime.Format("%y%m%d %H%M%S");
strCommand += "\r\n";
CString strMessageID = "";
m_pApp->OnIdle(0);
m_pApp->OnIdle(1);
m_pStatusBar->SetText(IDS_TALKING_TO_SERVER);
pSocket->Send(strCommand);
m_pStatusBar->SetText(IDS_WAITING_RESPONSE);
strResponse = pSocket->GetLine();
#ifdef _DEBUG
afxDump << strResponse;
#endif
strText = "Article request has been received and acknowledged.";
m_pStatusBar->SetText(strText);
nResponseCode = atoi(strResponse.Left(3));
if (nResponseCode == 230)
{
strText = "Now receiving information on new articles in ";
strText += m_strGroup + "... Please wait.";
m_pStatusBar->SetText(strText);
int nMessageIDs = 0;
// message IDs follow
char chText[30];
m_pDoc->DeleteArrays();
if (nArticles > 0 && nMaxArticles > 0)
{
for (int i = 1;((strResponse = pSocket->GetLine()) != ".\r\n") &&
(pSocket->IsConnected()) && i <= nMaxArticles;i++)
{
/*wait.Restore();*/
nLength = strResponse.GetLength();
if (nLength >= 2
&& strResponse[nLength-2] == '\r'
&& strResponse[nLength-1] == '\n')
{
strMessageID = strResponse.Left(nLength-2);
m_pDoc->m_strMessageIDs.Add(strMessageID);
#ifdef _DEBUG
afxDump << strMessageID << "\r\n";
#endif
strMessageID.Empty();
nMessageIDs = m_pDoc->m_strMessageIDs.GetSize();
// pump waiting Windows messages
for (;;)
{
MSG msg;
/*wait.Restore();*/
if (::PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
if (!m_pApp->PreTranslateMessage(&msg))
{
::TranslateMessage(&msg);
::DispatchMessage(&msg);
}
m_pApp->OnIdle(0);
m_pApp->OnIdle(1);
}
else
{
// to correctly handle idle processing, call
// CWinApp::OnIdle()
m_pApp->OnIdle(0); // update UI
m_pApp->OnIdle(1); // delete temp objects
break; // no more messages to pump
}
}
}
}
}
else
{
for (int i = 1;((strResponse = pSocket->GetLine()) != ".\r\n")
&& pSocket->IsConnected();i++)
{
/*wait.Restore();*/
nLength = strResponse.GetLength();
if (nLength >= 2
&& strResponse[nLength-2] == '\r'
&& strResponse[nLength-1] == '\n')
{
strMessageID = strResponse.Left(nLength-2);
m_pDoc->m_strMessageIDs.Add(strMessageID);
#ifdef _DEBUG
afxDump << strMessageID << "\r\n";
#endif
strMessageID.Empty();
nMessageIDs = m_pDoc->m_strMessageIDs.GetSize();
// pump waiting Windows messages
for (;;)
{
MSG msg;
/*wait.Restore();*/
if (::PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
if (!m_pApp->PreTranslateMessage(&msg))
{
::TranslateMessage(&msg);
::DispatchMessage(&msg);
}
m_pApp->OnIdle(0);
m_pApp->OnIdle(1);
}
else
{
// to correctly handle idle processing, call
// CWinApp::OnIdle()
m_pApp->OnIdle(0); // update UI
m_pApp->OnIdle(1); // delete temp objects
break; // no more messages to pump
}
}
}
}
}
if (m_pDoc->m_strMessageIDs.GetSize() == 0)
{
MessageBeep(-1);
AfxMessageBox(IDP_NEWSGROUP_EMPTY, MB_ICONSTOP|MB_OK);
if (!m_pDoc->IsSocketAvailable())
m_pDoc->ReleaseSocket();
return;
}
m_pStatusBar->ShowIdleMessage();
}
else
{
m_pDoc->DisplayNNTPError(nResponseCode);
m_pStatusBar->ShowIdleMessage();
m_pDoc->ReleaseSocket();
return;
}
CString strLine = "", strSubject = "";
CString strFrom = "", strTitle = "", text = "";
m_pPercentDialog = new CPercentDialog(AfxGetMainWnd());
strTitle = "Article Retrieval Progress";
text = "Please wait while we retrieve and process the headers for ";
text += "the articles of " + m_strGroup + ".\r\n";
text += "Thank you for your patience!";
m_pPercentDialog->Initialize(strTitle, text);
m_pPercentDialog->ShowWindow(SW_SHOW);
m_pPercentDialog->UpdateWindow();
text.Empty();
text = "Receiving and processing headers... Please wait.";
m_pStatusBar->SetText(text);
BOOL bIncremI = FALSE;
int iSav = 0;
for (int i = 0; i < m_pDoc->m_strMessageIDs.GetSize(); i++)
{
if (bIncremI)
{
i = iSav;
bIncremI = FALSE;
}
/*wait.Restore();*/
// build the string to send -- the HEAD command
strCommand = "HEAD ";
strCommand += m_pDoc->m_strMessageIDs[i];
strCommand += "\r\n";
m_pPercentDialog->CalculatePercent(i + 1, m_pDoc->m_strMessageIDs.GetSize());
m_pPercentDialog->UpdateWindow();
pSocket->Send(strCommand);
strResponse = pSocket->GetLine();
#ifdef _DEBUG
afxDump << strResponse;
#endif //_DEBUG
nResponseCode = atoi(strResponse.Left(3));
if (nResponseCode == 221)
{
strSubject = "";
strFrom = "";
while ( (strResponse = pSocket->GetLine()) != ".\r\n"
&& pSocket->IsConnected())
{
strText = "Receiving and processing headers... ";
strText += "Please wait.";
m_pStatusBar->SetText(strText);
/*wait.Restore();*/
nLength = strResponse.GetLength();
if (strResponse.Left(9) == "Subject: ")
{
strSubject = strResponse.Right(nLength - 9);
nLength = strSubject.GetLength();
if (nLength >= 2
&& strSubject[nLength-2] == '\r'
&& strSubject[nLength-1] == '\n')
{
strSubject = strSubject.Left(nLength-2);