• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeutils API Reference
  • KDE Home
  • Contact Us
 

kfloppy

  • sources
  • kde-4.12
  • kdeutils
  • kfloppy
floppy.cpp
Go to the documentation of this file.
1 /*
2 
3  This file is part of the KFloppy program, part of the KDE project
4 
5  Copyright (C) 1997 Bernd Johannes Wuebben <wuebben@math.cornell.edu>
6  Copyright (C) 2004, 2005 Nicolas GOUTTE <goutte@kde.org>
7 
8  This program is free software; you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation; either version 2 of the License, or
11  (at your option) any later version.
12 
13  This program is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with this program; if not, write to the Free Software
20  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 
22 */
23 
24 #include "floppy.h"
25 #include "format.h"
26 
27 #include <QCheckBox>
28 #include <QLabel>
29 #include <qcursor.h>
30 #include <qgroupbox.h>
31 #include <qradiobutton.h>
32 //Added by qt3to4:
33 #include <QVBoxLayout>
34 #include <QFrame>
35 #include <QHBoxLayout>
36 #include <QGridLayout>
37 #include <QKeyEvent>
38 #include <QCloseEvent>
39 #include <QtDBus/QtDBus>
40 #include <kconfig.h>
41 
42 #include <kmessagebox.h>
43 #include <kdebug.h>
44 #include <khelpmenu.h>
45 #include <kpushbutton.h>
46 #include <kmenu.h>
47 #include <kapplication.h>
48 #include <qprogressbar.h>
49 #include <klocale.h>
50 #include <kcombobox.h>
51 #include <klineedit.h>
52 #include <kurl.h>
53 #include <ktoolinvocation.h>
54 #include <kglobal.h>
55 
56 FloppyData::FloppyData(QWidget * parent)
57  : KDialog( parent ),
58  formatActions(0L), m_canLowLevel(false), m_canZeroOut( false )
59 {
60  QWidget *widget = new QWidget(this);
61  setMainWidget(widget);
62  setButtons(None);
63  formating = false;
64  //abort = false;
65  blocks = 0;
66 
67  QVBoxLayout* ml = new QVBoxLayout( widget );
68  ml->setSpacing( 10 );
69 
70  QHBoxLayout* h1 = new QHBoxLayout();
71  ml->addItem( h1 );
72 
73  QVBoxLayout* v1 = new QVBoxLayout( );
74  h1->addItem( v1 );
75  h1->addSpacing( 5 );
76 
77  QGridLayout* g1 = new QGridLayout();
78  v1->addItem( g1 );
79 
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 );
85 
86  // Make the combo box editable, so that the user can enter a device name
87  deviceComboBox->setEditable( true );
88 
89  deviceComboBox->addItem(i18nc("Primary floppy drive", "Primary"));
90  deviceComboBox->addItem(i18nc("Secondary floppy drive", "Secondary"));
91 
92  const QString deviceWhatsThis = i18n("<qt>Select the floppy drive.</qt>");
93 
94  label1->setWhatsThis( deviceWhatsThis);
95  deviceComboBox->setWhatsThis( deviceWhatsThis);
96 
97 
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 );
103 
104 #if defined(ANY_LINUX)
105  densityComboBox->addItem( i18n( "Auto-Detect" ) );
106 #endif
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"));
111 
112  const QString densityWhatsThis =
113  i18n("<qt>This allows you to select the "
114  "floppy disk's size and density.</qt>");
115 
116  label2->setWhatsThis( densityWhatsThis);
117  densityComboBox->setWhatsThis( densityWhatsThis);
118 
119 
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);
126 
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" ) );
133 #endif
134  // If you modify the user visible string, change them also (far) below
135 
136  QString userFeedBack;
137  uint numFileSystems = 0;
138 
139 #if defined(ANY_LINUX)
140  filesystemComboBox->setWhatsThis(
141  i18nc( "Linux", "KFloppy supports three file formats under Linux: MS-DOS, Ext2, and Minix" ) );
142  if (FATFilesystem::runtimeCheck()) {
143  filesystemComboBox->addItem(i18n("DOS"));
144  ++numFileSystems;
145  userFeedBack += i18nc( "Linux", "Program mkdosfs found." );
146  }
147  else {
148  userFeedBack += i18nc( "Linux", "Program mkdosfs <b>not found</b>. MSDOS formatting <b>not available</b>." );
149  }
150  userFeedBack += QLatin1String( "<br>" );
151  if (Ext2Filesystem::runtimeCheck()) {
152  filesystemComboBox->addItem(i18n("ext2"));
153  ++numFileSystems;
154  userFeedBack += i18n( "Program mke2fs found." );
155  }
156  else {
157  userFeedBack += i18n( "Program mke2fs <b>not found</b>. Ext2 formatting <b>not available</b>" );
158  }
159  userFeedBack += QLatin1String( "<br>" );
160  if (MinixFilesystem::runtimeCheck()) {
161  filesystemComboBox->addItem(i18n("Minix"));
162  ++numFileSystems;
163  userFeedBack += i18nc( "Linux", "Program mkfs.minix found." );
164  }
165  else {
166  userFeedBack += i18nc( "Linux", "Program mkfs.minix <b>not found</b>. Minix formatting <b>not available</b>" );
167  }
168 #elif defined(ANY_BSD)
169  filesystemComboBox->setWhatsThis(
170  i18nc( "BSD", "KFloppy supports two file formats under BSD: MS-DOS and UFS" ) );
171  if (FATFilesystem::runtimeCheck()) {
172  filesystemComboBox->addItem(i18n("DOS"));
173  ++numFileSystems;
174  userFeedBack += i18nc( "BSD", "Program newfs_msdos found." );
175  }
176  else {
177  userFeedBack += i18nc( "BSD", "Program newfs_msdos <b>not found</b>. MSDOS formatting <b>not available</b>." );
178  }
179  userFeedBack += QLatin1String( "<br>" );
180  if (UFSFilesystem::runtimeCheck()) {
181  filesystemComboBox->addItem(i18n("UFS"));
182  ++numFileSystems;
183  userFeedBack += i18nc( "BSD", "Program newfs found." );
184  }
185  else {
186  userFeedBack += i18nc( "BSD", "Program newfs <b>not found</b>. UFS formatting <b>not available</b>." );
187  }
188  userFeedBack += QLatin1String( "<br>" );
189  if (Ext2Filesystem::runtimeCheck()) {
190  filesystemComboBox->addItem(i18n("ext2"));
191  ++numFileSystems;
192  userFeedBack += i18n( "Program mke2fs found." );
193  }
194  else {
195  userFeedBack += i18n( "Program mke2fs <b>not found</b>. Ext2 formatting <b>not available</b>" );
196  }
197 #endif
198 
199  v1->addSpacing( 10 );
200 
201  buttongroup = new QGroupBox( i18n("&Formatting"), this );
202  QVBoxLayout* buttonGroupLayout = new QVBoxLayout(buttongroup);
203 
204  quick = new QRadioButton( i18n( "Q&uick format" ), buttongroup );
205  buttonGroupLayout->addWidget(quick);
206  quick->setObjectName( QLatin1String( "RadioButton_2" ) );
207  quick->setWhatsThis(
208  i18n("<qt>Quick format is only a high-level format:"
209  " it creates only a file system.</qt>") );
210 
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>") );
216 
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.") );
222 
223  v1->addWidget( buttongroup );
224 
225  // ### TODO: we need some user feedback telling why full formatting is disabled.
226  userFeedBack += QLatin1String( "<br>" );
227  m_canLowLevel = FDFormat::runtimeCheck();
228  if (m_canLowLevel){
229  fullformat->setChecked(true);
230  userFeedBack += i18n( "Program fdformat found." );
231  }
232  else {
233  fullformat->setDisabled(true);
234  quick->setChecked(true);
235  userFeedBack += i18n( "Program fdformat <b>not found</b>. Full formatting <b>disabled</b>." );
236  }
237  userFeedBack += QLatin1String( "<br>" );
238  m_canZeroOut = DDZeroOut::runtimeCheck();
239  if ( m_canZeroOut )
240  {
241  zerooutformat->setChecked( true );
242  userFeedBack += i18n( "Program dd found." );
243  }
244  else {
245  zerooutformat->setDisabled(true);
246  userFeedBack += i18n( "Program dd <b>not found</b>. Zeroing-out <b>disabled</b>." );
247  }
248 
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>") );
257 
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>") );
266 
267  QHBoxLayout* h2 = new QHBoxLayout();
268  v1->addItem( h2 );
269  h2->addSpacing( 20 );
270 
271  lineedit = new KLineEdit( widget );
272  // ### TODO ext2 supports 16 characters. Minix has not any label. UFS?
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>") );
280 
281  connect(labellabel,SIGNAL(toggled(bool)),lineedit,SLOT(setEnabled(bool)));
282 
283  QVBoxLayout* v3 = new QVBoxLayout();
284  h1->addItem( v3 );
285 
286  formatbutton = new KPushButton( widget );
287  formatbutton->setText(i18n( "&Format") );
288  formatbutton->setAutoRepeat( false );
289  if (!numFileSystems)
290  formatbutton->setDisabled(false); // We have not any helper program for creating any file system
291  connect(formatbutton,SIGNAL(clicked()),this,SLOT(format()));
292  v3->addWidget( formatbutton );
293  formatbutton->setWhatsThis(
294  i18n("<qt>Click here to start formatting.</qt>") );
295 
296  v3->addStretch( 1 );
297 
298  //Setup the Help Menu
299  helpMenu = new KHelpMenu(this, KGlobal::mainComponent().aboutData(), false);
300 
301  helpbutton = new KPushButton( KStandardGuiItem::help(), widget );
302  helpbutton->setAutoRepeat( false );
303  helpbutton->setMenu(helpMenu->menu());
304  v3->addWidget( helpbutton );
305 
306  quitbutton = new KPushButton( KStandardGuiItem::quit(), widget );
307  quitbutton->setAutoRepeat( false );
308  connect(quitbutton,SIGNAL(clicked()),this,SLOT(quit()));
309  v3->addWidget( quitbutton );
310 
311  ml->addSpacing( 10 );
312 
313  frame = new QLabel( widget );
314  frame->setObjectName( QLatin1String( "NewsWindow" ) );
315  frame->setFrameStyle(QFrame::Panel | QFrame::Sunken);
316  frame->setWordWrap( true );
317  frame->setWhatsThis(
318  i18n("<qt>This is the status window, where error messages are displayed.</qt>") );
319 
320  QString frameText( userFeedBack );
321  frameText.prepend( QLatin1String( "<qt>" ) );
322  frameText.append( QLatin1String( "</qt>" ) );
323  frame->setText( frameText );
324 
325  ml->addWidget( frame );
326 
327  progress = new QProgressBar( widget );
328  progress->setDisabled( true );
329  ml->addWidget( progress );
330 
331  progress->setWhatsThis(
332  i18n("<qt>Shows progress of the format.</qt>"));
333 
334  readSettings();
335  setWidgets();
336 
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 );
345  }
346 }
347 
348 
349 FloppyData::~FloppyData()
350 {
351  delete formatActions;
352 }
353 
354 void FloppyData::closeEvent(QCloseEvent*)
355 {
356  quit();
357 }
358 
359 void FloppyData::keyPressEvent(QKeyEvent *e)
360 {
361  switch(e->key()) {
362  case Qt::Key_F1:
363  KToolInvocation::invokeHelp();
364  break;
365  default:
366  KDialog::keyPressEvent(e);
367  return;
368  }
369 }
370 
371 void FloppyData::show() {
372  setCaption(i18n("KDE Floppy Formatter"));
373  KDialog::show();
374 }
375 
376 bool FloppyData::findDevice()
377 {
378  // Note: this function does not handle user-given devices
379 
380  drive=-1;
381  if( deviceComboBox->currentText() == i18nc("Primary floppy drive", "Primary") )
382  {
383  drive=0;
384  }
385  else if( deviceComboBox->currentText() == i18nc("Secondary floppy drive", "Secondary") )
386  {
387  drive=1;
388  }
389 
390  blocks=-1;
391 
392  if( densityComboBox->currentText() == i18n("3.5\" 1.44MB")){
393  blocks = 1440;
394  }
395  else
396  if( densityComboBox->currentText() == i18n("3.5\" 720KB")){
397  blocks = 720;
398  }
399  else
400  if( densityComboBox->currentText() == i18n("5.25\" 1.2MB")){
401  blocks = 1200;
402  }
403  else
404  if( densityComboBox->currentText() == i18n("5.25\" 360KB")){
405  blocks = 360;
406  }
407 #if defined(ANY_LINUX)
408  else { // For Linux, anything else is Auto
409  blocks = 0;
410  }
411 #endif
412 
413  return true;
414 }
415 
416 bool FloppyData::setInitialDevice(const QString& dev)
417 {
418 
419  QString newDevice = dev;
420 
421  KUrl url( newDevice );
422  if( url.isValid() && ( url.protocol() == QLatin1String( "media" ) || url.protocol() == QLatin1String( "system" ) ) ) {
423  QString name = url.fileName();
424 
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;
429  } else {
430  QStringList properties = reply;
431  newDevice = properties[5];
432  }
433  }
434 
435  int drive = -1;
436  if ( newDevice.startsWith(QLatin1String( "/dev/fd0" )) )
437  drive = 0;
438  if ( newDevice.startsWith(QLatin1String( "/dev/fd1" )))
439  drive = 1;
440 
441  // ### TODO user given devices
442 
443  bool ok = (drive>=0);
444  if (ok)
445  deviceComboBox->setCurrentIndex(drive);
446  return ok;
447 }
448 
449 void FloppyData::quit(){
450  if (formatActions) formatActions->quit();
451  writeSettings();
452  kapp->quit();
453  delete this;
454 }
455 
456 void FloppyData::setEnabled(bool b)
457 {
458  if (b)
459  unsetCursor();
460  else
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 ); // The other way round!
479 }
480 
481 void FloppyData::reset()
482 {
483  DEBUGSETUP;
484 
485  formating = false;
486 
487  if (formatActions)
488  {
489  formatActions->quit();
490  delete formatActions;
491  formatActions = 0L;
492  }
493 
494  progress->setValue(0);
495  formatbutton->setText(i18n("&Format"));
496  setEnabled(true);
497 }
498 
499 void FloppyData::format(){
500 
501  if(formating){
502  //abort = true;
503  reset();
504  return;
505  }
506 
507  frame->clear();
508 
509  const QString currentComboBoxDevice ( deviceComboBox->currentText() );
510  const bool userDevice = ( currentComboBoxDevice.startsWith (QLatin1String( "/dev/" )) );
511 
512 #ifdef ANY_BSD
513  if ( userDevice && filesystemComboBox->currentText() != i18n("UFS"))
514  {
515  KMessageBox::error( this, i18nc("BSD", "Formatting with BSD on a user-given device is only possible with UFS") );
516  return;
517  }
518  // no "else" !
519 #endif
520  if ( userDevice && ( quick->isChecked() || zerooutformat->isChecked() ) )
521  {
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)
527  {
528  return;
529  }
530  }
531  else if ( userDevice )
532  {
533  // The user has selected full formatting on a user-given device. That is not supported yet!
534  KMessageBox::error( this, i18n("Full formatting of a user-given device is not possible.") );
535  return;
536  }
537  else
538  {
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)
543  {
544  return;
545  }
546  }
547 
548  // formatbutton->setText(i18n("A&bort"));
549  setEnabled(false);
550 
551  // Erase text box
552  frame->setText( QString::null ); //krazy:exclude=nullstrassign for old broken gcc
553 
554  if ( !userDevice )
555  {
556  if ( !findDevice() )
557  {
558  reset();
559  return;
560  }
561  }
562 
563  delete formatActions;
564  formatActions = new KFActionQueue(this);
565 
566  connect(formatActions,SIGNAL(status(QString,int)),
567  this,SLOT(formatStatus(QString,int)));
568  connect(formatActions,SIGNAL(done(KFAction*,bool)),
569  this,SLOT(reset()));
570 
571  if ( quick->isChecked())
572  {
573  formating=false;
574  // No fdformat to push
575  }
576  else if ( zerooutformat->isChecked() )
577  {
578  DDZeroOut* f = new DDZeroOut( this );
579  if ( userDevice )
580  {
581  f->configureDevice( currentComboBoxDevice );
582  }
583  else
584  {
585  f->configureDevice( drive, blocks );
586  }
587  formatActions->queue(f);
588  }
589  else if ( userDevice )
590  {
591  // We should not have got here, assume quick format
592  formating=false;
593  // No fdformat to push
594  }
595  else
596  {
597  FDFormat *f = new FDFormat(this);
598  f->configureDevice(drive,blocks);
599  f->configure(verifylabel->isChecked());
600  formatActions->queue(f);
601  }
602 
603  if ( filesystemComboBox->currentText() == i18n("DOS") )
604  {
605  FATFilesystem *f = new FATFilesystem(this);
606  f->configure(verifylabel->isChecked(),
607  labellabel->isChecked(),
608  lineedit->text());
609  if ( userDevice )
610  {
611  f->configureDevice( currentComboBoxDevice );
612  }
613  else
614  {
615  f->configureDevice(drive,blocks);
616  }
617  formatActions->queue(f);
618  }
619 
620  else if ( filesystemComboBox->currentText() == i18n("ext2") )
621  {
622  Ext2Filesystem *f = new Ext2Filesystem(this);
623  f->configure(verifylabel->isChecked(),
624  labellabel->isChecked(),
625  lineedit->text());
626  if ( userDevice )
627  {
628  f->configureDevice( currentComboBoxDevice );
629  }
630  else
631  {
632  f->configureDevice(drive,blocks);
633  }
634  formatActions->queue(f);
635  }
636 
637 #ifdef ANY_BSD
638  else if ( filesystemComboBox->currentText() == i18n("UFS") )
639  {
640  FloppyAction *f = new UFSFilesystem(this);
641  f->configureDevice(drive,blocks);
642  formatActions->queue(f);
643  }
644 #endif
645 
646 #ifdef ANY_LINUX
647  else if ( filesystemComboBox->currentText() == i18n("Minix") )
648  {
649  MinixFilesystem *f = new MinixFilesystem(this);
650  f->configure(verifylabel->isChecked(),
651  labellabel->isChecked(),
652  lineedit->text());
653  if ( userDevice )
654  {
655  f->configureDevice( currentComboBoxDevice );
656  }
657  else
658  {
659  f->configureDevice(drive,blocks);
660  }
661  formatActions->queue(f);
662  }
663 #endif
664 
665  formatActions->exec();
666 }
667 
668 void FloppyData::formatStatus(const QString &s,int p)
669 {
670  kDebug(2002) << "FloppyData::formatStatus: " << s << " : " << p ;
671  if (!s.isEmpty())
672  {
673  const QString oldText ( frame->text() );
674  if ( oldText.isEmpty() )
675  {
676  frame->setText( s );
677  }
678  else
679  {
680  frame->setText( oldText + QLatin1Char( '\n' ) + s );
681  }
682  }
683 
684  if ((0<=p) && (p<=100))
685  progress->setValue(p);
686 }
687 
688 void FloppyData::writeSettings(){
689 
690  KConfigGroup config = KGlobal::config()->group("GeneralData");
691 
692  densityconfig = densityComboBox->currentText().trimmed();
693  filesystemconfig = filesystemComboBox->currentText().trimmed();
694  driveconfig = deviceComboBox->currentText().trimmed();
695 
696  quickformatconfig = quick->isChecked();
697 
698  labelnameconfig = lineedit->text().trimmed();
699 
700  labelconfig = labellabel->isChecked();
701 
702  verifyconfig = verifylabel->isChecked();
703 
704  config.writeEntry("CreateLabel",labelconfig);
705  config.writeEntry("Label",labelnameconfig);
706 
707 
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);
713  config.sync();
714 }
715 
716 void FloppyData::readSettings(){
717 
718  KConfigGroup config = KGlobal::config()->group("GeneralData");
719 
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" ) );
727 #else
728  densityconfig = config.readEntry( "Density", i18n("3.5\" 1.44MB") );
729 #endif
730  filesystemconfig = config.readEntry( "Filesystem", i18n("DOS") );
731 }
732 
733 void FloppyData::setWidgets(){
734 
735  labellabel->setChecked(labelconfig);
736  verifylabel->setChecked(verifyconfig);
737  quick->setChecked(quickformatconfig || !m_canLowLevel);
738  fullformat->setChecked(!quickformatconfig && m_canLowLevel);
739  lineedit->setText(labelnameconfig);
740 
741  for(int i = 0 ; i < deviceComboBox->count(); i++){
742  if ( deviceComboBox->itemText(i) == driveconfig){
743  deviceComboBox->setCurrentIndex(i);
744  }
745  }
746 
747  for(int i = 0 ; i < filesystemComboBox->count(); i++){
748  if ( filesystemComboBox->itemText(i) == filesystemconfig){
749  filesystemComboBox->setCurrentIndex(i);
750  }
751  }
752 
753  for(int i = 0 ; i < densityComboBox->count(); i++){
754  if ( densityComboBox->itemText(i) == densityconfig){
755  densityComboBox->setCurrentIndex(i);
756  }
757  }
758 }
759 
760 #include "floppy.moc"
floppy.h
KFAction::quit
virtual void quit()
Quit aborts the action.
Definition: format.cpp:64
FloppyData::~FloppyData
virtual ~FloppyData()
Definition: floppy.cpp:349
KFActionQueue::queue
void queue(KFAction *)
Add a KFAction to the queue.
Definition: format.cpp:95
FloppyData::quit
void quit()
Definition: floppy.cpp:449
FloppyData::findDevice
bool findDevice()
Maps combobox selection to drive and density.
Definition: floppy.cpp:376
FloppyData::show
void show()
Need to overload normal show() in order to mangle caption.
Definition: floppy.cpp:371
FloppyData::writeSettings
void writeSettings()
Writing the user-visible settings.
Definition: floppy.cpp:688
FATFilesystem::configure
bool configure(bool verify, bool label, const QString &l)
newfs_msdos(1) doesn't support an additional verify, but Linux mkdosfs(1) does.
Definition: format.cpp:648
KDialog
FloppyData::reset
void reset()
Definition: floppy.cpp:481
format.h
This file defines a hierarchy of classes that can run a sequence of external programs (like fdformat...
KFActionQueue::exec
virtual void exec()
Exec() should return quickly to ensire that the GUI thread stays alive.
Definition: format.cpp:103
FDFormat::configure
bool configure(bool verify)
verify instructs fdformat(1) to verify the medium as well.
Definition: format.cpp:400
FloppyData::formatStatus
void formatStatus(const QString &, int)
Definition: floppy.cpp:668
FloppyData::closeEvent
void closeEvent(QCloseEvent *)
Override closeEvent() in order to properly close the entire application.
Definition: floppy.cpp:354
Ext2Filesystem
Format with Ext2.
Definition: format.h:346
DEBUGSETUP
#define DEBUGSETUP
Definition: debug.h:42
KFActionQueue
Acts as a queue and executes the actions in the queue in FIFO order.
Definition: format.h:115
FloppyAction::configureDevice
bool configureDevice(int driveno, int density)
ConfigureDevice() needs to be called prior to exec() or exec() will fail; this indicates which drive ...
Definition: format.cpp:256
FATFilesystem::runtimeCheck
static bool runtimeCheck()
Definition: format.cpp:633
DDZeroOut
Zero out disk by runnind dd(1)
Definition: format.h:285
FloppyData::readSettings
void readSettings()
Reading the user-visible settings.
Definition: floppy.cpp:716
FloppyAction
Concrete action for running a single external program.
Definition: format.h:174
Ext2Filesystem::runtimeCheck
static bool runtimeCheck()
Definition: format.cpp:812
FloppyData::setWidgets
void setWidgets()
Map stored settings to widget status.
Definition: floppy.cpp:733
FloppyData::setInitialDevice
bool setInitialDevice(const QString &dev)
set default device
Definition: floppy.cpp:416
FDFormat
Concrete class that runs fdformat(1)
Definition: format.h:249
Ext2Filesystem::configure
bool configure(bool verify, bool label, const QString &l)
Same args as FATFilesystem::configure.
Definition: format.cpp:821
FloppyData::setEnabled
void setEnabled(bool)
Enable/disable all UI elements.
Definition: floppy.cpp:456
FATFilesystem
Create an msdos (FAT) filesystem on the floppy.
Definition: format.h:315
KFAction
Abstract base class of actions to be undertaken.
Definition: format.h:66
FloppyData::FloppyData
FloppyData(QWidget *parent=0)
Definition: floppy.cpp:56
FloppyData::keyPressEvent
void keyPressEvent(QKeyEvent *e)
Definition: floppy.cpp:359
FDFormat::runtimeCheck
static bool runtimeCheck()
Concrete classes can provide a runtimeCheck function (heck, this is static, so the name is up to you)...
Definition: format.cpp:394
DDZeroOut::runtimeCheck
static bool runtimeCheck()
Concrete classes can provide a runtimeCheck function (heck, this is static, so the name is up to you)...
Definition: format.cpp:561
FloppyData::format
void format()
Definition: floppy.cpp:499
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:08:02 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kfloppy

Skip menu "kfloppy"
  • Main Page
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdeutils API Reference

Skip menu "kdeutils API Reference"
  • ark
  • filelight
  • kcalc
  • kcharselect
  • kdf
  • kfloppy
  • kgpg
  • kremotecontrol
  • ktimer
  • kwallet
  • superkaramba
  • sweeper

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal