Added QML for Harmattan
[quandoparte] / application / view.cpp
1 #include "view.h"
2 #include <QDeclarativeView>
3 #include <QDebug>
4 #include <QDir>
5 #include <QFile>
6
7 // search Paths seem to be broken in Harmattan?
8
9 static QString trueFilePath(QString path)
10 {
11     qDebug() << "searching for" << path;
12     QString searchPathName = path.section(':', 0, 0);
13     qDebug() << "path is" << searchPathName;
14     QString fileName = path.section(':', 1, 1);
15     qDebug() << "filename is" << fileName;
16     QStringList dirs = QDir::searchPaths(searchPathName);
17     foreach(QString dir, dirs) {
18         qDebug() << "searching in" << dir;
19        QDir current(dir);
20        QString absoluteFileName = current.absoluteFilePath(fileName);
21         if (current.exists(fileName)) {
22             qDebug() << "found " << fileName << "in path" << absoluteFileName;
23             return absoluteFileName;
24         }
25     }
26     qDebug() << "file not found";
27     return QString();
28 }
29
30 View::View(QWidget *parent) :
31     QWidget(parent),
32     m_view(new QDeclarativeView(this))
33 {
34     showFullScreen();
35
36     // This does not seem ot work in harmattan. As a workaround, change dir to
37     // the qml dir, then load the file.
38     // m_view->setSource(QUrl::fromLocalFile("qml:main.qml"));
39     m_view->setSource(QUrl::fromLocalFile(trueFilePath("qml:main.qml")));
40 }