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