/* * Copyright (C) 2007 Petri Damsten * Copyright (C) 2010 Michel Lafon-Puyo * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License version 2 as * published by the Free Software Foundation * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details * * You should have received a copy of the GNU Library General Public * License along with this program; if not, write to the * Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "hwinfo.h" #include #include #include #include #include #include #include #include #include #define START "" #define START_BASIC "" #define START_TABLE "" #define INFO_ROW "" #define END_TABLE "
%1:%2
" #define END "" HWInfo::HWInfo(QObject *parent, const QVariantList &args) : SM::Applet(parent, args), m_info(0), m_icon(0) { resize(234 + 20 + 23, 135 + 20 + 25); setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); connect(Plasma::Theme::defaultTheme(), SIGNAL(themeChanged()), this, SLOT(updateHtml())); } HWInfo::~HWInfo() { } void HWInfo::init() { KGlobal::locale()->insertCatalog("plasma_applet_system-monitor"); setTitle(i18n("Hardware Info")); setEngine(dataEngine("soliddevice")); setSources(); connectToEngine(); } bool HWInfo::addVisualization(const QString& source) { if (mode() != SM::Applet::Panel) { if (!m_info) { m_info = new Plasma::TextBrowser(this); m_info->nativeWidget()->setHtml(QString(START + i18n("Getting hardware information...") + END)); appendVisualization(source, m_info); //m_info->nativeWidget()->document()->setTextWidth(contentsRect().width()); //setPreferredItemHeight(m_info->nativeWidget()->document()->size().height()); setPreferredItemHeight(135); } } else { if (!m_icon) { m_icon = new Plasma::IconWidget(KIcon(icon()), "", this); appendVisualization(source, m_icon); } } return true; } void HWInfo::deleteVisualizations() { SM::Applet::deleteVisualizations(); m_icon = 0; m_info = 0; } void HWInfo::setSources() { m_cpus = engine()->query("IS Processor")["IS Processor"].toStringList(); foreach (const QString& id, m_cpus) { appendSource(id); } m_networks = engine()->query("IS NetworkInterface")["IS NetworkInterface"].toStringList(); foreach (const QString& id, m_networks) { appendSource(id); } m_audios = engine()->query("IS AudioInterface")["IS AudioInterface"].toStringList(); foreach (const QString& id, m_audios) { appendSource(id); } m_gpus = engine()->query("IS Graphic")["IS Graphic"].toStringList(); foreach (const QString& id, m_gpus) { appendSource(id); } } void HWInfo::dataUpdated(const QString& source, const Plasma::DataEngine::Data &data) { if (m_audios.contains(source) && !m_audioNames.contains(data["Name"].toString()) && !data["Name"].toString().isEmpty()) { m_audioNames.append(data["Name"].toString()); } else if (m_networks.contains(source) && !m_networkNames.contains(data["Product"].toString()) && !data["Product"].toString().isEmpty()) { m_networkNames.append(data["Product"].toString()); } else if (m_cpus.contains(source) && !m_cpuNames.contains(data["Product"].toString()) && !data["Product"].toString().isEmpty()) { m_cpuNames.append(data["Product"].toString().trimmed()); } else if (m_gpus.contains(source) && !m_gpuNames.contains(data["Product"].toString()) && !data["Product"].toString().isEmpty()) { m_gpuNames.append(data["Product"].toString()); } updateHtml(); } void HWInfo::updateHtml() { QString html; foreach(const QString& cpu, m_cpuNames) { html += QString(INFO_ROW).arg(i18n("CPU")).arg(cpu); } foreach(const QString& gpu, m_gpuNames) { html += QString(INFO_ROW).arg(i18n("GPU")).arg(gpu); } foreach(const QString& audio, m_audioNames) { html += QString(INFO_ROW).arg(i18n("Audio")).arg(audio); } foreach(const QString& network, m_networkNames) { html += QString(INFO_ROW).arg(i18n("Network")).arg(network); } html += END_TABLE END; if (m_info) { Plasma::Theme* theme = Plasma::Theme::defaultTheme(); html = QString(START START_TABLE) .arg(theme->color(Plasma::Theme::TextColor).name()) + html; m_info->nativeWidget()->setHtml(html); } else if (m_icon) { html = START_BASIC START_TABLE + html; Plasma::ToolTipContent data(i18n("Hardware Info"), html); Plasma::ToolTipManager::self()->setContent(m_icon, data); } } #include "moc_hwinfo.cpp"