Fix file browser in qmlvideofx example.

Similar to de9092389f for qmlvideo.
Use QUrl::fromLocalFile() to get Windows drive handling
right. Emulate its behavior in QML code. Fix up() to terminate
correctly.

Task-number: QTBUG-32139
Change-Id: I36bafaa608ff054190dc76694f6254a74f3b513e
Reviewed-by: Yoann Lopes <yoann.lopes@digia.com>
This commit is contained in:
Friedemann Kleint
2013-07-31 11:15:25 +02:00
committed by The Qt Project
parent 188b59609b
commit c86d14a380
2 changed files with 10 additions and 13 deletions

View File

@@ -116,21 +116,13 @@ int main(int argc, char *argv[])
FileReader fileReader; FileReader fileReader;
viewer.rootContext()->setContextProperty("fileReader", &fileReader); viewer.rootContext()->setContextProperty("fileReader", &fileReader);
QUrl appPath(QString("file://%1").arg(app.applicationDirPath())); const QUrl appPath(QUrl::fromLocalFile(app.applicationDirPath()));
QUrl imagePath;
const QStringList picturesLocation = QStandardPaths::standardLocations(QStandardPaths::PicturesLocation); const QStringList picturesLocation = QStandardPaths::standardLocations(QStandardPaths::PicturesLocation);
if (picturesLocation.isEmpty()) const QUrl imagePath = picturesLocation.isEmpty() ? appPath : QUrl::fromLocalFile(picturesLocation.first());
imagePath = appPath.resolved(QUrl("images"));
else
imagePath = QString("file://%1").arg(picturesLocation.first());
viewer.rootContext()->setContextProperty("imagePath", imagePath); viewer.rootContext()->setContextProperty("imagePath", imagePath);
QUrl videoPath;
const QStringList moviesLocation = QStandardPaths::standardLocations(QStandardPaths::MoviesLocation); const QStringList moviesLocation = QStandardPaths::standardLocations(QStandardPaths::MoviesLocation);
if (moviesLocation.isEmpty()) const QUrl videoPath = moviesLocation.isEmpty() ? appPath : QUrl::fromLocalFile(moviesLocation.first());
videoPath = appPath.resolved(QUrl("./"));
else
videoPath = QString("file://%1").arg(moviesLocation.first());
viewer.rootContext()->setContextProperty("videoPath", videoPath); viewer.rootContext()->setContextProperty("videoPath", videoPath);
viewer.setTitle("qmlvideofx"); viewer.setTitle("qmlvideofx");

View File

@@ -102,7 +102,10 @@ Rectangle {
Rectangle { Rectangle {
id: wrapper id: wrapper
function launch() { function launch() {
var path = "file://" + filePath var path = "file://";
if (filePath.length > 2 && filePath[1] === ':') // Windows drive logic, see QUrl::fromLocalFile()
path += '/';
path += filePath;
if (folders.isFolder(index)) if (folders.isFolder(index))
down(path); down(path);
else else
@@ -307,7 +310,7 @@ Rectangle {
MouseArea { id: upRegion; anchors.centerIn: parent MouseArea { id: upRegion; anchors.centerIn: parent
width: 56 width: 56
height: 56 height: 56
onClicked: if (folders.parentFolder != "") up() onClicked: up()
} }
states: [ states: [
State { State {
@@ -353,6 +356,8 @@ Rectangle {
function up() { function up() {
var path = folders.parentFolder; var path = folders.parentFolder;
if (path.toString().length === 0 || path.toString() === 'file:')
return;
if (folders == folders1) { if (folders == folders1) {
view = view2 view = view2
folders = folders2; folders = folders2;