diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..9a6674d --- /dev/null +++ b/.travis.yml @@ -0,0 +1,21 @@ +language: cpp +os: + - linux +branches: + only: + - master +compiler: + - gcc + - clang +sudo: required +dist: trusty +addons: + apt: + sources: + - ubuntu-sdk-team + packages: + - qtdeclarative5-dev +script: + - /usr/lib/x86_64-linux-gnu/qt5/bin/qmake + - make + diff --git a/README.md b/README.md index 0f95439..a408819 100644 --- a/README.md +++ b/README.md @@ -2,3 +2,5 @@ focus ===== A simple work timer that allows you to see for how long you have been taking a break. + +[![Build Status](https://travis-ci.org/CINPLA/focus.svg?branch=master)](https://travis-ci.org/CINPLA/focus) diff --git a/focus.pro b/focus.pro index 531fb47..ee748de 100644 --- a/focus.pro +++ b/focus.pro @@ -1,9 +1,18 @@ # The .cpp file which was generated for your project. Feel free to hack it. -QT += quick +QT += quick dbus -SOURCES += main.cpp +SOURCES += main.cpp \ + pong.cpp RESOURCES += \ qml.qrc \ sounds.qrc \ fonts.qrc + +HEADERS += \ + pong.h + +DISTFILES += \ + server.py \ + .travis.yml \ + README.md diff --git a/main.cpp b/main.cpp index 1cfaa41..1ef4607 100644 --- a/main.cpp +++ b/main.cpp @@ -1,9 +1,20 @@ #include #include #include +#include +#include +#include +#include +#include +#include + +#include "pong.h" +#define SERVICE_NAME "org.example.QtDBus.PingExample" int main(int argc, char *argv[]) { + qmlRegisterType("Pong", 1, 0, "Pong"); + QGuiApplication app(argc, argv); QFontDatabase::addApplicationFont(":/fonts/SourceSansPro-Regular.ttf"); @@ -12,5 +23,6 @@ int main(int argc, char *argv[]) QQmlApplicationEngine engine; engine.load(QUrl(QStringLiteral("qrc:///qml/main.qml"))); + return app.exec(); } diff --git a/pong.cpp b/pong.cpp new file mode 100644 index 0000000..aea0402 --- /dev/null +++ b/pong.cpp @@ -0,0 +1,44 @@ +#include +#include + +#include +#include +#include + +#include "pong.h" + +Pong::Pong() +{ + if (!QDBusConnection::sessionBus().isConnected()) { + fprintf(stderr, "Cannot connect to the D-Bus session bus.\n" + "To start it, run:\n" + "\teval `dbus-launch --auto-syntax`\n"); + } + + if (!QDBusConnection::sessionBus().registerService("org.cinpla.focus")) { + fprintf(stderr, "%s\n", + qPrintable(QDBusConnection::sessionBus().lastError().message())); + } + + QDBusConnection::sessionBus().registerObject("/", this, QDBusConnection::ExportAllSlots); +} + +QString Pong::response() const +{ + return m_response; +} + +QString Pong::ping(const QString &message) +{ + emit pinged(message); + return response(); +} + +void Pong::setResponse(QString arg) +{ + if (m_response == arg) + return; + + m_response = arg; + emit responseChanged(arg); +} diff --git a/pong.h b/pong.h new file mode 100644 index 0000000..2602852 --- /dev/null +++ b/pong.h @@ -0,0 +1,25 @@ +#ifndef PONG_H +#define PONG_H + +#include + +class Pong: public QObject +{ + Q_OBJECT + Q_PROPERTY(QString response READ response WRITE setResponse NOTIFY responseChanged) + QString m_response; + +public: + Pong(); + QString response() const; + +public slots: + Q_SCRIPTABLE QString ping(const QString &message); + void setResponse(QString arg); + +signals: + void pinged(QString message); + void responseChanged(QString arg); +}; + +#endif diff --git a/qml/Focus.qml b/qml/Focus.qml index b934427..5a45a5e 100644 --- a/qml/Focus.qml +++ b/qml/Focus.qml @@ -1,5 +1,6 @@ import QtQuick 2.0 import QtMultimedia 5.0 +import Pong 1.0 Rectangle { id: pomodoroRoot @@ -22,6 +23,27 @@ Rectangle { return s; } + Pong { + onPinged: { + var oldTimeLeft = timeLeft + if(message.indexOf("pomodoro") !== -1) { + pomodoroRoot.state = "pomodoro" + timeLeft = 25 * 60 + response = "Entering pomodoro state. They had been chilling for " + oldTimeLeft.toFixed(0) + " seconds." + } else if(message.indexOf("break") !== -1) { + pomodoroRoot.state = "break" + timeLeft = 0 + response = "Entering break state. Time left was " + oldTimeLeft.toFixed(0) + " seconds." + } else if(message.indexOf("pause") !== -1 && pomodoroRoot.state === "pomodoro") { + pomodoroRoot.state = "pause" + response = "Entering paused state. Time left is " + oldTimeLeft.toFixed(0) + " seconds." + } else if(message.indexOf("resume") !== -1 && pomodoroRoot.state === "pause") { + pomodoroRoot.state = "pomodoro" + response = "Leaving paused state. Time left is " + oldTimeLeft.toFixed(0) + " seconds." + } + } + } + states: [ State { name: "pomodoro" diff --git a/server.py b/server.py new file mode 100644 index 0000000..26e0706 --- /dev/null +++ b/server.py @@ -0,0 +1,38 @@ +from flask import Flask +app = Flask(__name__) +from flask import request +from flask import Response + +import json +import dbus + +@app.route('/receive', methods=['POST']) +def slack_receive(): +#======================================================================== +# return w3w link +##=========================================================================== + + print "received" + msg = request.form['text'] + print msg + #get the interface + + #get the session bus + bus = dbus.SessionBus() + name = "org.cinpla.focus" + the_object = bus.get_object(name, "/") + the_interface = dbus.Interface(the_object, "local.focus.Pong") + reply = the_interface.ping(msg) + print(reply) + + + return Response(json.dumps({'text': reply})) + +@app.route('/') +def root(): + return '' + +import os +if __name__ == '__main__': + port = int(os.environ.get("PORT", 27020)) + app.run(host='0.0.0.0', port=port)