From db655e3a0a177afaba64053c4ea653e6342bf21b Mon Sep 17 00:00:00 2001 From: Ruediger Gad Date: Thu, 12 Apr 2012 20:07:26 +0200 Subject: [PATCH] Add DB for storing address and port. Add AboutDialog. --- QZeeControl.pro.user | 2 +- qml/QZeeControl/AboutDialog.qml | 71 ++++++++++++ qml/QZeeControl/MainPage.qml | 222 ++++++++++++++++++++---------------- qml/QZeeControl/main.qml | 9 +- qml/QZeeControl/settingsstorage.js | 62 ++++++++++ 5 files changed, 266 insertions(+), 100 deletions(-) create mode 100644 qml/QZeeControl/AboutDialog.qml create mode 100644 qml/QZeeControl/settingsstorage.js diff --git a/QZeeControl.pro.user b/QZeeControl.pro.user index 9df03b1..de527c5 100644 --- a/QZeeControl.pro.user +++ b/QZeeControl.pro.user @@ -1,6 +1,6 @@ - + ProjectExplorer.Project.ActiveTarget diff --git a/qml/QZeeControl/AboutDialog.qml b/qml/QZeeControl/AboutDialog.qml new file mode 100644 index 0000000..b433c82 --- /dev/null +++ b/qml/QZeeControl/AboutDialog.qml @@ -0,0 +1,71 @@ +/* + * Copyright 2012 Ruediger Gad + * + * This file is part of QZeeControl. + * + * QZeeControl is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * QZeeControl is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with QZeeControl. If not, see . + */ + +import QtQuick 1.1 +import com.nokia.meego 1.0 + +Dialog { + id: aboutDialog + + content:Item { + anchors.fill: parent + + Text { + id: homepage + text: "QZeeControl
Version 0.0.1
" + textFormat: Text.RichText; + onLinkActivated: { Qt.openUrlExternally(link); } + font.pixelSize: 25; horizontalAlignment: Text.AlignHCenter; + anchors.horizontalCenter: parent.horizontalCenter; anchors.bottom: description.top; anchors.bottomMargin: 8 + } + + Text { + id: description + text: "Control your N9 remotely." + font.pixelSize: 25; font.bold: true; anchors.horizontalCenter: parent.horizontalCenter; anchors.bottom: author.top; anchors.bottomMargin: 12; color: "white" + } + + Text { + id: author; + text: "Author:
" + + "Ruediger Gad - r.c.g@gmx.de
" + textFormat: Text.RichText; + onLinkActivated: { Qt.openUrlExternally(link); } + font.pixelSize: 20; anchors.centerIn: parent; color: "lightgray"; horizontalAlignment: Text.AlignHCenter + } + + Text { + id: license + text: "QZeeControl is free software: you can redistribute it and/or modify " + + "it under the terms of the GNU General Public License as published by " + + "the Free Software Foundation, either version 3 of the License, or " + + "(at your option) any later version."; + textFormat: Text.RichText; + onLinkActivated: { Qt.openUrlExternally(link); } + font.pixelSize: 18; + anchors.horizontalCenter: parent.horizontalCenter; + anchors.top: author.bottom; + anchors.topMargin: 12; + width: parent.width; + color: "lightgray"; + horizontalAlignment: Text.AlignHCenter; + wrapMode: Text.Wrap + } + } +} diff --git a/qml/QZeeControl/MainPage.qml b/qml/QZeeControl/MainPage.qml index dc08d05..c086e98 100644 --- a/qml/QZeeControl/MainPage.qml +++ b/qml/QZeeControl/MainPage.qml @@ -26,6 +26,8 @@ import qzeecontrol 1.0 Page { tools: commonTools + orientationLock: PageOrientation.LockPortrait + Component.onCompleted: { SettingsStorage.initialize(); @@ -102,132 +104,156 @@ Page { } } - Button{ - id: scanButton - anchors{bottom: addressRow.top; bottomMargin: 10; horizontalCenter: parent.horizontalCenter} - enabled: true + Item { + anchors.fill: parent + + Image { + id: header + height: 72 + source: "image://theme/color8-meegotouch-view-header-fixed" + anchors.left: parent.left + anchors.top: parent.top + anchors.right: parent.right + + Text { + text: "QZeeControl" + color: "white" + font.family: "Nokia Pure Text Light" + font.pixelSize: 32 + anchors.left: parent.left + anchors.leftMargin: 20 + anchors.verticalCenter: parent.verticalCenter + } + } + + Button{ + id: scanButton + anchors{bottom: addressRow.top; bottomMargin: 10; horizontalCenter: parent.horizontalCenter} + enabled: true - text: "Scan" + text: "Scan" - onClicked: { - btDiscovery.discovery = true + onClicked: { + btDiscovery.discovery = true + } } - } - Row{ - id: addressRow - spacing: 5 - anchors{bottom: infoText.top; bottomMargin: 10; horizontalCenter: parent.horizontalCenter} + Row{ + id: addressRow + spacing: 5 + anchors{bottom: infoText.top; bottomMargin: 10; horizontalCenter: parent.horizontalCenter} - TextField{ - id: addressField - text: "No device found yet." + TextField{ + id: addressField + text: "No device found yet." - onTextChanged: { - if(text === "No device found yet.") - return + onTextChanged: { + if(text === "No device found yet.") + return - connectButton.enabled = true - infoText.text = "Press \"Connect\" to connect to the device." - console.log("Storing address in DB: " + text) - SettingsStorage.setSetting("address", text) + connectButton.enabled = true + infoText.text = "Press \"Connect\" to connect to the device." + console.log("Storing address in DB: " + text) + SettingsStorage.setSetting("address", text) + } } - } - TextField{ - id: portField - text: "na" - width: 60 - validator: IntValidator{} - - onTextChanged: { - if(text === "na") - return - - console.log("Storing port in DB: " + text) - SettingsStorage.setSetting("port", text) + TextField{ + id: portField + text: "na" + width: 60 + validator: IntValidator{} + + onTextChanged: { + if(text === "na") + return + + console.log("Storing port in DB: " + text) + SettingsStorage.setSetting("port", text) + } } } - } - Label { - id: infoText - anchors{bottom: connectButton.top; bottomMargin: 10; horizontalCenter: parent.horizontalCenter} - width: parent.width + Label { + id: infoText + anchors{bottom: connectButton.top; bottomMargin: 10; horizontalCenter: parent.horizontalCenter} + width: parent.width - text: "Please scan for a device first." - horizontalAlignment: Text.AlignHCenter - wrapMode: Text.WordWrap - } + text: "Please scan for a device first." + horizontalAlignment: Text.AlignHCenter + wrapMode: Text.WordWrap + } - Button{ - id: connectButton - anchors{bottom: disconnectButton.top; bottomMargin: 10; horizontalCenter: parent.horizontalCenter} - enabled: false + Button{ + id: connectButton + anchors{bottom: disconnectButton.top; bottomMargin: 10; horizontalCenter: parent.horizontalCenter} + enabled: false - text: "Connect" + text: "Connect" - onClicked: { - enabled = false - btConn.connect(addressField.text, parseInt(portField.text)) + onClicked: { + enabled = false + btConn.connect(addressField.text, parseInt(portField.text)) + } } - } - Button{ - id: disconnectButton - anchors{bottom: buttonRow.top; bottomMargin: 10; horizontalCenter: parent.horizontalCenter} + Button{ + id: disconnectButton + anchors.centerIn: parent - text: "Disconnect" + text: "Disconnect" - onClicked: { - btConn.disconnect() + onClicked: { + btConn.disconnect() + } } - } - Row{ - id: buttonRow - anchors.centerIn: parent - spacing: 20 + Row{ + id: buttonRow + anchors{top: disconnectButton.bottom; bottomMargin: 10; horizontalCenter: parent.horizontalCenter} - Label{ - id: labelA - text: "A" - color: btConn.a ? "red" : "blue" - } - Label{ - id: labelB - text: "B" - color: btConn.b ? "red" : "blue" - } - Label{ - id: labelC - text: "C" - color: btConn.c ? "red" : "blue" - } - Label{ - id: labelD - text: "D" - color: btConn.d ? "red" : "blue" + spacing: 20 + + Label{ + id: labelA + text: "A" + color: btConn.a ? "red" : "blue" + } + Label{ + id: labelB + text: "B" + color: btConn.b ? "red" : "blue" + } + Label{ + id: labelC + text: "C" + color: btConn.c ? "red" : "blue" + } + Label{ + id: labelD + text: "D" + color: btConn.d ? "red" : "blue" + } } - } - Rectangle{ - id: moveArea - anchors{top: buttonRow.bottom; topMargin: 10; horizontalCenter: parent.horizontalCenter} - color: "gray" + Rectangle{ + id: moveArea + anchors{top: buttonRow.bottom; topMargin: 10; horizontalCenter: parent.horizontalCenter} + color: "gray" - width: 256 - height: 256 - } + width: 256 + height: 256 + } - Rectangle{ - id: cursorRectangle - width: 10 - height: 10 - color: "red" + Rectangle{ + id: cursorRectangle + width: 10 + height: 10 + color: "red" - x: moveArea.x + (moveArea.width * 0.5) + btConn.x - (cursorRectangle.width * 0.5) - y: moveArea.y + (moveArea.height * 0.5) + btConn.y - (cursorRectangle.height * 0.5) + x: moveArea.x + (moveArea.width * 0.5) + btConn.x - (cursorRectangle.width * 0.5) + y: moveArea.y + (moveArea.height * 0.5) + btConn.y - (cursorRectangle.height * 0.5) + } } BluetoothDiscoveryModel{ diff --git a/qml/QZeeControl/main.qml b/qml/QZeeControl/main.qml index d57f59a..8e72fa9 100644 --- a/qml/QZeeControl/main.qml +++ b/qml/QZeeControl/main.qml @@ -43,7 +43,14 @@ PageStackWindow { id: myMenu visualParent: pageStack MenuLayout { - MenuItem { text: "About" } + MenuItem { + text: "About" + onClicked: aboutDialog.open() + } } } + + AboutDialog{ + id: aboutDialog + } } diff --git a/qml/QZeeControl/settingsstorage.js b/qml/QZeeControl/settingsstorage.js new file mode 100644 index 0000000..21abede --- /dev/null +++ b/qml/QZeeControl/settingsstorage.js @@ -0,0 +1,62 @@ +/* + * The following code is taken from: + * http://www.developer.nokia.com/Community/Wiki/How-to_create_a_persistent_settings_database_in_Qt_Quick_%28QML%29 + * At the time of writing (2011-11-12) there were no copyright or licensing notes in place at the above web site. + * Hence, the following code is treated as public domain and has been simply copied and pasted here as is. + * Note: the application name and the name and size of the database had been changed to reflect Simplictionary. + * The version number is intended to describe the "storage format". + * Thanks to the original author (Slocan) for sharing this code. + */ + +//storage.js +// First, let's create a short helper function to get the database connection +function getDatabase() { + return openDatabaseSync("QZeeControl", "1.0", "SettingsStorageDatabase", 4000); +} + +// At the start of the application, we can initialize the tables we need if they haven't been created yet +function initialize() { + var db = getDatabase(); + db.transaction( + function(tx) { + // Create the settings table if it doesn't already exist + // If the table exists, this is skipped + tx.executeSql('CREATE TABLE IF NOT EXISTS settings(setting TEXT UNIQUE, value TEXT)'); + }); +} + +// This function is used to write a setting into the database +function setSetting(setting, value) { + // setting: string representing the setting name (eg: “username”) + // value: string representing the value of the setting (eg: “myUsername”) + var db = getDatabase(); + var res = ""; + db.transaction(function(tx) { + var rs = tx.executeSql('INSERT OR REPLACE INTO settings VALUES (?,?);', [setting,value]); + //console.log(rs.rowsAffected) + if (rs.rowsAffected > 0) { + res = "OK"; + } else { + res = "Error"; + } + } + ); + // The function returns “OK” if it was successful, or “Error” if it wasn't + return res; +} +// This function is used to retrieve a setting from the database +function getSetting(setting) { + var db = getDatabase(); + var res=""; + db.transaction(function(tx) { + var rs = tx.executeSql('SELECT value FROM settings WHERE setting=?;', [setting]); + if (rs.rows.length > 0) { + res = rs.rows.item(0).value; + } else { + res = "Unknown"; + } + }) + // The function returns “Unknown” if the setting was not found in the database + // For more advanced projects, this should probably be handled through error codes + return res +} -- 1.7.9.5