diff --git a/systray/src/SysTray_sv.ts b/systray/src/SysTray_sv.ts new file mode 100644 index 00000000..5767f648 --- /dev/null +++ b/systray/src/SysTray_sv.ts @@ -0,0 +1,41 @@ + + + + Icon + + + TellStick + TellStick + + + + &On + &På + + + + O&ff + &Av + + + + &Configure devices + &Konfigurera enheter + + + + &Quit + &Avsluta + + + + Error + Fel + + + + An error occurred while trying to transmit + Ett fel uppstod vid försök att sända + + + diff --git a/systray/src/icon.cpp b/systray/src/icon.cpp new file mode 100644 index 00000000..5ca35f29 --- /dev/null +++ b/systray/src/icon.cpp @@ -0,0 +1,200 @@ +// +// C++ Implementation: icon +// +// Description: +// +// +// Author: Micke Prag , (C) 2007 +// +// Copyright: See COPYING file that comes with this distribution +// +// +#include "icon.h" +#include +#include +#include +#include +#include "TellUsbD101.h" + +Icon::Icon() + : QObject() +{ + this->setMenu(); + connect( &i, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(activated(QSystemTrayIcon::ActivationReason))); + i.setIcon( QIcon(":/images/lamp-on.png") ); + i.setToolTip( tr("TellStick") ); + i.show(); +} + + +Icon::~Icon() +{ +} + + +/** + * @fn Icon::activated( QSystemTrayIcon::ActivationReason reason ) + */ +void Icon::activated( QSystemTrayIcon::ActivationReason reason ) +{ + if (reason == QSystemTrayIcon::DoubleClick) { + if (hasTelldusSetup()) { + configure(); + } + } +} + +/** + * @fn Icon::bell() + */ +void Icon::bell() +{ + QAction *action = (QAction *) sender(); + if (!devBell( action->data().toInt() )) + i.showMessage( tr("Error"), tr("An error occurred while trying to transmit"), QSystemTrayIcon::Critical ); +} + +/** + * @fn Icon::dim() + */ +void Icon::dim() +{ + QAction *action = (QAction *) sender(); + int intId = action->data().toString().section(":", 0, 0).toInt(); + int intLevel = action->data().toString().section(":", 1, 1).toInt(); + //i.showMessage( "", QString::number(intId)); + if (!devDim( intId, intLevel )) + i.showMessage( tr("Error"), tr("An error occurred while trying to transmit"), QSystemTrayIcon::Critical ); +} + +/** + * @fn Icon::on() + */ +void Icon::on() +{ + QAction *action = (QAction *) sender(); + if (!devTurnOn( action->data().toInt() )) + i.showMessage( tr("Error"), tr("An error occurred while trying to transmit"), QSystemTrayIcon::Critical ); +} + +/** + * @fn Icon::off() + */ +void Icon::off() +{ + QAction *action = (QAction *) sender(); + if (!devTurnOff( action->data().toInt() )) + i.showMessage( tr("Error"), tr("An error occurred while trying to transmit"), QSystemTrayIcon::Critical ); +} + + +/** + * @fn Icon::configure() + */ +void Icon::configure() +{ + QProcess *process = new QProcess(this); + connect(process, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(setMenu())); + process->setWorkingDirectory(QCoreApplication::applicationDirPath()); + process->start("TelldusSetup.exe"); +} + + +/** + * @fn Icon::setMenu() + */ +void Icon::setMenu() +{ + menu.clear(); + + int intNum = devGetNumberOfDevices(); + int index = 0; + while (index < intNum) { + addDevice(index, &menu); + index++; + } + + menu.addSeparator(); + + if (hasTelldusSetup()) { + QAction *configure = menu.addAction(tr("&Configure devices")); + connect(configure, SIGNAL(triggered()), this, SLOT(configure())); + configure->setIcon( QIcon(":/images/preferences-system.png") ); + } + + QAction *quit = menu.addAction(tr("&Quit")); + quit->setIcon( QIcon(":/images/system-log-out.png") ); + connect(quit, SIGNAL(triggered()), qApp, SLOT(quit())); + + i.setContextMenu(&menu); + +} + +void Icon::addDevice( int index, QMenu *menu ) { + int intId = devGetDeviceId(index); + QMenu *m = menu->addMenu( devGetName(intId) ); + + int methods = devMethods(intId); + if (methods & TELLSTICK_TURNON) { + QAction *on = m->addAction(tr("&On")); + on->setIcon(QIcon(":/images/lamp-on.png")); + on->setData( intId ); + connect( on, SIGNAL(triggered()), this, SLOT(on())); + } + + if (methods & TELLSTICK_DIM) { + QAction *dim = m->addAction(tr("90%")); + dim->setData( QString("%1:230").arg(intId) ); + connect( dim, SIGNAL(triggered()), this, SLOT(dim())); + + dim = m->addAction(tr("80%")); + dim->setData( QString("%1:204").arg(intId) ); + connect( dim, SIGNAL(triggered()), this, SLOT(dim())); + + dim = m->addAction(tr("70%")); + dim->setData( QString("%1:179").arg(intId) ); + connect( dim, SIGNAL(triggered()), this, SLOT(dim())); + + dim = m->addAction(tr("60%")); + dim->setData( QString("%1:153").arg(intId) ); + connect( dim, SIGNAL(triggered()), this, SLOT(dim())); + + dim = m->addAction(tr("50%")); + dim->setData( QString("%1:128").arg(intId) ); + connect( dim, SIGNAL(triggered()), this, SLOT(dim())); + + dim = m->addAction(tr("40%")); + dim->setData( QString("%1:102").arg(intId) ); + connect( dim, SIGNAL(triggered()), this, SLOT(dim())); + + dim = m->addAction(tr("30%")); + dim->setData( QString("%1:77").arg(intId) ); + connect( dim, SIGNAL(triggered()), this, SLOT(dim())); + + dim = m->addAction(tr("20%")); + dim->setData( QString("%1:51").arg(intId) ); + connect( dim, SIGNAL(triggered()), this, SLOT(dim())); + + dim = m->addAction(tr("10%")); + dim->setData( QString("%1:25").arg(intId) ); + connect( dim, SIGNAL(triggered()), this, SLOT(dim())); + } + + if (methods & TELLSTICK_TURNON) { + QAction *off = m->addAction(tr("O&ff")); + off->setData( intId ); + off->setIcon(QIcon(":/images/lamp-off.png")); + connect( off, SIGNAL(triggered()), this, SLOT(off())); + } + + if (methods & TELLSTICK_BELL) { + QAction *bell = m->addAction(tr("&Bell")); + bell->setData( intId ); + bell->setIcon(QIcon(":/images/bell.png")); + connect( bell, SIGNAL(triggered()), this, SLOT(bell())); + } +} + +bool Icon::hasTelldusSetup() { + return QFile::exists("TelldusSetup.exe"); +} diff --git a/systray/src/icon.h b/systray/src/icon.h new file mode 100644 index 00000000..68243342 --- /dev/null +++ b/systray/src/icon.h @@ -0,0 +1,51 @@ +// +// C++ Interface: icon +// +// Description: +// +// +// Author: Micke Prag , (C) 2007 +// +// Copyright: See COPYING file that comes with this distribution +// +// +#ifndef ICON_H +#define ICON_H + +#include +#include + +/** + @author Micke Prag +*/ +class Icon : public QObject +{ + Q_OBJECT +public: + Icon(); + + ~Icon(); + +protected: + QSystemTrayIcon i; + QMenu menu; + +protected slots: + void activated( QSystemTrayIcon::ActivationReason reason ); + void setMenu(); + +private slots: + void bell(); + void dim(); + void on(); + void off(); + +public slots: + void configure(); + +private: + void addDevice( int index, QMenu *menu ); + static bool hasTelldusSetup(); +}; + +#endif diff --git a/systray/src/images/bell.png b/systray/src/images/bell.png new file mode 100644 index 00000000..78765980 Binary files /dev/null and b/systray/src/images/bell.png differ diff --git a/systray/src/images/lamp-off.png b/systray/src/images/lamp-off.png new file mode 100644 index 00000000..007a1778 Binary files /dev/null and b/systray/src/images/lamp-off.png differ diff --git a/systray/src/images/lamp-on.png b/systray/src/images/lamp-on.png new file mode 100644 index 00000000..5bc874dd Binary files /dev/null and b/systray/src/images/lamp-on.png differ diff --git a/systray/src/images/preferences-system.png b/systray/src/images/preferences-system.png new file mode 100644 index 00000000..6e52db7c Binary files /dev/null and b/systray/src/images/preferences-system.png differ diff --git a/systray/src/images/system-log-out.png b/systray/src/images/system-log-out.png new file mode 100644 index 00000000..fddbc2bc Binary files /dev/null and b/systray/src/images/system-log-out.png differ diff --git a/systray/src/images/systray.ico b/systray/src/images/systray.ico new file mode 100644 index 00000000..9aeccbdc Binary files /dev/null and b/systray/src/images/systray.ico differ diff --git a/systray/src/main.cpp b/systray/src/main.cpp new file mode 100644 index 00000000..295fc7c2 --- /dev/null +++ b/systray/src/main.cpp @@ -0,0 +1,47 @@ +/*************************************************************************** + * Copyright (C) 2006 by Micke Prag * + * micke.prag@telldus.se * + * * + * 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 +#include +#include +#include "icon.h" + +int main(int argc, char *argv[]) +{ + QApplication a( argc, argv ); + + QCoreApplication::setOrganizationName("Telldus"); + QCoreApplication::setOrganizationDomain("telldus.se"); + QCoreApplication::setApplicationName("SysTray"); + + Q_INIT_RESOURCE(resource); + + QTranslator qtTranslator; + qtTranslator.load("qt_" + QLocale::system().name()); + a.installTranslator(&qtTranslator); + + QTranslator myappTranslator; + myappTranslator.load("SysTray_" + QLocale::system().name()); + a.installTranslator(&myappTranslator); + + Icon icon; + return a.exec(); +} diff --git a/systray/src/resource.qrc b/systray/src/resource.qrc new file mode 100644 index 00000000..325beebe --- /dev/null +++ b/systray/src/resource.qrc @@ -0,0 +1,9 @@ + + + images/bell.png + images/lamp-on.png + images/lamp-off.png + images/preferences-system.png + images/system-log-out.png + + diff --git a/systray/src/src.pro b/systray/src/src.pro new file mode 100644 index 00000000..c3669dde --- /dev/null +++ b/systray/src/src.pro @@ -0,0 +1,19 @@ +TEMPLATE = app + +SOURCES += main.cpp \ +icon.cpp +#menu.cpp +LIBS += -ltellusbd101 -L../bin +win32{ + TARGET = ../../bin/SysTray + CONFIG += release +} +unix{ + TARGET = ../bin/systray + CONFIG += debug +} +HEADERS += icon.h +#menu.h +RESOURCES += resource.qrc +RC_FILE = systray.rc +TRANSLATIONS = SysTray_sv.ts \ No newline at end of file diff --git a/systray/src/systray.rc b/systray/src/systray.rc new file mode 100644 index 00000000..3d90079c --- /dev/null +++ b/systray/src/systray.rc @@ -0,0 +1 @@ +IDI_ICON1 ICON DISCARDABLE "images/systray.ico" diff --git a/systray/systray.pro b/systray/systray.pro new file mode 100644 index 00000000..b2d719f0 --- /dev/null +++ b/systray/systray.pro @@ -0,0 +1,4 @@ +TEMPLATE = subdirs +SUBDIRS = src +CONFIG += warn_on +