Commit 03916759 authored by Martin Straka's avatar Martin Straka

Multiple file selection in file dialog

parent c1806554
......@@ -36,23 +36,33 @@ Dialog {
standardButtons: (selectedFileIndex != -1) ? (Dialog.Ok | Dialog.Cancel) : Dialog.Cancel
/* Place the dialogue in the centre. */
x: 2*defaultMargin
y: 2*defaultMargin
x: 2 * defaultMargin
y: 2 * defaultMargin
height: parent.height - 4*defaultMargin
width: parent.width - 4*defaultMargin
height: parent.height - 4 * defaultMargin
width: parent.width - 4 * defaultMargin
signal finished(string path)
/* This property must be set by caller. */
property bool multiSelect: false
property int selectedFileIndex: -1
signal finished(variant pathListModel)
function raise(title, filters, showFiles) {
root.title = title
folderModel.folder = standardLocationUrl(InteractionFilesystem.DESKTOP_LOCATION)
folderModel.folder = folderModel.folder
folderModel.showFiles = showFiles
if (filters != "") {
if (filters !== "") {
folderModel.nameFilters = [filters]
}
selectedFileIndex = -1
// clear add path list model
pathListModel.clear()
// deselect all item in the file idalog
for (fileList.currentIndex = 0; fileList.currentIndex < fileList.count; ++fileList.currentIndex) {
fileList.currentItem.color = datovkaPalette.window
}
root.open()
}
......@@ -64,13 +74,28 @@ Dialog {
return "file://" + interactionFilesystem.locate(location)
}
// retrun valid index if item is selected or invalid index
function isSelected(pathListModel, fileIndex) {
var path = stripUrlPrefix(folderModel.folder) + "/" + folderModel.get(fileIndex, "fileName")
var listLength = pathListModel.count
for (var j = 0; j < listLength; ++j) {
if (pathListModel.get(j).path === path) {
return j
}
}
return -1
}
InteractionFilesystem {
id: interactionFilesystem
}
ListModel {
id: pathListModel
}
contentItem: ColumnLayout {
spacing: formItemVerticalSpacing
ComboBox {
anchors {
left: parent.left;
......@@ -79,29 +104,31 @@ Dialog {
textRole: "label"
model: ListModel {
ListElement { label: qsTr("Desktop"); value: "desktop" }
ListElement { label: qsTr("Documents"); value: "documents" }
ListElement { label: qsTr("Documents"); value: "document" }
ListElement { label: qsTr("Downloads"); value: "download" }
ListElement { label: qsTr("Pictures"); value: "picture" }
ListElement { label: qsTr("Temp"); value: "temp" }
}
onCurrentIndexChanged: {
onActivated: {
var location = InteractionFilesystem.DESKTOP_LOCATION
if (model.get(currentIndex).value == "desktop") {
location = InteractionFilesystem.DESKTOP_LOCATION
} else if (model.get(currentIndex).value == "documents") {
if (model.get(currentIndex).value === "document") {
location = InteractionFilesystem.DOCUMENTS_LOCATION
} else {
location = InteractionFilesystem.DESKTOP_LOCATION
} else if (model.get(currentIndex).value === "download") {
location = InteractionFilesystem.DOWNLOAD_LOCATION
} else if (model.get(currentIndex).value === "picture") {
location = InteractionFilesystem.PICTURE_LOCATION
} else if (model.get(currentIndex).value === "temp") {
location = InteractionFilesystem.TEMP_LOCATION
}
folderModel.folder = standardLocationUrl(location)
}
}
} // ComboBox
RowLayout {
anchors {
left: parent.left;
right: parent.right;
}
spacing: formItemVerticalSpacing
Button {
id: upButton
text: "<"
......@@ -109,33 +136,24 @@ Dialog {
anchors.fill: parent
onClicked: {
/* Navigate to parent folder. */
if (folderModel.parentFolder != "") {
if (folderModel.parentFolder !== "") {
folderModel.folder = folderModel.parentFolder
}
}
}
}
Text {
text: "file://"
}
TextField {
id: pathField
Layout.fillWidth: true
text: stripUrlPrefix(folderModel.folder)
onEditingFinished: {
/* Navigate to supplied location if location exists. */
var path = interactionFilesystem.absoluteDirPath(text)
if (path != "") {
if (path !== "") {
folderModel.folder = "file://" + path
} else {
path = interactionFilesystem.absolutePath(text)
if (path != "") {
if (path !== "") {
folderModel.folder = "file://" + path
} else {
/* Restore original location. */
......@@ -143,12 +161,10 @@ Dialog {
}
}
}
}
}
} // TextField
} // RowLayout
ListView {
id: fileList
/* Fill remaining space with the list content. */
Layout.fillHeight: true
Layout.fillWidth: true
......@@ -161,12 +177,18 @@ Dialog {
selectedFileIndex = -1
pathField.text = stripUrlPrefix(folder)
}
}
} // FolderListModel
Component {
id: fileDelegate
Rectangle {
color: (index == selectedFileIndex) ? datovkaPalette.highlight : datovkaPalette.window
id: fileRectangle
color: if (multiSelect) {
// if files are in the pathList, select them
(isSelected(pathListModel, index) >= 0) ? datovkaPalette.highlight : datovkaPalette.window
} else {
// only one file can be selected
(index === selectedFileIndex) ? datovkaPalette.highlight : datovkaPalette.window
}
width: fileList.width
height: imgHeight
RowLayout {
......@@ -193,6 +215,22 @@ Dialog {
} else {
/* Select file. */
selectedFileIndex = index
var path = stripUrlPrefix(folderModel.folder) + "/" + folderModel.get(selectedFileIndex, "fileName")
if (!multiSelect) {
// only one file can be selected and append to list
pathListModel.clear()
pathListModel.append({path: path})
} else {
// file can be append to list or removed and deselected
var idx = isSelected(pathListModel, index);
if (idx >= 0) {
fileRectangle.color = datovkaPalette.window
pathListModel.remove(idx)
} else {
fileRectangle.color = datovkaPalette.highlight
pathListModel.append({path: path})
}
}
}
}
}
......@@ -202,16 +240,12 @@ Dialog {
delegate: fileDelegate
} // ListView
} // ColumnLayout
onAccepted: {
if (selectedFileIndex != -1) {
finished(stripUrlPrefix(folderModel.folder) + "/" + folderModel.get(selectedFileIndex, "fileName"))
} else {
finished("")
}
selectedFileIndex = -1
finished(pathListModel)
}
onRejected: {
finished("")
selectedFileIndex = -1
pathListModel.clear()
}
}
......@@ -126,25 +126,29 @@ Item {
dmAllowSubstDelivery.visible = boxEffectiveOVM
}
/* File dialog for choose of file in the storage */
/* File dialog for choose of files from the storage */
FileDialogue {
id: fileDialogue
multiSelect: true
onFinished: {
if (path != "") {
var listLength = pathListModel.count
for (var j = 0; j < listLength; ++j) {
var isInFiletList = false
for (var i = 0; i < sendMsgAttachmentModel.rowCount(); i++) {
if (sendMsgAttachmentModel.filePathFromRow(i) === path) {
if (sendMsgAttachmentModel.filePathFromRow(i) === pathListModel.get(j).path) {
isInFiletList = true
break
}
}
if (!isInFiletList) {
var fileName = getFileNameFromPath(path)
var fileName = getFileNameFromPath(pathListModel.get(j).path)
sendMsgAttachmentModel.appendFileFromPath(FileIdType.NO_FILE_ID,
fileName, path, getFileSizeString(files.getAttachmentSizeInBytes(path)),
fileName, pathListModel.get(j).path,
getFileSizeString(files.getAttachmentSizeInBytes(pathListModel.get(j).path)),
files.getAttachmentFileIcon(fileName))
}
}
pathListModel.clear()
}
}
......
......@@ -47,14 +47,19 @@ Item {
FileDialogue {
id: fileDialogue
multiSelect: false
onFinished: {
if (path == "") {
if (certPathLabelId.text == "") {
certPathLabelId.visible = false
var listLength = pathListModel.count
// set last selected certificate path
if (listLength > 0) {
if (pathListModel.get(listLength-1).path === "") {
if (certPathLabelId.text === "") {
certPathLabelId.visible = false
}
} else {
certPathLabelId.visible = true
certPathLabelId.text = pathListModel.get(listLength-1).path
}
} else {
certPathLabelId.visible = true
certPathLabelId.text = path
}
}
}
......
......@@ -62,6 +62,15 @@ enum QStandardPaths::StandardLocation toStandardLocation(
case InteractionFilesystem::DOCUMENTS_LOCATION:
return QStandardPaths::DocumentsLocation;
break;
case InteractionFilesystem::DOWNLOAD_LOCATION:
return QStandardPaths::DownloadLocation;
break;
case InteractionFilesystem::PICTURE_LOCATION:
return QStandardPaths::PicturesLocation;
break;
case InteractionFilesystem::TEMP_LOCATION:
return QStandardPaths::TempLocation;
break;
default :
Q_ASSERT(0);
return QStandardPaths::DesktopLocation;
......
......@@ -37,7 +37,10 @@ public:
/* Corresponds to some QStandardPaths::StandardLocation. */
enum Location {
DESKTOP_LOCATION,
DOCUMENTS_LOCATION
DOCUMENTS_LOCATION,
DOWNLOAD_LOCATION,
PICTURE_LOCATION,
TEMP_LOCATION
};
Q_ENUM(Location)
......
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