Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v1.10.0 #76

Merged
merged 18 commits into from
Aug 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ find_package(Qt5Qml REQUIRED)
find_package(Qt5Quick REQUIRED)
find_package(Qt5QuickControls2 REQUIRED)
find_package(Qt5Multimedia REQUIRED)
find_package(Qt5Network)

execute_process(
COMMAND dpkg-architecture -qDEB_HOST_MULTIARCH
Expand Down Expand Up @@ -60,7 +61,8 @@ add_subdirectory(qzxing/src)
include_directories(qzxing/src/zxing)
include_directories("${PROJECT_BINARY_DIR}")

set(SOURCES main.cpp)
set(SOURCES main.cpp
internetchecker/internetchecker.cpp)

# Sets BUILD_VERSION: tag of the current git HEAD or devel build
execute_process(
Expand Down Expand Up @@ -93,6 +95,9 @@ configure_file(manifest.json.in ${CMAKE_CURRENT_BINARY_DIR}/manifest.json)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/manifest.json DESTINATION ${CMAKE_INSTALL_PREFIX})
install(FILES ${PROJECT_NAME}.apparmor DESTINATION ${DATA_DIR})
install(FILES assets/logo.svg DESTINATION assets)
install(FILES pushexec PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ DESTINATION ${DATA_DIR})
install(FILES push.json DESTINATION ${DATA_DIR})
install(FILES push-apparmor.json DESTINATION ${DATA_DIR})

add_executable(${PROJECT_NAME} ${SOURCES} ${QT_RESOURCES})

Expand All @@ -104,11 +109,17 @@ install(TARGETS ${PROJECT_NAME} RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX})
#set directories
install(DIRECTORY "assets" DESTINATION .)
install(DIRECTORY "qml" DESTINATION .)
install(DIRECTORY "qml/pages" DESTINATION /qml)
install(DIRECTORY "qml/components" DESTINATION /qml)
install(DIRECTORY "qml/style" DESTINATION /qml)
install(DIRECTORY "qml/plugins" DESTINATION /qml)
install(DIRECTORY "qml/settings" DESTINATION /qml)
install(DIRECTORY "qml/logicalFields" DESTINATION /qml)
install(DIRECTORY "qml/controlStreams" DESTINATION /qml)
install(DIRECTORY "qml/streams" DESTINATION /qml)
install(DIRECTORY "qml/controlSemaphores" DESTINATION /qml)
install(DIRECTORY "qml/semaphores" DESTINATION /qml)
install(DIRECTORY "qml/pushNotifications" DESTINATION /qml)
install(DIRECTORY "js" DESTINATION .)
install(DIRECTORY "py" DESTINATION .)

Expand Down
44 changes: 44 additions & 0 deletions internetchecker/internetchecker.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* 2023 Ivo Xavier
*
* 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; version 3.
*
* kaltracker 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, see <http://www.gnu.org/licenses/>.
*/
#include <QEventLoop>
#include <QNetworkReply>
#include "internetchecker.h"

InternetChecker::InternetChecker(QObject *parent) : QObject(parent) {
m_networkManager = new QNetworkAccessManager(this);
m_networkConfigManager = new QNetworkConfigurationManager(this);
}

void InternetChecker::checkInternetConnection()
{
bool isConnected = false;

if (m_networkConfigManager->isOnline()) {
QNetworkRequest request(QUrl("https://www.ubports.com"));
QNetworkReply *reply = m_networkManager->get(request);
QEventLoop loop;
QObject::connect(reply, &QNetworkReply::finished, &loop, &QEventLoop::quit);
loop.exec();

if (reply->error() == QNetworkReply::NoError) {
isConnected = true;
}

reply->deleteLater();
}

emit internetStatusChanged(isConnected);
}
42 changes: 42 additions & 0 deletions internetchecker/internetchecker.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* 2023 Ivo Xavier
*
* 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; version 3.
*
* kaltracker 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, see <http://www.gnu.org/licenses/>.
*/


#ifndef INTERNETCHECKER_H
#define INTERNETCHECKER_H

#include <QObject>
#include <QNetworkAccessManager>
#include <QNetworkConfigurationManager>

class InternetChecker : public QObject {
Q_OBJECT

public:
explicit InternetChecker(QObject *parent = nullptr);

signals:
void internetStatusChanged(bool isConnected);

public slots:
void checkInternetConnection();

private:
QNetworkAccessManager *m_networkManager;
QNetworkConfigurationManager *m_networkConfigManager;
};

#endif
84 changes: 46 additions & 38 deletions js/GetData.js
Original file line number Diff line number Diff line change
Expand Up @@ -385,39 +385,45 @@ function getNotes() {

/*Axis: for Weight Tracker --start--*/

function getYWeightTracker(date_from, date_to) {
var get_y_weight_table = `SELECT weight FROM weight_tracker wt
WHERE date(wt.date) <= date(?) AND date(wt.date) >= date(?)
ORDER BY wt.date ASC`;

var tx = db.transaction(function(tx) {
var rs = tx.executeSql(get_y_weight_table, [date_to, date_from]);
return Array.from(rs.rows).map(function(row) {
return row.weight;
});
});
function getYWeightTracker(date_from, date_to){
var get_y_weight_table = 'SELECT weight FROM weight_tracker wt \
WHERE date(wt.date) <= date("which_date_to") AND date(wt.date) >= date("which_date_from") \
ORDER BY wt.date ASC'.replace("which_date_to", date_to).replace("which_date_from", date_from)
var db = connectDB();
var rs = "";
db.transaction(function(tx) {
rs = tx.executeSql(get_y_weight_table);
});

return tx;
var weight_values = [];
for(var i =0;i < rs.rows.length;i++) {
weight_values.push(rs.rows.item(i).weight);
}

return weight_values;
}



/*X axis: measurement dates*/
function getXWeightTracker(date_from, date_to) {
var get_x_weight_table = `SELECT date
FROM weight_tracker wt
WHERE date(wt.date) <= date(?) AND date(wt.date) >= date(?)
ORDER BY wt.date ASC`;

var tx = db.transaction(function(tx) {
var rs = tx.executeSql(get_x_weight_table, [date_to, date_from]);
return Array.from(rs.rows).map(function(row) {
return row.date;
});
});
function getXWeightTracker(date_from, date_to){
var get_x_weight_table = 'SELECT date FROM weight_tracker wt \
WHERE date(wt.date) <= date("which_date_to") AND date(wt.date) >= date("which_date_from") \
ORDER BY wt.date ASC'.replace("which_date_to", date_to).replace("which_date_from", date_from)
var db = connectDB();

return tx;
var rs = "";
db.transaction(function(tx) {
rs = tx.executeSql(get_x_weight_table);
});

/* build the array */
var date_registered = [];
for(var i =0;i < rs.rows.length;i++) {
date_registered.push(rs.rows.item(i).date);
}
return date_registered;
}

/* Axis: for Weight Tracker --end--*/

Expand All @@ -441,20 +447,22 @@ return ChartLineData;

/*Axis: for Weight Tracker --start--*/

function getYNutriscore() {
var get_y_nutriscores_values = `SELECT COUNT(nutriscore) AS nutriscore
FROM ingestions
GROUP BY nutriscore
ORDER BY 1 ASC`;

var tx = db.transaction(function(tx) {
var rs = tx.executeSql(get_y_nutriscores_values);
return Array.from(rs.rows).map(function(row) {
return row.nutriscore;
});
function getYNutriscore(){
var get_y_nutriscores_values = 'SELECT COUNT(nutriscore) AS nutriscore \
FROM ingestions \
GROUP BY nutriscore \
ORDER BY 1 ASC'
var db = connectDB();
var rs = "";
db.transaction(function(tx) {
rs = tx.executeSql(get_y_nutriscores_values);
});

return tx;

var nutriscore_count = [];
for(var i =0;i < rs.rows.length;i++) {
nutriscore_count.push(rs.rows.item(i).nutriscore);
}
return nutriscore_count;
}


Expand Down
15 changes: 14 additions & 1 deletion js/IngestionsTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ function connectDB() {
VALUES (?,?,?,?,?,?,?,?,?)';

function saveIngestion(name,nutriscore,cal,fat,carbo,protein,meal) {
ctrl_smph.setSemaphore(streams_smph,"user_event")
var db = connectDB();

//In multiSelection case an object is passed rather than single arguments
if(typeof name === 'object' && name !== null) {
for(var i in name){
Expand All @@ -55,32 +55,38 @@ function connectDB() {
}
);
}
ctrl_smph.defaultSemaphore(streams_smph)
}

var remove_all_ingestions = 'DELETE FROM ingestions'

function deleteAllIngestions(){
ctrl_smph.setSemaphore(streams_smph,"user_event")
var db = connectDB();
var rs;
db.transaction(function(tx) {
rs = tx.executeSql(remove_all_ingestions);
}
);
ctrl_smph.defaultSemaphore(streams_smph)
}

var remove_today_ingestions = 'DELETE FROM ingestions \
WHERE ingestions.date == date("now")'

function deleteTodayIngestions(){
ctrl_smph.setSemaphore(streams_smph,"user_event")
var db = connectDB();
var rs;
db.transaction(function(tx) {
rs = tx.executeSql(remove_today_ingestions);
}
);
ctrl_smph.setSemaphore(streams_smph)
}

function deleteMonthYearIngestion(month, year){
ctrl_smph.setSemaphore(streams_smph,"user_event")
var statement = 'DELETE FROM ingestions \
WHERE strftime("%m", date) == "which_month" AND strftime("%Y", date) == "which_year"'.replace("which_month", month).replace("which_year", year)
var db = connectDB();
Expand All @@ -89,10 +95,12 @@ function deleteMonthYearIngestion(month, year){
rs = tx.executeSql(statement);
}
);
ctrl_smph.defaultSemaphore(streams_smph)
return console.log("Ingestions removed from option month_year")
}

function deleteIngestion(id){
ctrl_smph.setSemaphore(streams_smph,"user_event")
var statement = 'DELETE FROM ingestions \
WHERE id == "which_id"'.replace("which_id", id)
var db = connectDB();
Expand All @@ -101,6 +109,7 @@ function deleteIngestion(id){
rs = tx.executeSql(statement);
}
);
ctrl_smph.defaultSemaphore(streams_smph)
}


Expand All @@ -125,16 +134,19 @@ var auto_clean = 'DELETE FROM ingestions \
WHERE ingestions.date < strftime("%Y", date())'

function autoClean(){
ctrl_smph.setSemaphore(streams_smph,"user_event")
var db = connectDB();
var rs;
db.transaction(function(tx) {
rs = tx.executeSql(auto_clean);
}
);
ctrl_smph.defaultSemaphore(streams_smph)
}


function deleteSpecificTodayIngestion(id){
ctrl_smph.setSemaphore(streams_smph,"user_event")
var remove_today_speficic_ingestion = 'DELETE FROM ingestions \
WHERE ingestions.id = which_id'.replace("which_id",id)
var db = connectDB();
Expand All @@ -143,4 +155,5 @@ function deleteSpecificTodayIngestion(id){
rs = tx.executeSql(remove_today_speficic_ingestion);
}
);
ctrl_smph.defaultSemaphore(streams_smph)
}
Loading