summaryrefslogtreecommitdiffstats
path: root/src/k3bsystemproblemdialog.cpp
blob: 75a9f58c066c3ce1799497d899217521185ead01 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
/* 
 *
 * $Id: k3bsystemproblemdialog.cpp 655079 2007-04-17 17:17:08Z trueg $
 * Copyright (C) 2003 Sebastian Trueg <trueg@k3b.org>
 *
 * This file is part of the K3b project.
 * Copyright (C) 1998-2007 Sebastian Trueg <trueg@k3b.org>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * See the file "COPYING" for the exact licensing terms.
 */


#include <config.h>


#include "k3bapplication.h"
#include "k3bsystemproblemdialog.h"
#include "k3bpassivepopup.h"
#include "k3bthemedheader.h"
#include <k3btitlelabel.h>
#include <k3bexternalbinmanager.h>
#include <k3bstdguiitems.h>
#include <k3bdevicemanager.h>
#include <k3bdevice.h>
#include <k3bversion.h>
#include <k3bglobals.h>
#include <k3bpluginmanager.h>
#include <k3bplugin.h>
#include <k3bprocess.h>
#include <k3bthememanager.h>
#include <k3bcore.h>

#include <tqpushbutton.h>
#include <tqcheckbox.h>
#include <tqlayout.h>
#include <tqlabel.h>
#include <tqfileinfo.h>

#include <klocale.h>
#include <kstandarddirs.h>
#include <ktextedit.h>
#include <kconfig.h>
#include <kapplication.h>
#include <kmessagebox.h>
#include <kprocess.h>
#include <kglobal.h>

#ifdef HAVE_ICONV_H
#include <langinfo.h>
#endif

#include <fstab.h>


static TQString markupString( const TQString& s_ )
{
  TQString s(s_);
  s.replace( '<', "&lt;" );
  s.replace( '>', "&gt;" );
  return s;
}


K3bSystemProblem::K3bSystemProblem( int t,
				    const TQString& p,
				    const TQString& d,
				    const TQString& s,
				    bool k )
  : type(t),
    problem(p),
    details(d),
    solution(s),
    solvableByK3bSetup(k)
{
}


K3bSystemProblemDialog::K3bSystemProblemDialog( const TQValueList<K3bSystemProblem>& problems,
						TQWidget* parent, 
						const char* name )
  : KDialog( parent, name )
{
  setCaption( i18n("System Configuration Problems") );

  // setup the title
  // ---------------------------------------------------------------------------------------------------
  K3bThemedHeader* titleFrame = new K3bThemedHeader( this );
  titleFrame->setTitle( i18n("System Configuration Problems"), 
			i18n("1 problem", "%n problems", problems.count() ) );

  m_closeButton = new TQPushButton( i18n("Close"), this );
  connect( m_closeButton, TQT_SIGNAL(clicked()), this, TQT_SLOT(close()) );
  m_checkDontShowAgain = new TQCheckBox( i18n("Do not show again"), this );

#ifdef HAVE_K3BSETUP
  m_k3bsetupButton = new TQPushButton( i18n("Start K3bSetup2"), this );
  connect( m_k3bsetupButton, TQT_SIGNAL(clicked()), this, TQT_SLOT(slotK3bSetup()) );
#endif

  // setup the problem view
  // ---------------------------------------------------------------------------------------------------
  KTextEdit* view = new KTextEdit( this );
  view->setReadOnly(true);
  view->setTextFormat(RichText);


  // tqlayout everything
  TQGridLayout* grid = new TQGridLayout( this );
  grid->setMargin( marginHint() );
  grid->setSpacing( spacingHint() );
  grid->addMultiCellWidget( titleFrame, 0, 0, 0, 1 );
  grid->addMultiCellWidget( view, 1, 1, 0, 1 );
  grid->addWidget( m_checkDontShowAgain, 2, 0 );
  TQHBoxLayout* buttonBox = new TQHBoxLayout;
  buttonBox->setSpacing( spacingHint() );
  buttonBox->setMargin( 0 );
#ifdef HAVE_K3BSETUP
  buttonBox->addWidget( m_k3bsetupButton );
#endif
  buttonBox->addWidget( m_closeButton );
  grid->addLayout( buttonBox, 2, 1 );
  grid->setColStretch( 0, 1 );
  grid->setRowStretch( 1, 1 );

  TQString text = "<html>";

  for( TQValueList<K3bSystemProblem>::const_iterator it = problems.begin();
       it != problems.end(); ++it ) {
    const K3bSystemProblem& p = *it;

    text.append( "<p><b>" );
    if( p.type == K3bSystemProblem::CRITICAL )
      text.append( "<span style=\"color:red\">" );
    text.append( markupString( p.problem ) );
    if( p.type == K3bSystemProblem::CRITICAL )
      text.append( "</span>" );
    text.append( "</b><br>" );
    text.append( markupString( p.details ) + "<br>" );
    if( !p.solution.isEmpty() )
      text.append( "<i>" + i18n("Solution") + "</i>: " + p.solution );
#ifdef HAVE_K3BSETUP
    else if( p.solvableByK3bSetup )
      text.append( "<i>" + i18n("Solution") + "</i>: " + i18n("Use K3bSetup to solve this problem.") );
#endif
    text.append( "</p>" );
  }

  text.append( "</html>" );

  view->setText(text);
  view->setCursorPosition(0,0);
  view->ensureCursorVisible();
}


void K3bSystemProblemDialog::closeEvent( TQCloseEvent* e )
{
  if( m_checkDontShowAgain->isChecked() ) {
    KConfigGroup grp( kapp->config(), "General Options" );
    grp.writeEntry( "check system config", false );
  }

  e->accept();
}


void K3bSystemProblemDialog::checkSystem( TQWidget* parent, 
					  const char* name )
{
  TQValueList<K3bSystemProblem> problems;

  if( k3bcore->deviceManager()->cdWriter().isEmpty() ) {
    problems.append( K3bSystemProblem( K3bSystemProblem::NON_CRITICAL,
				       i18n("No CD/DVD writer found."),
				       i18n("K3b did not find an optical writing device in your system. Thus, "
					    "you will not be able to burn CDs or DVDs. However, you can still "
					    "use other K3b features like audio track extraction or audio "
					    "transcoding or ISO9660 image creation."),
					    false ) );
  }
  else {
    // 1. cdrecord, cdrdao
    if( !k3bcore->externalBinManager()->foundBin( "cdrecord" ) ) {
      problems.append( K3bSystemProblem( K3bSystemProblem::CRITICAL,
					 i18n("Unable to find %1 executable").tqarg("cdrecord"),
					 i18n("K3b uses cdrecord to actually write CDs."),
					 i18n("Install the cdrtools package which contains "
					      "cdrecord."),
					 false ) );
    }
    else {
      if( k3bcore->externalBinManager()->binObject( "cdrecord" )->hasFeature( "outdated" ) ) {
	problems.append( K3bSystemProblem( K3bSystemProblem::NON_CRITICAL,
					   i18n("Used %1 version %2 is outdated").tqarg("cdrecord").tqarg(k3bcore->externalBinManager()->binObject( "cdrecord" )->version),
					   i18n("Although K3b supports all cdrtools versions since "
						"1.10 it is highly recommended to at least use "
						"version 2.0."),
					   i18n("Install a more recent version of the cdrtools."),
					   false ) );
      }

/*    
#ifdef Q_OS_LINUX

      //
      // Since kernel 2.6.8 older cdrecord versions are not able to use the SCSI subsystem when running suid root anymore
      // So far we ignore the suid root issue with kernel >= 2.6.8 and cdrecord < 2.01.01a02
      //
      // Kernel 2.6.16.something seems to introduce another problem which was apparently worked around in cdrecord 2.01.01a05
      //
      if( K3b::simpleKernelVersion() >= K3bVersion( 2, 6, 8 ) &&
	  k3bcore->externalBinManager()->binObject( "cdrecord" )->version < K3bVersion( 2, 1, 1, "a05" ) &&
	  !k3bcore->externalBinManager()->binObject( "cdrecord" )->hasFeature( "wodim" ) ) {
	if( k3bcore->externalBinManager()->binObject( "cdrecord" )->hasFeature( "suidroot" ) )
	  problems.append( K3bSystemProblem( K3bSystemProblem::CRITICAL,
					     i18n("%1 will be run with root privileges on kernel >= 2.6.8").tqarg("cdrecord <= 2.01.01a05"),
					     i18n("Since Linux kernel 2.6.8 %1 will not work when run suid "
						  "root for security reasons anymore.").tqarg("cdrecord <= 2.01.01a05"),
					     TQString(),
					     true ) );
      }
#ifdef CDRECORD_SUID_ROOT_CHECK
      else if( !k3bcore->externalBinManager()->binObject( "cdrecord" )->hasFeature( "suidroot" ) && getuid() != 0 ) // not root
	problems.append( K3bSystemProblem( K3bSystemProblem::CRITICAL,
					   i18n("%1 will be run without root privileges").tqarg("cdrecord"),
					   i18n("It is highly recommended to configure cdrecord "
						"to run with root privileges. Only then cdrecord "
						"runs with high priority which increases the overall "
						"stability of the burning process. Apart from that "
						"it allows changing the size of the used burning buffer. "
						"A lot of user problems could be solved this way. This is also "
						"true when using SuSE's resmgr."),
					   TQString(),
					   true ) );
#endif // CDRECORD_SUID_ROOT_CHECK
#endif
*/
    }
    if( !k3bcore->externalBinManager()->foundBin( "cdrdao" ) ) {
      problems.append( K3bSystemProblem( K3bSystemProblem::CRITICAL,
					 i18n("Unable to find %1 executable").tqarg("cdrdao"),
					 i18n("K3b uses cdrdao to actually write CDs."),
					 i18n("Install the cdrdao package."),
					 false ) );
    }
/*
    else {
#ifdef Q_OS_LINUX
#ifdef CDRECORD_SUID_ROOT_CHECK
      if( !k3bcore->externalBinManager()->binObject( "cdrdao" )->hasFeature( "suidroot" ) && getuid() != 0 )
	problems.append( K3bSystemProblem( K3bSystemProblem::CRITICAL,
					   i18n("%1 will be run without root privileges").tqarg("cdrdao"),
					   i18n("It is highly recommended to configure cdrdao "
						"to run with root privileges to increase the "
						"overall stability of the burning process."),
					   TQString(),
					   true ) );
#endif // CDRECORD_SUID_ROOT_CHECK
#endif
    }
*/
  }

  if( !k3bcore->deviceManager()->dvdWriter().isEmpty() ) {
    if( !k3bcore->externalBinManager()->foundBin( "growisofs" ) ) {
      problems.append( K3bSystemProblem( K3bSystemProblem::CRITICAL,
					 i18n("Unable to find %1 executable").tqarg("growisofs"),
					 i18n("K3b uses growisofs to actually write dvds. "
					      "Without growisofs you will not be able to write dvds. "
					      "Make sure to install at least version 5.10."),
					 i18n("Install the dvd+rw-tools package."),
					 false ) );
    }
    else {
      if( k3bcore->externalBinManager()->binObject( "growisofs" )->version < K3bVersion( 5, 10 ) ) {
	problems.append( K3bSystemProblem( K3bSystemProblem::CRITICAL,
					   i18n("Used %1 version %2 is outdated").tqarg("growisofs").tqarg(k3bcore->externalBinManager()->binObject( "growisofs" )->version),
					   i18n("K3b needs at least growisofs version 5.10 to write dvds. "
						"All older versions will not work and K3b will refuse to use them."),
					   i18n("Install a more recent version of %1.").tqarg("growisofs"),
					   false ) );
      }
      else if( k3bcore->externalBinManager()->binObject( "growisofs" )->version < K3bVersion( 5, 12 ) ) {
	problems.append( K3bSystemProblem( K3bSystemProblem::NON_CRITICAL,
					   i18n("Used %1 version %2 is outdated").tqarg("growisofs").tqarg(k3bcore->externalBinManager()->binObject( "growisofs" )->version),
					   i18n("K3b will not be able to copy DVDs on-the-fly or write a DVD+RW in multiple "
						"sessions using a growisofs "
						"version older than 5.12."),
					   i18n("Install a more recent version of %1.").tqarg("growisofs"),
					   false ) );
      }
      else if( k3bcore->externalBinManager()->binObject( "growisofs" )->version < K3bVersion( 7, 0 ) ) {
	problems.append( K3bSystemProblem( K3bSystemProblem::NON_CRITICAL,
					   i18n("Used %1 version %2 is outdated").tqarg("growisofs").tqarg(k3bcore->externalBinManager()->binObject( "growisofs" )->version),
					   i18n("It is highly recommended to use growisofs 7.0 or higher. "
						"K3b won't be able to write a DVD+RW in multiple "
						"sessions using a growisofs version older than 7.0." ),
					   i18n("Install a more recent version of %1.").tqarg("growisofs"),
					   false ) );
      }
      // for now we ignore the suid root bit becasue of the memorylocked issue
//       else if( !k3bcore->externalBinManager()->binObject( "growisofs" )->hasFeature( "suidroot" ) ) {
// 	problems.append( K3bSystemProblem( K3bSystemProblem::CRITICAL,
// 					   i18n("%1 will be run without root privileges").tqarg("growisofs"),
// 					   i18n("It is highly recommended to configure growisofs "
// 						"to run with root privileges. Only then growisofs "
// 						"runs with high priority which increases the overall "
// 						"stability of the burning process."),
// 					   TQString(),
// 					   true ) );
//       }
    }

    if( !k3bcore->externalBinManager()->foundBin( "dvd+rw-format" ) ) {
      problems.append( K3bSystemProblem( K3bSystemProblem::CRITICAL,
					 i18n("Unable to find %1 executable").tqarg("dvd+rw-format"),
					 i18n("K3b uses dvd+rw-format to format DVD-RWs and DVD+RWs."),
					 i18n("Install the dvd+rw-tools package."),
					 false ) );
    }
  }

  if( !k3bcore->externalBinManager()->foundBin( "mkisofs" ) ) {

  }
  else if( k3bcore->externalBinManager()->binObject( "mkisofs" )->hasFeature( "outdated" ) ) {
      problems.append( K3bSystemProblem( K3bSystemProblem::CRITICAL,
					 i18n("Used %1 version %2 is outdated")
					 .tqarg("mkisofs")
					 .tqarg(k3bcore->externalBinManager()->binObject( "mkisofs" )->version),
					 i18n("K3b needs at least mkisofs version 1.14. Older versions may introduce problems "
					      "when creating data projects."),
					 i18n("Install a more recent version of %1.").tqarg("mkisofs"),
					 false ) );
  }

  // 2. device check
  bool atapiReader = false;
  bool atapiWriter = false;
  bool dvd_r_dl = false;
  for( TQPtrListIterator<K3bDevice::Device> it( k3bcore->deviceManager()->readingDevices() );
       it.current(); ++it ) {
    if( it.current()->interfaceType() == K3bDevice::IDE )
      atapiReader = true;
    if( it.current()->type() & K3bDevice::DEVICE_DVD_R_DL )
      dvd_r_dl = true;
  }


  // check automounted devices
  TQPtrList<K3bDevice::Device> automountedDevices = checkForAutomounting();
  for( TQPtrListIterator<K3bDevice::Device> it( automountedDevices );
       it.current(); ++it ) {
    problems.append( K3bSystemProblem( K3bSystemProblem::NON_CRITICAL,
				       i18n("Device %1 - %2 is automounted.")
				       .tqarg(it.current()->vendor()).tqarg(it.current()->description()),
				       i18n("K3b is not able to unmount automounted devices. Thus, especially "
					    "DVD+RW rewriting might fail. There is no need to report this as "
					    "a bug or feature wish; it is not possible to solve this problem "
					    "from within K3b."),
				       i18n("Replace the automounting entries in /etc/fstab with old-fashioned "
					    "ones or use a user-space mounting solution like pmount or ivman."),
				       false ) );
  }


  if( atapiWriter ) {
    if( !K3b::plainAtapiSupport() &&
	!K3b::hackedAtapiSupport() ) {
      problems.append( K3bSystemProblem( K3bSystemProblem::CRITICAL,
					 i18n("No ATAPI writing support in kernel"),
					 i18n("Your kernel does not support writing without "
					      "SCSI emulation but there is at least one "
					      "writer in your system not configured to use "
					      "SCSI emulation."),
					 i18n("The best and recommended solution is to enable "
					      "ide-scsi (SCSI emulation) for all devices. "
					      "This way you won't have any problems."
					      "Be aware that you may still enable DMA on ide-scsi "
					      "emulated drives."),
					 false ) );
    }
    else {
      // we have atapi support in some way in the kernel

      if( k3bcore->externalBinManager()->foundBin( "cdrecord" ) ) {

	if( !( k3bcore->externalBinManager()->binObject( "cdrecord" )->hasFeature( "hacked-atapi" ) &&
	       K3b::hackedAtapiSupport() ) &&
	    !( k3bcore->externalBinManager()->binObject( "cdrecord" )->hasFeature( "plain-atapi" ) &&
	       K3b::plainAtapiSupport() ) ) {
	  problems.append( K3bSystemProblem( K3bSystemProblem::CRITICAL,
					     i18n("%1 %2 does not support ATAPI").tqarg("cdrecord").tqarg(k3bcore->externalBinManager()->binObject("cdrecord")->version),
					     i18n("The configured version of %1 does not "
						  "support writing to ATAPI devices without "
						  "SCSI emulation and there is at least one writer "
						  "in your system not configured to use "
						  "SCSI emulation.").tqarg("cdrecord"),
					     i18n("The best and recommended solution is to enable "
						  "ide-scsi (SCSI emulation) for all devices. "
						  "This way you won't have any problems. Or you install "
						  "(or select as the default) a more recent version of %1.").tqarg("cdrtools"),
					     false ) );
	}
      }

      if( k3bcore->externalBinManager()->foundBin( "cdrdao" ) ) {

	if( !k3bcore->externalBinManager()->binObject( "cdrdao" )->hasFeature( "hacked-atapi" ) &&
	    !k3bcore->externalBinManager()->binObject( "cdrdao" )->hasFeature( "plain-atapi") ) {
	  // FIXME: replace ">" with "&gt;"
	  problems.append( K3bSystemProblem( K3bSystemProblem::CRITICAL,
					     i18n("%1 %2 does not support ATAPI")
					     .tqarg("cdrdao").tqarg(k3bcore->externalBinManager()->binObject("cdrdao")->version),
					     i18n("The configured version of %1 does not "
						  "support writing to ATAPI devices without "
						  "SCSI emulation and there is at least one writer "
						  "in your system not configured to use "
						  "SCSI emulation.").tqarg("cdrdao"),
					     K3b::simpleKernelVersion() > K3bVersion( 2, 5, 0 )
					     ? i18n("Install cdrdao >= 1.1.8 which supports writing to "
						    "ATAPI devices directly.")
					     : i18n("The best, and recommended, solution is to use "
						    "ide-scsi (SCSI emulation) for all writer devices: "
						    "this way you will not have any problems; or, you can install "
						    "(or select as the default) a more recent version of %1.").tqarg("cdrdao"),
					     false ) );
	}
      }
    }
  }

  if( dvd_r_dl && k3bcore->externalBinManager()->foundBin( "growisofs" ) ) {
    if( k3bcore->externalBinManager()->binObject( "growisofs" )->version < K3bVersion( 6, 0 ) )
      problems.append( K3bSystemProblem( K3bSystemProblem::NON_CRITICAL,
					 i18n("Used %1 version %2 is outdated").tqarg("growisofs").tqarg(k3bcore->externalBinManager()->binObject( "growisofs" )->version),
					 i18n("K3b won't be able to write DVD-R Dual Layer media using a growisofs "
					      "version older than 6.0."),
					 i18n("Install a more recent version of growisofs."),
					 false ) );
  }

  for( TQPtrListIterator<K3bDevice::Device> it( k3bcore->deviceManager()->allDevices() );
       it.current(); ++it ) {
    K3bDevice::Device* dev = it.current();

    if( !TQFileInfo( dev->blockDeviceName() ).isWritable() )
      problems.append( K3bSystemProblem( K3bSystemProblem::CRITICAL,
					 i18n("No write access to device %1").tqarg(dev->blockDeviceName()),
					 i18n("K3b needs write access to all the devices to perform certain tasks. "
					      "Without it you might encounter problems with %1 - %2").tqarg(dev->vendor()).tqarg(dev->description()),
					 i18n("Make sure you have write access to %1. In case you are not using "
					      "devfs or udev K3bSetup is able to do this for you.").tqarg(dev->blockDeviceName()),
					 false ) );


    if( !dev->genericDevice().isEmpty() &&
	!TQFileInfo( dev->genericDevice() ).isWritable() )
      problems.append( K3bSystemProblem( K3bSystemProblem::CRITICAL,
					 i18n("No write access to generic SCSI device %1").tqarg(dev->genericDevice()),
					 i18n("Without write access to the generic device you might "
					      "encounter problems with Audio CD ripping from %1 - %2").tqarg(dev->vendor()).tqarg(dev->description()),
					 i18n("Make sure you have write access to %1. In case you are not using "
					      "devfs or udev K3bSetup is able to do this for you.").tqarg(dev->genericDevice()),
					 false ) );

    if( dev->interfaceType() == K3bDevice::IDE && !dmaActivated( dev ) )
      problems.append( K3bSystemProblem( K3bSystemProblem::CRITICAL,
					 i18n("DMA disabled on device %1 - %2").tqarg(dev->vendor()).tqarg(dev->description()),
					 i18n("With most modern CD/DVD devices enabling DMA highly increases "
					      "read/write performance. If you experience very low writing speeds "
					      "this is probably the cause."),
					 i18n("Enable DMA temporarily as root with 'hdparm -d 1 %1'.").tqarg(dev->blockDeviceName()) ) );
  }


  //
  // Check if the user specified some user parameters and warn about it
  //
  const TQMap<TQString, K3bExternalProgram*>& programMap = k3bcore->externalBinManager()->programs();
  for( TQMap<TQString, K3bExternalProgram*>::const_iterator it = programMap.constBegin();
       it != programMap.constEnd(); ++it ) {
    const K3bExternalProgram* p = it.data();
    if( !p->userParameters().isEmpty() ) {
      problems.append( K3bSystemProblem( K3bSystemProblem::WARNING,
					 i18n("User parameters specified for external program %1").tqarg(p->name()),
					 i18n("Sometimes it may be nessessary to specify user parameters in addition to "
					      "the parameters generated by K3b. This is simply a warning to make sure that "
					      "these parameters are really wanted and won't be part of some bug report."),
					 i18n("To remove the user parameters for the external program %1 open the "
					      "K3b settings page 'Programs' and choose the tab 'User Parameters'.")
					 .tqarg(p->name()),
					 false ) );
    }
  }

  //
  // Way too many users are complaining about K3b not being able to decode mp3 files. So just warn them about
  // the legal restrictions with many distros
  //
/*
  TQPtrList<K3bPlugin> plugins = k3bcore->pluginManager()->plugins( "AudioDecoder" );
  bool haveMp3Decoder = false;
  for( TQPtrListIterator<K3bPlugin> it( plugins ); *it; ++it ) {
    if( it.current()->pluginInfo().name() == "K3b MAD Decoder" ) {
      haveMp3Decoder = true;
      break;
    }
  }
  if( !haveMp3Decoder ) {
      problems.append( K3bSystemProblem( K3bSystemProblem::WARNING,
					 i18n("Mp3 Audio Decoder plugin not found."),
					 i18n("K3b could not load or find the Mp3 decoder plugin. This means that you will not "
					      "be able to create Audio CDs from Mp3 files. Many Linux distributions do not "
					      "include Mp3 support for legal reasons."),
					 i18n("To enable Mp3 support, please install the MAD Mp3 decoding library as well as the "
					      "K3b MAD Mp3 decoder plugin (the latter may already be installed but not functional "
					      "due to the missing libmad). Some distributions allow installation of Mp3 support "
					      "via an online update tool (i.e. SuSE's YOU)."),
					 false ) );
  }
*/

#ifdef HAVE_ICONV_H
  char* codec = nl_langinfo( CODESET );
  if( strcmp( codec, "ANSI_X3.4-1968" ) == 0 ) {
    //
    // On a glibc system the system locale defaults to ANSI_X3.4-1968
    // It is very unlikely that one would set the locale to ANSI_X3.4-1968
    // intentionally
    //
    problems.append( K3bSystemProblem( K3bSystemProblem::WARNING,
				       i18n("System locale charset is ANSI_X3.4-1968"),
				       i18n("Your system's locale charset (i.e. the charset used to encode filenames) "
					    "is set to ANSI_X3.4-1968. It is highly unlikely that this has been done "
					    "intentionally. Most likely the locale is not set at all. An invalid setting "
					    "will result in problems when creating data projects."),
				       i18n("To properly set the locale charset make sure the LC_* environment variables "
					    "are set. Normally the distribution setup tools take care of this."),
				       false ) );
  }
#endif


  //
  // Never run K3b as root and especially not suid root! The latter is not possible anyway since
  // the kdelibs refuse it.
  //
  if( ::getuid() == 0 ) {
    problems.append( K3bSystemProblem( K3bSystemProblem::WARNING,
				       i18n("Running K3b as root user"),
				       i18n("It is not recommended to run K3b under the root user account. "
					    "This introduces unnecessary security risks."),
				       i18n("Run K3b from a proper user account and setup the device and "
					    "external tool permissions appropriately.")
#ifdef HAVE_K3BSETUP
				       + ' ' + i18n("The latter can be done via K3bSetup.")
#endif
				       ,
				       true ) );
  }


  kdDebug() << "(K3bCore) System problems:" << endl;
  for( TQValueList<K3bSystemProblem>::const_iterator it = problems.begin();
       it != problems.end(); ++it ) {
    const K3bSystemProblem& p = *it;

    switch( p.type ) {
    case K3bSystemProblem::CRITICAL:
      kdDebug() << " CRITICAL" << endl;
      break;
    case K3bSystemProblem::NON_CRITICAL:
      kdDebug() << " NON_CRITICAL" << endl;
      break;
    case K3bSystemProblem::WARNING:
      kdDebug() << " WARNING" << endl;
      break;
    }
    kdDebug() << " PROBLEM:  " << p.problem << endl
	      << " DETAILS:  " << p.details << endl
	      << " SOLUTION: " << p.solution << endl << endl;

  }
  if( problems.isEmpty() ) {
    kdDebug() << "          - none - " << endl;
    //K3bPassivePopup::showPopup( i18n("No problems found in system configuration."), i18n("System Problems") );
  }
  else {
    static K3bSystemProblemDialog* s_openDlg = 0;
    if( s_openDlg )
      s_openDlg->close();
    K3bSystemProblemDialog dlg( problems, parent, name );
    s_openDlg = &dlg;
    dlg.exec();
    s_openDlg = 0;
  }

  // remember which version of K3b checked the system the last time
  KConfigGroup cfg( k3bcore->config(), "General Options" );
  cfg.writeEntry( "Last system check version", k3bcore->version() );
}

void K3bSystemProblemDialog::slotK3bSetup()
{
  KProcess p;
  p << "kdesu" << "kcmshell k3bsetup2 --lang " + KGlobal::locale()->language();
  if( !p.start( KProcess::DontCare ) )
    KMessageBox::error( 0, i18n("Unable to start K3bSetup2.") );
}


int K3bSystemProblemDialog::dmaActivated( K3bDevice::Device* dev )
{
  TQString hdparm = K3b::findExe( "hdparm" );
  if( hdparm.isEmpty() )
    return -1;

  K3bProcess p;
  K3bProcessOutputCollector out( &p );
  p << hdparm << "-d" << dev->blockDeviceName();
  if( !p.start( KProcess::Block, KProcess::AllOutput ) )
    return -1;

  // output is something like:
  //
  // /dev/hda:
  //  using_dma    =  1 (on)
  //
  // But we ignore the on/off since it might be translated
  //
  if( out.output().contains( "1 (" ) )
    return 1;
  else if( out.output().contains( "0 (" ) )
    return 0;
  else
    return -1;
}


TQPtrList<K3bDevice::Device> K3bSystemProblemDialog::checkForAutomounting()
{
  TQPtrList<K3bDevice::Device> l;

  ::setfsent();

  struct fstab * mountInfo = 0;
  while( (mountInfo = ::getfsent()) )
  {
    // check if the entry corresponds to a device
    TQString md = K3b::resolveLink( TQFile::decodeName( mountInfo->fs_spec ) );
    TQString type = TQFile::decodeName( mountInfo->fs_vfstype );

    if( type == "supermount" || type == "subfs" ) {
      // parse the device
      TQStringList opts = TQStringList::split( ",", TQString::fromLocal8Bit(mountInfo->fs_mntops) );
      for( TQStringList::const_iterator it = opts.begin(); it != opts.end(); ++it ) {
	if( (*it).startsWith("dev=") ) {
	  md = (*it).mid( 4 );
	  break;
	}
      }

      if( K3bDevice::Device* dev = k3bcore->deviceManager()->findDevice( md ) )
	l.append( dev );
    }
  } // while mountInfo

  ::endfsent();

  return l;
}


bool K3bSystemProblemDialog::readCheckSystemConfig()
{
  KConfigGroup cfgGrp( k3bcore->config(), "General Options" );

  K3bVersion configVersion( cfgGrp.readEntry( "Last system check version", "0.1" ) );
  if( configVersion < k3bcore->version() )
    cfgGrp.writeEntry( "check system config", true );

  return cfgGrp.readBoolEntry( "check system config", true );
}

#include "k3bsystemproblemdialog.moc"