Skip to content

Commit

Permalink
- first coding for history page
Browse files Browse the repository at this point in the history
  • Loading branch information
steffen-foerster committed Oct 3, 2014
1 parent 15c726d commit 595cdc4
Show file tree
Hide file tree
Showing 5 changed files with 245 additions and 10 deletions.
4 changes: 3 additions & 1 deletion harbour-barcode.pro
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ OTHER_FILES += \
qml/pages/TextPage.qml \
qml/js/History.js \
qml/components/Settings1View.qml \
qml/components/Settings2View.qml
qml/components/Settings2View.qml \
qml/pages/HistoryPage.qml \
qml/js/Utils.js

# to disable building translations every time, comment out the
# following CONFIG line
Expand Down
2 changes: 1 addition & 1 deletion qml/harbour-barcode.qml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ ApplicationWindow
return "0.7.0"
}

function openInDefaultBrowser(url) {
function openInDefaultApp(url) {
console.log("opening URL: " + url)
infoPanel.showText(qsTr("Opening in default app ..."), 500, 2000)
Qt.openUrlExternally(url)
Expand Down
41 changes: 41 additions & 0 deletions qml/js/Utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
The MIT License (MIT)
Copyright (c) 2014 Steffen Förster
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/

.pragma library

function isLink(text) {
var urls = text.match(/^(http[s]*:\/\/.{3,500}|www\..{3,500}|sms:\+\d{5,})$/);
var vcard = text.match(/^(.+VCARD.+)$/);
// is a known url scheme and not a vcard
return (urls && urls.length > 0 && !(vcard && vcard.length > 0));
}

function isText(text) {
return !isLink(text);
}

function shortenText(text, maxLength) {
var shortenText = text.replace("\n", " ")
return shortenText.length > maxLength ? shortenText.substr(0, maxLength) + "..." : shortenText
}
13 changes: 5 additions & 8 deletions qml/pages/AutoScanPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import harbour.barcode.AutoBarcodeScanner 1.0

import "../js/Settings.js" as Settings
import "../js/History.js" as History
import "../js/Utils.js" as Utils

Page {
id: scanPage
Expand Down Expand Up @@ -404,10 +405,7 @@ Page {
property string text: ""

function setValue(text) {
var urls = text.match(/^(http[s]*:\/\/.{3,500}|www\..{3,500}|sms:\+\d{5,})$/);
var vcard = text.match(/^(.+VCARD.+)$/);
// is a known url scheme and not a vcard
if (urls && urls.length > 0 && !(vcard && vcard.length > 0)) {
if (Utils.isLink(text)) {
setLink(text)
}
else {
Expand Down Expand Up @@ -435,8 +433,7 @@ Page {
clickableResult.enabled = true
clickableResult.isLink = false
clickableResult.text = text
var shortenText = text.replace("\n", " ")
resultText.text = shortenText.length > 15 ? shortenText.substr(0, 15) + "..." : shortenText
resultText.text = Utils.shortenText(text, 15)
resultText.width =
rowResult.width - clipboardImg.width - arrowRightImg.width - 2 * Theme.paddingLarge
}
Expand Down Expand Up @@ -497,10 +494,10 @@ Page {

onClicked: {
if (clickableResult.isLink) {
openInDefaultBrowser(clickableResult.text);
openInDefaultApp(clickableResult.text)
}
else {
pageStack.push("TextPage.qml", {text: clickableResult.text});
pageStack.push("TextPage.qml", {text: clickableResult.text})
}
}
}
Expand Down
195 changes: 195 additions & 0 deletions qml/pages/HistoryPage.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
/*
The MIT License (MIT)
Copyright (c) 2014 Steffen Förster
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/

import QtQuick 2.1
import Sailfish.Silica 1.0

import "../js/History.js" as History

Page {
id: historyPage

SilicaListView {
id: historyList

property Item contextMenu

anchors.fill: parent
width: parent.width
spacing: 0

PullDownMenu {
MenuItem {
text: qsTr("Remove all")
onClicked: {
removeAll();
}
}
}

model: ListModel {
id: historyModel
}

delegate: ListItem {
id: wrapper
property bool menuOpen: {
historyList.contextMenu != null
&& historyList.contextMenu.parent === wrapper
}

contentHeight: {
menuOpen ? historyList.contextMenu.height + itemColumn.height
: itemColumn.height
}

onClicked: {
var historyItem = historyList.get(index)
if (Utils.isLink(historyItem.value)) {
openInDefaultApp(historyItem.value)
}
else {
pageStack.push("TextPage.qml", {text: historyItem.value})
}
}

onPressAndHold: {
if (!bookmarkList.contextMenu) {
bookmarkList.contextMenu =
contextMenuComponent.createObject(bookmarkList)
}
bookmarkList.contextMenu.index = index
bookmarkList.contextMenu.show(wrapper);
}

Column {
id: itemColumn
Rectangle {
height: Theme.paddingLarge / 2
width: wrapper.ListView.view.width
opacity: 0
}
Label {
id: lbTitle
anchors {
left: parent.left
margins: Theme.paddingLarge
}
color: wrapper.highlighted ? Theme.highlightColor : Theme.primaryColor
font {
pixelSize: Theme.fontSizeSmall
bold: model.toread === 'yes'
}
wrapMode: Text.Wrap
text: model.title
width: wrapper.ListView.view.width - (2 * Theme.paddingLarge)
}
Label {
id: lbCreated
anchors {
left: parent.left
margins: Theme.paddingLarge
}
color: Theme.secondaryColor
font.pixelSize: Theme.fontSizeExtraSmall
text: Utils.formatTimestamp(model.time)
Image {
anchors {
verticalCenter: lbCreated.verticalCenter
left: lbCreated.right
leftMargin: Theme.paddingMedium
}
height: Theme.iconSizeSmall
fillMode: Image.PreserveAspectFit
source: "image://theme/icon-m-device-lock"
visible: model.shared === 'no'
}
}
Rectangle {
height: Theme.paddingLarge / 2
width: wrapper.ListView.view.width
opacity: 0
}
}
}

Component {
id: contextMenuComponent
ContextMenu {
property variant index

MenuItem {
text: qsTr("Open in default browser")
onClicked: {
openInDefaultBrowser(bookmarkModel.get(index).href);
}
}
MenuItem {
text: qsTr("Delete")
onClicked: {
remorse.execute(bookmarkList.contextMenu.parent,
"Deleting",
getDeleteFunction(bookmarkModel, index),
3000)
}
visible: root.state === "PINBOARD" || root.state === "PHONE"
}
MenuItem {
text: qsTr("Copy URL to clipboard")
onClicked: {
Clipboard.text = bookmarkModel.get(index).href
}
}

function getDeleteFunction(model, index) {
// Removing from list destroys the ListElement so we need a copy
var itemToDelete = Bookmark.copy(model.get(index));
var f = function() {
model.remove(index);
getServiceManager().deleteBookmark(itemToDelete,
function() {
window.bookmarksUpdated();
},
function(error) {
bookmarkModel.insert(index, itemToDelete)
infoPanel.showError(error);
}
)
}
return f;
}
}
}

RemorseItem { id: remorse }

VerticalScrollDecorator {}

ViewPlaceholder {
id: placeHolder
enabled: histroyModel.count === 0
text: qsTr("History is empty")
}
}
}

0 comments on commit 595cdc4

Please sign in to comment.