Add option to remember settings
This commit is contained in:
parent
9246d385b0
commit
80d5783620
12 changed files with 149 additions and 15 deletions
|
@ -9,8 +9,15 @@ Setting {
|
|||
property bool suppressChange: false
|
||||
|
||||
function update_choice() {
|
||||
if (choice_high == 0)
|
||||
{
|
||||
choice = undefined;
|
||||
}
|
||||
else
|
||||
{
|
||||
choice = new Object({low: choice_low, high: choice_high});
|
||||
}
|
||||
}
|
||||
|
||||
onChoice_highChanged: {
|
||||
if(!suppressChange)
|
||||
|
@ -19,12 +26,9 @@ Setting {
|
|||
{
|
||||
low_slider.value = choice_high > 0 ? choice_high : 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
update_choice()
|
||||
}
|
||||
}
|
||||
}
|
||||
onChoice_lowChanged: {
|
||||
if(!suppressChange)
|
||||
{
|
||||
|
@ -32,12 +36,9 @@ Setting {
|
|||
{
|
||||
high_slider.value = choice_low
|
||||
}
|
||||
else
|
||||
{
|
||||
update_choice()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
onChoiceChanged: {
|
||||
if(choice == undefined)
|
||||
|
@ -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 {
|
||||
MenuItem {
|
||||
|
|
|
@ -29,7 +29,7 @@ ApplicationWindow
|
|||
db_conn = LocalStorage.openDatabaseSync("SeaprintDB", "1.0", "Seaprint storage", 100000)
|
||||
db_conn.transaction(function (tx) {
|
||||
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] );
|
||||
});
|
||||
}
|
||||
|
||||
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 {
|
||||
|
|
|
@ -182,6 +182,19 @@ Page {
|
|||
|
||||
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: {
|
||||
|
||||
if(++debugCount == 5)
|
||||
|
@ -194,7 +207,7 @@ Page {
|
|||
return;
|
||||
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
|
||||
{
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import QtQuick 2.0
|
||||
import QtQuick 2.6
|
||||
import Sailfish.Silica 1.0
|
||||
import seaprint.mimer 1.0
|
||||
import seaprint.ippmsg 1.0
|
||||
|
@ -11,7 +11,7 @@ Page {
|
|||
|
||||
id: page
|
||||
property var printer
|
||||
property var jobParams: new Object();
|
||||
property var jobParams
|
||||
property string 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 {
|
||||
|
||||
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 {
|
||||
text: qsTr("Print")
|
||||
onClicked: {
|
||||
|
@ -75,6 +96,9 @@ Page {
|
|||
function isValid(name) {
|
||||
return printer.attrs.hasOwnProperty(name+"-supported");
|
||||
}
|
||||
function getInitialChoice(name) {
|
||||
return jobParams.hasOwnProperty(name) ? jobParams[name].value : undefined
|
||||
}
|
||||
function getChoices(name) {
|
||||
return isValid(name) ? printer.attrs[name+"-supported"].value : [];
|
||||
}
|
||||
|
@ -88,6 +112,7 @@ Page {
|
|||
name: "sides"
|
||||
prettyName: qsTr("Sides")
|
||||
valid: utils.isValid(name)
|
||||
choice: utils.getInitialChoice(name)
|
||||
choices: utils.getChoices(name)
|
||||
default_choice: utils.getDefaultChoice(name)
|
||||
mime_type: selectedFileType
|
||||
|
@ -99,6 +124,7 @@ Page {
|
|||
name: "media"
|
||||
prettyName: qsTr("Print media")
|
||||
valid: utils.isValid(name)
|
||||
choice: utils.getInitialChoice(name)
|
||||
choices: utils.getChoices(name)
|
||||
default_choice: utils.getDefaultChoice(name)
|
||||
mime_type: selectedFileType
|
||||
|
@ -110,6 +136,7 @@ Page {
|
|||
name: "copies"
|
||||
prettyName: qsTr("Copies")
|
||||
valid: utils.isValid(name)
|
||||
choice: utils.getInitialChoice(name)
|
||||
low: valid ? printer.attrs[name+"-supported"].value.low : 0
|
||||
high: valid ? printer.attrs[name+"-supported"].value.high : 0
|
||||
default_choice: utils.getDefaultChoice(name)
|
||||
|
@ -121,6 +148,7 @@ Page {
|
|||
name: "multiple-document-handling"
|
||||
prettyName: qsTr("Collated copies")
|
||||
valid: utils.isValid(name)
|
||||
choice: utils.getInitialChoice(name)
|
||||
choices: utils.getChoices(name)
|
||||
default_choice: utils.getDefaultChoice(name)
|
||||
mime_type: selectedFileType
|
||||
|
@ -133,9 +161,10 @@ Page {
|
|||
prettyName: qsTr("Page range")
|
||||
valid: (utils.isValid(name) || ConvertChecker.pdf) &&
|
||||
(selectedFileType == "application/pdf" || Mimer.isOffice(selectedFileType))
|
||||
choice: utils.getInitialChoice(name)
|
||||
|
||||
property var pdfpages: ConvertChecker.pdfPages(selectedFile)
|
||||
high: name=="page-ranges" ? (pdfpages == 0 ? 65535 : pdfpages) : 0
|
||||
high: pdfpages == 0 ? 65535 : pdfpages
|
||||
|
||||
onChoiceChanged: page.choiceMade(this)
|
||||
}
|
||||
|
@ -144,6 +173,7 @@ Page {
|
|||
name: "print-color-mode"
|
||||
prettyName: qsTr("Color mode")
|
||||
valid: utils.isValid(name)
|
||||
choice: utils.getInitialChoice(name)
|
||||
choices: utils.getChoices(name)
|
||||
default_choice: utils.getDefaultChoice(name)
|
||||
mime_type: selectedFileType
|
||||
|
@ -154,6 +184,7 @@ Page {
|
|||
tag: IppMsg.Enum
|
||||
name: "print-quality"
|
||||
prettyName: qsTr("Quality")
|
||||
choice: utils.getInitialChoice(name)
|
||||
valid: utils.isValid(name)
|
||||
choices: utils.getChoices(name)
|
||||
default_choice: utils.getDefaultChoice(name)
|
||||
|
@ -166,6 +197,7 @@ Page {
|
|||
name: "printer-resolution"
|
||||
prettyName: qsTr("Resolution")
|
||||
valid: utils.isValid(name)
|
||||
choice: utils.getInitialChoice(name)
|
||||
choices: utils.getChoices(name)
|
||||
default_choice: utils.getDefaultChoice(name)
|
||||
mime_type: selectedFileType
|
||||
|
@ -177,6 +209,7 @@ Page {
|
|||
name: "document-format"
|
||||
prettyName: qsTr("Transfer format")
|
||||
valid: utils.isValid(name)
|
||||
choice: utils.getInitialChoice(name)
|
||||
choices: utils.getChoices(name)
|
||||
default_choice: utils.getDefaultChoice(name)
|
||||
mime_type: selectedFileType
|
||||
|
@ -188,6 +221,7 @@ Page {
|
|||
name: "media-source"
|
||||
prettyName: qsTr("Media source")
|
||||
valid: utils.isValid(name)
|
||||
choice: utils.getInitialChoice(name)
|
||||
choices: utils.getChoices(name)
|
||||
default_choice: utils.getDefaultChoice(name)
|
||||
mime_type: selectedFileType
|
||||
|
@ -199,6 +233,7 @@ Page {
|
|||
name: "media-col"
|
||||
prettyName: qsTr("Zero margins")
|
||||
valid: false
|
||||
choice: utils.getInitialChoice(name)
|
||||
printer: page.printer
|
||||
|
||||
onChoiceChanged: page.choiceMade(this)
|
||||
|
|
|
@ -54,6 +54,11 @@ function has(arrayish, what)
|
|||
|
||||
function ippName(name, value)
|
||||
{
|
||||
if(value==undefined)
|
||||
{
|
||||
return ""
|
||||
}
|
||||
|
||||
switch(name) {
|
||||
case "job-state":
|
||||
switch(value) {
|
||||
|
|
|
@ -442,6 +442,14 @@
|
|||
<source>Collated copies</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</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>
|
||||
<name>RangeSetting</name>
|
||||
|
|
|
@ -442,6 +442,14 @@
|
|||
<source>Collated copies</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</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>
|
||||
<name>RangeSetting</name>
|
||||
|
|
|
@ -442,6 +442,14 @@
|
|||
<source>Collated copies</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</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>
|
||||
<name>RangeSetting</name>
|
||||
|
|
|
@ -442,6 +442,14 @@
|
|||
<source>Collated copies</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</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>
|
||||
<name>RangeSetting</name>
|
||||
|
|
|
@ -442,6 +442,14 @@
|
|||
<source>Collated copies</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</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>
|
||||
<name>RangeSetting</name>
|
||||
|
|
|
@ -442,6 +442,14 @@
|
|||
<source>Collated copies</source>
|
||||
<translation>整理后的副本</translation>
|
||||
</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>
|
||||
<name>RangeSetting</name>
|
||||
|
|
|
@ -442,6 +442,14 @@
|
|||
<source>Collated copies</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</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>
|
||||
<name>RangeSetting</name>
|
||||
|
|
Loading…
Reference in a new issue