1 | /* $Id: UIFileManagerGuestTable.cpp 81155 2019-10-08 14:45:09Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox Qt GUI - UIFileManagerGuestTable class implementation.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2016-2019 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | */
|
---|
17 |
|
---|
18 | /* Qt includes: */
|
---|
19 | #include <QDateTime>
|
---|
20 | #include <QFileInfo>
|
---|
21 | #include <QUuid>
|
---|
22 |
|
---|
23 | /* GUI includes: */
|
---|
24 | #include "QILabel.h"
|
---|
25 | #include "UIActionPool.h"
|
---|
26 | #include "UIErrorString.h"
|
---|
27 | #include "UICustomFileSystemModel.h"
|
---|
28 | #include "UIFileManager.h"
|
---|
29 | #include "UIFileManagerGuestTable.h"
|
---|
30 | #include "UIMessageCenter.h"
|
---|
31 | #include "UIPathOperations.h"
|
---|
32 | #include "UIToolBar.h"
|
---|
33 |
|
---|
34 | /* COM includes: */
|
---|
35 | #include "CFsObjInfo.h"
|
---|
36 | #include "CGuestFsObjInfo.h"
|
---|
37 | #include "CGuestDirectory.h"
|
---|
38 | #include "CProgress.h"
|
---|
39 |
|
---|
40 |
|
---|
41 | /*********************************************************************************************************************************
|
---|
42 | * UIGuestDirectoryDiskUsageComputer definition. *
|
---|
43 | *********************************************************************************************************************************/
|
---|
44 |
|
---|
45 | /** Open directories recursively and sum the disk usage. Don't block the GUI thread while doing this */
|
---|
46 | class UIGuestDirectoryDiskUsageComputer : public UIDirectoryDiskUsageComputer
|
---|
47 | {
|
---|
48 | Q_OBJECT;
|
---|
49 |
|
---|
50 | public:
|
---|
51 |
|
---|
52 | UIGuestDirectoryDiskUsageComputer(QObject *parent, QStringList strStartPath, const CGuestSession &session);
|
---|
53 |
|
---|
54 | protected:
|
---|
55 |
|
---|
56 | virtual void run() /* override */;
|
---|
57 | virtual void directoryStatisticsRecursive(const QString &path, UIDirectoryStatistics &statistics) /* override */;
|
---|
58 |
|
---|
59 | private:
|
---|
60 |
|
---|
61 | CGuestSession m_comGuestSession;
|
---|
62 | };
|
---|
63 |
|
---|
64 |
|
---|
65 | /*********************************************************************************************************************************
|
---|
66 | * UIGuestDirectoryDiskUsageComputer implementation. *
|
---|
67 | *********************************************************************************************************************************/
|
---|
68 |
|
---|
69 | UIGuestDirectoryDiskUsageComputer::UIGuestDirectoryDiskUsageComputer(QObject *parent, QStringList pathList, const CGuestSession &session)
|
---|
70 | :UIDirectoryDiskUsageComputer(parent, pathList)
|
---|
71 | , m_comGuestSession(session)
|
---|
72 | {
|
---|
73 | }
|
---|
74 |
|
---|
75 | void UIGuestDirectoryDiskUsageComputer::run()
|
---|
76 | {
|
---|
77 | /* Initialize COM: */
|
---|
78 | COMBase::InitializeCOM(false);
|
---|
79 | UIDirectoryDiskUsageComputer::run();
|
---|
80 | /* Cleanup COM: */
|
---|
81 | COMBase::CleanupCOM();
|
---|
82 | }
|
---|
83 |
|
---|
84 | void UIGuestDirectoryDiskUsageComputer::directoryStatisticsRecursive(const QString &path, UIDirectoryStatistics &statistics)
|
---|
85 | {
|
---|
86 | if (m_comGuestSession.isNull())
|
---|
87 | return;
|
---|
88 | /* Prevent modification of the continue flag while reading: */
|
---|
89 | m_mutex.lock();
|
---|
90 | /* Check if m_fOkToContinue is set to false. if so just end recursion: */
|
---|
91 | if (!isOkToContinue())
|
---|
92 | {
|
---|
93 | m_mutex.unlock();
|
---|
94 | return;
|
---|
95 | }
|
---|
96 | m_mutex.unlock();
|
---|
97 |
|
---|
98 | CGuestFsObjInfo fileInfo = m_comGuestSession.FsObjQueryInfo(path, true);
|
---|
99 |
|
---|
100 | if (!m_comGuestSession.isOk())
|
---|
101 | return;
|
---|
102 | /* if the object is a file or a symlink then read the size and return: */
|
---|
103 | if (fileInfo.GetType() == KFsObjType_File)
|
---|
104 | {
|
---|
105 | statistics.m_totalSize += fileInfo.GetObjectSize();
|
---|
106 | ++statistics.m_uFileCount;
|
---|
107 | sigResultUpdated(statistics);
|
---|
108 | return;
|
---|
109 | }
|
---|
110 | else if (fileInfo.GetType() == KFsObjType_Symlink)
|
---|
111 | {
|
---|
112 | statistics.m_totalSize += fileInfo.GetObjectSize();
|
---|
113 | ++statistics.m_uSymlinkCount;
|
---|
114 | sigResultUpdated(statistics);
|
---|
115 | return;
|
---|
116 | }
|
---|
117 |
|
---|
118 | if (fileInfo.GetType() != KFsObjType_Directory)
|
---|
119 | return;
|
---|
120 | /* Open the directory to start reading its content: */
|
---|
121 | QVector<KDirectoryOpenFlag> flag(1, KDirectoryOpenFlag_None);
|
---|
122 | CGuestDirectory directory = m_comGuestSession.DirectoryOpen(path, /*aFilter*/ "", flag);
|
---|
123 | if (!m_comGuestSession.isOk())
|
---|
124 | return;
|
---|
125 |
|
---|
126 | if (directory.isOk())
|
---|
127 | {
|
---|
128 | CFsObjInfo fsInfo = directory.Read();
|
---|
129 | while (fsInfo.isOk())
|
---|
130 | {
|
---|
131 | if (fsInfo.GetType() == KFsObjType_File)
|
---|
132 | statistics.m_uFileCount++;
|
---|
133 | else if (fsInfo.GetType() == KFsObjType_Symlink)
|
---|
134 | statistics.m_uSymlinkCount++;
|
---|
135 | else if(fsInfo.GetType() == KFsObjType_Directory)
|
---|
136 | {
|
---|
137 | QString dirPath = UIPathOperations::mergePaths(path, fsInfo.GetName());
|
---|
138 | directoryStatisticsRecursive(dirPath, statistics);
|
---|
139 | }
|
---|
140 | }
|
---|
141 | }
|
---|
142 | sigResultUpdated(statistics);
|
---|
143 | }
|
---|
144 |
|
---|
145 | UIFileManagerGuestTable::UIFileManagerGuestTable(UIActionPool *pActionPool, QWidget *pParent /*= 0*/)
|
---|
146 | :UIFileManagerTable(pActionPool, pParent)
|
---|
147 | {
|
---|
148 | prepareToolbar();
|
---|
149 | prepareActionConnections();
|
---|
150 | retranslateUi();
|
---|
151 | }
|
---|
152 |
|
---|
153 | void UIFileManagerGuestTable::initGuestFileTable(const CGuestSession &session)
|
---|
154 | {
|
---|
155 | if (!session.isOk())
|
---|
156 | return;
|
---|
157 | if (session.GetStatus() != KGuestSessionStatus_Started)
|
---|
158 | return;
|
---|
159 | m_comGuestSession = session;
|
---|
160 | /* To determine the path separator we need to have a valid guest session: */
|
---|
161 | determinePathSeparator();
|
---|
162 | initializeFileTree();
|
---|
163 | }
|
---|
164 |
|
---|
165 | void UIFileManagerGuestTable::retranslateUi()
|
---|
166 | {
|
---|
167 | if (m_pLocationLabel)
|
---|
168 | m_pLocationLabel->setText(UIFileManager::tr("Guest File System"));
|
---|
169 | UIFileManagerTable::retranslateUi();
|
---|
170 | }
|
---|
171 |
|
---|
172 | void UIFileManagerGuestTable::readDirectory(const QString& strPath,
|
---|
173 | UICustomFileSystemItem *parent, bool isStartDir /*= false*/)
|
---|
174 | {
|
---|
175 | if (!parent)
|
---|
176 | return;
|
---|
177 |
|
---|
178 | CGuestDirectory directory;
|
---|
179 | QVector<KDirectoryOpenFlag> flag;
|
---|
180 | flag.push_back(KDirectoryOpenFlag_None);
|
---|
181 |
|
---|
182 | directory = m_comGuestSession.DirectoryOpen(UIPathOperations::sanitize(strPath), /*aFilter*/ "", flag);
|
---|
183 | if (!m_comGuestSession.isOk())
|
---|
184 | {
|
---|
185 | emit sigLogOutput(UIErrorString::formatErrorInfo(m_comGuestSession), FileManagerLogType_Error);
|
---|
186 | return;
|
---|
187 | }
|
---|
188 |
|
---|
189 | parent->setIsOpened(true);
|
---|
190 | if (directory.isOk())
|
---|
191 | {
|
---|
192 | CFsObjInfo fsInfo = directory.Read();
|
---|
193 | QMap<QString, UICustomFileSystemItem*> fileObjects;
|
---|
194 |
|
---|
195 | while (fsInfo.isOk())
|
---|
196 | {
|
---|
197 | if (fsInfo.GetName() != "." && fsInfo.GetName() != "..")
|
---|
198 | {
|
---|
199 | QVector<QVariant> data;
|
---|
200 | QDateTime changeTime = QDateTime::fromMSecsSinceEpoch(fsInfo.GetChangeTime()/RT_NS_1MS);
|
---|
201 | KFsObjType fsObjectType = fileType(fsInfo);
|
---|
202 | UICustomFileSystemItem *item = new UICustomFileSystemItem(fsInfo.GetName(), parent, fsObjectType);
|
---|
203 | if (!item)
|
---|
204 | continue;
|
---|
205 | item->setData(static_cast<qulonglong>(fsInfo.GetObjectSize()), UICustomFileSystemModelColumn_Size);
|
---|
206 | item->setData(changeTime, UICustomFileSystemModelColumn_ChangeTime);
|
---|
207 | item->setData(fsInfo.GetUserName(), UICustomFileSystemModelColumn_Owner);
|
---|
208 | item->setData(permissionString(fsInfo), UICustomFileSystemModelColumn_Permissions);
|
---|
209 | item->setPath(UIPathOperations::removeTrailingDelimiters(UIPathOperations::mergePaths(strPath, fsInfo.GetName())));
|
---|
210 | item->setIsOpened(false);
|
---|
211 | item->setIsHidden(isFileObjectHidden(fsInfo));
|
---|
212 | fileObjects.insert(fsInfo.GetName(), item);
|
---|
213 | /* @todo. We will need to wait a fully implemented SymlinkRead function
|
---|
214 | * to be able to handle sym links properly: */
|
---|
215 | // QString path = UIPathOperations::mergePaths(strPath, fsInfo.GetName());
|
---|
216 | // QVector<KSymlinkReadFlag> aFlags;
|
---|
217 | // printf("%s %s %s\n", qPrintable(fsInfo.GetName()), qPrintable(path),
|
---|
218 | // qPrintable(m_comGuestSession.SymlinkRead(path, aFlags)));
|
---|
219 | }
|
---|
220 | fsInfo = directory.Read();
|
---|
221 | }
|
---|
222 | checkDotDot(fileObjects, parent, isStartDir);
|
---|
223 | }
|
---|
224 | directory.Close();
|
---|
225 | }
|
---|
226 |
|
---|
227 | void UIFileManagerGuestTable::deleteByItem(UICustomFileSystemItem *item)
|
---|
228 | {
|
---|
229 | if (!item)
|
---|
230 | return;
|
---|
231 | if (item->isUpDirectory())
|
---|
232 | return;
|
---|
233 |
|
---|
234 | if (item->isDirectory())
|
---|
235 | {
|
---|
236 | QVector<KDirectoryRemoveRecFlag> aFlags(1, KDirectoryRemoveRecFlag_ContentAndDir);
|
---|
237 | m_comGuestSession.DirectoryRemoveRecursive(item->path(), aFlags);
|
---|
238 | }
|
---|
239 | else
|
---|
240 | m_comGuestSession.FsObjRemove(item->path());
|
---|
241 | if (!m_comGuestSession.isOk())
|
---|
242 | {
|
---|
243 | emit sigLogOutput(QString(item->path()).append(" could not be deleted"), FileManagerLogType_Error);
|
---|
244 | emit sigLogOutput(UIErrorString::formatErrorInfo(m_comGuestSession), FileManagerLogType_Error);
|
---|
245 | }
|
---|
246 | }
|
---|
247 |
|
---|
248 | void UIFileManagerGuestTable::deleteByPath(const QStringList &pathList)
|
---|
249 | {
|
---|
250 | foreach (const QString &strPath, pathList)
|
---|
251 | {
|
---|
252 | CGuestFsObjInfo fileInfo = m_comGuestSession.FsObjQueryInfo(strPath, true);
|
---|
253 | KFsObjType eType = fileType(fileInfo);
|
---|
254 | if (eType == KFsObjType_File || eType == KFsObjType_Symlink)
|
---|
255 | {
|
---|
256 | m_comGuestSession.FsObjRemove(strPath);
|
---|
257 | }
|
---|
258 | else if (eType == KFsObjType_Directory)
|
---|
259 | {
|
---|
260 | QVector<KDirectoryRemoveRecFlag> aFlags(1, KDirectoryRemoveRecFlag_ContentAndDir);
|
---|
261 | m_comGuestSession.DirectoryRemoveRecursive(strPath, aFlags);
|
---|
262 | }
|
---|
263 |
|
---|
264 | }
|
---|
265 | }
|
---|
266 |
|
---|
267 | void UIFileManagerGuestTable::goToHomeDirectory()
|
---|
268 | {
|
---|
269 | if (m_comGuestSession.isNull())
|
---|
270 | return;
|
---|
271 | if (!rootItem() || rootItem()->childCount() <= 0)
|
---|
272 | return;
|
---|
273 | UICustomFileSystemItem *startDirItem = rootItem()->child(0);
|
---|
274 | if (!startDirItem)
|
---|
275 | return;
|
---|
276 |
|
---|
277 | QString userHome = UIPathOperations::sanitize(m_comGuestSession.GetUserHome());
|
---|
278 | if (!m_comGuestSession.isOk())
|
---|
279 | {
|
---|
280 | emit sigLogOutput(UIErrorString::formatErrorInfo(m_comGuestSession), FileManagerLogType_Error);
|
---|
281 | return;
|
---|
282 | }
|
---|
283 | QStringList pathList = userHome.split(UIPathOperations::delimiter, QString::SkipEmptyParts);
|
---|
284 | goIntoDirectory(UIPathOperations::pathTrail(userHome));
|
---|
285 | }
|
---|
286 |
|
---|
287 | bool UIFileManagerGuestTable::renameItem(UICustomFileSystemItem *item, QString newBaseName)
|
---|
288 | {
|
---|
289 |
|
---|
290 | if (!item || item->isUpDirectory() || newBaseName.isEmpty())
|
---|
291 | return false;
|
---|
292 | QString newPath = UIPathOperations::removeTrailingDelimiters(UIPathOperations::constructNewItemPath(item->path(), newBaseName));
|
---|
293 | QVector<KFsObjRenameFlag> aFlags(1, KFsObjRenameFlag_Replace);
|
---|
294 |
|
---|
295 | m_comGuestSession.FsObjRename(item->path(), newPath, aFlags);
|
---|
296 |
|
---|
297 | if (!m_comGuestSession.isOk())
|
---|
298 | {
|
---|
299 | emit sigLogOutput(UIErrorString::formatErrorInfo(m_comGuestSession), FileManagerLogType_Error);
|
---|
300 | return false;
|
---|
301 | }
|
---|
302 |
|
---|
303 | item->setPath(newPath);
|
---|
304 | return true;
|
---|
305 | }
|
---|
306 |
|
---|
307 | bool UIFileManagerGuestTable::createDirectory(const QString &path, const QString &directoryName)
|
---|
308 | {
|
---|
309 | QString newDirectoryPath = UIPathOperations::mergePaths(path, directoryName);
|
---|
310 | QVector<KDirectoryCreateFlag> flags(1, KDirectoryCreateFlag_None);
|
---|
311 |
|
---|
312 | m_comGuestSession.DirectoryCreate(newDirectoryPath, 0/*aMode*/, flags);
|
---|
313 |
|
---|
314 | if (!m_comGuestSession.isOk())
|
---|
315 | {
|
---|
316 | emit sigLogOutput(newDirectoryPath.append(" could not be created"), FileManagerLogType_Error);
|
---|
317 | emit sigLogOutput(UIErrorString::formatErrorInfo(m_comGuestSession), FileManagerLogType_Error);
|
---|
318 | return false;
|
---|
319 | }
|
---|
320 | emit sigLogOutput(newDirectoryPath.append(" has been created"), FileManagerLogType_Info);
|
---|
321 | return true;
|
---|
322 | }
|
---|
323 |
|
---|
324 | void UIFileManagerGuestTable::copyHostToGuest(const QStringList &hostSourcePathList,
|
---|
325 | const QString &strDestination /* = QString() */)
|
---|
326 | {
|
---|
327 | if (!checkGuestSession())
|
---|
328 | return;
|
---|
329 | QVector<QString> sourcePaths = hostSourcePathList.toVector();
|
---|
330 | QVector<QString> aFilters;
|
---|
331 | QVector<QString> aFlags;
|
---|
332 | QString strDestinationPath = strDestination;
|
---|
333 | if (strDestinationPath.isEmpty())
|
---|
334 | strDestinationPath = currentDirectoryPath();
|
---|
335 |
|
---|
336 | if (strDestinationPath.isEmpty())
|
---|
337 | {
|
---|
338 | emit sigLogOutput("No destination for copy operation", FileManagerLogType_Error);
|
---|
339 | return;
|
---|
340 | }
|
---|
341 | if (hostSourcePathList.empty())
|
---|
342 | {
|
---|
343 | emit sigLogOutput("No source for copy operation", FileManagerLogType_Error);
|
---|
344 | return;
|
---|
345 | }
|
---|
346 |
|
---|
347 | CProgress progress = m_comGuestSession.CopyToGuest(sourcePaths, aFilters, aFlags, strDestinationPath);
|
---|
348 | if (!checkGuestSession())
|
---|
349 | return;
|
---|
350 | emit sigNewFileOperation(progress);
|
---|
351 | }
|
---|
352 |
|
---|
353 | void UIFileManagerGuestTable::copyGuestToHost(const QString& hostDestinationPath)
|
---|
354 | {
|
---|
355 | if (!checkGuestSession())
|
---|
356 | return;
|
---|
357 | QVector<QString> sourcePaths = selectedItemPathList().toVector();
|
---|
358 | QVector<QString> aFilters;
|
---|
359 | QVector<QString> aFlags;
|
---|
360 |
|
---|
361 | if (hostDestinationPath.isEmpty())
|
---|
362 | {
|
---|
363 | emit sigLogOutput("No destination for copy operation", FileManagerLogType_Error);
|
---|
364 | return;
|
---|
365 | }
|
---|
366 | if (sourcePaths.empty())
|
---|
367 | {
|
---|
368 | emit sigLogOutput("No source for copy operation", FileManagerLogType_Error);
|
---|
369 | return;
|
---|
370 | }
|
---|
371 |
|
---|
372 | CProgress progress = m_comGuestSession.CopyFromGuest(sourcePaths, aFilters, aFlags, hostDestinationPath);
|
---|
373 | if (!checkGuestSession())
|
---|
374 | return;
|
---|
375 | emit sigNewFileOperation(progress);
|
---|
376 | }
|
---|
377 |
|
---|
378 | KFsObjType UIFileManagerGuestTable::fileType(const CFsObjInfo &fsInfo)
|
---|
379 | {
|
---|
380 | if (fsInfo.isNull() || !fsInfo.isOk())
|
---|
381 | return KFsObjType_Unknown;
|
---|
382 | if (fsInfo.GetType() == KFsObjType_Directory)
|
---|
383 | return KFsObjType_Directory;
|
---|
384 | else if (fsInfo.GetType() == KFsObjType_File)
|
---|
385 | return KFsObjType_File;
|
---|
386 | else if (fsInfo.GetType() == KFsObjType_Symlink)
|
---|
387 | return KFsObjType_Symlink;
|
---|
388 |
|
---|
389 | return KFsObjType_Unknown;
|
---|
390 | }
|
---|
391 |
|
---|
392 | KFsObjType UIFileManagerGuestTable::fileType(const CGuestFsObjInfo &fsInfo)
|
---|
393 | {
|
---|
394 | if (fsInfo.isNull() || !fsInfo.isOk())
|
---|
395 | return KFsObjType_Unknown;
|
---|
396 | if (fsInfo.GetType() == KFsObjType_Directory)
|
---|
397 | return KFsObjType_Directory;
|
---|
398 | else if (fsInfo.GetType() == KFsObjType_File)
|
---|
399 | return KFsObjType_File;
|
---|
400 | else if (fsInfo.GetType() == KFsObjType_Symlink)
|
---|
401 | return KFsObjType_Symlink;
|
---|
402 |
|
---|
403 | return KFsObjType_Unknown;
|
---|
404 | }
|
---|
405 |
|
---|
406 |
|
---|
407 | QString UIFileManagerGuestTable::fsObjectPropertyString()
|
---|
408 | {
|
---|
409 | QStringList selectedObjects = selectedItemPathList();
|
---|
410 | if (selectedObjects.isEmpty())
|
---|
411 | return QString();
|
---|
412 | if (selectedObjects.size() == 1)
|
---|
413 | {
|
---|
414 | if (selectedObjects.at(0).isNull())
|
---|
415 | return QString();
|
---|
416 |
|
---|
417 | CGuestFsObjInfo fileInfo = m_comGuestSession.FsObjQueryInfo(selectedObjects.at(0), false /*aFollowSymlinks*/);
|
---|
418 | if (!m_comGuestSession.isOk())
|
---|
419 | {
|
---|
420 | emit sigLogOutput(UIErrorString::formatErrorInfo(m_comGuestSession), FileManagerLogType_Error);
|
---|
421 | return QString();
|
---|
422 | }
|
---|
423 |
|
---|
424 | QStringList propertyStringList;
|
---|
425 |
|
---|
426 | /* Name: */
|
---|
427 | propertyStringList << UIFileManager::tr("<b>Name:</b> %1<br/>").arg(UIPathOperations::getObjectName(fileInfo.GetName()));
|
---|
428 |
|
---|
429 | /* Size: */
|
---|
430 | LONG64 size = fileInfo.GetObjectSize();
|
---|
431 | propertyStringList << UIFileManager::tr("<b>Size:</b> %1 bytes").arg(QString::number(size));
|
---|
432 | if (size >= UIFileManagerTable::m_iKiloByte)
|
---|
433 | propertyStringList << QString(" (%1)<br/>").arg(humanReadableSize(size));
|
---|
434 | else
|
---|
435 | propertyStringList << QString("<br/>");
|
---|
436 |
|
---|
437 | /* Allocated size: */
|
---|
438 | size = fileInfo.GetAllocatedSize();
|
---|
439 | propertyStringList << UIFileManager::tr("<b>Allocated:</b> %1 bytes").arg(QString::number(size));
|
---|
440 | if (size >= UIFileManagerTable::m_iKiloByte)
|
---|
441 | propertyStringList << QString(" (%1)<br/>").arg(humanReadableSize(size));
|
---|
442 | else
|
---|
443 | propertyStringList << QString("<br/>");
|
---|
444 |
|
---|
445 | /* Type: */
|
---|
446 | QString str;
|
---|
447 | KFsObjType const enmType = fileInfo.GetType();
|
---|
448 | switch (enmType)
|
---|
449 | {
|
---|
450 | case KFsObjType_Directory: str = UIFileManager::tr("directory"); break;
|
---|
451 | case KFsObjType_File: str = UIFileManager::tr("file"); break;
|
---|
452 | case KFsObjType_Symlink: str = UIFileManager::tr("symbolic link"); break;
|
---|
453 | case KFsObjType_DevChar: str = UIFileManager::tr("character device"); break;
|
---|
454 | case KFsObjType_DevBlock: str = UIFileManager::tr("block device"); break;
|
---|
455 | case KFsObjType_Fifo: str = UIFileManager::tr("fifo"); break;
|
---|
456 | case KFsObjType_Socket: str = UIFileManager::tr("socket"); break;
|
---|
457 | case KFsObjType_WhiteOut: str = UIFileManager::tr("whiteout"); break;
|
---|
458 | case KFsObjType_Unknown: str = UIFileManager::tr("unknown"); break;
|
---|
459 | default: str = UIFileManager::tr("illegal-value"); break;
|
---|
460 | }
|
---|
461 | propertyStringList << UIFileManager::tr("<b>Type:</b> %1<br/>").arg(str);
|
---|
462 |
|
---|
463 | /* INode number, device, link count: */
|
---|
464 | propertyStringList << UIFileManager::tr("<b>INode:</b> %1<br/>").arg(fileInfo.GetNodeId());
|
---|
465 | propertyStringList << UIFileManager::tr("<b>Device:</b> %1<br/>").arg(fileInfo.GetNodeIdDevice()); /** @todo hex */
|
---|
466 | propertyStringList << UIFileManager::tr("<b>Hardlinks:</b> %1<br/>").arg(fileInfo.GetHardLinks());
|
---|
467 |
|
---|
468 | /* Attributes: */
|
---|
469 | str = fileInfo.GetFileAttributes();
|
---|
470 | if (!str.isEmpty())
|
---|
471 | {
|
---|
472 | int offSpace = str.indexOf(' ');
|
---|
473 | if (offSpace < 0)
|
---|
474 | offSpace = str.length();
|
---|
475 | propertyStringList << UIFileManager::tr("<b>Mode:</b> %1<br/>").arg(str.left(offSpace));
|
---|
476 | propertyStringList << UIFileManager::tr("<b>Attributes:</b> %1<br/>").arg(str.mid(offSpace + 1).trimmed());
|
---|
477 | }
|
---|
478 |
|
---|
479 | /* Character/block device ID: */
|
---|
480 | ULONG uDeviceNo = fileInfo.GetDeviceNumber();
|
---|
481 | if (uDeviceNo != 0 || enmType == KFsObjType_DevChar || enmType == KFsObjType_DevBlock)
|
---|
482 | propertyStringList << UIFileManager::tr("<b>Device ID:</b> %1<br/>").arg(uDeviceNo); /** @todo hex */
|
---|
483 |
|
---|
484 | /* Owner: */
|
---|
485 | propertyStringList << UIFileManager::tr("<b>Owner:</b> %1 (%2)<br/>").
|
---|
486 | arg(fileInfo.GetUserName()).arg(fileInfo.GetUID());
|
---|
487 | propertyStringList << UIFileManager::tr("<b>Group:</b> %1 (%2)<br/>").
|
---|
488 | arg(fileInfo.GetGroupName()).arg(fileInfo.GetGID());
|
---|
489 |
|
---|
490 | /* Timestamps: */
|
---|
491 | propertyStringList << UIFileManager::tr("<b>Birth:</b> %1<br/>").
|
---|
492 | arg(QDateTime::fromMSecsSinceEpoch(fileInfo.GetBirthTime() / RT_NS_1MS).toString());
|
---|
493 | propertyStringList << UIFileManager::tr("<b>Change:</b> %1<br/>").
|
---|
494 | arg(QDateTime::fromMSecsSinceEpoch(fileInfo.GetChangeTime() / RT_NS_1MS).toString());
|
---|
495 | propertyStringList << UIFileManager::tr("<b>Modified:</b> %1<br/>").
|
---|
496 | arg(QDateTime::fromMSecsSinceEpoch(fileInfo.GetModificationTime() / RT_NS_1MS).toString());
|
---|
497 | propertyStringList << UIFileManager::tr("<b>Access:</b> %1<br/>").
|
---|
498 | arg(QDateTime::fromMSecsSinceEpoch(fileInfo.GetAccessTime() / RT_NS_1MS).toString());
|
---|
499 |
|
---|
500 | /* Join the list elements into a single string seperated by empty string: */
|
---|
501 | return propertyStringList.join(QString());
|
---|
502 | }
|
---|
503 |
|
---|
504 | int fileCount = 0;
|
---|
505 | int directoryCount = 0;
|
---|
506 | ULONG64 totalSize = 0;
|
---|
507 |
|
---|
508 | for(int i = 0; i < selectedObjects.size(); ++i)
|
---|
509 | {
|
---|
510 | CGuestFsObjInfo fileInfo = m_comGuestSession.FsObjQueryInfo(selectedObjects.at(0), true);
|
---|
511 | if (!m_comGuestSession.isOk())
|
---|
512 | {
|
---|
513 | emit sigLogOutput(UIErrorString::formatErrorInfo(m_comGuestSession), FileManagerLogType_Error);
|
---|
514 | continue;
|
---|
515 | }
|
---|
516 |
|
---|
517 | KFsObjType type = fileType(fileInfo);
|
---|
518 |
|
---|
519 | if (type == KFsObjType_File)
|
---|
520 | ++fileCount;
|
---|
521 | if (type == KFsObjType_Directory)
|
---|
522 | ++directoryCount;
|
---|
523 | totalSize += fileInfo.GetObjectSize();
|
---|
524 | }
|
---|
525 | QStringList propertyStringList;
|
---|
526 | propertyStringList << UIFileManager::tr("<b>Selected:</b> %1 files and %2 directories<br/>").
|
---|
527 | arg(QString::number(fileCount)).arg(QString::number(directoryCount));
|
---|
528 | propertyStringList << UIFileManager::tr("<b>Size (non-recursive):</b> %1 bytes").arg(QString::number(totalSize));
|
---|
529 | if (totalSize >= m_iKiloByte)
|
---|
530 | propertyStringList << QString(" (%1)").arg(humanReadableSize(totalSize));
|
---|
531 |
|
---|
532 | return propertyStringList.join(QString());;
|
---|
533 | }
|
---|
534 |
|
---|
535 | void UIFileManagerGuestTable::showProperties()
|
---|
536 | {
|
---|
537 | if (m_comGuestSession.isNull())
|
---|
538 | return;
|
---|
539 | QString fsPropertyString = fsObjectPropertyString();
|
---|
540 | if (fsPropertyString.isEmpty())
|
---|
541 | return;
|
---|
542 |
|
---|
543 | m_pPropertiesDialog = new UIPropertiesDialog(this);
|
---|
544 | if (!m_pPropertiesDialog)
|
---|
545 | return;
|
---|
546 |
|
---|
547 | QStringList selectedObjects = selectedItemPathList();
|
---|
548 | if (selectedObjects.size() == 0)
|
---|
549 | return;
|
---|
550 | //UIGuestDirectoryDiskUsageComputer *directoryThread = 0;
|
---|
551 |
|
---|
552 | /* if the selection include a directory or it is a multiple selection the create a worker thread
|
---|
553 | to compute total size of the selection (recusively) */
|
---|
554 | // bool createWorkerThread = (selectedObjects.size() > 1);
|
---|
555 | // if (!createWorkerThread &&
|
---|
556 | // fileType(m_comGuestSession.FsObjQueryInfo(selectedObjects[0], true)) == KFsObjType_Directory)
|
---|
557 | // createWorkerThread = true;
|
---|
558 | // if (createWorkerThread)
|
---|
559 | // {
|
---|
560 | // directoryThread = new UIGuestDirectoryDiskUsageComputer(this, selectedObjects, m_comGuestSession);
|
---|
561 | // if (directoryThread)
|
---|
562 | // {
|
---|
563 | // connect(directoryThread, &UIGuestDirectoryDiskUsageComputer::sigResultUpdated,
|
---|
564 | // this, &UIFileManagerGuestTable::sltReceiveDirectoryStatistics/*, Qt::DirectConnection*/);
|
---|
565 | // directoryThread->start();
|
---|
566 | // }
|
---|
567 | // }
|
---|
568 |
|
---|
569 | m_pPropertiesDialog->setWindowTitle(UIFileManager::tr("Properties"));
|
---|
570 | m_pPropertiesDialog->setPropertyText(fsPropertyString);
|
---|
571 | m_pPropertiesDialog->execute();
|
---|
572 |
|
---|
573 | // if (directoryThread)
|
---|
574 | // {
|
---|
575 | // if (directoryThread->isRunning())
|
---|
576 | // directoryThread->stopRecursion();
|
---|
577 | // disconnect(directoryThread, &UIGuestDirectoryDiskUsageComputer::sigResultUpdated,
|
---|
578 | // this, &UIFileManagerGuestTable::sltReceiveDirectoryStatistics/*, Qt::DirectConnection*/);
|
---|
579 | // }
|
---|
580 |
|
---|
581 |
|
---|
582 | delete m_pPropertiesDialog;
|
---|
583 | m_pPropertiesDialog = 0;
|
---|
584 |
|
---|
585 | }
|
---|
586 |
|
---|
587 | void UIFileManagerGuestTable::determineDriveLetters()
|
---|
588 | {
|
---|
589 | if (m_comGuestSession.isNull())
|
---|
590 | return;
|
---|
591 | KPathStyle pathStyle = m_comGuestSession.GetPathStyle();
|
---|
592 | if (pathStyle != KPathStyle_DOS)
|
---|
593 | return;
|
---|
594 |
|
---|
595 | /** @todo Currently API lacks a way to query windows drive letters.
|
---|
596 | * so we enumarate them by using CGuestSession::DirectoryExists() */
|
---|
597 | m_driveLetterList.clear();
|
---|
598 | for (int i = 'A'; i <= 'Z'; ++i)
|
---|
599 | {
|
---|
600 | QString path((char)i);
|
---|
601 | path += ":/";
|
---|
602 | bool exists = m_comGuestSession.DirectoryExists(path, false /* aFollowSymlinks */);
|
---|
603 | if (exists)
|
---|
604 | m_driveLetterList.push_back(path);
|
---|
605 | }
|
---|
606 | }
|
---|
607 |
|
---|
608 | void UIFileManagerGuestTable::determinePathSeparator()
|
---|
609 | {
|
---|
610 | if (m_comGuestSession.isNull())
|
---|
611 | return;
|
---|
612 | KPathStyle pathStyle = m_comGuestSession.GetPathStyle();
|
---|
613 | if (pathStyle == KPathStyle_DOS)
|
---|
614 | setPathSeparator(UIPathOperations::dosDelimiter);
|
---|
615 | }
|
---|
616 |
|
---|
617 | void UIFileManagerGuestTable::prepareToolbar()
|
---|
618 | {
|
---|
619 | if (m_pToolBar && m_pActionPool)
|
---|
620 | {
|
---|
621 | m_pToolBar->addAction(m_pActionPool->action(UIActionIndex_M_FileManager_S_Guest_GoUp));
|
---|
622 | m_pToolBar->addAction(m_pActionPool->action(UIActionIndex_M_FileManager_S_Guest_GoHome));
|
---|
623 | m_pToolBar->addAction(m_pActionPool->action(UIActionIndex_M_FileManager_S_Guest_Refresh));
|
---|
624 | m_pToolBar->addSeparator();
|
---|
625 | m_pToolBar->addAction(m_pActionPool->action(UIActionIndex_M_FileManager_S_Guest_Delete));
|
---|
626 | m_pToolBar->addAction(m_pActionPool->action(UIActionIndex_M_FileManager_S_Guest_Rename));
|
---|
627 | m_pToolBar->addAction(m_pActionPool->action(UIActionIndex_M_FileManager_S_Guest_CreateNewDirectory));
|
---|
628 |
|
---|
629 | m_pToolBar->addAction(m_pActionPool->action(UIActionIndex_M_FileManager_S_Guest_Copy));
|
---|
630 | m_pToolBar->addAction(m_pActionPool->action(UIActionIndex_M_FileManager_S_Guest_Cut));
|
---|
631 | m_pToolBar->addAction(m_pActionPool->action(UIActionIndex_M_FileManager_S_Guest_Paste));
|
---|
632 | m_pToolBar->addSeparator();
|
---|
633 | m_pToolBar->addAction(m_pActionPool->action(UIActionIndex_M_FileManager_S_Guest_SelectAll));
|
---|
634 | m_pToolBar->addAction(m_pActionPool->action(UIActionIndex_M_FileManager_S_Guest_InvertSelection));
|
---|
635 | m_pToolBar->addSeparator();
|
---|
636 | m_pToolBar->addAction(m_pActionPool->action(UIActionIndex_M_FileManager_S_Guest_ShowProperties));
|
---|
637 | m_selectionDependentActions.insert(m_pActionPool->action(UIActionIndex_M_FileManager_S_Guest_Delete));
|
---|
638 | m_selectionDependentActions.insert(m_pActionPool->action(UIActionIndex_M_FileManager_S_Guest_Rename));
|
---|
639 | m_selectionDependentActions.insert(m_pActionPool->action(UIActionIndex_M_FileManager_S_Guest_Copy));
|
---|
640 | m_selectionDependentActions.insert(m_pActionPool->action(UIActionIndex_M_FileManager_S_Guest_Cut));
|
---|
641 | m_selectionDependentActions.insert(m_pActionPool->action(UIActionIndex_M_FileManager_S_Guest_ShowProperties));
|
---|
642 |
|
---|
643 | /* Hide these actions for now until we have a suitable guest-to-guest copy function: */
|
---|
644 | m_pActionPool->action(UIActionIndex_M_FileManager_S_Guest_Copy)->setVisible(false);
|
---|
645 | m_pActionPool->action(UIActionIndex_M_FileManager_S_Guest_Cut)->setVisible(false);
|
---|
646 | m_pActionPool->action(UIActionIndex_M_FileManager_S_Guest_Paste)->setVisible(false);
|
---|
647 | }
|
---|
648 | setSelectionDependentActionsEnabled(false);
|
---|
649 | setPasteActionEnabled(false);
|
---|
650 | }
|
---|
651 |
|
---|
652 | void UIFileManagerGuestTable::createFileViewContextMenu(const QWidget *pWidget, const QPoint &point)
|
---|
653 | {
|
---|
654 | if (!pWidget)
|
---|
655 | return;
|
---|
656 |
|
---|
657 | QMenu menu;
|
---|
658 | menu.addAction(m_pActionPool->action(UIActionIndex_M_FileManager_S_Guest_GoUp));
|
---|
659 |
|
---|
660 | menu.addAction(m_pActionPool->action(UIActionIndex_M_FileManager_S_Guest_GoHome));
|
---|
661 | menu.addAction(m_pActionPool->action(UIActionIndex_M_FileManager_S_Guest_Refresh));
|
---|
662 | menu.addSeparator();
|
---|
663 | menu.addAction(m_pActionPool->action(UIActionIndex_M_FileManager_S_Guest_Delete));
|
---|
664 | menu.addAction(m_pActionPool->action(UIActionIndex_M_FileManager_S_Guest_Rename));
|
---|
665 | menu.addAction(m_pActionPool->action(UIActionIndex_M_FileManager_S_Guest_CreateNewDirectory));
|
---|
666 | menu.addSeparator();
|
---|
667 | menu.addAction(m_pActionPool->action(UIActionIndex_M_FileManager_S_Guest_Copy));
|
---|
668 | menu.addAction(m_pActionPool->action(UIActionIndex_M_FileManager_S_Guest_Cut));
|
---|
669 | menu.addAction(m_pActionPool->action(UIActionIndex_M_FileManager_S_Guest_Paste));
|
---|
670 | menu.addSeparator();
|
---|
671 | menu.addAction(m_pActionPool->action(UIActionIndex_M_FileManager_S_Guest_SelectAll));
|
---|
672 | menu.addAction(m_pActionPool->action(UIActionIndex_M_FileManager_S_Guest_InvertSelection));
|
---|
673 | menu.addSeparator();
|
---|
674 | menu.addAction(m_pActionPool->action(UIActionIndex_M_FileManager_S_Guest_ShowProperties));
|
---|
675 | menu.exec(pWidget->mapToGlobal(point));
|
---|
676 | }
|
---|
677 |
|
---|
678 | void UIFileManagerGuestTable::setPasteActionEnabled(bool fEnabled)
|
---|
679 | {
|
---|
680 | m_pActionPool->action(UIActionIndex_M_FileManager_S_Guest_Paste)->setEnabled(fEnabled);
|
---|
681 | }
|
---|
682 |
|
---|
683 | void UIFileManagerGuestTable::pasteCutCopiedObjects()
|
---|
684 | {
|
---|
685 | }
|
---|
686 |
|
---|
687 | void UIFileManagerGuestTable::prepareActionConnections()
|
---|
688 | {
|
---|
689 | connect(m_pActionPool->action(UIActionIndex_M_FileManager_S_Guest_GoUp), &QAction::triggered,
|
---|
690 | this, &UIFileManagerTable::sltGoUp);
|
---|
691 | connect(m_pActionPool->action(UIActionIndex_M_FileManager_S_Guest_GoHome), &QAction::triggered,
|
---|
692 | this, &UIFileManagerTable::sltGoHome);
|
---|
693 | connect(m_pActionPool->action(UIActionIndex_M_FileManager_S_Guest_Refresh), &QAction::triggered,
|
---|
694 | this, &UIFileManagerTable::sltRefresh);
|
---|
695 | connect(m_pActionPool->action(UIActionIndex_M_FileManager_S_Guest_Delete), &QAction::triggered,
|
---|
696 | this, &UIFileManagerTable::sltDelete);
|
---|
697 | connect(m_pActionPool->action(UIActionIndex_M_FileManager_S_Guest_Rename), &QAction::triggered,
|
---|
698 | this, &UIFileManagerTable::sltRename);
|
---|
699 | connect(m_pActionPool->action(UIActionIndex_M_FileManager_S_Guest_Copy), &QAction::triggered,
|
---|
700 | this, &UIFileManagerTable::sltCopy);
|
---|
701 | connect(m_pActionPool->action(UIActionIndex_M_FileManager_S_Guest_Cut), &QAction::triggered,
|
---|
702 | this, &UIFileManagerTable::sltCut);
|
---|
703 | connect(m_pActionPool->action(UIActionIndex_M_FileManager_S_Guest_Paste), &QAction::triggered,
|
---|
704 | this, &UIFileManagerTable::sltPaste);
|
---|
705 | connect(m_pActionPool->action(UIActionIndex_M_FileManager_S_Guest_SelectAll), &QAction::triggered,
|
---|
706 | this, &UIFileManagerTable::sltSelectAll);
|
---|
707 | connect(m_pActionPool->action(UIActionIndex_M_FileManager_S_Guest_InvertSelection), &QAction::triggered,
|
---|
708 | this, &UIFileManagerTable::sltInvertSelection);
|
---|
709 | connect(m_pActionPool->action(UIActionIndex_M_FileManager_S_Guest_ShowProperties), &QAction::triggered,
|
---|
710 | this, &UIFileManagerTable::sltShowProperties);
|
---|
711 | connect(m_pActionPool->action(UIActionIndex_M_FileManager_S_Guest_CreateNewDirectory), &QAction::triggered,
|
---|
712 | this, &UIFileManagerTable::sltCreateNewDirectory);
|
---|
713 | }
|
---|
714 |
|
---|
715 | bool UIFileManagerGuestTable::checkGuestSession()
|
---|
716 | {
|
---|
717 | if (!m_comGuestSession.isOk())
|
---|
718 | {
|
---|
719 | emit sigLogOutput(UIErrorString::formatErrorInfo(m_comGuestSession), FileManagerLogType_Error);
|
---|
720 | return false;
|
---|
721 | }
|
---|
722 | return true;
|
---|
723 | }
|
---|
724 |
|
---|
725 | QString UIFileManagerGuestTable::permissionString(const CFsObjInfo &fsInfo)
|
---|
726 | {
|
---|
727 | /* Attributes: */
|
---|
728 | QString strAttributes = fsInfo.GetFileAttributes();
|
---|
729 |
|
---|
730 | if (strAttributes.isEmpty())
|
---|
731 | return strAttributes;
|
---|
732 |
|
---|
733 | int offSpace = strAttributes.indexOf(' ');
|
---|
734 | if (offSpace < 0)
|
---|
735 | offSpace = strAttributes.length();
|
---|
736 | return strAttributes.left(offSpace);
|
---|
737 | }
|
---|
738 |
|
---|
739 | bool UIFileManagerGuestTable::isFileObjectHidden(const CFsObjInfo &fsInfo)
|
---|
740 | {
|
---|
741 | QString strAttributes = fsInfo.GetFileAttributes();
|
---|
742 |
|
---|
743 | if (strAttributes.isEmpty())
|
---|
744 | return false;
|
---|
745 |
|
---|
746 | int offSpace = strAttributes.indexOf(' ');
|
---|
747 | if (offSpace < 0)
|
---|
748 | offSpace = strAttributes.length();
|
---|
749 | QString strRight(strAttributes.mid(offSpace + 1).trimmed());
|
---|
750 |
|
---|
751 | if (strRight.indexOf('H', Qt::CaseSensitive) == -1)
|
---|
752 | return false;
|
---|
753 | return true;
|
---|
754 | }
|
---|
755 |
|
---|
756 | #include "UIFileManagerGuestTable.moc"
|
---|