Add option to remember settings

This commit is contained in:
Anton Thomasson 2021-03-20 22:45:58 +01:00
parent 9246d385b0
commit 80d5783620
12 changed files with 149 additions and 15 deletions

View file

@ -9,7 +9,14 @@ Setting {
property bool suppressChange: false property bool suppressChange: false
function update_choice() { function update_choice() {
choice = new Object({low: choice_low, high: choice_high}); if (choice_high == 0)
{
choice = undefined;
}
else
{
choice = new Object({low: choice_low, high: choice_high});
}
} }
onChoice_highChanged: { onChoice_highChanged: {
@ -19,10 +26,7 @@ Setting {
{ {
low_slider.value = choice_high > 0 ? choice_high : 1; low_slider.value = choice_high > 0 ? choice_high : 1;
} }
else update_choice()
{
update_choice()
}
} }
} }
onChoice_lowChanged: { onChoice_lowChanged: {
@ -32,10 +36,7 @@ Setting {
{ {
high_slider.value = choice_low high_slider.value = choice_low
} }
else update_choice()
{
update_choice()
}
} }
} }
@ -50,7 +51,7 @@ Setting {
} }
} }
displayValue: choice_high==0 ? qsTr("all") : ""+choice_low+" - "+choice_high displayValue: choice == undefined ? qsTr("all") : ""+choice.low+" - "+choice.high
menu: ContextMenu { menu: ContextMenu {
MenuItem { MenuItem {

View file

@ -29,7 +29,7 @@ ApplicationWindow
db_conn = LocalStorage.openDatabaseSync("SeaprintDB", "1.0", "Seaprint storage", 100000) db_conn = LocalStorage.openDatabaseSync("SeaprintDB", "1.0", "Seaprint storage", 100000)
db_conn.transaction(function (tx) { db_conn.transaction(function (tx) {
tx.executeSql('CREATE TABLE IF NOT EXISTS Favourites (ssid STRING, url STRING)'); tx.executeSql('CREATE TABLE IF NOT EXISTS Favourites (ssid STRING, url STRING)');
tx.executeSql('CREATE TABLE IF NOT EXISTS JobSettings (uuid STRING UNIQUE, data STRING)');
}); });
} }
@ -70,6 +70,30 @@ ApplicationWindow
tx.executeSql('DELETE FROM Favourites WHERE ssid=? AND url=?', [ssid, url] ); tx.executeSql('DELETE FROM Favourites WHERE ssid=? AND url=?', [ssid, url] );
}); });
} }
function setJobSettings(uuid, settings) {
db_conn.transaction(function (tx) {
tx.executeSql('REPLACE INTO JobSettings VALUES(?, ?)', [uuid, settings] );
});
}
function getJobSettings(uuid) {
var settings = "{}";
db_conn.transaction(function (tx) {
var res = tx.executeSql('SELECT * FROM JobSettings WHERE uuid=?', [uuid]);
if (res.rows.length)
{
settings = res.rows.item(0).data
}
});
return settings
}
function removeJobSettings(uuid) {
db_conn.transaction(function (tx) {
tx.executeSql('DELETE FROM JobSettings WHERE uuid=?', [uuid] );
});
}
} }
Notification { Notification {

View file

@ -182,6 +182,19 @@ Page {
property int debugCount: 0 property int debugCount: 0
function maybeGetParams()
{
if(printer.attrs.hasOwnProperty("printer-uuid"))
{
return JSON.parse(db.getJobSettings(printer.attrs["printer-uuid"].value));
}
else
{
return new Object();
}
}
onClicked: { onClicked: {
if(++debugCount == 5) if(++debugCount == 5)
@ -194,7 +207,7 @@ Page {
return; return;
if(selectedFile != "") if(selectedFile != "")
{ {
pageStack.push(Qt.resolvedUrl("PrinterPage.qml"), {printer: printer, selectedFile: selectedFile}) pageStack.push(Qt.resolvedUrl("PrinterPage.qml"), {printer: printer, selectedFile: selectedFile, jobParams: maybeGetParams()})
} }
else else
{ {

View file

@ -1,4 +1,4 @@
import QtQuick 2.0 import QtQuick 2.6
import Sailfish.Silica 1.0 import Sailfish.Silica 1.0
import seaprint.mimer 1.0 import seaprint.mimer 1.0
import seaprint.ippmsg 1.0 import seaprint.ippmsg 1.0
@ -11,7 +11,7 @@ Page {
id: page id: page
property var printer property var printer
property var jobParams: new Object(); property var jobParams
property string selectedFile property string selectedFile
property string selectedFileType: Mimer.get_type(selectedFile) property string selectedFileType: Mimer.get_type(selectedFile)
@ -44,6 +44,27 @@ Page {
// PullDownMenu and PushUpMenu must be declared in SilicaFlickable, SilicaListView or SilicaGridView // PullDownMenu and PushUpMenu must be declared in SilicaFlickable, SilicaListView or SilicaGridView
PullDownMenu { PullDownMenu {
MenuItem {
text: qsTr("Clear default settings")
visible: printer.attrs.hasOwnProperty("printer-uuid")
onClicked: {
db.removeJobSettings(printer.attrs["printer-uuid"].value);
pageStack.pop();
}
}
MenuItem {
text: qsTr("Save default settings")
visible: printer.attrs.hasOwnProperty("printer-uuid")
onClicked: {
var tmp = jobParams;
// Support vries between formats and values varies between documents, would be confusing to save
tmp["page-ranges"] = undefined;
db.setJobSettings(printer.attrs["printer-uuid"].value, JSON.stringify(tmp))
}
}
MenuItem { MenuItem {
text: qsTr("Print") text: qsTr("Print")
onClicked: { onClicked: {
@ -75,6 +96,9 @@ Page {
function isValid(name) { function isValid(name) {
return printer.attrs.hasOwnProperty(name+"-supported"); return printer.attrs.hasOwnProperty(name+"-supported");
} }
function getInitialChoice(name) {
return jobParams.hasOwnProperty(name) ? jobParams[name].value : undefined
}
function getChoices(name) { function getChoices(name) {
return isValid(name) ? printer.attrs[name+"-supported"].value : []; return isValid(name) ? printer.attrs[name+"-supported"].value : [];
} }
@ -88,6 +112,7 @@ Page {
name: "sides" name: "sides"
prettyName: qsTr("Sides") prettyName: qsTr("Sides")
valid: utils.isValid(name) valid: utils.isValid(name)
choice: utils.getInitialChoice(name)
choices: utils.getChoices(name) choices: utils.getChoices(name)
default_choice: utils.getDefaultChoice(name) default_choice: utils.getDefaultChoice(name)
mime_type: selectedFileType mime_type: selectedFileType
@ -99,6 +124,7 @@ Page {
name: "media" name: "media"
prettyName: qsTr("Print media") prettyName: qsTr("Print media")
valid: utils.isValid(name) valid: utils.isValid(name)
choice: utils.getInitialChoice(name)
choices: utils.getChoices(name) choices: utils.getChoices(name)
default_choice: utils.getDefaultChoice(name) default_choice: utils.getDefaultChoice(name)
mime_type: selectedFileType mime_type: selectedFileType
@ -110,6 +136,7 @@ Page {
name: "copies" name: "copies"
prettyName: qsTr("Copies") prettyName: qsTr("Copies")
valid: utils.isValid(name) valid: utils.isValid(name)
choice: utils.getInitialChoice(name)
low: valid ? printer.attrs[name+"-supported"].value.low : 0 low: valid ? printer.attrs[name+"-supported"].value.low : 0
high: valid ? printer.attrs[name+"-supported"].value.high : 0 high: valid ? printer.attrs[name+"-supported"].value.high : 0
default_choice: utils.getDefaultChoice(name) default_choice: utils.getDefaultChoice(name)
@ -121,6 +148,7 @@ Page {
name: "multiple-document-handling" name: "multiple-document-handling"
prettyName: qsTr("Collated copies") prettyName: qsTr("Collated copies")
valid: utils.isValid(name) valid: utils.isValid(name)
choice: utils.getInitialChoice(name)
choices: utils.getChoices(name) choices: utils.getChoices(name)
default_choice: utils.getDefaultChoice(name) default_choice: utils.getDefaultChoice(name)
mime_type: selectedFileType mime_type: selectedFileType
@ -133,9 +161,10 @@ Page {
prettyName: qsTr("Page range") prettyName: qsTr("Page range")
valid: (utils.isValid(name) || ConvertChecker.pdf) && valid: (utils.isValid(name) || ConvertChecker.pdf) &&
(selectedFileType == "application/pdf" || Mimer.isOffice(selectedFileType)) (selectedFileType == "application/pdf" || Mimer.isOffice(selectedFileType))
choice: utils.getInitialChoice(name)
property var pdfpages: ConvertChecker.pdfPages(selectedFile) property var pdfpages: ConvertChecker.pdfPages(selectedFile)
high: name=="page-ranges" ? (pdfpages == 0 ? 65535 : pdfpages) : 0 high: pdfpages == 0 ? 65535 : pdfpages
onChoiceChanged: page.choiceMade(this) onChoiceChanged: page.choiceMade(this)
} }
@ -144,6 +173,7 @@ Page {
name: "print-color-mode" name: "print-color-mode"
prettyName: qsTr("Color mode") prettyName: qsTr("Color mode")
valid: utils.isValid(name) valid: utils.isValid(name)
choice: utils.getInitialChoice(name)
choices: utils.getChoices(name) choices: utils.getChoices(name)
default_choice: utils.getDefaultChoice(name) default_choice: utils.getDefaultChoice(name)
mime_type: selectedFileType mime_type: selectedFileType
@ -154,6 +184,7 @@ Page {
tag: IppMsg.Enum tag: IppMsg.Enum
name: "print-quality" name: "print-quality"
prettyName: qsTr("Quality") prettyName: qsTr("Quality")
choice: utils.getInitialChoice(name)
valid: utils.isValid(name) valid: utils.isValid(name)
choices: utils.getChoices(name) choices: utils.getChoices(name)
default_choice: utils.getDefaultChoice(name) default_choice: utils.getDefaultChoice(name)
@ -166,6 +197,7 @@ Page {
name: "printer-resolution" name: "printer-resolution"
prettyName: qsTr("Resolution") prettyName: qsTr("Resolution")
valid: utils.isValid(name) valid: utils.isValid(name)
choice: utils.getInitialChoice(name)
choices: utils.getChoices(name) choices: utils.getChoices(name)
default_choice: utils.getDefaultChoice(name) default_choice: utils.getDefaultChoice(name)
mime_type: selectedFileType mime_type: selectedFileType
@ -177,6 +209,7 @@ Page {
name: "document-format" name: "document-format"
prettyName: qsTr("Transfer format") prettyName: qsTr("Transfer format")
valid: utils.isValid(name) valid: utils.isValid(name)
choice: utils.getInitialChoice(name)
choices: utils.getChoices(name) choices: utils.getChoices(name)
default_choice: utils.getDefaultChoice(name) default_choice: utils.getDefaultChoice(name)
mime_type: selectedFileType mime_type: selectedFileType
@ -188,6 +221,7 @@ Page {
name: "media-source" name: "media-source"
prettyName: qsTr("Media source") prettyName: qsTr("Media source")
valid: utils.isValid(name) valid: utils.isValid(name)
choice: utils.getInitialChoice(name)
choices: utils.getChoices(name) choices: utils.getChoices(name)
default_choice: utils.getDefaultChoice(name) default_choice: utils.getDefaultChoice(name)
mime_type: selectedFileType mime_type: selectedFileType
@ -199,6 +233,7 @@ Page {
name: "media-col" name: "media-col"
prettyName: qsTr("Zero margins") prettyName: qsTr("Zero margins")
valid: false valid: false
choice: utils.getInitialChoice(name)
printer: page.printer printer: page.printer
onChoiceChanged: page.choiceMade(this) onChoiceChanged: page.choiceMade(this)

View file

@ -54,6 +54,11 @@ function has(arrayish, what)
function ippName(name, value) function ippName(name, value)
{ {
if(value==undefined)
{
return ""
}
switch(name) { switch(name) {
case "job-state": case "job-state":
switch(value) { switch(value) {

View file

@ -442,6 +442,14 @@
<source>Collated copies</source> <source>Collated copies</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<source>Clear default settings</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Save default settings</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>RangeSetting</name> <name>RangeSetting</name>

View file

@ -442,6 +442,14 @@
<source>Collated copies</source> <source>Collated copies</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<source>Clear default settings</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Save default settings</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>RangeSetting</name> <name>RangeSetting</name>

View file

@ -442,6 +442,14 @@
<source>Collated copies</source> <source>Collated copies</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<source>Clear default settings</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Save default settings</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>RangeSetting</name> <name>RangeSetting</name>

View file

@ -442,6 +442,14 @@
<source>Collated copies</source> <source>Collated copies</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<source>Clear default settings</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Save default settings</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>RangeSetting</name> <name>RangeSetting</name>

View file

@ -442,6 +442,14 @@
<source>Collated copies</source> <source>Collated copies</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<source>Clear default settings</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Save default settings</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>RangeSetting</name> <name>RangeSetting</name>

View file

@ -442,6 +442,14 @@
<source>Collated copies</source> <source>Collated copies</source>
<translation></translation> <translation></translation>
</message> </message>
<message>
<source>Clear default settings</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Save default settings</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>RangeSetting</name> <name>RangeSetting</name>

View file

@ -442,6 +442,14 @@
<source>Collated copies</source> <source>Collated copies</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<source>Clear default settings</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Save default settings</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>RangeSetting</name> <name>RangeSetting</name>