00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "DfRioWindow.h"
00019
00020 #include <string>
00021 #include <vector>
00022 using namespace std;
00023
00024 #include <qmessagebox.h>
00025 #include <qapplication.h>
00026
00027 #include "Events.h"
00028 #include "RioQt.h"
00029
00030 DfRioWindow::DfRioWindow( QWidget *parent,
00031 FileWindow *rioFW,
00032 const char *name,
00033 WFlags f )
00034 : QMainWindow( parent, name, f )
00035 {
00036 dfList = new QListView( this );
00037
00038 this->rioFW = rioFW;
00039
00040 setCaption( tr( "Disk information at server " ) + rioFW->getHost() );
00041 setCentralWidget( dfList );
00042
00043
00044 dfList->addColumn( tr( "Machine" ) );
00045 dfList->addColumn( tr( "Device" ) );
00046 dfList->addColumn( tr( "Used Size" ) );
00047 dfList->addColumn( tr( "Free Size" ) );
00048 dfList->addColumn( tr( "Total Size" ) );
00049 dfList->addColumn( tr( "Percent Used" ) );
00050 dfList->addColumn( tr( "Percent Free" ) );
00051
00052
00053 dfList->setColumnAlignment( USED_SIZE_COLUMN, Qt::AlignRight );
00054 dfList->setColumnAlignment( FREE_SIZE_COLUMN, Qt::AlignRight );
00055 dfList->setColumnAlignment( TOTAL_SIZE_COLUMN, Qt::AlignRight );
00056 dfList->setColumnAlignment( PERCENT_USED_COLUMN, Qt::AlignRight );
00057 dfList->setColumnAlignment( PERCENT_FREE_COLUMN, Qt::AlignRight );
00058
00059 dfList->setRootIsDecorated( true );
00060 dfList->setShowSortIndicator( true );
00061
00062 getDiskInfo();
00063 }
00064
00065
00066
00067
00068 void DfRioWindow::closeEvent( QCloseEvent * closeEvent )
00069 {
00070 WindowClosedEvent *event;
00071
00072 event = new WindowClosedEvent( this );
00073 QApplication::postEvent( rioFW->getRioQt(), event );
00074
00075 closeEvent->accept();
00076 }
00077
00078
00079
00080
00081
00082
00083 void DfRioWindow::getDiskInfo( void )
00084 {
00085 vector<DfInfo> info;
00086 double percent_total;
00087 double percent_free_total;
00088 double percent;
00089 RioObjectSize usedsize_total;
00090 RioObjectSize freesize_total;
00091 RioObjectSize size_total;
00092
00093
00094
00095 dfList->clear();
00096
00097 if( rioFW->df( &info ) )
00098 {
00099 for( unsigned int node = 0; node < info.size(); node++ )
00100 {
00101 percent_total = 0;
00102 percent_free_total = 0;
00103 usedsize_total = 0;
00104 freesize_total = 0;
00105 size_total = 0;
00106
00107 for( unsigned int disk = 0;
00108 disk < info[ node ].storage_df_info.size();
00109 disk++ )
00110 {
00111 QListViewItem *item = new QListViewItem( dfList );
00112
00113 item->setText( MACHINE_COLUMN,
00114 QString( info[node].storage_df_info[disk].hostname ) );
00115 item->setText( DEVICE_COLUMN,
00116 QString( info[node].storage_df_info[disk].diskname ) );
00117 item->setText( USED_SIZE_COLUMN,
00118 QString( rioFW->formatSize( info[node].storage_df_info[disk].used_size ).c_str() ) );
00119 item->setText( FREE_SIZE_COLUMN,
00120 QString( rioFW->formatSize( info[node].storage_df_info[disk].free_size ).c_str() ) );
00121 item->setText( TOTAL_SIZE_COLUMN,
00122 QString( rioFW->formatSize( info[node].storage_df_info[disk].size ).c_str() ) );
00123
00124 percent = info[node].storage_df_info[disk].used_blocks * 100.0
00125 / info[node].storage_df_info[disk].total_blocks;
00126 item->setText( PERCENT_USED_COLUMN,
00127 QString( "%1 %%" ).arg( percent, 0, 'f', 2 ) );
00128
00129 percent_total += percent;
00130 percent = 100.0 - percent;
00131
00132 item->setText( PERCENT_FREE_COLUMN,
00133 QString( "%1 %%" ).arg( percent, 0, 'f', 2 ) );
00134
00135 percent_free_total += percent;
00136
00137 usedsize_total += info[node].storage_df_info[disk].used_size;
00138 freesize_total += info[node].storage_df_info[disk].free_size;
00139 size_total += info[node].storage_df_info[disk].size;
00140 }
00141
00142 QListViewItem *totalItem = new QListViewItem( dfList );
00143
00144 totalItem->setText( MACHINE_COLUMN, "Total" );
00145 totalItem->setText( DEVICE_COLUMN, "" );
00146 totalItem->setText( USED_SIZE_COLUMN,
00147 QString( rioFW->formatSize( usedsize_total ).c_str() ) );
00148 totalItem->setText( FREE_SIZE_COLUMN,
00149 QString( rioFW->formatSize( freesize_total ).c_str() ) );
00150 totalItem->setText( TOTAL_SIZE_COLUMN,
00151 QString( rioFW->formatSize( size_total ).c_str() ) );
00152
00153 percent_total /= info[ node ].storage_df_info.size();
00154
00155 totalItem->setText( PERCENT_USED_COLUMN,
00156 QString( "%1 %%" ).arg( percent_total, 0, 'f', 2 ) );
00157
00158 percent_free_total /= info[ node ].storage_df_info.size();
00159
00160 totalItem->setText( PERCENT_FREE_COLUMN,
00161 QString( "%1 %%" ).arg( percent_free_total, 0, 'f', 2 ) );
00162 }
00163
00164 disk_status = true;
00165 }
00166 else
00167 {
00168 ShowMessageEvent * event = new ShowMessageEvent( ShowMessageEvent::ERROR,
00169 tr( "Could not retrieve disk info from server " ) +
00170 rioFW->getHost() + "." );
00171 QApplication::postEvent( rioFW->getRioQt(), event );
00172 disk_status = false;
00173 }
00174 }
00175
00176
00177
00178
00179 bool DfRioWindow::getDiskStatus( void )
00180 {
00181 return disk_status;
00182 }
00183