Commit 11fc86e5 authored by eekkelund's avatar eekkelund

[AppLauncher] Add contacts search to AppLauncher search

parent bfbd154c
...@@ -30,8 +30,10 @@ ...@@ -30,8 +30,10 @@
****************************************************************************************/ ****************************************************************************************/
import QtQuick 2.6 import QtQuick 2.6
import org.nemomobile.lipstick 0.1 import org.nemomobile.lipstick 0.1
import QtQuick.Controls 1.4
import QtQuick.Controls.Nemo 1.0 import QtQuick.Controls.Nemo 1.0
import QtQuick.Controls.Styles.Nemo 1.0 import QtQuick.Controls.Styles.Nemo 1.0
import org.nemomobile.contacts 1.0
Item { Item {
height: (searchField.text.length > 0 ? listView.height+searchField.height : searchField.height) + (visible ? Theme.itemSpacingHuge + margin.height : 0) height: (searchField.text.length > 0 ? listView.height+searchField.height : searchField.height) + (visible ? Theme.itemSpacingHuge + margin.height : 0)
...@@ -94,7 +96,17 @@ Item { ...@@ -94,7 +96,17 @@ Item {
Text { Text {
id: sectionText id: sectionText
text: section text: {
switch (section) {
case 'Application':
return qsTr("Application")
case 'Contact':
return qsTr("Contact")
default:
return qsTr("Content")
}
}
font.capitalization: Font.AllUppercase font.capitalization: Font.AllUppercase
font.pixelSize: Theme.fontSizeMedium font.pixelSize: Theme.fontSizeMedium
color: Theme.textColor color: Theme.textColor
...@@ -134,20 +146,37 @@ Item { ...@@ -134,20 +146,37 @@ Item {
} }
LauncherFolderModel { id: searchLauncherModel } LauncherFolderModel { id: searchLauncherModel }
PeopleModel {
id: peopleModel
filterType: PeopleModel.FilterAll
filterPattern: searchString
requiredProperty: PeopleModel.PhoneNumberRequired
//searchableProperty: root.searchableProperty
}
//Orginal function ** Copyright (C) 2013 Jolla Ltd. ** Contact: Joona Petrell <joona.petrell@jollamobile.com>
//Function has been modified
function update() { function update() {
if(searchString.length<1) { if(searchString.length<1) {
listModel.clear() listModel.clear()
} else { } else {
var iconTitle var iconTitle
var category
var extraCaption
var iconId var iconId
var found var found
var i var i
var titles = [] var titles = []
var contacts = []
for (i = 0; i < searchLauncherModel.itemCount; ++i) { for (i = 0; i < searchLauncherModel.itemCount; ++i) {
titles.push({'iconTitle':searchLauncherModel.get(i).title, 'iconSource':searchLauncherModel.get(i).iconId, 'id':i, 'category':qsTr("Application")}) titles.push({'iconTitle':searchLauncherModel.get(i).title, 'iconSource':searchLauncherModel.get(i).iconId, 'id':i, 'category':qsTr("Application")})
} }
for (i = 0; i < peopleModel.count; ++i) {
if(peopleModel.get(i).firstName && peopleModel.get(i).lastName) {
contacts.push({'title':(peopleModel.get(i).firstName + " " + peopleModel.get(i).lastName), 'iconSource':peopleModel.get(i).avatarUrl.toString(), 'extraCaption':peopleModel.get(i).phoneNumbers, 'category':qsTr("Contact")})
}
}
var filteredTitles = titles.filter(function (icon) { var filteredTitles = titles.filter(function (icon) {
return icon.iconTitle.toLowerCase().indexOf(searchString) !== -1 return icon.iconTitle.toLowerCase().indexOf(searchString) !== -1
}) })
...@@ -173,25 +202,44 @@ Item { ...@@ -173,25 +202,44 @@ Item {
i++ i++
} }
} }
// add new items // add new items
for (i = 0; i < filteredTitles.length; ++i) { for (i = 0; i < filteredTitles.length; ++i) {
iconTitle = filteredTitles[i].iconTitle iconTitle = filteredTitles[i].iconTitle
iconId = filteredTitles[i].iconSource iconId = filteredTitles[i].iconSource
var id = filteredTitles[i].id var id = filteredTitles[i].id
var category = filteredTitles[i].category category = filteredTitles[i].category
found = existingTitleObject.hasOwnProperty(iconTitle) found = existingTitleObject.hasOwnProperty(iconTitle)
if (!found) { if (!found) {
// for simplicity, just adding to end instead of corresponding position in original list // for simplicity, just adding to end instead of corresponding position in original list
listModel.append({'title':iconTitle, 'iconSource':iconId, 'id':id, 'category':category}) listModel.append({'title':iconTitle, 'iconSource':iconId, 'id':id, 'category':category})
} }
} }
for (i = 0; i < contacts.length; ++i) {
iconTitle = contacts[i].title
iconId = contacts[i].iconSource
extraCaption = contacts[i].extraCaption[0]
category = contacts[i].category
listModel.append({'title':iconTitle, 'iconSource':iconId, 'extraCaption':extraCaption, 'category':category})
}
} }
} }
delegate: Item { delegate: Item {
width: parent.width
height:Theme.itemHeightExtraLarge*1.2
property string iconCaption: model.title property string iconCaption: model.title
property string iconSource: model.iconSource== "" ? "/usr/share/lipstick-glacier-home-qt5/qml/theme/default-icon.png" : ( model.iconSource.indexOf("/") == 0 ? "file://" : "image://theme/") + model.iconSource property string iconSource: {
if(model.iconSource) {
if(model.iconSource.indexOf("file:///") == 0) {
return model.iconSource
}else {
if( model.iconSource.indexOf("/") == 0) {
return "file://" + model.iconSource
} else return "image://theme/" + model.iconSource
}
} else return "/usr/share/lipstick-glacier-home-qt5/qml/theme/default-icon.png"
}
Rectangle { Rectangle {
anchors.fill: parent anchors.fill: parent
color: "#11ffffff" color: "#11ffffff"
...@@ -205,6 +253,11 @@ Item { ...@@ -205,6 +253,11 @@ Item {
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
anchors.left: parent.left anchors.left: parent.left
anchors.leftMargin: Theme.itemSpacingLarge anchors.leftMargin: Theme.itemSpacingLarge
onStatusChanged: {
if (iconImage.status == Image.Error) {
iconImage.source = "/usr/share/lipstick-glacier-home-qt5/qml/theme/default-icon.png"
}
}
} }
Spinner { Spinner {
id: spinner id: spinner
...@@ -226,36 +279,62 @@ Item { ...@@ -226,36 +279,62 @@ Item {
} }
} }
} }
Label { Item {
text:iconCaption id: labelWrapper
anchors.left: iconImage.right anchors {
anchors.leftMargin: Theme.itemSpacingLarge left: iconImage.right
anchors.right: parent.right leftMargin: Theme.itemSpacingLarge
anchors.verticalCenter: parent.verticalCenter right: parent.right
anchors.rightMargin: Theme.itemSpacingLarge verticalCenter: parent.verticalCenter
font.pixelSize:Theme.fontSizeLarge rightMargin: Theme.itemSpacingLarge
height:parent.height }
color:Theme.textColor height: labelWrapper.childrenRect.height
elide:Text.ElideRight Label {
horizontalAlignment:Text.AlignHCenter id:mainLabel
verticalAlignment:Text.AlignVCenter text:iconCaption
anchors {
left: parent.left
right: parent.right
}
font.pixelSize:Theme.fontSizeLarge
color:Theme.textColor
elide:Text.ElideRight
verticalAlignment:Text.AlignVCenter
}
Label {
id:extraLabel
text: extraCaption ? extraCaption : category === "Application" ? qsTr("Open" + " " + iconCaption) : ""
anchors {
top:mainLabel.bottom
left:mainLabel.left
}
font.pixelSize:Theme.fontSizeSmall
color:Theme.textColor
elide:Text.ElideRight
verticalAlignment:Text.AlignVCenter
}
} }
width: parent.width
height:Theme.itemHeightExtraLarge*1.2
MouseArea { MouseArea {
id:mouse id:mouse
anchors.fill: parent anchors.fill: parent
onClicked: { onClicked: {
if (searchLauncherModel.get(model.id).type !== LauncherModel.Folder) { switch (category ) {
var winId = switcher.switchModel.getWindowIdForTitle(model.title) case "Application":
if (winId == 0 || !searchLauncherModel.get(model.id).isLaunching) if (searchLauncherModel.get(model.id).type !== LauncherModel.Folder) {
searchLauncherModel.get(model.id).launchApplication() var winId = switcher.switchModel.getWindowIdForTitle(model.title)
else if (winId == 0 || !searchLauncherModel.get(model.id).isLaunching)
Lipstick.compositor.windowToFront(winId) searchLauncherModel.get(model.id).launchApplication()
else
Lipstick.compositor.windowToFront(winId)
}
context.state=""
break
case "Contact":
console.log("Call to person. Or open contextmenu where sms and call")
break
} }
} }
} }
} }
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment