harbour-seaprint/qml/harbour-seaprint.qml

157 lines
4.6 KiB
QML
Raw Normal View History

2021-07-11 15:27:03 +03:00
import QtQuick 2.6
2019-12-01 17:40:10 +03:00
import Sailfish.Silica 1.0
2019-12-01 17:55:55 +03:00
import QtQuick.LocalStorage 2.0
import Nemo.Notifications 1.0
2020-06-07 15:28:54 +03:00
import Nemo.Configuration 1.0
2021-03-21 14:49:54 +03:00
import seaprint.mimer 1.0
import seaprint.settings 1.0
2021-06-19 19:16:42 +03:00
2019-12-01 17:40:10 +03:00
import "pages"
2021-02-14 16:38:35 +03:00
import "components"
2019-12-01 17:40:10 +03:00
ApplicationWindow
{
2021-02-07 16:55:20 +03:00
id: appWin
2021-09-27 22:44:36 +03:00
property bool expectCalligra: true
2021-03-21 18:38:04 +03:00
initialPage: Component { FirstPage { selectedFile: Qt.application.arguments[1] ? Qt.application.arguments[1] : "" } }
2019-12-01 17:40:10 +03:00
cover: Qt.resolvedUrl("cover/CoverPage.qml")
2020-08-06 18:34:14 +03:00
allowedOrientations: Orientation.All
2019-12-01 17:55:55 +03:00
2021-02-07 16:55:20 +03:00
property string busyMessage: ""
property string progress: ""
2021-02-14 16:38:35 +03:00
WifiChecker {
id: wifi
}
2019-12-01 17:55:55 +03:00
Item {
id: db
property var db_conn
Component.onCompleted: {
2019-12-02 22:56:06 +03:00
db_conn = LocalStorage.openDatabaseSync("SeaprintDB", "1.0", "Seaprint storage", 100000)
2019-12-01 17:55:55 +03:00
db_conn.transaction(function (tx) {
2019-12-01 22:21:36 +03:00
tx.executeSql('CREATE TABLE IF NOT EXISTS Favourites (ssid STRING, url STRING)');
2021-03-21 14:49:54 +03:00
tx.executeSql('CREATE TABLE IF NOT EXISTS JobSettings (uuid STRING, type STRING, data STRING)');
2019-12-01 17:55:55 +03:00
});
}
2019-12-01 22:21:36 +03:00
function addFavourite(ssid, url) {
2019-12-13 21:59:01 +03:00
if(isFavourite(ssid, url))
return;
2019-12-01 17:55:55 +03:00
db_conn.transaction(function (tx) {
2019-12-13 21:59:01 +03:00
tx.executeSql('INSERT INTO Favourites VALUES(?, ?)', [ssid, url] );
2019-12-01 17:55:55 +03:00
});
}
2019-12-01 22:21:36 +03:00
function getFavourites(ssid) {
2019-12-01 17:55:55 +03:00
var favs = [];
db_conn.transaction(function (tx) {
2019-12-01 22:21:36 +03:00
var res = tx.executeSql('SELECT * FROM Favourites WHERE ssid=?', [ssid]);
2019-12-13 21:14:50 +03:00
for (var i = 0; i < res.rows.length; i++) {
console.log(res.rows.item(i).url)
favs.push(res.rows.item(i).url);
2019-12-01 17:55:55 +03:00
}
});
2019-12-01 22:21:36 +03:00
console.log(ssid, favs);
2019-12-01 17:55:55 +03:00
return favs
}
2019-12-13 21:14:50 +03:00
function isFavourite(ssid, url) {
var isfav = false;
db_conn.transaction(function (tx) {
var res = tx.executeSql('SELECT * FROM Favourites WHERE ssid=? AND url=?', [ssid, url]);
if (res.rows.length > 0) {
isfav = true;
}
});
return isfav
}
function removeFavourite(ssid, url) {
db_conn.transaction(function (tx) {
tx.executeSql('DELETE FROM Favourites WHERE ssid=? AND url=?', [ssid, url] );
});
}
2021-03-21 00:45:58 +03:00
2021-03-21 14:49:54 +03:00
function simplifyType(mimetype) {
if(Mimer.isImage(mimetype))
{
return {simple: "image", translatable: qsTr("images")};
}
else
{
return {simple: "document", translatable: qsTr("documents")};
}
}
function setJobSettings(uuid, mimetype, settings) {
var type = simplifyType(mimetype).simple;
2021-03-21 00:45:58 +03:00
db_conn.transaction(function (tx) {
2021-03-21 14:49:54 +03:00
tx.executeSql('DELETE FROM JobSettings WHERE uuid=? AND type=?', [uuid, type] );
tx.executeSql('INSERT INTO JobSettings VALUES(?, ?, ?)', [uuid, type, settings] );
2021-03-21 00:45:58 +03:00
});
}
2021-03-21 14:49:54 +03:00
function getJobSettings(uuid, mimetype) {
var type = simplifyType(mimetype).simple;
2021-03-21 00:45:58 +03:00
var settings = "{}";
db_conn.transaction(function (tx) {
2021-03-21 14:49:54 +03:00
var res = tx.executeSql('SELECT * FROM JobSettings WHERE uuid=? AND type=?', [uuid, type]);
2021-03-21 00:45:58 +03:00
if (res.rows.length)
{
settings = res.rows.item(0).data
}
});
return settings
}
2021-03-21 14:49:54 +03:00
function removeJobSettings(uuid, mimetype) {
var type = simplifyType(mimetype).simple;
2021-03-21 00:45:58 +03:00
db_conn.transaction(function (tx) {
2021-03-21 14:49:54 +03:00
tx.executeSql('DELETE FROM JobSettings WHERE uuid=? AND type=?', [uuid, type] );
2021-03-21 00:45:58 +03:00
});
}
2019-12-01 17:55:55 +03:00
}
Notification {
id: notifier
expireTimeout: 4000
function notify(data) {
console.log("notifyMessage", data)
body = data
previewBody = data
publish()
}
}
2020-06-07 15:28:54 +03:00
ConfigurationValue
{
id: nagScreenSetting
key: "/apps/harbour-seaprint/settings/nag-screen"
defaultValue: 0
2021-03-21 18:38:04 +03:00
property int expectedValue: expectCalligra ? 2 : 1
2020-06-07 15:28:54 +03:00
}
2020-06-07 15:33:35 +03:00
2020-06-07 18:05:46 +03:00
ConfigurationValue
{
id: considerAdditionalFormatsSetting
key: "/apps/harbour-seaprint/settings/consider-additional-formats"
defaultValue: true
}
2021-06-19 19:16:42 +03:00
ConfigurationValue
{
2021-06-19 19:16:42 +03:00
id: ignoreSslErrorsSetting
key: SeaPrintSettings.ignoreSslErrorsPath
defaultValue: SeaPrintSettings.ignoreSslErrorsDefault
}
2020-06-21 16:49:50 +03:00
2019-12-01 17:40:10 +03:00
}
2019-12-01 17:55:55 +03:00