2005-01-20 23:22:22 +00:00
|
|
|
// Berkeley Open Infrastructure for Network Computing
|
|
|
|
// http://boinc.berkeley.edu
|
|
|
|
// Copyright (C) 2005 University of California
|
2004-09-21 01:30:29 +00:00
|
|
|
//
|
2005-01-20 23:22:22 +00:00
|
|
|
// This 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 2.1 of the License, or (at your option) any later version.
|
2004-09-21 01:30:29 +00:00
|
|
|
//
|
2005-01-20 23:22:22 +00:00
|
|
|
// This software 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.
|
2004-09-21 01:30:29 +00:00
|
|
|
//
|
2005-01-20 23:22:22 +00:00
|
|
|
// To view the GNU Lesser General Public License visit
|
|
|
|
// http://www.gnu.org/copyleft/lesser.html
|
|
|
|
// or write to the Free Software Foundation, Inc.,
|
|
|
|
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
2004-09-21 01:30:29 +00:00
|
|
|
|
|
|
|
#if defined(__GNUG__) && !defined(__APPLE__)
|
|
|
|
#pragma implementation "ViewResources.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "stdwx.h"
|
|
|
|
#include "BOINCGUIApp.h"
|
|
|
|
#include "MainDocument.h"
|
2004-09-24 22:19:02 +00:00
|
|
|
#include "BOINCTaskCtrl.h"
|
|
|
|
#include "BOINCListCtrl.h"
|
2004-09-21 01:30:29 +00:00
|
|
|
#include "ViewResources.h"
|
|
|
|
#include "Events.h"
|
|
|
|
|
2004-12-02 07:43:47 +00:00
|
|
|
|
2004-09-21 01:30:29 +00:00
|
|
|
#include "res/usage.xpm"
|
|
|
|
|
|
|
|
|
2004-09-24 22:19:02 +00:00
|
|
|
#define COLUMN_PROJECT 0
|
|
|
|
#define COLUMN_DISKSPACE 1
|
|
|
|
|
|
|
|
|
2005-04-07 07:04:50 +00:00
|
|
|
CResource::CResource() {
|
2004-12-02 07:43:47 +00:00
|
|
|
m_strProjectName = wxEmptyString;
|
|
|
|
m_strDiskSpace = wxEmptyString;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-04-07 07:04:50 +00:00
|
|
|
CResource::~CResource() {
|
2004-12-02 07:43:47 +00:00
|
|
|
m_strProjectName.Clear();
|
|
|
|
m_strDiskSpace.Clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-09-24 22:19:02 +00:00
|
|
|
IMPLEMENT_DYNAMIC_CLASS(CViewResources, CBOINCBaseView)
|
2004-09-21 01:30:29 +00:00
|
|
|
|
2005-04-21 06:04:26 +00:00
|
|
|
BEGIN_EVENT_TABLE (CViewResources, CBOINCBaseView)
|
2005-04-21 23:14:10 +00:00
|
|
|
EVT_LIST_ITEM_SELECTED(ID_LIST_RESOURCEUTILIZATIONVIEW, CViewResources::OnListSelected)
|
|
|
|
EVT_LIST_ITEM_DESELECTED(ID_LIST_RESOURCEUTILIZATIONVIEW, CViewResources::OnListDeselected)
|
2005-04-21 06:04:26 +00:00
|
|
|
END_EVENT_TABLE ()
|
|
|
|
|
2004-09-21 01:30:29 +00:00
|
|
|
|
2005-04-07 07:04:50 +00:00
|
|
|
CViewResources::CViewResources() {}
|
2004-09-21 01:30:29 +00:00
|
|
|
|
|
|
|
|
|
|
|
CViewResources::CViewResources(wxNotebook* pNotebook) :
|
2005-04-21 06:04:26 +00:00
|
|
|
CBOINCBaseView(pNotebook, ID_TASK_RESOURCEUTILIZATIONVIEW, DEFAULT_TASK_FLAGS, ID_LIST_RESOURCEUTILIZATIONVIEW, DEFAULT_LIST_SINGLE_SEL_FLAGS)
|
|
|
|
{
|
|
|
|
CTaskItemGroup* pGroup = NULL;
|
|
|
|
CTaskItem* pItem = NULL;
|
|
|
|
|
2005-04-27 06:55:28 +00:00
|
|
|
wxASSERT(m_pTaskPane);
|
|
|
|
wxASSERT(m_pListPane);
|
2004-09-21 01:30:29 +00:00
|
|
|
|
2004-12-23 01:06:41 +00:00
|
|
|
//
|
|
|
|
// Setup View
|
|
|
|
//
|
2004-09-24 22:19:02 +00:00
|
|
|
|
2005-04-21 06:04:26 +00:00
|
|
|
// Create Task Pane Items
|
2005-04-21 23:14:10 +00:00
|
|
|
m_pTaskPane->UpdateControls();
|
2004-09-24 22:19:02 +00:00
|
|
|
|
2005-04-21 06:04:26 +00:00
|
|
|
// Create List Pane Items
|
2004-09-24 22:19:02 +00:00
|
|
|
m_pListPane->InsertColumn(COLUMN_PROJECT, _("Project"), wxLIST_FORMAT_LEFT, -1);
|
|
|
|
m_pListPane->InsertColumn(COLUMN_DISKSPACE, _("Disk Space"), wxLIST_FORMAT_LEFT, -1);
|
2005-04-22 01:46:32 +00:00
|
|
|
|
|
|
|
UpdateSelection();
|
2004-09-21 01:30:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-04-07 07:04:50 +00:00
|
|
|
CViewResources::~CViewResources() {
|
2005-02-01 00:54:06 +00:00
|
|
|
EmptyCache();
|
2005-04-21 06:04:26 +00:00
|
|
|
EmptyTasks();
|
2004-09-21 01:30:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-04-07 07:04:50 +00:00
|
|
|
wxString CViewResources::GetViewName() {
|
2004-09-21 01:30:29 +00:00
|
|
|
return wxString(_("Disk"));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-04-07 07:04:50 +00:00
|
|
|
const char** CViewResources::GetViewIcon() {
|
2004-09-21 01:30:29 +00:00
|
|
|
return usage_xpm;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-04-07 07:04:50 +00:00
|
|
|
wxInt32 CViewResources::GetDocCount() {
|
2004-10-26 08:41:02 +00:00
|
|
|
CMainDocument* pDoc = wxGetApp().GetDocument();
|
|
|
|
|
2005-04-27 06:55:28 +00:00
|
|
|
wxASSERT(pDoc);
|
2004-10-26 08:41:02 +00:00
|
|
|
wxASSERT(wxDynamicCast(pDoc, CMainDocument));
|
|
|
|
|
|
|
|
return pDoc->GetResourceCount();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-04-07 07:04:50 +00:00
|
|
|
wxString CViewResources::OnListGetItemText(long item, long column) const {
|
|
|
|
CResource* resource = m_ResourceCache.at(item);
|
2004-12-02 07:43:47 +00:00
|
|
|
wxString strBuffer = wxEmptyString;
|
2004-10-22 22:37:11 +00:00
|
|
|
|
2004-12-02 07:43:47 +00:00
|
|
|
switch(column)
|
|
|
|
{
|
|
|
|
case COLUMN_PROJECT:
|
2005-03-15 23:44:48 +00:00
|
|
|
strBuffer = resource->m_strProjectName;
|
2004-12-02 07:43:47 +00:00
|
|
|
break;
|
|
|
|
case COLUMN_DISKSPACE:
|
2005-03-15 23:44:48 +00:00
|
|
|
strBuffer = resource->m_strDiskSpace;
|
2004-12-02 07:43:47 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return strBuffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-04-07 07:04:50 +00:00
|
|
|
wxString CViewResources::OnDocGetItemText(long item, long column) const {
|
2004-12-02 07:43:47 +00:00
|
|
|
wxString strBuffer = wxEmptyString;
|
2004-10-22 22:37:11 +00:00
|
|
|
|
2005-04-07 07:04:50 +00:00
|
|
|
switch(column) {
|
|
|
|
case COLUMN_PROJECT:
|
|
|
|
FormatProjectName(item, strBuffer);
|
|
|
|
break;
|
|
|
|
case COLUMN_DISKSPACE:
|
|
|
|
FormatDiskSpace(item, strBuffer);
|
|
|
|
break;
|
2004-10-22 22:37:11 +00:00
|
|
|
}
|
2004-09-24 22:19:02 +00:00
|
|
|
return strBuffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-04-07 07:04:50 +00:00
|
|
|
wxInt32 CViewResources::AddCacheElement() {
|
2004-12-02 07:43:47 +00:00
|
|
|
CResource* pItem = new CResource();
|
2005-04-27 06:55:28 +00:00
|
|
|
wxASSERT(pItem);
|
|
|
|
if (pItem) {
|
2005-04-07 07:04:50 +00:00
|
|
|
m_ResourceCache.push_back(pItem);
|
2004-12-02 07:43:47 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
wxInt32 CViewResources::EmptyCache()
|
|
|
|
{
|
2005-01-29 19:59:39 +00:00
|
|
|
unsigned int i;
|
|
|
|
for (i=0; i<m_ResourceCache.size(); i++) {
|
|
|
|
delete m_ResourceCache[i];
|
|
|
|
}
|
2005-01-29 00:58:43 +00:00
|
|
|
m_ResourceCache.clear();
|
2004-12-02 07:43:47 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-04-07 07:04:50 +00:00
|
|
|
wxInt32 CViewResources::GetCacheCount() {
|
2005-01-29 00:58:43 +00:00
|
|
|
return m_ResourceCache.size();
|
2004-12-02 07:43:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-04-07 07:04:50 +00:00
|
|
|
wxInt32 CViewResources::RemoveCacheElement() {
|
2005-01-29 21:30:45 +00:00
|
|
|
delete m_ResourceCache.back();
|
2005-04-07 07:04:50 +00:00
|
|
|
m_ResourceCache.erase(m_ResourceCache.end() - 1);
|
2004-12-02 07:43:47 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-04-07 07:04:50 +00:00
|
|
|
wxInt32 CViewResources::UpdateCache(long item, long column, wxString& strNewData) {
|
|
|
|
CResource* resource = m_ResourceCache.at(item);
|
2004-12-02 07:43:47 +00:00
|
|
|
|
2005-04-07 07:04:50 +00:00
|
|
|
switch(column) {
|
|
|
|
case COLUMN_PROJECT:
|
|
|
|
resource->m_strProjectName = strNewData;
|
|
|
|
break;
|
|
|
|
case COLUMN_DISKSPACE:
|
|
|
|
resource->m_strDiskSpace = strNewData;
|
|
|
|
break;
|
2004-12-02 07:43:47 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-04-07 07:04:50 +00:00
|
|
|
void CViewResources::UpdateSelection() {
|
2004-09-24 22:19:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-04-07 07:04:50 +00:00
|
|
|
wxInt32 CViewResources::FormatProjectName(wxInt32 item, wxString& strBuffer) const
|
2004-10-22 22:37:11 +00:00
|
|
|
{
|
|
|
|
CMainDocument* pDoc = wxGetApp().GetDocument();
|
|
|
|
|
2005-04-27 06:55:28 +00:00
|
|
|
wxASSERT(pDoc);
|
2004-10-22 22:37:11 +00:00
|
|
|
wxASSERT(wxDynamicCast(pDoc, CMainDocument));
|
|
|
|
|
|
|
|
strBuffer.Clear();
|
|
|
|
|
|
|
|
pDoc->GetResourceProjectName(item, strBuffer);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-04-07 07:04:50 +00:00
|
|
|
wxInt32 CViewResources::FormatDiskSpace(wxInt32 item, wxString& strBuffer) const {
|
2004-10-22 22:37:11 +00:00
|
|
|
float fBuffer = 0;
|
|
|
|
double xTera = 1099511627776.0;
|
|
|
|
double xGiga = 1073741824.0;
|
|
|
|
double xMega = 1048576.0;
|
|
|
|
double xKilo = 1024.0;
|
|
|
|
CMainDocument* pDoc = wxGetApp().GetDocument();
|
|
|
|
|
2005-04-27 06:55:28 +00:00
|
|
|
wxASSERT(pDoc);
|
2004-10-22 22:37:11 +00:00
|
|
|
wxASSERT(wxDynamicCast(pDoc, CMainDocument));
|
|
|
|
|
|
|
|
strBuffer.Clear();
|
|
|
|
|
2005-04-07 07:04:50 +00:00
|
|
|
pDoc->GetResourceDiskspace(item, fBuffer);
|
|
|
|
|
|
|
|
if (fBuffer >= xTera) {
|
|
|
|
strBuffer.Printf(wxT("%0.2f TB"), fBuffer/xTera);
|
|
|
|
} else if (fBuffer >= xGiga) {
|
|
|
|
strBuffer.Printf(wxT("%0.2f GB"), fBuffer/xGiga);
|
|
|
|
} else if (fBuffer >= xMega) {
|
|
|
|
strBuffer.Printf(wxT("%0.2f MB"), fBuffer/xMega);
|
|
|
|
} else if (fBuffer >= xKilo) {
|
|
|
|
strBuffer.Printf(wxT("%0.2f KB"), fBuffer/xKilo);
|
|
|
|
} else {
|
|
|
|
strBuffer.Printf(wxT("%0.0f bytes"), fBuffer);
|
2004-10-22 22:37:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2004-12-08 00:40:19 +00:00
|
|
|
|
2005-01-02 18:29:53 +00:00
|
|
|
const char *BOINC_RCSID_5a37b46a6e = "$Id$";
|