author | ar <ar> | 2004-02-21 19:09:12 (UTC) |
---|---|---|
committer | ar <ar> | 2004-02-21 19:09:12 (UTC) |
commit | c7e563cbb26c20807e66dd4284d1ce9cbf8e1419 (patch) (unidiff) | |
tree | e55119af88abe930c1ce492f30efb72c929a730c /noncore/tools/formatter/formatter.cpp | |
parent | 536f271b1e6a1d1886e96a28524a3503c4c38c4e (diff) | |
download | opie-c7e563cbb26c20807e66dd4284d1ce9cbf8e1419.zip opie-c7e563cbb26c20807e66dd4284d1ce9cbf8e1419.tar.gz opie-c7e563cbb26c20807e66dd4284d1ce9cbf8e1419.tar.bz2 |
improve support for BigScreen
Diffstat (limited to 'noncore/tools/formatter/formatter.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/tools/formatter/formatter.cpp | 510 |
1 files changed, 279 insertions, 231 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 | |||
@@ -9,39 +9,39 @@ | |||
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 <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> |
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 | /* 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> |
39 | #include <qtabwidget.h> | 38 | #include <qtabwidget.h> |
40 | #include <qwidget.h> | 39 | #include <qwidget.h> |
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> |
47 | #include <sys/vfs.h> | 47 | #include <sys/vfs.h> |
@@ -51,27 +51,27 @@ | |||
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 */ |
57 | FormatterApp::FormatterApp( QWidget* parent, const char* name, WFlags fl, bool modal ) | 57 | FormatterApp::FormatterApp( QWidget* parent, const char* name, WFlags fl, bool modal ) |
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" ); |
@@ -98,17 +98,17 @@ FormatterApp::FormatterApp( QWidget* parent, const char* name, WFlags fl, bool | |||
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, 1); | 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 | ||
107 | TabWidget->insertTab( tab, tr( "Main" ) ); | 107 | TabWidget->insertTab( tab, tr( "Main" ) ); |
108 | 108 | ||
109 | tab_2 = new QWidget( TabWidget, "tab_2" ); | 109 | tab_2 = new QWidget( TabWidget, "tab_2" ); |
110 | tabLayout_2 = new QGridLayout( tab_2 ); | 110 | tabLayout_2 = new QGridLayout( tab_2 ); |
111 | tabLayout_2->setSpacing(3); | 111 | tabLayout_2->setSpacing(3); |
112 | tabLayout_2->setMargin(2); | 112 | tabLayout_2->setMargin(2); |
113 | 113 | ||
114 | mountPointLineEdit = new QLineEdit( tab_2, "mountPointLineEdit" ); | 114 | mountPointLineEdit = new QLineEdit( tab_2, "mountPointLineEdit" ); |
@@ -129,9 +129,9 @@ FormatterApp::FormatterApp( QWidget* parent, const char* name, WFlags fl, bool | |||
129 | 129 | ||
130 | editPushButton = new QPushButton( tab_2, "editPushButton" ); | 130 | editPushButton = new QPushButton( tab_2, "editPushButton" ); |
131 | editPushButton->setText( tr( "Edit fstab" ) ); | 131 | editPushButton->setText( tr( "Edit fstab" ) ); |
132 | editPushButton->setMaximumWidth(100); | 132 | editPushButton->setMaximumWidth(100); |
133 | 133 | ||
134 | tabLayout_2->addMultiCellWidget( editPushButton, 7, 7, 0, 0 ); | 134 | tabLayout_2->addMultiCellWidget( editPushButton, 7, 7, 0, 0 ); |
135 | 135 | ||
136 | fsckButton = new QPushButton( tab_2, "fsckPushButton" ); | 136 | fsckButton = new QPushButton( tab_2, "fsckPushButton" ); |
137 | fsckButton->setText( tr( "Check Disk" ) ); | 137 | fsckButton->setText( tr( "Check Disk" ) ); |
@@ -163,17 +163,17 @@ FormatterApp::FormatterApp( QWidget* parent, const char* name, WFlags fl, bool | |||
163 | connect( fileSystemsCombo,SIGNAL(activated(int)),this,SLOT( fsComboSelected(int ) )); | 163 | connect( fileSystemsCombo,SIGNAL(activated(int)),this,SLOT( fsComboSelected(int ) )); |
164 | connect( storageComboBox,SIGNAL(activated(int)),this,SLOT( storageComboSelected(int ) )); | 164 | connect( storageComboBox,SIGNAL(activated(int)),this,SLOT( storageComboSelected(int ) )); |
165 | connect( deviceComboBox,SIGNAL(activated(int)),this,SLOT( deviceComboSelected(int ) )); | 165 | connect( deviceComboBox,SIGNAL(activated(int)),this,SLOT( deviceComboSelected(int ) )); |
166 | 166 | ||
167 | 167 | ||
168 | fillCombos(); | 168 | fillCombos(); |
169 | } | 169 | } |
170 | 170 | ||
171 | FormatterApp::~FormatterApp() { | 171 | FormatterApp::~FormatterApp() |
172 | 172 | {} | |
173 | } | ||
174 | 173 | ||
175 | void FormatterApp::doFormat() { | 174 | void 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; |
179 | QString text = storageComboBox->currentText(); | 179 | QString text = storageComboBox->currentText(); |
@@ -189,184 +189,209 @@ void FormatterApp::doFormat() { | |||
189 | umountS = "umount -v /floppy 2>&1"; | 189 | umountS = "umount -v /floppy 2>&1"; |
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"; |
204 | // remountS = "/etc/sdcontrol insert"; | 206 | // remountS = "/etc/sdcontrol insert"; |
205 | } | 207 | } |
206 | 208 | ||
207 | switch ( QMessageBox::warning(this,tr("Format?") | 209 | switch ( QMessageBox::warning(this,tr("Format?") |
208 | , tr("Really format\n") +diskName+" "+ currentText + | 210 | , tr("Really format\n") +diskName+" "+ currentText + |
209 | tr("\nwith %1 filesystem?\nYou will loose all data!!").arg( fs ) | 211 | tr("\nwith %1 filesystem?\nYou will loose all data!!").arg( fs ) |
210 | ,tr("Yes") | 212 | ,tr("Yes") |
211 | ,tr("No") | 213 | ,tr("No") |
212 | ,0 | 214 | ,0 |
213 | ,1 | 215 | ,1 |
214 | ,1) ) { | 216 | ,1) ) |
215 | case 0: { | 217 | { |
216 | if(fs == "vfat") | 218 | case 0: |
217 | cmd = "mkdosfs -v " + diskDevice+" 2>&1"; | 219 | { |
218 | else if(fs == "ext2") | 220 | if(fs == "vfat") |
219 | cmd = "mke2fs -v " + diskDevice+" 2>&1"; | 221 | cmd = "mkdosfs -v " + diskDevice+" 2>&1"; |
220 | else { | 222 | else if(fs == "ext2") |
221 | QMessageBox::warning(this, tr("Formatter"),tr("Could not format.\nUnknown type"), tr("Ok")); | 223 | cmd = "mke2fs -v " + diskDevice+" 2>&1"; |
222 | break; | 224 | else |
223 | } | 225 | { |
224 | // cmd = "ls -l"; | 226 | QMessageBox::warning(this, tr("Formatter"),tr("Could not format.\nUnknown type"), tr("Ok")); |
225 | outDlg = new Output(this, tr("Formatter Output"),FALSE); | 227 | break; |
226 | outDlg->showMaximized(); | 228 | } |
227 | outDlg->show(); | 229 | // cmd = "ls -l"; |
228 | qApp->processEvents(); | 230 | outDlg = new Output(this, tr("Formatter Output"),FALSE); |
229 | FILE *fp; | 231 | QPEApplication::showDialog( outDlg); |
230 | char line[130]; | 232 | qApp->processEvents(); |
231 | 233 | FILE *fp; | |
232 | 234 | char line[130]; | |
233 | outDlg->OutputEdit->append( tr("Trying to umount %1.").arg( currentText) ); | 235 | |
234 | outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); | 236 | |
235 | 237 | outDlg->OutputEdit->append( tr("Trying to umount %1.").arg( currentText) ); | |
236 | sleep(1); | 238 | outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); |
237 | qDebug("Command is "+umountS); | 239 | |
238 | fp = popen( (const char *) umountS, "r"); | 240 | sleep(1); |
239 | // qDebug("%d", fp); | 241 | qDebug("Command is "+umountS); |
240 | if ( !fp ) { | 242 | fp = popen( (const char *) umountS, "r"); |
241 | qDebug("Could not execute '" + umountS + "'! err=%d\n" +(QString)strerror(errno), err); | 243 | // qDebug("%d", fp); |
242 | QMessageBox::warning( this, tr("Formatter"), tr("umount failed!"), tr("&OK") ); | 244 | if ( !fp ) |
243 | pclose(fp); | 245 | { |
244 | return; | 246 | qDebug("Could not execute '" + umountS + "'! err=%d\n" +(QString)strerror(errno), err); |
245 | } else { | 247 | QMessageBox::warning( this, tr("Formatter"), tr("umount failed!"), tr("&OK") ); |
246 | // outDlg->OutputEdit->append( currentText + tr("\nhas been successfully umounted.")); | 248 | pclose(fp); |
247 | // outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); | 249 | return; |
248 | while ( fgets( line, sizeof line, fp)) { | 250 | } |
249 | if( ((QString)line).find("busy",0,TRUE) != -1) { | 251 | else |
250 | qDebug("Could not find '" + umountS); | 252 | { |
251 | QMessageBox::warning( this, tr("Formatter"), tr("Could not umount.\nDevice is busy!"), tr("&OK") ); | 253 | // outDlg->OutputEdit->append( currentText + tr("\nhas been successfully umounted.")); |
252 | pclose(fp); | 254 | // outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); |
253 | return; | 255 | while ( fgets( line, sizeof line, fp)) |
254 | } else { | 256 | { |
255 | QString lineStr = line; | 257 | if( ((QString)line).find("busy",0,TRUE) != -1) |
256 | lineStr=lineStr.left(lineStr.length()-1); | 258 | { |
257 | outDlg->OutputEdit->append(lineStr); | 259 | qDebug("Could not find '" + umountS); |
258 | outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); | 260 | QMessageBox::warning( this, tr("Formatter"), tr("Could not umount.\nDevice is busy!"), tr("&OK") ); |
259 | } | 261 | pclose(fp); |
260 | } | 262 | return; |
261 | } | 263 | } |
262 | pclose(fp); | 264 | else |
263 | 265 | { | |
264 | qDebug("Command would be: "+cmd); | 266 | QString lineStr = line; |
265 | outDlg->OutputEdit->append( tr("Trying to format.") ); | 267 | lineStr=lineStr.left(lineStr.length()-1); |
266 | outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); | 268 | outDlg->OutputEdit->append(lineStr); |
267 | 269 | outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); | |
268 | fp = popen( (const char *) cmd, "r"); | 270 | } |
269 | while ( fgets( line, sizeof line, fp)) { | 271 | } |
270 | if( ((QString)line).find("No such device",0,TRUE) != -1) { | 272 | } |
271 | qDebug("No such device '" + umountS); | 273 | pclose(fp); |
272 | QMessageBox::warning( this, tr("Formatter"), tr("No such device!"), tr("&OK") ); | 274 | |
273 | pclose(fp); | 275 | qDebug("Command would be: "+cmd); |
274 | // outDlg->OutputEdit->append("No such device"); | 276 | outDlg->OutputEdit->append( tr("Trying to format.") ); |
275 | // outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); | 277 | outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); |
276 | return; | 278 | |
277 | } else { | 279 | fp = popen( (const char *) cmd, "r"); |
278 | QString lineStr = line; | 280 | while ( fgets( line, sizeof line, fp)) |
279 | lineStr=lineStr.left(lineStr.length()-1); | 281 | { |
280 | outDlg->OutputEdit->append(lineStr); | 282 | if( ((QString)line).find("No such device",0,TRUE) != -1) |
281 | outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); | 283 | { |
282 | } | 284 | qDebug("No such device '" + umountS); |
283 | } | 285 | QMessageBox::warning( this, tr("Formatter"), tr("No such device!"), tr("&OK") ); |
284 | outDlg->OutputEdit->append( currentText + tr("\nhas been successfully formatted.")); | 286 | pclose(fp); |
285 | outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); | 287 | // outDlg->OutputEdit->append("No such device"); |
286 | pclose(fp); | 288 | // outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); |
287 | 289 | return; | |
288 | outDlg->OutputEdit->append( tr("Trying to mount %1.").arg( currentText) ); | 290 | } |
289 | outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); | 291 | else |
290 | fp = popen( (const char *) remountS, "r"); | 292 | { |
291 | if ( !fp) { | 293 | QString lineStr = line; |
292 | qDebug("Could not execute '" + remountS + "'! err=%d\n" +(QString)strerror(errno), err); | 294 | lineStr=lineStr.left(lineStr.length()-1); |
293 | QMessageBox::warning( this, tr("Formatter"), tr("Card mount failed!"), tr("&OK") ); | 295 | outDlg->OutputEdit->append(lineStr); |
294 | 296 | outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); | |
295 | } else { | 297 | } |
296 | outDlg->OutputEdit->append(tr("%1\nhas been successfully mounted.").arg( currentText )); | 298 | } |
297 | while ( fgets( line, sizeof line, fp)) { | 299 | outDlg->OutputEdit->append( currentText + tr("\nhas been successfully formatted.")); |
298 | QString lineStr = line; | 300 | outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); |
299 | lineStr=lineStr.left(lineStr.length()-1); | 301 | pclose(fp); |
300 | outDlg->OutputEdit->append(lineStr); | 302 | |
301 | outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); | 303 | outDlg->OutputEdit->append( tr("Trying to mount %1.").arg( currentText) ); |
302 | } | 304 | outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); |
303 | } | 305 | fp = popen( (const char *) remountS, "r"); |
304 | pclose(fp); | 306 | if ( !fp) |
305 | sleep(1); | 307 | { |
306 | 308 | qDebug("Could not execute '" + remountS + "'! err=%d\n" +(QString)strerror(errno), err); | |
307 | outDlg->OutputEdit->append(tr("You can now close the output window.")); | 309 | QMessageBox::warning( this, tr("Formatter"), tr("Card mount failed!"), tr("&OK") ); |
308 | outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); | 310 | |
309 | // outDlg->close(); | 311 | } |
310 | // if(outDlg) | 312 | else |
311 | // delete outDlg; | 313 | { |
312 | } | 314 | outDlg->OutputEdit->append(tr("%1\nhas been successfully mounted.").arg( currentText )); |
313 | break; | 315 | while ( fgets( line, sizeof line, fp)) |
316 | { | ||
317 | QString lineStr = line; | ||
318 | lineStr=lineStr.left(lineStr.length()-1); | ||
319 | outDlg->OutputEdit->append(lineStr); | ||
320 | outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); | ||
321 | } | ||
322 | } | ||
323 | pclose(fp); | ||
324 | sleep(1); | ||
325 | |||
326 | outDlg->OutputEdit->append(tr("You can now close the output window.")); | ||
327 | outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); | ||
328 | // outDlg->close(); | ||
329 | // if(outDlg) | ||
330 | // delete outDlg; | ||
331 | } | ||
332 | break; | ||
314 | }; | 333 | }; |
315 | } | 334 | } |
316 | 335 | ||
317 | bool FormatterApp::doFdisk() { | 336 | bool FormatterApp::doFdisk() |
337 | { | ||
318 | return FALSE; | 338 | return FALSE; |
319 | 339 | ||
320 | } | 340 | } |
321 | 341 | ||
322 | void FormatterApp::fillCombos() { | 342 | void 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); |
337 | } | 360 | } |
338 | parsetab("/etc/mtab"); | 361 | parsetab("/etc/mtab"); |
339 | // parsetab("/etc/fstab"); | 362 | // parsetab("/etc/fstab"); |
340 | fileSystemsCombo->insertStringList( fsList,-1); | 363 | fileSystemsCombo->insertStringList( fsList,-1); |
341 | deviceComboBox->insertStringList( deviceList,-1); | 364 | deviceComboBox->insertStringList( deviceList,-1); |
342 | storageComboSelected(0); | 365 | storageComboSelected(0); |
343 | deviceComboSelected(0); | 366 | deviceComboSelected(0); |
344 | } | 367 | } |
345 | 368 | ||
346 | 369 | ||
347 | void FormatterApp::fsComboSelected(int ) { | 370 | void FormatterApp::fsComboSelected(int ) |
371 | {} | ||
348 | 372 | ||
349 | } | 373 | void FormatterApp::storageComboSelected(int index ) |
350 | 374 | { | |
351 | void 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)); |
355 | 378 | ||
356 | TextLabel4->setText( tr( "Storage Type: %1").arg( nameS) ); | 379 | TextLabel4->setText( tr( "Storage Type: %1").arg( nameS) ); |
357 | currentText = currentText.right( currentText.length() - currentText.find(" -> ",0,TRUE) - 4); | 380 | currentText = currentText.right( currentText.length() - currentText.find(" -> ",0,TRUE) - 4); |
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 | ||
368 | void FormatterApp::deviceComboSelected(int index) { | 392 | void 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; |
372 | 397 | ||
@@ -374,14 +399,16 @@ void FormatterApp::deviceComboSelected(int index) { | |||
374 | 399 | ||
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; |
387 | long div = 1024 / (*it)->blockSize(); | 414 | long div = 1024 / (*it)->blockSize(); |
@@ -399,103 +426,111 @@ void FormatterApp::deviceComboSelected(int index) { | |||
399 | } | 426 | } |
400 | } | 427 | } |
401 | fsType = getFileSystemType((const QString &)selectedText); | 428 | fsType = getFileSystemType((const QString &)selectedText); |
402 | 429 | ||
403 | TextLabel5->setText(tr("Type: %1\nFormatted with %2\n%3, %4, %5").arg( nameS).arg( fsType).arg(totalS).arg( usedS).arg( avS )); | 430 | TextLabel5->setText(tr("Type: %1\nFormatted with %2\n%3, %4, %5").arg( nameS).arg( fsType).arg(totalS).arg( usedS).arg( avS )); |
404 | TextLabel5->setTextFormat( Qt::RichText ); | 431 | TextLabel5->setTextFormat( Qt::RichText ); |
405 | // storageComboSelected(0); | 432 | // storageComboSelected(0); |
406 | } | 433 | } |
407 | 434 | ||
408 | void FormatterApp::cleanUp() { | 435 | void FormatterApp::cleanUp() |
436 | {} | ||
409 | 437 | ||
410 | } | ||
411 | 438 | ||
412 | 439 | void FormatterApp::editFstab() | |
413 | void 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 | ||
418 | void FormatterApp::parsetab(const QString &fileName) { | 445 | void 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 |
433 | & filesystemType.find("auto",0,TRUE) == -1) | 464 | & filesystemType.find("auto",0,TRUE) == -1) |
434 | fsList << filesystemType; | 465 | fsList << filesystemType; |
435 | deviceList << deviceName; | 466 | deviceList << deviceName; |
436 | qDebug(deviceName+"::"+filesystemType); | 467 | qDebug(deviceName+"::"+filesystemType); |
437 | fileSystemTypeList << deviceName+"::"+filesystemType; | 468 | fileSystemTypeList << deviceName+"::"+filesystemType; |
438 | } | 469 | } |
439 | } | 470 | } |
440 | } | 471 | } |
441 | endmntent( mntfp ); | 472 | endmntent( mntfp ); |
442 | // } else if(fileName == "/etc/fstab") { | 473 | // } else if(fileName == "/etc/fstab") { |
443 | // QFile f("/etc/fstab"); | 474 | // QFile f("/etc/fstab"); |
444 | // if ( f.open(IO_ReadOnly) ) { | 475 | // if ( f.open(IO_ReadOnly) ) { |
445 | // QTextStream t (&f); | 476 | // QTextStream t (&f); |
446 | // QString s; | 477 | // QString s; |
447 | // while (! t.eof()) { | 478 | // while (! t.eof()) { |
448 | // s=t.readLine(); | 479 | // s=t.readLine(); |
449 | // s=s.simplifyWhiteSpace(); | 480 | // s=s.simplifyWhiteSpace(); |
450 | // if ( (!s.isEmpty() ) && (s.find(" ")!=0) ) { | 481 | // if ( (!s.isEmpty() ) && (s.find(" ")!=0) ) { |
451 | // // = me->mnt_fsname; | 482 | // // = me->mnt_fsname; |
452 | // QString filesystemType = me->mnt_type; | 483 | // QString filesystemType = me->mnt_type; |
453 | // QString deviceName = s.left(0,s.find(BLANK) ); | 484 | // QString deviceName = s.left(0,s.find(BLANK) ); |
454 | // s=s.remove(0,s.find(BLANK)+1 ); // devicename | 485 | // s=s.remove(0,s.find(BLANK)+1 ); // devicename |
455 | 486 | ||
456 | // s=s.remove(0,s.find(BLANK)+1 ); // mountpoint | 487 | // s=s.remove(0,s.find(BLANK)+1 ); // mountpoint |
457 | // QStringt mountPoint= s.left(0,s.find(BLANK) ); | 488 | // QStringt mountPoint= s.left(0,s.find(BLANK) ); |
458 | // s=s.remove(0,s.find(BLANK)+1 ); // fs | 489 | // s=s.remove(0,s.find(BLANK)+1 ); // fs |
459 | // QString filesystemType= s.left(0,s.find(BLANK) ); | 490 | // QString filesystemType= s.left(0,s.find(BLANK) ); |
460 | // } | 491 | // } |
461 | // } | 492 | // } |
462 | // } | 493 | // } |
463 | // f.close(); | 494 | // f.close(); |
464 | // } | 495 | // } |
465 | } | 496 | } |
466 | 497 | ||
467 | QString FormatterApp::getFileSystemType(const QString ¤tText) { | 498 | QString FormatterApp::getFileSystemType(const QString ¤tText) |
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 | } |
477 | } | 511 | } |
478 | return ""; | 512 | return ""; |
479 | } | 513 | } |
480 | 514 | ||
481 | bool FormatterApp::doFsck() { | 515 | bool FormatterApp::doFsck() |
516 | { | ||
482 | 517 | ||
483 | Output *outDlg; | 518 | Output *outDlg; |
484 | QString selectedDevice; | 519 | QString selectedDevice; |
485 | // #if defined(QT_QWS_IPAQ) || defined(QT_QWS_SL5XXX) | 520 | // #if defined(QT_QWS_IPAQ) || defined(QT_QWS_SL5XXX) |
486 | selectedDevice = deviceComboBox->currentText(); | 521 | selectedDevice = deviceComboBox->currentText(); |
487 | QString mountPoint = mountPointLineEdit->text(); | 522 | QString mountPoint = mountPointLineEdit->text(); |
488 | QString umountS = "umount -v "+mountPoint+" 2>&1"; | 523 | QString umountS = "umount -v "+mountPoint+" 2>&1"; |
489 | QString remountS = "mount -v "+mountPoint+" 2>&1"; | 524 | QString remountS = "mount -v "+mountPoint+" 2>&1"; |
490 | // #else | 525 | // #else |
491 | // // for testing | 526 | // // for testing |
492 | // // currentText = diskDevice = "/dev/fd0"; | 527 | // // currentText = diskDevice = "/dev/fd0"; |
493 | // QString umountS = "umount -v /floppy 2>&1"; | 528 | // QString umountS = "umount -v /floppy 2>&1"; |
494 | // QString remountS = "mount -v /floppy 2>&1"; | 529 | // QString remountS = "mount -v /floppy 2>&1"; |
495 | // selectedDevice ="/dev/fd0"; | 530 | // selectedDevice ="/dev/fd0"; |
496 | 531 | ||
497 | // #endif | 532 | // #endif |
498 | 533 | ||
499 | QString fsType = getFileSystemType((const QString &)selectedDevice); | 534 | QString fsType = getFileSystemType((const QString &)selectedDevice); |
500 | QString cmd; | 535 | QString cmd; |
501 | qDebug( selectedDevice +" "+ fsType); | 536 | qDebug( selectedDevice +" "+ fsType); |
@@ -503,82 +538,95 @@ bool FormatterApp::doFsck() { | |||
503 | if(fsType == "ext2") cmd = "e2fsck -cpvy "; | 538 | if(fsType == "ext2") cmd = "e2fsck -cpvy "; |
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]; |
512 | outDlg->OutputEdit->append( tr("Trying to umount.")); | 546 | outDlg->OutputEdit->append( tr("Trying to umount.")); |
513 | outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); | 547 | outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); |
514 | 548 | ||
515 | sleep(1); | 549 | sleep(1); |
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 ) |
520 | qDebug("Could not execute '" + umountS + "'!\n" +(QString)strerror(errno)); | 554 | { |
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 | } |
525 | // outDlg->OutputEdit->append( currentText + tr("\nhas been successfully umounted.")); | 560 | else |
526 | // outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); | 561 | { |
527 | while ( fgets( line, sizeof line, fp)) { | 562 | // outDlg->OutputEdit->append( currentText + tr("\nhas been successfully umounted.")); |
528 | if( ((QString)line).find("busy",0,TRUE) != -1) { | 563 | // outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); |
529 | qDebug("Could not find '" + umountS); | 564 | while ( fgets( line, sizeof line, fp)) |
565 | { | ||
566 | if( ((QString)line).find("busy",0,TRUE) != -1) | ||
567 | { | ||
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); |
538 | outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); | 579 | outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); |
539 | } | 580 | } |
540 | } | 581 | } |
541 | } | 582 | } |
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 | { |
547 | qDebug("No such device '" + umountS); | 588 | if( ((QString)line).find("No such device",0,TRUE) != -1) |
589 | { | ||
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); |
557 | outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); | 602 | outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); |
558 | } | 603 | } |
559 | } | 604 | } |
560 | outDlg->OutputEdit->append(tr("You can now close the output window.")); | 605 | outDlg->OutputEdit->append(tr("You can now close the output window.")); |
561 | outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); | 606 | outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); |
562 | // outDlg->OutputEdit->append( currentText + tr("\nhas been successfully formatted.")); | 607 | // outDlg->OutputEdit->append( currentText + tr("\nhas been successfully formatted.")); |
563 | // outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); | 608 | // outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); |
564 | pclose(fp); | 609 | pclose(fp); |
565 | 610 | ||
566 | ///////////////////////////////////////// | 611 | ///////////////////////////////////////// |
567 | 612 | ||
568 | return true; | 613 | return true; |
569 | } | 614 | } |
570 | 615 | ||
571 | bool FormatterApp::doFsckCheck() { | 616 | bool FormatterApp::doFsckCheck() |
617 | { | ||
572 | 618 | ||
573 | return FALSE; | 619 | return FALSE; |
574 | } | 620 | } |
575 | 621 | ||
576 | int FormatterApp::formatCheck(const QString &) { | 622 | int FormatterApp::formatCheck(const QString &) |
623 | { | ||
577 | 624 | ||
578 | return -1; | 625 | return -1; |
579 | } | 626 | } |
580 | 627 | ||
581 | int FormatterApp::runCommand(const QString &) { | 628 | int FormatterApp::runCommand(const QString &) |
629 | { | ||
582 | 630 | ||
583 | return -1; | 631 | return -1; |
584 | } | 632 | } |