Mercurial > octave
comparison libgui/languages/build_ts/octave-qt/qfileinfogatherer.cpp @ 31537:5ceb4bfcdb0f stable
add tools and files for updating the gui's language files for translation
* libgui/languages/build_ts/README.md: readme for updating language files
* libgui/languages/build_ts/octave-qsci: QScintilla source files for
languages without translation provided by QScintilla
* libgui/languages/build_ts/octave-qt: Qt source files for languages
without translation provided by Qt
author | Torsten Lilge <ttl-octave@mailbox.org> |
---|---|
date | Thu, 24 Nov 2022 06:48:25 +0100 |
parents | |
children | c8dd3da44e83 |
comparison
equal
deleted
inserted
replaced
31535:4b80982e0af8 | 31537:5ceb4bfcdb0f |
---|---|
1 /**************************************************************************** | |
2 ** | |
3 ** Copyright (C) 2015 The Qt Company Ltd. | |
4 ** Contact: http://www.qt.io/licensing/ | |
5 ** | |
6 ** This file is part of the QtGui 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 http://www.qt.io/terms-conditions. For further | |
15 ** information use the contact form at http://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 2.1 or version 3 as published by the Free | |
20 ** Software Foundation and appearing in the file LICENSE.LGPLv21 and | |
21 ** LICENSE.LGPLv3 included in the packaging of this file. Please review the | |
22 ** following information to ensure the GNU Lesser General Public License | |
23 ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and | |
24 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | |
25 ** | |
26 ** As a special exception, The Qt Company gives you certain additional | |
27 ** rights. These rights are described in The Qt Company LGPL Exception | |
28 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | |
29 ** | |
30 ** GNU General Public License Usage | |
31 ** Alternatively, this file may be used under the terms of the GNU | |
32 ** General Public License version 3.0 as published by the Free Software | |
33 ** Foundation and appearing in the file LICENSE.GPL included in the | |
34 ** packaging of this file. Please review the following information to | |
35 ** ensure the GNU General Public License version 3.0 requirements will be | |
36 ** met: http://www.gnu.org/copyleft/gpl.html. | |
37 ** | |
38 ** $QT_END_LICENSE$ | |
39 ** | |
40 ****************************************************************************/ | |
41 | |
42 #include "qfileinfogatherer_p.h" | |
43 #include <qdebug.h> | |
44 #include <qfsfileengine.h> | |
45 #include <qdiriterator.h> | |
46 #ifndef Q_OS_WIN | |
47 # include <unistd.h> | |
48 # include <sys/types.h> | |
49 #endif | |
50 #if defined(Q_OS_VXWORKS) | |
51 # include "qplatformdefs.h" | |
52 #endif | |
53 | |
54 QT_BEGIN_NAMESPACE | |
55 | |
56 #ifndef QT_NO_FILESYSTEMMODEL | |
57 | |
58 #ifdef QT_BUILD_INTERNAL | |
59 static bool fetchedRoot = false; | |
60 Q_AUTOTEST_EXPORT void qt_test_resetFetchedRoot() | |
61 { | |
62 fetchedRoot = false; | |
63 } | |
64 | |
65 Q_AUTOTEST_EXPORT bool qt_test_isFetchedRoot() | |
66 { | |
67 return fetchedRoot; | |
68 } | |
69 #endif | |
70 | |
71 /*! | |
72 Creates thread | |
73 */ | |
74 QFileInfoGatherer::QFileInfoGatherer(QObject *parent) | |
75 : QThread(parent), abort(false), | |
76 #ifndef QT_NO_FILESYSTEMWATCHER | |
77 watcher(0), | |
78 #endif | |
79 m_resolveSymlinks(false), m_iconProvider(&defaultProvider) | |
80 { | |
81 #ifdef Q_OS_WIN | |
82 m_resolveSymlinks = true; | |
83 #elif !defined(Q_OS_INTEGRITY) && !defined(Q_OS_VXWORKS) | |
84 userId = getuid(); | |
85 groupId = getgid(); | |
86 #endif | |
87 #ifndef QT_NO_FILESYSTEMWATCHER | |
88 watcher = new QFileSystemWatcher(this); | |
89 connect(watcher, SIGNAL(directoryChanged(QString)), this, SLOT(list(QString))); | |
90 connect(watcher, SIGNAL(fileChanged(QString)), this, SLOT(updateFile(QString))); | |
91 #endif | |
92 start(LowPriority); | |
93 } | |
94 | |
95 /*! | |
96 Destroys thread | |
97 */ | |
98 QFileInfoGatherer::~QFileInfoGatherer() | |
99 { | |
100 QMutexLocker locker(&mutex); | |
101 abort = true; | |
102 condition.wakeOne(); | |
103 locker.unlock(); | |
104 wait(); | |
105 } | |
106 | |
107 void QFileInfoGatherer::setResolveSymlinks(bool enable) | |
108 { | |
109 Q_UNUSED(enable); | |
110 #ifdef Q_OS_WIN | |
111 QMutexLocker locker(&mutex); | |
112 m_resolveSymlinks = enable; | |
113 #endif | |
114 } | |
115 | |
116 bool QFileInfoGatherer::resolveSymlinks() const | |
117 { | |
118 return m_resolveSymlinks; | |
119 } | |
120 | |
121 void QFileInfoGatherer::setIconProvider(QFileIconProvider *provider) | |
122 { | |
123 QMutexLocker locker(&mutex); | |
124 m_iconProvider = provider; | |
125 } | |
126 | |
127 QFileIconProvider *QFileInfoGatherer::iconProvider() const | |
128 { | |
129 return m_iconProvider; | |
130 } | |
131 | |
132 /*! | |
133 Fetch extended information for all \a files in \a path | |
134 | |
135 \sa updateFile(), update(), resolvedName() | |
136 */ | |
137 void QFileInfoGatherer::fetchExtendedInformation(const QString &path, const QStringList &files) | |
138 { | |
139 QMutexLocker locker(&mutex); | |
140 // See if we already have this dir/file in our que | |
141 int loc = this->path.lastIndexOf(path); | |
142 while (loc > 0) { | |
143 if (this->files.at(loc) == files) { | |
144 return; | |
145 } | |
146 loc = this->path.lastIndexOf(path, loc - 1); | |
147 } | |
148 this->path.push(path); | |
149 this->files.push(files); | |
150 condition.wakeAll(); | |
151 } | |
152 | |
153 /*! | |
154 Fetch extended information for all \a filePath | |
155 | |
156 \sa fetchExtendedInformation() | |
157 */ | |
158 void QFileInfoGatherer::updateFile(const QString &filePath) | |
159 { | |
160 QString dir = filePath.mid(0, filePath.lastIndexOf(QDir::separator())); | |
161 QString fileName = filePath.mid(dir.length() + 1); | |
162 fetchExtendedInformation(dir, QStringList(fileName)); | |
163 } | |
164 | |
165 /* | |
166 List all files in \a directoryPath | |
167 | |
168 \sa listed() | |
169 */ | |
170 void QFileInfoGatherer::clear() | |
171 { | |
172 #ifndef QT_NO_FILESYSTEMWATCHER | |
173 QMutexLocker locker(&mutex); | |
174 watcher->removePaths(watcher->files()); | |
175 watcher->removePaths(watcher->directories()); | |
176 #endif | |
177 } | |
178 | |
179 /* | |
180 Remove a \a path from the watcher | |
181 | |
182 \sa listed() | |
183 */ | |
184 void QFileInfoGatherer::removePath(const QString &path) | |
185 { | |
186 #ifndef QT_NO_FILESYSTEMWATCHER | |
187 QMutexLocker locker(&mutex); | |
188 watcher->removePath(path); | |
189 #endif | |
190 } | |
191 | |
192 /* | |
193 List all files in \a directoryPath | |
194 | |
195 \sa listed() | |
196 */ | |
197 void QFileInfoGatherer::list(const QString &directoryPath) | |
198 { | |
199 fetchExtendedInformation(directoryPath, QStringList()); | |
200 } | |
201 | |
202 /* | |
203 Until aborted wait to fetch a directory or files | |
204 */ | |
205 void QFileInfoGatherer::run() | |
206 { | |
207 forever { | |
208 bool updateFiles = false; | |
209 QMutexLocker locker(&mutex); | |
210 if (abort) { | |
211 return; | |
212 } | |
213 if (this->path.isEmpty()) | |
214 condition.wait(&mutex); | |
215 QString path; | |
216 QStringList list; | |
217 if (!this->path.isEmpty()) { | |
218 path = this->path.first(); | |
219 list = this->files.first(); | |
220 this->path.pop_front(); | |
221 this->files.pop_front(); | |
222 updateFiles = true; | |
223 } | |
224 locker.unlock(); | |
225 if (updateFiles) | |
226 getFileInfos(path, list); | |
227 } | |
228 } | |
229 | |
230 QExtendedInformation QFileInfoGatherer::getInfo(const QFileInfo &fileInfo) const | |
231 { | |
232 QExtendedInformation info(fileInfo); | |
233 info.icon = m_iconProvider->icon(fileInfo); | |
234 info.displayType = m_iconProvider->type(fileInfo); | |
235 #ifndef QT_NO_FILESYSTEMWATCHER | |
236 // ### Not ready to listen all modifications | |
237 #if 0 | |
238 // Enable the next two commented out lines to get updates when the file sizes change... | |
239 if (!fileInfo.exists() && !fileInfo.isSymLink()) { | |
240 info.size = -1; | |
241 //watcher->removePath(fileInfo.absoluteFilePath()); | |
242 } else { | |
243 if (!fileInfo.absoluteFilePath().isEmpty() && fileInfo.exists() && fileInfo.isReadable() | |
244 && !watcher->files().contains(fileInfo.absoluteFilePath())) { | |
245 //watcher->addPath(fileInfo.absoluteFilePath()); | |
246 } | |
247 } | |
248 #endif | |
249 #endif | |
250 | |
251 if (m_resolveSymlinks && info.isSymLink(/* ignoreNtfsSymLinks = */ true)) { | |
252 QFileInfo resolvedInfo(fileInfo.symLinkTarget()); | |
253 resolvedInfo = resolvedInfo.canonicalFilePath(); | |
254 if (resolvedInfo.exists()) { | |
255 emit nameResolved(fileInfo.filePath(), resolvedInfo.fileName()); | |
256 } | |
257 } | |
258 return info; | |
259 } | |
260 | |
261 QString QFileInfoGatherer::translateDriveName(const QFileInfo &drive) const | |
262 { | |
263 QString driveName = drive.absoluteFilePath(); | |
264 #if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) | |
265 if (driveName.startsWith(QLatin1Char('/'))) // UNC host | |
266 return drive.fileName(); | |
267 #endif | |
268 #if (defined(Q_OS_WIN) && !defined(Q_OS_WINCE)) || defined(Q_OS_SYMBIAN) | |
269 if (driveName.endsWith(QLatin1Char('/'))) | |
270 driveName.chop(1); | |
271 #endif | |
272 return driveName; | |
273 } | |
274 | |
275 /* | |
276 Get specific file info's, batch the files so update when we have 100 | |
277 items and every 200ms after that | |
278 */ | |
279 void QFileInfoGatherer::getFileInfos(const QString &path, const QStringList &files) | |
280 { | |
281 #ifndef QT_NO_FILESYSTEMWATCHER | |
282 if (files.isEmpty() | |
283 && !watcher->directories().contains(path) | |
284 && !path.isEmpty() | |
285 && !path.startsWith(QLatin1String("//")) /*don't watch UNC path*/) { | |
286 watcher->addPath(path); | |
287 } | |
288 #endif | |
289 | |
290 // List drives | |
291 if (path.isEmpty()) { | |
292 #ifdef QT_BUILD_INTERNAL | |
293 fetchedRoot = true; | |
294 #endif | |
295 QFileInfoList infoList; | |
296 if (files.isEmpty()) { | |
297 infoList = QDir::drives(); | |
298 } else { | |
299 for (int i = 0; i < files.count(); ++i) | |
300 infoList << QFileInfo(files.at(i)); | |
301 } | |
302 for (int i = infoList.count() - 1; i >= 0; --i) { | |
303 QString driveName = translateDriveName(infoList.at(i)); | |
304 QList<QPair<QString,QFileInfo> > updatedFiles; | |
305 updatedFiles.append(QPair<QString,QFileInfo>(driveName, infoList.at(i))); | |
306 emit updates(path, updatedFiles); | |
307 } | |
308 return; | |
309 } | |
310 | |
311 QElapsedTimer base; | |
312 base.start(); | |
313 QFileInfo fileInfo; | |
314 bool firstTime = true; | |
315 QList<QPair<QString, QFileInfo> > updatedFiles; | |
316 QStringList filesToCheck = files; | |
317 | |
318 QString itPath = QDir::fromNativeSeparators(files.isEmpty() ? path : QLatin1String("")); | |
319 QDirIterator dirIt(itPath, QDir::AllEntries | QDir::System | QDir::Hidden); | |
320 QStringList allFiles; | |
321 while(!abort && dirIt.hasNext()) { | |
322 dirIt.next(); | |
323 fileInfo = dirIt.fileInfo(); | |
324 allFiles.append(fileInfo.fileName()); | |
325 fetch(fileInfo, base, firstTime, updatedFiles, path); | |
326 } | |
327 if (!allFiles.isEmpty()) | |
328 emit newListOfFiles(path, allFiles); | |
329 | |
330 QStringList::const_iterator filesIt = filesToCheck.constBegin(); | |
331 while(!abort && filesIt != filesToCheck.constEnd()) { | |
332 fileInfo.setFile(path + QDir::separator() + *filesIt); | |
333 ++filesIt; | |
334 fetch(fileInfo, base, firstTime, updatedFiles, path); | |
335 } | |
336 if (!updatedFiles.isEmpty()) | |
337 emit updates(path, updatedFiles); | |
338 emit directoryLoaded(path); | |
339 } | |
340 | |
341 void QFileInfoGatherer::fetch(const QFileInfo &fileInfo, QElapsedTimer &base, bool &firstTime, QList<QPair<QString, QFileInfo> > &updatedFiles, const QString &path) { | |
342 updatedFiles.append(QPair<QString, QFileInfo>(fileInfo.fileName(), fileInfo)); | |
343 QElapsedTimer current; | |
344 current.start(); | |
345 if ((firstTime && updatedFiles.count() > 100) || base.msecsTo(current) > 1000) { | |
346 emit updates(path, updatedFiles); | |
347 updatedFiles.clear(); | |
348 base = current; | |
349 firstTime = false; | |
350 } | |
351 } | |
352 | |
353 #endif // QT_NO_FILESYSTEMMODEL | |
354 | |
355 QT_END_NAMESPACE |