00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include "revmanager.h"
00011
00012
00013 RevManager::RevManager(QWidget* parent, const char* name, WFlags fl)
00014 : revManagerDlg(parent,name,fl)
00015 {
00016 mainWin = parent;
00017 proc = new QProcess();
00018
00019 strcpy(deviceRev,RevDevice().ascii());
00020
00021
00022 connect( proc, SIGNAL(readyReadStdout()), this, SLOT(readFromStdErrOut()) );
00023 connect( proc, SIGNAL(readyReadStderr()), this, SLOT(readFromStdErrOut()) );
00024 }
00025
00026
00027 RevManager::~RevManager()
00028 {
00029 delete proc;
00030 proc = NULL;
00031 }
00032
00033
00034 void RevManager::Init(bool *mounted)
00035 {
00036 revMounted = mounted;
00037 if (*revMounted == FALSE)
00038 {
00039 if (MountRev() == TRUE)
00040 {
00041 *revMounted = TRUE;
00042 ledStatus->setColor(Qt::green);
00043 this->UpdatePgbUsage();
00044 }
00045 else
00046 {
00047 *revMounted = FALSE;
00048 ledStatus->setColor(Qt::red);
00049 pgbUsage->setProgress(0);
00050 }
00051 }
00052 else
00053 {
00054 this->UpdatePgbUsage();
00055 }
00056 }
00057
00058
00059 void RevManager::UpdatePgbUsage()
00060 {
00061 QTextStream t (dfStringErrOut, IO_ReadOnly);
00062 QString s;
00063
00064 dfStringErrOut="";
00065
00066 proc->clearArguments();
00067
00068 proc->addArgument("df");
00069 proc->addArgument("-hT");
00070 proc->addArgument("--type=udf");
00071 proc->addArgument("--sync");
00072
00073 proc->start();
00074
00075 while (proc->isRunning())
00076 {
00077 qApp->processEvents();
00078 }
00079
00080
00081 s = t.readLine();
00082 if ( (s.isEmpty()) || ( s.left(10) != "Filesystem" ) )
00083 {
00084
00085 QMessageBox::critical(this,"Error","Error running df command!",
00086 QMessageBox::Ok,QMessageBox::NoButton,QMessageBox::NoButton);
00087 return;
00088 }
00089
00090
00091 while (!t.eof())
00092 {
00093 s = t.readLine();
00094 s = s.simplifyWhiteSpace();
00095 if (!s.isEmpty())
00096 {
00097 if (s.find(' ') < 0)
00098 {
00099 if (!t.eof())
00100 {
00101 s = s.append(t.readLine());
00102 s = s.simplifyWhiteSpace();
00103 }
00104 }
00105
00106 if(s.left(s.find(' ')) == deviceRev)
00107 {
00108 QString p;
00109
00110 s = s.remove(0,s.find(' ')+1);
00111
00112 s = s.remove(0,s.find(' ')+1);
00113
00114
00115 s = s.remove(0,s.find(' ')+1);
00116
00117 spaceUsed = s.left(s.find(' '));
00118 lblUsed->setText("Used space: " + spaceUsed);
00119 s = s.remove(0,s.find(' ')+1);
00120
00121 spaceFree = s.left(s.find(' '));
00122 lblFree->setText("Free space: " + spaceFree);
00123 s = s.remove(0,s.find(' ')+1);
00124
00125 p = s.left(s.find(' '));
00126 p = p.remove('%');
00127 percent = p.toInt();
00128 pgbUsage->setProgress(percent);
00129
00130 s = "";
00131 }
00132 }
00133 }
00134 }
00135
00136
00137 void RevManager::btnFormat_clicked()
00138 {
00139 if (*revMounted == TRUE)
00140 {
00141 if (UmountRev() == TRUE)
00142 {
00143 *revMounted = FALSE;
00144 ledStatus->setColor(Qt::red);
00145 pgbUsage->setProgress(0);
00146 lblUsed->setText("Used space: ");
00147 lblFree->setText("Free space: ");
00148 }
00149 else
00150 {
00151 *revMounted = TRUE;
00152
00153 QMessageBox::critical(this,"Error","Unable to umount Rev!",
00154 QMessageBox::Ok,QMessageBox::NoButton,QMessageBox::NoButton);
00155 return;
00156 }
00157 }
00158 else
00159 {
00160
00161
00162 if (MountRev() == FALSE)
00163 {
00164
00165
00166 QMessageBox::critical(this,"Error","Rev Error!",
00167 QMessageBox::Ok,QMessageBox::NoButton,QMessageBox::NoButton);
00168 return;
00169 }
00170 if (UmountRev() == FALSE)
00171 {
00172
00173
00174 QMessageBox::critical(this,"Error","Rev Error!",
00175 QMessageBox::Ok,QMessageBox::NoButton,QMessageBox::NoButton);
00176 pgbUsage->setProgress(0);
00177 lblUsed->setText("Used space: ");
00178 lblFree->setText("Free space: ");
00179 }
00180 }
00181
00182 if( QMessageBox::warning(this,"Format","Do you want to format Rev?\n\nAll data will be lost!", "Format","Cancel", 0, 0, 1 ) == 0)
00183 {
00184
00185
00186 proc->clearArguments();
00187
00188 proc->addArgument("mkudffs");
00189 proc->addArgument(deviceRev);
00190
00191 proc->start();
00192
00193 while (proc->isRunning())
00194 {
00195 qApp->processEvents();
00196 }
00197
00198 QMessageBox::information(this,"Finish","Rev formatted successfully!",
00199 QMessageBox::Ok,QMessageBox::NoButton,QMessageBox::NoButton);
00200 }
00201 }
00202
00203
00204 void RevManager::btnMount_clicked()
00205 {
00206 if (*revMounted == TRUE)
00207 {
00208 if (UmountRev() == TRUE)
00209 {
00210 EjectRev();
00211 *revMounted = FALSE;
00212 ledStatus->setColor(Qt::red);
00213 pgbUsage->setProgress(0);
00214 lblUsed->setText("Used space: ");
00215 lblFree->setText("Free space: ");
00216 }
00217 else
00218 {
00219 *revMounted = TRUE;
00220
00221 QMessageBox::critical(this,"Error","Unable to umount Rev!",
00222 QMessageBox::Ok,QMessageBox::NoButton,QMessageBox::NoButton);
00223 }
00224 }
00225 else
00226 {
00227 if (MountRev() == TRUE)
00228 {
00229 *revMounted = TRUE;
00230 ledStatus->setColor(Qt::green);
00231 this->UpdatePgbUsage();
00232 }
00233 else
00234 {
00235 *revMounted = FALSE;
00236
00237 QMessageBox::critical(this,"Error","Unable to mount Rev!",
00238 QMessageBox::Ok,QMessageBox::NoButton,QMessageBox::NoButton);
00239 }
00240 }
00241 }
00242
00243
00244 void RevManager::btnCancel_clicked()
00245 {
00246 this->Close();
00247 }
00248
00249
00250 void RevManager::closeEvent (QCloseEvent *e)
00251 {
00252 e->accept();
00253 this->Close();
00254 }
00255
00256
00257 void RevManager::Close()
00258 {
00259 this->hide();
00260 mainWin->setEnabled(TRUE);
00261 }
00262
00263
00264 void RevManager::readFromStdErrOut()
00265 {
00266 dfStringErrOut.append(proc->readStdout());
00267 }
00268
00269 #include "revmanager.moc"
00270