0
|
1 |
/****************************************************************************
|
|
2 |
**
|
|
3 |
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
4 |
** All rights reserved.
|
|
5 |
** Contact: Nokia Corporation (qt-info@nokia.com)
|
|
6 |
**
|
|
7 |
** This file is part of the QtCore module of the Qt Toolkit.
|
|
8 |
**
|
|
9 |
** $QT_BEGIN_LICENSE:LGPL$
|
|
10 |
** No Commercial Usage
|
|
11 |
** This file contains pre-release code and may not be distributed.
|
|
12 |
** You may use this file in accordance with the terms and conditions
|
|
13 |
** contained in the Technology Preview License Agreement accompanying
|
|
14 |
** this package.
|
|
15 |
**
|
|
16 |
** GNU Lesser General Public License Usage
|
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
18 |
** General Public License version 2.1 as published by the Free Software
|
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
20 |
** packaging of this file. Please review the following information to
|
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
23 |
**
|
|
24 |
** In addition, as a special exception, Nokia gives you certain additional
|
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception
|
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
27 |
**
|
|
28 |
** If you have questions regarding the use of this file, please contact
|
|
29 |
** Nokia at qt-info@nokia.com.
|
|
30 |
**
|
|
31 |
**
|
|
32 |
**
|
|
33 |
**
|
|
34 |
**
|
|
35 |
**
|
|
36 |
**
|
|
37 |
**
|
|
38 |
** $QT_END_LICENSE$
|
|
39 |
**
|
|
40 |
****************************************************************************/
|
|
41 |
|
|
42 |
#include "qfsfileengine_iterator_p.h"
|
|
43 |
#include "qfsfileengine_p.h"
|
|
44 |
#include "qplatformdefs.h"
|
|
45 |
|
|
46 |
#include <QtCore/qvariant.h>
|
|
47 |
|
|
48 |
QT_BEGIN_NAMESPACE
|
|
49 |
|
|
50 |
class QFSFileEngineIteratorPlatformSpecificData
|
|
51 |
{
|
|
52 |
public:
|
|
53 |
inline QFSFileEngineIteratorPlatformSpecificData()
|
|
54 |
: uncShareIndex(-1), findFileHandle(INVALID_HANDLE_VALUE),
|
|
55 |
done(false), uncFallback(false)
|
|
56 |
{}
|
|
57 |
|
|
58 |
QFSFileEngineIterator *it;
|
|
59 |
|
|
60 |
QStringList uncShares;
|
|
61 |
int uncShareIndex;
|
|
62 |
|
|
63 |
HANDLE findFileHandle;
|
|
64 |
WIN32_FIND_DATA findData;
|
|
65 |
bool done;
|
|
66 |
bool uncFallback;
|
|
67 |
|
|
68 |
void saveCurrentFileName();
|
|
69 |
};
|
|
70 |
|
|
71 |
void QFSFileEngineIteratorPlatformSpecificData::saveCurrentFileName()
|
|
72 |
{
|
|
73 |
if (uncFallback) {
|
|
74 |
// Windows share / UNC path
|
|
75 |
it->currentEntry = uncShares.at(uncShareIndex - 1);
|
|
76 |
} else {
|
|
77 |
// Local directory
|
|
78 |
it->currentEntry = QString::fromWCharArray(findData.cFileName);
|
|
79 |
}
|
|
80 |
}
|
|
81 |
|
|
82 |
void QFSFileEngineIterator::advance()
|
|
83 |
{
|
|
84 |
platform->saveCurrentFileName();
|
|
85 |
|
|
86 |
if (platform->done)
|
|
87 |
return;
|
|
88 |
|
|
89 |
if (platform->uncFallback) {
|
|
90 |
++platform->uncShareIndex;
|
|
91 |
} else if (platform->findFileHandle != INVALID_HANDLE_VALUE) {
|
|
92 |
if (!FindNextFile(platform->findFileHandle, &platform->findData)) {
|
|
93 |
platform->done = true;
|
|
94 |
FindClose(platform->findFileHandle);
|
|
95 |
}
|
|
96 |
}
|
|
97 |
}
|
|
98 |
|
|
99 |
void QFSFileEngineIterator::newPlatformSpecifics()
|
|
100 |
{
|
|
101 |
platform = new QFSFileEngineIteratorPlatformSpecificData;
|
|
102 |
platform->it = this;
|
|
103 |
}
|
|
104 |
|
|
105 |
void QFSFileEngineIterator::deletePlatformSpecifics()
|
|
106 |
{
|
|
107 |
delete platform;
|
|
108 |
platform = 0;
|
|
109 |
}
|
|
110 |
|
|
111 |
bool QFSFileEngineIterator::hasNext() const
|
|
112 |
{
|
|
113 |
if (platform->done)
|
|
114 |
return false;
|
|
115 |
|
|
116 |
if (platform->uncFallback)
|
|
117 |
return platform->uncShareIndex > 0 && platform->uncShareIndex <= platform->uncShares.size();
|
|
118 |
|
|
119 |
if (platform->findFileHandle == INVALID_HANDLE_VALUE) {
|
|
120 |
QString path = this->path();
|
|
121 |
// Local directory
|
|
122 |
if (path.endsWith(QLatin1String(".lnk")))
|
|
123 |
path = QFileInfo(path).readLink();
|
|
124 |
|
|
125 |
if (!path.endsWith(QLatin1Char('/')))
|
|
126 |
path.append(QLatin1Char('/'));
|
|
127 |
path.append(QLatin1String("*.*"));
|
|
128 |
|
|
129 |
QString fileName = QFSFileEnginePrivate::longFileName(path);
|
|
130 |
platform->findFileHandle = FindFirstFile((const wchar_t *)fileName.utf16(), &platform->findData);
|
|
131 |
|
|
132 |
if (platform->findFileHandle == INVALID_HANDLE_VALUE) {
|
|
133 |
if (path.startsWith(QLatin1String("//"))) {
|
|
134 |
path = this->path();
|
|
135 |
// UNC
|
|
136 |
QStringList parts = QDir::toNativeSeparators(path).split(QLatin1Char('\\'), QString::SkipEmptyParts);
|
|
137 |
|
|
138 |
if (parts.count() == 1 && QFSFileEnginePrivate::uncListSharesOnServer(QLatin1String("\\\\") + parts.at(0),
|
|
139 |
&platform->uncShares)) {
|
|
140 |
if (platform->uncShares.isEmpty()) {
|
|
141 |
platform->done = true;
|
|
142 |
} else {
|
|
143 |
platform->uncShareIndex = 1;
|
|
144 |
}
|
|
145 |
platform->uncFallback = true;
|
|
146 |
} else {
|
|
147 |
platform->done = true;
|
|
148 |
}
|
|
149 |
} else {
|
|
150 |
platform->done = true;
|
|
151 |
}
|
|
152 |
}
|
|
153 |
|
|
154 |
if (!platform->done && (!platform->uncFallback || !platform->uncShares.isEmpty()))
|
|
155 |
platform->saveCurrentFileName();
|
|
156 |
}
|
|
157 |
|
|
158 |
return !platform->done;
|
|
159 |
}
|
|
160 |
|
|
161 |
QT_END_NAMESPACE
|