summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorMartin Jones <martin.jones@nokia.com>2009-12-22 06:33:34 (GMT)
committerMartin Jones <martin.jones@nokia.com>2009-12-22 06:33:34 (GMT)
commit43c20fed3f88e23baa5bd9657c348cbc1f8e60f3 (patch)
tree0bb5541d62fefebac974f6af0ed9cb8a3d155bf5 /examples
parentc27410eebd2ad0e893bb68767ce794232d4144b2 (diff)
downloadQt-43c20fed3f88e23baa5bd9657c348cbc1f8e60f3.zip
Qt-43c20fed3f88e23baa5bd9657c348cbc1f8e60f3.tar.gz
Qt-43c20fed3f88e23baa5bd9657c348cbc1f8e60f3.tar.bz2
Remove loader. Its functionality is now available in qmlviewer.
Diffstat (limited to 'examples')
-rw-r--r--examples/declarative/loader/Browser.qml232
-rw-r--r--examples/declarative/loader/Button.qml16
-rw-r--r--examples/declarative/loader/images/folder.pngbin1841 -> 0 bytes
-rw-r--r--examples/declarative/loader/images/titlebar.pngbin1436 -> 0 bytes
-rw-r--r--examples/declarative/loader/images/titlebar.sci5
-rw-r--r--examples/declarative/loader/images/up.pngbin662 -> 0 bytes
-rw-r--r--examples/declarative/loader/loader.pro19
-rw-r--r--examples/declarative/loader/loader.qml10
-rw-r--r--examples/declarative/loader/loader.qrc11
-rw-r--r--examples/declarative/loader/main.cpp287
-rw-r--r--examples/declarative/loader/qmlfolderlistmodel.cpp388
-rw-r--r--examples/declarative/loader/qmlfolderlistmodel.h118
12 files changed, 0 insertions, 1086 deletions
diff --git a/examples/declarative/loader/Browser.qml b/examples/declarative/loader/Browser.qml
deleted file mode 100644
index f3a1182..0000000
--- a/examples/declarative/loader/Browser.qml
+++ /dev/null
@@ -1,232 +0,0 @@
-import Qt 4.6
-
-Rectangle {
- id: root
- property bool keyPressed: false
- property var folders: folders1
- property var view: view1
- width: parent.width
- height: parent.height
- color: palette.window
- FolderListModel {
- id: folders1
- nameFilters: [ "*.qml" ]
- folder: "file:///E:/" // Documents on your S60 phone (or Windows E: drive)
- }
- FolderListModel {
- id: folders2
- nameFilters: [ "*.qml" ]
- folder: "file:///E:/" // Documents on your S60 phone (or Windows E: drive)
- }
-
- SystemPalette { id: palette }
-
- Script {
- function down(path) {
- if (folders == folders1) {
- view = view2
- folders = folders2;
- view1.state = "exitLeft";
- } else {
- view = view1
- folders = folders1;
- view2.state = "exitLeft";
- }
- view.x = root.width;
- view.state = "current";
- folders.folder = path;
- }
- function up() {
- var path = folders.parentFolder;
- if (folders == folders1) {
- view = view2
- folders = folders2;
- view1.state = "exitRight";
- } else {
- view = view1
- folders = folders1;
- view2.state = "exitRight";
- }
- view.x = -root.width;
- view.state = "current";
- folders.folder = path;
- }
- }
-
- Component {
- id: folderDelegate
- Rectangle {
- id: wrapper
- function launch() {
- if (folders.isFolder(index)) {
- down(filePath);
- } else {
- qmlLauncher.launch(filePath);
- }
- }
- width: root.width
- height: 48
- color: "transparent"
- Rectangle {
- id: highlight; visible: false
- anchors.fill: parent
- gradient: Gradient {
- GradientStop { id: t1; position: 0.0; color: palette.highlight }
- GradientStop { id: t2; position: 1.0; color: Qt.lighter(palette.highlight) }
- }
- }
- Item {
- width: 46; height: 46
- Image { source: "images/folder.png"; anchors.centerIn: parent; visible: folders.isFolder(index)}
- }
- Text {
- id: nameText
- anchors.fill: parent; verticalAlignment: Text.AlignVCenter
- text: fileName; anchors.leftMargin: 48
- font.pixelSize: 32
- color: wrapper.isCurrentItem ? palette.highlightedText : palette.text
- }
- MouseRegion {
- id: mouseRegion
- anchors.fill: parent
- onClicked: { launch() }
- }
- states: [
- State {
- name: "pressed"
- when: mouseRegion.pressed
- PropertyChanges { target: highlight; visible: true }
- PropertyChanges { target: nameText; color: palette.highlightedText }
- }
- ]
- }
- }
-
- ListView {
- id: view1
- anchors.top: titleBar.bottom
- anchors.bottom: parent.bottom
- x: 0
- width: parent.width
- model: folders1
- delegate: folderDelegate
- highlight: Rectangle { color: palette.highlight; visible: root.keyPressed }
- focus: true
- pressDelay: 100
- state: "current"
- states: [
- State {
- name: "current"
- PropertyChanges { target: view1; x: 0 }
- },
- State {
- name: "exitLeft"
- PropertyChanges { target: view1; x: -root.width }
- },
- State {
- name: "exitRight"
- PropertyChanges { target: view1; x: root.width }
- }
- ]
- transitions: [
- Transition {
- to: "current"
- SequentialAnimation {
- NumberAnimation { matchProperties: "x"; duration: 250 }
- }
- },
- Transition {
- NumberAnimation { matchProperties: "x"; duration: 250 }
- NumberAnimation { matchProperties: "x"; duration: 250 }
- }
- ]
- }
-
- ListView {
- id: view2
- anchors.top: titleBar.bottom
- anchors.bottom: parent.bottom
- x: parent.width
- width: parent.width
- model: folders2
- delegate: folderDelegate
- highlight: Rectangle { color: palette.highlight; visible: root.keyPressed }
- focus: true
- pressDelay: 100
- states: [
- State {
- name: "current"
- PropertyChanges { target: view2; x: 0 }
- },
- State {
- name: "exitLeft"
- PropertyChanges { target: view2; x: -root.width }
- },
- State {
- name: "exitRight"
- PropertyChanges { target: view2; x: root.width }
- }
- ]
- transitions: [
- Transition {
- to: "current"
- SequentialAnimation {
- NumberAnimation { matchProperties: "x"; duration: 250 }
- }
- },
- Transition {
- NumberAnimation { matchProperties: "x"; duration: 250 }
- }
- ]
- }
-
- Keys.onPressed: {
- root.keyPressed = true;
- if (event.key == Qt.Key_Return || event.key == Qt.Key_Select || event.key == Qt.Key_Right) {
- view.currentItem.launch();
- event.accepted = true;
- }
- }
- Keys.onLeftPressed: up()
-
- BorderImage {
- source: "images/titlebar.sci";
- width: parent.width;
- height: 48
- y: -7
- id: titleBar
-
- Rectangle {
- id: upButton
- width: 40
- height: titleBar.height - 7
- color: "transparent"
-
- Image { anchors.centerIn: parent; source: "images/up.png" }
- MouseRegion { id: upRegion; anchors.fill: parent
- onClicked: if (folders.parentFolder != "") up()
- }
- states: [
- State {
- name: "pressed"
- when: upRegion.pressed
- PropertyChanges { target: upButton; color: palette.highlightedText }
- }
- ]
- }
- Rectangle {
- color: "gray"
- x: 40
- width: 1
- height: 40
- }
-
- Text {
- anchors.left: upButton.right; anchors.right: parent.right; height: parent.height
- anchors.leftMargin: 4; anchors.rightMargin: 4
- text: folders.folder; color: "white"
- elide: Text.ElideLeft; horizontalAlignment: Text.AlignRight; verticalAlignment: Text.AlignVCenter
- font.pixelSize: 32
- }
- }
-}
diff --git a/examples/declarative/loader/Button.qml b/examples/declarative/loader/Button.qml
deleted file mode 100644
index 928ff06..0000000
--- a/examples/declarative/loader/Button.qml
+++ /dev/null
@@ -1,16 +0,0 @@
-import Qt 4.6
-
-Rectangle {
- id: container
-
- property var text
- signal clicked
-
- height: text.height + 10
- width: text.width + 20
- border.width: 1
- radius: 4
- color: "grey"
- MouseRegion { anchors.fill: parent; onClicked: container.clicked() }
- Text { id: text; anchors.centerIn:parent; font.pointSize: 10; text: parent.text }
-}
diff --git a/examples/declarative/loader/images/folder.png b/examples/declarative/loader/images/folder.png
deleted file mode 100644
index e53e2ad..0000000
--- a/examples/declarative/loader/images/folder.png
+++ /dev/null
Binary files differ
diff --git a/examples/declarative/loader/images/titlebar.png b/examples/declarative/loader/images/titlebar.png
deleted file mode 100644
index 51c9008..0000000
--- a/examples/declarative/loader/images/titlebar.png
+++ /dev/null
Binary files differ
diff --git a/examples/declarative/loader/images/titlebar.sci b/examples/declarative/loader/images/titlebar.sci
deleted file mode 100644
index 0418d94..0000000
--- a/examples/declarative/loader/images/titlebar.sci
+++ /dev/null
@@ -1,5 +0,0 @@
-border.left: 10
-border.top: 12
-border.bottom: 12
-border.right: 10
-source: titlebar.png
diff --git a/examples/declarative/loader/images/up.png b/examples/declarative/loader/images/up.png
deleted file mode 100644
index b05f802..0000000
--- a/examples/declarative/loader/images/up.png
+++ /dev/null
Binary files differ
diff --git a/examples/declarative/loader/loader.pro b/examples/declarative/loader/loader.pro
deleted file mode 100644
index 84b2d21..0000000
--- a/examples/declarative/loader/loader.pro
+++ /dev/null
@@ -1,19 +0,0 @@
-SOURCES = main.cpp qmlfolderlistmodel.cpp
-HEADERS = qmlfolderlistmodel.h
-RESOURCES = loader.qrc
-
-QT += script declarative network
-
-target.path = $$[QT_INSTALL_EXAMPLES]/declarative/loader
-sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS loader.pro
-sources.path = $$[QT_INSTALL_EXAMPLES]/declarative/loader
-INSTALLS += target sources
-
-symbian {
-# TARGET.UID3 =
- include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
- TARGET.EPOCHEAPSIZE = 0x20000 0x2000000
- HEADERS += $$QT_SOURCE_TREE/examples/network/qftp/sym_iap_util.h
- LIBS += -lesock -lconnmon -linsock
- TARGET.CAPABILITY = NetworkServices
-}
diff --git a/examples/declarative/loader/loader.qml b/examples/declarative/loader/loader.qml
deleted file mode 100644
index 319db84..0000000
--- a/examples/declarative/loader/loader.qml
+++ /dev/null
@@ -1,10 +0,0 @@
-import Qt 4.6
-
-Rectangle {
- width: 300
- height: 400
- Loader {
- anchors.fill: parent
- source: "Browser.qml"
- }
-}
diff --git a/examples/declarative/loader/loader.qrc b/examples/declarative/loader/loader.qrc
deleted file mode 100644
index 94d7b92..0000000
--- a/examples/declarative/loader/loader.qrc
+++ /dev/null
@@ -1,11 +0,0 @@
-<RCC>
- <qresource prefix="/" >
- <file>loader.qml</file>
- <file>Browser.qml</file>
- <file>images/up.png</file>
- <file>Button.qml</file>
- <file>images/folder.png</file>
- <file>images/titlebar.sci</file>
- <file>images/titlebar.png</file>
- </qresource>
-</RCC>
diff --git a/examples/declarative/loader/main.cpp b/examples/declarative/loader/main.cpp
deleted file mode 100644
index 22e3646..0000000
--- a/examples/declarative/loader/main.cpp
+++ /dev/null
@@ -1,287 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
-** All rights reserved.
-** Contact: Nokia Corporation (qt-info@nokia.com)
-**
-** This file is part of the examples of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the Technology Preview License Agreement accompanying
-** this package.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** If you have questions regarding the use of this file, please contact
-** Nokia at qt-info@nokia.com.
-**
-**
-**
-**
-**
-**
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-#include <QApplication>
-#include <QUrl>
-#include <QFileInfo>
-#include <QDir>
-#include <QPlainTextEdit>
-#include <QAction>
-#include <QVBoxLayout>
-#include <QMainWindow>
-#include <QMenuBar>
-#include <QDebug>
-#include <QmlContext>
-#include <QmlComponent>
-#include <QmlEngine>
-#include <qmlview.h>
-#include <QDebug>
-#include <QNetworkDiskCache>
-#include <QNetworkAccessManager>
-#include <QtCore>
-
-#if defined (Q_OS_SYMBIAN)
-#define SYMBIAN_NETWORK_INIT
-#endif
-
-#if defined (SYMBIAN_NETWORK_INIT)
-#include "sym_iap_util.h"
-#endif
-
-QmlView *canvas = 0;
-
-class Logger : public QWidget
-{
- Q_OBJECT
-public:
- Logger() : QWidget() {
- logText = new QPlainTextEdit;
- QVBoxLayout *layout = new QVBoxLayout;
- layout->addWidget(logText);
- layout->setMargin(0);
- setLayout(layout);
-#ifdef Q_OS_SYMBIAN
- QAction *closeAction = new QAction("Close", this);
- closeAction->setSoftKeyRole(QAction::NegativeSoftKey);
- connect(closeAction, SIGNAL(triggered()), this, SLOT(close()));
- addAction(closeAction);
-#endif
- connect(logText, SIGNAL(textChanged()), this, SIGNAL(textChanged()));
- }
-
- void append(const QString &text) {
- logText->appendPlainText(text);
- }
-
- static Logger *instance() {
- static Logger *logger = 0;
- if (!logger)
- logger = new Logger();
- return logger;
- }
-
-signals:
- void textChanged();
-
-private:
- QPlainTextEdit *logText;
-};
-
-void myMessageOutput(QtMsgType type, const char *msg)
-{
- switch (type) {
- case QtDebugMsg:
- Logger::instance()->append(QString(msg));
- break;
- case QtWarningMsg:
- Logger::instance()->append(QString(msg));
- break;
- case QtCriticalMsg:
- Logger::instance()->append(QString(msg));
- break;
- case QtFatalMsg:
- Logger::instance()->append(QString(msg));
- abort();
- }
-}
-
-
-class QmlLauncher : public QObject
-{
- Q_OBJECT
-public:
- QmlLauncher() {}
-
- Q_INVOKABLE void launch(const QString &fileName)
- {
- m_fileName = fileName;
- QMetaObject::invokeMethod(this, "doLaunch", Qt::QueuedConnection);
- }
-
-private slots:
- void doLaunch()
- {
- qDebug() << "dolaunch";
- QUrl url(m_fileName);
- QFileInfo fi(url.toLocalFile());
- if (fi.exists()) {
- canvas->reset();
-
- url = QUrl::fromLocalFile(fi.absoluteFilePath());
- QmlContext *ctxt = canvas->rootContext();
- QDir dir(fi.path()+"/dummydata", "*.qml");
- QStringList list = dir.entryList();
- for (int i = 0; i < list.size(); ++i) {
- QString qml = list.at(i);
- QFile f(dir.filePath(qml));
- f.open(QIODevice::ReadOnly);
- QByteArray data = f.readAll();
- QmlComponent comp(canvas->engine());
- comp.setData(data, QUrl());
- QObject *dummyData = comp.create();
-
- if(comp.isError()) {
- QList<QmlError> errors = comp.errors();
- foreach (const QmlError &error, errors) {
- qWarning() << error;
- }
- }
-
- if (dummyData) {
- qml.truncate(qml.length()-4);
- ctxt->setContextProperty(qml, dummyData);
- dummyData->setParent(this);
- }
- }
-
- canvas->setUrl(url);
- canvas->execute();
- }
- }
-
-signals:
- void logUpdated();
-
-private:
- QString m_fileName;
-};
-
-class MainWindow : public QMainWindow
-{
- Q_OBJECT
-public:
- MainWindow() : QMainWindow()
- {
- }
-
-public slots:
- void toggleFullScreen()
- {
- if (isFullScreen()) {
-#ifdef Q_OS_SYMBIAN
- showMaximized();
-#else
- showNormal();
-#endif
- } else {
- showFullScreen();
- }
- }
-
- void showLog()
- {
-#ifdef Q_OS_SYMBIAN
- Logger::instance()->showMaximized();
-#else
- Logger::instance()->show();
-#endif
- }
-
- void enableNetwork()
- {
-#if defined(SYMBIAN_NETWORK_INIT)
- qt_SetDefaultIap();
-#endif
- }
-};
-
-class ConfiguredNetworkAccessManager : public QNetworkAccessManager {
-public:
- ConfiguredNetworkAccessManager()
- {
- QNetworkDiskCache *cache = new QNetworkDiskCache;
- cache->setCacheDirectory(QDir::tempPath()+QLatin1String("/qml-loader-network-cache"));
- setCache(cache);
- }
-
- QNetworkReply *createRequest (Operation op, const QNetworkRequest &req, QIODevice * outgoingData)
- {
- QNetworkRequest request = req;
- request.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferCache);
- request.setAttribute(QNetworkRequest::HttpPipeliningAllowedAttribute, true);
- return QNetworkAccessManager::createRequest(op,request,outgoingData);
- }
-};
-
-
-int main(int argc, char *argv[])
-{
- qInstallMsgHandler(myMessageOutput);
- QApplication app(argc, argv);
-
- MainWindow *mw = new MainWindow;
-
- QmlLauncher *launcher = new QmlLauncher;
-
- QObject::connect(Logger::instance(), SIGNAL(textChanged()), launcher, SIGNAL(logUpdated()));
-
- canvas = new QmlView;
- canvas->setFocusPolicy(Qt::StrongFocus);
- canvas->engine()->setNetworkAccessManager(new ConfiguredNetworkAccessManager);
-
- QMenuBar *mb = mw->menuBar();
- QAction *showLogAction = new QAction("View Log...", mw);
- mb->addAction(showLogAction);
- QObject::connect(showLogAction, SIGNAL(triggered()), mw, SLOT(showLog()));
- QAction *toggleFSAction = new QAction("Fullscreen", mw);
- mb->addAction(toggleFSAction);
- QObject::connect(toggleFSAction, SIGNAL(triggered()), mw, SLOT(toggleFullScreen()));
-#if defined(SYMBIAN_NETWORK_INIT)
- QAction *enableNetworkAction = new QAction("Enable Network", mw);
- mb->addAction(enableNetworkAction);
- QObject::connect(enableNetworkAction, SIGNAL(triggered()), mw, SLOT(enableNetwork()));
-#endif
-
- QmlContext *ctxt = canvas->rootContext();
- ctxt->setContextProperty("qmlLauncher", launcher);
- canvas->setUrl(QUrl("qrc:/loader.qml"));
-#ifdef Q_OS_SYMBIAN
- canvas->setContentResizable(true);
- mw->showMaximized();
-#else
- mw->show();
-#endif
- canvas->execute();
- mw->setCentralWidget(canvas);
-
- return app.exec();
-}
-
-#include "main.moc"
diff --git a/examples/declarative/loader/qmlfolderlistmodel.cpp b/examples/declarative/loader/qmlfolderlistmodel.cpp
deleted file mode 100644
index 14d2324..0000000
--- a/examples/declarative/loader/qmlfolderlistmodel.cpp
+++ /dev/null
@@ -1,388 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
-** All rights reserved.
-** Contact: Nokia Corporation (qt-info@nokia.com)
-**
-** This file is part of the examples of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the Technology Preview License Agreement accompanying
-** this package.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** If you have questions regarding the use of this file, please contact
-** Nokia at qt-info@nokia.com.
-**
-**
-**
-**
-**
-**
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qmlfolderlistmodel.h"
-#include <QDirModel>
-#include <QDebug>
-#include <QtDeclarative/qmlcontext.h>
-
-class QmlFolderListModelPrivate
-{
-public:
- QmlFolderListModelPrivate()
- : sortField(QmlFolderListModel::Name), sortReversed(false), count(0) {
- nameFilters << QLatin1String("*");
- }
-
- void updateSorting() {
- QDir::SortFlags flags = 0;
- switch(sortField) {
- case QmlFolderListModel::Unsorted:
- flags |= QDir::Unsorted;
- break;
- case QmlFolderListModel::Name:
- flags |= QDir::Name;
- break;
- case QmlFolderListModel::Time:
- flags |= QDir::Time;
- break;
- case QmlFolderListModel::Size:
- flags |= QDir::Size;
- break;
- case QmlFolderListModel::Type:
- flags |= QDir::Type;
- break;
- }
-
- if (sortReversed)
- flags |= QDir::Reversed;
-
- model.setSorting(flags);
- }
-
- QDirModel model;
- QUrl folder;
- QStringList nameFilters;
- QModelIndex folderIndex;
- QmlFolderListModel::SortField sortField;
- bool sortReversed;
- int count;
-};
-
-/*!
- \qmlclass FolderListModel
- \brief The FolderListModel provides a model of the contents of a folder in a filesystem.
-
- FolderListModel provides access to the local filesystem. The \e folder property
- specifies the folder to list.
-
- Qt uses "/" as a universal directory separator in the same way that "/" is
- used as a path separator in URLs. If you always use "/" as a directory
- separator, Qt will translate your paths to conform to the underlying
- operating system.
-
- The roles available are:
- \list
- \o fileName
- \o filePath
- \endlist
-
- Additionally a file entry can be differentiated from a folder entry
- via the \l isFolder() method.
-*/
-
-QmlFolderListModel::QmlFolderListModel(QObject *parent)
- : QListModelInterface(parent)
-{
- d = new QmlFolderListModelPrivate;
- d->model.setFilter(QDir::AllDirs | QDir::Files | QDir::Drives | QDir::NoDotAndDotDot);
- connect(&d->model, SIGNAL(rowsInserted(const QModelIndex&,int,int))
- , this, SLOT(inserted(const QModelIndex&,int,int)));
- connect(&d->model, SIGNAL(rowsRemoved(const QModelIndex&,int,int))
- , this, SLOT(removed(const QModelIndex&,int,int)));
- connect(&d->model, SIGNAL(dataChanged(const QModelIndex&,const QModelIndex&))
- , this, SLOT(dataChanged(const QModelIndex&,const QModelIndex&)));
- connect(&d->model, SIGNAL(modelReset()), this, SLOT(refresh()));
- connect(&d->model, SIGNAL(layoutChanged()), this, SLOT(refresh()));
-}
-
-QmlFolderListModel::~QmlFolderListModel()
-{
- delete d;
-}
-
-QHash<int,QVariant> QmlFolderListModel::data(int index, const QList<int> &roles) const
-{
- Q_UNUSED(roles);
- QHash<int,QVariant> folderData;
- QModelIndex modelIndex = d->model.index(index, 0, d->folderIndex);
- if (modelIndex.isValid()) {
- folderData[QDirModel::FileNameRole] = d->model.data(modelIndex, QDirModel::FileNameRole);
- folderData[QDirModel::FilePathRole] = QUrl::fromLocalFile(d->model.data(modelIndex, QDirModel::FilePathRole).toString());
- }
-
- return folderData;
-}
-
-int QmlFolderListModel::count() const
-{
- return d->count;
-}
-
-QList<int> QmlFolderListModel::roles() const
-{
- QList<int> r;
- r << QDirModel::FileNameRole;
- r << QDirModel::FilePathRole;
- return r;
-}
-
-QString QmlFolderListModel::toString(int role) const
-{
- switch (role) {
- case QDirModel::FileNameRole:
- return QLatin1String("fileName");
- case QDirModel::FilePathRole:
- return QLatin1String("filePath");
- }
-
- return QString();
-}
-
-/*!
- \qmlproperty string FolderListModel::folder
-
- The \a folder property holds the folder the model is currently providing.
-
- It is a URL, but must be a file: or qrc: URL (or relative to such a URL).
-*/
-QUrl QmlFolderListModel::folder() const
-{
- return d->folder;
-}
-
-void QmlFolderListModel::setFolder(const QUrl &folder)
-{
- if (folder == d->folder)
- return;
- QModelIndex index = d->model.index(folder.toLocalFile());
- if (index.isValid() && d->model.isDir(index)) {
- d->folder = folder;
- QMetaObject::invokeMethod(this, "refresh", Qt::QueuedConnection);
- emit folderChanged();
- }
-}
-
-QUrl QmlFolderListModel::parentFolder() const
-{
- int pos = d->folder.path().lastIndexOf(QLatin1Char('/'));
- if (pos == -1)
- return QUrl();
- QUrl r = d->folder;
- r.setPath(d->folder.path().left(pos));
- return r;
-}
-
-/*!
- \qmlproperty list<string> FolderListModel::nameFilters
-
- The \a nameFilters property contains a list of filename filters.
- The filters may include the ? and * wildcards.
-
- The example below filters on PNG and JPEG files:
-
- \code
- FolderListModel {
- nameFilters: [ "*.png", "*.jpg" ]
- }
- \endcode
-*/
-QStringList QmlFolderListModel::nameFilters() const
-{
- return d->nameFilters;
-}
-
-void QmlFolderListModel::setNameFilters(const QStringList &filters)
-{
- d->nameFilters = filters;
- d->model.setNameFilters(d->nameFilters);
-}
-
-void QmlFolderListModel::componentComplete()
-{
- if (!d->folder.isValid() || !QDir().exists(d->folder.toLocalFile()))
- setFolder(QUrl(QLatin1String("file://")+QDir::currentPath()));
-
- if (!d->folderIndex.isValid())
- QMetaObject::invokeMethod(this, "refresh", Qt::QueuedConnection);
-}
-
-QmlFolderListModel::SortField QmlFolderListModel::sortField() const
-{
- return d->sortField;
-}
-
-void QmlFolderListModel::setSortField(SortField field)
-{
- if (field != d->sortField) {
- d->sortField = field;
- d->updateSorting();
- }
-}
-
-bool QmlFolderListModel::sortReversed() const
-{
- return d->sortReversed;
-}
-
-void QmlFolderListModel::setSortReversed(bool rev)
-{
- if (rev != d->sortReversed) {
- d->sortReversed = rev;
- d->updateSorting();
- }
-}
-
-/*!
- \qmlmethod bool FolderListModel::isFolder(int index)
-
- Returns true if the entry \a index is a folder; otherwise
- returns false.
-*/
-bool QmlFolderListModel::isFolder(int index) const
-{
- if (index != -1) {
- QModelIndex idx = d->model.index(index, 0, d->folderIndex);
- if (idx.isValid())
- return d->model.isDir(idx);
- }
- return false;
-}
-
-void QmlFolderListModel::refresh()
-{
- d->folderIndex = QModelIndex();
- if (d->count) {
- int tmpCount = d->count;
- d->count = 0;
- emit itemsRemoved(0, tmpCount);
- }
- d->folderIndex = d->model.index(d->folder.toLocalFile());
- d->count = d->model.rowCount(d->folderIndex);
- if (d->count) {
- emit itemsInserted(0, d->count);
- }
-}
-
-void QmlFolderListModel::inserted(const QModelIndex &index, int start, int end)
-{
- if (index == d->folderIndex) {
- d->count = d->model.rowCount(d->folderIndex);
- emit itemsInserted(start, end - start + 1);
- }
-}
-
-void QmlFolderListModel::removed(const QModelIndex &index, int start, int end)
-{
- if (index == d->folderIndex) {
- d->count = d->model.rowCount(d->folderIndex);
- emit itemsRemoved(start, end - start + 1);
- }
-}
-
-void QmlFolderListModel::dataChanged(const QModelIndex &start, const QModelIndex &end)
-{
- qDebug() << "data changed";
- if (start.parent() == d->folderIndex)
- emit itemsChanged(start.row(), end.row() - start.row() + 1, roles());
-}
-
-/*!
- \qmlproperty bool FolderListModel::showDirs
-
- If true (the default), directories are included in the model.
-
- Note that the nameFilters are ignored for directories.
-*/
-bool QmlFolderListModel::showDirs() const
-{
- return d->model.filter() & QDir::AllDirs;
-}
-
-void QmlFolderListModel::setShowDirs(bool on)
-{
- if (!(d->model.filter() & QDir::AllDirs) == !on)
- return;
- if (on)
- d->model.setFilter(d->model.filter() | QDir::AllDirs | QDir::Drives);
- else
- d->model.setFilter(d->model.filter() & ~(QDir::AllDirs | QDir::Drives));
-}
-
-/*!
- \qmlproperty bool FolderListModel::showDotAndDotDot
-
- If true, the "." and ".." directories are included in the model.
-
- The default is false.
-*/
-bool QmlFolderListModel::showDotAndDotDot() const
-{
- return !(d->model.filter() & QDir::NoDotAndDotDot);
-}
-
-void QmlFolderListModel::setShowDotAndDotDot(bool on)
-{
- if (!(d->model.filter() & QDir::NoDotAndDotDot) == on)
- return;
- if (on)
- d->model.setFilter(d->model.filter() & ~QDir::NoDotAndDotDot);
- else
- d->model.setFilter(d->model.filter() | QDir::NoDotAndDotDot);
-}
-
-/*!
- \qmlproperty bool FolderListModel::showOnlyReadable
-
- If true, only readable files and directories are shown.
-
- The default is false.
-*/
-bool QmlFolderListModel::showOnlyReadable() const
-{
- return d->model.filter() & QDir::Readable;
-}
-
-void QmlFolderListModel::setShowOnlyReadable(bool on)
-{
- if (!(d->model.filter() & QDir::Readable) == !on)
- return;
- if (on)
- d->model.setFilter(d->model.filter() | QDir::Readable);
- else
- d->model.setFilter(d->model.filter() & ~QDir::Readable);
-}
-
-
-QML_DEFINE_TYPE(Qt,4,6,FolderListModel,QmlFolderListModel)
-
-QT_END_NAMESPACE
-
diff --git a/examples/declarative/loader/qmlfolderlistmodel.h b/examples/declarative/loader/qmlfolderlistmodel.h
deleted file mode 100644
index ac9568f..0000000
--- a/examples/declarative/loader/qmlfolderlistmodel.h
+++ /dev/null
@@ -1,118 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
-** All rights reserved.
-** Contact: Nokia Corporation (qt-info@nokia.com)
-**
-** This file is part of the examples of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the Technology Preview License Agreement accompanying
-** this package.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** If you have questions regarding the use of this file, please contact
-** Nokia at qt-info@nokia.com.
-**
-**
-**
-**
-**
-**
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QMLFOLDERLISTMODEL_H
-#define QMLFOLDERLISTMODEL_H
-
-#include <qml.h>
-#include "../../../src/declarative/3rdparty/qlistmodelinterface_p.h"
-
-class QmlContext;
-class QModelIndex;
-
-class QmlFolderListModelPrivate;
-class QmlFolderListModel : public QListModelInterface, public QmlParserStatus
-{
- Q_OBJECT
- Q_INTERFACES(QmlParserStatus)
-
- Q_PROPERTY(QUrl folder READ folder WRITE setFolder NOTIFY folderChanged)
- Q_PROPERTY(QUrl parentFolder READ parentFolder NOTIFY folderChanged)
- Q_PROPERTY(QStringList nameFilters READ nameFilters WRITE setNameFilters)
- Q_PROPERTY(SortField sortField READ sortField WRITE setSortField)
- Q_PROPERTY(bool sortReversed READ sortReversed WRITE setSortReversed)
- Q_PROPERTY(bool showDirs READ showDirs WRITE setShowDirs)
- Q_PROPERTY(bool showDotAndDotDot READ showDotAndDotDot WRITE setShowDotAndDotDot)
- Q_PROPERTY(bool showOnlyReadable READ showOnlyReadable WRITE setShowOnlyReadable)
-
-public:
- QmlFolderListModel(QObject *parent = 0);
- ~QmlFolderListModel();
-
- virtual QHash<int,QVariant> data(int index, const QList<int> &roles = (QList<int>())) const;
- virtual int count() const;
- virtual QList<int> roles() const;
- virtual QString toString(int role) const;
-
- QUrl folder() const;
- void setFolder(const QUrl &folder);
-
- QUrl parentFolder() const;
-
- QStringList nameFilters() const;
- void setNameFilters(const QStringList &filters);
-
- virtual void componentComplete();
-
- Q_INVOKABLE bool isFolder(int index) const;
-
- enum SortField { Unsorted, Name, Time, Size, Type };
- SortField sortField() const;
- void setSortField(SortField field);
- Q_ENUMS(SortField)
-
- bool sortReversed() const;
- void setSortReversed(bool rev);
-
- bool showDirs() const;
- void setShowDirs(bool);
- bool showDotAndDotDot() const;
- void setShowDotAndDotDot(bool);
- bool showOnlyReadable() const;
- void setShowOnlyReadable(bool);
-
-Q_SIGNALS:
- void folderChanged();
-
-private Q_SLOTS:
- void refresh();
- void inserted(const QModelIndex &index, int start, int end);
- void removed(const QModelIndex &index, int start, int end);
- void dataChanged(const QModelIndex &start, const QModelIndex &end);
-
-private:
- Q_DISABLE_COPY(QmlFolderListModel)
- QmlFolderListModelPrivate *d;
-};
-
-QML_DECLARE_TYPE(QmlFolderListModel)
-
-#endif // QMLFOLDERLISTMODEL_H