30 #include <qgroupbox.h>
31 #include <qradiobutton.h>
33 #include <QVBoxLayout>
35 #include <QHBoxLayout>
36 #include <QGridLayout>
38 #include <QCloseEvent>
39 #include <QtDBus/QtDBus>
42 #include <kmessagebox.h>
44 #include <khelpmenu.h>
45 #include <kpushbutton.h>
47 #include <kapplication.h>
48 #include <qprogressbar.h>
50 #include <kcombobox.h>
51 #include <klineedit.h>
53 #include <ktoolinvocation.h>
58 formatActions(0L), m_canLowLevel(false), m_canZeroOut( false )
60 QWidget *widget =
new QWidget(
this);
61 setMainWidget(widget);
67 QVBoxLayout* ml =
new QVBoxLayout( widget );
70 QHBoxLayout* h1 =
new QHBoxLayout();
73 QVBoxLayout* v1 =
new QVBoxLayout( );
77 QGridLayout* g1 =
new QGridLayout();
80 deviceComboBox =
new KComboBox(
false, widget );
81 label1 =
new QLabel( i18n(
"Floppy &drive:"), widget );
82 label1->setBuddy( deviceComboBox );
83 g1->addWidget( label1, 0, 0, Qt::AlignLeft );
84 g1->addWidget( deviceComboBox, 0, 1 );
87 deviceComboBox->setEditable(
true );
89 deviceComboBox->addItem(i18nc(
"Primary floppy drive",
"Primary"));
90 deviceComboBox->addItem(i18nc(
"Secondary floppy drive",
"Secondary"));
92 const QString deviceWhatsThis = i18n(
"<qt>Select the floppy drive.</qt>");
94 label1->setWhatsThis( deviceWhatsThis);
95 deviceComboBox->setWhatsThis( deviceWhatsThis);
98 densityComboBox =
new KComboBox(
false, widget );
99 label2 =
new QLabel( i18n(
"&Size:"), widget);
100 label2->setBuddy( densityComboBox );
101 g1->addWidget( label2, 1, 0, Qt::AlignLeft );
102 g1->addWidget( densityComboBox, 1, 1 );
104 #if defined(ANY_LINUX)
105 densityComboBox->addItem( i18n(
"Auto-Detect" ) );
107 densityComboBox->addItem(i18n(
"3.5\" 1.44MB"));
108 densityComboBox->addItem(i18n(
"3.5\" 720KB"));
109 densityComboBox->addItem(i18n(
"5.25\" 1.2MB"));
110 densityComboBox->addItem(i18n(
"5.25\" 360KB"));
112 const QString densityWhatsThis =
113 i18n(
"<qt>This allows you to select the "
114 "floppy disk's size and density.</qt>");
116 label2->setWhatsThis( densityWhatsThis);
117 densityComboBox->setWhatsThis( densityWhatsThis);
120 filesystemComboBox =
new KComboBox(
false, widget );
121 label3 =
new QLabel( i18n(
"F&ile system:"), widget);
122 label3->setBuddy( filesystemComboBox );
123 g1->addWidget( label3, 2, 0, Qt::AlignLeft );
124 g1->addWidget( filesystemComboBox, 2, 1 );
125 g1->setColumnStretch(1, 1);
127 #if defined(ANY_LINUX)
128 label3->setWhatsThis(
129 i18nc(
"Linux",
"KFloppy supports three file formats under Linux: MS-DOS, Ext2, and Minix" ) );
130 #elif defined(ANY_BSD)
131 label3->setWhatsThis(
132 i18nc(
"BSD",
"KFloppy supports three file formats under BSD: MS-DOS, UFS, and Ext2" ) );
136 QString userFeedBack;
137 uint numFileSystems = 0;
139 #if defined(ANY_LINUX)
140 filesystemComboBox->setWhatsThis(
141 i18nc(
"Linux",
"KFloppy supports three file formats under Linux: MS-DOS, Ext2, and Minix" ) );
143 filesystemComboBox->addItem(i18n(
"DOS"));
145 userFeedBack += i18nc(
"Linux",
"Program mkdosfs found." );
148 userFeedBack += i18nc(
"Linux",
"Program mkdosfs <b>not found</b>. MSDOS formatting <b>not available</b>." );
150 userFeedBack += QLatin1String(
"<br>" );
152 filesystemComboBox->addItem(i18n(
"ext2"));
154 userFeedBack += i18n(
"Program mke2fs found." );
157 userFeedBack += i18n(
"Program mke2fs <b>not found</b>. Ext2 formatting <b>not available</b>" );
159 userFeedBack += QLatin1String(
"<br>" );
160 if (MinixFilesystem::runtimeCheck()) {
161 filesystemComboBox->addItem(i18n(
"Minix"));
163 userFeedBack += i18nc(
"Linux",
"Program mkfs.minix found." );
166 userFeedBack += i18nc(
"Linux",
"Program mkfs.minix <b>not found</b>. Minix formatting <b>not available</b>" );
168 #elif defined(ANY_BSD)
169 filesystemComboBox->setWhatsThis(
170 i18nc(
"BSD",
"KFloppy supports two file formats under BSD: MS-DOS and UFS" ) );
172 filesystemComboBox->addItem(i18n(
"DOS"));
174 userFeedBack += i18nc(
"BSD",
"Program newfs_msdos found." );
177 userFeedBack += i18nc(
"BSD",
"Program newfs_msdos <b>not found</b>. MSDOS formatting <b>not available</b>." );
179 userFeedBack += QLatin1String(
"<br>" );
180 if (UFSFilesystem::runtimeCheck()) {
181 filesystemComboBox->addItem(i18n(
"UFS"));
183 userFeedBack += i18nc(
"BSD",
"Program newfs found." );
186 userFeedBack += i18nc(
"BSD",
"Program newfs <b>not found</b>. UFS formatting <b>not available</b>." );
188 userFeedBack += QLatin1String(
"<br>" );
190 filesystemComboBox->addItem(i18n(
"ext2"));
192 userFeedBack += i18n(
"Program mke2fs found." );
195 userFeedBack += i18n(
"Program mke2fs <b>not found</b>. Ext2 formatting <b>not available</b>" );
199 v1->addSpacing( 10 );
201 buttongroup =
new QGroupBox( i18n(
"&Formatting"),
this );
202 QVBoxLayout* buttonGroupLayout =
new QVBoxLayout(buttongroup);
204 quick =
new QRadioButton( i18n(
"Q&uick format" ), buttongroup );
205 buttonGroupLayout->addWidget(quick);
206 quick->setObjectName( QLatin1String(
"RadioButton_2" ) );
208 i18n(
"<qt>Quick format is only a high-level format:"
209 " it creates only a file system.</qt>") );
211 zerooutformat =
new QRadioButton( i18n(
"&Zero out and quick format"), buttongroup );
212 buttonGroupLayout->addWidget(zerooutformat);
213 zerooutformat->setObjectName( QLatin1String(
"RadioButton_ZeroOutFormat" ) );
214 zerooutformat->setWhatsThis(
215 i18n(
"<qt>This first erases the floppy by writing zeros and then it creates the file system.</qt>") );
217 fullformat =
new QRadioButton( i18n(
"Fu&ll format"), buttongroup );
218 buttonGroupLayout->addWidget(fullformat);
219 fullformat->setObjectName( QLatin1String(
"RadioButton_3" ) );
220 fullformat->setWhatsThis(
221 i18n(
"Full format is a low-level and high-level format. It erases everything on the disk.") );
223 v1->addWidget( buttongroup );
226 userFeedBack += QLatin1String(
"<br>" );
229 fullformat->setChecked(
true);
230 userFeedBack += i18n(
"Program fdformat found." );
233 fullformat->setDisabled(
true);
234 quick->setChecked(
true);
235 userFeedBack += i18n(
"Program fdformat <b>not found</b>. Full formatting <b>disabled</b>." );
237 userFeedBack += QLatin1String(
"<br>" );
241 zerooutformat->setChecked(
true );
242 userFeedBack += i18n(
"Program dd found." );
245 zerooutformat->setDisabled(
true);
246 userFeedBack += i18n(
"Program dd <b>not found</b>. Zeroing-out <b>disabled</b>." );
249 verifylabel =
new QCheckBox(
this );
250 verifylabel->setObjectName( QLatin1String(
"CheckBox_Integrity" ) );
251 verifylabel->setText(i18n(
"&Verify integrity" ));
252 verifylabel->setChecked(
true);
253 v1->addWidget( verifylabel, Qt::AlignLeft );
254 verifylabel->setWhatsThis(
255 i18n(
"<qt>Check this if you want the floppy disk to be checked after formatting."
256 " Please note that the floppy will be checked twice if you have selected full formatting.</qt>") );
258 labellabel =
new QCheckBox(
this );
259 labellabel->setObjectName( QLatin1String(
"Checkbox_Label" ) );
260 labellabel->setText(i18n(
"Volume la&bel:") );
261 labellabel->setChecked(
true);
262 v1->addWidget( labellabel, Qt::AlignLeft );
263 labellabel->setWhatsThis(
264 i18n(
"<qt>Check this if you want a volume label for your floppy."
265 " Please note that Minix does not support labels at all.</qt>") );
267 QHBoxLayout* h2 =
new QHBoxLayout();
269 h2->addSpacing( 20 );
271 lineedit =
new KLineEdit( widget );
273 lineedit->setText(i18nc(
"Volume label, maximal 11 characters",
"KDE Floppy" ) );
274 lineedit->setMaxLength(11);
275 h2->addWidget( lineedit, Qt::AlignRight );
276 lineedit->setWhatsThis(
277 i18n(
"<qt>This is for the volume label."
278 " Due to a limitation of MS-DOS the label can only be 11 characters long."
279 " Please note that Minix does not support labels, whatever you enter here.</qt>") );
281 connect(labellabel,SIGNAL(toggled(
bool)),lineedit,SLOT(
setEnabled(
bool)));
283 QVBoxLayout* v3 =
new QVBoxLayout();
286 formatbutton =
new KPushButton( widget );
287 formatbutton->setText(i18n(
"&Format") );
288 formatbutton->setAutoRepeat(
false );
290 formatbutton->setDisabled(
false);
291 connect(formatbutton,SIGNAL(clicked()),
this,SLOT(
format()));
292 v3->addWidget( formatbutton );
293 formatbutton->setWhatsThis(
294 i18n(
"<qt>Click here to start formatting.</qt>") );
299 helpMenu =
new KHelpMenu(
this, KGlobal::mainComponent().aboutData(),
false);
301 helpbutton =
new KPushButton( KStandardGuiItem::help(), widget );
302 helpbutton->setAutoRepeat(
false );
303 helpbutton->setMenu(helpMenu->menu());
304 v3->addWidget( helpbutton );
306 quitbutton =
new KPushButton( KStandardGuiItem::quit(), widget );
307 quitbutton->setAutoRepeat(
false );
308 connect(quitbutton,SIGNAL(clicked()),
this,SLOT(
quit()));
309 v3->addWidget( quitbutton );
311 ml->addSpacing( 10 );
313 frame =
new QLabel( widget );
314 frame->setObjectName( QLatin1String(
"NewsWindow" ) );
315 frame->setFrameStyle(QFrame::Panel | QFrame::Sunken);
316 frame->setWordWrap(
true );
318 i18n(
"<qt>This is the status window, where error messages are displayed.</qt>") );
320 QString frameText( userFeedBack );
321 frameText.prepend( QLatin1String(
"<qt>" ) );
322 frameText.append( QLatin1String(
"</qt>" ) );
323 frame->setText( frameText );
325 ml->addWidget( frame );
327 progress =
new QProgressBar( widget );
328 progress->setDisabled(
true );
329 ml->addWidget( progress );
331 progress->setWhatsThis(
332 i18n(
"<qt>Shows progress of the format.</qt>"));
337 if (!numFileSystems) {
338 QString errorMessage;
339 errorMessage += QLatin1String(
"<qt>" );
340 errorMessage += i18n(
"KFloppy cannot find any of the needed programs for creating file systems; please check your installation.<br /><br />Log:");
341 errorMessage += QLatin1String(
"<br>" );
342 errorMessage += userFeedBack;
343 errorMessage += QLatin1String(
"</qt>" );
344 KMessageBox::error(
this, errorMessage );
351 delete formatActions;
363 KToolInvocation::invokeHelp();
366 KDialog::keyPressEvent(e);
372 setCaption(i18n(
"KDE Floppy Formatter"));
381 if( deviceComboBox->currentText() == i18nc(
"Primary floppy drive",
"Primary") )
385 else if( deviceComboBox->currentText() == i18nc(
"Secondary floppy drive",
"Secondary") )
392 if( densityComboBox->currentText() == i18n(
"3.5\" 1.44MB")){
396 if( densityComboBox->currentText() == i18n(
"3.5\" 720KB")){
400 if( densityComboBox->currentText() == i18n(
"5.25\" 1.2MB")){
404 if( densityComboBox->currentText() == i18n(
"5.25\" 360KB")){
407 #if defined(ANY_LINUX)
419 QString newDevice = dev;
421 KUrl url( newDevice );
422 if( url.isValid() && ( url.protocol() == QLatin1String(
"media" ) || url.protocol() == QLatin1String(
"system" ) ) ) {
423 QString name = url.fileName();
425 QDBusInterface mediamanager( QLatin1String(
"org.kde.kded" ), QLatin1String(
"/modules/mediamanager" ), QLatin1String(
"org.kde.MediaManager" ) );
426 QDBusReply<QStringList> reply = mediamanager.call( QLatin1String(
"properties" ), name );
427 if (!reply.isValid()) {
428 kError() <<
"Invalid reply from mediamanager" << endl;
430 QStringList properties = reply;
431 newDevice = properties[5];
436 if ( newDevice.startsWith(QLatin1String(
"/dev/fd0" )) )
438 if ( newDevice.startsWith(QLatin1String(
"/dev/fd1" )))
443 bool ok = (drive>=0);
445 deviceComboBox->setCurrentIndex(drive);
450 if (formatActions) formatActions->
quit();
461 setCursor(QCursor(Qt::WaitCursor));
462 label1->setEnabled(b);
463 deviceComboBox->setEnabled(b);
464 label2->setEnabled(b);
465 densityComboBox->setEnabled(b);
466 label3->setEnabled(b);
467 filesystemComboBox->setEnabled(b);
468 buttongroup->setEnabled(b);
469 quick->setEnabled(b);
470 fullformat->setEnabled(b && m_canLowLevel);
471 zerooutformat->setEnabled(b && m_canZeroOut);
472 verifylabel->setEnabled(b);
473 labellabel->setEnabled(b);
474 lineedit->setEnabled(b && labellabel->isChecked() );
475 helpbutton->setEnabled(b);
476 quitbutton->setEnabled(b);
477 formatbutton->setEnabled(b);
478 progress->setDisabled( b );
489 formatActions->
quit();
490 delete formatActions;
494 progress->setValue(0);
495 formatbutton->setText(i18n(
"&Format"));
509 const QString currentComboBoxDevice ( deviceComboBox->currentText() );
510 const bool userDevice = ( currentComboBoxDevice.startsWith (QLatin1String(
"/dev/" )) );
513 if ( userDevice && filesystemComboBox->currentText() != i18n(
"UFS"))
515 KMessageBox::error(
this, i18nc(
"BSD",
"Formatting with BSD on a user-given device is only possible with UFS") );
520 if ( userDevice && ( quick->isChecked() || zerooutformat->isChecked() ) )
522 if (KMessageBox::warningContinueCancel(
this,
523 i18n(
"<qt>Formatting will erase all data on the device:<br/><b>%1</b><br/>"
524 "(Please check the correctness of the device name.)<br/>"
525 "Are you sure you wish to proceed?</qt>", currentComboBoxDevice )
526 , i18n(
"Proceed?") ) != KMessageBox::Continue)
531 else if ( userDevice )
534 KMessageBox::error(
this, i18n(
"Full formatting of a user-given device is not possible.") );
539 if (KMessageBox::warningContinueCancel(
this,
540 i18n(
"Formatting will erase all data on the disk.\n"
541 "Are you sure you wish to proceed?"), i18n(
"Proceed?") ) !=
542 KMessageBox::Continue)
552 frame->setText( QString::null );
563 delete formatActions;
566 connect(formatActions,SIGNAL(status(QString,
int)),
568 connect(formatActions,SIGNAL(done(
KFAction*,
bool)),
571 if ( quick->isChecked())
576 else if ( zerooutformat->isChecked() )
587 formatActions->
queue(f);
589 else if ( userDevice )
600 formatActions->
queue(f);
603 if ( filesystemComboBox->currentText() == i18n(
"DOS") )
607 labellabel->isChecked(),
617 formatActions->
queue(f);
620 else if ( filesystemComboBox->currentText() == i18n(
"ext2") )
624 labellabel->isChecked(),
634 formatActions->
queue(f);
638 else if ( filesystemComboBox->currentText() == i18n(
"UFS") )
642 formatActions->
queue(f);
647 else if ( filesystemComboBox->currentText() == i18n(
"Minix") )
649 MinixFilesystem *f =
new MinixFilesystem(
this);
650 f->configure(verifylabel->isChecked(),
651 labellabel->isChecked(),
655 f->configureDevice( currentComboBoxDevice );
659 f->configureDevice(drive,blocks);
661 formatActions->
queue(f);
665 formatActions->
exec();
670 kDebug(2002) <<
"FloppyData::formatStatus: " << s <<
" : " << p ;
673 const QString oldText ( frame->text() );
674 if ( oldText.isEmpty() )
680 frame->setText( oldText + QLatin1Char(
'\n' ) + s );
684 if ((0<=p) && (p<=100))
685 progress->setValue(p);
690 KConfigGroup config = KGlobal::config()->group(
"GeneralData");
692 densityconfig = densityComboBox->currentText().trimmed();
693 filesystemconfig = filesystemComboBox->currentText().trimmed();
694 driveconfig = deviceComboBox->currentText().trimmed();
696 quickformatconfig = quick->isChecked();
698 labelnameconfig = lineedit->text().trimmed();
700 labelconfig = labellabel->isChecked();
702 verifyconfig = verifylabel->isChecked();
704 config.writeEntry(
"CreateLabel",labelconfig);
705 config.writeEntry(
"Label",labelnameconfig);
708 config.writeEntry(
"QuickFormat",quickformatconfig);
709 config.writeEntry(
"FloppyDrive",driveconfig);
710 config.writeEntry(
"Density",densityconfig);
711 config.writeEntry(
"Filesystem",filesystemconfig);
712 config.writeEntry(
"Verify",verifyconfig);
718 KConfigGroup config = KGlobal::config()->group(
"GeneralData");
720 verifyconfig = config.readEntry(
"Verify", 1);
721 labelconfig = config.readEntry(
"CreateLabel",1);
722 labelnameconfig = config.readEntry(
"Label", i18nc(
"Volume label, maximal 11 characters",
"KDE Floppy") );
723 quickformatconfig = config.readEntry(
"QuickFormat",0);
724 driveconfig = config.readEntry(
"FloppyDrive", i18nc(
"Primary floppy drive",
"Primary") );
725 #if defined(ANY_LINUX)
726 densityconfig = config.readEntry(
"Density", i18n(
"Auto-Detect" ) );
728 densityconfig = config.readEntry(
"Density", i18n(
"3.5\" 1.44MB") );
730 filesystemconfig = config.readEntry(
"Filesystem", i18n(
"DOS") );
735 labellabel->setChecked(labelconfig);
736 verifylabel->setChecked(verifyconfig);
737 quick->setChecked(quickformatconfig || !m_canLowLevel);
738 fullformat->setChecked(!quickformatconfig && m_canLowLevel);
739 lineedit->setText(labelnameconfig);
741 for(
int i = 0 ; i < deviceComboBox->count(); i++){
742 if ( deviceComboBox->itemText(i) == driveconfig){
743 deviceComboBox->setCurrentIndex(i);
747 for(
int i = 0 ; i < filesystemComboBox->count(); i++){
748 if ( filesystemComboBox->itemText(i) == filesystemconfig){
749 filesystemComboBox->setCurrentIndex(i);
753 for(
int i = 0 ; i < densityComboBox->count(); i++){
754 if ( densityComboBox->itemText(i) == densityconfig){
755 densityComboBox->setCurrentIndex(i);
760 #include "floppy.moc"
virtual void quit()
Quit aborts the action.
void queue(KFAction *)
Add a KFAction to the queue.
bool findDevice()
Maps combobox selection to drive and density.
void show()
Need to overload normal show() in order to mangle caption.
void writeSettings()
Writing the user-visible settings.
bool configure(bool verify, bool label, const QString &l)
newfs_msdos(1) doesn't support an additional verify, but Linux mkdosfs(1) does.
virtual void exec()
Exec() should return quickly to ensire that the GUI thread stays alive.
void formatStatus(const QString &, int)
void closeEvent(QCloseEvent *)
Override closeEvent() in order to properly close the entire application.
Acts as a queue and executes the actions in the queue in FIFO order.
bool configureDevice(int driveno, int density)
ConfigureDevice() needs to be called prior to exec() or exec() will fail; this indicates which drive ...
static bool runtimeCheck()
Zero out disk by runnind dd(1)
void readSettings()
Reading the user-visible settings.
Concrete action for running a single external program.
static bool runtimeCheck()
void setWidgets()
Map stored settings to widget status.
bool setInitialDevice(const QString &dev)
set default device
bool configure(bool verify, bool label, const QString &l)
Same args as FATFilesystem::configure.
void setEnabled(bool)
Enable/disable all UI elements.
Create an msdos (FAT) filesystem on the floppy.
Abstract base class of actions to be undertaken.
FloppyData(QWidget *parent=0)
void keyPressEvent(QKeyEvent *e)
static bool runtimeCheck()
Concrete classes can provide a runtimeCheck function (heck, this is static, so the name is up to you)...