summaryrefslogtreecommitdiff
authorllornkcor <llornkcor>2002-07-20 19:45:16 (UTC)
committer llornkcor <llornkcor>2002-07-20 19:45:16 (UTC)
commitf095be190be0bcacd7911c585d034fd031e16099 (patch) (unidiff)
treeb54bdc4dbf17e9b1b7799db3121fc71dd2d45dcd
parent62e980bfddd33cbd66cccd4c013780ec6e964523 (diff)
downloadopie-f095be190be0bcacd7911c585d034fd031e16099.zip
opie-f095be190be0bcacd7911c585d034fd031e16099.tar.gz
opie-f095be190be0bcacd7911c585d034fd031e16099.tar.bz2
fix
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/tools/formatter/formatter.cpp17
1 files changed, 9 insertions, 8 deletions
diff --git a/noncore/tools/formatter/formatter.cpp b/noncore/tools/formatter/formatter.cpp
index d52a4be..bd0bb01 100644
--- a/noncore/tools/formatter/formatter.cpp
+++ b/noncore/tools/formatter/formatter.cpp
@@ -377,193 +377,194 @@ void FormatterApp::deviceComboSelected(int index) {
377 long mult = (*it)->blockSize() / 1024; 377 long mult = (*it)->blockSize() / 1024;
378 long div = 1024 / (*it)->blockSize(); 378 long div = 1024 / (*it)->blockSize();
379 if ( !mult ) mult = 1; 379 if ( !mult ) mult = 1;
380 if ( !div ) div = 1; 380 if ( !div ) div = 1;
381 long total = (*it)->totalBlocks() * mult / div; 381 long total = (*it)->totalBlocks() * mult / div;
382 long totalMb = total/1024; 382 long totalMb = total/1024;
383 long avail = (*it)->availBlocks() * mult / div; 383 long avail = (*it)->availBlocks() * mult / div;
384 long availMb = avail/1024; 384 long availMb = avail/1024;
385 long used = total - avail; 385 long used = total - avail;
386 long usedMb = used/1024; 386 long usedMb = used/1024;
387 totalS.sprintf(tr("Total: %1 kB ( %d mB)\n").arg( total ), totalMb ); 387 totalS.sprintf(tr("Total: %1 kB ( %d mB)\n").arg( total ), totalMb );
388 usedS.sprintf(tr("Used: %1 kB ( %d mB)\n").arg(used) ,usedMb); 388 usedS.sprintf(tr("Used: %1 kB ( %d mB)\n").arg(used) ,usedMb);
389 avS.sprintf( tr("Available: %1 kB ( %d mB)").arg(avail), availMb ); 389 avS.sprintf( tr("Available: %1 kB ( %d mB)").arg(avail), availMb );
390 } 390 }
391 } 391 }
392 fsType = getFileSystemType((const QString &)selectedText); 392 fsType = getFileSystemType((const QString &)selectedText);
393 393
394 TextLabel5->setText("Type: "+ nameS+" Formatted with "+ fsType + " \n" + totalS + usedS + avS); 394 TextLabel5->setText("Type: "+ nameS+" Formatted with "+ fsType + " \n" + totalS + usedS + avS);
395// storageComboSelected(0); 395// storageComboSelected(0);
396} 396}
397 397
398void FormatterApp::cleanUp() { 398void FormatterApp::cleanUp() {
399 399
400} 400}
401 401
402 402
403void FormatterApp::editFstab() { 403void FormatterApp::editFstab() {
404 QCopEnvelope e("QPE/Application/textedit","setDocument(QString)"); 404 QCopEnvelope e("QPE/Application/textedit","setDocument(QString)");
405 e << (const QString &)"/etc/fstab"; 405 e << (const QString &)"/etc/fstab";
406} 406}
407 407
408void FormatterApp::parsetab(const QString &fileName) { 408void FormatterApp::parsetab(const QString &fileName) {
409 409
410 fileSystemTypeList.clear(); 410 fileSystemTypeList.clear();
411 fsList.clear(); 411 fsList.clear();
412 struct mntent *me; 412 struct mntent *me;
413// if(fileName == "/etc/mtab") { 413// if(fileName == "/etc/mtab") {
414 FILE *mntfp = setmntent( fileName.latin1(), "r" ); 414 FILE *mntfp = setmntent( fileName.latin1(), "r" );
415 if ( mntfp ) { 415 if ( mntfp ) {
416 while ( (me = getmntent( mntfp )) != 0 ) { 416 while ( (me = getmntent( mntfp )) != 0 ) {
417 QString deviceName = me->mnt_fsname; 417 QString deviceName = me->mnt_fsname;
418 QString filesystemType = me->mnt_type; 418 QString filesystemType = me->mnt_type;
419 if(deviceName != "none") { 419 if(deviceName != "none") {
420 if( fsList.contains(filesystemType) == 0 420 if( fsList.contains(filesystemType) == 0
421 & filesystemType.find("proc",0,TRUE) == -1 421 & filesystemType.find("proc",0,TRUE) == -1
422 & filesystemType.find("cramfs",0,TRUE) == -1 422 & filesystemType.find("cramfs",0,TRUE) == -1
423 & filesystemType.find("auto",0,TRUE) == -1) 423 & filesystemType.find("auto",0,TRUE) == -1)
424 fsList << filesystemType; 424 fsList << filesystemType;
425 deviceList << deviceName; 425 deviceList << deviceName;
426 qDebug(deviceName+"::"+filesystemType); 426 qDebug(deviceName+"::"+filesystemType);
427 fileSystemTypeList << deviceName+"::"+filesystemType; 427 fileSystemTypeList << deviceName+"::"+filesystemType;
428 } 428 }
429 } 429 }
430 } 430 }
431 endmntent( mntfp ); 431 endmntent( mntfp );
432// } else if(fileName == "/etc/fstab") { 432// } else if(fileName == "/etc/fstab") {
433// QFile f("/etc/fstab"); 433// QFile f("/etc/fstab");
434// if ( f.open(IO_ReadOnly) ) { 434// if ( f.open(IO_ReadOnly) ) {
435// QTextStream t (&f); 435// QTextStream t (&f);
436// QString s; 436// QString s;
437// while (! t.eof()) { 437// while (! t.eof()) {
438// s=t.readLine(); 438// s=t.readLine();
439// s=s.simplifyWhiteSpace(); 439// s=s.simplifyWhiteSpace();
440// if ( (!s.isEmpty() ) && (s.find(" ")!=0) ) { 440// if ( (!s.isEmpty() ) && (s.find(" ")!=0) ) {
441// // = me->mnt_fsname; 441// // = me->mnt_fsname;
442// QString filesystemType = me->mnt_type; 442// QString filesystemType = me->mnt_type;
443// QString deviceName = s.left(0,s.find(BLANK) ); 443// QString deviceName = s.left(0,s.find(BLANK) );
444// s=s.remove(0,s.find(BLANK)+1 ); // devicename 444// s=s.remove(0,s.find(BLANK)+1 ); // devicename
445 445
446// s=s.remove(0,s.find(BLANK)+1 ); // mountpoint 446// s=s.remove(0,s.find(BLANK)+1 ); // mountpoint
447// QStringt mountPoint= s.left(0,s.find(BLANK) ); 447// QStringt mountPoint= s.left(0,s.find(BLANK) );
448// s=s.remove(0,s.find(BLANK)+1 ); // fs 448// s=s.remove(0,s.find(BLANK)+1 ); // fs
449// QString filesystemType= s.left(0,s.find(BLANK) ); 449// QString filesystemType= s.left(0,s.find(BLANK) );
450// } 450// }
451// } 451// }
452// } 452// }
453// f.close(); 453// f.close();
454// } 454// }
455} 455}
456 456
457QString FormatterApp::getFileSystemType(const QString &currentText) { 457QString FormatterApp::getFileSystemType(const QString &currentText) {
458 458
459 parsetab("/etc/mtab"); //why did TT forget filesystem type? 459 parsetab("/etc/mtab"); //why did TT forget filesystem type?
460 460
461 for ( QStringList::Iterator it = fileSystemTypeList.begin(); it != fileSystemTypeList.end(); ++it ) { 461 for ( QStringList::Iterator it = fileSystemTypeList.begin(); it != fileSystemTypeList.end(); ++it ) {
462 QString temp = (*it); 462 QString temp = (*it);
463 if( temp.find( currentText,0,TRUE) != -1) { 463 if( temp.find( currentText,0,TRUE) != -1) {
464 return temp.right( temp.length() - temp.find("::",0,TRUE) - 2); 464 return temp.right( temp.length() - temp.find("::",0,TRUE) - 2);
465// qDebug(fsType); 465// qDebug(fsType);
466 } 466 }
467 } 467 }
468 return ""; 468 return "";
469} 469}
470 470
471bool FormatterApp::doFsck() { 471bool FormatterApp::doFsck() {
472 472
473 Output *outDlg; 473 Output *outDlg;
474 QString selectedDevice; 474 QString selectedDevice;
475//f defined(QT_QWS_IPAQ) || defined(QT_QWS_EBX) // lets test on something cheap 475#if defined(QT_QWS_IPAQ) || defined(QT_QWS_EBX)
476 selectedDevice = deviceComboBox->currentText(); 476 selectedDevice = deviceComboBox->currentText();
477//#else 477#else
478 // for testing
478// currentText = diskDevice = "/dev/fd0"; 479// currentText = diskDevice = "/dev/fd0";
479 QString umountS = "umount -v /floppy 2>&1"; 480 QString umountS = "umount -v /floppy 2>&1";
480 QString remountS = "mount -v /floppy 2>&1"; 481 QString remountS = "mount -v /floppy 2>&1";
481 selectedDevice ="/dev/fd0"; 482 selectedDevice ="/dev/fd0";
482 483
483//#endif 484#endif
484 485
485 QString fsType = getFileSystemType((const QString &)selectedDevice); 486 QString fsType = getFileSystemType((const QString &)selectedDevice);
486 QString cmd; 487 QString cmd;
487 qDebug( selectedDevice +" "+ fsType); 488 qDebug( selectedDevice +" "+ fsType);
488 if(fsType == "vfat") cmd = "dosfsck -vy "; 489 if(fsType == "vfat") cmd = "dosfsck -vy ";
489 if(fsType == "ext2") cmd = "e2fsck -cpvy "; 490 if(fsType == "ext2") cmd = "e2fsck -cpvy ";
490 cmd += selectedDevice + " 2>&1"; 491 cmd += selectedDevice + " 2>&1";
491 492
492 outDlg = new Output(this, tr("Formatter Output"),FALSE); 493 outDlg = new Output(this, tr("Formatter Output"),FALSE);
493 outDlg->showMaximized(); 494 outDlg->showMaximized();
494 outDlg->show(); 495 outDlg->show();
495 qApp->processEvents(); 496 qApp->processEvents();
496 FILE *fp; 497 FILE *fp;
497 char line[130]; 498 char line[130];
498 outDlg->OutputEdit->append( tr("Trying to umount.")); 499 outDlg->OutputEdit->append( tr("Trying to umount."));
499 outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); 500 outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE);
500 501
501 sleep(1); 502 sleep(1);
502// qDebug("Command is "+umountS); 503// qDebug("Command is "+umountS);
503 fp = popen( (const char *) umountS, "r"); 504 fp = popen( (const char *) umountS, "r");
504// qDebug("%d", fp); 505// qDebug("%d", fp);
505 if ( !fp ) { 506 if ( !fp ) {
506 qDebug("Could not execute '" + umountS + "'!\n" +(QString)strerror(errno)); 507 qDebug("Could not execute '" + umountS + "'!\n" +(QString)strerror(errno));
507 QMessageBox::warning( this, tr("Formatter"), tr("umount failed!"), tr("&OK") ); 508 QMessageBox::warning( this, tr("Formatter"), tr("umount failed!"), tr("&OK") );
508 pclose(fp); 509 pclose(fp);
509 return false; 510 return false;
510 } else { 511 } else {
511// outDlg->OutputEdit->append( currentText + tr("\nhas been successfully umounted.")); 512// outDlg->OutputEdit->append( currentText + tr("\nhas been successfully umounted."));
512// outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); 513// outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE);
513 while ( fgets( line, sizeof line, fp)) { 514 while ( fgets( line, sizeof line, fp)) {
514 if( ((QString)line).find("busy",0,TRUE) != -1) { 515 if( ((QString)line).find("busy",0,TRUE) != -1) {
515 qDebug("Could not find '" + umountS); 516 qDebug("Could not find '" + umountS);
516 QMessageBox::warning( this, tr("Formatter"), tr("Could not umount.\nDevice is busy!"), tr("&OK") ); 517 QMessageBox::warning( this, tr("Formatter"), tr("Could not umount.\nDevice is busy!"), tr("&OK") );
517 pclose(fp); 518 pclose(fp);
518 return false; 519 return false;
519 } else { 520 } else {
520 QString lineStr = line; 521 QString lineStr = line;
521 lineStr=lineStr.left(lineStr.length()-1); 522 lineStr=lineStr.left(lineStr.length()-1);
522 outDlg->OutputEdit->append(lineStr); 523 outDlg->OutputEdit->append(lineStr);
523 outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); 524 outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE);
524 } 525 }
525 } 526 }
526 } 527 }
527 pclose(fp); 528 pclose(fp);
528///////////////////////////////////// 529/////////////////////////////////////
529 fp = popen( (const char *) cmd, "r"); 530 fp = popen( (const char *) cmd, "r");
530 while ( fgets( line, sizeof line, fp)) { 531 while ( fgets( line, sizeof line, fp)) {
531 if( ((QString)line).find("No such device",0,TRUE) != -1) { 532 if( ((QString)line).find("No such device",0,TRUE) != -1) {
532 qDebug("No such device '" + umountS); 533 qDebug("No such device '" + umountS);
533 QMessageBox::warning( this, tr("Formatter"), tr("No such device!"), tr("&OK") ); 534 QMessageBox::warning( this, tr("Formatter"), tr("No such device!"), tr("&OK") );
534 pclose(fp); 535 pclose(fp);
535// outDlg->OutputEdit->append("No such device"); 536// outDlg->OutputEdit->append("No such device");
536// outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); 537// outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE);
537 return false; 538 return false;
538 } else { 539 } else {
539 QString lineStr = line; 540 QString lineStr = line;
540 lineStr=lineStr.left(lineStr.length()-1); 541 lineStr=lineStr.left(lineStr.length()-1);
541 outDlg->OutputEdit->append(lineStr); 542 outDlg->OutputEdit->append(lineStr);
542 outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); 543 outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE);
543 } 544 }
544 } 545 }
545 outDlg->OutputEdit->append(tr("You can now close the output window.")); 546 outDlg->OutputEdit->append(tr("You can now close the output window."));
546 outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); 547 outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE);
547// outDlg->OutputEdit->append( currentText + tr("\nhas been successfully formatted.")); 548// outDlg->OutputEdit->append( currentText + tr("\nhas been successfully formatted."));
548// outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); 549// outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE);
549 pclose(fp); 550 pclose(fp);
550 551
551///////////////////////////////////////// 552/////////////////////////////////////////
552 553
553 return true; 554 return true;
554} 555}
555 556
556bool FormatterApp::doFsckCheck() { 557bool FormatterApp::doFsckCheck() {
557 558
558 return FALSE; 559 return FALSE;
559} 560}
560 561
561int FormatterApp::formatCheck(const QString &deviceStr) { 562int FormatterApp::formatCheck(const QString &deviceStr) {
562 563
563 return -1; 564 return -1;
564} 565}
565 566
566int FormatterApp::runCommand(const QString &command) { 567int FormatterApp::runCommand(const QString &command) {
567 568
568 return -1; 569 return -1;
569} 570}