diff options
author | Slávek Banko <slavek.banko@axis.cz> | 2013-08-21 21:26:05 +0200 |
---|---|---|
committer | Slávek Banko <slavek.banko@axis.cz> | 2013-08-21 21:26:05 +0200 |
commit | 29b50d195f91ee5131805a0ca9fe45ab77655c8a (patch) | |
tree | 2ccda3f73a19fa8f03e6c02f9113728e5aad1d44 /src | |
download | klcddimmer-29b50d195f91ee5131805a0ca9fe45ab77655c8a.tar.gz klcddimmer-29b50d195f91ee5131805a0ca9fe45ab77655c8a.zip |
Initial import of klcddimmer 0.3
Diffstat (limited to 'src')
-rw-r--r-- | src/Makefile.am | 20 | ||||
-rw-r--r-- | src/brightnesschooser.cpp | 100 | ||||
-rw-r--r-- | src/brightnesschooser.h | 53 | ||||
-rw-r--r-- | src/brightnesschooser.ui | 154 | ||||
-rw-r--r-- | src/brightnesschooserimpl.cpp | 217 | ||||
-rw-r--r-- | src/brightnesschooserimpl.h | 82 | ||||
-rw-r--r-- | src/hi16-app-klcddimmer.png | bin | 0 -> 712 bytes | |||
-rw-r--r-- | src/hi32-app-klcddimmer.png | bin | 0 -> 1672 bytes | |||
-rw-r--r-- | src/hi48-app-klcddimmer.png | bin | 0 -> 2679 bytes | |||
-rw-r--r-- | src/klcddimmer.cpp | 213 | ||||
-rw-r--r-- | src/klcddimmer.desktop | 34 | ||||
-rw-r--r-- | src/klcddimmer.h | 146 | ||||
-rw-r--r-- | src/klcddimmer.lsm | 16 | ||||
-rw-r--r-- | src/klcddimmer.svg | 154 | ||||
-rw-r--r-- | src/klcddimmerapplet.cpp | 57 | ||||
-rw-r--r-- | src/klcddimmerapplet.h | 50 | ||||
-rw-r--r-- | src/preferences.cpp | 58 | ||||
-rw-r--r-- | src/preferences.h | 192 | ||||
-rw-r--r-- | src/preferences.kcfg | 38 | ||||
-rw-r--r-- | src/preferences.kcfgc | 4 | ||||
-rw-r--r-- | src/progpreferences.cpp | 152 | ||||
-rw-r--r-- | src/progpreferences.h | 65 | ||||
-rw-r--r-- | src/progpreferences.ui | 292 |
23 files changed, 2097 insertions, 0 deletions
diff --git a/src/Makefile.am b/src/Makefile.am new file mode 100644 index 0000000..85db9d3 --- /dev/null +++ b/src/Makefile.am @@ -0,0 +1,20 @@ +INCLUDES= $(all_includes) +METASOURCES = AUTO + +lib_LTLIBRARIES = klcddimmer_panelapplet.la + +klcddimmer_panelapplet_la_SOURCES = brightnesschooser.ui \ + brightnesschooserimpl.cpp klcddimmer.cpp klcddimmerapplet.cpp preferences.kcfg preferences.kcfgc \ + progpreferences.ui +klcddimmer_panelapplet_la_LDFLAGS = -module -avoid-version $(all_libraries) +klcddimmer_panelapplet_la_LIBADD = $(LIB_KDEUI) + +klcddimmer_DATA = klcddimmer.desktop +klcddimmerdir = $(kde_datadir)/kicker/applets + +messages: rc.cpp + $(EXTRACTRC) `find . -name \*.ui -o -name \*.rc` > rc.cpp + $(XGETTEXT) *.cpp -o $(podir)/klcddimmer.pot +noinst_HEADERS = brightnesschooserimpl.h klcddimmerapplet.h + +KDE_ICON = AUTO diff --git a/src/brightnesschooser.cpp b/src/brightnesschooser.cpp new file mode 100644 index 0000000..2b2c282 --- /dev/null +++ b/src/brightnesschooser.cpp @@ -0,0 +1,100 @@ +#include <kdialog.h> +#include <klocale.h> +/**************************************************************************** +** Form implementation generated from reading ui file '/home/bettini/work/klcddimmer/src/brightnesschooser.ui' +** +** Created: Sat Feb 24 20:45:57 2007 +** by: The User Interface Compiler ($Id: qt/main.cpp 3.3.7 edited Aug 31 2005 $) +** +** WARNING! All changes made in this file will be lost! +****************************************************************************/ + +#include "brightnesschooser.h" + +#include <qvariant.h> +#include <qpushbutton.h> +#include <qlabel.h> +#include <qslider.h> +#include <qlayout.h> +#include <qtooltip.h> +#include <qwhatsthis.h> + +/* + * Constructs a BrightnessChooser as a child of 'parent', with the + * name 'name' and widget flags set to 'f'. + */ +BrightnessChooser::BrightnessChooser( QWidget* parent, const char* name, WFlags fl ) + : QWidget( parent, name, fl ) +{ + if ( !name ) + setName( "BrightnessChooser" ); + BrightnessChooserLayout = new QGridLayout( this, 1, 1, 11, 6, "BrightnessChooserLayout"); + + layout9 = new QGridLayout( 0, 1, 1, 0, 6, "layout9"); + + layout7 = new QHBoxLayout( 0, 0, 0, "layout7"); + spacer1 = new QSpacerItem( 20, 20, QSizePolicy::Minimum, QSizePolicy::Minimum ); + layout7->addItem( spacer1 ); + + layout5 = new QVBoxLayout( 0, 0, 6, "layout5"); + + valueLabel = new QLabel( this, "valueLabel" ); + valueLabel->setAlignment( int( QLabel::AlignCenter ) ); + layout5->addWidget( valueLabel ); + + brightnessSlider = new QSlider( this, "brightnessSlider" ); + brightnessSlider->setOrientation( QSlider::Vertical ); + layout5->addWidget( brightnessSlider ); + layout7->addLayout( layout5 ); + spacer1_2 = new QSpacerItem( 16, 20, QSizePolicy::Minimum, QSizePolicy::Minimum ); + layout7->addItem( spacer1_2 ); + + layout9->addLayout( layout7, 0, 0 ); + + okButton = new QPushButton( this, "okButton" ); + okButton->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)1, 0, 0, okButton->sizePolicy().hasHeightForWidth() ) ); + + layout9->addWidget( okButton, 1, 0 ); + + BrightnessChooserLayout->addLayout( layout9, 0, 0 ); + languageChange(); + resize( QSize(124, 163).expandedTo(minimumSizeHint()) ); + clearWState( WState_Polished ); + + // signals and slots connections + connect( okButton, SIGNAL( clicked() ), this, SLOT( updateBrightness() ) ); + connect( brightnessSlider, SIGNAL( valueChanged(int) ), this, SLOT( updateValue(int) ) ); +} + +/* + * Destroys the object and frees any allocated resources + */ +BrightnessChooser::~BrightnessChooser() +{ + // no need to delete child widgets, Qt does it all for us +} + +/* + * Sets the strings of the subwidgets using the current + * language. + */ +void BrightnessChooser::languageChange() +{ + setCaption( tr2i18n( "Form1" ) ); + valueLabel->setText( tr2i18n( "0" ) ); + QToolTip::add( brightnessSlider, tr2i18n( "set the brightness and click OK or press ENTER" ) ); + okButton->setText( tr2i18n( "&OK" ) ); + okButton->setAccel( QKeySequence( tr2i18n( "Alt+O" ) ) ); +} + +void BrightnessChooser::updateBrightness() +{ + qWarning( "BrightnessChooser::updateBrightness(): Not implemented yet" ); +} + +void BrightnessChooser::updateValue(int) +{ + qWarning( "BrightnessChooser::updateValue(int): Not implemented yet" ); +} + +#include "brightnesschooser.moc" diff --git a/src/brightnesschooser.h b/src/brightnesschooser.h new file mode 100644 index 0000000..9d36265 --- /dev/null +++ b/src/brightnesschooser.h @@ -0,0 +1,53 @@ +/**************************************************************************** +** Form interface generated from reading ui file '/home/bettini/work/klcddimmer/src/brightnesschooser.ui' +** +** Created: Sat Feb 24 20:45:57 2007 +** by: The User Interface Compiler ($Id: qt/main.cpp 3.3.7 edited Aug 31 2005 $) +** +** WARNING! All changes made in this file will be lost! +****************************************************************************/ + +#ifndef BRIGHTNESSCHOOSER_H +#define BRIGHTNESSCHOOSER_H + +#include <qvariant.h> +#include <qwidget.h> + +class QVBoxLayout; +class QHBoxLayout; +class QGridLayout; +class QSpacerItem; +class QLabel; +class QSlider; +class QPushButton; + +class BrightnessChooser : public QWidget +{ + Q_OBJECT + +public: + BrightnessChooser( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 ); + ~BrightnessChooser(); + + QLabel* valueLabel; + QSlider* brightnessSlider; + QPushButton* okButton; + +public slots: + virtual void updateBrightness(); + virtual void updateValue(int); + +protected: + QGridLayout* BrightnessChooserLayout; + QGridLayout* layout9; + QHBoxLayout* layout7; + QSpacerItem* spacer1; + QSpacerItem* spacer1_2; + QVBoxLayout* layout5; + +protected slots: + virtual void languageChange(); + +}; + +#endif // BRIGHTNESSCHOOSER_H diff --git a/src/brightnesschooser.ui b/src/brightnesschooser.ui new file mode 100644 index 0000000..4f6524f --- /dev/null +++ b/src/brightnesschooser.ui @@ -0,0 +1,154 @@ +<!DOCTYPE UI><UI version="3.3" stdsetdef="1"> +<class>BrightnessChooser</class> +<widget class="QWidget"> + <property name="name"> + <cstring>BrightnessChooser</cstring> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>124</width> + <height>163</height> + </rect> + </property> + <property name="caption"> + <string>Form1</string> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QLayoutWidget" row="0" column="0"> + <property name="name"> + <cstring>layout9</cstring> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QLayoutWidget" row="0" column="0"> + <property name="name"> + <cstring>layout7</cstring> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>0</number> + </property> + <property name="spacing"> + <number>0</number> + </property> + <spacer> + <property name="name"> + <cstring>spacer1</cstring> + </property> + <property name="orientation"> + <enum>Horizontal</enum> + </property> + <property name="sizeType"> + <enum>Minimum</enum> + </property> + <property name="sizeHint"> + <size> + <width>20</width> + <height>20</height> + </size> + </property> + </spacer> + <widget class="QLayoutWidget"> + <property name="name"> + <cstring>layout5</cstring> + </property> + <vbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QLabel"> + <property name="name"> + <cstring>valueLabel</cstring> + </property> + <property name="text"> + <string>0</string> + </property> + <property name="alignment"> + <set>AlignCenter</set> + </property> + </widget> + <widget class="QSlider"> + <property name="name"> + <cstring>brightnessSlider</cstring> + </property> + <property name="orientation"> + <enum>Vertical</enum> + </property> + <property name="toolTip" stdset="0"> + <string>set the brightness and click OK or press ENTER</string> + </property> + </widget> + </vbox> + </widget> + <spacer> + <property name="name"> + <cstring>spacer1_2</cstring> + </property> + <property name="orientation"> + <enum>Horizontal</enum> + </property> + <property name="sizeType"> + <enum>Minimum</enum> + </property> + <property name="sizeHint"> + <size> + <width>16</width> + <height>20</height> + </size> + </property> + </spacer> + </hbox> + </widget> + <widget class="QPushButton" row="1" column="0"> + <property name="name"> + <cstring>okButton</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>1</hsizetype> + <vsizetype>1</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>&OK</string> + </property> + <property name="accel"> + <string>Alt+O</string> + </property> + </widget> + </grid> + </widget> + </grid> +</widget> +<connections> + <connection> + <sender>okButton</sender> + <signal>clicked()</signal> + <receiver>BrightnessChooser</receiver> + <slot>updateBrightness()</slot> + </connection> + <connection> + <sender>brightnessSlider</sender> + <signal>valueChanged(int)</signal> + <receiver>BrightnessChooser</receiver> + <slot>updateValue(int)</slot> + </connection> +</connections> +<slots> + <slot>updateBrightness()</slot> + <slot>updateValue(int)</slot> +</slots> +<layoutdefaults spacing="6" margin="11"/> +</UI> diff --git a/src/brightnesschooserimpl.cpp b/src/brightnesschooserimpl.cpp new file mode 100644 index 0000000..30fed3e --- /dev/null +++ b/src/brightnesschooserimpl.cpp @@ -0,0 +1,217 @@ +/*************************************************************************** + * Copyright (C) 2005 by Lorenzo Bettini * + * http://www.lorenzobettini.it * + * * + * 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., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#include "brightnesschooserimpl.h" + +#include <qprocess.h> +#include <qslider.h> +#include <qlabel.h> +#include <qmessagebox.h> +#include <kdebug.h> +#include <qevent.h> +#include <qregexp.h> + +#include "preferences.h" + +BrightnessChooserImpl::BrightnessChooserImpl(QWidget *parent, const char *name) + : BrightnessChooser(parent, name), proc(0) +{ + updateSlider(); + + // check whether to restore the previous brightness value + if (Preferences::saveCurrent()) { + kdDebug() << "restore previous brightness value: " << + Preferences::currentValue() << endl; + setValue(Preferences::currentValue()); + } + + valueLabel->setText(getValue()); + brightnessSlider->setFocus(); +} + + +BrightnessChooserImpl::~BrightnessChooserImpl() +{ + // in case save the current brightness setting + if (Preferences::saveCurrent()) { + const QString &val = getValue(); + kdDebug() << "save the current brightness value: " << val << endl; + Preferences::setCurrentValue(val); + Preferences::writeConfig(); + } +} + +void BrightnessChooserImpl::updateSlider() +{ + brightnessSlider->setPageStep(QString(Preferences::step()).toInt()); + brightnessSlider->setLineStep(QString(Preferences::step()).toInt()); + brightnessSlider->setRange(QString(Preferences::minValue()).toInt(), + QString(Preferences::maxValue()).toInt()+1); + valueLabel->setText(getValue()); + kdDebug() << "updateSlider" << endl; + kdDebug() << "program: " << Preferences::program() << endl; + kdDebug() << "min value: " << Preferences::minValue() << endl; + kdDebug() << "max value: " << Preferences::maxValue() << endl; + kdDebug() << "page step: " << brightnessSlider->pageStep() << endl; + kdDebug() << "line step: " << brightnessSlider->lineStep() << endl; +} + +void BrightnessChooserImpl::updateBrightness() +{ + if (proc) + delete proc; // delete the previous instance + + proc = new QProcess(this); + + QString args = Preferences::setArgument(); + args += getValue(); + proc->addArgument( Preferences::program() ); + proc->addArgument( args ); + + connect( proc, SIGNAL(readyReadStdout()), + this, SLOT(readFromStdout()) ); + connect( proc, SIGNAL(readyReadStderr()), + this, SLOT(readFromStderr()) ); + connect( proc, SIGNAL(processExited()), + this, SLOT(procExited()) ); + + if ( !proc->start() ) { + // error handling + QMessageBox::critical( 0, + tr("Fatal error"), + tr("Could not start the brightness adjustment command."), + tr("Quit") ); + } + + QString arguments = proc->arguments().join(" "); + qWarning("%s", arguments.ascii()); +} + +void BrightnessChooserImpl::getBrightness() +{ + QString args = Preferences::getArgument(); + + /* some programs, such as nvclock, do not have a parameter to + get the current brightness; in such case we simply return */ + if (args == "") { + kdDebug() << "the program does not support a get brightness functionality" << endl; + return; + } + + if (proc) + delete proc; // delete the previous instance + + proc = new QProcess(this); + + proc->addArgument( Preferences::program() ); + proc->addArgument( args ); + + connect( proc, SIGNAL(readyReadStdout()), + this, SLOT(readValueFromStdout()) ); + connect( proc, SIGNAL(readyReadStderr()), + this, SLOT(readFromStderr()) ); + connect( proc, SIGNAL(processExited()), + this, SLOT(procExited()) ); + + if ( !proc->start() ) { + // error handling + QMessageBox::critical( 0, + tr("Fatal error"), + tr("Could not start the brightness adjustment command."), + tr("Quit") ); + } + + QString arguments = proc->arguments().join(" "); + qWarning("%s", arguments.ascii()); +} + +void BrightnessChooserImpl::updateValue(int) +{ + valueLabel->setText(getValue()); +} + +void BrightnessChooserImpl::readFromStderr() +{ + // Read and process the data. + // Bear in mind that the data might be output in chunks. + QString out = proc->readStderr(); + qWarning( "%s", out.ascii() ); +} + +void BrightnessChooserImpl::readFromStdout() +{ + // Read and process the data. + // Bear in mind that the data might be output in chunks. + QString out = proc->readStdout(); + qWarning( "%s", out.ascii() ); +} + +void BrightnessChooserImpl::readValueFromStdout() +{ + // Read and process the data. + // Bear in mind that the data might be output in chunks. + QString out = proc->readStdout(); + QRegExp regexp("(\\d+)"); + if (regexp.search(out) > 0) { + QString result = regexp.cap(1); + kdDebug() << "initial slider value: " << brightnessSlider->value() << endl; + kdDebug() << "captured result: " << result << endl; + brightnessSlider->setValue(brightnessSlider->maxValue() - result.toInt()); + kdDebug() << "updated slider value: " << brightnessSlider->value() << endl; + } + qWarning( "%s", out.ascii() ); +} + +void BrightnessChooserImpl::procExited() +{ + qWarning("process terminated"); + + emit valueUpdated(); +} + +const QString BrightnessChooserImpl::getValue() +{ + return QString::number((brightnessSlider->maxValue() - brightnessSlider->value())); +} + +void BrightnessChooserImpl::setValue(const QString &val) +{ + int iVal = brightnessSlider->maxValue() - val.toInt(); + kdDebug() << "set slider value: " << iVal << endl; + brightnessSlider->setValue(iVal); + updateBrightness(); +} + +void BrightnessChooserImpl::keyPressEvent(QKeyEvent *event) +{ + /* intercept ENTER and simulate the OK button; + also intercept ESC in order to close the parent widget (otherwise + ESC is passed to the applet which seems to close the main panel?)*/ + if (event->key() == Qt::Key_Return || event->key() == Qt::Key_Enter) { + kdDebug() << "pressed ENTER" << endl; + updateBrightness(); + } else if (event->key() == Qt::Key_Escape) { + kdDebug() << "pressed ESC" << endl; + parentWidget()->close(); + } else { + BrightnessChooser::keyPressEvent(event); + } +} + +#include "brightnesschooserimpl.moc" diff --git a/src/brightnesschooserimpl.h b/src/brightnesschooserimpl.h new file mode 100644 index 0000000..2bf2fa9 --- /dev/null +++ b/src/brightnesschooserimpl.h @@ -0,0 +1,82 @@ +/*************************************************************************** + * Copyright (C) 2005 by Lorenzo Bettini * + * http://www.lorenzobettini.it * + * * + * 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., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#ifndef BRIGHTNESSCHOOSERIMPL_H +#define BRIGHTNESSCHOOSERIMPL_H + +#include <brightnesschooser.h> + +class QProcess; + +/** +Implementation slots for BrightnessChooser + +@author Lorenzo Bettini, http://www.lorenzobettini.it,, +*/ +class BrightnessChooserImpl : public BrightnessChooser +{ +Q_OBJECT +public: + BrightnessChooserImpl(QWidget *parent = 0, const char *name = 0); + + ~BrightnessChooserImpl(); + + /** + * Updates the slider properties according to the global + * properties. + */ + void updateSlider(); + + /** + * Returns the current value of brightness. + * @return + */ + const QString getValue(); + + /** + * Sets the current value of brightness + * @param val + */ + void setValue(const QString &val); + + /// retrieve the current brightness + void getBrightness(); + + protected slots: + void updateBrightness(); + void updateValue(int); + void readFromStderr(); + void readFromStdout(); + void readValueFromStdout(); + void procExited(); + + private: + /// process instance used to adjust brightness + QProcess *proc; + + signals: + void valueUpdated(); + + protected: + /// to intercept the Enter key press and direct it to OK button + void keyPressEvent( QKeyEvent * ); + +}; + +#endif diff --git a/src/hi16-app-klcddimmer.png b/src/hi16-app-klcddimmer.png Binary files differnew file mode 100644 index 0000000..c15ddb5 --- /dev/null +++ b/src/hi16-app-klcddimmer.png diff --git a/src/hi32-app-klcddimmer.png b/src/hi32-app-klcddimmer.png Binary files differnew file mode 100644 index 0000000..38fc2d5 --- /dev/null +++ b/src/hi32-app-klcddimmer.png diff --git a/src/hi48-app-klcddimmer.png b/src/hi48-app-klcddimmer.png Binary files differnew file mode 100644 index 0000000..721756c --- /dev/null +++ b/src/hi48-app-klcddimmer.png diff --git a/src/klcddimmer.cpp b/src/klcddimmer.cpp new file mode 100644 index 0000000..971c7c1 --- /dev/null +++ b/src/klcddimmer.cpp @@ -0,0 +1,213 @@ +/*************************************************************************** + * Copyright (C) 2005 by Lorenzo Bettini * + * http://www.lorenzobettini.it * + * * + * 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., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#include <qlcdnumber.h> +#include <kglobal.h> +#include <klocale.h> +#include <kconfigdialog.h> +#include <kapplication.h> +#include <kmessagebox.h> +#include <kpopupmenu.h> +#include <kdatetbl.h> // for KPopupFrame +#include <kiconloader.h> +#include <kaboutapplication.h> +#include <qlabel.h> +#include <qframe.h> +#include <kdebug.h> + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "klcddimmer.h" +#include "brightnesschooserimpl.h" +#include "progpreferences.h" +#include "preferences.h" +#include "klcddimmerapplet.h" + + +klcddimmer::klcddimmer(const QString& configFile, Type type, int actions, QWidget *parent, const char *name) + : KPanelApplet(configFile, type, actions, parent, name), + mBrightnessChooserFrame(0) +{ + // Get the current application configuration handle + ksConfig = config(); + + /* + QLCDNumber *w = new QLCDNumber(this); + w->display(42); + */ + + // this is the popup windows that is shown when the left button is pressed + mBrightnessChooserFrame = new KPopupFrame(this); + //mBrightnessChooserFrame = new QWidget + // (this, "klcddimmer popup", WStyle_Customize | WType_Popup | Qt::WStyle_DialogBorder); + chooser = new BrightnessChooserImpl(mBrightnessChooserFrame); + mBrightnessChooserFrame->setMainWidget(chooser); + mBrightnessChooserFrame->resize(chooser->size()); + + connect(chooser, SIGNAL(valueUpdated()), this, SLOT(valueUpdate())); + + initContextMenu(); + + /* + QFrame *w = new QFrame(this); + valueLabel = new QLabel(w); + valueLabel->setText(chooser->getValue()); + */ + + klcddimmerView = new KlcdDimmerApplet(this); + mainView = klcddimmerView; + + // klcddimmerView->brightnessIcon->setPixmap(SmallIcon("klcddimmer")); + klcddimmerView->setBrightnessLevel(chooser->getValue()); + //klcddimmerView->resize( QSize(122, 48).expandedTo(minimumSizeHint()) ); + + mainView->show(); + + /* get the current value */ + chooser->getBrightness(); +} + + +klcddimmer::~klcddimmer() +{ +} + + +void klcddimmer::about() +{ + //KMessageBox::information(0, i18n("This is an about box")); + + KAboutData aboutData("KLcdDimmer", "KLcdDimmer", VERSION, + I18N_NOOP("Applet for LCD brightness adjustment"), KAboutData::License_GPL_V2); + aboutData.addAuthor("Lorenzo Bettini", "main author", "", + "http://www.lorenzobettini.it"); + aboutData.setHomepage("http://klcddimmer.sourceforge.net"); + aboutData.setCustomAuthorText("please use http://sourceforge.net/projects/klcddimmer to report bugs", + "please use <a href=http://sourceforge.net/projects/klcddimmer>http://sourceforge.net/projects/klcddimmer</a> to report bugs"); + KAboutApplication about(&aboutData, this, 0); + about.setProgramLogo( KGlobal::instance()->iconLoader()->iconPath( "klcddimmer", -KIcon::SizeLarge ) ); + about.exec(); +} + + +void klcddimmer::help() +{ + KMessageBox::information(0, i18n("This is a help box")); +} + + +void klcddimmer::preferences() +{ + KConfigDialog dialog( this, "settings", Preferences::self() ); + + ProgPreferences *preferences = new ProgPreferences(0, "Program"); + dialog.addPage(preferences, i18n("Program"), "wizard"); + + if (dialog.exec()) + { + chooser->updateSlider(); + } +} + +/* +int klcddimmer::widthForHeight(int height) const +{ + return klcddimmerView->width(); +} + +int klcddimmer::heightForWidth(int width) const +{ + return klcddimmerView->height(); +} +*/ + +int klcddimmer::widthForHeight( int height ) const +{ + // kdDebug() << "icon sizeHint: " << klcddimmerView->brightnessIcon->sizeHint() << endl; + // kdDebug() << "text sizeHint: " << klcddimmerView->brightnessLevel->sizeHint() << endl; + + return height; +} + +int klcddimmer::heightForWidth( int width ) const +{ + // kdDebug() << "icon sizeHint: " << klcddimmerView->brightnessIcon->sizeHint() << endl; + // kdDebug() << "text sizeHint: " << klcddimmerView->brightnessLevel->sizeHint() << endl; + + return width; +} + + +void klcddimmer::resizeEvent(QResizeEvent *e) +{ + klcddimmerView->resize(this->width(),this->height()); +} + +void klcddimmer::initContextMenu() +{ + mContextMenu = new KPopupMenu(this); + //mContextMenu->insertItem(SmallIcon("reload"), i18n("&Update Now"), + // this, SLOT(slotUpdateNow()), 0, -1, 2); + mContextMenu->insertSeparator(); + mContextMenu->insertItem(SmallIcon("klcddimmer"), i18n("&About KLcdDimmer"), this, SLOT(about())); + mContextMenu->insertItem(SmallIcon("configure"), + i18n("&Configure KLcdDimmer..."), this, SLOT(preferences())); + setCustomMenu(mContextMenu); +} + +void klcddimmer::mousePressEvent(QMouseEvent *e) +{ + if ( e->button() == LeftButton ) + { + if (!mBrightnessChooserFrame->isShown()) { + mBrightnessChooserFrame->popup(e->globalPos()); + } + } + else if ( e->button() != RightButton ) + { + KPanelApplet::mousePressEvent( e ); + return; + } + else // must be right button + { + mContextMenu->exec(e->globalPos()); + } +} + +void klcddimmer::valueUpdate() +{ + kdDebug() << "updated value: " << chooser->getValue() << endl; + klcddimmerView->setBrightnessLevel(chooser->getValue()); +} + +extern "C" +{ + KPanelApplet* init( QWidget *parent, const QString& configFile) + { + KGlobal::locale()->insertCatalogue("klcddimmer"); + return new klcddimmer(configFile, KPanelApplet::Normal, + KPanelApplet::About | KPanelApplet::Help | KPanelApplet::Preferences, + parent, "klcddimmer"); + } +} + + diff --git a/src/klcddimmer.desktop b/src/klcddimmer.desktop new file mode 100644 index 0000000..1c51f72 --- /dev/null +++ b/src/klcddimmer.desktop @@ -0,0 +1,34 @@ +[Desktop Entry] +Encoding=UTF-8 +Comment=A KDE panel applet to set brightness of LCD screen +Comment[br]=Un arloadig panell a vez graet klcddimmer +Comment[ca]=Un applet del plafó anomenat klcddimmer +Comment[cy]=Rhaglennig panel o'r enw klcddimmer +Comment[da]=En panel-applet der hedder klcddimmer +Comment[de]=Ein Miniprogramm mit dem Namen klcddimmer +Comment[es]=Un applet del panel llamado klcddimmer +Comment[et]=Paneeliaplett nimega klcddimmer +Comment[eu]=klcddimmer izeneko panel applet bat +Comment[fr]=Un applet pour le tableau de bord nommé klcddimmer +Comment[hi]=एक फलक ऐपलेट जो कहलाता है- klcddimmer +Comment[hu]=klcddimmer nevű panel-kisalkalmazás +Comment[is]=Spjaldforritlingur nefndur klcddimmer +Comment[it]=Un applet per il pannello chiamata klcddimmer +Comment[ja]=klcddimmer と呼ばれるパネルアプレット +Comment[nb]=Et panelprogram som heter klcddimmer +Comment[nl]=Een paneel-applet met naam klcddimmer +Comment[pl]=Aplet panelu o nazwie klcddimmer +Comment[pt]=Um 'applet' para o painel chamado klcddimmer +Comment[pt_BR]=Uma applet de painel chamada klcddimmer +Comment[ru]=Апплет панели klcddimmer +Comment[sl]=Pultni vstavek z imenom klcddimmer +Comment[sr]=Панелни аплет по имену klcddimmer +Comment[sr@Latn]=Panelni aplet po imenu klcddimmer +Comment[sv]=Ett panelminiprogram som kallas klcddimmer +Comment[ta]=ஒரு பானல் ஆப்லெட் klcddimmer என்ற்உ அழைக்கப்படுகிறது +Comment[tg]=Пайраҳаи апплети klcddimmer +Comment[zh_CN]=一个称作klcddimmer的面板小程序 +Name=klcddimmer +Icon=klcddimmer +X-KDE-Library=klcddimmer_panelapplet +X-KDE-UniqueApplet = false diff --git a/src/klcddimmer.h b/src/klcddimmer.h new file mode 100644 index 0000000..d8ee218 --- /dev/null +++ b/src/klcddimmer.h @@ -0,0 +1,146 @@ +/*************************************************************************** + * Copyright (C) 2005 by Lorenzo Bettini * + * http://www.lorenzobettini.it * + * * + * 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., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#ifndef KLCDDIMMER_H +#define KLCDDIMMER_H + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include <kpanelapplet.h> +#include <qstring.h> +#include <kconfig.h> + +class KPopupMenu; +class BrightnessChooserImpl; +class KPopupFrame; +class KlcdDimmerApplet; + +class klcddimmer : public KPanelApplet +{ + Q_OBJECT + +public: + /** + * Construct a @ref KPanelApplet just like any other widget. + * + * @param configFile The configFile handed over in the factory function. + * @param Type The applet @ref type(). + * @param actions Standard RMB menu actions supported by the applet (see @ref action() ). + * @param parent The pointer to the parent widget handed over in the factory function. + * @param name A Qt object name for your applet. + **/ + klcddimmer(const QString& configFile, Type t = Normal, int actions = 0, + QWidget *parent = 0, const char *name = 0); + /** destructor */ + ~klcddimmer(); + + /** + * Retrieve a suggested width for a given height. + * + * Every applet should reimplement this function. + * + * Depending on the panel orientation the height (horizontal panel) or the + * width (vertical panel) of the applets is fixed. + * The exact values of the fixed size component depend on the panel size. + * + * On a horizontal panel the applet height is fixed, the panel will + * call @ref widthForHeight(int height) with @p height + * equal to 'the fixed applet height' + * when laying out the applets. + * + * The applet can now choose the other size component (width) + * based on the given height. + * + * The width you return is granted. + **/ + virtual int widthForHeight(int height) const; + /** + * @return A suggested height for a given width. + * + * Every applet should reimplement this function. + * + * Depending on the panel orientation the height (horizontal panel) or the + * width (vertical panel) of the applets is fixed. + * The exact values of the fixed size component depend on the panel size. + * + * On a vertical panel the applet width is fixed, the panel will + * call @ref heightForWidth(int width) with @p width + * equal to 'the fixed applet width' + * when laying out the applets. + * + * The applet can now choose the other size component (height) + * based on the given width. + * + * The height you return is granted. + **/ + virtual int heightForWidth(int width) const; + /** + * Is called when the user selects "About" from the applets RMB menu. + * Reimplement this function to launch a about dialog. + * + * Note that this is called only when your applet supports the About action. + * See @ref Action and @ref KPanelApplet(). + **/ + + public slots: + virtual void about(); + /** + * Is called when the user selects "Help" from the applets RMB menu. + * Reimplement this function to launch a manual or help page. + * + * Note that this is called only when your applet supports the Help action. + * See @ref Action and @ref KPanelApplet(). + **/ + virtual void help(); + /** + * Is called when the user selects "Preferences" from the applets RMB menu. + * Reimplement this function to launch a preferences dialog or kcontrol module. + * + * Note that this is called only when your applet supports the preferences action. + * See @ref Action and @ref KPanelApplet(). + **/ + virtual void preferences(); + /** + * It is called when the brightness value has been updated. + */ + virtual void valueUpdate(); + +protected: + void resizeEvent(QResizeEvent *); + void mousePressEvent(QMouseEvent *e); + +private: + KConfig *ksConfig; + QWidget *mainView; + KPopupMenu *mContextMenu; + KPopupFrame *mBrightnessChooserFrame; + BrightnessChooserImpl *chooser; + KlcdDimmerApplet *klcddimmerView; + +private: // Private methods + /** + * Initializes the context menu + */ + void initContextMenu(); +}; + +#endif diff --git a/src/klcddimmer.lsm b/src/klcddimmer.lsm new file mode 100644 index 0000000..fc0f472 --- /dev/null +++ b/src/klcddimmer.lsm @@ -0,0 +1,16 @@ +Begin3 +Title: klcddimmer -- Some description +Version: 0.1 +Entered-date: +Description: +Keywords: KDE Qt +Author: Lorenzo Bettini, http://www.lorenzobettini.it,, +Maintained-by: Lorenzo Bettini, http://www.lorenzobettini.it,, +Home-page: +Alternate-site: +Primary-site: ftp://ftp.kde.org/pub/kde/unstable/apps/utils + xxxxxx klcddimmer-0.1.tar.gz + xxx klcddimmer-0.1.lsm +Platform: Linux. Needs KDE +Copying-policy: Custom +End diff --git a/src/klcddimmer.svg b/src/klcddimmer.svg new file mode 100644 index 0000000..4388204 --- /dev/null +++ b/src/klcddimmer.svg @@ -0,0 +1,154 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<!-- Created with Inkscape (http://www.inkscape.org/) --> +<svg + xmlns:dc="http://purl.org/dc/elements/1.1/" + xmlns:cc="http://web.resource.org/cc/" + xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" + xmlns:svg="http://www.w3.org/2000/svg" + xmlns="http://www.w3.org/2000/svg" + xmlns:xlink="http://www.w3.org/1999/xlink" + xmlns:sodipodi="http://inkscape.sourceforge.net/DTD/sodipodi-0.dtd" + xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" + width="744.09448819" + height="1052.3622047" + id="svg2" + sodipodi:version="0.32" + inkscape:version="0.42.2" + sodipodi:docbase="/home/bettini/tmp" + sodipodi:docname="klcddimmer.svg"> + <defs + id="defs4"> + <linearGradient + id="linearGradient6681"> + <stop + style="stop-color:#1d2c9e;stop-opacity:1.0000000;" + offset="0.0000000" + id="stop6683" /> + <stop + style="stop-color:#0e739e;stop-opacity:0;" + offset="1" + id="stop6685" /> + </linearGradient> + <linearGradient + id="linearGradient5206"> + <stop + style="stop-color:#fff600;stop-opacity:1;" + offset="0" + id="stop5208" /> + <stop + style="stop-color:#fff600;stop-opacity:0;" + offset="1" + id="stop5210" /> + </linearGradient> + <linearGradient + id="linearGradient5198"> + <stop + style="stop-color:#000000;stop-opacity:1;" + offset="0" + id="stop5200" /> + <stop + style="stop-color:#000000;stop-opacity:0;" + offset="1" + id="stop5202" /> + </linearGradient> + <linearGradient + id="linearGradient2060"> + <stop + style="stop-color:#000000;stop-opacity:1;" + offset="0" + id="stop2062" /> + <stop + style="stop-color:#000000;stop-opacity:0;" + offset="1" + id="stop2064" /> + </linearGradient> + <radialGradient + inkscape:collect="always" + xlink:href="#linearGradient5198" + id="radialGradient5204" + cx="213.71428" + cy="280.93362" + fx="213.71428" + fy="280.93362" + r="71.928574" + gradientUnits="userSpaceOnUse" /> + <radialGradient + inkscape:collect="always" + xlink:href="#linearGradient5206" + id="radialGradient5212" + cx="213.71428" + cy="280.93362" + fx="213.71428" + fy="280.93362" + r="71.928574" + gradientUnits="userSpaceOnUse" /> + <linearGradient + inkscape:collect="always" + xlink:href="#linearGradient6681" + id="linearGradient6689" + x1="422.69739" + y1="277.47690" + x2="483.50323" + y2="277.47690" + gradientUnits="userSpaceOnUse" /> + </defs> + <sodipodi:namedview + id="base" + pagecolor="#ffffff" + bordercolor="#666666" + borderopacity="1.0" + inkscape:pageopacity="0.0" + inkscape:pageshadow="2" + inkscape:zoom="1.0000000" + inkscape:cx="375.00000" + inkscape:cy="523.84790" + inkscape:document-units="px" + inkscape:current-layer="layer1" + inkscape:window-width="1273" + inkscape:window-height="944" + inkscape:window-x="0" + inkscape:window-y="46" /> + <metadata + id="metadata7"> + <rdf:RDF> + <cc:Work + rdf:about=""> + <dc:format>image/svg+xml</dc:format> + <dc:type + rdf:resource="http://purl.org/dc/dcmitype/StillImage" /> + </cc:Work> + </rdf:RDF> + </metadata> + <g + inkscape:label="Layer 1" + inkscape:groupmode="layer" + id="layer1"> + <path + sodipodi:type="arc" + style="fill:url(#radialGradient5212);fill-opacity:1.0;fill-rule:evenodd;stroke:url(#radialGradient5204);stroke-width:1.0000000px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1.0000000;opacity:1.0000000" + id="path1314" + sodipodi:cx="245.71428" + sodipodi:cy="280.93362" + sodipodi:rx="71.428574" + sodipodi:ry="71.428574" + d="M 317.14285 280.93362 A 71.428574 71.428574 0 1 1 174.28571,280.93362 A 71.428574 71.428574 0 1 1 317.14285 280.93362 z" + inkscape:export-xdpi="90.000000" + inkscape:export-ydpi="90.000000" + inkscape:export-filename="/home/bettini/tmp/path5943.png" /> + <path + sodipodi:type="arc" + style="opacity:1.0000000;fill:url(#linearGradient6689);fill-opacity:1.0000000;fill-rule:evenodd;stroke:#000000;stroke-width:0.99968761;stroke-miterlimit:4.0000000;stroke-dasharray:none;stroke-opacity:0.0000000" + id="path5943" + sodipodi:cx="424.00000" + sodipodi:cy="277.36218" + sodipodi:rx="59.000000" + sodipodi:ry="60.000000" + d="M 429.15265,217.59143 A 59.000000,60.000000 0 0 1 423.19738,337.35663" + sodipodi:start="4.7998334" + sodipodi:end="7.8675857" + sodipodi:open="true" + transform="matrix(1.228777,-6.370894e-2,5.618174e-2,1.180589,-292.2493,-20.31316)" + inkscape:export-xdpi="90.000000" + inkscape:export-ydpi="90.000000" /> + </g> +</svg> diff --git a/src/klcddimmerapplet.cpp b/src/klcddimmerapplet.cpp new file mode 100644 index 0000000..2c64bfb --- /dev/null +++ b/src/klcddimmerapplet.cpp @@ -0,0 +1,57 @@ +/*************************************************************************** + * Copyright (C) 2005 by Lorenzo Bettini * + * http://www.lorenzobettini.it * + * * + * 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., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#include "klcddimmerapplet.h" + +#include <qpixmap.h> +#include <qlabel.h> +#include <kiconloader.h> +#include <qlayout.h> + +KlcdDimmerApplet::KlcdDimmerApplet(QWidget *parent, const char *name) + : QWidget(parent, name) +{ + // the icon and the text will be aligned vertically centered + layout = new QVBoxLayout(this); + + brightnessIcon = new QLabel(this); + brightnessIcon->setAlignment(AlignCenter); + brightnessIcon->setBackgroundOrigin(AncestorOrigin); + brightnessLevel = new QLabel(this); + brightnessLevel->setAlignment(AlignCenter); + // use the same background of the panel + brightnessLevel->setBackgroundOrigin(AncestorOrigin); + + layout->addWidget(brightnessIcon); + layout->addWidget(brightnessLevel); + + brightnessIcon->setPixmap(SmallIcon("klcddimmer")); +} + + +KlcdDimmerApplet::~KlcdDimmerApplet() +{ +} + +void KlcdDimmerApplet::setBrightnessLevel(const QString &level) +{ + brightnessLevel->setText(level); +} + +#include "klcddimmerapplet.moc" diff --git a/src/klcddimmerapplet.h b/src/klcddimmerapplet.h new file mode 100644 index 0000000..2e5067b --- /dev/null +++ b/src/klcddimmerapplet.h @@ -0,0 +1,50 @@ +/*************************************************************************** + * Copyright (C) 2005 by Lorenzo Bettini * + * http://www.lorenzobettini.it * + * * + * 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., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#ifndef KLCDDIMMERAPPLET_H +#define KLCDDIMMERAPPLET_H + +#include <qwidget.h> + +class QLabel; +class QBoxLayout; + +/** + * The actual graphical representation for KlcdDimmer + * @author Lorenzo Bettini, http://www.lorenzobettini.it,, +*/ +class KlcdDimmerApplet : public QWidget +{ + Q_OBJECT + +public: + KlcdDimmerApplet(QWidget *parent=0, const char *name=0); + + ~KlcdDimmerApplet(); + + void setBrightnessLevel(const QString &level); + + protected: + QLabel* brightnessLevel; + QLabel* brightnessIcon; + + QBoxLayout *layout; +}; + +#endif diff --git a/src/preferences.cpp b/src/preferences.cpp new file mode 100644 index 0000000..11bc28d --- /dev/null +++ b/src/preferences.cpp @@ -0,0 +1,58 @@ +// This file is generated by kconfig_compiler from preferences.kcfg. +// All changes you do to this file will be lost. + +#include "preferences.h" + +#include <kstaticdeleter.h> + +Preferences *Preferences::mSelf = 0; +static KStaticDeleter<Preferences> staticPreferencesDeleter; + +Preferences *Preferences::self() +{ + if ( !mSelf ) { + staticPreferencesDeleter.setObject( mSelf, new Preferences() ); + mSelf->readConfig(); + } + + return mSelf; +} + +Preferences::Preferences( ) + : KConfigSkeleton( QString::fromLatin1( "klcddimmerrc" ) ) +{ + mSelf = this; + setCurrentGroup( QString::fromLatin1( "general" ) ); + + KConfigSkeleton::ItemString *itemProgram; + itemProgram = new KConfigSkeleton::ItemString( currentGroup(), QString::fromLatin1( "Program" ), mProgram, QString::fromLatin1( "smartdimmer" ) ); + addItem( itemProgram, QString::fromLatin1( "Program" ) ); + KConfigSkeleton::ItemString *itemSetArgument; + itemSetArgument = new KConfigSkeleton::ItemString( currentGroup(), QString::fromLatin1( "SetArgument" ), mSetArgument, QString::fromLatin1( "-s" ) ); + addItem( itemSetArgument, QString::fromLatin1( "SetArgument" ) ); + KConfigSkeleton::ItemString *itemGetArgument; + itemGetArgument = new KConfigSkeleton::ItemString( currentGroup(), QString::fromLatin1( "GetArgument" ), mGetArgument, QString::fromLatin1( "-g" ) ); + addItem( itemGetArgument, QString::fromLatin1( "GetArgument" ) ); + KConfigSkeleton::ItemString *itemMinValue; + itemMinValue = new KConfigSkeleton::ItemString( currentGroup(), QString::fromLatin1( "MinValue" ), mMinValue, QString::fromLatin1( "1" ) ); + addItem( itemMinValue, QString::fromLatin1( "MinValue" ) ); + KConfigSkeleton::ItemString *itemMaxValue; + itemMaxValue = new KConfigSkeleton::ItemString( currentGroup(), QString::fromLatin1( "MaxValue" ), mMaxValue, QString::fromLatin1( "21" ) ); + addItem( itemMaxValue, QString::fromLatin1( "MaxValue" ) ); + KConfigSkeleton::ItemString *itemStep; + itemStep = new KConfigSkeleton::ItemString( currentGroup(), QString::fromLatin1( "Step" ), mStep, QString::fromLatin1( "1" ) ); + addItem( itemStep, QString::fromLatin1( "Step" ) ); + KConfigSkeleton::ItemBool *itemSaveCurrent; + itemSaveCurrent = new KConfigSkeleton::ItemBool( currentGroup(), QString::fromLatin1( "SaveCurrent" ), mSaveCurrent, false ); + addItem( itemSaveCurrent, QString::fromLatin1( "SaveCurrent" ) ); + KConfigSkeleton::ItemString *itemCurrentValue; + itemCurrentValue = new KConfigSkeleton::ItemString( currentGroup(), QString::fromLatin1( "CurrentValue" ), mCurrentValue ); + addItem( itemCurrentValue, QString::fromLatin1( "CurrentValue" ) ); +} + +Preferences::~Preferences() +{ + if ( mSelf == this ) + staticPreferencesDeleter.setObject( mSelf, 0, false ); +} + diff --git a/src/preferences.h b/src/preferences.h new file mode 100644 index 0000000..7966ccc --- /dev/null +++ b/src/preferences.h @@ -0,0 +1,192 @@ +// This file is generated by kconfig_compiler from preferences.kcfg. +// All changes you do to this file will be lost. +#ifndef PREFERENCES_H +#define PREFERENCES_H + +#include <kconfigskeleton.h> +#include <kdebug.h> + +class Preferences : public KConfigSkeleton +{ + public: + + static Preferences *self(); + ~Preferences(); + + /** + Set program to adjust lcd brightness + */ + static + void setProgram( const QString & v ) + { + if (!self()->isImmutable( QString::fromLatin1( "Program" ) )) + self()->mProgram = v; + } + + /** + Get program to adjust lcd brightness + */ + static + QString program() + { + return self()->mProgram; + } + + /** + Set argument to set the brighness + */ + static + void setSetArgument( const QString & v ) + { + if (!self()->isImmutable( QString::fromLatin1( "SetArgument" ) )) + self()->mSetArgument = v; + } + + /** + Get argument to set the brighness + */ + static + QString setArgument() + { + return self()->mSetArgument; + } + + /** + Set argument to get the brighness + */ + static + void setGetArgument( const QString & v ) + { + if (!self()->isImmutable( QString::fromLatin1( "GetArgument" ) )) + self()->mGetArgument = v; + } + + /** + Get argument to get the brighness + */ + static + QString getArgument() + { + return self()->mGetArgument; + } + + /** + Set minimum value for brightness + */ + static + void setMinValue( const QString & v ) + { + if (!self()->isImmutable( QString::fromLatin1( "MinValue" ) )) + self()->mMinValue = v; + } + + /** + Get minimum value for brightness + */ + static + QString minValue() + { + return self()->mMinValue; + } + + /** + Set maximum value for brightness + */ + static + void setMaxValue( const QString & v ) + { + if (!self()->isImmutable( QString::fromLatin1( "MaxValue" ) )) + self()->mMaxValue = v; + } + + /** + Get maximum value for brightness + */ + static + QString maxValue() + { + return self()->mMaxValue; + } + + /** + Set step to increment + */ + static + void setStep( const QString & v ) + { + if (!self()->isImmutable( QString::fromLatin1( "Step" ) )) + self()->mStep = v; + } + + /** + Get step to increment + */ + static + QString step() + { + return self()->mStep; + } + + /** + Set save the current value + */ + static + void setSaveCurrent( bool v ) + { + if (!self()->isImmutable( QString::fromLatin1( "SaveCurrent" ) )) + self()->mSaveCurrent = v; + } + + /** + Get save the current value + */ + static + bool saveCurrent() + { + return self()->mSaveCurrent; + } + + /** + Set the current brightness value + */ + static + void setCurrentValue( const QString & v ) + { + if (!self()->isImmutable( QString::fromLatin1( "CurrentValue" ) )) + self()->mCurrentValue = v; + } + + /** + Get the current brightness value + */ + static + QString currentValue() + { + return self()->mCurrentValue; + } + + static + void writeConfig() + { + static_cast<KConfigSkeleton*>(self())->writeConfig(); + } + protected: + Preferences(); + static Preferences *mSelf; + + + // general + QString mProgram; + QString mSetArgument; + QString mGetArgument; + QString mMinValue; + QString mMaxValue; + QString mStep; + bool mSaveCurrent; + QString mCurrentValue; + + private: +}; + +#endif + diff --git a/src/preferences.kcfg b/src/preferences.kcfg new file mode 100644 index 0000000..f8b3f35 --- /dev/null +++ b/src/preferences.kcfg @@ -0,0 +1,38 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE kcfg SYSTEM "http://www.kde.org/standards/kcfg/1.0/kcfg.dtd"> +<kcfg> + <kcfgfile name="klcddimmerrc"/> + <group name="general"> + <entry name="Program" type="String"> + <label>program to adjust lcd brightness</label> + <default>smartdimmer</default> + </entry> + <entry name="SetArgument" type="String"> + <label>argument to set the brighness</label> + <default>-s</default> + </entry> + <entry name="GetArgument" type="String"> + <label>argument to get the brighness</label> + <default>-g</default> + </entry> + <entry name="MinValue" type="String"> + <label>minimum value for brightness</label> + <default>1</default> + </entry> + <entry name="MaxValue" type="String"> + <label>maximum value for brightness</label> + <default>21</default> + </entry> + <entry name="Step" type="String"> + <label>step to increment</label> + <default>1</default> + </entry> + <entry name="SaveCurrent" type="Bool"> + <label>save the current value</label> + <default>false</default> + </entry> + <entry name="CurrentValue" type="String"> + <label>the current brightness value</label> + </entry> + </group> +</kcfg>
\ No newline at end of file diff --git a/src/preferences.kcfgc b/src/preferences.kcfgc new file mode 100644 index 0000000..72efbfa --- /dev/null +++ b/src/preferences.kcfgc @@ -0,0 +1,4 @@ +File=preferences.kcfg +ClassName=Preferences +Singleton=true +Mutators=true
\ No newline at end of file diff --git a/src/progpreferences.cpp b/src/progpreferences.cpp new file mode 100644 index 0000000..0070f19 --- /dev/null +++ b/src/progpreferences.cpp @@ -0,0 +1,152 @@ +#include <kdialog.h> +#include <klocale.h> +/**************************************************************************** +** Form implementation generated from reading ui file '/home/bettini/work/klcddimmer/src/progpreferences.ui' +** +** Created: Sat Feb 24 20:45:58 2007 +** by: The User Interface Compiler ($Id: qt/main.cpp 3.3.7 edited Aug 31 2005 $) +** +** WARNING! All changes made in this file will be lost! +****************************************************************************/ + +#include "progpreferences.h" + +#include <qvariant.h> +#include <qpushbutton.h> +#include <qlabel.h> +#include <qlineedit.h> +#include <knuminput.h> +#include <qcheckbox.h> +#include <qlayout.h> +#include <qtooltip.h> +#include <qwhatsthis.h> + +/* + * Constructs a ProgPreferences as a child of 'parent', with the + * name 'name' and widget flags set to 'f'. + */ +ProgPreferences::ProgPreferences( QWidget* parent, const char* name, WFlags fl ) + : QWidget( parent, name, fl ) +{ + if ( !name ) + setName( "ProgPreferences" ); + ProgPreferencesLayout = new QGridLayout( this, 1, 1, 11, 6, "ProgPreferencesLayout"); + + layout11 = new QVBoxLayout( 0, 0, 6, "layout11"); + + layout2 = new QHBoxLayout( 0, 0, 6, "layout2"); + + textLabel1 = new QLabel( this, "textLabel1" ); + layout2->addWidget( textLabel1 ); + + kcfg_Program = new QLineEdit( this, "kcfg_Program" ); + layout2->addWidget( kcfg_Program ); + layout11->addLayout( layout2 ); + + layout3 = new QHBoxLayout( 0, 0, 6, "layout3"); + + textLabel2 = new QLabel( this, "textLabel2" ); + layout3->addWidget( textLabel2 ); + + kcfg_SetArgument = new QLineEdit( this, "kcfg_SetArgument" ); + layout3->addWidget( kcfg_SetArgument ); + layout11->addLayout( layout3 ); + + layout3_2 = new QHBoxLayout( 0, 0, 6, "layout3_2"); + + textLabel2_2 = new QLabel( this, "textLabel2_2" ); + layout3_2->addWidget( textLabel2_2 ); + + kcfg_GetArgument = new QLineEdit( this, "kcfg_GetArgument" ); + layout3_2->addWidget( kcfg_GetArgument ); + layout11->addLayout( layout3_2 ); + + layout7 = new QHBoxLayout( 0, 0, 6, "layout7"); + + textLabel3 = new QLabel( this, "textLabel3" ); + layout7->addWidget( textLabel3 ); + spacer1 = new QSpacerItem( 40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum ); + layout7->addItem( spacer1 ); + + kcfg_MinValue = new KIntNumInput( this, "kcfg_MinValue" ); + layout7->addWidget( kcfg_MinValue ); + layout11->addLayout( layout7 ); + + layout7_2 = new QHBoxLayout( 0, 0, 6, "layout7_2"); + + textLabel3_2 = new QLabel( this, "textLabel3_2" ); + layout7_2->addWidget( textLabel3_2 ); + spacer1_2 = new QSpacerItem( 40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum ); + layout7_2->addItem( spacer1_2 ); + + kcfg_MaxValue = new KIntNumInput( this, "kcfg_MaxValue" ); + layout7_2->addWidget( kcfg_MaxValue ); + layout11->addLayout( layout7_2 ); + + layout7_2_2 = new QHBoxLayout( 0, 0, 6, "layout7_2_2"); + + textLabel3_2_2 = new QLabel( this, "textLabel3_2_2" ); + layout7_2_2->addWidget( textLabel3_2_2 ); + spacer1_2_2 = new QSpacerItem( 40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum ); + layout7_2_2->addItem( spacer1_2_2 ); + + kcfg_Step = new KIntNumInput( this, "kcfg_Step" ); + layout7_2_2->addWidget( kcfg_Step ); + layout11->addLayout( layout7_2_2 ); + + kcfg_SaveCurrent = new QCheckBox( this, "kcfg_SaveCurrent" ); + layout11->addWidget( kcfg_SaveCurrent ); + + ProgPreferencesLayout->addLayout( layout11, 0, 0 ); + languageChange(); + resize( QSize(600, 480).expandedTo(minimumSizeHint()) ); + clearWState( WState_Polished ); +} + +/* + * Destroys the object and frees any allocated resources + */ +ProgPreferences::~ProgPreferences() +{ + // no need to delete child widgets, Qt does it all for us +} + +/* + * Sets the strings of the subwidgets using the current + * language. + */ +void ProgPreferences::languageChange() +{ + setCaption( tr2i18n( "Form1" ) ); + textLabel1->setText( tr2i18n( "program" ) ); + QToolTip::add( kcfg_Program, tr2i18n( "the program to set the brightness" ) ); + QWhatsThis::add( kcfg_Program, tr2i18n( "the program to set the brightness" ) ); + textLabel2->setText( tr2i18n( "set argument" ) ); + QToolTip::add( kcfg_SetArgument, tr2i18n( "the argument to pass to the program<br>to set the brightness" ) ); + QWhatsThis::add( kcfg_SetArgument, tr2i18n( "the argument to pass to the program<br>\n" +"to set the brightness" ) ); + textLabel2_2->setText( tr2i18n( "get argument" ) ); + QToolTip::add( kcfg_GetArgument, tr2i18n( "the argument to pass to the program<br>to get the brightness" ) ); + QWhatsThis::add( kcfg_GetArgument, tr2i18n( "the argument to pass to the program<br>\n" +"to get the brightness.\n" +"<p>\n" +"This can be left empty if the program does not support\n" +"a \"get\" argument." ) ); + textLabel3->setText( tr2i18n( "minimum value" ) ); + QToolTip::add( kcfg_MinValue, tr2i18n( "the minimum value for the brightness" ) ); + QWhatsThis::add( kcfg_MinValue, tr2i18n( "brightness" ) ); + textLabel3_2->setText( tr2i18n( "maximum value" ) ); + QToolTip::add( kcfg_MaxValue, tr2i18n( "the maximum value for the brightness" ) ); + QWhatsThis::add( kcfg_MaxValue, tr2i18n( "brightness" ) ); + textLabel3_2_2->setText( tr2i18n( "step" ) ); + QToolTip::add( kcfg_Step, tr2i18n( "step value<br>to increment/decrement the brightness" ) ); + QWhatsThis::add( kcfg_Step, tr2i18n( "brightness" ) ); + kcfg_SaveCurrent->setText( tr2i18n( "S&ave the current brightness value" ) ); + kcfg_SaveCurrent->setAccel( QKeySequence( tr2i18n( "Alt+A" ) ) ); + QToolTip::add( kcfg_SaveCurrent, tr2i18n( "When closing, it saves the current brightness value<br>so that it can be restored<br>when the applet starts." ) ); + QWhatsThis::add( kcfg_SaveCurrent, tr2i18n( "When closing, it saves the current brightness value<br>\n" +"so that it can be restored<br>\n" +"when the applet starts." ) ); +} + +#include "progpreferences.moc" diff --git a/src/progpreferences.h b/src/progpreferences.h new file mode 100644 index 0000000..aceaf95 --- /dev/null +++ b/src/progpreferences.h @@ -0,0 +1,65 @@ +/**************************************************************************** +** Form interface generated from reading ui file '/home/bettini/work/klcddimmer/src/progpreferences.ui' +** +** Created: Sat Feb 24 20:45:58 2007 +** by: The User Interface Compiler ($Id: qt/main.cpp 3.3.7 edited Aug 31 2005 $) +** +** WARNING! All changes made in this file will be lost! +****************************************************************************/ + +#ifndef PROGPREFERENCES_H +#define PROGPREFERENCES_H + +#include <qvariant.h> +#include <qwidget.h> + +class QVBoxLayout; +class QHBoxLayout; +class QGridLayout; +class QSpacerItem; +class QLabel; +class QLineEdit; +class KIntNumInput; +class QCheckBox; + +class ProgPreferences : public QWidget +{ + Q_OBJECT + +public: + ProgPreferences( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 ); + ~ProgPreferences(); + + QLabel* textLabel1; + QLineEdit* kcfg_Program; + QLabel* textLabel2; + QLineEdit* kcfg_SetArgument; + QLabel* textLabel2_2; + QLineEdit* kcfg_GetArgument; + QLabel* textLabel3; + KIntNumInput* kcfg_MinValue; + QLabel* textLabel3_2; + KIntNumInput* kcfg_MaxValue; + QLabel* textLabel3_2_2; + KIntNumInput* kcfg_Step; + QCheckBox* kcfg_SaveCurrent; + +protected: + QGridLayout* ProgPreferencesLayout; + QVBoxLayout* layout11; + QHBoxLayout* layout2; + QHBoxLayout* layout3; + QHBoxLayout* layout3_2; + QHBoxLayout* layout7; + QSpacerItem* spacer1; + QHBoxLayout* layout7_2; + QSpacerItem* spacer1_2; + QHBoxLayout* layout7_2_2; + QSpacerItem* spacer1_2_2; + +protected slots: + virtual void languageChange(); + +}; + +#endif // PROGPREFERENCES_H diff --git a/src/progpreferences.ui b/src/progpreferences.ui new file mode 100644 index 0000000..a8e208f --- /dev/null +++ b/src/progpreferences.ui @@ -0,0 +1,292 @@ +<!DOCTYPE UI><UI version="3.3" stdsetdef="1"> +<class>ProgPreferences</class> +<widget class="QWidget"> + <property name="name"> + <cstring>ProgPreferences</cstring> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>600</width> + <height>480</height> + </rect> + </property> + <property name="caption"> + <string>Form1</string> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QLayoutWidget" row="0" column="0"> + <property name="name"> + <cstring>layout11</cstring> + </property> + <vbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QLayoutWidget"> + <property name="name"> + <cstring>layout2</cstring> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QLabel"> + <property name="name"> + <cstring>textLabel1</cstring> + </property> + <property name="text"> + <string>program</string> + </property> + </widget> + <widget class="QLineEdit"> + <property name="name"> + <cstring>kcfg_Program</cstring> + </property> + <property name="toolTip" stdset="0"> + <string>the program to set the brightness</string> + </property> + <property name="whatsThis" stdset="0"> + <string>the program to set the brightness</string> + </property> + </widget> + </hbox> + </widget> + <widget class="QLayoutWidget"> + <property name="name"> + <cstring>layout3</cstring> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QLabel"> + <property name="name"> + <cstring>textLabel2</cstring> + </property> + <property name="text"> + <string>set argument</string> + </property> + </widget> + <widget class="QLineEdit"> + <property name="name"> + <cstring>kcfg_SetArgument</cstring> + </property> + <property name="toolTip" stdset="0"> + <string>the argument to pass to the program<br>to set the brightness</string> + </property> + <property name="whatsThis" stdset="0"> + <string>the argument to pass to the program<br> +to set the brightness</string> + </property> + </widget> + </hbox> + </widget> + <widget class="QLayoutWidget"> + <property name="name"> + <cstring>layout3_2</cstring> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QLabel"> + <property name="name"> + <cstring>textLabel2_2</cstring> + </property> + <property name="text"> + <string>get argument</string> + </property> + </widget> + <widget class="QLineEdit"> + <property name="name"> + <cstring>kcfg_GetArgument</cstring> + </property> + <property name="toolTip" stdset="0"> + <string>the argument to pass to the program<br>to get the brightness</string> + </property> + <property name="whatsThis" stdset="0"> + <string>the argument to pass to the program<br> +to get the brightness. +<p> +This can be left empty if the program does not support +a "get" argument.</string> + </property> + </widget> + </hbox> + </widget> + <widget class="QLayoutWidget"> + <property name="name"> + <cstring>layout7</cstring> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QLabel"> + <property name="name"> + <cstring>textLabel3</cstring> + </property> + <property name="text"> + <string>minimum value</string> + </property> + </widget> + <spacer> + <property name="name"> + <cstring>spacer1</cstring> + </property> + <property name="orientation"> + <enum>Horizontal</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>40</width> + <height>20</height> + </size> + </property> + </spacer> + <widget class="KIntNumInput"> + <property name="name"> + <cstring>kcfg_MinValue</cstring> + </property> + <property name="toolTip" stdset="0"> + <string>the minimum value for the brightness</string> + </property> + <property name="whatsThis" stdset="0"> + <string>brightness</string> + </property> + </widget> + </hbox> + </widget> + <widget class="QLayoutWidget"> + <property name="name"> + <cstring>layout7_2</cstring> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QLabel"> + <property name="name"> + <cstring>textLabel3_2</cstring> + </property> + <property name="text"> + <string>maximum value</string> + </property> + </widget> + <spacer> + <property name="name"> + <cstring>spacer1_2</cstring> + </property> + <property name="orientation"> + <enum>Horizontal</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>40</width> + <height>20</height> + </size> + </property> + </spacer> + <widget class="KIntNumInput"> + <property name="name"> + <cstring>kcfg_MaxValue</cstring> + </property> + <property name="toolTip" stdset="0"> + <string>the maximum value for the brightness</string> + </property> + <property name="whatsThis" stdset="0"> + <string>brightness</string> + </property> + </widget> + </hbox> + </widget> + <widget class="QLayoutWidget"> + <property name="name"> + <cstring>layout7_2_2</cstring> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QLabel"> + <property name="name"> + <cstring>textLabel3_2_2</cstring> + </property> + <property name="text"> + <string>step</string> + </property> + </widget> + <spacer> + <property name="name"> + <cstring>spacer1_2_2</cstring> + </property> + <property name="orientation"> + <enum>Horizontal</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>40</width> + <height>20</height> + </size> + </property> + </spacer> + <widget class="KIntNumInput"> + <property name="name"> + <cstring>kcfg_Step</cstring> + </property> + <property name="toolTip" stdset="0"> + <string>step value<br>to increment/decrement the brightness</string> + </property> + <property name="whatsThis" stdset="0"> + <string>brightness</string> + </property> + </widget> + </hbox> + </widget> + <widget class="QCheckBox"> + <property name="name"> + <cstring>kcfg_SaveCurrent</cstring> + </property> + <property name="text"> + <string>S&ave the current brightness value</string> + </property> + <property name="accel"> + <string>Alt+A</string> + </property> + <property name="toolTip" stdset="0"> + <string>When closing, it saves the current brightness value<br>so that it can be restored<br>when the applet starts.</string> + </property> + <property name="whatsThis" stdset="0"> + <string>When closing, it saves the current brightness value<br> +so that it can be restored<br> +when the applet starts.</string> + </property> + </widget> + </vbox> + </widget> + </grid> +</widget> +<layoutdefaults spacing="6" margin="11"/> +<includehints> + <includehint>knuminput.h</includehint> + <includehint>knuminput.h</includehint> + <includehint>knuminput.h</includehint> + <includehint>knuminput.h</includehint> + <includehint>knuminput.h</includehint> + <includehint>knuminput.h</includehint> +</includehints> +</UI> |