• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

Engines

hddtemp.cpp

Go to the documentation of this file.
00001 /*
00002  *   Copyright (C) 2007 Petri Damsten <damu@iki.fi>
00003  *   Copyright (C) 2007 Christopher Blauvelt <cblauvelt@gmail.com>
00004  *
00005  *   This program is free software; you can redistribute it and/or modify
00006  *   it under the terms of the GNU Library General Public License version 2 as
00007  *   published by the Free Software Foundation
00008  *
00009  *   This program is distributed in the hope that it will be useful,
00010  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *   GNU General Public License for more details
00013  *
00014  *   You should have received a copy of the GNU Library General Public
00015  *   License along with this program; if not, write to the
00016  *   Free Software Foundation, Inc.,
00017  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00018  */
00019 
00020 #include "hddtemp.h"
00021 
00022 #include <QTcpSocket>
00023 
00024 #include <KDebug>
00025 
00026 HddTemp::HddTemp(QObject* parent)
00027     : QObject(parent),
00028       m_failCount(0),
00029       m_timer(0)
00030 {
00031     updateData();
00032     m_timer = new QTimer(this);
00033     connect(m_timer, SIGNAL(timeout()), this, SLOT(updateData()));
00034     m_timer->start(10000);
00035 }
00036 
00037 HddTemp::~HddTemp()
00038 {
00039 }
00040 
00041 QStringList HddTemp::sources() const
00042 {
00043     return m_data.keys();
00044 }
00045 
00046 bool HddTemp::updateData()
00047 {
00048     if (m_failCount > 4) {
00049         return false;
00050     }
00051     QTcpSocket socket;
00052     QString data;
00053 
00054     socket.connectToHost("localhost", 7634);
00055     if (socket.waitForConnected(500)) {
00056         while (data.length() < 1024) {
00057             if (!socket.waitForReadyRead(500)) {
00058                 if (data.length() > 0) {
00059                     break;
00060                 } else {
00061                     //kDebug() << socket.errorString();
00062                     return false;
00063                 }
00064             }
00065             data += QString(socket.readAll());
00066         }
00067         socket.disconnectFromHost();
00068         //on success retry fail count
00069         m_failCount = 0;
00070     } else {
00071         m_failCount++;
00072         //kDebug() << socket.errorString();
00073         return false;
00074     }
00075     QStringList list = data.split('|');
00076     int i = 1;
00077     m_data.clear();
00078     while (i + 4 < list.size()) {
00079         m_data[list[i]].append(list[i + 2]);
00080         m_data[list[i]].append(list[i + 3]);
00081         i += 5;
00082     }
00083     return true;
00084 }
00085 
00086 QVariant HddTemp::data(const QString source, const DataType type) const
00087 {
00088     return m_data[source][type];
00089 }
00090 
00091 #include "hddtemp.moc"

Engines

Skip menu "Engines"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members

API Reference

Skip menu "API Reference"
  • KWin
  •   KWin Libraries
  • Libraries
  •   libkworkspace
  •   libsolidcontrol
  •   libtaskmanager
  • Plasma
  •   Animators
  •   Applets
  •   Engines
  • Solid Modules
Generated for API Reference by doxygen 1.5.7
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal