summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/tools/formatter/formatter.cpp29
1 files changed, 16 insertions, 13 deletions
diff --git a/noncore/tools/formatter/formatter.cpp b/noncore/tools/formatter/formatter.cpp
index 2b8ce7f..ed0ced1 100644
--- a/noncore/tools/formatter/formatter.cpp
+++ b/noncore/tools/formatter/formatter.cpp
@@ -1,568 +1,571 @@
1/**************************************************************************** 1/****************************************************************************
2 ** formatter.cpp 2 ** formatter.cpp
3 ** 3 **
4 ** Copyright: Thu Apr 11 11:01:13 2002 4 ** Copyright: Thu Apr 11 11:01:13 2002
5 ** by: L. J. Potter 5 ** by: L. J. Potter
6 ** 6 **
7 ****************************************************************************/ 7 ****************************************************************************/
8 8
9#include "formatter.h" 9#include "formatter.h"
10#include "inputDialog.h" 10#include "inputDialog.h"
11#include "output.h" 11#include "output.h"
12 12
13#include <qpe/qpemenubar.h> 13#include <qpe/qpemenubar.h>
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>
17#include <qpe/config.h> 17#include <qpe/config.h>
18#include <qpe/mimetype.h> 18#include <qpe/mimetype.h>
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#include <qmultilineedit.h> 22#include <qmultilineedit.h>
23#include <qstring.h> 23#include <qstring.h>
24#include <qlist.h> 24#include <qlist.h>
25#include <qstringlist.h> 25#include <qstringlist.h>
26#include <qdir.h> 26#include <qdir.h>
27#include <qfile.h> 27#include <qfile.h>
28 28
29#include <qtstream.h> 29#include <qtstream.h>
30 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 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> 49#include <string.h>
50#include <errno.h> 50#include <errno.h>
51 51
52#define BLANK ' ' 52#define BLANK ' '
53#define DELIMITER '#' 53#define DELIMITER '#'
54 54
55/* 55/*
56 Blah blah blah blah */ 56 Blah blah blah blah */
57FormatterApp::FormatterApp( QWidget* parent, const char* name, bool modal, WFlags fl ) 57FormatterApp::FormatterApp( QWidget* parent, const char* name, bool modal, WFlags fl )
58 : QMainWindow( parent, name, fl ) 58 : QMainWindow( parent, name, fl )
59// : QDialog( parent, name, modal, fl ) 59// : QDialog( parent, name, modal, fl )
60{ 60{
61 if ( !name ) 61 if ( !name )
62 setName( "FormatterApp" ); 62 setName( "FormatterApp" );
63 connect( qApp,SIGNAL( aboutToQuit()),SLOT( cleanUp()) ); 63 connect( qApp,SIGNAL( aboutToQuit()),SLOT( cleanUp()) );
64 64
65 setCaption( tr( "Formatter" ) ); 65 setCaption( tr( "Formatter" ) );
66 FormatterAppLayout = new QGridLayout( this ); 66 FormatterAppLayout = new QGridLayout( this );
67 FormatterAppLayout->setSpacing( 2); 67 FormatterAppLayout->setSpacing( 2);
68 FormatterAppLayout->setMargin( 2 ); 68 FormatterAppLayout->setMargin( 2 );
69 69
70 TabWidget = new QTabWidget( this, "TabWidget" ); 70 TabWidget = new QTabWidget( this, "TabWidget" );
71 71
72 tab = new QWidget( TabWidget, "tab" ); 72 tab = new QWidget( TabWidget, "tab" );
73 tabLayout = new QGridLayout( tab ); 73 tabLayout = new QGridLayout( tab );
74 tabLayout->setSpacing( 3); 74 tabLayout->setSpacing( 3);
75 tabLayout->setMargin( 2); 75 tabLayout->setMargin( 2);
76 76
77 storageComboBox = new QComboBox( FALSE, tab, "storageComboBox" ); 77 storageComboBox = new QComboBox( FALSE, tab, "storageComboBox" );
78 storageComboBox->setMaximumWidth(220); 78 storageComboBox->setMaximumWidth(220);
79 79
80 tabLayout->addMultiCellWidget( storageComboBox, 0, 0, 0, 0 ); 80 tabLayout->addMultiCellWidget( storageComboBox, 0, 0, 0, 1);
81 81
82 TextLabel4 = new QLabel( tab, "TextLabel4" ); 82 TextLabel4 = new QLabel( tab, "TextLabel4" );
83 TextLabel4->setText( tr( "Storage Type" ) ); 83 TextLabel4->setText( tr( "Storage Type" ) );
84 84
85 tabLayout->addMultiCellWidget( TextLabel4, 1, 1, 0, 0 ); 85 tabLayout->addMultiCellWidget( TextLabel4, 1, 1, 0, 1);
86 86
87 TextLabel2 = new QLabel( tab, "TextLabel2" ); 87 TextLabel2 = new QLabel( tab, "TextLabel2" );
88 TextLabel2->setText( tr( "File Systems" ) ); 88 TextLabel2->setText( tr( "File Systems" ) );
89 89
90 tabLayout->addMultiCellWidget( TextLabel2, 4, 4, 0, 0 ); 90 tabLayout->addMultiCellWidget( TextLabel2, 4, 4, 0, 1);
91 91
92 fileSystemsCombo = new QComboBox( FALSE, tab, "fileSystemsCombo" ); 92 fileSystemsCombo = new QComboBox( FALSE, tab, "fileSystemsCombo" );
93 fileSystemsCombo->setMaximumWidth(220); 93 fileSystemsCombo->setMaximumWidth(220);
94 94
95 tabLayout->addMultiCellWidget( fileSystemsCombo, 3, 3, 0, 0 ); 95 tabLayout->addMultiCellWidget( fileSystemsCombo, 3, 3, 0, 1);
96 QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Minimum, QSizePolicy::Minimum ); 96 QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Minimum, QSizePolicy::Minimum );
97 tabLayout->addItem( spacer, 2, 0 ); 97 tabLayout->addItem( spacer, 2, 0 );
98 98
99 formatPushButton = new QPushButton( tab, "formatPushButton" ); 99 formatPushButton = new QPushButton( tab, "formatPushButton" );
100 formatPushButton->setText( tr( "Format" ) ); 100 formatPushButton->setText( tr( "Format" ) );
101 formatPushButton->setMaximumWidth(170); 101 formatPushButton->setMaximumWidth(170);
102 102
103 tabLayout->addMultiCellWidget( formatPushButton, 6, 6, 0, 0 ); 103 tabLayout->addMultiCellWidget( formatPushButton, 6, 6, 0, 1);
104 QSpacerItem* spacer_2 = new QSpacerItem( 20, 20, QSizePolicy::Minimum, QSizePolicy::Minimum ); 104 QSpacerItem* spacer_2 = new QSpacerItem( 20, 20, QSizePolicy::Minimum, QSizePolicy::Minimum );
105 tabLayout->addItem( spacer_2, 5, 0 ); 105 tabLayout->addItem( spacer_2, 5, 0 );
106
106 TabWidget->insertTab( tab, tr( "Main" ) ); 107 TabWidget->insertTab( tab, tr( "Main" ) );
107 108
108 tab_2 = new QWidget( TabWidget, "tab_2" ); 109 tab_2 = new QWidget( TabWidget, "tab_2" );
109 tabLayout_2 = new QGridLayout( tab_2 ); 110 tabLayout_2 = new QGridLayout( tab_2 );
110 tabLayout_2->setSpacing(3); 111 tabLayout_2->setSpacing(3);
111 tabLayout_2->setMargin(2); 112 tabLayout_2->setMargin(2);
112 113
113 mountPointLineEdit = new QLineEdit( tab_2, "mountPointLineEdit" ); 114 mountPointLineEdit = new QLineEdit( tab_2, "mountPointLineEdit" );
114 115
115 tabLayout_2->addMultiCellWidget( mountPointLineEdit, 0, 0, 0, 0 ); 116 tabLayout_2->addMultiCellWidget( mountPointLineEdit, 0, 0, 0, 1);
116 117
117 deviceComboBox = new QComboBox( FALSE, tab_2, "deviceComboBox" ); 118 deviceComboBox = new QComboBox( FALSE, tab_2, "deviceComboBox" );
118 119
119 tabLayout_2->addMultiCellWidget( deviceComboBox, 3, 3, 0, 0 ); 120 tabLayout_2->addMultiCellWidget( deviceComboBox, 3, 3, 0, 1);
120 121
121 TextLabel5 = new QLabel( tab_2, "TextLabel5" ); 122 TextLabel5 = new QLabel( tab_2, "TextLabel5" );
122 TextLabel5->setText( tr( "CAUTION:\n" 123 TextLabel5->setText( tr( "CAUTION:\n"
123 "Changing parameters on this \n" 124 "Changing parameters on this \n"
124 "page may cause your system \n" 125 "page may cause your system \n"
125 "to stop functioning properly!!" ) );//idiot message 126 "to stop functioning properly!!" ) );//idiot message
126 127
127 tabLayout_2->addMultiCellWidget( TextLabel5, 6, 6, 0, 0 ); 128 tabLayout_2->addMultiCellWidget( TextLabel5, 6, 6, 0, 1);
128 129
129 editPushButton = new QPushButton( tab_2, "editPushButton" ); 130 editPushButton = new QPushButton( tab_2, "editPushButton" );
130 editPushButton->setText( tr( "Edit fstab" ) ); 131 editPushButton->setText( tr( "Edit fstab" ) );
131 132 editPushButton->setMaximumWidth(100);
133
132 tabLayout_2->addMultiCellWidget( editPushButton, 7, 7, 0, 0 ); 134 tabLayout_2->addMultiCellWidget( editPushButton, 7, 7, 0, 0 );
133 135
134 fsckButton = new QPushButton( tab_2, "fsckPushButton" ); 136 fsckButton = new QPushButton( tab_2, "fsckPushButton" );
135 fsckButton->setText( tr( "Check Disk" ) ); 137 fsckButton->setText( tr( "Check Disk" ) );
138 fsckButton->setMaximumWidth(100);
136 139
137 tabLayout_2->addMultiCellWidget( fsckButton, 7, 7, 1, 0 ); 140 tabLayout_2->addMultiCellWidget( fsckButton, 7, 7, 1, 1);
138 141
139 TextLabel3 = new QLabel( tab_2, "TextLabel3" ); 142 TextLabel3 = new QLabel( tab_2, "TextLabel3" );
140 TextLabel3->setText( tr( "Device" ) ); 143 TextLabel3->setText( tr( "Device" ) );
141 144
142 tabLayout_2->addMultiCellWidget( TextLabel3, 4, 4, 0, 0 ); 145 tabLayout_2->addMultiCellWidget( TextLabel3, 4, 4, 0, 1 );
143 QSpacerItem* spacer_3 = new QSpacerItem( 20, 20, QSizePolicy::Minimum, QSizePolicy::Expanding ); 146 QSpacerItem* spacer_3 = new QSpacerItem( 20, 20, QSizePolicy::Minimum, QSizePolicy::Expanding );
144 tabLayout_2->addItem( spacer_3, 5, 0 ); 147 tabLayout_2->addItem( spacer_3, 5, 0 );
145 148
146 TextLabel1 = new QLabel( tab_2, "TextLabel1" ); 149 TextLabel1 = new QLabel( tab_2, "TextLabel1" );
147 TextLabel1->setText( tr( "Mount Point" ) ); 150 TextLabel1->setText( tr( "Mount Point" ) );
148 151
149 tabLayout_2->addMultiCellWidget( TextLabel1, 1, 1, 0, 0 ); 152 tabLayout_2->addMultiCellWidget( TextLabel1, 1, 1, 0, 1 );
150 QSpacerItem* spacer_4 = new QSpacerItem( 20, 20, QSizePolicy::Minimum, QSizePolicy::Expanding ); 153 QSpacerItem* spacer_4 = new QSpacerItem( 20, 20, QSizePolicy::Minimum, QSizePolicy::Expanding );
151 tabLayout_2->addItem( spacer_4, 2, 1 ); 154 tabLayout_2->addItem( spacer_4, 2, 1 );
152 TabWidget->insertTab( tab_2, tr( "Advanced" ) ); 155 TabWidget->insertTab( tab_2, tr( "Advanced" ) );
153 156
154 FormatterAppLayout->addWidget( TabWidget, 0, 0 ); 157 FormatterAppLayout->addWidget( TabWidget, 0, 1 );
155 158
156 connect( formatPushButton ,SIGNAL(released()),this,SLOT( doFormat()) ); 159 connect( formatPushButton ,SIGNAL(released()),this,SLOT( doFormat()) );
157 connect( editPushButton ,SIGNAL(released()),this,SLOT( editFstab()) ); 160 connect( editPushButton ,SIGNAL(released()),this,SLOT( editFstab()) );
158 connect( fsckButton ,SIGNAL(released()),this,SLOT( doFsck()) ); 161 connect( fsckButton ,SIGNAL(released()),this,SLOT( doFsck()) );
159 162
160 connect( fileSystemsCombo,SIGNAL(activated(int)),this,SLOT( fsComboSelected(int ) )); 163 connect( fileSystemsCombo,SIGNAL(activated(int)),this,SLOT( fsComboSelected(int ) ));
161 connect( storageComboBox,SIGNAL(activated(int)),this,SLOT( storageComboSelected(int ) )); 164 connect( storageComboBox,SIGNAL(activated(int)),this,SLOT( storageComboSelected(int ) ));
162 connect( deviceComboBox,SIGNAL(activated(int)),this,SLOT( deviceComboSelected(int ) )); 165 connect( deviceComboBox,SIGNAL(activated(int)),this,SLOT( deviceComboSelected(int ) ));
163 166
164 167
165 fillCombos(); 168 fillCombos();
166} 169}
167 170
168FormatterApp::~FormatterApp() { 171FormatterApp::~FormatterApp() {
169 172
170} 173}
171 174
172void FormatterApp::doFormat() { 175void FormatterApp::doFormat() {
173 int err=0; 176 int err=0;
174 Output *outDlg; 177 Output *outDlg;
175 QString umountS, remountS; 178 QString umountS, remountS;
176 QString text = storageComboBox->currentText(); 179 QString text = storageComboBox->currentText();
177 QString currentText = storageComboBox->currentText(); 180 QString currentText = storageComboBox->currentText();
178 QString cmd; 181 QString cmd;
179 QString diskDevice = currentText.right( currentText.length() - currentText.find(" -> ",0,TRUE) - 4); 182 QString diskDevice = currentText.right( currentText.length() - currentText.find(" -> ",0,TRUE) - 4);
180 QString diskName = currentText.left(currentText.find(" -> ",0,TRUE)); 183 QString diskName = currentText.left(currentText.find(" -> ",0,TRUE));
181 QString fs = fileSystemsCombo->currentText(); 184 QString fs = fileSystemsCombo->currentText();
182 185
183#if defined(QT_QWS_IPAQ) || defined(QT_QWS_EBX) // lets test on something cheap 186#if defined(QT_QWS_IPAQ) || defined(QT_QWS_EBX) // lets test on something cheap
184#else 187#else
185 currentText = diskDevice = "/dev/fd0"; 188 currentText = diskDevice = "/dev/fd0";
186 umountS = "umount -v /floppy 2>&1"; 189 umountS = "umount -v /floppy 2>&1";
187 remountS = "mount -v /floppy 2>&1"; 190 remountS = "mount -v /floppy 2>&1";
188#endif 191#endif
189 192
190 if( currentText.find("CF",0,TRUE) != -1) { 193 if( currentText.find("CF",0,TRUE) != -1) {
191 umountS = "umount "; 194 umountS = "umount ";
192 remountS = "mount "; 195 remountS = "mount ";
193 196
194// umountS = "/sbin/cardctl eject"; 197// umountS = "/sbin/cardctl eject";
195// remountS = "/sbin/cardctl insert"; 198// remountS = "/sbin/cardctl insert";
196 } 199 }
197 if( currentText.find("SD",0,TRUE) != -1) { 200 if( currentText.find("SD",0,TRUE) != -1) {
198 umountS = "umount "; 201 umountS = "umount ";
199 remountS = "mount "; 202 remountS = "mount ";
200// umountS = "/etc/sdcontrol compeject"; 203// umountS = "/etc/sdcontrol compeject";
201// remountS = "/etc/sdcontrol insert"; 204// remountS = "/etc/sdcontrol insert";
202 } 205 }
203 206
204 switch ( QMessageBox::warning(this,tr("Format?!?"),tr("Really format\n") +diskName+" "+ currentText + 207 switch ( QMessageBox::warning(this,tr("Format?!?"),tr("Really format\n") +diskName+" "+ currentText +
205 tr("\nwith ") + fs + tr(" filesystem?!?\nYou will loose all data!!"),tr("Yes"),tr("No"),0,1,1) ) { 208 tr("\nwith ") + fs + tr(" filesystem?!?\nYou will loose all data!!"),tr("Yes"),tr("No"),0,1,1) ) {
206 case 0: { 209 case 0: {
207 if(fs == "vfat") 210 if(fs == "vfat")
208 cmd = "mkdosfs -v " + diskDevice+" 2>&1"; 211 cmd = "mkdosfs -v " + diskDevice+" 2>&1";
209 else if(fs == "ext2") 212 else if(fs == "ext2")
210 cmd = "mke2fs -v " + diskDevice+" 2>&1"; 213 cmd = "mke2fs -v " + diskDevice+" 2>&1";
211 else { 214 else {
212 QMessageBox::warning(this, tr("Formatter"),tr("Could not format.\nUnknown type"), tr("Ok")); 215 QMessageBox::warning(this, tr("Formatter"),tr("Could not format.\nUnknown type"), tr("Ok"));
213 break; 216 break;
214 } 217 }
215// cmd = "ls -l"; 218// cmd = "ls -l";
216 outDlg = new Output(this, tr("Formatter Output"),FALSE); 219 outDlg = new Output(this, tr("Formatter Output"),FALSE);
217 outDlg->showMaximized(); 220 outDlg->showMaximized();
218 outDlg->show(); 221 outDlg->show();
219 qApp->processEvents(); 222 qApp->processEvents();
220 FILE *fp; 223 FILE *fp;
221 char line[130]; 224 char line[130];
222 outDlg->OutputEdit->append( tr("Trying to umount.") + currentText ); 225 outDlg->OutputEdit->append( tr("Trying to umount.") + currentText );
223 outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); 226 outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE);
224 227
225 sleep(1); 228 sleep(1);
226 qDebug("Command is "+umountS); 229 qDebug("Command is "+umountS);
227 fp = popen( (const char *) umountS, "r"); 230 fp = popen( (const char *) umountS, "r");
228 qDebug("%d", fp); 231 qDebug("%d", fp);
229 if ( !fp ) { 232 if ( !fp ) {
230 qDebug("Could not execute '" + umountS + "'! err=%d\n" +(QString)strerror(errno), err); 233 qDebug("Could not execute '" + umountS + "'! err=%d\n" +(QString)strerror(errno), err);
231 QMessageBox::warning( this, tr("Formatter"), tr("umount failed!"), tr("&OK") ); 234 QMessageBox::warning( this, tr("Formatter"), tr("umount failed!"), tr("&OK") );
232 pclose(fp); 235 pclose(fp);
233 return; 236 return;
234 } else { 237 } else {
235// outDlg->OutputEdit->append( currentText + tr("\nhas been successfully umounted.")); 238// outDlg->OutputEdit->append( currentText + tr("\nhas been successfully umounted."));
236// outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); 239// outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE);
237 while ( fgets( line, sizeof line, fp)) { 240 while ( fgets( line, sizeof line, fp)) {
238 if( ((QString)line).find("busy",0,TRUE) != -1) { 241 if( ((QString)line).find("busy",0,TRUE) != -1) {
239 qDebug("Could not find '" + umountS); 242 qDebug("Could not find '" + umountS);
240 QMessageBox::warning( this, tr("Formatter"), tr("Could not umount.\nDevice is busy!"), tr("&OK") ); 243 QMessageBox::warning( this, tr("Formatter"), tr("Could not umount.\nDevice is busy!"), tr("&OK") );
241 pclose(fp); 244 pclose(fp);
242 return; 245 return;
243 } else { 246 } else {
244 QString lineStr = line; 247 QString lineStr = line;
245 lineStr=lineStr.left(lineStr.length()-1); 248 lineStr=lineStr.left(lineStr.length()-1);
246 outDlg->OutputEdit->append(lineStr); 249 outDlg->OutputEdit->append(lineStr);
247 outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); 250 outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE);
248 } 251 }
249 } 252 }
250 } 253 }
251 pclose(fp); 254 pclose(fp);
252 255
253 qDebug("Command would be: "+cmd); 256 qDebug("Command would be: "+cmd);
254 outDlg->OutputEdit->append( tr("Trying to format.") ); 257 outDlg->OutputEdit->append( tr("Trying to format.") );
255 outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); 258 outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE);
256 259
257 fp = popen( (const char *) cmd, "r"); 260 fp = popen( (const char *) cmd, "r");
258 while ( fgets( line, sizeof line, fp)) { 261 while ( fgets( line, sizeof line, fp)) {
259 if( ((QString)line).find("No such device",0,TRUE) != -1) { 262 if( ((QString)line).find("No such device",0,TRUE) != -1) {
260 qDebug("No such device '" + umountS); 263 qDebug("No such device '" + umountS);
261 QMessageBox::warning( this, tr("Formatter"), tr("No such device!"), tr("&OK") ); 264 QMessageBox::warning( this, tr("Formatter"), tr("No such device!"), tr("&OK") );
262 pclose(fp); 265 pclose(fp);
263// outDlg->OutputEdit->append("No such device"); 266// outDlg->OutputEdit->append("No such device");
264// outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); 267// outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE);
265 return; 268 return;
266 } else { 269 } else {
267 QString lineStr = line; 270 QString lineStr = line;
268 lineStr=lineStr.left(lineStr.length()-1); 271 lineStr=lineStr.left(lineStr.length()-1);
269 outDlg->OutputEdit->append(lineStr); 272 outDlg->OutputEdit->append(lineStr);
270 outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); 273 outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE);
271 } 274 }
272 } 275 }
273 outDlg->OutputEdit->append( currentText + tr("\nhas been successfully formatted.")); 276 outDlg->OutputEdit->append( currentText + tr("\nhas been successfully formatted."));
274 outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); 277 outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE);
275 pclose(fp); 278 pclose(fp);
276 279
277 outDlg->OutputEdit->append( tr("Trying to mount.") + currentText ); 280 outDlg->OutputEdit->append( tr("Trying to mount.") + currentText );
278 outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); 281 outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE);
279 fp = popen( (const char *) remountS, "r"); 282 fp = popen( (const char *) remountS, "r");
280 if ( !fp) { 283 if ( !fp) {
281 qDebug("Could not execute '" + remountS + "'! err=%d\n" +(QString)strerror(errno), err); 284 qDebug("Could not execute '" + remountS + "'! err=%d\n" +(QString)strerror(errno), err);
282 QMessageBox::warning( this, tr("Formatter"), tr("Card mount failed!"), tr("&OK") ); 285 QMessageBox::warning( this, tr("Formatter"), tr("Card mount failed!"), tr("&OK") );
283 286
284 } else { 287 } else {
285 outDlg->OutputEdit->append( currentText + tr("\nhas been successfully mounted.")); 288 outDlg->OutputEdit->append( currentText + tr("\nhas been successfully mounted."));
286 while ( fgets( line, sizeof line, fp)) { 289 while ( fgets( line, sizeof line, fp)) {
287 QString lineStr = line; 290 QString lineStr = line;
288 lineStr=lineStr.left(lineStr.length()-1); 291 lineStr=lineStr.left(lineStr.length()-1);
289 outDlg->OutputEdit->append(lineStr); 292 outDlg->OutputEdit->append(lineStr);
290 outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); 293 outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE);
291 } 294 }
292 } 295 }
293 pclose(fp); 296 pclose(fp);
294 sleep(1); 297 sleep(1);
295 298
296 outDlg->OutputEdit->append(tr("You can now close the output window.")); 299 outDlg->OutputEdit->append(tr("You can now close the output window."));
297 outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); 300 outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE);
298// outDlg->close(); 301// outDlg->close();
299// if(outDlg) 302// if(outDlg)
300// delete outDlg; 303// delete outDlg;
301 } 304 }
302 break; 305 break;
303 }; 306 };
304} 307}
305 308
306bool FormatterApp::doFdisk() { 309bool FormatterApp::doFdisk() {
307 return FALSE; 310 return FALSE;
308 311
309} 312}
310 313
311void FormatterApp::fillCombos() { 314void FormatterApp::fillCombos() {
312 315
313 StorageInfo storageInfo; 316 StorageInfo storageInfo;
314 const QList<FileSystem> &fs = storageInfo.fileSystems(); 317 const QList<FileSystem> &fs = storageInfo.fileSystems();
315 QListIterator<FileSystem> it ( fs ); 318 QListIterator<FileSystem> it ( fs );
316 QString storage; 319 QString storage;
317 for( ; it.current(); ++it ){ 320 for( ; it.current(); ++it ){
318 const QString name = (*it)->name(); 321 const QString name = (*it)->name();
319 const QString path = (*it)->path(); 322 const QString path = (*it)->path();
320 const QString disk = (*it)->disk(); 323 const QString disk = (*it)->disk();
321 const QString options = (*it)->options(); 324 const QString options = (*it)->options();
322 if( name.find( tr("Internal"),0,TRUE) == -1) { 325 if( name.find( tr("Internal"),0,TRUE) == -1) {
323 storageComboBox->insertItem(name +" -> "+disk); 326 storageComboBox->insertItem(name +" -> "+disk);
324 } 327 }
325// deviceComboBox->insertItem(disk); 328// deviceComboBox->insertItem(disk);
326 } 329 }
327 parsetab("/etc/mtab"); 330 parsetab("/etc/mtab");
328// parsetab("/etc/fstab"); 331// parsetab("/etc/fstab");
329 fileSystemsCombo->insertStringList( fsList,-1); 332 fileSystemsCombo->insertStringList( fsList,-1);
330 deviceComboBox->insertStringList( deviceList,-1); 333 deviceComboBox->insertStringList( deviceList,-1);
331 storageComboSelected(0); 334 storageComboSelected(0);
332 deviceComboSelected(0); 335 deviceComboSelected(0);
333} 336}
334 337
335 338
336void FormatterApp::fsComboSelected(int index) { 339void FormatterApp::fsComboSelected(int index) {
337 340
338} 341}
339 342
340void FormatterApp::storageComboSelected(int index ) { 343void FormatterApp::storageComboSelected(int index ) {
341 344
342 QString currentText = storageComboBox->text(index); 345 QString currentText = storageComboBox->text(index);
343 QString nameS = currentText.left( currentText.find("->",0,TRUE)); 346 QString nameS = currentText.left( currentText.find("->",0,TRUE));
344 347
345 TextLabel4->setText( tr( "Storage Type : ") + nameS ); 348 TextLabel4->setText( tr( "Storage Type : ") + nameS );
346 currentText = currentText.right( currentText.length() - currentText.find(" -> ",0,TRUE) - 4); 349 currentText = currentText.right( currentText.length() - currentText.find(" -> ",0,TRUE) - 4);
347 350
348 QString fsType = getFileSystemType((const QString &) currentText); 351 QString fsType = getFileSystemType((const QString &) currentText);
349// qDebug(fsType); 352// qDebug(fsType);
350 for(int i = 0; i < fileSystemsCombo->count(); i++) { 353 for(int i = 0; i < fileSystemsCombo->count(); i++) {
351 if( fsType == fileSystemsCombo->text(i)) 354 if( fsType == fileSystemsCombo->text(i))
352 fileSystemsCombo->setCurrentItem(i); 355 fileSystemsCombo->setCurrentItem(i);
353 } 356 }
354// deviceComboSelected(index); 357// deviceComboSelected(index);
355} 358}
356 359
357void FormatterApp::deviceComboSelected(int index) { 360void FormatterApp::deviceComboSelected(int index) {
358 361
359 StorageInfo storageInfo; 362 StorageInfo storageInfo;
360 QString totalS, usedS, avS, diskS, nameS, fsType, selectedText; 363 QString totalS, usedS, avS, diskS, nameS, fsType, selectedText;
361 364
362 selectedText = deviceComboBox->text(index); 365 selectedText = deviceComboBox->text(index);
363 366
364 const QList<FileSystem> &fs = storageInfo.fileSystems(); 367 const QList<FileSystem> &fs = storageInfo.fileSystems();
365 QListIterator<FileSystem> it ( fs ); 368 QListIterator<FileSystem> it ( fs );
366 QString storage; 369 QString storage;
367 for( ; it.current(); ++it ){ 370 for( ; it.current(); ++it ){
368 const QString name = (*it)->name(); 371 const QString name = (*it)->name();
369 const QString path = (*it)->path(); 372 const QString path = (*it)->path();
370 const QString disk = (*it)->disk(); 373 const QString disk = (*it)->disk();
371// const QString options = (*it)->options(); 374// const QString options = (*it)->options();
372 if( selectedText == disk) { 375 if( selectedText == disk) {
373 diskS = disk; nameS= name; 376 diskS = disk; nameS= name;
374 mountPointLineEdit->setText(path); 377 mountPointLineEdit->setText(path);
375 long mult = (*it)->blockSize() / 1024; 378 long mult = (*it)->blockSize() / 1024;
376 long div = 1024 / (*it)->blockSize(); 379 long div = 1024 / (*it)->blockSize();
377 if ( !mult ) mult = 1; 380 if ( !mult ) mult = 1;
378 if ( !div ) div = 1; 381 if ( !div ) div = 1;
379 long total = (*it)->totalBlocks() * mult / div; 382 long total = (*it)->totalBlocks() * mult / div;
380 long totalMb = total/1024; 383 long totalMb = total/1024;
381 long avail = (*it)->availBlocks() * mult / div; 384 long avail = (*it)->availBlocks() * mult / div;
382 long availMb = avail/1024; 385 long availMb = avail/1024;
383 long used = total - avail; 386 long used = total - avail;
384 long usedMb = used/1024; 387 long usedMb = used/1024;
385 totalS.sprintf(tr("Total: %1 kB ( %d mB)\n").arg( total ), totalMb ); 388 totalS.sprintf(tr("Total: %1 kB ( %d mB)\n").arg( total ), totalMb );
386 usedS.sprintf(tr("Used: %1 kB ( %d mB)\n").arg(used) ,usedMb); 389 usedS.sprintf(tr("Used: %1 kB ( %d mB)\n").arg(used) ,usedMb);
387 avS.sprintf( tr("Available: %1 kB ( %d mB)").arg(avail), availMb ); 390 avS.sprintf( tr("Available: %1 kB ( %d mB)").arg(avail), availMb );
388 } 391 }
389 } 392 }
390 fsType = getFileSystemType((const QString &)selectedText); 393 fsType = getFileSystemType((const QString &)selectedText);
391 394
392 TextLabel5->setText("Type: "+ nameS+"\nFormatted with "+ fsType + " \n" + totalS + usedS + avS); 395 TextLabel5->setText("Type: "+ nameS+"\nFormatted with "+ fsType + " \n" + totalS + usedS + avS);
393// storageComboSelected(0); 396// storageComboSelected(0);
394} 397}
395 398
396void FormatterApp::cleanUp() { 399void FormatterApp::cleanUp() {
397 400
398} 401}
399 402
400 403
401void FormatterApp::editFstab() { 404void FormatterApp::editFstab() {
402 QCopEnvelope e("QPE/Application/textedit","setDocument(QString)"); 405 QCopEnvelope e("QPE/Application/textedit","setDocument(QString)");
403 e << (const QString &)"/etc/fstab"; 406 e << (const QString &)"/etc/fstab";
404} 407}
405 408
406void FormatterApp::parsetab(const QString &fileName) { 409void FormatterApp::parsetab(const QString &fileName) {
407 410
408 fileSystemTypeList.clear(); 411 fileSystemTypeList.clear();
409 fsList.clear(); 412 fsList.clear();
410 struct mntent *me; 413 struct mntent *me;
411// if(fileName == "/etc/mtab") { 414// if(fileName == "/etc/mtab") {
412 FILE *mntfp = setmntent( fileName.latin1(), "r" ); 415 FILE *mntfp = setmntent( fileName.latin1(), "r" );
413 if ( mntfp ) { 416 if ( mntfp ) {
414 while ( (me = getmntent( mntfp )) != 0 ) { 417 while ( (me = getmntent( mntfp )) != 0 ) {
415 QString deviceName = me->mnt_fsname; 418 QString deviceName = me->mnt_fsname;
416 QString filesystemType = me->mnt_type; 419 QString filesystemType = me->mnt_type;
417 if(deviceName != "none") { 420 if(deviceName != "none") {
418 if( fsList.contains(filesystemType) == 0 421 if( fsList.contains(filesystemType) == 0
419 & filesystemType.find("proc",0,TRUE) == -1 422 & filesystemType.find("proc",0,TRUE) == -1
420 & filesystemType.find("cramfs",0,TRUE) == -1 423 & filesystemType.find("cramfs",0,TRUE) == -1
421 & filesystemType.find("auto",0,TRUE) == -1) 424 & filesystemType.find("auto",0,TRUE) == -1)
422 fsList << filesystemType; 425 fsList << filesystemType;
423 deviceList << deviceName; 426 deviceList << deviceName;
424 qDebug(deviceName+"::"+filesystemType); 427 qDebug(deviceName+"::"+filesystemType);
425 fileSystemTypeList << deviceName+"::"+filesystemType; 428 fileSystemTypeList << deviceName+"::"+filesystemType;
426 } 429 }
427 } 430 }
428 } 431 }
429 endmntent( mntfp ); 432 endmntent( mntfp );
430// } else if(fileName == "/etc/fstab") { 433// } else if(fileName == "/etc/fstab") {
431// QFile f("/etc/fstab"); 434// QFile f("/etc/fstab");
432// if ( f.open(IO_ReadOnly) ) { 435// if ( f.open(IO_ReadOnly) ) {
433// QTextStream t (&f); 436// QTextStream t (&f);
434// QString s; 437// QString s;
435// while (! t.eof()) { 438// while (! t.eof()) {
436// s=t.readLine(); 439// s=t.readLine();
437// s=s.simplifyWhiteSpace(); 440// s=s.simplifyWhiteSpace();
438// if ( (!s.isEmpty() ) && (s.find(" ")!=0) ) { 441// if ( (!s.isEmpty() ) && (s.find(" ")!=0) ) {
439// // = me->mnt_fsname; 442// // = me->mnt_fsname;
440// QString filesystemType = me->mnt_type; 443// QString filesystemType = me->mnt_type;
441// QString deviceName = s.left(0,s.find(BLANK) ); 444// QString deviceName = s.left(0,s.find(BLANK) );
442// s=s.remove(0,s.find(BLANK)+1 ); // devicename 445// s=s.remove(0,s.find(BLANK)+1 ); // devicename
443 446
444// s=s.remove(0,s.find(BLANK)+1 ); // mountpoint 447// s=s.remove(0,s.find(BLANK)+1 ); // mountpoint
445// QStringt mountPoint= s.left(0,s.find(BLANK) ); 448// QStringt mountPoint= s.left(0,s.find(BLANK) );
446// s=s.remove(0,s.find(BLANK)+1 ); // fs 449// s=s.remove(0,s.find(BLANK)+1 ); // fs
447// QString filesystemType= s.left(0,s.find(BLANK) ); 450// QString filesystemType= s.left(0,s.find(BLANK) );
448// } 451// }
449// } 452// }
450// } 453// }
451// f.close(); 454// f.close();
452// } 455// }
453} 456}
454 457
455QString FormatterApp::getFileSystemType(const QString &currentText) { 458QString FormatterApp::getFileSystemType(const QString &currentText) {
456 459
457 parsetab("/etc/mtab"); //why did TT forget filesystem type? 460 parsetab("/etc/mtab"); //why did TT forget filesystem type?
458 461
459 for ( QStringList::Iterator it = fileSystemTypeList.begin(); it != fileSystemTypeList.end(); ++it ) { 462 for ( QStringList::Iterator it = fileSystemTypeList.begin(); it != fileSystemTypeList.end(); ++it ) {
460 QString temp = (*it); 463 QString temp = (*it);
461 if( temp.find( currentText,0,TRUE) != -1) { 464 if( temp.find( currentText,0,TRUE) != -1) {
462 return temp.right( temp.length() - temp.find("::",0,TRUE) - 2); 465 return temp.right( temp.length() - temp.find("::",0,TRUE) - 2);
463// qDebug(fsType); 466// qDebug(fsType);
464 } 467 }
465 } 468 }
466 return ""; 469 return "";
467} 470}
468 471
469bool FormatterApp::doFsck() { 472bool FormatterApp::doFsck() {
470 473
471 Output *outDlg; 474 Output *outDlg;
472 QString selectedDevice; 475 QString selectedDevice;
473#if defined(QT_QWS_IPAQ) || defined(QT_QWS_EBX) 476#if defined(QT_QWS_IPAQ) || defined(QT_QWS_EBX)
474 selectedDevice = deviceComboBox->currentText(); 477 selectedDevice = deviceComboBox->currentText();
475#else 478#else
476 // for testing 479 // for testing
477// currentText = diskDevice = "/dev/fd0"; 480// currentText = diskDevice = "/dev/fd0";
478 QString umountS = "umount -v /floppy 2>&1"; 481 QString umountS = "umount -v /floppy 2>&1";
479 QString remountS = "mount -v /floppy 2>&1"; 482 QString remountS = "mount -v /floppy 2>&1";
480 selectedDevice ="/dev/fd0"; 483 selectedDevice ="/dev/fd0";
481 484
482#endif 485#endif
483 486
484 QString fsType = getFileSystemType((const QString &)selectedDevice); 487 QString fsType = getFileSystemType((const QString &)selectedDevice);
485 QString cmd; 488 QString cmd;
486 qDebug( selectedDevice +" "+ fsType); 489 qDebug( selectedDevice +" "+ fsType);
487 if(fsType == "vfat") cmd = "dosfsck -vy "; 490 if(fsType == "vfat") cmd = "dosfsck -vy ";
488 if(fsType == "ext2") cmd = "e2fsck -cpvy "; 491 if(fsType == "ext2") cmd = "e2fsck -cpvy ";
489 cmd += selectedDevice + " 2>&1"; 492 cmd += selectedDevice + " 2>&1";
490 493
491 outDlg = new Output(this, tr("Formatter Output"),FALSE); 494 outDlg = new Output(this, tr("Formatter Output"),FALSE);
492 outDlg->showMaximized(); 495 outDlg->showMaximized();
493 outDlg->show(); 496 outDlg->show();
494 qApp->processEvents(); 497 qApp->processEvents();
495 FILE *fp; 498 FILE *fp;
496 char line[130]; 499 char line[130];
497 outDlg->OutputEdit->append( tr("Trying to umount.")); 500 outDlg->OutputEdit->append( tr("Trying to umount."));
498 outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); 501 outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE);
499 502
500 sleep(1); 503 sleep(1);
501// qDebug("Command is "+umountS); 504// qDebug("Command is "+umountS);
502 fp = popen( (const char *) umountS, "r"); 505 fp = popen( (const char *) umountS, "r");
503// qDebug("%d", fp); 506// qDebug("%d", fp);
504 if ( !fp ) { 507 if ( !fp ) {
505 qDebug("Could not execute '" + umountS + "'!\n" +(QString)strerror(errno)); 508 qDebug("Could not execute '" + umountS + "'!\n" +(QString)strerror(errno));
506 QMessageBox::warning( this, tr("Formatter"), tr("umount failed!"), tr("&OK") ); 509 QMessageBox::warning( this, tr("Formatter"), tr("umount failed!"), tr("&OK") );
507 pclose(fp); 510 pclose(fp);
508 return false; 511 return false;
509 } else { 512 } else {
510// outDlg->OutputEdit->append( currentText + tr("\nhas been successfully umounted.")); 513// outDlg->OutputEdit->append( currentText + tr("\nhas been successfully umounted."));
511// outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); 514// outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE);
512 while ( fgets( line, sizeof line, fp)) { 515 while ( fgets( line, sizeof line, fp)) {
513 if( ((QString)line).find("busy",0,TRUE) != -1) { 516 if( ((QString)line).find("busy",0,TRUE) != -1) {
514 qDebug("Could not find '" + umountS); 517 qDebug("Could not find '" + umountS);
515 QMessageBox::warning( this, tr("Formatter"), tr("Could not umount.\nDevice is busy!"), tr("&OK") ); 518 QMessageBox::warning( this, tr("Formatter"), tr("Could not umount.\nDevice is busy!"), tr("&OK") );
516 pclose(fp); 519 pclose(fp);
517 return false; 520 return false;
518 } else { 521 } else {
519 QString lineStr = line; 522 QString lineStr = line;
520 lineStr=lineStr.left(lineStr.length()-1); 523 lineStr=lineStr.left(lineStr.length()-1);
521 outDlg->OutputEdit->append(lineStr); 524 outDlg->OutputEdit->append(lineStr);
522 outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); 525 outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE);
523 } 526 }
524 } 527 }
525 } 528 }
526 pclose(fp); 529 pclose(fp);
527///////////////////////////////////// 530/////////////////////////////////////
528 fp = popen( (const char *) cmd, "r"); 531 fp = popen( (const char *) cmd, "r");
529 while ( fgets( line, sizeof line, fp)) { 532 while ( fgets( line, sizeof line, fp)) {
530 if( ((QString)line).find("No such device",0,TRUE) != -1) { 533 if( ((QString)line).find("No such device",0,TRUE) != -1) {
531 qDebug("No such device '" + umountS); 534 qDebug("No such device '" + umountS);
532 QMessageBox::warning( this, tr("Formatter"), tr("No such device!"), tr("&OK") ); 535 QMessageBox::warning( this, tr("Formatter"), tr("No such device!"), tr("&OK") );
533 pclose(fp); 536 pclose(fp);
534// outDlg->OutputEdit->append("No such device"); 537// outDlg->OutputEdit->append("No such device");
535// outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); 538// outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE);
536 return false; 539 return false;
537 } else { 540 } else {
538 QString lineStr = line; 541 QString lineStr = line;
539 lineStr=lineStr.left(lineStr.length()-1); 542 lineStr=lineStr.left(lineStr.length()-1);
540 outDlg->OutputEdit->append(lineStr); 543 outDlg->OutputEdit->append(lineStr);
541 outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); 544 outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE);
542 } 545 }
543 } 546 }
544 outDlg->OutputEdit->append(tr("You can now close the output window.")); 547 outDlg->OutputEdit->append(tr("You can now close the output window."));
545 outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); 548 outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE);
546// outDlg->OutputEdit->append( currentText + tr("\nhas been successfully formatted.")); 549// outDlg->OutputEdit->append( currentText + tr("\nhas been successfully formatted."));
547// outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); 550// outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE);
548 pclose(fp); 551 pclose(fp);
549 552
550///////////////////////////////////////// 553/////////////////////////////////////////
551 554
552 return true; 555 return true;
553} 556}
554 557
555bool FormatterApp::doFsckCheck() { 558bool FormatterApp::doFsckCheck() {
556 559
557 return FALSE; 560 return FALSE;
558} 561}
559 562
560int FormatterApp::formatCheck(const QString &deviceStr) { 563int FormatterApp::formatCheck(const QString &deviceStr) {
561 564
562 return -1; 565 return -1;
563} 566}
564 567
565int FormatterApp::runCommand(const QString &command) { 568int FormatterApp::runCommand(const QString &command) {
566 569
567 return -1; 570 return -1;
568} 571}