Skip to content

Commit

Permalink
[sailfish-office] Store user orientation as a setting per document.
Browse files Browse the repository at this point in the history
  • Loading branch information
dcaliste committed Mar 20, 2018
1 parent 2063326 commit e949bb9
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
3 changes: 2 additions & 1 deletion plugin/PDFDocumentPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ DocumentPage {
_settings = new PDFStorage.Settings(pdfDocument.source)
}
var last = view.getPagePosition()
_settings.setLastPage(last[0] + 1, last[1], last[2], view.itemWidth)
_settings.setLastPage(last[0] + 1, last[1], last[2], view.itemWidth, view.pageRotation)
}

attachedPage: Component {
Expand All @@ -73,6 +73,7 @@ DocumentPage {
_settings = new PDFStorage.Settings(pdfDocument.source)
}
var last = _settings.getLastPage()
view.pageRotation = last[4]
if (last[3] > 0) {
view.itemWidth = last[3]
view.adjust()
Expand Down
29 changes: 20 additions & 9 deletions plugin/PDFStorage.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2015 Caliste Damien.
* Copyright (C) 2015-2018 Caliste Damien.
* Contact: Damien Caliste <[email protected]>
*
* This program is free software; you can redistribute it and/or
Expand All @@ -24,15 +24,24 @@ var Settings = function(file) {

/* Different tables. */
function createTableLastViewSettings(tx) {
/* Currently store the last page, may be altered later to store
zoom level or page position. */
tx.executeSql("CREATE TABLE IF NOT EXISTS Version("
+ "id INT)")
var rs = tx.executeSql('SELECT id FROM Version')
var id = 0
if (rs.rows.length > 0) id = rs.rows.item(0).id

tx.executeSql("CREATE TABLE IF NOT EXISTS LastViewSettings("
+ "file TEXT NOT NULL,"
+ "page INT NOT NULL,"
+ "top REAL ,"
+ "left REAL ,"
+ "width INT CHECK(width > 0))");
tx.executeSql('CREATE UNIQUE INDEX IF NOT EXISTS idx_file ON LastViewSettings(file)');
+ "width INT CHECK(width > 0),"
+ "orientation INT DEFAULT 0)")
tx.executeSql('CREATE UNIQUE INDEX IF NOT EXISTS idx_file ON LastViewSettings(file)')
if (id == 0)
tx.executeSql('ALTER TABLE LastViewSettings ADD COLUMN orientation INT DEFAULT 0')

tx.executeSql('INSERT OR REPLACE INTO Version(id) VALUES (1)')
}

/* Get and set operations. */
Expand All @@ -42,24 +51,26 @@ Settings.prototype.getLastPage = function() {
var left = 0
var width = 0
var file = this.source
var orientation = 0
this.db.transaction(function(tx) {
createTableLastViewSettings(tx);
var rs = tx.executeSql('SELECT page, top, left, width FROM LastViewSettings WHERE file = ?', [file]);
var rs = tx.executeSql('SELECT page, top, left, width, orientation FROM LastViewSettings WHERE file = ?', [file]);
if (rs.rows.length > 0) {
page = rs.rows.item(0).page;
top = rs.rows.item(0).top;
left = rs.rows.item(0).left;
width = rs.rows.item(0).width;
orientation = rs.rows.item(0).orientation;
}
});
// Return page is in [1:]
return [page, top, left, width];
return [page, top, left, width, orientation];
}
Settings.prototype.setLastPage = function(page, top, left, width) {
Settings.prototype.setLastPage = function(page, top, left, width, orientation) {
// page is in [1:]
var file = this.source
this.db.transaction(function(tx) {
createTableLastViewSettings(tx);
var rs = tx.executeSql('INSERT OR REPLACE INTO LastViewSettings(file, page, top, left, width) VALUES (?,?,?,?,?)', [file, page, top, left, width]);
var rs = tx.executeSql('INSERT OR REPLACE INTO LastViewSettings(file, page, top, left, width, orientation) VALUES (?,?,?,?,?,?)', [file, page, top, left, width, orientation]);
});
}
1 change: 1 addition & 0 deletions plugin/PDFView.qml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ SilicaFlickable {
property alias itemWidth: pdfCanvas.width
property alias itemHeight: pdfCanvas.height
property alias document: pdfCanvas.document
property alias pageRotation: pdfCanvas.pageRotation
property int currentPage: !quickScrollAnimation.running
? pdfCanvas.currentPage : quickScrollAnimation.pageTo
property alias selection: pdfSelection
Expand Down

0 comments on commit e949bb9

Please sign in to comment.