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
@@ -11,5 +11,5 @@
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>
@@ -20,4 +20,6 @@
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>
@@ -26,12 +28,9 @@
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>
@@ -42,4 +41,5 @@
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>
@@ -169,9 +169,9 @@ FormatterApp::FormatterApp( QWidget* parent, const char* name, WFlags fl, bool
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;
@@ -191,5 +191,6 @@ void FormatterApp::doFormat() {
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 ";
@@ -198,5 +199,6 @@ void FormatterApp::doFormat() {
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 ";
@@ -212,11 +214,14 @@ void FormatterApp::doFormat() {
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;
@@ -224,6 +229,5 @@ void FormatterApp::doFormat() {
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;
@@ -238,19 +242,26 @@ void FormatterApp::doFormat() {
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);
@@ -267,6 +278,8 @@ void FormatterApp::doFormat() {
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") );
@@ -275,5 +288,7 @@ void FormatterApp::doFormat() {
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);
@@ -289,11 +304,15 @@ void FormatterApp::doFormat() {
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);
@@ -315,10 +334,12 @@ void FormatterApp::doFormat() {
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;
@@ -326,10 +347,12 @@ void FormatterApp::fillCombos() {
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 }
@@ -345,9 +368,9 @@ void FormatterApp::fillCombos() {
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);
@@ -359,5 +382,6 @@ void FormatterApp::storageComboSelected(int index ) {
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);
@@ -366,5 +390,6 @@ void FormatterApp::storageComboSelected(int index ) {
366} 390}
367 391
368void FormatterApp::deviceComboSelected(int index) { 392void FormatterApp::deviceComboSelected(int index)
393{
369 394
370 StorageInfo storageInfo; 395 StorageInfo storageInfo;
@@ -376,10 +401,12 @@ void FormatterApp::deviceComboSelected(int index) {
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);
@@ -406,15 +433,16 @@ void FormatterApp::deviceComboSelected(int index) {
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();
@@ -423,9 +451,12 @@ void FormatterApp::parsetab(const QString &fileName) {
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
@@ -465,11 +496,14 @@ void FormatterApp::parsetab(const QString &fileName) {
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);
@@ -479,5 +513,6 @@ QString FormatterApp::getFileSystemType(const QString &currentText) {
479} 513}
480 514
481bool FormatterApp::doFsck() { 515bool FormatterApp::doFsck()
516{
482 517
483 Output *outDlg; 518 Output *outDlg;
@@ -505,6 +540,5 @@ bool FormatterApp::doFsck() {
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;
@@ -517,14 +551,19 @@ bool FormatterApp::doFsck() {
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"),
@@ -532,5 +571,7 @@ bool FormatterApp::doFsck() {
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);
@@ -543,6 +584,8 @@ bool FormatterApp::doFsck() {
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") );
@@ -551,5 +594,7 @@ bool FormatterApp::doFsck() {
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);
@@ -569,15 +614,18 @@ bool FormatterApp::doFsck() {
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;