-rw-r--r-- | core/applets/batteryapplet/.cvsignore | 3 | ||||
-rw-r--r-- | core/applets/batteryapplet/Makefile.in | 122 | ||||
-rw-r--r-- | core/applets/batteryapplet/battery.cpp | 152 | ||||
-rw-r--r-- | core/applets/batteryapplet/battery.h | 55 | ||||
-rw-r--r-- | core/applets/batteryapplet/batteryapplet.pro | 12 | ||||
-rw-r--r-- | core/applets/batteryapplet/batteryappletimpl.cpp | 63 | ||||
-rw-r--r-- | core/applets/batteryapplet/batteryappletimpl.h | 44 | ||||
-rw-r--r-- | core/applets/batteryapplet/batterystatus.cpp | 140 | ||||
-rw-r--r-- | core/applets/batteryapplet/batterystatus.h | 45 | ||||
-rw-r--r-- | core/applets/batteryapplet/qpe-batteryapplet.control | 9 | ||||
-rwxr-xr-x | core/applets/batteryapplet/qpe-batteryapplet.postinst | 2 | ||||
-rwxr-xr-x | core/applets/batteryapplet/qpe-batteryapplet.postrm | 2 |
12 files changed, 649 insertions, 0 deletions
diff --git a/core/applets/batteryapplet/.cvsignore b/core/applets/batteryapplet/.cvsignore new file mode 100644 index 0000000..edfa921 --- a/dev/null +++ b/core/applets/batteryapplet/.cvsignore @@ -0,0 +1,3 @@ +moc_* +*.moc +Makefile diff --git a/core/applets/batteryapplet/Makefile.in b/core/applets/batteryapplet/Makefile.in new file mode 100644 index 0000000..0493fd6 --- a/dev/null +++ b/core/applets/batteryapplet/Makefile.in @@ -0,0 +1,122 @@ +############################################################################# + +####### Compiler, tools and options + +CXX = $(SYSCONF_CXX) $(QT_CXX_MT) +CXXFLAGS= $(SYSCONF_CXXFLAGS_QT) $(SYSCONF_CXXFLAGS) $(SYSCONF_CXXFLAGS_LIB) +CC = $(SYSCONF_CC) $(QT_C_MT) +CFLAGS = $(SYSCONF_CFLAGS) $(SYSCONF_CFLAGS_LIB) +INCPATH = -I$(QPEDIR)/include +LFLAGS = $(SYSCONF_LFLAGS_QT) $(SYSCONF_RPATH_QT) $(SYSCONF_LFLAGS) $(QT_LFLAGS_MT) +LIBS = $(SUBLIBS) -lqpe $(SYSCONF_LIBS_QT) $(SYSCONF_LIBS_QTAPP) +MOC = $(SYSCONF_MOC) +UIC = $(SYSCONF_UIC) + +####### Target + +DESTDIR = ../../plugins/applets/ +VER_MAJ = 1 +VER_MIN = 0 +VER_PATCH = 0 +TARGET = batteryapplet +TARGET1 = lib$(TARGET).so.$(VER_MAJ) + +####### Files + +HEADERS = battery.h \ + batterystatus.h \ + batteryappletimpl.h +SOURCES = battery.cpp \ + batterystatus.cpp \ + batteryappletimpl.cpp +OBJECTS = battery.o \ + batterystatus.o \ + batteryappletimpl.o +INTERFACES = +UICDECLS = +UICIMPLS = +SRCMOC = moc_battery.cpp +OBJMOC = moc_battery.o + + +####### Implicit rules + +.SUFFIXES: .cpp .cxx .cc .C .c + +.cpp.o: + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $< + +.cxx.o: + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $< + +.cc.o: + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $< + +.C.o: + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $< + +.c.o: + $(CC) -c $(CFLAGS) $(INCPATH) -o $@ $< + +####### Build rules + + +all: $(DESTDIR)$(SYSCONF_LINK_TARGET) + +$(DESTDIR)$(SYSCONF_LINK_TARGET): $(UICDECLS) $(OBJECTS) $(OBJMOC) $(SUBLIBS) + $(SYSCONF_LINK_LIB) + +moc: $(SRCMOC) + +tmake: + tmake batteryapplet.pro + +clean: + -rm -f $(OBJECTS) $(OBJMOC) $(SRCMOC) $(UICIMPLS) $(UICDECLS) + -rm -f *~ core + -rm -f allmoc.cpp + +####### Extension Modules + +listpromodules: + @echo + +listallmodules: + @echo + +listaddonpromodules: + @echo + +listaddonentmodules: + @echo + + +REQUIRES= + +####### Sub-libraries + + +###### Combined headers + + + +####### Compile + +battery.o: battery.cpp \ + battery.h \ + batterystatus.h + +batterystatus.o: batterystatus.cpp \ + batterystatus.h + +batteryappletimpl.o: batteryappletimpl.cpp \ + battery.h \ + batteryappletimpl.h + +moc_battery.o: moc_battery.cpp \ + battery.h + +moc_battery.cpp: battery.h + $(MOC) battery.h -o moc_battery.cpp + + diff --git a/core/applets/batteryapplet/battery.cpp b/core/applets/batteryapplet/battery.cpp new file mode 100644 index 0000000..3d254fc --- a/dev/null +++ b/core/applets/batteryapplet/battery.cpp @@ -0,0 +1,152 @@ +/********************************************************************** +** Copyright (C) 2000 Trolltech AS. All rights reserved. +** +** This file is part of Qtopia Environment. +** +** This file may be distributed and/or modified under the terms of the +** GNU General Public License version 2 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +** See http://www.trolltech.com/gpl/ for GPL licensing information. +** +** Contact info@trolltech.com if any conditions of this licensing are +** not clear to you. +** +**********************************************************************/ +#include "battery.h" +#include "batterystatus.h" + +#include <qpe/power.h> + +#include <qpainter.h> +#include <qtimer.h> + + +BatteryMeter::BatteryMeter( QWidget *parent = 0 ) + : QWidget( parent ), charging(false) +{ + ps = new PowerStatus; + startTimer( 10000 ); + setFixedHeight(12); + chargeTimer = new QTimer( this ); + connect( chargeTimer, SIGNAL(timeout()), this, SLOT(chargeTimeout()) ); + timerEvent(0); +} + +BatteryMeter::~BatteryMeter() +{ + delete ps; +} + +QSize BatteryMeter::sizeHint() const +{ + return QSize(10,12); +} + +void BatteryMeter::mouseReleaseEvent( QMouseEvent *) +{ + if ( batteryView && batteryView->isVisible() ) { + delete (QWidget *) batteryView; + } else { + if ( !batteryView ) + batteryView = new BatteryStatus( ps ); + batteryView->showMaximized(); + batteryView->raise(); + batteryView->show(); + } +} + +void BatteryMeter::timerEvent( QTimerEvent * ) +{ + PowerStatus prev = *ps; + + *ps = PowerStatusManager::readStatus(); + + if ( prev != *ps ) { + percent = ps->batteryPercentRemaining(); + if ( !charging && ps->batteryStatus() == PowerStatus::Charging && percent < 0 ) { + percent = 0; + charging = true; + chargeTimer->start( 500 ); + } else if ( charging && ps->batteryStatus() != PowerStatus::Charging ) { + charging = false; + chargeTimer->stop(); + if ( batteryView ) + batteryView->updatePercent( percent ); + } + repaint(FALSE); + if ( batteryView ) + batteryView->repaint(); + } +} + +void BatteryMeter::chargeTimeout() +{ + percent += 20; + if ( percent > 100 ) + percent = 0; + + repaint(FALSE); + if ( batteryView ) + batteryView->updatePercent( percent ); +} + +void BatteryMeter::paintEvent( QPaintEvent* ) +{ + QPainter p(this); + + QColor c; + QColor darkc; + QColor lightc; + if ( ps->acStatus() == PowerStatus::Offline ) { + c = blue.light(120); + darkc = c.dark(120); + lightc = c.light(140); + } else if ( ps->acStatus() == PowerStatus::Online ) { + c = green.dark(130); + darkc = c.dark(120); + lightc = c.light(180); + } else { + c = red; + darkc = c.dark(120); + lightc = c.light(160); + } + + int w = 6; + int h = height()-3; + int pix = (percent * h) / 100; + int y2 = height() - 2; + int y = y2 - pix; + int x1 = (width() - w) / 2; + + p.setPen(QColor(80,80,80)); + p.drawLine(x1+w/4,0,x1+w/4+w/2,0); + p.drawRect(x1,1,w,height()-1); + p.setBrush(c); + + int extra = ((percent * h) % 100)/(100/4); + +#define Y(i) ((i<=extra)?y-1:y) +#define DRAWUPPER(i) if ( Y(i) >= 2 ) p.drawLine(i+x1,2,i+x1,Y(i)); + p.setPen( gray ); + DRAWUPPER(1); + DRAWUPPER(3); + p.setPen( gray.light(130) ); + DRAWUPPER(2); + p.setPen( gray.dark(120) ); + DRAWUPPER(4); + +#define DRAW(i) { if ( Y(i) < y2 ) p.drawLine(i+x1,Y(i)+1,i+x1,y2); } + p.setPen( c ); + DRAW(1); + DRAW(3); + p.setPen( lightc ); + DRAW(2); + p.setPen(darkc); + DRAW(4); +} + diff --git a/core/applets/batteryapplet/battery.h b/core/applets/batteryapplet/battery.h new file mode 100644 index 0000000..d4807b0 --- a/dev/null +++ b/core/applets/batteryapplet/battery.h @@ -0,0 +1,55 @@ +/********************************************************************** +** Copyright (C) 2000 Trolltech AS. All rights reserved. +** +** This file is part of Qtopia Environment. +** +** This file may be distributed and/or modified under the terms of the +** GNU General Public License version 2 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +** See http://www.trolltech.com/gpl/ for GPL licensing information. +** +** Contact info@trolltech.com if any conditions of this licensing are +** not clear to you. +** +**********************************************************************/ +#ifndef BATTERY_H +#define BATTERY_H + +#include <qwidget.h> +#include <qguardedptr.h> + +class PowerStatus; +class BatteryStatus; +class QTimer; + +class BatteryMeter : public QWidget +{ + Q_OBJECT +public: + BatteryMeter( QWidget *parent = 0 ); + ~BatteryMeter(); + + QSize sizeHint() const; + +protected: + void timerEvent( QTimerEvent * ); + void paintEvent( QPaintEvent* ); + void mouseReleaseEvent( QMouseEvent * ); + +protected slots: + void chargeTimeout(); + +protected: + QGuardedPtr<BatteryStatus> batteryView; + PowerStatus *ps; + QTimer *chargeTimer; + int percent; + bool charging; +}; + +#endif diff --git a/core/applets/batteryapplet/batteryapplet.pro b/core/applets/batteryapplet/batteryapplet.pro new file mode 100644 index 0000000..fa0fca8 --- a/dev/null +++ b/core/applets/batteryapplet/batteryapplet.pro @@ -0,0 +1,12 @@ +TEMPLATE = lib +CONFIG += qt warn_on release +HEADERS = battery.h batterystatus.h batteryappletimpl.h +SOURCES = battery.cpp batterystatus.cpp batteryappletimpl.cpp +TARGET = batteryapplet +DESTDIR = ../../plugins/applets +INCLUDEPATH += $(QPEDIR)/include +DEPENDPATH += ../$(QPEDIR)/include .. +LIBS += -lqpe +VERSION = 1.0.0 + +TRANSLATIONS += ../../i18n/de/libbatteryapplet.ts diff --git a/core/applets/batteryapplet/batteryappletimpl.cpp b/core/applets/batteryapplet/batteryappletimpl.cpp new file mode 100644 index 0000000..3f3079a --- a/dev/null +++ b/core/applets/batteryapplet/batteryappletimpl.cpp @@ -0,0 +1,63 @@ +/********************************************************************** +** Copyright (C) 2000 Trolltech AS. All rights reserved. +** +** This file is part of Qtopia Environment. +** +** This file may be distributed and/or modified under the terms of the +** GNU General Public License version 2 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +** See http://www.trolltech.com/gpl/ for GPL licensing information. +** +** Contact info@trolltech.com if any conditions of this licensing are +** not clear to you. +** +**********************************************************************/ +#include "battery.h" +#include "batteryappletimpl.h" + + +BatteryAppletImpl::BatteryAppletImpl() + : battery(0), ref(0) +{ +} + +BatteryAppletImpl::~BatteryAppletImpl() +{ + delete battery; +} + +QWidget *BatteryAppletImpl::applet( QWidget *parent ) +{ + if ( !battery ) + battery = new BatteryMeter( parent ); + return battery; +} + +int BatteryAppletImpl::position() const +{ + return 8; +} + +QRESULT BatteryAppletImpl::queryInterface( const QUuid &uuid, QUnknownInterface **iface ) +{ + *iface = 0; + if ( uuid == IID_QUnknown ) + *iface = this; + else if ( uuid == IID_TaskbarApplet ) + *iface = this; + + if ( *iface ) + (*iface)->addRef(); + return QS_OK; +} + +Q_EXPORT_INTERFACE() +{ + Q_CREATE_INSTANCE( BatteryAppletImpl ) +} + diff --git a/core/applets/batteryapplet/batteryappletimpl.h b/core/applets/batteryapplet/batteryappletimpl.h new file mode 100644 index 0000000..94f49db --- a/dev/null +++ b/core/applets/batteryapplet/batteryappletimpl.h @@ -0,0 +1,44 @@ +/********************************************************************** +** Copyright (C) 2000 Trolltech AS. All rights reserved. +** +** This file is part of Qtopia Environment. +** +** This file may be distributed and/or modified under the terms of the +** GNU General Public License version 2 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +** See http://www.trolltech.com/gpl/ for GPL licensing information. +** +** Contact info@trolltech.com if any conditions of this licensing are +** not clear to you. +** +**********************************************************************/ +#ifndef BATTERYAPPLETIMPL_H +#define BATTERYAPPLETIMPL_H + +#include <qpe/taskbarappletinterface.h> + +class BatteryMeter; + +class BatteryAppletImpl : public TaskbarAppletInterface +{ +public: + BatteryAppletImpl(); + virtual ~BatteryAppletImpl(); + + QRESULT queryInterface( const QUuid&, QUnknownInterface** ); + Q_REFCOUNT + + virtual QWidget *applet( QWidget *parent ); + virtual int position() const; + +private: + BatteryMeter *battery; + ulong ref; +}; + +#endif diff --git a/core/applets/batteryapplet/batterystatus.cpp b/core/applets/batteryapplet/batterystatus.cpp new file mode 100644 index 0000000..d18b6c9 --- a/dev/null +++ b/core/applets/batteryapplet/batterystatus.cpp @@ -0,0 +1,140 @@ +/********************************************************************** +** Copyright (C) 2000 Trolltech AS. All rights reserved. +** +** This file is part of Qtopia Environment. +** +** This file may be distributed and/or modified under the terms of the +** GNU General Public License version 2 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +** See http://www.trolltech.com/gpl/ for GPL licensing information. +** +** Contact info@trolltech.com if any conditions of this licensing are +** not clear to you. +** +**********************************************************************/ +#include "batterystatus.h" + +#include <qpe/power.h> + +#include <qpainter.h> +#include <qpushbutton.h> +#include <qdrawutil.h> + + +BatteryStatus::BatteryStatus( const PowerStatus *p, QWidget *parent ) + : QWidget( parent, 0, WDestructiveClose), ps(p) +{ + setCaption( tr("Battery Status") ); + QPushButton *pb = new QPushButton( tr("Close"), this ); + pb->move( 70, 220 ); + pb->show(); + connect( pb, SIGNAL( clicked() ), this, SLOT( close() ) ); + percent = ps->batteryPercentRemaining(); + show(); +} + +BatteryStatus::~BatteryStatus() +{ +} + +void BatteryStatus::updatePercent( int pc ) +{ + percent = pc; + repaint(FALSE); +} + +void BatteryStatus::drawSegment( QPainter *p, const QRect &r, const QColor &topgrad, const QColor &botgrad, const QColor &highlight, int hightlight_height ) +{ + int h1, h2, s1, s2, v1, v2, ng = r.height(), hy = ng*30/100, hh = hightlight_height; + topgrad.hsv( &h1, &s1, &v1 ); + botgrad.hsv( &h2, &s2, &v2 ); + for ( int j = 0; j < hy-2; j++ ) { + p->setPen( QColor( h1 + ((h2-h1)*j)/(ng-1), s1 + ((s2-s1)*j)/(ng-1), + v1 + ((v2-v1)*j)/(ng-1), QColor::Hsv ) ); + p->drawLine( r.x(), r.top()+hy-2-j, r.x()+r.width(), r.top()+hy-2-j ); + } + for ( int j = 0; j < hh; j++ ) { + p->setPen( highlight ); + p->drawLine( r.x(), r.top()+hy-2+j, r.x()+r.width(), r.top()+hy-2+j ); + } + for ( int j = 0; j < ng-hy-hh; j++ ) { + p->setPen( QColor( h1 + ((h2-h1)*j)/(ng-1), s1 + ((s2-s1)*j)/(ng-1), + v1 + ((v2-v1)*j)/(ng-1), QColor::Hsv ) ); + p->drawLine( r.x(), r.top()+hy+hh-2+j, r.x()+r.width(), r.top()+hy+hh-2+j ); + } +} + +void BatteryStatus::paintEvent( QPaintEvent * ) +{ + QPainter p(this); + QString text; + if ( ps->batteryStatus() == PowerStatus::Charging ) { + text = tr("Charging"); + } else if ( ps->batteryPercentAccurate() ) { + text.sprintf( tr("Percentage battery remaining") + ": %i%%", percent ); + } else { + text = tr("Battery status: "); + switch ( ps->batteryStatus() ) { + case PowerStatus::High: + text += tr("Good"); + break; + case PowerStatus::Low: + text += tr("Low"); + break; + case PowerStatus::VeryLow: + text += tr("Very Low"); + break; + case PowerStatus::Critical: + text += tr("Critical"); + break; + default: // NotPresent, etc. + text += tr("Unknown"); + } + } + p.drawText( 10, 120, text ); + if ( ps->acStatus() == PowerStatus::Backup ) + p.drawText( 10, 150, tr("On backup power") ); + else if ( ps->acStatus() == PowerStatus::Online ) + p.drawText( 10, 150, tr("Power on-line") ); + else if ( ps->acStatus() == PowerStatus::Offline ) + p.drawText( 10, 150, tr("External power disconnected") ); + + if ( ps->batteryTimeRemaining() >= 0 ) { + text.sprintf( tr("Battery time remaining") + ": %im %02is", + ps->batteryTimeRemaining() / 60, ps->batteryTimeRemaining() % 60 ); + p.drawText( 10, 180, text ); + } + + QColor c; + QColor darkc; + QColor lightc; + if ( ps->acStatus() == PowerStatus::Offline ) { + c = blue.light(120); + darkc = c.dark(280); + lightc = c.light(145); + } else if ( ps->acStatus() == PowerStatus::Online ) { + c = green.dark(130); + darkc = c.dark(200); + lightc = c.light(220); + } else { + c = red; + darkc = c.dark(280); + lightc = c.light(140); + } + if ( percent < 0 ) + return; + + int percent2 = percent * 2; + p.setPen( black ); + qDrawShadePanel( &p, 9, 30, 204, 39, colorGroup(), TRUE, 1, NULL); + qDrawShadePanel( &p, 212, 37, 12, 24, colorGroup(), TRUE, 1, NULL); + drawSegment( &p, QRect( 10, 30, percent2, 40 ), lightc, darkc, lightc.light(115), 6 ); + drawSegment( &p, QRect( 11 + percent2, 30, 200 - percent2, 40 ), white.light(80), black, white.light(90), 6 ); + drawSegment( &p, QRect( 212, 37, 10, 25 ), white.light(80), black, white.light(90), 2 ); +} + diff --git a/core/applets/batteryapplet/batterystatus.h b/core/applets/batteryapplet/batterystatus.h new file mode 100644 index 0000000..85b2c4d --- a/dev/null +++ b/core/applets/batteryapplet/batterystatus.h @@ -0,0 +1,45 @@ +/********************************************************************** +** Copyright (C) 2000 Trolltech AS. All rights reserved. +** +** This file is part of Qtopia Environment. +** +** This file may be distributed and/or modified under the terms of the +** GNU General Public License version 2 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +** See http://www.trolltech.com/gpl/ for GPL licensing information. +** +** Contact info@trolltech.com if any conditions of this licensing are +** not clear to you. +** +**********************************************************************/ +#ifndef BATTERY_STATUS_H +#define BATTERY_STATUS_H + +#include <qwidget.h> + +class PowerStatus; + +class BatteryStatus : public QWidget +{ +public: + BatteryStatus( const PowerStatus *s, QWidget *parent=0 ); + ~BatteryStatus(); + + void updatePercent( int ); + +protected: + void drawSegment( QPainter *p, const QRect &r, const QColor &topgrad, const QColor &botgrad, const QColor &highlight, int hightlight_height ); + void paintEvent( QPaintEvent *pe ); + +private: + const PowerStatus *ps; + int percent; +}; + +#endif + diff --git a/core/applets/batteryapplet/qpe-batteryapplet.control b/core/applets/batteryapplet/qpe-batteryapplet.control new file mode 100644 index 0000000..83d0b8b --- a/dev/null +++ b/core/applets/batteryapplet/qpe-batteryapplet.control @@ -0,0 +1,9 @@ +Files: plugins/applets/libbatteryapplet.so* +Priority: optional +Section: qpe/taskbar +Maintainer: Warwick Allison <warwick@trolltech.com> +Architecture: arm +Version: $QPE_VERSION-3 +Depends: qpe-base ($QPE_VERSION) +Description: Battery Monitor applet + Battery Monitor applet for the Qtopia environment taskbar. diff --git a/core/applets/batteryapplet/qpe-batteryapplet.postinst b/core/applets/batteryapplet/qpe-batteryapplet.postinst new file mode 100755 index 0000000..ba76ffa --- a/dev/null +++ b/core/applets/batteryapplet/qpe-batteryapplet.postinst @@ -0,0 +1,2 @@ +#!/bin/sh +/opt/QtPalmtop/bin/qcop QPE/TaskBar "reloadApplets()" diff --git a/core/applets/batteryapplet/qpe-batteryapplet.postrm b/core/applets/batteryapplet/qpe-batteryapplet.postrm new file mode 100755 index 0000000..ba76ffa --- a/dev/null +++ b/core/applets/batteryapplet/qpe-batteryapplet.postrm @@ -0,0 +1,2 @@ +#!/bin/sh +/opt/QtPalmtop/bin/qcop QPE/TaskBar "reloadApplets()" |