2019-01-06 00:40:22 +03:00
|
|
|
/**
|
|
|
|
* Battery Buddy, a Sailfish application to prolong battery lifetime
|
|
|
|
*
|
2020-03-21 04:27:09 +03:00
|
|
|
* Copyright (C) 2019-2020 Matti Viljanen
|
2019-01-06 00:40:22 +03:00
|
|
|
*
|
|
|
|
* Battery Buddy 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 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Battery Buddy 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 CarBudget. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
* Author: Matti Viljanen
|
|
|
|
*/
|
2019-01-05 16:49:35 +03:00
|
|
|
#ifdef QT_QML_DEBUG
|
|
|
|
#include <QtQuick>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <sailfishapp.h>
|
|
|
|
|
2019-01-05 18:15:32 +03:00
|
|
|
#include <QGuiApplication>
|
|
|
|
#include <QQmlContext>
|
|
|
|
#include <QQuickView>
|
|
|
|
#include <QQmlEngine>
|
2019-01-05 22:57:35 +03:00
|
|
|
#include <QTimer>
|
2020-03-21 02:17:15 +03:00
|
|
|
#include <QDebug>
|
2019-01-05 18:15:32 +03:00
|
|
|
|
|
|
|
#include "battery.h"
|
2019-01-05 22:58:52 +03:00
|
|
|
#include "settings.h"
|
2019-01-05 18:15:32 +03:00
|
|
|
|
2019-01-05 16:49:35 +03:00
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
// SailfishApp::main() will display "qml/harbour-batterybuddy.qml", if you need more
|
|
|
|
// control over initialization, you can use:
|
|
|
|
//
|
|
|
|
// - SailfishApp::application(int, char *[]) to get the QGuiApplication *
|
|
|
|
// - SailfishApp::createView() to get a new QQuickView * instance
|
|
|
|
// - SailfishApp::pathTo(QString) to get a QUrl to a resource file
|
|
|
|
// - SailfishApp::pathToMainQml() to get a QUrl to the main QML file
|
|
|
|
//
|
|
|
|
// To display the view, call "show()" (will show fullscreen on device).
|
|
|
|
|
2020-03-21 02:17:15 +03:00
|
|
|
qInfo() << "Starting Battery Buddy...";
|
|
|
|
|
2019-01-05 18:15:32 +03:00
|
|
|
QGuiApplication* app = SailfishApp::application(argc, argv);
|
|
|
|
QQuickView* view = SailfishApp::createView();
|
|
|
|
|
2020-03-20 17:18:14 +03:00
|
|
|
Settings* settings = new Settings();
|
2020-03-20 21:58:01 +03:00
|
|
|
Battery* battery = new Battery(settings);
|
2019-01-05 22:58:52 +03:00
|
|
|
|
2020-03-20 21:58:01 +03:00
|
|
|
QTimer* updater = new QTimer();
|
2020-03-20 17:18:14 +03:00
|
|
|
QObject::connect(updater, SIGNAL(timeout()), battery, SLOT(updateData()));
|
|
|
|
updater->start(3000);
|
2019-01-05 22:57:35 +03:00
|
|
|
|
2020-03-20 17:18:14 +03:00
|
|
|
view->rootContext()->setContextProperty("battery", battery);
|
|
|
|
view->rootContext()->setContextProperty("settings", settings);
|
2019-01-06 00:41:33 +03:00
|
|
|
|
2019-01-05 18:15:32 +03:00
|
|
|
view->setSource(SailfishApp::pathTo("qml/harbour-batterybuddy.qml"));
|
|
|
|
view->showFullScreen();
|
|
|
|
|
2020-03-21 02:17:15 +03:00
|
|
|
qInfo() << "Launching GUI...";
|
|
|
|
|
2020-03-20 17:18:14 +03:00
|
|
|
int retval = app->exec();
|
|
|
|
|
2020-03-21 02:17:15 +03:00
|
|
|
qInfo() << "Exiting...";
|
|
|
|
|
2020-03-20 18:29:09 +03:00
|
|
|
updater->stop();
|
|
|
|
battery->blockSignals(true);
|
|
|
|
battery->setChargingEnabled(true);
|
|
|
|
|
2020-03-20 17:18:14 +03:00
|
|
|
delete updater;
|
|
|
|
delete battery;
|
|
|
|
delete settings;
|
|
|
|
|
2020-03-21 02:17:15 +03:00
|
|
|
qInfo() << "Goodbye!";
|
|
|
|
|
2020-03-20 17:18:14 +03:00
|
|
|
return retval;
|
2019-01-05 16:49:35 +03:00
|
|
|
}
|