1/****************************************************************************
2**
3** Copyright (C) 2017 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the Qt Labs Platform module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#include "qquickplatformstandardpaths_p.h"
41
42#include <QtQml/qqmlengine.h>
43
44QT_BEGIN_NAMESPACE
45
46/*!
47 \qmltype StandardPaths
48 \inherits QtObject
49//! \instantiates QQuickPlatformStandardPaths
50 \inqmlmodule Qt.labs.platform
51 \since 5.8
52 \brief Provides access to the standard system paths.
53
54 The StandardPaths singleton type provides methods for querying the standard
55 system paths. The standard paths are mostly useful in conjunction with the
56 FileDialog and FolderDialog types.
57
58 \qml
59 FileDialog {
60 folder: StandardPaths.writableLocation(StandardPaths.DocumentsLocation)
61 }
62 \endqml
63
64 \labs
65
66 \sa FileDialog, FolderDialog, QStandardPaths
67*/
68
69static QList<QUrl> toUrlList(const QStringList &paths)
70{
71 QList<QUrl> urls;
72 urls.reserve(alloc: paths.size());
73 for (const QString &path : paths)
74 urls += QUrl::fromLocalFile(localfile: path);
75 return urls;
76}
77
78QQuickPlatformStandardPaths::QQuickPlatformStandardPaths(QObject *parent)
79 : QObject(parent)
80{
81}
82
83QObject *QQuickPlatformStandardPaths::create(QQmlEngine *engine, QJSEngine *scriptEngine)
84{
85 Q_UNUSED(scriptEngine);
86 return new QQuickPlatformStandardPaths(engine);
87}
88
89/*!
90 \qmlmethod string Qt.labs.platform::StandardPaths::displayName(StandardLocation type)
91
92 \include standardpath/functiondocs.qdocinc displayName
93
94 \sa QStandardPaths::displayName()
95*/
96QString QQuickPlatformStandardPaths::displayName(QStandardPaths::StandardLocation type)
97{
98 return QStandardPaths::displayName(type);
99}
100
101/*!
102 \qmlmethod url Qt.labs.platform::StandardPaths::findExecutable(string executableName, list<string> paths)
103
104 \include standardpath/functiondocs.qdocinc findExecutable
105
106 \sa QStandardPaths::findExecutable()
107*/
108QUrl QQuickPlatformStandardPaths::findExecutable(const QString &executableName, const QStringList &paths)
109{
110 return QUrl::fromLocalFile(localfile: QStandardPaths::findExecutable(executableName, paths));
111}
112
113/*!
114 \qmlmethod url Qt.labs.platform::StandardPaths::locate(StandardLocation type, string fileName, LocateOptions options)
115
116 \include standardpath/functiondocs.qdocinc locate
117
118 \sa QStandardPaths::locate()
119*/
120QUrl QQuickPlatformStandardPaths::locate(QStandardPaths::StandardLocation type, const QString &fileName, QStandardPaths::LocateOptions options)
121{
122 return QUrl::fromLocalFile(localfile: QStandardPaths::locate(type, fileName, options));
123}
124
125/*!
126 \qmlmethod list<url> Qt.labs.platform::StandardPaths::locateAll(StandardLocation type, string fileName, LocateOptions options)
127
128 \include standardpath/functiondocs.qdocinc locateAll
129
130 \sa QStandardPaths::locateAll()
131*/
132QList<QUrl> QQuickPlatformStandardPaths::locateAll(QStandardPaths::StandardLocation type, const QString &fileName, QStandardPaths::LocateOptions options)
133{
134 return toUrlList(paths: QStandardPaths::locateAll(type, fileName, options));
135}
136
137/*!
138 \qmlmethod void Qt.labs.platform::StandardPaths::setTestModeEnabled(bool testMode)
139
140 \include standardpath/functiondocs.qdocinc setTestModeEnabled
141
142 \sa QStandardPaths::setTestModeEnabled()
143*/
144void QQuickPlatformStandardPaths::setTestModeEnabled(bool testMode)
145{
146 QStandardPaths::setTestModeEnabled(testMode);
147}
148
149/*!
150 \qmlmethod list<url> Qt.labs.platform::StandardPaths::standardLocations(StandardLocation type)
151
152 \include standardpath/functiondocs.qdocinc standardLocations
153
154 \sa QStandardPaths::standardLocations()
155*/
156QList<QUrl> QQuickPlatformStandardPaths::standardLocations(QStandardPaths::StandardLocation type)
157{
158 return toUrlList(paths: QStandardPaths::standardLocations(type));
159}
160
161/*!
162 \qmlmethod url Qt.labs.platform::StandardPaths::writableLocation(StandardLocation type)
163
164 \include standardpath/functiondocs.qdocinc writableLocation
165
166 \sa QStandardPaths::writableLocation()
167*/
168QUrl QQuickPlatformStandardPaths::writableLocation(QStandardPaths::StandardLocation type)
169{
170 return QUrl::fromLocalFile(localfile: QStandardPaths::writableLocation(type));
171}
172
173QT_END_NAMESPACE
174

source code of qtquickcontrols2/src/imports/platform/qquickplatformstandardpaths.cpp