From 61517e5bfd252c02c98905f21c075641bddee1c3 Mon Sep 17 00:00:00 2001 From: Richard Genoud Date: Wed, 4 Dec 2019 15:34:27 +0100 Subject: [PATCH] add thermostat sofware skeleton --- soft/thermostat/inc/mainwindow.h | 27 ++++++++++++ soft/thermostat/inc/zoneitem.h | 26 ++++++++++++ soft/thermostat/lang/thermostat_fr.ts | 18 ++++++++ soft/thermostat/scripts/get_tag_version.sh | 43 +++++++++++++++++++ soft/thermostat/src/main.cpp | 42 +++++++++++++++++++ soft/thermostat/src/mainwindow.cpp | 48 +++++++++++++++++++++ soft/thermostat/src/zoneitem.cpp | 38 +++++++++++++++++ soft/thermostat/thermostat.pro | 67 ++++++++++++++++++++++++++++++ soft/thermostat/thermostat.qrc | 6 +++ 9 files changed, 315 insertions(+) create mode 100644 soft/thermostat/inc/mainwindow.h create mode 100644 soft/thermostat/inc/zoneitem.h create mode 100644 soft/thermostat/lang/thermostat_fr.ts create mode 100755 soft/thermostat/scripts/get_tag_version.sh create mode 100644 soft/thermostat/src/main.cpp create mode 100644 soft/thermostat/src/mainwindow.cpp create mode 100644 soft/thermostat/src/zoneitem.cpp create mode 100644 soft/thermostat/thermostat.pro create mode 100644 soft/thermostat/thermostat.qrc diff --git a/soft/thermostat/inc/mainwindow.h b/soft/thermostat/inc/mainwindow.h new file mode 100644 index 0000000..a523395 --- /dev/null +++ b/soft/thermostat/inc/mainwindow.h @@ -0,0 +1,27 @@ +// SPDX-License-Identifier: GPL-3.0-or-later +/* + * Qt mutizone MQTT thermostat + * + * Copyright (C) 2019 Richard Genoud + * + */ + +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#include +#include +#include + +class MainWindow : public QMainWindow +{ + Q_OBJECT + +public: + explicit MainWindow(QWidget *parent = 0); + ~MainWindow(); +}; + +#endif // MAINWINDOW_H + +/* vim: set tabstop=8 shiftwidth=8 softtabstop=0 noexpandtab: */ diff --git a/soft/thermostat/inc/zoneitem.h b/soft/thermostat/inc/zoneitem.h new file mode 100644 index 0000000..5afeb52 --- /dev/null +++ b/soft/thermostat/inc/zoneitem.h @@ -0,0 +1,26 @@ +// SPDX-License-Identifier: GPL-3.0-or-later +/* + * Qt mutizone MQTT thermostat + * + * Copyright (C) 2019 Richard Genoud + * + */ + +#ifndef ZONEITEM_H +#define ZONEITEM_H + +#include +#include + +class ZoneItem : public QWidget +{ + Q_OBJECT + +public: + explicit ZoneItem(QWidget *parent = Q_NULLPTR); + ~ZoneItem(); +}; + +#endif // ZONEITEM_H + +/* vim: set tabstop=8 shiftwidth=8 softtabstop=0 noexpandtab: */ diff --git a/soft/thermostat/lang/thermostat_fr.ts b/soft/thermostat/lang/thermostat_fr.ts new file mode 100644 index 0000000..aa3d0d0 --- /dev/null +++ b/soft/thermostat/lang/thermostat_fr.ts @@ -0,0 +1,18 @@ + + + + + MainWindow + + Sorico's thermostat + + + + + ZoneItem + + Living room + Salon + + + diff --git a/soft/thermostat/scripts/get_tag_version.sh b/soft/thermostat/scripts/get_tag_version.sh new file mode 100755 index 0000000..f985129 --- /dev/null +++ b/soft/thermostat/scripts/get_tag_version.sh @@ -0,0 +1,43 @@ +#!/bin/sh + +devflag="" +dirtyflag="" +# set the version from tags +tag="$(git describe --exact-match --tags 2>/dev/null)" +if [ -n "$tag" ]; then + # we are exactly on a tag (ex: 2015_09_10_08_51_version_1.6.7) + # so we have just to extract the version + version="$(echo "$tag" | sed "s/^.*_//")" +else + # we are not on a tag. + # In this case, we want to have the previous tag version plus "dev" string + # and the number of commits + # git describe format is tag-x-gsha1 + tag="$(git describe --long --tags 2>/dev/null)" + if [ -n "$tag" ]; then + version="$(echo "$tag" | sed "s/^.*_\(.*\)-[0-9]\+-g[^-]\+$/\1/")" + nbcommit="$(echo "$tag" | sed "s/^.*_.*-\([0-9]\+\)-g[^-]\+$/\1/")" + commit="$(echo "$tag" | sed "s/^.*_.*-[0-9]\+-g\([^-]\+\)$/\1/")" + devflag="-dev" + else + nbcommit=0 + version="$(git log -1 --pretty="format:%h")" + fi +fi + +dirtyflag=$(git diff-index --name-only HEAD) +if [ -n "$dirtyflag" ]; then + flag="-dirty" +else + flag="$devflag" +fi + +[ "$nbcommit" -eq "$nbcommit" ] 2>/dev/null || nbcommit=0 + +printf "%s%s" "${version}" "${flag}" +if [ "$nbcommit" -ne 0 ]; then + printf "%03d_%s" "${nbcommit}" "${commit}" +fi +printf "\n" + +# /* vim: set noai ts=8 sw=8: */ diff --git a/soft/thermostat/src/main.cpp b/soft/thermostat/src/main.cpp new file mode 100644 index 0000000..cd26708 --- /dev/null +++ b/soft/thermostat/src/main.cpp @@ -0,0 +1,42 @@ +// SPDX-License-Identifier: GPL-3.0-or-later +/* + * Qt mutizone MQTT thermostat + * + * Copyright (C) 2019 Richard Genoud + * + */ + + +#include +#include +#include + +#include "mainwindow.h" + +int main(int argc, char *argv[]) +{ + QTranslator qtTranslator; + QTranslator translator; + + Q_INIT_RESOURCE(thermostat); + + QApplication a(argc, argv); + a.setApplicationVersion(VERSION); + + /* + * Init l10n + */ + if (qtTranslator.load("qt_" + QLocale::system().name(), + QLibraryInfo::location(QLibraryInfo::TranslationsPath))) + a.installTranslator(&qtTranslator); + + if (translator.load(":/lang/thermostat_" + QLocale::system().name() + ".qm")) + a.installTranslator(&translator); + + MainWindow w; + w.show(); + + return a.exec(); +} + +/* vim: set tabstop=8 shiftwidth=8 softtabstop=0 noexpandtab: */ diff --git a/soft/thermostat/src/mainwindow.cpp b/soft/thermostat/src/mainwindow.cpp new file mode 100644 index 0000000..73384a6 --- /dev/null +++ b/soft/thermostat/src/mainwindow.cpp @@ -0,0 +1,48 @@ +// SPDX-License-Identifier: GPL-3.0-or-later +/* + * Qt mutizone MQTT thermostat + * + * Copyright (C) 2019 Richard Genoud + * + */ + +#include +#include +#include +#include + +#include "zoneitem.h" +#include "mainwindow.h" + +MainWindow::MainWindow(QWidget *parent) : + QMainWindow(parent) +{ + + /* + * Sensors-related layout + */ + QGridLayout *mainLayout = new QGridLayout; + + mainLayout->addWidget(new ZoneItem(this), 0, 0); + mainLayout->addWidget(new ZoneItem(this), 0, 1); + mainLayout->addWidget(new QPushButton(tr("Menu")), 0, 2); + mainLayout->addWidget(new ZoneItem(this), 1, 0); + mainLayout->addWidget(new ZoneItem(this), 1, 1); + mainLayout->addWidget(new QPushButton(tr("Auto")), 1, 2); + + QWidget *mainWidget = new QWidget; + mainWidget->setLayout(mainLayout); + + /* + * Top widget + */ + setCentralWidget(mainWidget); + + setWindowTitle(tr("Sorico's thermostat")); +} + +MainWindow::~MainWindow() +{ +} + +/* vim: set tabstop=8 shiftwidth=8 softtabstop=0 noexpandtab: */ diff --git a/soft/thermostat/src/zoneitem.cpp b/soft/thermostat/src/zoneitem.cpp new file mode 100644 index 0000000..0b19763 --- /dev/null +++ b/soft/thermostat/src/zoneitem.cpp @@ -0,0 +1,38 @@ +// SPDX-License-Identifier: GPL-3.0-or-later +/* + * Qt mutizone MQTT thermostat + * + * Copyright (C) 2019 Richard Genoud + * + */ + +#include +#include +#include +#include +#include + +#include "zoneitem.h" + +ZoneItem::ZoneItem(QWidget *parent) : + QWidget(parent) +{ + /* + * Layout for the left part of the window + */ + QVBoxLayout *topLayout = new QVBoxLayout; + QPushButton *btn = new QPushButton; + btn->setText("20°C"); + btn->setFlat(true); + topLayout->addWidget(new QLabel(tr("Living room"))); + topLayout->addWidget(btn); + topLayout->addWidget(new QLabel("45%h")); + + this->setLayout(topLayout); +} + +ZoneItem::~ZoneItem() +{ +} + +/* vim: set tabstop=8 shiftwidth=8 softtabstop=0 noexpandtab: */ diff --git a/soft/thermostat/thermostat.pro b/soft/thermostat/thermostat.pro new file mode 100644 index 0000000..29f68e5 --- /dev/null +++ b/soft/thermostat/thermostat.pro @@ -0,0 +1,67 @@ +QT += core gui + +greaterThan(QT_MAJOR_VERSION, 4): QT += widgets + +CONFIG += c++11 + +TARGET = thermostat +TEMPLATE = app + +# The following define makes your compiler emit warnings if you use +# any feature of Qt which as been marked as deprecated (the exact warnings +# depend on your compiler). Please consult the documentation of the +# deprecated API in order to know how to port your code away from it. +DEFINES += QT_DEPRECATED_WARNINGS + +# You can also make your code fail to compile if you use deprecated APIs. +# In order to do so, uncomment the following line. +# You can also select to disable deprecated APIs only up to a certain version of Qt. +DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 + +SOURCES += src/main.cpp \ + src/mainwindow.cpp \ + src/zoneitem.cpp \ + + +HEADERS += inc/mainwindow.h \ + inc/zoneitem.h \ + +RESOURCES += thermostat.qrc + +TRANSLATION_DIR = lang + +TRANSLATIONS += $$TRANSLATION_DIR/thermostat_fr.ts + +# This is not working with Qt5.7 on debian. +CONFIG += lrelease embed_translations + +target.path = /usr/bin/ +INSTALLS += target + +VERSION = $$system(./scripts/get_tag_version.sh) + +QMAKE_CXXFLAGS += -Wall -Werror +QMAKE_CXXFLAGS += -std=c++11 +QMAKE_CXXFLAGS += -DVERSION=\'\"$$VERSION\"\' +QMAKE_CXXFLAGS_DEBUG += -O0 +QMAKE_CXXFLAGS_RELEASE += -Os + +unix: CONFIG += link_pkgconfig + +INCLUDEPATH += inc/ \ + + +LUPDATE = $$shell_path($$[QT_INSTALL_BINS]/lupdate) -locations relative -no-ui-lines -no-sort +LRELEASE = $$shell_path($$[QT_INSTALL_BINS]/lrelease) -compress -nounfinished -removeidentical +LCONVERT = $$shell_path($$[QT_INSTALL_BINS]/lconvert) +langupd.command = $$LUPDATE $$shell_path($$_PRO_FILE_) -ts $$_PRO_FILE_PWD_/$$TRANSLATIONS + +langrel.depends = langupd +langrel.input = TRANSLATIONS +langrel.output = $$TRANSLATION_DIR/${QMAKE_FILE_BASE}.qm +langrel.commands = $$LRELEASE ${QMAKE_FILE_IN} +langrel.CONFIG += no_link + +QMAKE_EXTRA_TARGETS += langupd +QMAKE_EXTRA_COMPILERS += langrel +PRE_TARGETDEPS += langupd compiler_langrel_make_all diff --git a/soft/thermostat/thermostat.qrc b/soft/thermostat/thermostat.qrc new file mode 100644 index 0000000..cecc323 --- /dev/null +++ b/soft/thermostat/thermostat.qrc @@ -0,0 +1,6 @@ + + + + lang/thermostat_fr.qm + +