#include "hddWindow.h" HDDWindow::HDDWindow( int chans, QWidget* parentCP, QWidget* parent ) : QMainWindow( parentCP ) { // Copy parameter to a member variable. channels = chans; // Connect the signal. connect( this, SIGNAL( lowHDD( double, double, double, int ) ), parentCP, SLOT( setHDDStatus( double, double, double, int ) ) ); // Initialize the arrays of doubles for determining actual recording speed. lastUsedSize = new double[ channels ]; curUsedSize = new double[ channels ]; newData = new bool[ channels ]; timeL = new double[ channels ]; for( int z = 0; z < channels; ++ z ) { lastUsedSize[z] = 0.0; curUsedSize[z] = 0.0; timeL[z] = 0.0; newData[z] = false; } warningPlayed = false; rightThemeSelected = false; // Set the window name. setObjectName( "HDD Status Window" ); setWindowTitle( "HDD Status Window" ); // Create the grid layout. layout = new QGridLayout; // Create the labels. colLabels[0] = new QLabel( tr( "Channel #" ) ); colLabels[1] = new QLabel( tr( "Est. Rec. Speed (MB/s)" ) ); colLabels[2] = new QLabel( tr( "Actual Rec. Speed (MB/s)" ) ); colLabels[3] = new QLabel( tr( "Total Space (GB)" ) ); colLabels[4] = new QLabel( tr( "Free Space (GB)" ) ); colLabels[5] = new QLabel( tr( "Time Left (Actual)" ) ); colLabels[6] = new QLabel( tr( "Status LED" ) ); // Create the row labels. rowLabels = new QLabel*[ channels ]; for( int i = 0; i < channels; ++i ) { QString name = "Channel "; QString num; num.setNum( i+1 ); name.append( num ); name.append( ": " ); rowLabels[i] = new QLabel( name.toStdString().c_str() ); } // Create the QLineEdit objects. estRec = new QLineEdit*[ channels ]; actRec = new QLineEdit*[ channels ]; totalSpace = new QLineEdit*[ channels ]; freeSpace = new QLineEdit*[ channels ]; timeLeft = new QLineEdit*[ channels ]; for( int l = 0; l < channels; ++l ) { estRec[l] = new QLineEdit( "-1" ); estRec[l]->setReadOnly( true ); actRec[l] = new QLineEdit( "-1" ); actRec[l]->setReadOnly( true ); totalSpace[l] = new QLineEdit( "-1" ); totalSpace[l]->setReadOnly( true ); freeSpace[l] = new QLineEdit( "-1" ); freeSpace[l]->setReadOnly( true ); timeLeft[l] = new QLineEdit( "-1" ); timeLeft[l]->setReadOnly( true ); estRec[l]->setAlignment( Qt::AlignRight ); actRec[l]->setAlignment( Qt::AlignRight ); totalSpace[l]->setAlignment( Qt::AlignRight ); freeSpace[l]->setAlignment( Qt::AlignRight ); timeLeft[l]->setAlignment( Qt::AlignRight ); } // Create the LEDs. ledStatus = new QFrame*[ channels ]; for( int j = 0; j < channels; ++j ) { ledStatus[j] = new QFrame( this ); QPalette palette = ledStatus[j]->palette(); palette.setColor( QPalette::Window, Qt::red ); ledStatus[j]->setPalette( palette ); ledStatus[j]->setAutoFillBackground( true ); ledStatus[j]->setFrameStyle( QFrame::Panel | QFrame::Sunken ); ledStatus[j]->setMaximumSize( 20, 20 ); ledStatus[j]->setMinimumSize( 20, 20 ); } // Add elements to the layout. // Add the column labels. for( int j = 0; j < cLabels; ++j ) { layout->addWidget( colLabels[j], 1, j, Qt::AlignCenter ); } // Add the row elements. for( int k = 0; k < channels; ++k ) { layout->addWidget( rowLabels[k], k+2, 0, Qt::AlignCenter ); layout->addWidget( estRec[k], k+2, 1, Qt::AlignCenter ); layout->addWidget( actRec[k], k+2, 2, Qt::AlignCenter ); layout->addWidget( totalSpace[k], k+2, 3, Qt::AlignCenter ); layout->addWidget( freeSpace[k], k+2, 4, Qt::AlignCenter ); layout->addWidget( timeLeft[k], k+2, 5, Qt::AlignCenter ); layout->addWidget( ledStatus[k], k+2, 6, Qt::AlignCenter ); } // Create a central widget and set the layout for the window. setCentralWidget( new QWidget() ); centralWidget()->setLayout( layout ); } HDDWindow::~HDDWindow() { } void HDDWindow::setEstRecTime( QString speed ) { for( int i = 0; i < channels; ++i ) { estRec[i]->setText( speed ); } } void HDDWindow::hddStatusData( int chan, QString total, QString used, double sec ) { // Perform the math functions first. // First, find the total space and free space in GB. double t = ( ( total.toDouble() / 1024.0 ) / 1024.0 ); double f = ( ( ( total.toDouble() - used.toDouble() ) / 1024.0 ) / 1024.0 ); // Second, find the current data recording rate. double recSpeed = 0.0; double time = 0.0; int hour, min; lastUsedSize[ chan ] = curUsedSize[ chan ]; curUsedSize[ chan ] = used.toDouble(); if( !( ( lastUsedSize[ chan ] < 0.1 ) && ( lastUsedSize[ chan ] > -0.1 ) ) ) { recSpeed = ( ( curUsedSize[ chan ] - lastUsedSize[ chan ] ) / 1024.0 ) / sec; // Speed in MB/s time = ( f * 1024 ) / recSpeed; // Time left in seconds. time = time / 60.0; // Time left in minutes. } hour = (int)time / 60; // Hours left. min = (int)time % 60; // Minutes left. timeL[ chan ] = time; // Set the QStrings to be displayed in the LineEdit boxes. QString free, speed, minutes, hours; total.setNum( t, 'f', 1 ); free.setNum( f, 'f', 1 ); speed.setNum( recSpeed, 'f', 1 ); hours.setNum( hour ); minutes.setNum( min ); freeSpace[ chan ]->setText( free ); totalSpace[ chan ]->setText( total ); actRec[ chan ]->setText( speed ); if( min < 10 ) { timeLeft[ chan ]->setText( hours + ":0" + minutes ); } else { timeLeft[ chan ]->setText( hours + ":" + minutes ); } // Check if the actual recording speed is within acceptable distance from the estimated speed. if( abs( actRec[ chan ]->text().toDouble() - estRec[ chan ]->text().toDouble() ) < 0.3 ) { QPalette palette = ledStatus[ chan ]->palette(); palette.setColor( QPalette::Window, Qt::green ); ledStatus[ chan ]->setPalette( palette ); ledStatus[ chan ]->setAutoFillBackground( true ); } else { QPalette palette = ledStatus[ chan ]->palette(); palette.setColor( QPalette::Window, Qt::red ); ledStatus[ chan ]->setPalette( palette ); ledStatus[ chan ]->setAutoFillBackground( true ); } // Check if every channel has now received new data from the update. newData[ chan ] = true; bool check = true; for( int i = 0; i < channels; ++i ) { // Check if each channel has received new data. if( !newData[i] ) { check = false; } } // All channels have received new data from update. if( check ) { // Determine the lowest HDD in terms of time. hddLowest(); // Reset the check for new data for each channel. for( int j = 0; j < channels; ++j ) { newData[j] = false; } } } void HDDWindow::hddLowest() { // Determine the which HDD has the least amount of recording time left. double lowestTime = 999999999999.0; int index = 0; for( int i = 0; i < channels; ++i ) { if( timeL[i] < lowestTime ) { lowestTime = timeL[i]; index = i; } } /*if( ( (int)timeL[ index ] < 10 ) && ( !warningPlayed ) && ( rightThemeSelected ) ) { warningPlayed = true; QSound warning( "/misc/warning.wav" ); warning.setLoops( 3 ); warning.play(); }*/ // Emit a signal back to the parent with the relevant information. emit lowHDD( actRec[index]->text().toDouble(), totalSpace[index]->text().toDouble(), freeSpace[index]->text().toDouble(), (int)timeL[index] ); } void HDDWindow::themeGood( bool toggle ) { rightThemeSelected = toggle; /*if( rightThemeSelected ) { std::cout << "BLAH" << std::endl; QSound warning( "misc/warning.wav" ); if( warning.isAvailable() ) { //warning.setLoops( 3 ); warning.play();std::cout << "BLAH AGAIN" << std::endl; } }*/ }