2004-09-21 01:30:29 +00:00
|
|
|
// $Id$
|
|
|
|
//
|
|
|
|
// The contents of this file are subject to the BOINC Public License
|
|
|
|
// Version 1.0 (the "License"); you may not use this file except in
|
|
|
|
// compliance with the License. You may obtain a copy of the License at
|
|
|
|
// http://boinc.berkeley.edu/license_1.0.txt
|
|
|
|
//
|
|
|
|
// Software distributed under the License is distributed on an "AS IS"
|
|
|
|
// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
|
|
|
|
// License for the specific language governing rights and limitations
|
|
|
|
// under the License.
|
|
|
|
//
|
|
|
|
// The Original Code is the Berkeley Open Infrastructure for Network Computing.
|
|
|
|
//
|
|
|
|
// The Initial Developer of the Original Code is the SETI@home project.
|
|
|
|
// Portions created by the SETI@home project are Copyright (C) 2002
|
|
|
|
// University of California at Berkeley. All Rights Reserved.
|
|
|
|
//
|
|
|
|
// Contributor(s):
|
|
|
|
//
|
|
|
|
// Revision History:
|
|
|
|
//
|
|
|
|
|
|
|
|
#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"
|
|
|
|
|
|
|
|
#include "res/usage.xpm"
|
2004-09-24 22:19:02 +00:00
|
|
|
#include "res/task.xpm"
|
|
|
|
#include "res/tips.xpm"
|
2004-09-21 01:30:29 +00:00
|
|
|
|
|
|
|
|
2004-10-09 03:05:01 +00:00
|
|
|
#define VIEW_HEADER wxT("resources")
|
2004-09-24 22:19:02 +00:00
|
|
|
|
2004-10-09 03:05:01 +00:00
|
|
|
#define SECTION_TASK wxT(VIEW_HEADER "task")
|
|
|
|
#define SECTION_TIPS wxT(VIEW_HEADER "tips")
|
2004-09-24 22:19:02 +00:00
|
|
|
|
2004-10-09 03:05:01 +00:00
|
|
|
#define BITMAP_RESOURCES wxT(VIEW_HEADER ".xpm")
|
|
|
|
#define BITMAP_TASKHEADER wxT(SECTION_TASK ".xpm")
|
|
|
|
#define BITMAP_TIPSHEADER wxT(SECTION_TIPS ".xpm")
|
2004-09-21 01:30:29 +00:00
|
|
|
|
2004-09-24 22:19:02 +00:00
|
|
|
#define COLUMN_PROJECT 0
|
|
|
|
#define COLUMN_DISKSPACE 1
|
|
|
|
|
|
|
|
|
2004-10-19 19:41:29 +00:00
|
|
|
const wxString LINKDESC_DEFAULT =
|
|
|
|
_("No available options currently defined.");
|
|
|
|
|
|
|
|
|
2004-09-24 22:19:02 +00:00
|
|
|
IMPLEMENT_DYNAMIC_CLASS(CViewResources, CBOINCBaseView)
|
2004-09-21 01:30:29 +00:00
|
|
|
|
|
|
|
|
|
|
|
CViewResources::CViewResources()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
CViewResources::CViewResources(wxNotebook* pNotebook) :
|
2004-10-27 21:10:22 +00:00
|
|
|
CBOINCBaseView( pNotebook, ID_HTML_RESOURCEUTILIZATIONVIEW, DEFAULT_HTML_FLAGS, ID_LIST_RESOURCEUTILIZATIONVIEW, DEFAULT_LIST_SINGLE_SEL_FLAGS )
|
2004-09-21 01:30:29 +00:00
|
|
|
{
|
|
|
|
wxASSERT(NULL != m_pTaskPane);
|
|
|
|
wxASSERT(NULL != m_pListPane);
|
|
|
|
|
2004-09-24 22:19:02 +00:00
|
|
|
wxBitmap bmpResources(usage_xpm);
|
|
|
|
wxBitmap bmpTask(task_xpm);
|
|
|
|
wxBitmap bmpTips(tips_xpm);
|
|
|
|
|
|
|
|
bmpResources.SetMask(new wxMask(bmpResources, wxColour(255, 0, 255)));
|
|
|
|
bmpTask.SetMask(new wxMask(bmpTask, wxColour(255, 0, 255)));
|
|
|
|
bmpTips.SetMask(new wxMask(bmpTips, wxColour(255, 0, 255)));
|
|
|
|
|
|
|
|
m_pTaskPane->AddVirtualFile(wxT(BITMAP_RESOURCES), bmpResources, wxBITMAP_TYPE_XPM);
|
|
|
|
|
2004-10-09 03:05:01 +00:00
|
|
|
m_pTaskPane->CreateTaskHeader(BITMAP_TASKHEADER, bmpTask, _("Tasks"));
|
|
|
|
m_pTaskPane->CreateTaskHeader(BITMAP_TIPSHEADER, bmpTips, _("Quick Tips"));
|
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);
|
|
|
|
|
|
|
|
m_bTipsHeaderHidden = false;
|
2004-10-26 17:12:58 +00:00
|
|
|
m_bItemSelected = false;
|
2004-09-24 22:19:02 +00:00
|
|
|
|
|
|
|
SetCurrentQuickTip(
|
2004-10-09 03:05:01 +00:00
|
|
|
LINK_DEFAULT,
|
2004-10-19 19:41:29 +00:00
|
|
|
LINKDESC_DEFAULT
|
2004-09-24 22:19:02 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
UpdateSelection();
|
2004-09-21 01:30:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
CViewResources::~CViewResources()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
wxString CViewResources::GetViewName()
|
|
|
|
{
|
|
|
|
return wxString(_("Disk"));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
char** CViewResources::GetViewIcon()
|
|
|
|
{
|
|
|
|
return usage_xpm;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-10-26 08:41:02 +00:00
|
|
|
wxInt32 CViewResources::GetListRowCount()
|
|
|
|
{
|
|
|
|
CMainDocument* pDoc = wxGetApp().GetDocument();
|
|
|
|
|
|
|
|
wxASSERT(NULL != pDoc);
|
|
|
|
wxASSERT(wxDynamicCast(pDoc, CMainDocument));
|
|
|
|
|
|
|
|
return pDoc->GetResourceCount();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-09-24 22:19:02 +00:00
|
|
|
wxString CViewResources::OnListGetItemText( long item, long column ) const
|
|
|
|
{
|
2004-10-22 22:37:11 +00:00
|
|
|
wxString strBuffer = wxEmptyString;
|
|
|
|
CMainDocument* pDoc = wxGetApp().GetDocument();
|
|
|
|
|
|
|
|
wxASSERT(NULL != pDoc);
|
|
|
|
wxASSERT(wxDynamicCast(pDoc, CMainDocument));
|
|
|
|
|
|
|
|
switch(column)
|
|
|
|
{
|
|
|
|
case COLUMN_PROJECT:
|
|
|
|
if (item == m_iCacheFrom) pDoc->CachedStateLock();
|
|
|
|
FormatProjectName( item, strBuffer );
|
|
|
|
break;
|
|
|
|
case COLUMN_DISKSPACE:
|
|
|
|
FormatDiskSpace( item, strBuffer );
|
|
|
|
if (item == m_iCacheTo) pDoc->CachedStateUnlock();
|
|
|
|
break;
|
|
|
|
}
|
2004-09-24 22:19:02 +00:00
|
|
|
return strBuffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CViewResources::OnTaskLinkClicked( const wxHtmlLinkInfo& link )
|
|
|
|
{
|
|
|
|
wxASSERT(NULL != m_pTaskPane);
|
|
|
|
wxASSERT(NULL != m_pListPane);
|
|
|
|
|
|
|
|
wxString strMessage;
|
|
|
|
|
|
|
|
if ( link.GetHref() == wxT(SECTION_TASK) )
|
|
|
|
m_bTaskHeaderHidden ? m_bTaskHeaderHidden = false : m_bTaskHeaderHidden = true;
|
2004-10-22 22:37:11 +00:00
|
|
|
else if ( link.GetHref() == wxT(SECTION_TIPS) )
|
2004-09-24 22:19:02 +00:00
|
|
|
m_bTipsHeaderHidden ? m_bTipsHeaderHidden = false : m_bTipsHeaderHidden = true;
|
|
|
|
|
|
|
|
UpdateSelection();
|
2004-10-22 22:37:11 +00:00
|
|
|
m_pListPane->Refresh();
|
2004-09-24 22:19:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CViewResources::OnTaskCellMouseHover( wxHtmlCell* cell, wxCoord x, wxCoord y )
|
|
|
|
{
|
|
|
|
if ( NULL != cell->GetLink() )
|
|
|
|
{
|
|
|
|
bool bUpdateSelection = false;
|
|
|
|
wxString strLink;
|
|
|
|
|
|
|
|
strLink = cell->GetLink()->GetHref();
|
|
|
|
|
2004-10-09 03:05:01 +00:00
|
|
|
if ( UpdateQuickTip( strLink, wxT("test"), wxT("test") ) )
|
|
|
|
bUpdateSelection = true;
|
2004-09-24 22:19:02 +00:00
|
|
|
else
|
|
|
|
{
|
2004-10-05 02:55:26 +00:00
|
|
|
if ( 0 == m_pListPane->GetSelectedItemCount() )
|
2004-09-24 22:19:02 +00:00
|
|
|
{
|
|
|
|
if ( wxT(LINK_DEFAULT) != GetCurrentQuickTip() )
|
|
|
|
{
|
|
|
|
SetCurrentQuickTip(
|
2004-10-09 03:05:01 +00:00
|
|
|
LINK_DEFAULT,
|
2004-10-19 19:41:29 +00:00
|
|
|
LINKDESC_DEFAULT
|
2004-09-24 22:19:02 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
bUpdateSelection = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( bUpdateSelection )
|
|
|
|
{
|
|
|
|
UpdateSelection();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CViewResources::UpdateSelection()
|
|
|
|
{
|
|
|
|
wxASSERT(NULL != m_pTaskPane);
|
|
|
|
wxASSERT(NULL != m_pListPane);
|
|
|
|
|
2004-10-05 02:55:26 +00:00
|
|
|
if ( 0 == m_pListPane->GetSelectedItemCount() )
|
2004-09-24 22:19:02 +00:00
|
|
|
{
|
|
|
|
m_bTaskHeaderHidden = true;
|
|
|
|
|
2004-10-09 03:05:01 +00:00
|
|
|
if ( m_bItemSelected )
|
|
|
|
{
|
|
|
|
SetCurrentQuickTip(
|
|
|
|
LINK_DEFAULT,
|
|
|
|
wxT("")
|
|
|
|
);
|
|
|
|
}
|
2004-09-24 22:19:02 +00:00
|
|
|
m_bItemSelected = false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_bTaskHeaderHidden = true;
|
|
|
|
|
|
|
|
m_bItemSelected = true;
|
|
|
|
}
|
|
|
|
UpdateTaskPane();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CViewResources::UpdateTaskPane()
|
|
|
|
{
|
|
|
|
wxASSERT(NULL != m_pTaskPane);
|
|
|
|
|
|
|
|
m_pTaskPane->BeginTaskPage();
|
|
|
|
|
2004-10-09 03:05:01 +00:00
|
|
|
m_pTaskPane->BeginTaskSection( SECTION_TASK, BITMAP_TASKHEADER, m_bTaskHeaderHidden );
|
2004-09-24 22:19:02 +00:00
|
|
|
if (!m_bTaskHeaderHidden)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
m_pTaskPane->EndTaskSection( m_bTaskHeaderHidden );
|
|
|
|
|
2004-10-09 03:05:01 +00:00
|
|
|
m_pTaskPane->UpdateQuickTip( SECTION_TIPS, BITMAP_TIPSHEADER, GetCurrentQuickTipText(), m_bTipsHeaderHidden);
|
2004-09-24 22:19:02 +00:00
|
|
|
|
|
|
|
m_pTaskPane->EndTaskPage();
|
2004-09-21 01:30:29 +00:00
|
|
|
}
|
|
|
|
|
2004-10-22 22:37:11 +00:00
|
|
|
|
|
|
|
wxInt32 CViewResources::FormatProjectName( wxInt32 item, wxString& strBuffer ) const
|
|
|
|
{
|
|
|
|
CMainDocument* pDoc = wxGetApp().GetDocument();
|
|
|
|
|
|
|
|
wxASSERT(NULL != pDoc);
|
|
|
|
wxASSERT(wxDynamicCast(pDoc, CMainDocument));
|
|
|
|
|
|
|
|
strBuffer.Clear();
|
|
|
|
|
|
|
|
pDoc->GetResourceProjectName(item, strBuffer);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
wxInt32 CViewResources::FormatDiskSpace( wxInt32 item, wxString& strBuffer ) const
|
|
|
|
{
|
|
|
|
float fBuffer = 0;
|
|
|
|
double xTera = 1099511627776.0;
|
|
|
|
double xGiga = 1073741824.0;
|
|
|
|
double xMega = 1048576.0;
|
|
|
|
double xKilo = 1024.0;
|
|
|
|
CMainDocument* pDoc = wxGetApp().GetDocument();
|
|
|
|
|
|
|
|
wxASSERT(NULL != pDoc);
|
|
|
|
wxASSERT(wxDynamicCast(pDoc, CMainDocument));
|
|
|
|
|
|
|
|
strBuffer.Clear();
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|