/*************************************************************************** * Copyright (C) 2006 by Ken Werner * * ken.werner@web.de * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * 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 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 "uptimesrc.h" #include #include UptimeSrc::UptimeSrc(QWidget* inParent, const QFile& inSourceFile): LabelSource(inParent), mSourceFile(inSourceFile.name()), mTrigger(this, 30000){ // 30 seconds mEnabled = false; // disable this source by default to to save kicker space mID = "Uptime"; mName = mID; mDescription = i18n("This source is provided by /proc/uptime."); } UptimeSrc::~UptimeSrc(){ } std::listUptimeSrc::createInstances(QWidget* inParent){ std::list list; QFile uptimeFile("/proc/uptime" ); if(uptimeFile.open(IO_ReadOnly)) list.push_back(new UptimeSrc(inParent, uptimeFile)); return list; } QString UptimeSrc::fetchValue(){ QString s = "n/a"; int secs; if(mSourceFile.open(IO_ReadOnly)) { QTextStream stream( &mSourceFile ); stream >> secs; //QString seconds = QString::number(secs % 60).rightJustify(2, '0'); QString minutes = QString::number(secs / 60 % 60).rightJustify(2, '0'); QString hours = QString::number(secs / 3600 % 24).rightJustify(2, '0'); QString days = QString::number(secs / 86400); if(days != "0") s = mTimeFormatLong.arg(days).arg(hours).arg(minutes); else s = mTimeFormatShort.arg(hours).arg(minutes); mSourceFile.close(); } return s; } void UptimeSrc::realizeWidget() { LabelSource::realizeWidget(); mTimeFormatLong = i18n("%1d %2:%3"); mTimeFormatShort = i18n("%1:%2"); }