~ubuntu-branches/ubuntu/utopic/kde-workspace/utopic-proposed

« back to all changes in this revision

Viewing changes to kinfocenter/Modules/base/info_linux.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michał Zając
  • Date: 2011-07-09 08:31:15 UTC
  • Revision ID: james.westby@ubuntu.com-20110709083115-ohyxn6z93mily9fc
Tags: upstream-4.6.90
Import upstream version 4.6.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
/*
 
3
Copyright 1998  Helge Deller deller@gmx.de
 
4
 
 
5
This program is free software; you can redistribute it and/or
 
6
modify it under the terms of the GNU General Public License as
 
7
published by the Free Software Foundation; either version 2 of
 
8
the License or (at your option) version 3 or any later version
 
9
accepted by the membership of KDE e.V. (or its successor approved
 
10
by the membership of KDE e.V.), which shall act as a proxy 
 
11
defined in Section 14 of version 3 of the license.
 
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, see <http://www.gnu.org/licenses/>.
 
20
*/
 
21
 
 
22
#include <unistd.h>
 
23
#include <syscall.h>
 
24
#include <stdio.h>
 
25
#include <sys/stat.h>
 
26
#include <linux/kernel.h>
 
27
#include <ctype.h>
 
28
#include "config-infocenter.h"
 
29
 
 
30
#ifdef HAVE_PCIUTILS
 
31
#include "kpci.h"
 
32
#endif //HAVE_PCIUTILS
 
33
#include <QRegExp>
 
34
#include <QFile>
 
35
#include <QHeaderView>
 
36
 
 
37
#include <klocale.h>
 
38
#include <kiconloader.h>
 
39
#include <kglobalsettings.h>
 
40
#include <kdebug.h>
 
41
 
 
42
#define INFO_IRQ "/proc/interrupts"
 
43
#define INFO_DMA "/proc/dma"
 
44
 
 
45
#define INFO_PCI "/proc/pci"
 
46
 
 
47
#define INFO_IOPORTS "/proc/ioports"
 
48
 
 
49
#define INFO_MISC "/proc/misc"
 
50
 
 
51
#define INFO_SCSI "/proc/scsi/scsi"
 
52
 
 
53
#define MAXCOLUMNWIDTH 600
 
54
 
 
55
bool GetInfo_ReadfromFile(QTreeWidget* tree, const char *FileName, const QChar& splitChar) {
 
56
        bool added = false;
 
57
        QFile file(FileName);
 
58
 
 
59
        if (!file.exists()) {
 
60
                return false;
 
61
        }
 
62
 
 
63
        if (!file.open(QIODevice::ReadOnly)) {
 
64
                return false;
 
65
        }
 
66
        QTextStream stream(&file);
 
67
 
 
68
        QString line = stream.readLine();
 
69
 
 
70
        while (!line.isNull()) {
 
71
                QString s1, s2;
 
72
                if (!line.isEmpty()) {
 
73
                        if (!splitChar.isNull()) {
 
74
                                int pos = line.indexOf(splitChar);
 
75
                                s1 = line.left(pos-1).trimmed();
 
76
                                s2 = line.mid(pos+1).trimmed();
 
77
                        } else
 
78
                                s1 = line;
 
79
                }
 
80
                QStringList list;
 
81
                list << s1 << s2;
 
82
                new QTreeWidgetItem(tree, list);
 
83
                added = true;
 
84
                line = stream.readLine();
 
85
        }
 
86
 
 
87
        file.close();
 
88
 
 
89
        return added;
 
90
}
 
91
 
 
92
bool GetInfo_IRQ(QTreeWidget* tree) {
 
93
        tree->setFont(KGlobalSettings::fixedFont());
 
94
        tree->setHeaderHidden(true);
 
95
        
 
96
        return GetInfo_ReadfromFile(tree, INFO_IRQ, 0);
 
97
}
 
98
 
 
99
bool GetInfo_DMA(QTreeWidget* tree) {
 
100
        QFile file(INFO_DMA);
 
101
 
 
102
        QStringList headers;
 
103
        headers << i18n("DMA-Channel") << i18n("Used By");
 
104
        tree->setHeaderLabels(headers);
 
105
 
 
106
        if (file.exists() && file.open(QIODevice::ReadOnly)) {
 
107
                QTextStream stream(&file);
 
108
                QString line;
 
109
 
 
110
                line = stream.readLine();
 
111
                while (!line.isNull()) {
 
112
                        if (!line.isEmpty()) {
 
113
                                QRegExp rx("^\\s*(\\S+)\\s*:\\s*(\\S+)");
 
114
                                if (-1 != rx.indexIn(line)) {
 
115
                                        QStringList list;
 
116
                                        list << rx.cap(1) << rx.cap(2);
 
117
                                        new QTreeWidgetItem(tree, list);
 
118
                                }
 
119
                        }
 
120
                        line = stream.readLine();
 
121
                }
 
122
                file.close();
 
123
        } else {
 
124
                return false;
 
125
        }
 
126
 
 
127
        return true;
 
128
}
 
129
 
 
130
bool GetInfo_PCI(QTreeWidget* tree) {
 
131
        int num;
 
132
 
 
133
#ifdef HAVE_PCIUTILS
 
134
        if ( (num = GetInfo_PCIUtils(tree))) {
 
135
                return num;
 
136
        }
 
137
        
 
138
#endif //HAVE_PCIUTILS
 
139
        tree->setHeaderHidden(true);
 
140
        tree->setSortingEnabled(false);
 
141
 
 
142
        /* try to get the output of the lspci package first */
 
143
        if ((num = GetInfo_ReadfromPipe(tree, "lspci -v", true)) || (num = GetInfo_ReadfromPipe(tree, "/sbin/lspci -v", true)) || (num = GetInfo_ReadfromPipe(tree, "/usr/sbin/lspci -v", true)) || (num = GetInfo_ReadfromPipe(tree, "/usr/local/sbin/lspci -v", true)) || (num = GetInfo_ReadfromPipe(tree,
 
144
                        "/usr/bin/lspci -v", true)))
 
145
                return num;
 
146
 
 
147
        /* if lspci failed, read the contents of /proc/pci */
 
148
        return GetInfo_ReadfromFile(tree, INFO_PCI, 0);
 
149
 
 
150
}
 
151
 
 
152
bool GetInfo_IO_Ports(QTreeWidget* tree) {
 
153
        QStringList headers;
 
154
        headers << i18n("I/O-Range") << i18n("Used By");
 
155
        tree->setHeaderLabels(headers);
 
156
        return GetInfo_ReadfromFile(tree, INFO_IOPORTS, ':');
 
157
}
 
158
 
 
159
bool GetInfo_SCSI(QTreeWidget* tree) {
 
160
        return GetInfo_ReadfromFile(tree, INFO_SCSI, 0);
 
161
}
 
162
 
 
163
static void cleanPassword(QString & str) {
 
164
        int index = 0;
 
165
        QString passwd("password=");
 
166
 
 
167
        while (index >= 0) {
 
168
                index = str.indexOf(passwd, index, Qt::CaseInsensitive);
 
169
                if (index >= 0) {
 
170
                        index += passwd.length();
 
171
                        while (index < (int) str.length() && str[index] != ' ' && str[index] != ',')
 
172
                                str[index++] = '*';
 
173
                }
 
174
        }
 
175
}
 
176
 
 
177
bool GetInfo_XServer_and_Video(QTreeWidget* tree) {
 
178
        return GetInfo_XServer_Generic(tree);
 
179
}