DlgEventLog.cpp 34.8 KB
Newer Older
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
// This file is part of BOINC.
// http://boinc.berkeley.edu
// Copyright (C) 2008 University of California
//
// BOINC is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License
// as published by the Free Software Foundation,
// either version 3 of the License, or (at your option) any later version.
//
// BOINC 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 Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with BOINC.  If not, see <http://www.gnu.org/licenses/>.

#if defined(__GNUG__) && !defined(__APPLE__)
#pragma implementation "DlgEventLog.h"
#endif

#include "stdwx.h"
#include "common_defs.h"
#include "diagnostics.h"
#include "str_util.h"
#include "mfile.h"
#include "miofile.h"
#include "parse.h"
#include "error_numbers.h"
#include "Events.h"
#include "BOINCGUIApp.h"
#include "SkinManager.h"
#include "MainDocument.h"
#include "BOINCBaseFrame.h"
#include "version.h"
#include "DlgEventLogListCtrl.h"
#include "DlgEventLog.h"
#include "AdvancedFrame.h"
39
#include "DlgDiagnosticLogFlags.h"
40

41
42
43
#ifdef __WXMAC__
#include <time.h>
#endif
44
45
46
47
48
49
50

////@begin includes
////@end includes

////@begin XPM images
////@end XPM images

51
52
53
54
#define DLGEVENTLOG_INITIAL_WIDTH ADJUSTFORXDPI(640)
#define DLGEVENTLOG_INITIAL_HEIGHT ADJUSTFORYDPI(480)
#define DLGEVENTLOG_MIN_WIDTH ADJUSTFORXDPI(600)
#define DLGEVENTLOG_MIN_HEIGHT ADJUSTFORYDPI(250)
55
56
57
58
59
60
61

#define COLUMN_PROJECT              0
#define COLUMN_TIME                 1
#define COLUMN_MESSAGE              2


static bool s_bIsFiltered = false;
62
static bool s_bFilteringChanged = false;
63
64
65
66
67
68
static std::string s_strFilteredProjectName;

/*!
 * CDlgEventLog type definition
 */

69
IMPLEMENT_DYNAMIC_CLASS( CDlgEventLog, DlgEventLogBase )
70
71
72
73
74

/*!
 * CDlgEventLog event table definition
 */

75
BEGIN_EVENT_TABLE( CDlgEventLog, DlgEventLogBase )
76
////@begin CDlgEventLog event table entries
77
    EVT_ACTIVATE(CDlgEventLog::OnActivate)
78
79
80
81
82
83
    EVT_HELP(wxID_ANY, CDlgEventLog::OnHelp)
    EVT_BUTTON(wxID_OK, CDlgEventLog::OnOK)
    EVT_BUTTON(ID_COPYAll, CDlgEventLog::OnMessagesCopyAll)
    EVT_BUTTON(ID_COPYSELECTED, CDlgEventLog::OnMessagesCopySelected)
    EVT_BUTTON(ID_TASK_MESSAGES_FILTERBYPROJECT, CDlgEventLog::OnMessagesFilter)
    EVT_BUTTON(ID_SIMPLE_HELP, CDlgEventLog::OnButtonHelp)
84
	EVT_MENU(ID_SGDIAGNOSTICLOGFLAGS, CDlgEventLog::OnDiagnosticLogFlags)
85
86
87
	EVT_SIZE(CDlgEventLog::OnSize)
    EVT_MOVE(CDlgEventLog::OnMove)
    EVT_CLOSE(CDlgEventLog::OnClose)
88
    EVT_LIST_COL_END_DRAG(ID_SIMPLE_MESSAGESVIEW, CDlgEventLog::OnColResize)
89
90
91
92
93
94
95
96
97
98
99
100
101
////@end CDlgEventLog event table entries
END_EVENT_TABLE()

/*!
 * CDlgEventLog constructors
 */

CDlgEventLog::CDlgEventLog( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
{
    wxLogTrace(wxT("Function Start/End"), wxT("CDlgEventLog::CDlgEventLog - Constructor Function Begin"));

    Create(parent, id, caption, pos, size, style);

102
103
104
105
106
#ifdef __WXGTK__
    m_pList->SaveEventHandler((m_pList->GetMainWin())->GetEventHandler());
    (m_pList->GetMainWin())->PushEventHandler(new MyEvtLogEvtHandler(m_pList));
#endif

107
108
109
110
111
112
    wxLogTrace(wxT("Function Start/End"), wxT("CDlgEventLog::CDlgEventLog - Constructor Function End"));
}


CDlgEventLog::~CDlgEventLog() {
    wxLogTrace(wxT("Function Start/End"), wxT("CDlgEventLog::CDlgEventLog - Destructor Function Begin"));
113
 
114
115
#ifdef __WXGTK__
    (m_pList->GetMainWin())->PopEventHandler(true);
116
117
#endif

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
    if (m_pMessageInfoAttr) {
        delete m_pMessageInfoAttr;
        m_pMessageInfoAttr = NULL;
    }

    if (m_pMessageErrorAttr) {
        delete m_pMessageErrorAttr;
        m_pMessageErrorAttr = NULL;
    }

    if (m_pMessageInfoGrayAttr) {
        delete m_pMessageInfoGrayAttr;
        m_pMessageInfoGrayAttr = NULL;
    }

    if (m_pMessageErrorGrayAttr) {
        delete m_pMessageErrorGrayAttr;
        m_pMessageErrorGrayAttr = NULL;
    }

    m_iFilteredIndexes.Clear();

    wxGetApp().OnEventLogClose();

    wxLogTrace(wxT("Function Start/End"), wxT("CDlgEventLog::CDlgEventLog - Destructor Function End"));
}


/*!
 * CDlgEventLog creator
 */

bool CDlgEventLog::Create( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
{
////@begin CDlgEventLog member initialisation
153
154
155
156
    CMainDocument* pDoc     = wxGetApp().GetDocument();
    wxASSERT(pDoc);
    wxASSERT(wxDynamicCast(pDoc, CMainDocument));
    
157
158
    m_iPreviousRowCount = 0;
    m_iTotalDocCount = 0;
159
    m_iPreviousFirstMsgSeqNum = pDoc->GetFirstMsgSeqNum();
160
    m_iPreviousLastMsgSeqNum = m_iPreviousFirstMsgSeqNum - 1;
161

162
    m_iNumDeletedFilteredRows = 0;
163
    m_iTotalDeletedFilterRows = 0;
164
    
165
166
167
168
169
    if (!s_bIsFiltered) {
        s_strFilteredProjectName.clear();
    }
    m_iFilteredIndexes.Clear();
	m_bProcessingRefreshEvent = false;
170
    m_bWasConnected = false;
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
    m_bEventLogIsOpen = true;
////@end CDlgEventLog member initialisation

    CSkinAdvanced* pSkinAdvanced = wxGetApp().GetSkinManager()->GetAdvanced();
    wxPoint oTempPoint;
    wxSize  oTempSize;

    wxASSERT(pSkinAdvanced);
    wxASSERT(wxDynamicCast(pSkinAdvanced, CSkinAdvanced));

    if ((pos == wxDefaultPosition) && (size == wxDefaultSize)) {
        // Get size and position from the previous configuration
        GetWindowDimensions( oTempPoint, oTempSize );

#ifdef __WXMSW__
186
        // Get the current display space for the current window
187
		int iDisplay = wxNOT_FOUND;
188
189
190
191
		if ( wxGetApp().GetFrame() != NULL )
            iDisplay = wxDisplay::GetFromWindow(wxGetApp().GetFrame());
		if ( iDisplay == wxNOT_FOUND )
            iDisplay = 0;
192
        wxDisplay *display = new wxDisplay(iDisplay);
193
        wxRect rDisplay = display->GetClientArea();
194
195
196

		// Check that the saved height and width is not larger than the displayable space.
		// If it is, then reduce the size.
197
198
199
200
201
        if ( oTempSize.GetWidth() > rDisplay.width ) oTempSize.SetWidth(rDisplay.width);
        if ( oTempSize.GetHeight() > rDisplay.height ) oTempSize.SetHeight(rDisplay.height);

        // Check if part of the display was going to be off the screen, if so, center the 
        // display on that axis
202
203
204
205
		if ( oTempPoint.x < rDisplay.x ) {
			oTempPoint.x = rDisplay.x;
		} else if ( oTempPoint.x + oTempSize.GetWidth() > rDisplay.x + rDisplay.width ) {
			oTempPoint.x = rDisplay.x + rDisplay.width - oTempSize.GetWidth();
206
207
		}

208
209
210
211
		if ( oTempPoint.y < rDisplay.y ) {
			oTempPoint.y = rDisplay.y;
		} else if ( oTempPoint.y + oTempSize.GetHeight() > rDisplay.y + rDisplay.height ) {
			oTempPoint.y = rDisplay.y + rDisplay.height - oTempSize.GetHeight();
212
213
		}

214
        delete display;
215
216
217
218
219
220
221
222
223
224
225
226
227
#endif
#ifdef __WXMAC__
        // If the user has changed the arrangement of multiple 
        // displays, make sure the window title bar is still on-screen.
    if (!IsWindowOnScreen(oTempPoint.x, oTempPoint.y, oTempSize.GetWidth(), oTempSize.GetHeight())) {
        oTempPoint.y = oTempPoint.x = 30;
    }
#endif  // ! __WXMAC__
    } else {
        oTempPoint = pos;
        oTempSize = size;
    }

228
    DlgEventLogBase::Create( parent, id, caption, oTempPoint, oTempSize, style );
229

230
    SetSizeHints(DLGEVENTLOG_MIN_WIDTH, DLGEVENTLOG_MIN_HEIGHT);
231
232
233
234
235
236
237
238
239
240
    SetExtraStyle(GetExtraStyle()|wxWS_EX_BLOCK_EVENTS);

    // Initialize Application Title
    wxString strCaption = caption;
    if (strCaption.IsEmpty()) {
        strCaption.Printf(_("%s - Event Log"), pSkinAdvanced->GetApplicationName().c_str());
    }
    SetTitle(strCaption);

    // Initialize Application Icon
241
    SetIcons(*pSkinAdvanced->GetApplicationIcon());
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

    CreateControls();

	// Create List Pane Items
    m_pList->InsertColumn(COLUMN_PROJECT, _("Project"), wxLIST_FORMAT_LEFT, 109);
    m_pList->InsertColumn(COLUMN_TIME, _("Time"), wxLIST_FORMAT_LEFT, 130);
    m_pList->InsertColumn(COLUMN_MESSAGE, _("Message"), wxLIST_FORMAT_LEFT, 378);

    m_pMessageInfoAttr = new wxListItemAttr(
        wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT),
        wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW),
        wxNullFont
    );
    m_pMessageErrorAttr = new wxListItemAttr(
        *wxRED,
        wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW),
        wxNullFont
    );
#if EVENT_LOG_STRIPES
    m_pMessageInfoGrayAttr = new wxListItemAttr(
        wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT),
        wxColour(240, 240, 240),
        wxNullFont
    );
    m_pMessageErrorGrayAttr = new wxListItemAttr(*wxRED, wxColour(240, 240, 240), wxNullFont);
#else
    m_pMessageInfoGrayAttr = new wxListItemAttr(*m_pMessageInfoAttr);
    m_pMessageErrorGrayAttr = new wxListItemAttr(*m_pMessageErrorAttr);
#endif

    SetTextColor();
    RestoreState();
274
    OnRefresh();
275
276
    // Register that we had the Event Log open immediately
    SaveState();
277
    
278
    m_Shortcuts[0].Set(wxACCEL_CTRL|wxACCEL_SHIFT, (int)'F', ID_SGDIAGNOSTICLOGFLAGS);
279
280
281
282
    m_pAccelTable = new wxAcceleratorTable(1, m_Shortcuts);

    SetAcceleratorTable(*m_pAccelTable);

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
    return true;
}


/*!
 * Control creation for CDlgEventLog
 */

void CDlgEventLog::CreateControls()
{
    wxFlexGridSizer* itemFlexGridSizer2 = new wxFlexGridSizer(2, 1, 0, 0);
    itemFlexGridSizer2->AddGrowableRow(0);
    itemFlexGridSizer2->AddGrowableCol(0);
    SetSizer(itemFlexGridSizer2);

    m_pList = new CDlgEventLogListCtrl(this, ID_SIMPLE_MESSAGESVIEW, EVENT_LOG_DEFAULT_LIST_MULTI_SEL_FLAGS);
    itemFlexGridSizer2->Add(m_pList, 0, wxGROW|wxALL, 5);

    wxBoxSizer* itemBoxSizer4 = new wxBoxSizer(wxHORIZONTAL);
    
    itemFlexGridSizer2->Add(itemBoxSizer4, 0, wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL|wxALL, 12);

    m_pFilterButton = new wxButton(this, ID_TASK_MESSAGES_FILTERBYPROJECT, _("&Show only this project"),  wxDefaultPosition, wxDefaultSize);
    itemBoxSizer4->Add(m_pFilterButton, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);

#ifdef wxUSE_CLIPBOARD
    wxButton* itemButton1 = new wxButton(this, ID_COPYAll, _("Copy &All"), wxDefaultPosition, wxDefaultSize );
    itemButton1->SetHelpText(
        _("Copy all the messages to the clipboard.")
    );
#if wxUSE_TOOLTIPS
    itemButton1->SetToolTip(
        _("Copy all the messages to the clipboard.")
    );
#endif
    itemBoxSizer4->Add(itemButton1, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);

    m_pCopySelectedButton = new wxButton(this, ID_COPYSELECTED, _("Copy &Selected"),  wxDefaultPosition, wxDefaultSize );
    m_pCopySelectedButton->SetHelpText(
#ifdef __WXMAC__
        _("Copy the selected messages to the clipboard. You can select multiple messages by holding down the shift or command key while clicking on messages.")
#else
        _("Copy the selected messages to the clipboard. You can select multiple messages by holding down the shift or control key while clicking on messages.")
#endif
    );
#if wxUSE_TOOLTIPS
    m_pCopySelectedButton->SetToolTip(
#ifdef __WXMAC__
        _("Copy the selected messages to the clipboard. You can select multiple messages by holding down the shift or command key while clicking on messages.")
#else
        _("Copy the selected messages to the clipboard. You can select multiple messages by holding down the shift or control key while clicking on messages.")
#endif
    );
#endif
    itemBoxSizer4->Add(m_pCopySelectedButton, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
#endif

    wxButton* itemButton44 = new wxButton(this, wxID_OK, _("&Close"),  wxDefaultPosition, wxDefaultSize);
    itemBoxSizer4->Add(itemButton44, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);

    SetFilterButtonText(); 
}


void CDlgEventLog::SetFilterButtonText() {
    if (s_bIsFiltered) {
        m_pFilterButton->SetLabel( _("Show all &messages") );
        m_pFilterButton->SetHelpText( _("Show messages for all projects") );
#ifdef wxUSE_TOOLTIPS
        m_pFilterButton->SetToolTip(_("Show messages for all projects"));
#endif
    } else {
        m_pFilterButton->SetLabel( _("&Show only this project") );
        m_pFilterButton->SetHelpText( _("Show only the messages for the selected project") );
#ifdef wxUSE_TOOLTIPS
        m_pFilterButton->SetToolTip(_("Show only the messages for the selected project"));
#endif
    }
    // Adjust button size for new text
    Layout();
}


/*!
 * Text color selection for CDlgEventLog
 */

void CDlgEventLog::SetTextColor() {
    bool isConnected = wxGetApp().GetDocument()->IsConnected();

    if (isConnected) {
        m_pMessageInfoAttr->SetTextColour(*wxBLACK);
        m_pMessageErrorAttr->SetTextColour(*wxRED);
        m_pMessageInfoGrayAttr->SetTextColour(*wxBLACK);
        m_pMessageErrorGrayAttr->SetTextColour(*wxRED);
    } else {
        wxColourDatabase colorBase;
        m_pMessageInfoAttr->SetTextColour(wxColour(128, 128, 128));
        m_pMessageErrorAttr->SetTextColour(wxColour(255, 128, 128));
        m_pMessageInfoGrayAttr->SetTextColour(wxColour(128, 128, 128));
        m_pMessageErrorGrayAttr->SetTextColour(wxColour(255, 128, 128));
    }
}


388
389
390
391
392
393
394
395
396
397
/*!
 * wxEVT_ACTIVATE event handler for ID_DLGMESSAGES
 */

void CDlgEventLog::OnActivate(wxActivateEvent& event) {
    bool isActive = event.GetActive();
    if (isActive) wxGetApp().SetEventLogWasActive(true);
    event.Skip();
}

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
/*!
 * wxEVT_HELP event handler for ID_DLGMESSAGES
 */

void CDlgEventLog::OnHelp(wxHelpEvent& event) {
    wxLogTrace(wxT("Function Start/End"), wxT("CDlgEventLog::OnHelp - Function Begin"));

    if (IsShown()) {
        wxString strURL = wxGetApp().GetSkinManager()->GetAdvanced()->GetOrganizationHelpUrl();

        wxString wxurl;
		wxurl.Printf(
            wxT("%s?target=simple_messages&version=%s&controlid=%d"),
            strURL.c_str(),
            wxString(BOINC_VERSION_STRING, wxConvUTF8).c_str(),
            event.GetId()
        );
        wxLaunchDefaultBrowser(wxurl);
    }

    wxLogTrace(wxT("Function Start/End"), wxT("CDlgEventLog::OnHelp - Function End"));
}


/*!
 * wxEVT_COMMAND_BUTTON_CLICKED event handler for wxID_OK
 */

void CDlgEventLog::OnOK( wxCommandEvent& WXUNUSED(event) ) {
427
428
429
    SaveState();
    SetWindowDimensions();

430
431
432
433
434
435
436
437
438
439
    Close();
}


/*!
 * wxEVT_CLOSE event handler for CDlgEventLog (window close control clicked)
 */

void CDlgEventLog::OnClose(wxCloseEvent& WXUNUSED(event)) {
    m_bEventLogIsOpen = false;  // User specifically closed window
440
441
442
443

    SaveState();
    SetWindowDimensions();

444
445
446
447
448
449
450
451
452
453
454
455
456
457
    Destroy();
}


void CDlgEventLog::OnMessagesFilter( wxCommandEvent& WXUNUSED(event) ) {
    wxLogTrace(wxT("Function Start/End"), wxT("CDlgEventLog::OnMessagesFilter - Function Begin"));

    wxInt32 iIndex = -1;
    MESSAGE* message;
    
    wxASSERT(m_pList);

    m_iFilteredIndexes.Clear();
    s_strFilteredProjectName.clear();
458
    m_iTotalDeletedFilterRows = 0;
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481

    if (s_bIsFiltered) {
        s_bIsFiltered = false;
        m_iFilteredDocCount = m_iTotalDocCount;
    } else {
        iIndex = m_pList->GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
        if (iIndex >= 0) {
             message = wxGetApp().GetDocument()->message(iIndex);
             if ((message->project).size() > 0) {
                s_strFilteredProjectName = message->project;
                s_bIsFiltered = true;
                for (iIndex = 0; iIndex < m_iTotalDocCount; iIndex++) {
                    message = wxGetApp().GetDocument()->message(iIndex);
                    if (message->project.empty() || (message->project == s_strFilteredProjectName)) {
                        m_iFilteredIndexes.Add(iIndex);
                    }

                }
                m_iFilteredDocCount = (int)(m_iFilteredIndexes.GetCount());
           }
        }
    }
    
482
    s_bFilteringChanged = true;
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
    SetFilterButtonText();
    
    // Force a complete update
    m_iPreviousRowCount = 0;
    m_pList->DeleteAllItems();
    m_pList->SetItemCount(m_iFilteredDocCount);
    OnRefresh();

    wxLogTrace(wxT("Function Start/End"), wxT("CDlgEventLog::OnMessagesFilter - Function End"));
}


wxInt32 CDlgEventLog::GetFilteredMessageIndex( wxInt32 iRow) const {
    if (s_bIsFiltered) return m_iFilteredIndexes[iRow];
    return iRow;
}


501
502
503
504
505
506
// NOTE: this function is designed to be called only
// from CDlgEventLog::OnRefresh().  If you need to call it
// from other routines, it will need modification.
//
// Get the (possibly filtered) item count (i.e., the Row count) and
// make any needed adjustments if oldest items have been deleted.
507
wxInt32 CDlgEventLog::GetDocCount() {
508
509
510
511
    int i, j, numDeletedRows;
    CMainDocument* pDoc     = wxGetApp().GetDocument();
    wxASSERT(pDoc);
    wxASSERT(wxDynamicCast(pDoc, CMainDocument));
512
    
513
514
515
    m_iTotalDocCount = pDoc->GetMessageCount();

    numDeletedRows = pDoc->GetFirstMsgSeqNum() - m_iPreviousFirstMsgSeqNum;
516
517
518
    if ((numDeletedRows < 0) || (m_iPreviousFirstMsgSeqNum < 0)) {
        numDeletedRows = 0;
    }
519
    m_iNumDeletedFilteredRows = 0;
520

521
    if (s_bIsFiltered) {
522
523
524
525
526
        if (numDeletedRows > 0) {
            // Remove any deleted messages from our filtered list
            while (m_iFilteredIndexes.GetCount() > 0) {
                if (m_iFilteredIndexes[0] >= numDeletedRows) break;
                m_iFilteredIndexes.RemoveAt(0);
527
                m_iNumDeletedFilteredRows++;
528
                m_iTotalDeletedFilterRows++;
529
530
531
532
533
534
535
536
537
538
            }
            
            // Adjust the remaining indexes
            for (i = m_iFilteredIndexes.GetCount()-1; i >= 0; i--) {
                m_iFilteredIndexes[i] -= numDeletedRows;
            }
        }
        
        // Add indexes of new messages to filtered list as appropriate
        i = m_iTotalDocCount - (pDoc->GetLastMsgSeqNum() - m_iPreviousLastMsgSeqNum);
539
        if (i < 0) i = 0;
540
        for (; i < m_iTotalDocCount; i++) {
541
            MESSAGE* message = pDoc->message(i);
542
543
544
545
546
            if (message->project.empty() || (message->project == s_strFilteredProjectName)) {
                m_iFilteredIndexes.Add(i);
            }
        }
        m_iFilteredDocCount = (int)(m_iFilteredIndexes.GetCount());
547
548
    } else {
        m_iFilteredDocCount = m_iTotalDocCount;
549
        m_iNumDeletedFilteredRows = numDeletedRows;
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
    }

    if (numDeletedRows > 0) {
        // Adjust the selected row numbers
        wxArrayInt arrSelRows;
        
        i = -1;
        for (;;) {
            i = m_pList->GetNextItem(i, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
            if (i < 0) break;
            arrSelRows.Add(i);
        }
        int count = arrSelRows.Count();
        for (i=0; i<count; i++) {
            m_pList->SetItemState(arrSelRows[i], 0, wxLIST_STATE_SELECTED);
        }

        for (i=0; i<count; i++) {
568
            if ((j = arrSelRows[i] - m_iNumDeletedFilteredRows) >= 0) {
569
570
571
                m_pList->SetItemState(j, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
            }
        }
572
    }
573
574
    
    return s_bIsFiltered ? m_iFilteredDocCount : m_iTotalDocCount;
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
}


/*!
 * called from CMainDocument::HandleCompletedRPC() after wxEVT_RPC_FINISHED event
 */
void CDlgEventLog::OnRefresh() {
    bool isConnected;
    static wxString strLastMachineName = wxEmptyString;
    wxString strNewMachineName = wxEmptyString;
    CMainDocument* pDoc     = wxGetApp().GetDocument();
    wxASSERT(pDoc);
    wxASSERT(wxDynamicCast(pDoc, CMainDocument));
    
    if (!IsShown()) return;

    if (!m_bProcessingRefreshEvent) {
        m_bProcessingRefreshEvent = true;
        wxASSERT(m_pList);

        wxInt32 iRowCount = GetDocCount();
596
597
        long topItem = m_pList->GetTopItem();
        
598
599
600
        if (0 >= iRowCount) {
            m_pList->DeleteAllItems();
            ResetMessageFiltering();
601
602
            m_iPreviousFirstMsgSeqNum = 0;
            m_iPreviousLastMsgSeqNum = 0;
603
604
605
606
607
608
609
        } else {
            // If connected computer changed, reset message filtering
            isConnected = wxGetApp().GetDocument()->IsConnected();
            if (isConnected) {
                pDoc->GetConnectedComputerName(strNewMachineName);
                if (strLastMachineName != strNewMachineName) {
                    strLastMachineName = strNewMachineName;
610
                    m_bWasConnected = false;
611
                    ResetMessageFiltering();
612
                    m_iPreviousFirstMsgSeqNum = pDoc->GetFirstMsgSeqNum();
613
614
                    m_iPreviousLastMsgSeqNum = m_iPreviousFirstMsgSeqNum - 1;
                    iRowCount = m_iTotalDocCount;   // In case we had filtering set
615
616
617
618
                }
            }

            // If connection status changed, adjust color of messages display
619
620
            if (m_bWasConnected != isConnected) {
                m_bWasConnected = isConnected;
621
622
623
624
625
626
627
628
629
                SetTextColor();

                // Force a complete update
                m_pList->DeleteAllItems();
                m_pList->SetItemCount(iRowCount);
                m_iPreviousRowCount = 0;    // Force scrolling to bottom

            } else {
                // Connection status didn't change
630
                if (m_iPreviousLastMsgSeqNum != pDoc->GetLastMsgSeqNum()) {
631
632
633
634
635
                    if (m_iPreviousRowCount == iRowCount) {
                        m_pList->Refresh();
                    } else {
                        m_pList->SetItemCount(iRowCount);
                    }
636
637
638
639
                }
            }
        }

640
641
        if (iRowCount > 1) {
            if (s_bFilteringChanged) {
642
                m_pList->EnsureVisible(iRowCount - 1);
643
644
645
646
647
648
649
650
651
652
653
654
655
                s_bFilteringChanged = false;
            } else {
                if (m_iPreviousLastMsgSeqNum != pDoc->GetLastMsgSeqNum()) {
                    if (EnsureLastItemVisible()) {
                        m_pList->EnsureVisible(iRowCount - 1);
                    } else if (topItem > 0) {
                        int n = topItem - m_iNumDeletedFilteredRows;
                        if (n < 0) n = 0;
                        Freeze();   // Avoid flicker if selected rows are visible
                        m_pList->EnsureVisible(n);
                        Thaw();
                    }
                }
656
            }
657
658
        }

659
        m_iPreviousRowCount = iRowCount;
660
661
662
663
664
        if (m_iTotalDocCount > 0) {
            m_iPreviousFirstMsgSeqNum = pDoc->GetFirstMsgSeqNum();
            m_iPreviousLastMsgSeqNum = pDoc->GetLastMsgSeqNum();
        }
        
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
        UpdateButtons();

        m_bProcessingRefreshEvent = false;
    }
}


bool CDlgEventLog::SaveState() {
    wxLogTrace(wxT("Function Start/End"), wxT("CDlgEventLog::SaveState - Function Begin"));

    wxString    strBaseConfigLocation = wxEmptyString;
    wxConfigBase*   pConfig = wxConfigBase::Get(FALSE);
    wxListItem      liColumnInfo;
    wxInt32         iIndex = 0;
    wxInt32         iColumnCount = 0;

    wxASSERT(pConfig);

    // An odd case happens every once and awhile where wxWidgets looses
    //   the pointer to the config object, or it is cleaned up before
    //   the window has finished it's cleanup duty.  If we detect a NULL
    //   pointer, return false.
    if (!pConfig) return false;

    strBaseConfigLocation = wxString(wxT("/"));
    pConfig->SetPath(strBaseConfigLocation);
    pConfig->Write(wxT("EventLogOpen"), m_bEventLogIsOpen);

    //
    // Save Frame State
    //
    strBaseConfigLocation = wxString(wxT("/EventLog/"));
    pConfig->SetPath(strBaseConfigLocation);

    // Convert to a zero based index
    iColumnCount = m_pList->GetColumnCount() - 1;

    // Which fields are we interested in?
    liColumnInfo.SetMask(
        wxLIST_MASK_TEXT |
        wxLIST_MASK_WIDTH |
        wxLIST_MASK_FORMAT
    );

    // Cycle through the columns recording anything interesting
    for (iIndex = 0; iIndex <= iColumnCount; iIndex++) {
        m_pList->GetColumn(iIndex, liColumnInfo);

        pConfig->SetPath(strBaseConfigLocation + liColumnInfo.GetText());
        pConfig->Write(wxT("Width"), m_pList->GetColumnWidth(iIndex)); // Work around bug in wxMac-2.8.0 wxListCtrl::SetColumn()
    }

    wxLogTrace(wxT("Function Start/End"), wxT("CDlgEventLog::SaveState - Function End"));
    return true;
}


bool CDlgEventLog::RestoreState() {
    wxLogTrace(wxT("Function Start/End"), wxT("CDlgEventLog::RestoreState - Function Begin"));

    wxString        strBaseConfigLocation = wxString(wxT("/EventLog/"));
    wxConfigBase*   pConfig = wxConfigBase::Get(FALSE);
    wxListItem      liColumnInfo;
    wxInt32         iIndex = 0;
    wxInt32         iColumnCount = 0;
    wxInt32         iTempValue = 0;

    wxASSERT(pConfig);

    // An odd case happens every once and awhile where wxWidgets looses
    //   the pointer to the config object, or it is cleaned up before
    //   the window has finished it's cleanup duty.  If we detect a NULL
    //   pointer, return false.
    if (!pConfig) return false;

    //
    // Restore Frame State
    //
    pConfig->SetPath(strBaseConfigLocation);

    // Convert to a zero based index
    iColumnCount = m_pList->GetColumnCount() - 1;

    // Which fields are we interested in?
    liColumnInfo.SetMask(
        wxLIST_MASK_TEXT |
        wxLIST_MASK_WIDTH |
        wxLIST_MASK_FORMAT
    );

    // Cycle through the columns recording anything interesting
    for (iIndex = 0; iIndex <= iColumnCount; iIndex++) {
        m_pList->GetColumn(iIndex, liColumnInfo);

        pConfig->SetPath(strBaseConfigLocation + liColumnInfo.GetText());
        pConfig->Read(wxT("Width"), &iTempValue, -1);
        if (-1 != iTempValue) {
            liColumnInfo.SetWidth(iTempValue);
#if (defined(__WXMAC__) &&  wxCHECK_VERSION(2,8,0))
            m_pList->SetColumnWidth(iIndex,iTempValue); // Work around bug in wxMac-2.8.0 wxListCtrl::SetColumn()
#endif
        }

        m_pList->SetColumn(iIndex, liColumnInfo);
    }

    wxLogTrace(wxT("Function Start/End"), wxT("CDlgEventLog::RestoreState - Function End"));
    return true;
}


void CDlgEventLog::GetWindowDimensions( wxPoint& position, wxSize& size ) {
    wxString        strBaseConfigLocation = wxString(wxT("/EventLog/"));
    wxConfigBase*   pConfig = wxConfigBase::Get(FALSE);
    int             iHeight = 0, iWidth = 0, iTop = 0, iLeft = 0;

    wxASSERT(pConfig);

    pConfig->SetPath(strBaseConfigLocation);

    pConfig->Read(wxT("YPos"), &iTop, 30);
    pConfig->Read(wxT("XPos"), &iLeft, 30);
787
788
    pConfig->Read(wxT("Width"), &iWidth, DLGEVENTLOG_INITIAL_WIDTH);
    pConfig->Read(wxT("Height"), &iHeight, DLGEVENTLOG_INITIAL_HEIGHT);
789

790
    // Guard against a rare situation where registry values are zero
791
792
    if (iWidth < 50) iWidth = DLGEVENTLOG_INITIAL_WIDTH;
    if (iHeight < 50) iHeight = DLGEVENTLOG_INITIAL_HEIGHT;
793
794
    position.y = iTop;
    position.x = iLeft;
795
796
    size.x = std::max(iWidth, DLGEVENTLOG_MIN_WIDTH);
    size.y = std::max(iHeight, DLGEVENTLOG_MIN_HEIGHT);
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
}


void CDlgEventLog::SetWindowDimensions() {
    wxString        strBaseConfigLocation = wxString(wxT("/EventLog/"));
    wxConfigBase*   pConfig = wxConfigBase::Get(FALSE);

    wxASSERT(pConfig);

    if (!IsIconized()) {
        pConfig->SetPath(strBaseConfigLocation);
        pConfig->Write(wxT("XPos"), GetPosition().x);
        pConfig->Write(wxT("YPos"), GetPosition().y);
        pConfig->Write(wxT("Width"), GetSize().x);
        pConfig->Write(wxT("Height"), GetSize().y);
    }
}


void CDlgEventLog::OnSize(wxSizeEvent& event) {
    SetWindowDimensions();
    event.Skip();
}


void CDlgEventLog::OnMove(wxMoveEvent& event) {
    SetWindowDimensions();
    event.Skip();
}


/*!
 * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_COPYAll
 */

void CDlgEventLog::OnMessagesCopyAll( wxCommandEvent& WXUNUSED(event) ) {
    wxLogTrace(wxT("Function Start/End"), wxT("CDlgEventLog::OnMessagesCopyAll - Function Begin"));

#ifdef wxUSE_CLIPBOARD
    wxInt32 iIndex          = -1;
    wxInt32 iRowCount       = 0;

    iRowCount = m_pList->GetItemCount();

    OpenClipboard( iRowCount * 1024 );

    for (iIndex = 0; iIndex < iRowCount; iIndex++) {
        CopyToClipboard(iIndex);            
    }

    CloseClipboard();
#endif

    wxLogTrace(wxT("Function Start/End"), wxT("CDlgEventLog::OnMessagesCopyAll - Function End"));
}


/*!
 * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_COPYSELECTED
 */

void CDlgEventLog::OnMessagesCopySelected( wxCommandEvent& WXUNUSED(event) ) {
    wxLogTrace(wxT("Function Start/End"), wxT("CDlgEventLog::OnMessagesCopySelected - Function Begin"));

#ifdef wxUSE_CLIPBOARD
    wxInt32 iIndex = -1;
    wxInt32 iRowCount = 0;

    // Count the number of items selected
    for (;;) {
        iIndex = m_pList->GetNextItem(
            iIndex, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED
        );
        if (iIndex == -1) break;

        iRowCount++;            
    }

    OpenClipboard( iRowCount * 1024 );

    // Reset the position indicator
    iIndex = -1;

    for (;;) {
        iIndex = m_pList->GetNextItem(
            iIndex, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED
        );
        if (iIndex == -1) break;

        CopyToClipboard(iIndex);            
    }

    CloseClipboard();
#endif

    wxLogTrace(wxT("Function Start/End"), wxT("CDlgEventLog::OnMessagesCopySelected - Function End"));
}


/*!
 * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_SIMPLE_HELP
 */

void CDlgEventLog::OnButtonHelp( wxCommandEvent& event ) {
    wxLogTrace(wxT("Function Start/End"), wxT("CDlgEventLog::OnHelp - Function Begin"));

    if (IsShown()) {
    	wxString strURL = wxGetApp().GetSkinManager()->GetAdvanced()->GetOrganizationHelpUrl();

		wxString wxurl;
		wxurl.Printf(
            wxT("%s?target=simple_messages&version=%s&controlid=%d"),
            strURL.c_str(),
            wxString(BOINC_VERSION_STRING, wxConvUTF8).c_str(),
            event.GetId()
        );
        wxLaunchDefaultBrowser(wxurl);
    }

    wxLogTrace(wxT("Function Start/End"), wxT("CDlgEventLog::OnHelp - Function End"));
}


920
921
922
923
924
925
926
927
928
929
void CDlgEventLog::OnDiagnosticLogFlags(wxCommandEvent& WXUNUSED(event)) {
    wxLogTrace(wxT("Function Start/End"), wxT("CDlgEventLog::OnDiagnosticLogFlags - Function Begin"));

    CDlgDiagnosticLogFlags dlg(this);
	dlg.ShowModal();

    wxLogTrace(wxT("Function Start/End"), wxT("CDlgEventLog::OnDiagnosticLogFlags - Function End"));
}


930
void CDlgEventLog::OnColResize( wxListEvent& ) {
931
932
933
934
    // Register the new column widths immediately
    SaveState();
}

935
void CDlgEventLog::ResetMessageFiltering() {
936
    s_bFilteringChanged = false;
937
938
939
940
    s_bIsFiltered = false;
    s_strFilteredProjectName.clear();
    m_iFilteredIndexes.Clear();
    SetFilterButtonText();
941
    m_iTotalDeletedFilterRows = 0;
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
}


void CDlgEventLog::UpdateButtons() {
    bool enableFilterButton = s_bIsFiltered; 
    bool enableCopySelectedButon = false; 
    if (m_iTotalDocCount > 0) {
        int n = m_pList->GetSelectedItemCount();
        if (n > 0) {
            enableCopySelectedButon = true;
        }
        
        if ((n == 1) && (! s_bIsFiltered)) {
            n = m_pList->GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
            MESSAGE* message = wxGetApp().GetDocument()->message(n);
            if ((message->project).size() > 0) {
                enableFilterButton = true;
            }
        }
    }
    m_pFilterButton->Enable(enableFilterButton);
    m_pCopySelectedButton->Enable(enableCopySelectedButon);
}


wxString CDlgEventLog::OnListGetItemText(long item, long column) const {
    wxString        strBuffer   = wxEmptyString;
    wxInt32         index       = GetFilteredMessageIndex(item);

    switch(column) {
    case COLUMN_PROJECT:
        FormatProjectName(index, strBuffer);
        break;
    case COLUMN_TIME:
        FormatTime(index, strBuffer);
        break;
    case COLUMN_MESSAGE:
        FormatMessage(index, strBuffer);
        break;
    }

    return strBuffer;
}


wxListItemAttr* CDlgEventLog::OnListGetItemAttr(long item) const {
    wxListItemAttr* pAttribute  = NULL;
    wxInt32         index       = GetFilteredMessageIndex(item);
    MESSAGE*        message     = wxGetApp().GetDocument()->message(index);

    // If we are using some theme where the default background color isn't
    //   white, then our whole system is boned. Use defaults instead.
    if (wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW) != wxColor(wxT("WHITE"))) return NULL;

    if (message) {
997
        item += s_bIsFiltered ? m_iTotalDeletedFilterRows : m_iPreviousFirstMsgSeqNum;
998
999
1000
        switch(message->priority) {
        case MSG_USER_ALERT:
            pAttribute = item % 2 ? m_pMessageErrorGrayAttr : m_pMessageErrorAttr;
For faster browsing, not all history is shown. View entire blame