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 )
61 setMainWidget(widget);
80 deviceComboBox =
new KComboBox(
false, widget );
81 label1 =
new QLabel( i18n(
"Floppy &drive:"), widget );
83 g1->
addWidget( label1, 0, 0, Qt::AlignLeft );
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>");
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 );
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>");
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 );
127 #if defined(ANY_LINUX)
129 i18nc(
"Linux",
"KFloppy supports three file formats under Linux: MS-DOS, Ext2, and Minix" ) );
130 #elif defined(ANY_BSD)
132 i18nc(
"BSD",
"KFloppy supports three file formats under BSD: MS-DOS, UFS, and Ext2" ) );
137 uint numFileSystems = 0;
139 #if defined(ANY_LINUX)
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>." );
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>" );
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)
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>." );
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>." );
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>" );
201 buttongroup =
new QGroupBox( i18n(
"&Formatting"),
this );
204 quick =
new QRadioButton( i18n(
"Q&uick format" ), buttongroup );
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);
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);
221 i18n(
"Full format is a low-level and high-level format. It erases everything on the disk.") );
230 userFeedBack += i18n(
"Program fdformat found." );
235 userFeedBack += i18n(
"Program fdformat <b>not found</b>. Full formatting <b>disabled</b>." );
242 userFeedBack += i18n(
"Program dd found." );
246 userFeedBack += i18n(
"Program dd <b>not found</b>. Zeroing-out <b>disabled</b>." );
251 verifylabel->
setText(i18n(
"&Verify integrity" ));
253 v1->
addWidget( verifylabel, Qt::AlignLeft );
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>") );
260 labellabel->
setText(i18n(
"Volume la&bel:") );
262 v1->
addWidget( labellabel, Qt::AlignLeft );
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>") );
271 lineedit =
new KLineEdit( widget );
273 lineedit->
setText(i18nc(
"Volume label, maximal 11 characters",
"KDE Floppy" ) );
275 h2->
addWidget( lineedit, Qt::AlignRight );
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)));
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()));
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());
306 quitbutton =
new KPushButton( KStandardGuiItem::quit(), widget );
307 quitbutton->setAutoRepeat(
false );
308 connect(quitbutton,SIGNAL(clicked()),
this,SLOT(
quit()));
313 frame =
new QLabel( widget );
318 i18n(
"<qt>This is the status window, where error messages are displayed.</qt>") );
320 QString frameText( userFeedBack );
332 i18n(
"<qt>Shows progress of the format.</qt>"));
337 if (!numFileSystems) {
340 errorMessage += i18n(
"KFloppy cannot find any of the needed programs for creating file systems; please check your installation.<br /><br />Log:");
342 errorMessage += userFeedBack;
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)
421 KUrl url( newDevice );
428 kError() <<
"Invalid reply from mediamanager" << endl;
431 newDevice = properties[5];
443 bool ok = (drive>=0);
450 if (formatActions) formatActions->
quit();
461 setCursor(
QCursor(Qt::WaitCursor));
475 helpbutton->setEnabled(b);
476 quitbutton->setEnabled(b);
477 formatbutton->setEnabled(b);
489 formatActions->
quit();
490 delete formatActions;
495 formatbutton->setText(i18n(
"&Format"));
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") );
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)),
587 formatActions->
queue(f);
589 else if ( userDevice )
600 formatActions->
queue(f);
603 if ( filesystemComboBox->
currentText() == i18n(
"DOS") )
617 formatActions->
queue(f);
620 else if ( filesystemComboBox->
currentText() == i18n(
"ext2") )
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);
655 f->configureDevice( currentComboBoxDevice );
659 f->configureDevice(drive,blocks);
661 formatActions->
queue(f);
665 formatActions->
exec();
670 kDebug(2002) <<
"FloppyData::formatStatus: " << s <<
" : " << p ;
674 if ( oldText.isEmpty() )
684 if ((0<=p) && (p<=100))
690 KConfigGroup config = KGlobal::config()->group(
"GeneralData");
692 densityconfig = densityComboBox->
currentText().trimmed();
693 filesystemconfig = filesystemComboBox->
currentText().trimmed();
694 driveconfig = deviceComboBox->
currentText().trimmed();
698 labelnameconfig = lineedit->
text().trimmed();
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") );
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){
747 for(
int i = 0 ; i < filesystemComboBox->
count(); i++){
748 if ( filesystemComboBox->
itemText(i) == filesystemconfig){
753 for(
int i = 0 ; i < densityComboBox->
count(); i++){
754 if ( densityComboBox->
itemText(i) == densityconfig){
760 #include "floppy.moc"
virtual void quit()
Quit aborts the action.
QString & append(QChar ch)
void queue(KFAction *)
Add a KFAction to the queue.
bool findDevice()
Maps combobox selection to drive and density.
void setText(const QString &)
void show()
Need to overload normal show() in order to mangle caption.
QString & prepend(QChar ch)
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.
QString itemText(int index) const
void setFrameStyle(int style)
void setEditable(bool editable)
void addSpacing(int size)
QDBusMessage call(const QString &method, const QVariant &arg1, const QVariant &arg2, const QVariant &arg3, const QVariant &arg4, const QVariant &arg5, const QVariant &arg6, const QVariant &arg7, const QVariant &arg8)
void addItem(const QString &text, const QVariant &userData)
void setBuddy(QWidget *buddy)
virtual void exec()
Exec() should return quickly to ensire that the GUI thread stays alive.
virtual void addItem(QLayoutItem *item)
void setObjectName(const QString &name)
bool startsWith(const QString &s, Qt::CaseSensitivity cs) const
void formatStatus(const QString &, int)
void setText(const QString &)
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 addStretch(int stretch)
void setColumnStretch(int column, int stretch)
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
void setCurrentIndex(int index)
bool configure(bool verify, bool label, const QString &l)
Same args as FATFilesystem::configure.
void setText(const QString &text)
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)
void setWordWrap(bool on)
void setSpacing(int spacing)
static bool runtimeCheck()
Concrete classes can provide a runtimeCheck function (heck, this is static, so the name is up to you)...