Added project "Systray"
This commit is contained in:
parent
813d72861d
commit
00dc68bd1b
14 changed files with 372 additions and 0 deletions
41
systray/src/SysTray_sv.ts
Normal file
41
systray/src/SysTray_sv.ts
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!DOCTYPE TS><TS version="1.1" language="sv_SE">
|
||||||
|
<context>
|
||||||
|
<name>Icon</name>
|
||||||
|
<message>
|
||||||
|
<location filename="icon.cpp" line="25"/>
|
||||||
|
<source>TellStick</source>
|
||||||
|
<translation>TellStick</translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<location filename="icon.cpp" line="117"/>
|
||||||
|
<source>&On</source>
|
||||||
|
<translation>&På</translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<location filename="icon.cpp" line="122"/>
|
||||||
|
<source>O&ff</source>
|
||||||
|
<translation>&Av</translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<location filename="icon.cpp" line="100"/>
|
||||||
|
<source>&Configure devices</source>
|
||||||
|
<translation>&Konfigurera enheter</translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<location filename="icon.cpp" line="105"/>
|
||||||
|
<source>&Quit</source>
|
||||||
|
<translation>&Avsluta</translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<location filename="icon.cpp" line="67"/>
|
||||||
|
<source>Error</source>
|
||||||
|
<translation>Fel</translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<location filename="icon.cpp" line="67"/>
|
||||||
|
<source>An error occurred while trying to transmit</source>
|
||||||
|
<translation>Ett fel uppstod vid försök att sända</translation>
|
||||||
|
</message>
|
||||||
|
</context>
|
||||||
|
</TS>
|
200
systray/src/icon.cpp
Normal file
200
systray/src/icon.cpp
Normal file
|
@ -0,0 +1,200 @@
|
||||||
|
//
|
||||||
|
// C++ Implementation: icon
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// Author: Micke Prag <micke.prag@telldus.se>, (C) 2007
|
||||||
|
//
|
||||||
|
// Copyright: See COPYING file that comes with this distribution
|
||||||
|
//
|
||||||
|
//
|
||||||
|
#include "icon.h"
|
||||||
|
#include <QApplication>
|
||||||
|
#include <QMenu>
|
||||||
|
#include <QProcess>
|
||||||
|
#include <QFile>
|
||||||
|
#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");
|
||||||
|
}
|
51
systray/src/icon.h
Normal file
51
systray/src/icon.h
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
//
|
||||||
|
// C++ Interface: icon
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// Author: Micke Prag <micke.prag@telldus.se>, (C) 2007
|
||||||
|
//
|
||||||
|
// Copyright: See COPYING file that comes with this distribution
|
||||||
|
//
|
||||||
|
//
|
||||||
|
#ifndef ICON_H
|
||||||
|
#define ICON_H
|
||||||
|
|
||||||
|
#include <QSystemTrayIcon>
|
||||||
|
#include <QMenu>
|
||||||
|
|
||||||
|
/**
|
||||||
|
@author Micke Prag <micke.prag@telldus.se>
|
||||||
|
*/
|
||||||
|
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
|
BIN
systray/src/images/bell.png
Normal file
BIN
systray/src/images/bell.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.8 KiB |
BIN
systray/src/images/lamp-off.png
Normal file
BIN
systray/src/images/lamp-off.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.4 KiB |
BIN
systray/src/images/lamp-on.png
Normal file
BIN
systray/src/images/lamp-on.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.4 KiB |
BIN
systray/src/images/preferences-system.png
Normal file
BIN
systray/src/images/preferences-system.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.1 KiB |
BIN
systray/src/images/system-log-out.png
Normal file
BIN
systray/src/images/system-log-out.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.7 KiB |
BIN
systray/src/images/systray.ico
Normal file
BIN
systray/src/images/systray.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 13 KiB |
47
systray/src/main.cpp
Normal file
47
systray/src/main.cpp
Normal file
|
@ -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 <QApplication>
|
||||||
|
#include <QTranslator>
|
||||||
|
#include <QLocale>
|
||||||
|
#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();
|
||||||
|
}
|
9
systray/src/resource.qrc
Normal file
9
systray/src/resource.qrc
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
<RCC>
|
||||||
|
<qresource prefix="/" >
|
||||||
|
<file>images/bell.png</file>
|
||||||
|
<file>images/lamp-on.png</file>
|
||||||
|
<file>images/lamp-off.png</file>
|
||||||
|
<file>images/preferences-system.png</file>
|
||||||
|
<file>images/system-log-out.png</file>
|
||||||
|
</qresource>
|
||||||
|
</RCC>
|
19
systray/src/src.pro
Normal file
19
systray/src/src.pro
Normal file
|
@ -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
|
1
systray/src/systray.rc
Normal file
1
systray/src/systray.rc
Normal file
|
@ -0,0 +1 @@
|
||||||
|
IDI_ICON1 ICON DISCARDABLE "images/systray.ico"
|
4
systray/systray.pro
Normal file
4
systray/systray.pro
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
TEMPLATE = subdirs
|
||||||
|
SUBDIRS = src
|
||||||
|
CONFIG += warn_on
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue