2 * Copyright (C) 2007 Petri Damsten <damu@iki.fi>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Library General Public License version 2 as
6 * published by the Free Software Foundation
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details
13 * You should have received a copy of the GNU Library General Public
14 * License along with this program; if not, write to the
15 * Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 #include <Plasma/WebView>
21 #include <Plasma/IconWidget>
22 #include <Plasma/Containment>
23 #include <Plasma/ToolTipManager>
24 #include <Plasma/Theme>
25 #include <KStandardDirs>
28 #include <QTextDocument>
29 #include <QGraphicsLinearLayout>
31 #define START "<html><head><style type=\"text/css\">\
32 body { background-color: %1; } \
33 td { vertical-align: top; font-size:7pt; font-weight:normal; font-style:normal; color: %2; } \
34 </style></head><body>"
35 #define START_BASIC "<html><head></head><body>"
36 #define START_TABLE "<table>"
37 #define INFO_ROW "<tr><td>%1:</td><td>%2</td></tr>"
38 #define END_TABLE "</table>"
39 #define END "</body><html>"
41 HWInfo::HWInfo(QObject
*parent
, const QVariantList
&args
)
42 : SM::Applet(parent
, args
), m_info(0), m_icon(0)
44 setHasConfigurationInterface(false);
45 resize(234 + 20 + 23, 135 + 20 + 25);
46 setSizePolicy(QSizePolicy::Preferred
, QSizePolicy::Preferred
);
47 connect(Plasma::Theme::defaultTheme(), SIGNAL(themeChanged()), this, SLOT(updateHtml()));
56 setTitle(i18n("Hardware Info"));
61 bool HWInfo::addMeter(const QString
&)
63 if (mode() != SM::Applet::Panel
) {
64 m_info
= new Plasma::WebView(this);
65 m_info
->setHtml(QString(START
+ i18n("Getting hardware information...") + END
));
67 mainLayout()->addItem(m_info
);
68 //m_info->nativeWidget()->document()->setTextWidth(contentsRect().width());
69 //setPreferredItemHeight(m_info->nativeWidget()->document()->size().height());
70 setPreferredItemHeight(135);
72 m_icon
= new Plasma::IconWidget(KIcon("hwinfo"), QString(), this);
74 mainLayout()->addItem(m_icon
);
79 void HWInfo::connectToEngine()
81 Applet::connectToEngine();
82 setEngine(dataEngine("soliddevice"));
84 m_cpus
= engine()->query("IS Processor")["IS Processor"].toStringList();
85 foreach (const QString
& id
, m_cpus
) {
86 engine()->connectSource(id
, this);
88 m_networks
= engine()->query("IS NetworkInterface")["IS NetworkInterface"].toStringList();
89 foreach (const QString
& id
, m_networks
) {
90 engine()->connectSource(id
, this);
92 m_audios
= engine()->query("IS AudioInterface")["IS AudioInterface"].toStringList();
93 foreach (const QString
& id
, m_audios
) {
94 engine()->connectSource(id
, this);
96 // TODO: get this from soliddevice
97 Plasma::DataEngine
* engine
= dataEngine("executable");
98 QString path
= QString::fromLocal8Bit(getenv("PATH")) + QString::fromLatin1(":/usr/sbin:/sbin/");
99 QString exe
= KStandardDirs::findExe( "lspci", path
);
101 kError() << "lspci not found in " << path
<< endl
;
104 QString tmp
= exe
+ " | grep VGA | sed 's/.*: //g'";
105 engine
->connectSource(tmp
, this);
109 void HWInfo::dataUpdated(const QString
& source
,
110 const Plasma::DataEngine::Data
&data
)
112 if (m_audios
.contains(source
) && !m_audioNames
.contains(data
["Name"].toString()) &&
113 !data
["Name"].toString().isEmpty()) {
114 m_audioNames
.append(data
["Name"].toString());
115 } else if (m_networks
.contains(source
) && !m_networkNames
.contains(data
["Product"].toString()) &&
116 !data
["Product"].toString().isEmpty()) {
117 m_networkNames
.append(data
["Product"].toString());
118 } else if (m_cpus
.contains(source
) && !m_cpuNames
.contains(data
["Product"].toString()) &&
119 !data
["Product"].toString().isEmpty()) {
120 m_cpuNames
.append(data
["Product"].toString().trimmed());
121 } else if (source
.indexOf("VGA") > -1) {
122 m_gpu
= data
["stdout"].toString().trimmed();
127 void HWInfo::updateHtml()
130 foreach(const QString
& cpu
, m_cpuNames
) {
131 html
+= QString(INFO_ROW
).arg(i18n("CPU")).arg(cpu
);
133 html
+= QString(INFO_ROW
).arg(i18n("GPU")).arg(m_gpu
);
134 foreach(const QString
& audio
, m_audioNames
) {
135 html
+= QString(INFO_ROW
).arg(i18n("Audio")).arg(audio
);
137 foreach(const QString
& network
, m_networkNames
) {
138 html
+= QString(INFO_ROW
).arg(i18n("Network")).arg(network
);
140 html
+= END_TABLE END
;
142 Plasma::Theme
* theme
= Plasma::Theme::defaultTheme();
143 html
= QString(START START_TABLE
)
144 .arg(theme
->color(Plasma::Theme::BackgroundColor
).name())
145 .arg(theme
->color(Plasma::Theme::TextColor
).name()) + html
;
146 m_info
->setHtml(html
);
148 html
= START_BASIC START_TABLE
+ html
;
149 Plasma::ToolTipContent
data(i18n("Hardware Info"), html
);
150 Plasma::ToolTipManager::self()->setContent(m_icon
, data
);
154 #include "hwinfo.moc"