Fix crash if key bindings specified in profile cannot be found. Improve
[personal-kdebase.git] / apps / kinfocenter / info / info.cpp
blobc9d5256402bd5b46fbbcd239792e0f4107c4ae86
1 /*
2 Main Widget for showing system-dependent information.
3 (But all functions in THIS FILE should be system independent !)
5 (C) 1998-2003 by Helge Deller <deller@kde.org>
7 */
9 #include "info.h"
11 #include <QLayout>
12 #include <QProcess>
13 #include <QLabel>
14 #include <QHBoxLayout>
15 #include <QTextStream>
16 #include <QHeaderView>
18 #include <kglobalsettings.h>
19 #include <kiconloader.h>
20 #include <kdialog.h>
21 #include <klocale.h>
22 #include <kdebug.h>
24 KInfoListWidget::KInfoListWidget(const KComponentData &inst, const QString &_title, QWidget *parent, bool _getlistbox(QTreeWidget *tree) ) :
25 KCModule(inst, parent), title(_title) {
26 KAboutData *about = new KAboutData("kcminfo", 0,
27 ki18n("KDE Panel System Information Control Module"),
28 0, KLocalizedString(), KAboutData::License_GPL,
29 ki18n( "(c) 2008 Nicolas Ternisien\n"
30 "(c) 1998 - 2002 Helge Deller"));
32 about->addAuthor(ki18n("Nicolas Ternisien"), KLocalizedString(), "nicolas.ternisien@gmail.com");
33 about->addAuthor(ki18n("Helge Deller"), KLocalizedString(), "deller@kde.org");
34 setAboutData(about);
36 kDebug() << "Constructing a KInfoListWidget..." << endl;
38 //setButtons(KCModule::Help);
39 getlistbox = _getlistbox;
40 QHBoxLayout *layout = new QHBoxLayout(this);
41 layout->setSpacing(KDialog::spacingHint());
42 layout->setMargin(0);
43 widgetStack = new QStackedWidget(this);
44 layout->addWidget(widgetStack);
46 tree = new QTreeWidget(widgetStack);
47 widgetStack->addWidget(tree);
48 tree->setMinimumSize(200, 120);
49 tree->setFont(KGlobalSettings::generalFont()); /* default font */
50 tree->setSortingEnabled(true);
51 tree->setRootIsDecorated(false);
52 tree->header()->setSortIndicatorShown(true);
53 tree->setWhatsThis(i18n("This list displays system information on the selected category.") );
55 noInfoText = new QLabel(widgetStack);
56 widgetStack->addWidget(noInfoText);
57 noInfoText->setAlignment(Qt::AlignCenter);
58 noInfoText->setWordWrap( true);
59 widgetStack->setCurrentWidget(noInfoText);
63 void KInfoListWidget::load() {
64 kDebug() << "Loading KInfoListWidget..." << endl;
66 //TODO Remove tree content before clear it
67 tree->clear();
69 errorString = i18nc("%1 is one of the modules of the kinfocenter, cpu info, os info, etc", "No information available about %1.", title) + QLatin1String("\n\n") + DEFAULT_ERRORSTRING;
71 /* No Sorting per default */
72 tree->setSortingEnabled(false);
74 bool ok = false;
75 /* retrieve the information */
76 if (getlistbox) {
77 ok = (*getlistbox)(tree);
80 /* set default title */
81 if (tree->headerItem()->columnCount()<=1) {
82 QStringList headers;
83 headers << title;
84 tree->setHeaderLabels(headers);
87 if (ok) {
88 widgetStack->setCurrentWidget(tree);
89 } else {
90 noInfoText->setText(errorString);
91 widgetStack->setCurrentWidget(noInfoText);
94 tree->resizeColumnToContents(0);
96 emit changed(false);
99 QString KInfoListWidget::quickHelp() const {
100 return i18n("All the information modules return information about a certain"
101 " aspect of your computer hardware or your operating system.");