summaryrefslogtreecommitdiff
path: root/noncore/tools/formatter/formatter.cpp
Unidiff
Diffstat (limited to 'noncore/tools/formatter/formatter.cpp') (more/less context) (show whitespace changes)
-rw-r--r--noncore/tools/formatter/formatter.cpp174
1 files changed, 111 insertions, 63 deletions
diff --git a/noncore/tools/formatter/formatter.cpp b/noncore/tools/formatter/formatter.cpp
index 532ee40..e869317 100644
--- a/noncore/tools/formatter/formatter.cpp
+++ b/noncore/tools/formatter/formatter.cpp
@@ -10,7 +10,7 @@
10#include "inputDialog.h" 10#include "inputDialog.h"
11#include "output.h" 11#include "output.h"
12 12
13#include <qmenubar.h> 13/* OPIE */
14#include <qpe/qpetoolbar.h> 14#include <qpe/qpetoolbar.h>
15#include <qpe/qpeapplication.h> 15#include <qpe/qpeapplication.h>
16#include <qpe/resource.h> 16#include <qpe/resource.h>
@@ -19,20 +19,19 @@
19#include <qpe/qcopenvelope_qws.h> 19#include <qpe/qcopenvelope_qws.h>
20#include <qpe/storage.h> 20#include <qpe/storage.h>
21 21
22/* QT */
23#include <qmenubar.h>
22#include <qmultilineedit.h> 24#include <qmultilineedit.h>
23#include <qstring.h> 25#include <qstring.h>
24#include <qlist.h> 26#include <qlist.h>
25#include <qstringlist.h> 27#include <qstringlist.h>
26#include <qdir.h> 28#include <qdir.h>
27#include <qfile.h> 29#include <qfile.h>
28
29#include <qtstream.h> 30#include <qtstream.h>
30
31#include <qcombobox.h> 31#include <qcombobox.h>
32#include <qpopupmenu.h> 32#include <qpopupmenu.h>
33#include <qmessagebox.h> 33#include <qmessagebox.h>
34#include <qregexp.h> 34#include <qregexp.h>
35
36#include <qlabel.h> 35#include <qlabel.h>
37#include <qlineedit.h> 36#include <qlineedit.h>
38#include <qpushbutton.h> 37#include <qpushbutton.h>
@@ -41,6 +40,7 @@
41#include <qlayout.h> 40#include <qlayout.h>
42#include <qvariant.h> 41#include <qvariant.h>
43 42
43/* STD */
44#include <unistd.h> 44#include <unistd.h>
45#include <stdio.h> 45#include <stdio.h>
46#include <stdlib.h> 46#include <stdlib.h>
@@ -168,11 +168,11 @@ FormatterApp::FormatterApp( QWidget* parent, const char* name, WFlags fl, bool
168 fillCombos(); 168 fillCombos();
169} 169}
170 170
171FormatterApp::~FormatterApp() { 171FormatterApp::~FormatterApp()
172 172{}
173}
174 173
175void FormatterApp::doFormat() { 174void FormatterApp::doFormat()
175{
176 int err=0; 176 int err=0;
177 Output *outDlg; 177 Output *outDlg;
178 QString umountS, remountS; 178 QString umountS, remountS;
@@ -190,14 +190,16 @@ void FormatterApp::doFormat() {
190 remountS = "mount -v /floppy 2>&1"; 190 remountS = "mount -v /floppy 2>&1";
191#endif 191#endif
192 192
193 if( currentText.find("CF",0,TRUE) != -1) { 193 if( currentText.find("CF",0,TRUE) != -1)
194 {
194 umountS = "umount "; 195 umountS = "umount ";
195 remountS = "mount "; 196 remountS = "mount ";
196 197
197// umountS = "/sbin/cardctl eject"; 198// umountS = "/sbin/cardctl eject";
198// remountS = "/sbin/cardctl insert"; 199// remountS = "/sbin/cardctl insert";
199 } 200 }
200 if( currentText.find("SD",0,TRUE) != -1) { 201 if( currentText.find("SD",0,TRUE) != -1)
202 {
201 umountS = "umount "; 203 umountS = "umount ";
202 remountS = "mount "; 204 remountS = "mount ";
203// umountS = "/etc/sdcontrol compeject"; 205// umountS = "/etc/sdcontrol compeject";
@@ -211,20 +213,22 @@ void FormatterApp::doFormat() {
211 ,tr("No") 213 ,tr("No")
212 ,0 214 ,0
213 ,1 215 ,1
214 ,1) ) { 216 ,1) )
215 case 0: { 217 {
218 case 0:
219 {
216 if(fs == "vfat") 220 if(fs == "vfat")
217 cmd = "mkdosfs -v " + diskDevice+" 2>&1"; 221 cmd = "mkdosfs -v " + diskDevice+" 2>&1";
218 else if(fs == "ext2") 222 else if(fs == "ext2")
219 cmd = "mke2fs -v " + diskDevice+" 2>&1"; 223 cmd = "mke2fs -v " + diskDevice+" 2>&1";
220 else { 224 else
225 {
221 QMessageBox::warning(this, tr("Formatter"),tr("Could not format.\nUnknown type"), tr("Ok")); 226 QMessageBox::warning(this, tr("Formatter"),tr("Could not format.\nUnknown type"), tr("Ok"));
222 break; 227 break;
223 } 228 }
224// cmd = "ls -l"; 229// cmd = "ls -l";
225 outDlg = new Output(this, tr("Formatter Output"),FALSE); 230 outDlg = new Output(this, tr("Formatter Output"),FALSE);
226 outDlg->showMaximized(); 231 QPEApplication::showDialog( outDlg);
227 outDlg->show();
228 qApp->processEvents(); 232 qApp->processEvents();
229 FILE *fp; 233 FILE *fp;
230 char line[130]; 234 char line[130];
@@ -237,21 +241,28 @@ void FormatterApp::doFormat() {
237 qDebug("Command is "+umountS); 241 qDebug("Command is "+umountS);
238 fp = popen( (const char *) umountS, "r"); 242 fp = popen( (const char *) umountS, "r");
239 // qDebug("%d", fp); 243 // qDebug("%d", fp);
240 if ( !fp ) { 244 if ( !fp )
245 {
241 qDebug("Could not execute '" + umountS + "'! err=%d\n" +(QString)strerror(errno), err); 246 qDebug("Could not execute '" + umountS + "'! err=%d\n" +(QString)strerror(errno), err);
242 QMessageBox::warning( this, tr("Formatter"), tr("umount failed!"), tr("&OK") ); 247 QMessageBox::warning( this, tr("Formatter"), tr("umount failed!"), tr("&OK") );
243 pclose(fp); 248 pclose(fp);
244 return; 249 return;
245 } else { 250 }
251 else
252 {
246// outDlg->OutputEdit->append( currentText + tr("\nhas been successfully umounted.")); 253// outDlg->OutputEdit->append( currentText + tr("\nhas been successfully umounted."));
247// outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); 254// outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE);
248 while ( fgets( line, sizeof line, fp)) { 255 while ( fgets( line, sizeof line, fp))
249 if( ((QString)line).find("busy",0,TRUE) != -1) { 256 {
257 if( ((QString)line).find("busy",0,TRUE) != -1)
258 {
250 qDebug("Could not find '" + umountS); 259 qDebug("Could not find '" + umountS);
251 QMessageBox::warning( this, tr("Formatter"), tr("Could not umount.\nDevice is busy!"), tr("&OK") ); 260 QMessageBox::warning( this, tr("Formatter"), tr("Could not umount.\nDevice is busy!"), tr("&OK") );
252 pclose(fp); 261 pclose(fp);
253 return; 262 return;
254 } else { 263 }
264 else
265 {
255 QString lineStr = line; 266 QString lineStr = line;
256 lineStr=lineStr.left(lineStr.length()-1); 267 lineStr=lineStr.left(lineStr.length()-1);
257 outDlg->OutputEdit->append(lineStr); 268 outDlg->OutputEdit->append(lineStr);
@@ -266,15 +277,19 @@ void FormatterApp::doFormat() {
266 outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); 277 outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE);
267 278
268 fp = popen( (const char *) cmd, "r"); 279 fp = popen( (const char *) cmd, "r");
269 while ( fgets( line, sizeof line, fp)) { 280 while ( fgets( line, sizeof line, fp))
270 if( ((QString)line).find("No such device",0,TRUE) != -1) { 281 {
282 if( ((QString)line).find("No such device",0,TRUE) != -1)
283 {
271 qDebug("No such device '" + umountS); 284 qDebug("No such device '" + umountS);
272 QMessageBox::warning( this, tr("Formatter"), tr("No such device!"), tr("&OK") ); 285 QMessageBox::warning( this, tr("Formatter"), tr("No such device!"), tr("&OK") );
273 pclose(fp); 286 pclose(fp);
274// outDlg->OutputEdit->append("No such device"); 287// outDlg->OutputEdit->append("No such device");
275// outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); 288// outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE);
276 return; 289 return;
277 } else { 290 }
291 else
292 {
278 QString lineStr = line; 293 QString lineStr = line;
279 lineStr=lineStr.left(lineStr.length()-1); 294 lineStr=lineStr.left(lineStr.length()-1);
280 outDlg->OutputEdit->append(lineStr); 295 outDlg->OutputEdit->append(lineStr);
@@ -288,13 +303,17 @@ void FormatterApp::doFormat() {
288 outDlg->OutputEdit->append( tr("Trying to mount %1.").arg( currentText) ); 303 outDlg->OutputEdit->append( tr("Trying to mount %1.").arg( currentText) );
289 outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); 304 outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE);
290 fp = popen( (const char *) remountS, "r"); 305 fp = popen( (const char *) remountS, "r");
291 if ( !fp) { 306 if ( !fp)
307 {
292 qDebug("Could not execute '" + remountS + "'! err=%d\n" +(QString)strerror(errno), err); 308 qDebug("Could not execute '" + remountS + "'! err=%d\n" +(QString)strerror(errno), err);
293 QMessageBox::warning( this, tr("Formatter"), tr("Card mount failed!"), tr("&OK") ); 309 QMessageBox::warning( this, tr("Formatter"), tr("Card mount failed!"), tr("&OK") );
294 310
295 } else { 311 }
312 else
313 {
296 outDlg->OutputEdit->append(tr("%1\nhas been successfully mounted.").arg( currentText )); 314 outDlg->OutputEdit->append(tr("%1\nhas been successfully mounted.").arg( currentText ));
297 while ( fgets( line, sizeof line, fp)) { 315 while ( fgets( line, sizeof line, fp))
316 {
298 QString lineStr = line; 317 QString lineStr = line;
299 lineStr=lineStr.left(lineStr.length()-1); 318 lineStr=lineStr.left(lineStr.length()-1);
300 outDlg->OutputEdit->append(lineStr); 319 outDlg->OutputEdit->append(lineStr);
@@ -314,23 +333,27 @@ void FormatterApp::doFormat() {
314 }; 333 };
315} 334}
316 335
317bool FormatterApp::doFdisk() { 336bool FormatterApp::doFdisk()
337{
318 return FALSE; 338 return FALSE;
319 339
320} 340}
321 341
322void FormatterApp::fillCombos() { 342void FormatterApp::fillCombos()
343{
323 344
324 StorageInfo storageInfo; 345 StorageInfo storageInfo;
325 const QList<FileSystem> &fs = storageInfo.fileSystems(); 346 const QList<FileSystem> &fs = storageInfo.fileSystems();
326 QListIterator<FileSystem> it ( fs ); 347 QListIterator<FileSystem> it ( fs );
327 QString storage; 348 QString storage;
328 for( ; it.current(); ++it ){ 349 for( ; it.current(); ++it )
350 {
329 const QString name = (*it)->name(); 351 const QString name = (*it)->name();
330 const QString path = (*it)->path(); 352 const QString path = (*it)->path();
331 const QString disk = (*it)->disk(); 353 const QString disk = (*it)->disk();
332 const QString options = (*it)->options(); 354 const QString options = (*it)->options();
333 if( name.find( tr("Internal"),0,TRUE) == -1) { 355 if( name.find( tr("Internal"),0,TRUE) == -1)
356 {
334 storageComboBox->insertItem(name +" -> "+disk); 357 storageComboBox->insertItem(name +" -> "+disk);
335 } 358 }
336// deviceComboBox->insertItem(disk); 359// deviceComboBox->insertItem(disk);
@@ -344,11 +367,11 @@ void FormatterApp::fillCombos() {
344} 367}
345 368
346 369
347void FormatterApp::fsComboSelected(int ) { 370void FormatterApp::fsComboSelected(int )
371{}
348 372
349} 373void FormatterApp::storageComboSelected(int index )
350 374{
351void FormatterApp::storageComboSelected(int index ) {
352 375
353 QString currentText = storageComboBox->text(index); 376 QString currentText = storageComboBox->text(index);
354 QString nameS = currentText.left( currentText.find("->",0,TRUE)); 377 QString nameS = currentText.left( currentText.find("->",0,TRUE));
@@ -358,14 +381,16 @@ void FormatterApp::storageComboSelected(int index ) {
358 381
359 QString fsType = getFileSystemType((const QString &) currentText); 382 QString fsType = getFileSystemType((const QString &) currentText);
360// qDebug(fsType); 383// qDebug(fsType);
361 for(int i = 0; i < fileSystemsCombo->count(); i++) { 384 for(int i = 0; i < fileSystemsCombo->count(); i++)
385 {
362 if( fsType == fileSystemsCombo->text(i)) 386 if( fsType == fileSystemsCombo->text(i))
363 fileSystemsCombo->setCurrentItem(i); 387 fileSystemsCombo->setCurrentItem(i);
364 } 388 }
365// deviceComboSelected(index); 389// deviceComboSelected(index);
366} 390}
367 391
368void FormatterApp::deviceComboSelected(int index) { 392void FormatterApp::deviceComboSelected(int index)
393{
369 394
370 StorageInfo storageInfo; 395 StorageInfo storageInfo;
371 QString totalS, usedS, avS, diskS, nameS, fsType, selectedText; 396 QString totalS, usedS, avS, diskS, nameS, fsType, selectedText;
@@ -375,12 +400,14 @@ void FormatterApp::deviceComboSelected(int index) {
375 const QList<FileSystem> &fs = storageInfo.fileSystems(); 400 const QList<FileSystem> &fs = storageInfo.fileSystems();
376 QListIterator<FileSystem> it ( fs ); 401 QListIterator<FileSystem> it ( fs );
377 QString storage; 402 QString storage;
378 for( ; it.current(); ++it ){ 403 for( ; it.current(); ++it )
404 {
379 const QString name = (*it)->name(); 405 const QString name = (*it)->name();
380 const QString path = (*it)->path(); 406 const QString path = (*it)->path();
381 const QString disk = (*it)->disk(); 407 const QString disk = (*it)->disk();
382// const QString options = (*it)->options(); 408// const QString options = (*it)->options();
383 if( selectedText == disk) { 409 if( selectedText == disk)
410 {
384 diskS = disk; nameS= name; 411 diskS = disk; nameS= name;
385 mountPointLineEdit->setText(path); 412 mountPointLineEdit->setText(path);
386 long mult = (*it)->blockSize() / 1024; 413 long mult = (*it)->blockSize() / 1024;
@@ -405,28 +432,32 @@ void FormatterApp::deviceComboSelected(int index) {
405// storageComboSelected(0); 432// storageComboSelected(0);
406} 433}
407 434
408void FormatterApp::cleanUp() { 435void FormatterApp::cleanUp()
409 436{}
410}
411 437
412 438
413void FormatterApp::editFstab() { 439void FormatterApp::editFstab()
440{
414 QCopEnvelope e("QPE/Application/textedit","setDocument(QString)"); 441 QCopEnvelope e("QPE/Application/textedit","setDocument(QString)");
415 e << (const QString &)"/etc/fstab"; 442 e << (const QString &)"/etc/fstab";
416} 443}
417 444
418void FormatterApp::parsetab(const QString &fileName) { 445void FormatterApp::parsetab(const QString &fileName)
446{
419 447
420 fileSystemTypeList.clear(); 448 fileSystemTypeList.clear();
421 fsList.clear(); 449 fsList.clear();
422 struct mntent *me; 450 struct mntent *me;
423// if(fileName == "/etc/mtab") { 451// if(fileName == "/etc/mtab") {
424 FILE *mntfp = setmntent( fileName.latin1(), "r" ); 452 FILE *mntfp = setmntent( fileName.latin1(), "r" );
425 if ( mntfp ) { 453 if ( mntfp )
426 while ( (me = getmntent( mntfp )) != 0 ) { 454 {
455 while ( (me = getmntent( mntfp )) != 0 )
456 {
427 QString deviceName = me->mnt_fsname; 457 QString deviceName = me->mnt_fsname;
428 QString filesystemType = me->mnt_type; 458 QString filesystemType = me->mnt_type;
429 if(deviceName != "none") { 459 if(deviceName != "none")
460 {
430 if( fsList.contains(filesystemType) == 0 461 if( fsList.contains(filesystemType) == 0
431 & filesystemType.find("proc",0,TRUE) == -1 462 & filesystemType.find("proc",0,TRUE) == -1
432 & filesystemType.find("cramfs",0,TRUE) == -1 463 & filesystemType.find("cramfs",0,TRUE) == -1
@@ -464,13 +495,16 @@ void FormatterApp::parsetab(const QString &fileName) {
464// } 495// }
465} 496}
466 497
467QString FormatterApp::getFileSystemType(const QString &currentText) { 498QString FormatterApp::getFileSystemType(const QString &currentText)
499{
468 500
469 parsetab("/etc/mtab"); //why did TT forget filesystem type? 501 parsetab("/etc/mtab"); //why did TT forget filesystem type?
470 502
471 for ( QStringList::Iterator it = fileSystemTypeList.begin(); it != fileSystemTypeList.end(); ++it ) { 503 for ( QStringList::Iterator it = fileSystemTypeList.begin(); it != fileSystemTypeList.end(); ++it )
504 {
472 QString temp = (*it); 505 QString temp = (*it);
473 if( temp.find( currentText,0,TRUE) != -1) { 506 if( temp.find( currentText,0,TRUE) != -1)
507 {
474 return temp.right( temp.length() - temp.find("::",0,TRUE) - 2); 508 return temp.right( temp.length() - temp.find("::",0,TRUE) - 2);
475// qDebug(fsType); 509// qDebug(fsType);
476 } 510 }
@@ -478,7 +512,8 @@ QString FormatterApp::getFileSystemType(const QString &currentText) {
478 return ""; 512 return "";
479} 513}
480 514
481bool FormatterApp::doFsck() { 515bool FormatterApp::doFsck()
516{
482 517
483 Output *outDlg; 518 Output *outDlg;
484 QString selectedDevice; 519 QString selectedDevice;
@@ -504,8 +539,7 @@ bool FormatterApp::doFsck() {
504 cmd += selectedDevice + " 2>&1"; 539 cmd += selectedDevice + " 2>&1";
505 540
506 outDlg = new Output(this, tr("Formatter Output"),FALSE); 541 outDlg = new Output(this, tr("Formatter Output"),FALSE);
507 outDlg->showMaximized(); 542 QPEApplication::showDialog( outDlg );
508 outDlg->show();
509 qApp->processEvents(); 543 qApp->processEvents();
510 FILE *fp; 544 FILE *fp;
511 char line[130]; 545 char line[130];
@@ -516,22 +550,29 @@ bool FormatterApp::doFsck() {
516// qDebug("Command is "+umountS); 550// qDebug("Command is "+umountS);
517 fp = popen( (const char *) umountS, "r"); 551 fp = popen( (const char *) umountS, "r");
518// qDebug("%d", fp); 552// qDebug("%d", fp);
519 if ( !fp ) { 553 if ( !fp )
554 {
520 qDebug("Could not execute '" + umountS + "'!\n" +(QString)strerror(errno)); 555 qDebug("Could not execute '" + umountS + "'!\n" +(QString)strerror(errno));
521 QMessageBox::warning( this, tr("Formatter"), tr("umount failed!"), tr("&OK") ); 556 QMessageBox::warning( this, tr("Formatter"), tr("umount failed!"), tr("&OK") );
522 pclose(fp); 557 pclose(fp);
523 return false; 558 return false;
524 } else { 559 }
560 else
561 {
525// outDlg->OutputEdit->append( currentText + tr("\nhas been successfully umounted.")); 562// outDlg->OutputEdit->append( currentText + tr("\nhas been successfully umounted."));
526// outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); 563// outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE);
527 while ( fgets( line, sizeof line, fp)) { 564 while ( fgets( line, sizeof line, fp))
528 if( ((QString)line).find("busy",0,TRUE) != -1) { 565 {
566 if( ((QString)line).find("busy",0,TRUE) != -1)
567 {
529 qDebug("Could not find '" + umountS); 568 qDebug("Could not find '" + umountS);
530 QMessageBox::warning( this, tr("Formatter"), 569 QMessageBox::warning( this, tr("Formatter"),
531 tr("Could not umount.\nDevice is busy!"), tr("&OK") ); 570 tr("Could not umount.\nDevice is busy!"), tr("&OK") );
532 pclose(fp); 571 pclose(fp);
533 return false; 572 return false;
534 } else { 573 }
574 else
575 {
535 QString lineStr = line; 576 QString lineStr = line;
536 lineStr=lineStr.left(lineStr.length()-1); 577 lineStr=lineStr.left(lineStr.length()-1);
537 outDlg->OutputEdit->append(lineStr); 578 outDlg->OutputEdit->append(lineStr);
@@ -542,15 +583,19 @@ bool FormatterApp::doFsck() {
542 pclose(fp); 583 pclose(fp);
543///////////////////////////////////// 584/////////////////////////////////////
544 fp = popen( (const char *) cmd, "r"); 585 fp = popen( (const char *) cmd, "r");
545 while ( fgets( line, sizeof line, fp)) { 586 while ( fgets( line, sizeof line, fp))
546 if( ((QString)line).find("No such device",0,TRUE) != -1) { 587 {
588 if( ((QString)line).find("No such device",0,TRUE) != -1)
589 {
547 qDebug("No such device '" + umountS); 590 qDebug("No such device '" + umountS);
548 QMessageBox::warning( this, tr("Formatter"), tr("No such device!"), tr("&OK") ); 591 QMessageBox::warning( this, tr("Formatter"), tr("No such device!"), tr("&OK") );
549 pclose(fp); 592 pclose(fp);
550// outDlg->OutputEdit->append("No such device"); 593// outDlg->OutputEdit->append("No such device");
551// outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); 594// outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE);
552 return false; 595 return false;
553 } else { 596 }
597 else
598 {
554 QString lineStr = line; 599 QString lineStr = line;
555 lineStr=lineStr.left(lineStr.length()-1); 600 lineStr=lineStr.left(lineStr.length()-1);
556 outDlg->OutputEdit->append(lineStr); 601 outDlg->OutputEdit->append(lineStr);
@@ -568,17 +613,20 @@ bool FormatterApp::doFsck() {
568 return true; 613 return true;
569} 614}
570 615
571bool FormatterApp::doFsckCheck() { 616bool FormatterApp::doFsckCheck()
617{
572 618
573 return FALSE; 619 return FALSE;
574} 620}
575 621
576int FormatterApp::formatCheck(const QString &) { 622int FormatterApp::formatCheck(const QString &)
623{
577 624
578 return -1; 625 return -1;
579} 626}
580 627
581int FormatterApp::runCommand(const QString &) { 628int FormatterApp::runCommand(const QString &)
629{
582 630
583 return -1; 631 return -1;
584} 632}