added simple login page and about page, not functional yet, since i have to code the javascript

This commit is contained in:
Hauke Schade 2012-11-16 00:28:37 +01:00
parent 7a0b160c89
commit 039b3024cb
6 changed files with 630 additions and 29 deletions

123
qml/ttrss/About.qml Normal file
View file

@ -0,0 +1,123 @@
//Copyright Hauke Schade, 2012
//
//This file is part of TTRss.
//
//TTRss 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 2 of the License, or (at your option) any later version.
//TTRss 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 TTRss (on a Maemo/Meego system there is a copy
//in /usr/share/common-licenses. If not, see http://www.gnu.org/licenses/.
import QtQuick 1.1
import com.nokia.meego 1.0
import QtWebKit 1.0
Page {
tools: aboutTools
state: (screen.currentOrientation === Screen.Portrait) ? "portrait" : "landscape"
states: [
State {
name: "landscape"
PropertyChanges {
target: logo
anchors.leftMargin: 50
anchors.topMargin: 50
}
AnchorChanges {
target: logo
anchors {
horizontalCenter: undefined
left: parent.left
top: parent.top
}
}
AnchorChanges {
target: aboutInfoContainer
anchors {
horizontalCenter: undefined
left: logo.right
top: logo.top
}
}
PropertyChanges {
target: aboutInfoContainer
anchors.leftMargin: 50
}
},
State {
name: "portrait"
AnchorChanges {
target: logo
anchors {
left: undefined
top: parent.top
horizontalCenter: parent.horizontalCenter
}
}
AnchorChanges {
target: aboutInfoContainer
anchors {
left: undefined
top: logo.bottom
horizontalCenter: parent.horizontalCenter
}
}
PropertyChanges {
target: aboutInfoContainer
anchors.topMargin: 50
}
}
]
transitions: Transition {
AnchorAnimation { duration: 500 }
}
Column {
id: logo
anchors {
top: parent.top
topMargin: 30
}
Image {
width: 398
height: 225
source: "resources/ttrsslogo.png"
}
}
Column {
id: aboutInfoContainer
Label {
id: aboutInfo
width: 350
text: qsTr("Version")+": 0.0.1<br/>"
+qsTr("Copyright")+": Hauke Schade 2012<br/>"
+'<a href="http://github.com/cnlpete/ttrss">'+qsTr('TTRss Privacy Policy')+'</a><br/>';
onLinkActivated: {
Qt.openUrlExternally(link)
}
}
}
ToolBarLayout {
id: aboutTools
ToolIcon {
iconId: "toolbar-back";
onClicked: { pageStack.pop(); }
}
}
}

View file

@ -1,23 +1,248 @@
//Copyright Hauke Schade, 2012
//
//This file is part of TTRss.
//
//TTRss 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 2 of the License, or (at your option) any later version.
//TTRss 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 TTRss (on a Maemo/Meego system there is a copy
//in /usr/share/common-licenses. If not, see http://www.gnu.org/licenses/.
import QtQuick 1.1
import com.nokia.meego 1.0
Page {
function openFile(file) {
var component = Qt.createComponent(file)
if (component.status === Component.Ready)
pageStack.push(component);
else
console.log("Error loading component:", component.errorString());
}
property bool loading: false
tools: commonTools
Label {
id: label
anchors.centerIn: parent
text: qsTr("Hello world!")
visible: false
state: (screen.currentOrientation === Screen.Portrait) ? "portrait" : "landscape"
states: [
State {
name: "landscape"
PropertyChanges {
target: logo
anchors.leftMargin: 50
anchors.topMargin: 50
}
AnchorChanges {
target: logo
anchors {
horizontalCenter: undefined
left: parent.left
top: parent.top
}
}
AnchorChanges {
target: loginBox
anchors {
horizontalCenter: undefined
left: logo.right
top: logo.top
}
}
PropertyChanges {
target: loginBox
anchors.leftMargin: 50
}
},
State {
name: "portrait"
AnchorChanges {
target: logo
anchors {
left: undefined
top: parent.top
horizontalCenter: parent.horizontalCenter
}
}
AnchorChanges {
target: loginBox
anchors {
left: undefined
top: logo.bottom
horizontalCenter: parent.horizontalCenter
}
}
PropertyChanges {
target: loginBox
anchors.topMargin: 50
}
}
]
transitions: Transition {
AnchorAnimation { duration: 500 }
}
Button{
Column {
id: logo
anchors {
top: parent.top
topMargin: 30
}
Image {
width: 398
height: 225
source: "resources/ttrsslogo.png"
}
}
Column {
id: loginBox
Label {
id: serverLabel
text: qsTr("Server:")
}
TextField {
id: server
text: ""
width: 300
enabled: !loading
}
Label {
id: usernameLabel
text: qsTr("Username:")
}
TextField {
id: username
text: ""
width: 300
enabled: !loading
}
Label {
id: passwordLabel
text: qsTr("Password:")
}
TextField {
id: password
echoMode: TextInput.PasswordEchoOnEdit
width: 300
enabled: !loading
}
}
BusyIndicator {
id: busyindicator1
visible: loading
running: loading
anchors {
horizontalCenter: parent.horizontalCenter
top: label.bottom
topMargin: 10
verticalCenter: parent.verticalCenter
}
platformStyle: BusyIndicatorStyle { size: 'large' }
}
ToolBarLayout {
id: commonTools
visible: true
ToolButton {
id: loginButton
text: qsTr("Login")
anchors.right: menuButton.left
onClicked: {
var settings = rootWindow.settingsObject();
settings.set("server", server.text);
settings.set("username", username.text);
settings.set("password", password.text);
startLogin();
}
enabled: !loading
}
ToolIcon {
id: menuButton
platformIconId: "toolbar-view-menu"
anchors.right: (parent === undefined) ? undefined : parent.right
onClicked: (myMenu.status === DialogStatus.Closed) ? myMenu.open() : myMenu.close()
enabled: !loading
}
}
Menu {
id: myMenu
visualParent: pageStack
MenuLayout {
MenuItem {
text: qsTr("About")
onClicked: {
openFile("About.qml");
}
}
}
}
function enableLoginBox(focus) {
if(focus) {
password.forceActiveFocus();
}
}
function startLogin() {
// close the menu
if (myMenu.status !== DialogStatus.Closed)
myMenu.close()
//Start the loading anim
loading = true;
}
//Dialog for login errors
Dialog {
id: loginErrorDialog
title: Rectangle {
id: titleField
height: 2
width: parent.width
color: "red"
}
content:Item {
id: loginErrorDialogContents
height: 50
width: parent.width
Text {
id: loginErrorDialogText
font.pixelSize: 22
anchors.centerIn: parent
color: "white"
text: "Hello Dialog"
}
}
buttons: ButtonRow {
style: ButtonStyle { }
anchors.horizontalCenter: parent.horizontalCenter
Button { text: "OK"; onClicked: loginErrorDialog.accept() }
}
}
Component.onCompleted: {
var settings = rootWindow.settingsObject();
settings.initialize();
server.text = settings.get("server", "http://");
username.text = settings.get("username", "");
password.text = settings.get("password", "");
var dologin = settings.get("dologin", "false");
if(dologin === "true") {
startLogin();
}
text: qsTr("Click here!")
onClicked: label.visible = true
}
}

35
qml/ttrss/dump.js Normal file
View file

@ -0,0 +1,35 @@
/**
* Function : dump()
* Arguments: The data - array,hash(associative array),object
* The level - OPTIONAL
* Returns : The textual representation of the array.
* This function was inspired by the print_r function of PHP.
* This will accept some data as the argument and return a
* text that will be a more readable version of the
* array/hash/object that is given.
* Docs: http://www.openjs.com/scripts/others/dump_function_php_print_r.php
*/
function dump(arr,level) {
var dumped_text = "";
if(!level) level = 0;
//The padding given at the beginning of the line.
var level_padding = "";
for(var j=0;j<level+1;j++) level_padding += " ";
if(typeof(arr) == 'object') { //Array/Hashes/Objects
for(var item in arr) {
var value = arr[item];
if(typeof(value) == 'object') { //If it is an array,
dumped_text += level_padding + "'" + item + "' ...\n";
dumped_text += dump(value,level+1);
} else {
dumped_text += level_padding + "'" + item + "' => \"" + value + "\"\n";
}
}
} else { //Stings/Chars/Numbers etc.
dumped_text = "===>"+arr+"<===("+typeof(arr)+")";
}
return dumped_text;
}

171
qml/ttrss/htmlentities.js Normal file
View file

@ -0,0 +1,171 @@
function get_html_translation_table (table, quote_style) {
// Returns the internal translation table used by htmlspecialchars and htmlentities
//
// version: 1109.2015
// discuss at: http://phpjs.org/functions/get_html_translation_table // + original by: Philip Peterson
// + revised by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
// + bugfixed by: noname
// + bugfixed by: Alex
// + bugfixed by: Marco // + bugfixed by: madipta
// + improved by: KELAN
// + improved by: Brett Zamir (http://brett-zamir.me)
// + bugfixed by: Brett Zamir (http://brett-zamir.me)
// + input by: Frank Forte // + bugfixed by: T.Wild
// + input by: Ratheous
// % note: It has been decided that we're not going to add global
// % note: dependencies to php.js, meaning the constants are not
// % note: real constants, but strings instead. Integers are also supported if someone // % note: chooses to create the constants themselves.
// * example 1: get_html_translation_table('HTML_SPECIALCHARS');
// * returns 1: {'"': '&quot;', '&': '&amp;', '<': '&lt;', '>': '&gt;'}
var entities = {},
hash_map = {}, decimal;
var constMappingTable = {},
constMappingQuoteStyle = {};
var useTable = {},
useQuoteStyle = {};
// Translate arguments
constMappingTable[0] = 'HTML_SPECIALCHARS';
constMappingTable[1] = 'HTML_ENTITIES';
constMappingQuoteStyle[0] = 'ENT_NOQUOTES'; constMappingQuoteStyle[2] = 'ENT_COMPAT';
constMappingQuoteStyle[3] = 'ENT_QUOTES';
useTable = !isNaN(table) ? constMappingTable[table] : table ? table.toUpperCase() : 'HTML_SPECIALCHARS';
useQuoteStyle = !isNaN(quote_style) ? constMappingQuoteStyle[quote_style] : quote_style ? quote_style.toUpperCase() : 'ENT_COMPAT';
if (useTable !== 'HTML_SPECIALCHARS' && useTable !== 'HTML_ENTITIES') {
throw new Error("Table: " + useTable + ' not supported');
// return false;
}
entities['38'] = '&amp;';
if (useTable === 'HTML_ENTITIES') {
entities['160'] = '&nbsp;';
entities['161'] = '&iexcl;'; entities['162'] = '&cent;';
entities['163'] = '&pound;';
entities['164'] = '&curren;';
entities['165'] = '&yen;';
entities['166'] = '&brvbar;'; entities['167'] = '&sect;';
entities['168'] = '&uml;';
entities['169'] = '&copy;';
entities['170'] = '&ordf;';
entities['171'] = '&laquo;'; entities['172'] = '&not;';
entities['173'] = '&shy;';
entities['174'] = '&reg;';
entities['175'] = '&macr;';
entities['176'] = '&deg;'; entities['177'] = '&plusmn;';
entities['178'] = '&sup2;';
entities['179'] = '&sup3;';
entities['180'] = '&acute;';
entities['181'] = '&micro;'; entities['182'] = '&para;';
entities['183'] = '&middot;';
entities['184'] = '&cedil;';
entities['185'] = '&sup1;';
entities['186'] = '&ordm;'; entities['187'] = '&raquo;';
entities['188'] = '&frac14;';
entities['189'] = '&frac12;';
entities['190'] = '&frac34;';
entities['191'] = '&iquest;'; entities['192'] = '&Agrave;';
entities['193'] = '&Aacute;';
entities['194'] = '&Acirc;';
entities['195'] = '&Atilde;';
entities['196'] = '&Auml;'; entities['197'] = '&Aring;';
entities['198'] = '&AElig;';
entities['199'] = '&Ccedil;';
entities['200'] = '&Egrave;';
entities['201'] = '&Eacute;'; entities['202'] = '&Ecirc;';
entities['203'] = '&Euml;';
entities['204'] = '&Igrave;';
entities['205'] = '&Iacute;';
entities['206'] = '&Icirc;'; entities['207'] = '&Iuml;';
entities['208'] = '&ETH;';
entities['209'] = '&Ntilde;';
entities['210'] = '&Ograve;';
entities['211'] = '&Oacute;'; entities['212'] = '&Ocirc;';
entities['213'] = '&Otilde;';
entities['214'] = '&Ouml;';
entities['215'] = '&times;';
entities['216'] = '&Oslash;'; entities['217'] = '&Ugrave;';
entities['218'] = '&Uacute;';
entities['219'] = '&Ucirc;';
entities['220'] = '&Uuml;';
entities['221'] = '&Yacute;'; entities['222'] = '&THORN;';
entities['223'] = '&szlig;';
entities['224'] = '&agrave;';
entities['225'] = '&aacute;';
entities['226'] = '&acirc;'; entities['227'] = '&atilde;';
entities['228'] = '&auml;';
entities['229'] = '&aring;';
entities['230'] = '&aelig;';
entities['231'] = '&ccedil;'; entities['232'] = '&egrave;';
entities['233'] = '&eacute;';
entities['234'] = '&ecirc;';
entities['235'] = '&euml;';
entities['236'] = '&igrave;'; entities['237'] = '&iacute;';
entities['238'] = '&icirc;';
entities['239'] = '&iuml;';
entities['240'] = '&eth;';
entities['241'] = '&ntilde;'; entities['242'] = '&ograve;';
entities['243'] = '&oacute;';
entities['244'] = '&ocirc;';
entities['245'] = '&otilde;';
entities['246'] = '&ouml;'; entities['247'] = '&divide;';
entities['248'] = '&oslash;';
entities['249'] = '&ugrave;';
entities['250'] = '&uacute;';
entities['251'] = '&ucirc;'; entities['252'] = '&uuml;';
entities['253'] = '&yacute;';
entities['254'] = '&thorn;';
entities['255'] = '&yuml;';
}
if (useQuoteStyle !== 'ENT_NOQUOTES') {
entities['34'] = '&quot;';
}
if (useQuoteStyle === 'ENT_QUOTES') { entities['39'] = '&#39;';
}
entities['60'] = '&lt;';
entities['62'] = '&gt;';
// ascii decimals to real symbols
for (decimal in entities) {
if (entities.hasOwnProperty(decimal)) {
hash_map[String.fromCharCode(decimal)] = entities[decimal]; }
}
return hash_map;
}
function html_entity_decode (string, quote_style) {
// Convert all HTML entities to their applicable characters
//
// version: 1109.2015
// discuss at: http://phpjs.org/functions/html_entity_decode // + original by: john (http://www.jd-tech.net)
// + input by: ger
// + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
// + revised by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
// + bugfixed by: Onno Marsman // + improved by: marc andreu
// + revised by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
// + input by: Ratheous
// + bugfixed by: Brett Zamir (http://brett-zamir.me)
// + input by: Nick Kolosov (http://sammy.ru) // + bugfixed by: Fox
// - depends on: get_html_translation_table
// * example 1: html_entity_decode('Kevin &amp; van Zonneveld');
// * returns 1: 'Kevin & van Zonneveld'
// * example 2: html_entity_decode('&amp;lt;'); // * returns 2: '&lt;'
var hash_map = {},
symbol = '',
tmp_str = '',
entity = ''; tmp_str = string.toString();
if (false === (hash_map = this.get_html_translation_table('HTML_ENTITIES', quote_style))) {
return false;
}
// fix &amp; problem
// http://phpjs.org/functions/get_html_translation_table:416#comment_97660
delete(hash_map['&']);
hash_map['&'] = '&amp;';
for (symbol in hash_map) {
entity = hash_map[symbol];
tmp_str = tmp_str.split(entity).join(symbol);
} tmp_str = tmp_str.split('&#039;').join("'");
return tmp_str;
}

View file

@ -1,30 +1,28 @@
//Copyright Hauke Schade, 2012
//
//This file is part of TTRss.
//
//TTRss 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 2 of the License, or (at your option) any later version.
//TTRss 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 TTRss (on a Maemo/Meego system there is a copy
//in /usr/share/common-licenses. If not, see http://www.gnu.org/licenses/.
import QtQuick 1.1
import com.nokia.meego 1.0
import "settings.js" as Settings
PageStackWindow {
id: appWindow
id: rootWindow
function settingsObject() {
return Settings;
}
initialPage: mainPage
MainPage {
id: mainPage
}
ToolBarLayout {
id: commonTools
visible: true
ToolIcon {
platformIconId: "toolbar-view-menu"
anchors.right: (parent === undefined) ? undefined : parent.right
onClicked: (myMenu.status === DialogStatus.Closed) ? myMenu.open() : myMenu.close()
}
}
Menu {
id: myMenu
visualParent: pageStack
MenuLayout {
MenuItem { text: qsTr("Sample menu item") }
}
}
}

49
qml/ttrss/settings.js Normal file
View file

@ -0,0 +1,49 @@
//Based on the example code at:
//http://www.developer.nokia.com/Community/Wiki/How-to_create_a_persistent_settings_database_in_Qt_Quick_%28QML%29
function getDatabase() {
return openDatabaseSync("TTRssGo", "1.0", "Saved state for TTRssGo", 1000);
}
// 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 set(setting, value) {
// setting: string representing the setting name (eg: “username”)
// value: string representing the value of the setting (eg: “myUsername”)
var db = getDatabase();
var success = false;
db.transaction(function(tx) {
var rs = tx.executeSql('INSERT OR REPLACE INTO settings VALUES (?,?);', [setting,value]);
//console.log(rs.rowsAffected)
if (rs.rowsAffected > 0) {
success = true;
}
});
// The function returns true if it was successful, or false if it wasn't
return success;
}
// This function is used to retrieve a setting from the database
function get(setting, defaultValue) {
var db = getDatabase();
var result = defaultValue;
db.transaction(function(tx) {
var rs = tx.executeSql('SELECT value FROM settings WHERE setting=?;', [setting]);
if (rs.rows.length > 0) {
result = rs.rows.item(0).value;
}});
// The function returns defaultValue if no setting is found
return result;
}