diff --git a/harbour-seaprint.pro b/harbour-seaprint.pro index dfff66b..2cf915d 100644 --- a/harbour-seaprint.pro +++ b/harbour-seaprint.pro @@ -14,12 +14,18 @@ TARGET = harbour-seaprint CONFIG += sailfishapp -SOURCES += src/harbour-seaprint.cpp +SOURCES += src/harbour-seaprint.cpp \ + src/ippdiscovery.cpp \ + src/bytestream.cpp \ + src/ippmsg.cpp \ + src/ippprinter.cpp + DISTFILES += qml/harbour-seaprint.qml \ qml/cover/CoverPage.qml \ - qml/pages/FirstPage.qml \ - qml/pages/SecondPage.qml \ + qml/pages/*.qml \ + qml/pages/utils.js \ + qml/pages/printer.svg \ rpm/harbour-seaprint.changes.in \ rpm/harbour-seaprint.changes.run.in \ rpm/harbour-seaprint.spec \ @@ -38,3 +44,9 @@ CONFIG += sailfishapp_i18n # following TRANSLATIONS line. And also do not forget to # modify the localized app name in the the .desktop file. TRANSLATIONS += translations/harbour-seaprint-de.ts + +HEADERS += \ + src/ippdiscovery.h \ + src/bytestream.h \ + src/ippmsg.h \ + src/ippprinter.h diff --git a/qml/harbour-seaprint.qml b/qml/harbour-seaprint.qml index 829cf95..dd1428c 100644 --- a/qml/harbour-seaprint.qml +++ b/qml/harbour-seaprint.qml @@ -1,5 +1,7 @@ import QtQuick 2.0 import Sailfish.Silica 1.0 +import QtQuick.LocalStorage 2.0 +import Nemo.Notifications 1.0 import "pages" ApplicationWindow @@ -7,4 +9,49 @@ ApplicationWindow initialPage: Component { FirstPage { } } cover: Qt.resolvedUrl("cover/CoverPage.qml") allowedOrientations: defaultAllowedOrientations + + Item { + id: db + property var db_conn + + Component.onCompleted: { + db_conn = LocalStorage.openDatabaseSync("TintDB", "1.0", "Tint storage", 100000) + db_conn.transaction(function (tx) { + tx.executeSql('CREATE TABLE IF NOT EXISTS Favourites (url STRING UNIQUE)'); + + }); + } + + function addFavourite(url) { + db_conn.transaction(function (tx) { + tx.executeSql('REPLACE INTO Favourites VALUES(?)', [url] ); + }); + } + + function getFavourites() { + var favs = []; + db_conn.transaction(function (tx) { + var res = tx.executeSql('SELECT * FROM Favourites'); + if (res.rows.length !== 0) { + console.log(res.rows.item(0).url) + favs.push(res.rows.item(0).url); + } + }); + return favs + } + } + + Notification { + id: notifier + + expireTimeout: 4000 + + function notify(data) { + console.log("notifyMessage", data) + body = data + previewBody = data + publish() + } + } } + diff --git a/qml/pages/FirstPage.qml b/qml/pages/FirstPage.qml index 447accf..89af658 100644 --- a/qml/pages/FirstPage.qml +++ b/qml/pages/FirstPage.qml @@ -1,12 +1,32 @@ import QtQuick 2.0 import Sailfish.Silica 1.0 +import Sailfish.Pickers 1.0 +import seaprint.ippdiscovery 1.0 +import seaprint.ippprinter 1.0 +import "utils.js" as Utils +import Nemo.DBus 2.0 Page { id: page - - // The effective value will be restricted by ApplicationWindow.allowedOrientations allowedOrientations: Orientation.All + property string selectedFile: "/home/nemo/Downloads/1.pdf" + + IppDiscovery { + id: discovery + } + + DBusAdaptor { + + } + + Component.onCompleted: { + discovery.discover(); + var favourites = db.getFavourites(); + console.log(favourites); + discovery.favourites = favourites; + } + // To enable PullDownMenu, place our content in a SilicaFlickable SilicaFlickable { anchors.fill: parent @@ -14,29 +34,126 @@ Page { // PullDownMenu and PushUpMenu must be declared in SilicaFlickable, SilicaListView or SilicaGridView PullDownMenu { MenuItem { - text: qsTr("Show Page 2") - onClicked: pageStack.push(Qt.resolvedUrl("SecondPage.qml")) + text: qsTr("Add by URL") + onClicked: {var dialog = pageStack.push(Qt.resolvedUrl("InputDialog.qml"), + {value: qsTr("Add favourite"), title: qsTr("URL")}); + dialog.accepted.connect(function() { + db.addFavourite(dialog.value); + discovery.insert(dialog.value); + }) + } + } + MenuItem { + text: qsTr("Refresh") + onClicked: discovery.discover() } } - // Tell SilicaFlickable the height of its content. - contentHeight: column.height + SilicaListView { + anchors.fill: parent + id: listView + model: discovery + spacing: Theme.paddingSmall - // Place our content in a Column. The PageHeader is always placed at the top - // of the page, followed by our content. - Column { - id: column - width: page.width - spacing: Theme.paddingLarge - PageHeader { - title: qsTr("UI Template") + delegate: BackgroundItem { + id: delegate + height: visible ? Math.max(column.implicitHeight, Theme.itemSizeLarge+2*Theme.paddingMedium) : 0 + visible: printer.attrs["printer-name"] ? true : false + enabled: Utils.can_print(printer, selectedFile) + onClicked: { + if(selectedFile != "") + { + pageStack.push(Qt.resolvedUrl("PrinterPage.qml"), {printer: printer, selectedFile: selectedFile}) + } + else + { + notifier.notify(qsTr("No file selected")) + } + } + + IppPrinter { + id: printer + url: model.display + } + + Image { + id: icon + anchors.top: parent.top + anchors.left: parent.left + anchors.topMargin: Theme.paddingMedium + anchors.leftMargin: Theme.paddingMedium + + height: Theme.itemSizeLarge + width: Theme.itemSizeLarge + source: printer.attrs["printer-icons"] ? printer.attrs["printer-icons"].value[0] : "printer.svg" + // Some printers serve their icons over https with invalid certs... + onStatusChanged: if (status == Image.Error) source = "printer.svg" + } + + Column { + id: column + anchors.left: icon.right + anchors.leftMargin: Theme.paddingMedium + + Label { + id: name_label + color: delegate.enabled ? Theme.primaryColor : Theme.secondaryColor + text: printer.attrs["printer-name"].value + } + + Label { + id: mm_label + color: delegate.enabled ? Theme.primaryColor : Theme.secondaryColor + font.pixelSize: Theme.fontSizeExtraSmall + text: printer.attrs["printer-make-and-model"].value + } + + Label { + id: uri_label + color: Theme.secondaryColor + font.pixelSize: Theme.fontSizeTiny + text: model.display + } + + Label { + id: format_label + color: delegate.enabled ? Theme.primaryColor : "red" + font.pixelSize: Theme.fontSizeExtraSmall + text: Utils.supported_formats(printer) + } + } + } - Label { - x: Theme.horizontalPageMargin - text: qsTr("Hello Sailors") - color: Theme.secondaryHighlightColor - font.pixelSize: Theme.fontSizeExtraLarge + onCountChanged: { + console.log("count", count) + } + } + } + DockedPanel { + id: fileDock + open: true + height: fileButton.height*2 + width: parent.width + dock: Dock.Bottom + + ValueButton { + id: fileButton + width: parent.width + anchors.verticalCenter: parent.verticalCenter + label: qsTr("Choose file") + value: selectedFile != "" ? selectedFile : qsTr("None") + onClicked: pageStack.push(filePickerPage) + } + Component { + id: filePickerPage + FilePickerPage { + title: fileButton.label + nameFilters: ["*.pdf", "*.jpg", "*.jpeg"] + + onSelectedContentPropertiesChanged: { + page.selectedFile = selectedContentProperties.filePath + } } } } diff --git a/src/harbour-seaprint.cpp b/src/harbour-seaprint.cpp index 1eca44f..f9b3ada 100644 --- a/src/harbour-seaprint.cpp +++ b/src/harbour-seaprint.cpp @@ -3,10 +3,15 @@ #endif #include +#include +#include int main(int argc, char *argv[]) { - // SailfishApp::main() will display "qml/harbour-seaprint.qml", if you need more + qmlRegisterType("seaprint.ippdiscovery", 1, 0, "IppDiscovery"); + qmlRegisterType("seaprint.ippprinter", 1, 0, "IppPrinter"); + + // SailfishApp::main() will display "qml/harbour-printtool.qml", if you need more // control over initialization, you can use: // // - SailfishApp::application(int, char *[]) to get the QGuiApplication * diff --git a/translations/harbour-seaprint-de.ts b/translations/harbour-seaprint-de.ts index 7dbef71..d84223e 100644 --- a/translations/harbour-seaprint-de.ts +++ b/translations/harbour-seaprint-de.ts @@ -1,6 +1,6 @@ - + CoverPage @@ -11,16 +11,39 @@ FirstPage - Show Page 2 - Zur Seite 2 + Add by URL + - UI Template - UI-Vorlage + Add favourite + - Hello Sailors - Hallo Matrosen + URL + + + + Refresh + + + + No file selected + + + + Choose file + + + + None + + + + + PrinterPage + + Print + diff --git a/translations/harbour-seaprint.ts b/translations/harbour-seaprint.ts index 0374c0e..7b29f62 100644 --- a/translations/harbour-seaprint.ts +++ b/translations/harbour-seaprint.ts @@ -1,6 +1,6 @@ - + CoverPage @@ -11,15 +11,38 @@ FirstPage - Show Page 2 + Add by URL - UI Template + Add favourite - Hello Sailors + URL + + + + Refresh + + + + No file selected + + + + Choose file + + + + None + + + + + PrinterPage + + Print