File: k3bsystemproblemdialog.cpp

package info (click to toggle)
k3b 2.0.3a-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 50,416 kB
  • ctags: 12,996
  • sloc: cpp: 100,125; sh: 67; xml: 10; makefile: 8
file content (700 lines) | stat: -rw-r--r-- 36,204 bytes parent folder | download | duplicates (3)
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
691
692
693
694
695
696
697
698
699
700
/*
 *
 * Copyright (C) 2003-2008 Sebastian Trueg <trueg@k3b.org>
 *
 * This file is part of the K3b project.
 * Copyright (C) 1998-2008 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-k3b.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 "k3bthememanager.h"
#include "k3bcore.h"

#include <KColorScheme>
#include <KConfigGroup>
#include <KGlobal>
#include <KLocale>
#include <KMessageBox>
#include <KProcess>
#include <KPushButton>
#include <KStandardGuiItem>
#include <KTextEdit>

#include <QCheckBox>
#include <QCloseEvent>
#include <QFileInfo>
#include <QGridLayout>
#include <QHBoxLayout>
#include <QList>

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

#ifndef Q_OS_WIN32
#include <fstab.h>
#endif
#include <unistd.h>


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


K3b::SystemProblem::SystemProblem( Type t,
                                   const QString& p,
                                   const QString& d,
                                   const QString& s )
    : type(t),
      problem(p),
      details(d),
      solution(s)
{
}


K3b::SystemProblemDialog::SystemProblemDialog( const QList<K3b::SystemProblem>& problems,
                                               bool showK3bSetupButton,
                                               QWidget* parent)
    : KDialog( parent )
{
    setCaption( i18n("System Configuration Problems") );
    setButtons(KDialog::None);
    QWidget *widget = new QWidget(this);
    setMainWidget(widget);
    // setup the title
    // ---------------------------------------------------------------------------------------------------
    K3b::ThemedHeader* titleFrame = new K3b::ThemedHeader( widget );
    titleFrame->setTitle( i18n("System Configuration Problems"),
                          i18np("1 problem", "%1 problems", problems.count() ) );

    KPushButton* closeButton = new KPushButton( KStandardGuiItem::close(), widget );
    connect( closeButton, SIGNAL(clicked()), this, SLOT(close()) );
    m_checkDontShowAgain = new QCheckBox( i18n("Do not show again"), widget );

    QPushButton* k3bsetupButton = 0;
#ifdef BUILD_K3BSETUP
    if( showK3bSetupButton ) {
        k3bsetupButton = new QPushButton( i18n("Modify Permissions..."), widget );
        connect( k3bsetupButton, SIGNAL(clicked()), this, SLOT(slotK3bSetup()) );
    }
#else
    Q_UNUSED( showK3bSetupButton );
#endif

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

    // layout everything
    QGridLayout* grid = new QGridLayout( widget );
    grid->addWidget( titleFrame, 0, 0, 1, 2 );
    grid->addWidget( view, 1, 0, 1, 2 );
    grid->addWidget( m_checkDontShowAgain, 2, 0 );
    QHBoxLayout* buttonBox = new QHBoxLayout;
    buttonBox->setMargin( 0 );
    if( k3bsetupButton != 0 ) {
        buttonBox->addWidget( k3bsetupButton );
    }
    buttonBox->addWidget( closeButton );
    grid->addLayout( buttonBox, 2, 1 );
    grid->setColumnStretch( 0, 1 );
    grid->setRowStretch( 1, 1 );
    
    const KColorScheme colorScheme( QPalette::Normal, KColorScheme::Button );
    const QColor negativeTextColor = colorScheme.foreground( KColorScheme::NegativeText ).color();

    QString text = "<html>";

    for( QList<K3b::SystemProblem>::const_iterator it = problems.constBegin();
         it != problems.constEnd(); ++it ) {
        const K3b::SystemProblem& p = *it;

        text.append( "<p><b>" );
        if( p.type == K3b::SystemProblem::CRITICAL ) {
            text.append( QString("<span style=\"color:%1\">").arg( negativeTextColor.name() ) );
        }
        text.append( markupString( p.problem ) );
        if( p.type == K3b::SystemProblem::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 );
        text.append( "</p>" );
    }

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

    view->setText(text);
    view->moveCursor( QTextCursor::Start );
    view->ensureCursorVisible();
}


void K3b::SystemProblemDialog::closeEvent( QCloseEvent* e )
{
    if( m_checkDontShowAgain->isChecked() ) {
        KConfigGroup grp( KGlobal::config(), "General Options" );
        grp.writeEntry( "check system config", false );
    }

    e->accept();
}


void K3b::SystemProblemDialog::checkSystem( QWidget* parent, NotificationLevel level )
{
    QList<K3b::SystemProblem> problems;
    bool showK3bSetupButton = false;
    
#ifdef BUILD_K3BSETUP
    const QString k3bSetupSolutionText = i18n("Click \"Modify Permissions...\" to solve this problem.");
#else
    const QString k3bSetupSolutionText = QString();
#endif

    if( k3bcore->deviceManager()->allDevices().isEmpty() ) {
        problems.append( K3b::SystemProblem( K3b::SystemProblem::CRITICAL,
                                           i18n("No optical drive found."),
                                           i18n("K3b did not find any optical device in your system."),
#ifdef ENABLE_HAL_SUPPORT
                                           i18n("Make sure HAL daemon is running, it is used by K3b for finding devices.")
#else
                                           QString()
#endif
                                           ) );
    }
    else if( k3bcore->deviceManager()->cdWriter().isEmpty() ) {
        problems.append( K3b::SystemProblem( K3b::SystemProblem::NON_CRITICAL,
                                           i18n("No CD/DVD/BD 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 such as audio track extraction, audio "
                                                "transcoding or ISO9660 image creation."),
                                           QString() ) );
    }
    else {
        // 1. cdrecord, cdrdao
        if( !k3bcore->externalBinManager()->foundBin( "cdrecord" ) ) {
            problems.append( K3b::SystemProblem( K3b::SystemProblem::CRITICAL,
                                               i18n("Unable to find %1 executable",QString("cdrecord")),
                                               i18n("K3b uses cdrecord to actually write CDs."),
                                               i18n("Install the cdrtools package which contains "
                                                    "cdrecord.") ) );
        }
        else {
            if( k3bcore->externalBinManager()->binObject( "cdrecord" )->hasFeature( "outdated" ) ) {
                problems.append( K3b::SystemProblem( K3b::SystemProblem::NON_CRITICAL,
                                                   i18n("Used %1 version %2 is outdated",QString("cdrecord"),QString(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.") ) );
            }

/*
#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() >= K3b::Version( 2, 6, 8 ) &&
                k3bcore->externalBinManager()->binObject( "cdrecord" )->version < K3b::Version( 2, 1, 1, "a05" ) &&
                !k3bcore->externalBinManager()->binObject( "cdrecord" )->hasFeature( "wodim" ) ) {
                if( k3bcore->externalBinManager()->binObject( "cdrecord" )->hasFeature( "suidroot" ) ) {
                    showK3bSetupButton = true;
                    problems.append( K3b::SystemProblem( K3b::SystemProblem::CRITICAL,
                                                         i18n("%1 will be run with root privileges on kernel >= 2.6.8",QString("cdrecord <= 2.01.01a05")),
                                                         i18n("Since Linux kernel 2.6.8 %1 will not work when run suid "
                                                              "root for security reasons anymore.",
                                                         QLatin1String( "cdrecord <= 2.01.01a05") ),
                                                         k3bSetupSolutionText ) );
                }
            }
#ifdef CDRECORD_SUID_ROOT_CHECK
            else if( !k3bcore->externalBinManager()->binObject( "cdrecord" )->hasFeature( "suidroot" ) && getuid() != 0 ) { // not root
                showK3bSetupButton = true;
                problems.append( K3b::SystemProblem( K3b::SystemProblem::CRITICAL,
                                                     i18n("%1 will be run without root privileges",QString("cdrecord")),
                                                     i18n("It is highly recommended to configure cdrecord "
                                                          "to run with root privileges, as then cdrecord "
                                                          "runs with high priority that increases the overall "
                                                          "stability of the burning process. As well as this, "
                                                          "it allows the size of the burning buffer to be changed, "
                                                          "and a lot of user problems can be solved this way."),
                                                     k3bSetupSolutionText ) );
            }
#endif // CDRECORD_SUID_ROOT_CHECK
#endif
*/
        }

        if( !k3bcore->externalBinManager()->foundBin( "cdrdao" ) ) {
            problems.append( K3b::SystemProblem( K3b::SystemProblem::CRITICAL,
                                               i18n("Unable to find %1 executable",QString("cdrdao")),
                                               i18n("K3b uses cdrdao to actually write CDs."),
                                               i18n("Install the cdrdao package.") ) );
        }
/*
        else {
#ifdef Q_OS_LINUX
#ifdef CDRECORD_SUID_ROOT_CHECK
            if( !k3bcore->externalBinManager()->binObject( "cdrdao" )->hasFeature( "suidroot" ) && getuid() != 0 ) {
                showK3bSetupButton = true;
                problems.append( K3b::SystemProblem( K3b::SystemProblem::CRITICAL,
                                                     i18n("%1 will be run without root privileges",QString("cdrdao")),
                                                     i18n("It is highly recommended to configure cdrdao "
                                                          "to run with root privileges to increase the "
                                                          "overall stability of the burning process."),
                                                     k3bSetupSolutionText ) );
            }
#endif // CDRECORD_SUID_ROOT_CHECK
#endif
        }
*/
    }


    if( !k3bcore->deviceManager()->dvdWriter().isEmpty() ) {
        if( !k3bcore->externalBinManager()->foundBin( "growisofs" ) ) {
            problems.append( K3b::SystemProblem( K3b::SystemProblem::CRITICAL,
                                               i18n("Unable to find %1 executable",QString("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.") ) );
        }
        else {
            if( k3bcore->externalBinManager()->binObject( "growisofs" )->version < K3b::Version( 5, 10 ) ) {
                problems.append( K3b::SystemProblem( K3b::SystemProblem::CRITICAL,
                                                   i18n("Used %1 version %2 is outdated",QString("growisofs"),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.",QString("growisofs")) ) );
            }
            else if( k3bcore->externalBinManager()->binObject( "growisofs" )->version < K3b::Version( 5, 12 ) ) {
                problems.append( K3b::SystemProblem( K3b::SystemProblem::NON_CRITICAL,
                                                   i18n("Used %1 version %2 is outdated",QString("growisofs"),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.",QString("growisofs")) ) );
            }
            else if( k3bcore->externalBinManager()->binObject( "growisofs" )->version < K3b::Version( 7, 0 ) ) {
                problems.append( K3b::SystemProblem( K3b::SystemProblem::NON_CRITICAL,
                                                   i18n("Used %1 version %2 is outdated",QString("growisofs"),k3bcore->externalBinManager()->binObject( "growisofs" )->version),
                                                   i18n("It is highly recommended to use growisofs 7.0 or higher. "
                                                        "K3b will not 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.",QString("growisofs")) ) );
            }
//            // for now we ignore the suid root bit becasue of the memorylocked issue
//            else if( !k3bcore->externalBinManager()->binObject( "growisofs" )->hasFeature( "suidroot" ) ) {
//                showK3bSetupButton = true;
//                problems.append( K3b::SystemProblem( K3b::SystemProblem::CRITICAL,
//                                                     i18n("%1 will be run without root privileges","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."),
//                                                     k3bSetupSolutionText ) );
//            }
        }

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

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

    }
    else if( k3bcore->externalBinManager()->binObject( "mkisofs" )->hasFeature( "outdated" ) ) {
        problems.append( K3b::SystemProblem( K3b::SystemProblem::CRITICAL,
                                           i18n("Used %1 version %2 is outdated",
                                                QString("mkisofs"),
                                                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.",QString("mkisofs")) ) );
    }

    // 2. device check
#ifdef __GNUC__
#warning Make sure we have a proper new kernel and cdrecord for simple dev= stuff
#endif
    bool atapiWriter = false;
    bool dvd_r_dl = false;
    QList<K3b::Device::Device *> items(k3bcore->deviceManager()->readingDevices());
    for( QList<K3b::Device::Device *>::const_iterator it = items.constBegin();
         it != items.constEnd(); ++it ) {
        if( (*it)->type() & K3b::Device::DEVICE_DVD_R_DL )
            dvd_r_dl = true;
    }

#ifndef Q_OS_WIN32
    // check automounted devices
    QList<K3b::Device::Device*> automountedDevices = checkForAutomounting();
    for( QList<K3b::Device::Device *>::const_iterator it = automountedDevices.constBegin();
         it != automountedDevices.constEnd(); ++it ) {
        problems.append( K3b::SystemProblem( K3b::SystemProblem::NON_CRITICAL,
                                           i18n("Device %1 - %2 is automounted.",
                                                (*it)->vendor(),(*it)->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.") ) );
    }

#endif
    if( atapiWriter ) {
        if( !K3b::plainAtapiSupport() &&
            !K3b::hackedAtapiSupport() ) {
            problems.append( K3b::SystemProblem( K3b::SystemProblem::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 will not have any problems. "
                                                    "Be aware that you may still enable DMA on ide-scsi "
                                                    "emulated drives.") ) );
        }
        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( K3b::SystemProblem( K3b::SystemProblem::CRITICAL,
                                                       i18n("%1 %2 does not support ATAPI",QString("cdrecord"),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.",QString("cdrecord")),
                                                       i18n("The best and recommended solution is to enable "
                                                            "ide-scsi (SCSI emulation) for all devices. "
                                                            "This way you will not have any problems. Or you install "
                                                            "(or select as the default) a more recent version of %1.",QString("cdrtools")) ) );
                }
            }

            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( K3b::SystemProblem( K3b::SystemProblem::CRITICAL,
                                                       i18n("%1 %2 does not support ATAPI",
                                                            QLatin1String( "cdrdao"),
                                                            k3bcore->externalBinManager()->binObject("cdrdao")->version.toString() ),
                                                       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.", QLatin1String( "cdrdao" ) ),
                                                       K3b::simpleKernelVersion() > K3b::Version( 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.",
                                                              QString("cdrdao")) ) );
                }
            }
        }
    }

    if( dvd_r_dl && k3bcore->externalBinManager()->foundBin( "growisofs" ) ) {
        if( k3bcore->externalBinManager()->binObject( "growisofs" )->version < K3b::Version( 6, 0 ) ) {
            problems.append( K3b::SystemProblem( K3b::SystemProblem::NON_CRITICAL,
                                               i18n("Used %1 version %2 is outdated",QString("growisofs"),k3bcore->externalBinManager()->binObject( "growisofs" )->version),
                                               i18n("K3b will not 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.") ) );
        }
    }

    QList<K3b::Device::Device *> items2(k3bcore->deviceManager()->allDevices());
    for( QList<K3b::Device::Device *>::const_iterator it = items2.constBegin();
         it != items2.constEnd(); ++it ) {
        K3b::Device::Device* dev = (*it);
#ifndef Q_OS_WIN32
        if( !QFileInfo( dev->blockDeviceName() ).isWritable() ) {
            showK3bSetupButton = true;
            problems.append( K3b::SystemProblem( K3b::SystemProblem::CRITICAL,
                                               i18n("No write access to device %1",dev->blockDeviceName()),
                                               i18n("K3b needs write access to all the devices to perform certain tasks. "
                                                    "Without it you might encounter problems with %1 - %2",dev->vendor(),dev->description()),
                                               i18n("Make sure you have write access to %1. In case you are not using "
                                                    "devfs or udev click \"Modify Permissions...\" and setup permissions by hand.",dev->blockDeviceName()) ) );
        }

        if( !dmaActivated( dev ) ) {
            problems.append( K3b::SystemProblem( K3b::SystemProblem::CRITICAL,
                                               i18n("DMA disabled on device %1 - %2",dev->vendor(),dev->description()),
                                               i18n("With most modern CD/DVD/BD 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'.",dev->blockDeviceName()) ) );
        }
#endif
    }


    //
    // Check if the user specified some user parameters and warn about it
    //
    const QMap<QString, K3b::ExternalProgram*>& programMap = k3bcore->externalBinManager()->programs();
    for( QMap<QString, K3b::ExternalProgram*>::const_iterator it = programMap.constBegin();
         it != programMap.constEnd(); ++it ) {
        const K3b::ExternalProgram* p = *it;
        if( !p->userParameters().isEmpty() ) {
            problems.append( K3b::SystemProblem( K3b::SystemProblem::WARNING,
                                               i18n("User parameters specified for external program %1",p->name()),
                                               i18n("Sometimes it may be necessary 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 will not 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'."
                                                    ,p->name()) ) );
        }
    }

    //
    // 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
    //
/*
    QList<K3b::Plugin*> plugins = k3bcore->pluginManager()->plugins( "AudioDecoder" );
    bool haveMp3Decoder = false;
    for( QList<K3b::Plugin*>::const_iterator it = plugins.constBegin();
         it != plugins.constEnd(); ++it ) {
        if( (*it)->pluginInfo().pluginName() == "k3bmaddecoder" ) {
            haveMp3Decoder = true;
            break;
        }
    }
    if( !haveMp3Decoder ) {
        problems.append( K3b::SystemProblem( K3b::SystemProblem::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). To get MP3 support, please install the package libk3b6-extracodecs.") ) );
    }
*/

#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( K3b::SystemProblem( K3b::SystemProblem::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.") ) );
    }
#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 ) {
        showK3bSetupButton = true;
        problems.append( K3b::SystemProblem( K3b::SystemProblem::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 BUILD_K3BSETUP
                                           + ' ' + i18n("The latter can be done via \"Modify Permissions...\".")
#endif
                                           ) );
    }


    kDebug() << "(K3b::Core) System problems:";
    for( QList<K3b::SystemProblem>::const_iterator it = problems.constBegin();
         it != problems.constEnd(); ++it ) {
        const K3b::SystemProblem& p = *it;

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

    }
    if( problems.isEmpty() ) {
        kDebug() << "          - none - ";
        if( level == AlwaysNotify ) {
//            K3b::PassivePopup::showPopup( i18n("No problems found in system configuration."), i18n("System configured properly") );
        }
    }
    else {
        static K3b::SystemProblemDialog* s_openDlg = 0;
        if( s_openDlg )
            s_openDlg->close();
        K3b::SystemProblemDialog dlg( problems, showK3bSetupButton, parent );
        s_openDlg = &dlg;
        dlg.exec();
        s_openDlg = 0;
    }

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

void K3b::SystemProblemDialog::slotK3bSetup()
{
    QStringList args;
    args << "k3bsetup" << "--lang" << KGlobal::locale()->language();
    if( !KProcess::startDetached( K3b::findExe("kcmshell4"), args ) )
        KMessageBox::error( 0, i18n("Unable to start K3b::Setup.") );
}


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

    KProcess p;
    p.setOutputChannelMode( KProcess::MergedChannels );

    p << hdparm << "-d" << dev->blockDeviceName();
    p.start();
    if( !p.waitForFinished( -1 ) )
        return -1;

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


#ifndef Q_OS_WIN32
QList<K3b::Device::Device*> K3b::SystemProblemDialog::checkForAutomounting()
{
    QList<K3b::Device::Device *> l;
    ::setfsent();

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

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

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

    ::endfsent();
    return l;
}
#endif


bool K3b::SystemProblemDialog::readCheckSystemConfig()
{
    KConfigGroup cfgGrp( KGlobal::config(), "General Options" );

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

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

#include "k3bsystemproblemdialog.moc"