-rw-r--r-- | noncore/tools/formatter/formatter.cpp | 125 | ||||
-rw-r--r-- | noncore/tools/formatter/formatter.h | 16 |
2 files changed, 108 insertions, 33 deletions
diff --git a/noncore/tools/formatter/formatter.cpp b/noncore/tools/formatter/formatter.cpp index 8c8ef2a..0dd42c8 100644 --- a/noncore/tools/formatter/formatter.cpp +++ b/noncore/tools/formatter/formatter.cpp | |||
@@ -33,32 +33,34 @@ | |||
33 | #include <qmessagebox.h> | 33 | #include <qmessagebox.h> |
34 | #include <qregexp.h> | 34 | #include <qregexp.h> |
35 | 35 | ||
36 | #include <qlabel.h> | 36 | #include <qlabel.h> |
37 | #include <qlineedit.h> | 37 | #include <qlineedit.h> |
38 | #include <qpushbutton.h> | 38 | #include <qpushbutton.h> |
39 | #include <qtabwidget.h> | 39 | #include <qtabwidget.h> |
40 | #include <qwidget.h> | 40 | #include <qwidget.h> |
41 | #include <qlayout.h> | 41 | #include <qlayout.h> |
42 | #include <qvariant.h> | 42 | #include <qvariant.h> |
43 | 43 | ||
44 | #include <unistd.h> | 44 | #include <unistd.h> |
45 | #include <stdio.h> | 45 | #include <stdio.h> |
46 | #include <stdlib.h> | 46 | #include <stdlib.h> |
47 | #include <sys/vfs.h> | 47 | #include <sys/vfs.h> |
48 | #include <mntent.h> | 48 | #include <mntent.h> |
49 | #include <string.h> | ||
50 | #include <errno.h> | ||
49 | 51 | ||
50 | #define BLANK ' ' | 52 | #define BLANK ' ' |
51 | #define DELIMITER '#' | 53 | #define DELIMITER '#' |
52 | 54 | ||
53 | /* | 55 | /* |
54 | Blah blah blah blah */ | 56 | Blah blah blah blah */ |
55 | FormatterApp::FormatterApp( QWidget* parent, const char* name, bool modal, WFlags fl ) | 57 | FormatterApp::FormatterApp( QWidget* parent, const char* name, bool modal, WFlags fl ) |
56 | : QMainWindow( parent, name, fl ) | 58 | : QMainWindow( parent, name, fl ) |
57 | // : QDialog( parent, name, modal, fl ) | 59 | // : QDialog( parent, name, modal, fl ) |
58 | { | 60 | { |
59 | if ( !name ) | 61 | if ( !name ) |
60 | setName( "FormatterApp" ); | 62 | setName( "FormatterApp" ); |
61 | connect( qApp,SIGNAL( aboutToQuit()),SLOT( cleanUp()) ); | 63 | connect( qApp,SIGNAL( aboutToQuit()),SLOT( cleanUp()) ); |
62 | 64 | ||
63 | setCaption( tr( "Formatter" ) ); | 65 | setCaption( tr( "Formatter" ) ); |
64 | FormatterAppLayout = new QGridLayout( this ); | 66 | FormatterAppLayout = new QGridLayout( this ); |
@@ -162,114 +164,165 @@ FormatterApp::FormatterApp( QWidget* parent, const char* name, bool modal, WFla | |||
162 | 164 | ||
163 | /* | 165 | /* |
164 | * Destroys the object and frees any allocated resources | 166 | * Destroys the object and frees any allocated resources |
165 | frickin no duh?!? | 167 | frickin no duh?!? |
166 | */ | 168 | */ |
167 | FormatterApp::~FormatterApp() | 169 | FormatterApp::~FormatterApp() |
168 | { | 170 | { |
169 | 171 | ||
170 | } | 172 | } |
171 | 173 | ||
172 | void FormatterApp::doFormat() { | 174 | void FormatterApp::doFormat() { |
173 | int err=0; | 175 | int err=0; |
174 | Output *outDlg; | 176 | Output *outDlg; |
175 | QString umountS, remountS; | 177 | QString umountS, remountS; |
176 | QString text = storageComboBox->currentText(); | 178 | QString text = storageComboBox->currentText(); |
177 | QString currentText = storageComboBox->currentText(); | 179 | QString currentText = storageComboBox->currentText(); |
178 | QString cmd = currentText.right( currentText.length() - currentText.find(" -> ",0,TRUE) - 4); | 180 | QString cmd; |
181 | QString diskDevice = currentText.right( currentText.length() - currentText.find(" -> ",0,TRUE) - 4); | ||
182 | QString diskName = currentText.left(currentText.find(" -> ",0,TRUE)); | ||
179 | QString fs = fileSystemsCombo->currentText(); | 183 | QString fs = fileSystemsCombo->currentText(); |
180 | 184 | ||
185 | #if defined(QT_QWS_IPAQ) || defined(QT_QWS_EBX) // lets test on something cheap | ||
186 | #else | ||
187 | currentText = diskDevice = "/dev/fd0"; | ||
188 | umountS = "umount -v /floppy 2>&1"; | ||
189 | remountS = "mount -v /floppy 2>&1"; | ||
190 | #endif | ||
191 | |||
181 | if( currentText.find("CF",0,TRUE) != -1) { | 192 | if( currentText.find("CF",0,TRUE) != -1) { |
182 | umountS = "/sbin/cardctl eject"; | 193 | umountS = "umount "; |
183 | remountS = "/sbin/cardctl insert"; | 194 | remountS = "mount "; |
195 | |||
196 | // umountS = "/sbin/cardctl eject"; | ||
197 | // remountS = "/sbin/cardctl insert"; | ||
184 | } | 198 | } |
185 | if( currentText.find("SD",0,TRUE) != -1) { | 199 | if( currentText.find("SD",0,TRUE) != -1) { |
186 | umountS = "/etc/sdcontrol compeject"; | 200 | umountS = "umount "; |
187 | remountS = "/etc/sdcontrol insert"; | 201 | remountS = "mount "; |
202 | // umountS = "/etc/sdcontrol compeject"; | ||
203 | // remountS = "/etc/sdcontrol insert"; | ||
188 | } | 204 | } |
189 | 205 | ||
190 | switch ( QMessageBox::warning(this,tr("Format?!?"),tr("Really format\n") + currentText + | 206 | switch ( QMessageBox::warning(this,tr("Format?!?"),tr("Really format\n") +diskName+" "+ currentText + |
191 | tr("\nwith ") + fs + tr(" filesystem?!?"),tr("Yes"),tr("No"),0,1,1) ) { | 207 | tr("\nwith ") + fs + tr(" filesystem?!?\nYou will loose all data!!"),tr("Yes"),tr("No"),0,1,1) ) { |
192 | case 0: { | 208 | case 0: { |
193 | if(fs == "vfat") | 209 | if(fs == "vfat") |
194 | cmd = "mkdosfs " + cmd; | 210 | cmd = "mkdosfs -v " + diskDevice+" 2>&1"; |
195 | else if(fs == "ext2") | 211 | else if(fs == "ext2") |
196 | cmd = "mke2fs " + cmd; | 212 | cmd = "mke2fs -v " + diskDevice+" 2>&1"; |
197 | else { | 213 | else { |
198 | QMessageBox::warning(this, tr("Formatter"),tr("Could not format.\nUnknown type"), tr("Ok")); | 214 | QMessageBox::warning(this, tr("Formatter"),tr("Could not format.\nUnknown type"), tr("Ok")); |
199 | break; | 215 | break; |
200 | } | 216 | } |
201 | // cmd = "ls -l"; | 217 | // cmd = "ls -l"; |
202 | outDlg = new Output(this, tr("Formatter Output"),FALSE); | 218 | outDlg = new Output(this, tr("Formatter Output"),FALSE); |
203 | outDlg->showMaximized(); | 219 | outDlg->showMaximized(); |
204 | outDlg->show(); | 220 | outDlg->show(); |
205 | qApp->processEvents(); | 221 | qApp->processEvents(); |
206 | FILE *fp; | 222 | FILE *fp; |
207 | char line[130]; | 223 | char line[130]; |
208 | outDlg->OutputEdit->append( tr("Trying to eject.") + currentText ); | 224 | outDlg->OutputEdit->append( tr("Trying to umount.") + currentText ); |
225 | outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); | ||
226 | |||
209 | sleep(1); | 227 | sleep(1); |
210 | fp = popen( (const char *) umountS, "r"); | 228 | qDebug("Command is "+umountS); |
229 | fp = popen( (const char *) umountS, "r"); | ||
230 | qDebug("%d", fp); | ||
211 | if ( !fp ) { | 231 | if ( !fp ) { |
212 | qDebug("Could not execute '" + umountS + "'! err=%d", fp); | 232 | qDebug("Could not execute '" + umountS + "'! err=%d\n" +(QString)strerror(errno), err); |
213 | QMessageBox::warning( this, tr("CardMonitor"), tr("Card eject failed!"), tr("&OK") ); | 233 | QMessageBox::warning( this, tr("Formatter"), tr("umount failed!"), tr("&OK") ); |
214 | pclose(fp); | 234 | pclose(fp); |
215 | return; | 235 | return; |
216 | } else { | 236 | } else { |
217 | outDlg->OutputEdit->append( currentText + tr("\nhas been successfully ejected.")); | 237 | // outDlg->OutputEdit->append( currentText + tr("\nhas been successfully umounted.")); |
218 | 238 | // outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); | |
219 | while ( fgets( line, sizeof line, fp)) { | 239 | while ( fgets( line, sizeof line, fp)) { |
220 | outDlg->OutputEdit->append(line); | 240 | if( ((QString)line).find("busy",0,TRUE) != -1) { |
241 | qDebug("Could not find '" + umountS); | ||
242 | QMessageBox::warning( this, tr("Formatter"), tr("Could not umount.\nDevice is busy!"), tr("&OK") ); | ||
243 | pclose(fp); | ||
244 | return; | ||
245 | } else { | ||
246 | QString lineStr = line; | ||
247 | lineStr=lineStr.left(lineStr.length()-1); | ||
248 | outDlg->OutputEdit->append(lineStr); | ||
249 | outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); | ||
250 | } | ||
221 | } | 251 | } |
222 | } | 252 | } |
223 | pclose(fp); | 253 | pclose(fp); |
224 | // err = system( (const char *) umountS); | ||
225 | 254 | ||
226 | qDebug("Command would be: "+cmd); | 255 | qDebug("Command would be: "+cmd); |
227 | outDlg->OutputEdit->append( tr("Trying to format.") ); | 256 | outDlg->OutputEdit->append( tr("Trying to format.") ); |
257 | outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); | ||
228 | 258 | ||
229 | fp = popen( (const char *) cmd, "r"); | 259 | fp = popen( (const char *) cmd, "r"); |
230 | while ( fgets( line, sizeof line, fp)) { | 260 | while ( fgets( line, sizeof line, fp)) { |
231 | outDlg->OutputEdit->append(line); | 261 | if( ((QString)line).find("No such device",0,TRUE) != -1) { |
262 | qDebug("No such device '" + umountS); | ||
263 | QMessageBox::warning( this, tr("Formatter"), tr("No such device!"), tr("&OK") ); | ||
264 | pclose(fp); | ||
265 | // outDlg->OutputEdit->append("No such device"); | ||
266 | // outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); | ||
267 | return; | ||
268 | } else { | ||
269 | QString lineStr = line; | ||
270 | lineStr=lineStr.left(lineStr.length()-1); | ||
271 | outDlg->OutputEdit->append(lineStr); | ||
272 | outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); | ||
273 | } | ||
232 | } | 274 | } |
233 | outDlg->OutputEdit->append( currentText + tr("\nhas been successfully formatted.")); | 275 | outDlg->OutputEdit->append( currentText + tr("\nhas been successfully formatted.")); |
276 | outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); | ||
234 | pclose(fp); | 277 | pclose(fp); |
235 | 278 | ||
236 | outDlg->OutputEdit->append( tr("Trying to insert.") + currentText ); | 279 | outDlg->OutputEdit->append( tr("Trying to mount.") + currentText ); |
280 | outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); | ||
237 | fp = popen( (const char *) remountS, "r"); | 281 | fp = popen( (const char *) remountS, "r"); |
238 | if ( !fp) { | 282 | if ( !fp) { |
239 | qDebug("Could not execute '" + remountS + "'! err=%d", err); | 283 | qDebug("Could not execute '" + remountS + "'! err=%d\n" +(QString)strerror(errno), err); |
240 | QMessageBox::warning( this, tr("Formatter"), tr("Card insert failed!"), tr("&OK") ); | 284 | QMessageBox::warning( this, tr("Formatter"), tr("Card mount failed!"), tr("&OK") ); |
241 | 285 | ||
242 | } else { | 286 | } else { |
243 | outDlg->OutputEdit->append( currentText + tr("\nhas been successfully inserted.")); | 287 | outDlg->OutputEdit->append( currentText + tr("\nhas been successfully mounted.")); |
244 | while ( fgets( line, sizeof line, fp)) { | 288 | while ( fgets( line, sizeof line, fp)) { |
245 | outDlg->OutputEdit->append(line); | 289 | QString lineStr = line; |
290 | lineStr=lineStr.left(lineStr.length()-1); | ||
291 | outDlg->OutputEdit->append(lineStr); | ||
292 | outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); | ||
246 | } | 293 | } |
247 | } | 294 | } |
248 | pclose(fp); | 295 | pclose(fp); |
249 | sleep(1); | 296 | sleep(1); |
250 | 297 | ||
251 | outDlg->OutputEdit->append(tr("You can now close the output window.")); | 298 | outDlg->OutputEdit->append(tr("You can now close the output window.")); |
252 | outDlg->close(); | 299 | outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); |
253 | if(outDlg) | 300 | // outDlg->close(); |
254 | delete outDlg; | 301 | // if(outDlg) |
302 | // delete outDlg; | ||
255 | } | 303 | } |
256 | break; | 304 | break; |
257 | }; | 305 | }; |
258 | } | 306 | } |
259 | 307 | ||
308 | bool FormatterApp::doFdisk() { | ||
309 | return FALSE; | ||
310 | |||
311 | } | ||
312 | |||
260 | void FormatterApp::fillCombos() { | 313 | void FormatterApp::fillCombos() { |
261 | 314 | ||
262 | StorageInfo storageInfo; | 315 | StorageInfo storageInfo; |
263 | const QList<FileSystem> &fs = storageInfo.fileSystems(); | 316 | const QList<FileSystem> &fs = storageInfo.fileSystems(); |
264 | QListIterator<FileSystem> it ( fs ); | 317 | QListIterator<FileSystem> it ( fs ); |
265 | QString storage; | 318 | QString storage; |
266 | for( ; it.current(); ++it ){ | 319 | for( ; it.current(); ++it ){ |
267 | const QString name = (*it)->name(); | 320 | const QString name = (*it)->name(); |
268 | const QString path = (*it)->path(); | 321 | const QString path = (*it)->path(); |
269 | const QString disk = (*it)->disk(); | 322 | const QString disk = (*it)->disk(); |
270 | const QString options = (*it)->options(); | 323 | const QString options = (*it)->options(); |
271 | if( name.find( tr("Internal"),0,TRUE) == -1) { | 324 | if( name.find( tr("Internal"),0,TRUE) == -1) { |
272 | storageComboBox->insertItem(name +" -> "+disk); | 325 | storageComboBox->insertItem(name +" -> "+disk); |
273 | } | 326 | } |
274 | deviceComboBox->insertItem(disk); | 327 | deviceComboBox->insertItem(disk); |
275 | } | 328 | } |
@@ -393,27 +446,43 @@ void FormatterApp::parsetab() { | |||
393 | } | 446 | } |
394 | 447 | ||
395 | QString FormatterApp::getFileSystemType(const QString ¤tText) { | 448 | QString FormatterApp::getFileSystemType(const QString ¤tText) { |
396 | 449 | ||
397 | parsetab(); //why did TT forget filesystem type? | 450 | parsetab(); //why did TT forget filesystem type? |
398 | 451 | ||
399 | for ( QStringList::Iterator it = fileSystemTypeList.begin(); it != fileSystemTypeList.end(); ++it ) { | 452 | for ( QStringList::Iterator it = fileSystemTypeList.begin(); it != fileSystemTypeList.end(); ++it ) { |
400 | QString temp = (*it); | 453 | QString temp = (*it); |
401 | if( temp.find( currentText,0,TRUE) != -1) { | 454 | if( temp.find( currentText,0,TRUE) != -1) { |
402 | return temp.right( temp.length() - temp.find("::",0,TRUE) - 2); | 455 | return temp.right( temp.length() - temp.find("::",0,TRUE) - 2); |
403 | // qDebug(fsType); | 456 | // qDebug(fsType); |
404 | } | 457 | } |
405 | } | 458 | } |
406 | return ""; | 459 | return ""; |
407 | } | 460 | } |
408 | 461 | ||
409 | void FormatterApp::doFsck() { | 462 | bool FormatterApp::doFsck() { |
410 | 463 | ||
411 | QString selectedDevice = deviceComboBox->currentText(); | 464 | QString selectedDevice = deviceComboBox->currentText(); |
412 | QString fsType = getFileSystemType((const QString &)selectedDevice); | 465 | QString fsType = getFileSystemType((const QString &)selectedDevice); |
413 | QString cmd; | 466 | QString cmd; |
414 | qDebug( selectedDevice +" "+ fsType); | 467 | qDebug( selectedDevice +" "+ fsType); |
415 | if(fsType == "vfat") cmd = "dosfsck -vy "; | 468 | if(fsType == "vfat") cmd = "dosfsck -vy "; |
416 | if(fsType == "ext2") cmd = "e2fsck -cpvy "; | 469 | if(fsType == "ext2") cmd = "e2fsck -cpvy "; |
417 | cmd += selectedDevice; | 470 | cmd += selectedDevice; |
418 | 471 | ||
472 | |||
473 | return FALSE; | ||
474 | } | ||
475 | |||
476 | bool FormatterApp::doFsckCheck() { | ||
477 | return FALSE; | ||
478 | } | ||
479 | |||
480 | int FormatterApp::formatCheck(const QString &deviceStr) { | ||
481 | |||
482 | return -1; | ||
483 | } | ||
484 | |||
485 | int FormatterApp::runCommand(const QString &command) { | ||
486 | |||
487 | return -1; | ||
419 | } | 488 | } |
diff --git a/noncore/tools/formatter/formatter.h b/noncore/tools/formatter/formatter.h index a566ec0..871054d 100644 --- a/noncore/tools/formatter/formatter.h +++ b/noncore/tools/formatter/formatter.h | |||
@@ -30,30 +30,36 @@ class FormatterApp : public QMainWindow | |||
30 | Q_OBJECT | 30 | Q_OBJECT |
31 | 31 | ||
32 | public: | 32 | public: |
33 | FormatterApp( QWidget* parent = 0, const char* name = 0, bool modal = FALSE, WFlags fl = 0 ); | 33 | FormatterApp( QWidget* parent = 0, const char* name = 0, bool modal = FALSE, WFlags fl = 0 ); |
34 | ~FormatterApp(); | 34 | ~FormatterApp(); |
35 | 35 | ||
36 | QTabWidget *TabWidget; | 36 | QTabWidget *TabWidget; |
37 | QWidget *tab, *tab_2;; | 37 | QWidget *tab, *tab_2;; |
38 | QLabel *TextLabel1, *TextLabel2, *TextLabel3, *TextLabel4, *TextLabel5; | 38 | QLabel *TextLabel1, *TextLabel2, *TextLabel3, *TextLabel4, *TextLabel5; |
39 | QComboBox *storageComboBox, *fileSystemsCombo, *deviceComboBox; | 39 | QComboBox *storageComboBox, *fileSystemsCombo, *deviceComboBox; |
40 | QPushButton *formatPushButton, *editPushButton, *fsckButton; | 40 | QPushButton *formatPushButton, *editPushButton, *fsckButton; |
41 | QLineEdit* mountPointLineEdit; | 41 | QLineEdit* mountPointLineEdit; |
42 | QStringList fileSystemTypeList, fsList; | 42 | QStringList fileSystemTypeList, fsList; |
43 | protected: | 43 | protected: |
44 | QGridLayout *FormatterAppLayout, *tabLayout, *tabLayout_2; | 44 | QGridLayout *FormatterAppLayout, *tabLayout, *tabLayout_2; |
45 | QString getFileSystemType(const QString &); | 45 | QString getFileSystemType(const QString &); |
46 | |||
47 | void fillCombos(); | ||
48 | void parsetab(); | ||
49 | bool doFdisk(); | ||
50 | int formatCheck(const QString &); | ||
51 | int runCommand(const QString &); | ||
46 | 52 | ||
47 | protected slots: | 53 | protected slots: |
48 | void doFormat(); | ||
49 | void fillCombos(); | ||
50 | void cleanUp(); | 54 | void cleanUp(); |
55 | void doFormat(); | ||
56 | void editFstab(); | ||
57 | bool doFsck(); | ||
58 | bool doFsckCheck(); | ||
59 | |||
51 | void fsComboSelected(int); | 60 | void fsComboSelected(int); |
52 | void storageComboSelected(int ); | 61 | void storageComboSelected(int ); |
53 | void deviceComboSelected(int ); | 62 | void deviceComboSelected(int ); |
54 | void editFstab(); | ||
55 | void parsetab(); | ||
56 | void doFsck(); | ||
57 | }; | 63 | }; |
58 | 64 | ||
59 | #endif // FORMATTERAPP_H | 65 | #endif // FORMATTERAPP_H |