File indexing completed on 2024-03-24 05:53:25
0001 /* 0002 0003 This file is part of the KFloppy program, part of the KDE project 0004 0005 Copyright (C) 1997 Bernd Johannes Wuebben <wuebben@math.cornell.edu> 0006 Copyright (C) 2004, 2005 Nicolas GOUTTE <goutte@kde.org> 0007 Copyright (C) 2015, 2016 Wolfgang Bauer <wbauer@tmo.at> 0008 0009 This program is free software; you can redistribute it and/or modify 0010 it under the terms of the GNU General Public License as published by 0011 the Free Software Foundation; either version 2 of the License, or 0012 (at your option) any later version. 0013 0014 This program is distributed in the hope that it will be useful, 0015 but WITHOUT ANY WARRANTY; without even the implied warranty of 0016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0017 GNU General Public License for more details. 0018 0019 You should have received a copy of the GNU General Public License 0020 along with this program; if not, write to the Free Software 0021 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 0022 0023 */ 0024 0025 #include "floppy.h" 0026 #include "format.h" 0027 0028 #include <QApplication> 0029 #include <QCheckBox> 0030 #include <QCursor> 0031 #include <QDBusInterface> 0032 #include <QDBusReply> 0033 #include <QFrame> 0034 #include <QGridLayout> 0035 #include <QGroupBox> 0036 #include <QHBoxLayout> 0037 #include <QLabel> 0038 #include <QProgressBar> 0039 #include <QPushButton> 0040 #include <QRadioButton> 0041 #include <QUrl> 0042 #include <QVBoxLayout> 0043 0044 #include <KAboutData> 0045 #include <KComboBox> 0046 #include <KConfigGroup> 0047 #include <KGuiItem> 0048 #include <KHelpClient> 0049 #include <KHelpMenu> 0050 #include <KLineEdit> 0051 #include <KLocalizedString> 0052 #include <KSharedConfig> 0053 #include <KStandardGuiItem> 0054 #include <kmessagebox.h> 0055 0056 FloppyData::FloppyData(QWidget *parent) 0057 : QDialog(parent) 0058 , formatActions(nullptr) 0059 , m_canLowLevel(false) 0060 , m_canZeroOut(false) 0061 { 0062 auto widget = new QWidget(this); 0063 formating = false; 0064 // abort = false; 0065 blocks = 0; 0066 0067 auto ml = new QVBoxLayout(widget); 0068 ml->setSpacing(10); 0069 0070 auto h1 = new QHBoxLayout(); 0071 ml->addItem(h1); 0072 0073 auto v1 = new QVBoxLayout(); 0074 h1->addItem(v1); 0075 h1->addSpacing(5); 0076 0077 auto g1 = new QGridLayout(); 0078 v1->addItem(g1); 0079 0080 deviceComboBox = new KComboBox(false, widget); 0081 label1 = new QLabel(i18n("Floppy &drive:"), widget); 0082 label1->setBuddy(deviceComboBox); 0083 g1->addWidget(label1, 0, 0, Qt::AlignLeft); 0084 g1->addWidget(deviceComboBox, 0, 1); 0085 0086 // Make the combo box editable, so that the user can enter a device name 0087 deviceComboBox->setEditable(true); 0088 0089 deviceComboBox->addItem(i18nc("Primary floppy drive", "Primary")); 0090 deviceComboBox->addItem(i18nc("Secondary floppy drive", "Secondary")); 0091 0092 const QString deviceWhatsThis = i18n("<qt>Select the floppy drive.</qt>"); 0093 0094 label1->setWhatsThis(deviceWhatsThis); 0095 deviceComboBox->setWhatsThis(deviceWhatsThis); 0096 0097 densityComboBox = new KComboBox(false, widget); 0098 label2 = new QLabel(i18n("&Size:"), widget); 0099 label2->setBuddy(densityComboBox); 0100 g1->addWidget(label2, 1, 0, Qt::AlignLeft); 0101 g1->addWidget(densityComboBox, 1, 1); 0102 0103 #if defined(ANY_LINUX) 0104 densityComboBox->addItem(i18n("Auto-Detect")); 0105 #endif 0106 densityComboBox->addItem(i18n("3.5\" 1.44MB")); 0107 densityComboBox->addItem(i18n("3.5\" 720KB")); 0108 densityComboBox->addItem(i18n("5.25\" 1.2MB")); 0109 densityComboBox->addItem(i18n("5.25\" 360KB")); 0110 0111 const QString densityWhatsThis = i18n( 0112 "<qt>This allows you to select the " 0113 "floppy disk's size and density.</qt>"); 0114 0115 label2->setWhatsThis(densityWhatsThis); 0116 densityComboBox->setWhatsThis(densityWhatsThis); 0117 0118 filesystemComboBox = new KComboBox(false, widget); 0119 label3 = new QLabel(i18n("F&ile system:"), widget); 0120 label3->setBuddy(filesystemComboBox); 0121 g1->addWidget(label3, 2, 0, Qt::AlignLeft); 0122 g1->addWidget(filesystemComboBox, 2, 1); 0123 g1->setColumnStretch(1, 1); 0124 0125 #if defined(ANY_LINUX) 0126 label3->setWhatsThis(i18nc("Linux", "KFloppy supports three file formats under Linux: MS-DOS, Ext2, and Minix")); 0127 #elif defined(ANY_BSD) 0128 label3->setWhatsThis(i18nc("BSD", "KFloppy supports three file formats under BSD: MS-DOS, UFS, and Ext2")); 0129 #endif 0130 // If you modify the user visible string, change them also (far) below 0131 0132 QString userFeedBack; 0133 uint numFileSystems = 0; 0134 0135 #if defined(ANY_LINUX) 0136 filesystemComboBox->setWhatsThis(i18nc("Linux", "KFloppy supports three file formats under Linux: MS-DOS, Ext2, and Minix")); 0137 if (FATFilesystem::runtimeCheck()) { 0138 filesystemComboBox->addItem(i18n("DOS")); 0139 ++numFileSystems; 0140 userFeedBack += i18nc("Linux", "Program mkdosfs found."); 0141 } else { 0142 userFeedBack += i18nc("Linux", "Program mkdosfs <b>not found</b>. MSDOS formatting <b>not available</b>."); 0143 } 0144 userFeedBack += QLatin1String("<br>"); 0145 if (Ext2Filesystem::runtimeCheck()) { 0146 filesystemComboBox->addItem(i18n("ext2")); 0147 ++numFileSystems; 0148 userFeedBack += i18n("Program mke2fs found."); 0149 } else { 0150 userFeedBack += i18n("Program mke2fs <b>not found</b>. Ext2 formatting <b>not available</b>"); 0151 } 0152 userFeedBack += QLatin1String("<br>"); 0153 if (MinixFilesystem::runtimeCheck()) { 0154 filesystemComboBox->addItem(i18n("Minix")); 0155 ++numFileSystems; 0156 userFeedBack += i18nc("Linux", "Program mkfs.minix found."); 0157 } else { 0158 userFeedBack += i18nc("Linux", "Program mkfs.minix <b>not found</b>. Minix formatting <b>not available</b>"); 0159 } 0160 #elif defined(ANY_BSD) 0161 filesystemComboBox->setWhatsThis(i18nc("BSD", "KFloppy supports two file formats under BSD: MS-DOS and UFS")); 0162 if (FATFilesystem::runtimeCheck()) { 0163 filesystemComboBox->addItem(i18n("DOS")); 0164 ++numFileSystems; 0165 userFeedBack += i18nc("BSD", "Program newfs_msdos found."); 0166 } else { 0167 userFeedBack += i18nc("BSD", "Program newfs_msdos <b>not found</b>. MSDOS formatting <b>not available</b>."); 0168 } 0169 userFeedBack += QLatin1String("<br>"); 0170 if (UFSFilesystem::runtimeCheck()) { 0171 filesystemComboBox->addItem(i18n("UFS")); 0172 ++numFileSystems; 0173 userFeedBack += i18nc("BSD", "Program newfs found."); 0174 } else { 0175 userFeedBack += i18nc("BSD", "Program newfs <b>not found</b>. UFS formatting <b>not available</b>."); 0176 } 0177 userFeedBack += QLatin1String("<br>"); 0178 if (Ext2Filesystem::runtimeCheck()) { 0179 filesystemComboBox->addItem(i18n("ext2")); 0180 ++numFileSystems; 0181 userFeedBack += i18n("Program mke2fs found."); 0182 } else { 0183 userFeedBack += i18n("Program mke2fs <b>not found</b>. Ext2 formatting <b>not available</b>"); 0184 } 0185 #endif 0186 0187 v1->addSpacing(10); 0188 0189 buttongroup = new QGroupBox(i18n("&Formatting"), this); 0190 auto buttonGroupLayout = new QVBoxLayout(buttongroup); 0191 0192 quick = new QRadioButton(i18n("Q&uick format"), buttongroup); 0193 buttonGroupLayout->addWidget(quick); 0194 quick->setObjectName(QStringLiteral("RadioButton_2")); 0195 quick->setWhatsThis( 0196 i18n("<qt>Quick format is only a high-level format:" 0197 " it creates only a file system.</qt>")); 0198 0199 zerooutformat = new QRadioButton(i18n("&Zero out and quick format"), buttongroup); 0200 buttonGroupLayout->addWidget(zerooutformat); 0201 zerooutformat->setObjectName(QStringLiteral("RadioButton_ZeroOutFormat")); 0202 zerooutformat->setWhatsThis(i18n("<qt>This first erases the floppy by writing zeros and then it creates the file system.</qt>")); 0203 0204 fullformat = new QRadioButton(i18n("Fu&ll format"), buttongroup); 0205 buttonGroupLayout->addWidget(fullformat); 0206 fullformat->setObjectName(QStringLiteral("RadioButton_3")); 0207 fullformat->setWhatsThis(i18n("Full format is a low-level and high-level format. It erases everything on the disk.")); 0208 0209 v1->addWidget(buttongroup); 0210 0211 // ### TODO: we need some user feedback telling why full formatting is disabled. 0212 userFeedBack += QLatin1String("<br>"); 0213 m_canLowLevel = FDFormat::runtimeCheck(); 0214 if (m_canLowLevel) { 0215 fullformat->setChecked(true); 0216 userFeedBack += i18n("Program fdformat found."); 0217 } else { 0218 fullformat->setDisabled(true); 0219 quick->setChecked(true); 0220 userFeedBack += i18n("Program fdformat <b>not found</b>. Full formatting <b>disabled</b>."); 0221 } 0222 userFeedBack += QLatin1String("<br>"); 0223 m_canZeroOut = DDZeroOut::runtimeCheck(); 0224 if (m_canZeroOut) { 0225 zerooutformat->setChecked(true); 0226 userFeedBack += i18n("Program dd found."); 0227 } else { 0228 zerooutformat->setDisabled(true); 0229 userFeedBack += i18n("Program dd <b>not found</b>. Zeroing-out <b>disabled</b>."); 0230 } 0231 0232 verifylabel = new QCheckBox(this); 0233 verifylabel->setObjectName(QStringLiteral("CheckBox_Integrity")); 0234 verifylabel->setText(i18n("&Verify integrity")); 0235 verifylabel->setChecked(true); 0236 v1->addWidget(verifylabel, Qt::AlignLeft); 0237 verifylabel->setWhatsThis( 0238 i18n("<qt>Check this if you want the floppy disk to be checked after formatting." 0239 " Please note that the floppy will be checked twice if you have selected full formatting.</qt>")); 0240 0241 labellabel = new QCheckBox(this); 0242 labellabel->setObjectName(QStringLiteral("Checkbox_Label")); 0243 labellabel->setText(i18n("Volume la&bel:")); 0244 labellabel->setChecked(true); 0245 v1->addWidget(labellabel, Qt::AlignLeft); 0246 labellabel->setWhatsThis( 0247 i18n("<qt>Check this if you want a volume label for your floppy." 0248 " Please note that Minix does not support labels at all.</qt>")); 0249 0250 auto h2 = new QHBoxLayout(); 0251 v1->addItem(h2); 0252 h2->addSpacing(20); 0253 0254 lineedit = new KLineEdit(widget); 0255 // ### TODO ext2 supports 16 characters. Minix has not any label. UFS? 0256 lineedit->setText(i18nc("Volume label, maximal 11 characters", "KDE Floppy")); 0257 lineedit->setMaxLength(11); 0258 h2->addWidget(lineedit, Qt::AlignRight); 0259 lineedit->setWhatsThis( 0260 i18n("<qt>This is for the volume label." 0261 " Due to a limitation of MS-DOS the label can only be 11 characters long." 0262 " Please note that Minix does not support labels, whatever you enter here.</qt>")); 0263 0264 connect(labellabel, &QAbstractButton::toggled, lineedit, &QWidget::setEnabled); 0265 0266 auto v3 = new QVBoxLayout(); 0267 h1->addItem(v3); 0268 0269 formatbutton = new QPushButton(widget); 0270 formatbutton->setText(i18n("&Format")); 0271 formatbutton->setAutoRepeat(false); 0272 if (!numFileSystems) 0273 formatbutton->setDisabled(false); // We have not any helper program for creating any file system 0274 connect(formatbutton, &QAbstractButton::clicked, this, &FloppyData::format); 0275 v3->addWidget(formatbutton); 0276 formatbutton->setWhatsThis(i18n("<qt>Click here to start formatting.</qt>")); 0277 0278 v3->addStretch(1); 0279 0280 // Setup the Help Menu 0281 helpMenu = new KHelpMenu(this, KAboutData::applicationData(), false); 0282 0283 helpbutton = new QPushButton(widget); 0284 KGuiItem::assign(helpbutton, KStandardGuiItem::help()); 0285 helpbutton->setAutoRepeat(false); 0286 helpbutton->setMenu(helpMenu->menu()); 0287 v3->addWidget(helpbutton); 0288 0289 quitbutton = new QPushButton(widget); 0290 KGuiItem::assign(quitbutton, KStandardGuiItem::quit()); 0291 quitbutton->setAutoRepeat(false); 0292 connect(quitbutton, &QAbstractButton::clicked, this, &FloppyData::quit); 0293 v3->addWidget(quitbutton); 0294 0295 ml->addSpacing(10); 0296 0297 frame = new QLabel(widget); 0298 frame->setObjectName(QStringLiteral("NewsWindow")); 0299 frame->setFrameStyle(QFrame::Panel | QFrame::Sunken); 0300 frame->setWordWrap(true); 0301 frame->setWhatsThis(i18n("<qt>This is the status window, where error messages are displayed.</qt>")); 0302 0303 QString frameText(userFeedBack); 0304 frameText.prepend(QLatin1String("<qt>")); 0305 frameText.append(QLatin1String("</qt>")); 0306 frame->setText(frameText); 0307 0308 ml->addWidget(frame); 0309 0310 progress = new QProgressBar(widget); 0311 progress->setDisabled(true); 0312 ml->addWidget(progress); 0313 0314 progress->setWhatsThis(i18n("<qt>Shows progress of the format.</qt>")); 0315 0316 setLayout(ml); 0317 0318 readSettings(); 0319 setWidgets(); 0320 if (!numFileSystems) { 0321 QString errorMessage; 0322 errorMessage += QLatin1String("<qt>"); 0323 errorMessage += i18n("KFloppy cannot find any of the needed programs for creating file systems; please check your installation.<br /><br />Log:"); 0324 errorMessage += QLatin1String("<br>"); 0325 errorMessage += userFeedBack; 0326 errorMessage += QLatin1String("</qt>"); 0327 KMessageBox::error(this, errorMessage); 0328 } 0329 } 0330 0331 FloppyData::~FloppyData() 0332 { 0333 delete formatActions; 0334 } 0335 0336 void FloppyData::closeEvent(QCloseEvent *) 0337 { 0338 quit(); 0339 } 0340 0341 void FloppyData::keyPressEvent(QKeyEvent *e) 0342 { 0343 switch (e->key()) { 0344 case Qt::Key_F1: 0345 KHelpClient::invokeHelp(); 0346 break; 0347 default: 0348 QDialog::keyPressEvent(e); 0349 return; 0350 } 0351 } 0352 0353 void FloppyData::show() 0354 { 0355 setWindowTitle(i18n("KDE Floppy Formatter")); 0356 QDialog::show(); 0357 } 0358 0359 bool FloppyData::findDevice() 0360 { 0361 // Note: this function does not handle user-given devices 0362 0363 drive = -1; 0364 if (deviceComboBox->currentText() == i18nc("Primary floppy drive", "Primary")) { 0365 drive = 0; 0366 } else if (deviceComboBox->currentText() == i18nc("Secondary floppy drive", "Secondary")) { 0367 drive = 1; 0368 } 0369 0370 blocks = -1; 0371 0372 if (densityComboBox->currentText() == i18n("3.5\" 1.44MB")) { 0373 blocks = 1440; 0374 } else if (densityComboBox->currentText() == i18n("3.5\" 720KB")) { 0375 blocks = 720; 0376 } else if (densityComboBox->currentText() == i18n("5.25\" 1.2MB")) { 0377 blocks = 1200; 0378 } else if (densityComboBox->currentText() == i18n("5.25\" 360KB")) { 0379 blocks = 360; 0380 } 0381 #if defined(ANY_LINUX) 0382 else { // For Linux, anything else is Auto 0383 blocks = 0; 0384 } 0385 #endif 0386 0387 return true; 0388 } 0389 0390 bool FloppyData::setInitialDevice(const QString &dev) 0391 { 0392 QString newDevice = dev; 0393 0394 QUrl url(newDevice); 0395 if (url.isValid() && (url.scheme() == QLatin1String("media") || url.scheme() == QLatin1String("system"))) { 0396 QString name = url.fileName(); 0397 0398 QDBusInterface mediamanager(QStringLiteral("org.kde.kded"), QStringLiteral("/modules/mediamanager"), QStringLiteral("org.kde.MediaManager")); 0399 QDBusReply<QStringList> reply = mediamanager.call(QStringLiteral("properties"), name); 0400 if (!reply.isValid()) { 0401 qCritical() << "Invalid reply from mediamanager"; 0402 } else { 0403 const QStringList properties = reply; 0404 newDevice = properties.at(5); 0405 } 0406 } 0407 0408 int drive = -1; 0409 if (newDevice.startsWith(QLatin1String("/dev/fd0"))) 0410 drive = 0; 0411 else if (newDevice.startsWith(QLatin1String("/dev/fd1"))) 0412 drive = 1; 0413 0414 // ### TODO user given devices 0415 0416 bool ok = (drive >= 0); 0417 if (ok) 0418 deviceComboBox->setCurrentIndex(drive); 0419 return ok; 0420 } 0421 0422 void FloppyData::quit() 0423 { 0424 if (formatActions) 0425 formatActions->quit(); 0426 writeSettings(); 0427 qApp->quit(); 0428 delete this; 0429 } 0430 0431 void FloppyData::setEnabled(bool b) 0432 { 0433 if (b) 0434 unsetCursor(); 0435 else 0436 setCursor(QCursor(Qt::WaitCursor)); 0437 label1->setEnabled(b); 0438 deviceComboBox->setEnabled(b); 0439 label2->setEnabled(b); 0440 densityComboBox->setEnabled(b); 0441 label3->setEnabled(b); 0442 filesystemComboBox->setEnabled(b); 0443 buttongroup->setEnabled(b); 0444 quick->setEnabled(b); 0445 fullformat->setEnabled(b && m_canLowLevel); 0446 zerooutformat->setEnabled(b && m_canZeroOut); 0447 verifylabel->setEnabled(b); 0448 labellabel->setEnabled(b); 0449 lineedit->setEnabled(b && labellabel->isChecked()); 0450 helpbutton->setEnabled(b); 0451 quitbutton->setEnabled(b); 0452 formatbutton->setEnabled(b); 0453 progress->setDisabled(b); // The other way round! 0454 } 0455 0456 void FloppyData::reset() 0457 { 0458 DEBUGSETUP; 0459 0460 formating = false; 0461 0462 if (formatActions) { 0463 formatActions->quit(); 0464 delete formatActions; 0465 formatActions = nullptr; 0466 } 0467 0468 progress->setValue(0); 0469 formatbutton->setText(i18n("&Format")); 0470 setEnabled(true); 0471 } 0472 0473 void FloppyData::format() 0474 { 0475 if (formating) { 0476 // abort = true; 0477 reset(); 0478 return; 0479 } 0480 0481 frame->clear(); 0482 0483 const QString currentComboBoxDevice(deviceComboBox->currentText()); 0484 const bool userDevice = (currentComboBoxDevice.startsWith(QLatin1String("/dev/"))); 0485 0486 #ifdef ANY_BSD 0487 if (userDevice && filesystemComboBox->currentText() != i18n("UFS")) { 0488 KMessageBox::error(this, i18nc("BSD", "Formatting with BSD on a user-given device is only possible with UFS")); 0489 return; 0490 } 0491 // no "else" ! 0492 #endif 0493 if (userDevice && (quick->isChecked() || zerooutformat->isChecked())) { 0494 if (KMessageBox::warningContinueCancel(this, 0495 i18n("<qt>Formatting will erase all data on the device:<br/><b>%1</b><br/>" 0496 "(Please check the correctness of the device name.)<br/>" 0497 "Are you sure you wish to proceed?</qt>", 0498 currentComboBoxDevice), 0499 i18n("Proceed?")) 0500 != KMessageBox::Continue) { 0501 return; 0502 } 0503 } else if (userDevice) { 0504 // The user has selected full formatting on a user-given device. That is not supported yet! 0505 KMessageBox::error(this, i18n("Full formatting of a user-given device is not possible.")); 0506 return; 0507 } else { 0508 if (KMessageBox::warningContinueCancel(this, 0509 i18n("Formatting will erase all data on the disk.\n" 0510 "Are you sure you wish to proceed?"), 0511 i18n("Proceed?")) 0512 != KMessageBox::Continue) { 0513 return; 0514 } 0515 } 0516 0517 // formatbutton->setText(i18n("A&bort")); 0518 setEnabled(false); 0519 0520 // Erase text box 0521 frame->setText(QString()); 0522 0523 if (!userDevice) { 0524 if (!findDevice()) { 0525 reset(); 0526 return; 0527 } 0528 } 0529 0530 delete formatActions; 0531 formatActions = new KFActionQueue(this); 0532 0533 connect(formatActions, &KFAction::status, this, &FloppyData::formatStatus); 0534 connect(formatActions, &KFAction::done, this, &FloppyData::reset); 0535 0536 if (quick->isChecked()) { 0537 formating = false; 0538 // No fdformat to push 0539 } else if (zerooutformat->isChecked()) { 0540 auto f = new DDZeroOut(this); 0541 if (userDevice) { 0542 f->configureDevice(currentComboBoxDevice); 0543 } else { 0544 f->configureDevice(drive, blocks); 0545 } 0546 formatActions->queue(f); 0547 } else if (userDevice) { 0548 // We should not have got here, assume quick format 0549 formating = false; 0550 // No fdformat to push 0551 } else { 0552 auto f = new FDFormat(this); 0553 f->configureDevice(drive, blocks); 0554 f->configure(verifylabel->isChecked()); 0555 formatActions->queue(f); 0556 } 0557 0558 if (filesystemComboBox->currentText() == i18n("DOS")) { 0559 auto f = new FATFilesystem(this); 0560 f->configure(verifylabel->isChecked(), labellabel->isChecked(), lineedit->text()); 0561 if (userDevice) { 0562 f->configureDevice(currentComboBoxDevice); 0563 } else { 0564 f->configureDevice(drive, blocks); 0565 } 0566 formatActions->queue(f); 0567 } 0568 0569 else if (filesystemComboBox->currentText() == i18n("ext2")) { 0570 auto f = new Ext2Filesystem(this); 0571 f->configure(verifylabel->isChecked(), labellabel->isChecked(), lineedit->text()); 0572 if (userDevice) { 0573 f->configureDevice(currentComboBoxDevice); 0574 } else { 0575 f->configureDevice(drive, blocks); 0576 } 0577 formatActions->queue(f); 0578 } 0579 #ifdef ANY_BSD 0580 else if (filesystemComboBox->currentText() == i18n("UFS")) { 0581 FloppyAction *f = new UFSFilesystem(this); 0582 f->configureDevice(drive, blocks); 0583 formatActions->queue(f); 0584 } 0585 #endif 0586 0587 #ifdef ANY_LINUX 0588 else if (filesystemComboBox->currentText() == i18n("Minix")) { 0589 auto f = new MinixFilesystem(this); 0590 f->configure(verifylabel->isChecked(), labellabel->isChecked(), lineedit->text()); 0591 if (userDevice) { 0592 f->configureDevice(currentComboBoxDevice); 0593 } else { 0594 f->configureDevice(drive, blocks); 0595 } 0596 formatActions->queue(f); 0597 } 0598 #endif 0599 0600 formatActions->exec(); 0601 } 0602 0603 void FloppyData::formatStatus(const QString &s, int p) 0604 { 0605 qCDebug(KFLOPPY_LOG) << "FloppyData::formatStatus: " << s << " : " << p; 0606 if (!s.isEmpty()) { 0607 const QString oldText(frame->text()); 0608 if (oldText.isEmpty()) { 0609 frame->setText(s); 0610 } else { 0611 frame->setText(oldText + QLatin1Char('\n') + s); 0612 } 0613 } 0614 0615 if ((0 <= p) && (p <= 100)) 0616 progress->setValue(p); 0617 } 0618 0619 void FloppyData::writeSettings() 0620 { 0621 KConfigGroup config = KSharedConfig::openConfig()->group(QStringLiteral("GeneralData")); 0622 0623 densityconfig = densityComboBox->currentText().trimmed(); 0624 filesystemconfig = filesystemComboBox->currentText().trimmed(); 0625 driveconfig = deviceComboBox->currentText().trimmed(); 0626 0627 quickformatconfig = quick->isChecked(); 0628 0629 labelnameconfig = lineedit->text().trimmed(); 0630 0631 labelconfig = labellabel->isChecked(); 0632 0633 verifyconfig = verifylabel->isChecked(); 0634 0635 config.writeEntry("CreateLabel", labelconfig); 0636 config.writeEntry("Label", labelnameconfig); 0637 0638 config.writeEntry("QuickFormat", quickformatconfig); 0639 config.writeEntry("FloppyDrive", driveconfig); 0640 config.writeEntry("Density", densityconfig); 0641 config.writeEntry("Filesystem", filesystemconfig); 0642 config.writeEntry("Verify", verifyconfig); 0643 config.sync(); 0644 } 0645 0646 void FloppyData::readSettings() 0647 { 0648 KConfigGroup config = KSharedConfig::openConfig()->group(QStringLiteral("GeneralData")); 0649 0650 verifyconfig = config.readEntry("Verify", 1); 0651 labelconfig = config.readEntry("CreateLabel", 1); 0652 labelnameconfig = config.readEntry("Label", i18nc("Volume label, maximal 11 characters", "KDE Floppy")); 0653 quickformatconfig = config.readEntry("QuickFormat", 0); 0654 driveconfig = config.readEntry("FloppyDrive", i18nc("Primary floppy drive", "Primary")); 0655 #if defined(ANY_LINUX) 0656 densityconfig = config.readEntry("Density", i18n("Auto-Detect")); 0657 #else 0658 densityconfig = config.readEntry("Density", i18n("3.5\" 1.44MB")); 0659 #endif 0660 filesystemconfig = config.readEntry("Filesystem", i18n("DOS")); 0661 } 0662 0663 void FloppyData::setWidgets() 0664 { 0665 labellabel->setChecked(labelconfig); 0666 verifylabel->setChecked(verifyconfig); 0667 quick->setChecked(quickformatconfig || !m_canLowLevel); 0668 fullformat->setChecked(!quickformatconfig && m_canLowLevel); 0669 lineedit->setText(labelnameconfig); 0670 0671 for (int i = 0; i < deviceComboBox->count(); i++) { 0672 if (deviceComboBox->itemText(i) == driveconfig) { 0673 deviceComboBox->setCurrentIndex(i); 0674 } 0675 } 0676 0677 for (int i = 0; i < filesystemComboBox->count(); i++) { 0678 if (filesystemComboBox->itemText(i) == filesystemconfig) { 0679 filesystemComboBox->setCurrentIndex(i); 0680 } 0681 } 0682 0683 for (int i = 0; i < densityComboBox->count(); i++) { 0684 if (densityComboBox->itemText(i) == densityconfig) { 0685 densityComboBox->setCurrentIndex(i); 0686 } 0687 } 0688 }