summaryrefslogtreecommitdiff
authormickeyl <mickeyl>2004-09-27 20:56:02 (UTC)
committer mickeyl <mickeyl>2004-09-27 20:56:02 (UTC)
commitba463a1029d1c0ff553a3dc9bf544617289d95f0 (patch) (side-by-side diff)
treeab5ce458e2aa66525346695780f0f73571125128
parent83bb04664aea3f878b86259aa76846afa617c694 (diff)
downloadopie-ba463a1029d1c0ff553a3dc9bf544617289d95f0.zip
opie-ba463a1029d1c0ff553a3dc9bf544617289d95f0.tar.gz
opie-ba463a1029d1c0ff553a3dc9bf544617289d95f0.tar.bz2
A brightness applet
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--ChangeLog1
-rw-r--r--noncore/applets/brightnessapplet/brightnessapplet.cpp235
-rw-r--r--noncore/applets/brightnessapplet/brightnessapplet.h81
-rw-r--r--noncore/applets/brightnessapplet/brightnessapplet.pro13
-rw-r--r--noncore/applets/brightnessapplet/config.in6
-rw-r--r--packages1
-rw-r--r--pics/brightnessapplet/icon.pngbin0 -> 3280 bytes
7 files changed, 337 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index 8701a54..4833e0d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,17 +1,18 @@
2004-??-?? Opie 1.1.x
New Features
------------
* Ported opie-mediaplayer2 to recent libxine (brad,zecke)
+ * Ported brightnessapplet from Qtopia 1.7 (mickeyl)
Fixed Bugs
----------
2004-09-17 Opie 1.1.6
New Features
------------
* Fifteen gained configurable number of items (zecke)
* Fifteen can have custom background images (zecke)
* Added daemonizing capabilities to QWS Server [via Qt/Embedded] (mickeyl)
* Integrated the new security framework into libopie2 (zecke,clem)
diff --git a/noncore/applets/brightnessapplet/brightnessapplet.cpp b/noncore/applets/brightnessapplet/brightnessapplet.cpp
new file mode 100644
index 0000000..1ade35e
--- a/dev/null
+++ b/noncore/applets/brightnessapplet/brightnessapplet.cpp
@@ -0,0 +1,235 @@
+/*
+                 This file is part of the Opie Project
+
+ =. (C) 2004 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de>
+ .=l. Based on Qtopia 1.7 Brightnessapplet (C) 2003-2004 TrollTech
+           .>+-=
+ _;:,     .>    :=|. This program is free software; you can
+.> <`_,   >  .   <= redistribute it and/or modify it under
+:`=1 )Y*s>-.--   : the terms of the GNU General Public
+.="- .-=="i,     .._ License as published by the Free Software
+ - .   .-<_>     .<> Foundation; either version 2 of the License,
+     ._= =}       : or (at your option) any later version.
+    .%`+i>       _;_.
+    .i_,=:_.      -<s. 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 application; see the file COPYING.LIB.
+ If not, write to the Free Software Foundation,
+ Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+
+*/
+
+#include "brightnessapplet.h"
+
+/* OPIE */
+#include <opie2/odebug.h>
+#include <opie2/odevice.h>
+#include <opie2/otaskbarapplet.h>
+#include <qpe/applnk.h>
+#include <qpe/config.h>
+#include <qpe/power.h>
+#include <qpe/qcopenvelope_qws.h>
+#include <qpe/resource.h>
+using namespace Opie::Core;
+using namespace Opie::Ui;
+
+/* QT */
+#include <qpainter.h>
+#include <qlabel.h>
+#include <qslider.h>
+#include <qlayout.h>
+
+/* STD */
+#include <assert.h>
+
+/* XPM */
+static const char * const light_on_xpm[] = {
+"9 16 5 1",
+" c None",
+". c #FFFFFFFF0000",
+"X c #000000000000",
+"o c #FFFFFFFFFFFF",
+"O c #FFFF6C6C0000",
+" ",
+" XXX ",
+" XoooX ",
+" Xoooo.X ",
+"Xoooooo.X",
+"Xoooo...X",
+"Xooo.o..X",
+" Xooo..X ",
+" Xoo...X ",
+" Xoo.X ",
+" Xoo.XX ",
+" XOOOXX ",
+" XOOOXX ",
+" XOXX ",
+" XX ",
+" "};
+
+
+/* XPM */
+static const char * const light_off_xpm[] = {
+"9 16 4 1",
+" c None",
+". c #000000000000",
+"X c #6B6B6C6C6C6C",
+"o c #FFFF6C6C0000",
+" ",
+" ",
+" ... ",
+" . . ",
+" . X. ",
+". X.",
+". XXX.",
+". X XX.",
+" . XX. ",
+" . XXX. ",
+" . X. ",
+" . X.. ",
+" .ooo.. ",
+" .ooo.. ",
+" .o.. ",
+" .. "};
+
+BrightnessAppletControl::BrightnessAppletControl( OTaskbarApplet* parent, const char* name )
+ :QFrame( parent, name, WStyle_StaysOnTop | WType_Popup )
+{
+ setFrameStyle( QFrame::PopupPanel | QFrame::Raised );
+ QGridLayout *gl = new QGridLayout( this, 3, 2, 6, 3 );
+ //gl->setRowStretch( 1, 100 );
+
+ int maxbright = ODevice::inst()->displayBrightnessResolution();
+ slider = new QSlider(this);
+ slider->setMaxValue(maxbright);
+ slider->setOrientation(QSlider::Vertical);
+ slider->setTickmarks(QSlider::Right);
+ slider->setTickInterval(QMAX(1, maxbright / 16));
+ slider->setLineStep(QMAX(1, maxbright / 16));
+ slider->setPageStep(QMAX(1, maxbright / 16));
+ gl->addMultiCellWidget( slider, 0, 2, 0, 0 );
+
+ QPixmap onPm( (const char **)light_on_xpm );
+ QLabel *l = new QLabel( this );
+ l->setPixmap( onPm );
+ gl->addWidget( l, 0, 1 );
+
+ QPixmap offPm( (const char **)light_off_xpm );
+ l = new QLabel( this );
+ l->setPixmap( offPm );
+ gl->addWidget( l, 2, 1 );
+
+ setFixedHeight( 100 );
+ setFixedWidth( gl->sizeHint().width() );
+ setFocusPolicy(QWidget::NoFocus);
+}
+
+
+BrightnessAppletControl::~BrightnessAppletControl()
+{
+}
+
+
+BrightnessApplet::BrightnessApplet( QWidget *parent, const char *name )
+ :OTaskbarApplet( parent, name )
+{
+ setFixedHeight( AppLnk::smallIconSize() );
+ setFixedWidth( AppLnk::smallIconSize() );
+ _pixmap.convertFromImage( Resource::loadImage( "brightnessapplet/icon" ).smoothScale( height(), width() ) );
+ _control = new BrightnessAppletControl( this, "control" );
+}
+
+
+void BrightnessApplet::writeSystemBrightness(int brightness)
+{
+ PowerStatus ps = PowerStatusManager::readStatus();
+
+ Config cfg("qpe");
+ if (ps.acStatus() == PowerStatus::Online) {
+ cfg.setGroup("AC");
+ } else {
+ cfg.setGroup("Battery");
+ }
+ cfg.writeEntry("Brightness", brightness);
+}
+
+
+int BrightnessApplet::readSystemBrightness(void)
+{
+ PowerStatus ps = PowerStatusManager::readStatus();
+ Config cfg("qpe");
+
+ if (ps.acStatus() == PowerStatus::Online) {
+ cfg.setGroup("AC");
+ } else {
+ cfg.setGroup("Battery");
+ }
+
+ return cfg.readNumEntry("Brightness", 128);
+}
+
+
+BrightnessApplet::~BrightnessApplet()
+{
+}
+
+
+int BrightnessApplet::position()
+{
+ return 7;
+}
+
+
+void BrightnessApplet::paintEvent( QPaintEvent* )
+{
+ QPainter p(this);
+ p.drawPixmap(0, 0, _pixmap );
+}
+
+
+int BrightnessApplet::calcBrightnessValue()
+{
+ int v = _control->slider->maxValue() - _control->slider->value();
+ return (v * 255 + _control->slider->maxValue() / 2) / _control->slider->maxValue();
+}
+
+
+void BrightnessApplet::sliderMoved( int value )
+{
+#ifndef QT_NO_COP
+ QCopEnvelope e("QPE/System", "setBacklight(int)");
+ e << calcBrightnessValue();
+#else
+#error This Applet makes no sense without QCOP
+#endif // QT_NO_COP
+}
+
+
+void BrightnessApplet::mousePressEvent( QMouseEvent* )
+{
+ if ( !_control->isVisible() )
+ {
+ int v = 255 - readSystemBrightness();
+ popup( _control );
+ _control->slider->setValue((_control->slider->maxValue() * v + 128) / 255);
+ connect(_control->slider, SIGNAL(valueChanged(int)), this, SLOT(sliderMoved(int)));
+ }
+ else
+ {
+ _control->hide();
+ writeSystemBrightness( calcBrightnessValue() );
+ }
+}
+
+
+EXPORT_OPIE_APPLET_v1( BrightnessApplet )
+
diff --git a/noncore/applets/brightnessapplet/brightnessapplet.h b/noncore/applets/brightnessapplet/brightnessapplet.h
new file mode 100644
index 0000000..8b88bd1
--- a/dev/null
+++ b/noncore/applets/brightnessapplet/brightnessapplet.h
@@ -0,0 +1,81 @@
+/*
+                 This file is part of the Opie Project
+
+ =. (C) 2004 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de>
+ .=l. Based on Qtopia 1.7 Brightnessapplet (C) 2003-2004 TrollTech
+           .>+-=
+ _;:,     .>    :=|. This program is free software; you can
+.> <`_,   >  .   <= redistribute it and/or modify it under
+:`=1 )Y*s>-.--   : the terms of the GNU General Public
+.="- .-=="i,     .._ License as published by the Free Software
+ - .   .-<_>     .<> Foundation; either version 2 of the License,
+     ._= =}       : or (at your option) any later version.
+    .%`+i>       _;_.
+    .i_,=:_.      -<s. 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 application; see the file COPYING.LIB.
+ If not, write to the Free Software Foundation,
+ Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+
+*/
+
+#ifndef NETWORKAPPLET_H
+#define NETWORKAPPLET_H
+
+#include <opie2/otaskbarapplet.h>
+#include <qframe.h>
+#include <qstring.h>
+#include <qtoolbutton.h>
+#include <qlineedit.h>
+#include <qpixmap.h>
+
+class QShowEvent;
+class QHideEvent;
+class QSlider;
+
+class BrightnessAppletControl : public QFrame
+{
+ public:
+ BrightnessAppletControl( Opie::Ui::OTaskbarApplet* parent, const char* name = 0 );
+ ~BrightnessAppletControl();
+
+ QSlider* slider;
+};
+
+class BrightnessApplet : public Opie::Ui::OTaskbarApplet
+{
+ Q_OBJECT
+
+ public:
+ BrightnessApplet( QWidget* parent = 0, const char* name = 0 );
+ ~BrightnessApplet();
+
+ void writeSystemBrightness( int brightness );
+ int readSystemBrightness();
+ int calcBrightnessValue();
+
+ static int position();
+
+ public slots:
+ void sliderMoved( int value );
+
+ protected:
+ virtual void paintEvent( QPaintEvent* );
+ virtual void mousePressEvent( QMouseEvent* );
+
+ private:
+ BrightnessAppletControl* _control;
+ QPixmap _pixmap;
+};
+
+#endif
+
diff --git a/noncore/applets/brightnessapplet/brightnessapplet.pro b/noncore/applets/brightnessapplet/brightnessapplet.pro
new file mode 100644
index 0000000..5044f38
--- a/dev/null
+++ b/noncore/applets/brightnessapplet/brightnessapplet.pro
@@ -0,0 +1,13 @@
+TEMPLATE = lib
+CONFIG += qt plugin warn_on
+HEADERS = brightnessapplet.h
+SOURCES = brightnessapplet.cpp
+TARGET = brightnessapplet
+DESTDIR = $(OPIEDIR)/plugins/applets
+INCLUDEPATH += $(OPIEDIR)/include
+DEPENDPATH += $(OPIEDIR)/include
+LIBS += -lqpe -lopiecore2 -lopieui2
+VERSION = 0.1.0
+
+
+include ( $(OPIEDIR)/include.pro )
diff --git a/noncore/applets/brightnessapplet/config.in b/noncore/applets/brightnessapplet/config.in
new file mode 100644
index 0000000..ba88bf0
--- a/dev/null
+++ b/noncore/applets/brightnessapplet/config.in
@@ -0,0 +1,6 @@
+ config BRIGHTNESSAPPLET
+ boolean "opie-brightness (control lcd brightness on-the-fly)"
+ default "n"
+ depends ( LIBQPE || LIBQPE-X11 ) && LIBOPIE2CORE && LIBOPIE2UI
+ comment "Network applet needs a libqpe and libopie2 (core, ui)"
+ depends !(( LIBQPE || LIBQPE-X11 ) && LIBOPIE2CORE && LIBOPIE2UI)
diff --git a/packages b/packages
index ab7b77a..275d2f9 100644
--- a/packages
+++ b/packages
@@ -6,24 +6,25 @@ CONFIG_APPLET_EXAMPLE examples/applet example.pro
CONFIG_APPSKEY noncore/settings/appskey appskey.pro
CONFIG_AQPKG noncore/settings/aqpkg aqpkg.pro
CONFIG_AUTOROTATEAPPLET noncore/applets/autorotateapplet autorotateapplet.pro
CONFIG_BACKGAMMON noncore/games/backgammon backgammon.pro
CONFIG_BACKUP noncore/settings/backup backup.pro
CONFIG_BARTENDER noncore/apps/opie-bartender bartender.pro
CONFIG_BATTERYAPPLET core/applets/batteryapplet batteryapplet.pro
CONFIG_BEND noncore/unsupported/mail2/bend bend.pro
CONFIG_BIGSCREEN_EXAMPLE libopie/big-screen/example osplitter_mail.pro
CONFIG_BINARY noncore/tools/calc2/binary binary.pro
CONFIG_BLUE-PIN noncore/net/opietooth/blue-pin blue-pin.pro
CONFIG_BOUNCE noncore/games/bounce bounce.pro
+CONFIG_BRIGHTNESSAPPLET noncore/applets/brightnessapplet brightnessapplet.pro
CONFIG_BUTTON-SETTINGS core/settings/button button.pro
CONFIG_BUZZWORD noncore/games/buzzword buzzword.pro
CONFIG_CALC2 noncore/tools/calc2 calc.pro
CONFIG_CALCULATOR noncore/tools/calculator calculator.pro
CONFIG_CALIBRATE core/apps/calibrate calibrate.pro
CONFIG_CAMERA noncore/multimedia/camera camera.pro
CONFIG_CARDMON core/applets/cardmon cardmon.pro
CONFIG_CHECKBOOK noncore/apps/checkbook checkbook.pro
CONFIG_CITYTIME core/settings/citytime citytime.pro
CONFIG_CLIPBOARDAPPLET core/applets/clipboardapplet clipboardapplet.pro
CONFIG_CLOCKAPPLET core/applets/clockapplet clockapplet.pro
CONFIG_CLOCK noncore/tools/clock clock.pro
diff --git a/pics/brightnessapplet/icon.png b/pics/brightnessapplet/icon.png
new file mode 100644
index 0000000..c7765c9
--- a/dev/null
+++ b/pics/brightnessapplet/icon.png
Binary files differ