timer to timeout and saving inactive list items

svn path=/trunk/boinc/; revision=836
This commit is contained in:
Eric Heien 2003-01-28 01:22:47 +00:00
parent e0a4de8a57
commit f47ce21b50
4 changed files with 139 additions and 15 deletions

View File

@ -302,6 +302,29 @@ int CProgressListCtrl::InsertItem(int nItem, LPCTSTR lpszItem)
return CListCtrl::InsertItem(nItem, lpszItem);
}
//////////
// CProgressListCtrl::GetColumnTitle
// arguments: nCol: column to get title of
// strTitle: reference to string to put title in
// returns: void
// function: gets the title of a column and puts it in a string,
// if the column is out of bounds, sets the empty string
void CProgressListCtrl::GetColumnTitle(int nCol, CString& strTitle)
{
if(nCol < 0 || nCol >= GetHeaderCtrl()->GetItemCount()) {
strTitle.Empty();
return;
}
char szTitle[256];
LVCOLUMN lvcol;
ZeroMemory(&lvcol, sizeof(LVCOLUMN));
lvcol.mask = LVCF_TEXT;
lvcol.pszText = szTitle;
lvcol.cchTextMax = 256;
GetColumn(nCol, &lvcol);
strTitle.Format("%s", szTitle);
}
//////////
// CProgressListCtrl::GetColumnWidth
// arguments: nCol: column to get width of
@ -719,6 +742,44 @@ void CProgressListCtrl::SetMenuItems(char** szTitles, int nLength)
}
}
void CProgressListCtrl::SaveInactive(char* szFile, char* szSection)
{
CString strSection, strKey, strValue;
int nMax = 0;
for(int i = 0; i < GetItemCount(); i ++) {
if(GetItemData(i) != NULL) continue;
strSection.Format("%s-%d", szSection, nMax);
for(int si = 0; si < GetHeaderCtrl()->GetItemCount(); si ++) {
GetColumnTitle(si, strKey);
strValue = GetItemText(i, si);
WritePrivateProfileString(strSection, strKey, strValue, szFile);
}
nMax ++;
}
strValue.Format("%d", nMax);
WritePrivateProfileString(szSection, "max", strValue, szFile);
}
void CProgressListCtrl::LoadInactive(char* szFile, char* szSection)
{
CString strSection, strKey;
char szValue[512];
int nMax = GetPrivateProfileInt(szSection, "max", 0, szFile);
for(int i = 0; i < nMax; i ++) {
strSection.Format("%s-%d", szSection, i);
GetColumnTitle(0, strKey);
GetPrivateProfileString(strSection, strKey, "", szValue, 512, szFile);
InsertItem(GetItemCount(), szValue);
for(int si = 1; si < GetHeaderCtrl()->GetItemCount(); si ++) {
GetColumnTitle(si, strKey);
GetPrivateProfileString(strSection, strKey, "", szValue, 512, szFile);
SetItemText(GetItemCount() - 1, si, szValue);
}
}
}
//////////
// CProgressListCtrl::OnCreate
// arguments: lpcs: a pointer to the create structure
@ -906,7 +967,7 @@ void CProgressListCtrl::OnRButtonDown(UINT nFlags, CPoint point)
// returns: true if the notification is processed, otherwise false
// function: handles notifications from children, including:
// user clicking a header sorts by that column.
// user double clicking a header does not resize it.
// user double clicking a header resizes it to longest string in that column.
// user tracking a hidden column does not resize it.
BOOL CProgressListCtrl::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult)
{
@ -937,15 +998,9 @@ BOOL CProgressListCtrl::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult)
}
// find longest string and resize to its length
char szTitle[256];
int nMax = 0;
LVCOLUMN lvcol;
ZeroMemory(&lvcol, sizeof(LVCOLUMN));
lvcol.mask = LVCF_TEXT;
lvcol.pszText = szTitle;
lvcol.cchTextMax = 256;
GetColumn(phdn->iItem, &lvcol);
nMax = GetStringWidth(szTitle) + 12;
CString strTitle;
GetColumnTitle(phdn->iItem, strTitle);
int nMax = GetStringWidth(strTitle) + 12;
for(int i = 0; i < GetItemCount(); i ++) {
CString strBuf;
strBuf = GetItemText(i, phdn->iItem);

View File

@ -90,11 +90,14 @@ public:
int InsertColumn(int, LPCTSTR, int, int, int);
int InsertItem(int, LPCTSTR);
void GetTextRect(int, int, LPRECT);
void GetColumnTitle(int, CString&);
int GetColumnWidth(int);
BOOL SetColumnWidth(int, int);
void SetItemColor(int, COLORREF);
void SetProjectURL(int, char*);
void SetMenuItems(char**, int);
void SaveInactive(char*, char*);
void LoadInactive(char*, char*);
protected:
CMenu m_PopupMenu; // context menu for header

View File

@ -548,6 +548,44 @@ void CMainWindow::SetStatusIcon(DWORD dwMessage)
m_nIconState = dwMessage;
}
//////////
// CMainWindow::SaveListControls
// arguments: void
// returns: void
// function: saves relevant elements of list controls
void CMainWindow::SaveListControls()
{
char szPath[256];
CString strKey, strVal;
GetCurrentDirectory(256, szPath);
strcat(szPath, "\\");
strcat(szPath, LIST_STATE_FILE_NAME);
file_delete(szPath);
m_ProjectListCtrl.SaveInactive(szPath, "PROJECTS");
m_ResultListCtrl.SaveInactive(szPath, "WORK");
m_XferListCtrl.SaveInactive(szPath, "TRANSFERS");
m_MessageListCtrl.SaveInactive(szPath, "MESSAGES");
}
//////////
// CMainWindow::LoadListControls
// arguments: void
// returns: void
// function: loads relevant elements of list controls
void CMainWindow::LoadListControls()
{
char szPath[256];
CString strKey, strVal;
GetCurrentDirectory(256, szPath);
strcat(szPath, "\\");
strcat(szPath, LIST_STATE_FILE_NAME);
m_ProjectListCtrl.LoadInactive(szPath, "PROJECTS");
m_ResultListCtrl.LoadInactive(szPath, "WORK");
m_XferListCtrl.LoadInactive(szPath, "TRANSFERS");
m_MessageListCtrl.LoadInactive(szPath, "MESSAGES");
file_delete(szPath);
}
//////////
// CMainWindow::SaveUserSettings
// arguments: void
@ -873,6 +911,29 @@ void CMainWindow::PostNcDestroy()
delete this;
}
//////////
// CMainWindow::SetTimeOut
// arguments: void
// returns: void
// function: creates a thread to signal a timeout
void CMainWindow::SetTimeOut()
{
CreateThread(NULL, 0, TimeOutThreadProc, GetSafeHwnd(), NULL, NULL);
}
//////////
// CMainWindow::TimeOutThreadProc
// arguments: hWnd: handle to window to signal cast as LPVOID
// returns: true for success, false otherwise
// function: sleeps for some time then signals the given window
DWORD CMainWindow::TimeOutThreadProc(LPVOID hWnd)
{
CWnd* pWnd = CWnd::FromHandle((HWND)hWnd);
Sleep(GUI_REFRESH);
pWnd->SendMessage(WM_TIMER, 0, 0);
return 1;
}
//////////
// CMainWindow::DefWindowProc
// arguments: message: message received
@ -1258,6 +1319,7 @@ void CMainWindow::OnCommandExit()
}
SaveUserSettings();
SaveListControls();
CWnd::OnClose();
}
@ -1406,7 +1468,7 @@ int CMainWindow::OnCreate(LPCREATESTRUCT lpcs)
OnCommandExit();
return 0;
}
SetTimer(ID_TIMER, GUI_REFRESH, 0);
SetTimeOut();
// load dll and start idle detection
m_hIdleDll = LoadLibrary("boinc.dll");
@ -1430,6 +1492,8 @@ int CMainWindow::OnCreate(LPCREATESTRUCT lpcs)
}
LoadUserSettings();
LoadListControls();
CMenu* ConMenu = NULL;
ConMenu = m_MainMenu.GetSubMenu(2);
if(ConMenu) {
@ -1621,8 +1685,6 @@ LRESULT CMainWindow::OnStatusIcon(WPARAM wParam, LPARAM lParam)
// and updates gui display.
void CMainWindow::OnTimer(UINT uEventID)
{
KillTimer(ID_TIMER);
// update state and gui
while(gstate.do_something());
NetCheck(); // need to check if network connection can be terminated
@ -1642,6 +1704,5 @@ void CMainWindow::OnTimer(UINT uEventID)
UpdateGUI(&gstate);
}
SetTimer(ID_TIMER, GUI_REFRESH, 0);
SetTimeOut();
}

View File

@ -114,6 +114,8 @@ protected:
COLORREF GetPieColor(int);
void ShowTab(int);
void SetStatusIcon(DWORD);
void SaveListControls();
void LoadListControls();
void SaveUserSettings();
void LoadUserSettings();
void LoadLanguage();
@ -121,6 +123,8 @@ protected:
void Syncronize(CProgressListCtrl*, vector<void*>*);
void SyncronizePie(CPieChartCtrl*, vector<PROJECT*>*);
virtual void PostNcDestroy();
void SetTimeOut();
static DWORD WINAPI TimeOutThreadProc(LPVOID);
LRESULT DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam);
afx_msg void OnClose();
@ -147,6 +151,7 @@ protected:
afx_msg void OnSize(UINT, int, int);
afx_msg LRESULT OnStatusIcon(WPARAM, LPARAM);
afx_msg void OnTimer(UINT);
DECLARE_MESSAGE_MAP()
};