[71025] | 1 | /* $Id: UIFileManagerHostTable.cpp 106061 2024-09-16 14:03:52Z vboxsync $ */
|
---|
| 2 | /** @file
|
---|
[76177] | 3 | * VBox Qt GUI - UIFileManagerHostTable class implementation.
|
---|
[71025] | 4 | */
|
---|
| 5 |
|
---|
| 6 | /*
|
---|
[106061] | 7 | * Copyright (C) 2016-2024 Oracle and/or its affiliates.
|
---|
[71025] | 8 | *
|
---|
[96407] | 9 | * This file is part of VirtualBox base platform packages, as
|
---|
| 10 | * available from https://www.virtualbox.org.
|
---|
| 11 | *
|
---|
| 12 | * This program is free software; you can redistribute it and/or
|
---|
| 13 | * modify it under the terms of the GNU General Public License
|
---|
| 14 | * as published by the Free Software Foundation, in version 3 of the
|
---|
| 15 | * License.
|
---|
| 16 | *
|
---|
| 17 | * This program is distributed in the hope that it will be useful, but
|
---|
| 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
| 20 | * General Public License for more details.
|
---|
| 21 | *
|
---|
| 22 | * You should have received a copy of the GNU General Public License
|
---|
| 23 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
| 24 | *
|
---|
| 25 | * SPDX-License-Identifier: GPL-3.0-only
|
---|
[71025] | 26 | */
|
---|
| 27 |
|
---|
| 28 | /* Qt includes: */
|
---|
[76606] | 29 | #include <QAction>
|
---|
| 30 | #include <QDateTime>
|
---|
| 31 | #include <QDir>
|
---|
[71025] | 32 |
|
---|
| 33 | /* GUI includes: */
|
---|
[76606] | 34 | #include "QILabel.h"
|
---|
| 35 | #include "UIActionPool.h"
|
---|
[102363] | 36 | #include "UICommon.h"
|
---|
[76606] | 37 | #include "UIFileManager.h"
|
---|
[100302] | 38 | #include "UIFileTableNavigationWidget.h"
|
---|
[102485] | 39 | #include "UIFileSystemModel.h"
|
---|
[76606] | 40 | #include "UIFileManagerHostTable.h"
|
---|
| 41 | #include "UIPathOperations.h"
|
---|
[86233] | 42 | #include "QIToolBar.h"
|
---|
[104228] | 43 | #include "UITranslationEventListener.h"
|
---|
[75057] | 44 |
|
---|
[104229] | 45 |
|
---|
[71505] | 46 | /*********************************************************************************************************************************
|
---|
| 47 | * UIHostDirectoryDiskUsageComputer definition. *
|
---|
| 48 | *********************************************************************************************************************************/
|
---|
| 49 |
|
---|
| 50 | /** Open directories recursively and sum the disk usage. Don't block the GUI thread while doing this */
|
---|
[71563] | 51 | class UIHostDirectoryDiskUsageComputer : public UIDirectoryDiskUsageComputer
|
---|
[71505] | 52 | {
|
---|
| 53 | Q_OBJECT;
|
---|
| 54 |
|
---|
| 55 | public:
|
---|
| 56 |
|
---|
[71531] | 57 | UIHostDirectoryDiskUsageComputer(QObject *parent, QStringList strStartPath);
|
---|
[71505] | 58 |
|
---|
[71563] | 59 | protected:
|
---|
[71505] | 60 |
|
---|
[93990] | 61 | virtual void directoryStatisticsRecursive(const QString &path, UIDirectoryStatistics &statistics) RT_OVERRIDE;
|
---|
[71505] | 62 | };
|
---|
| 63 |
|
---|
| 64 |
|
---|
| 65 | /*********************************************************************************************************************************
|
---|
| 66 | * UIHostDirectoryDiskUsageComputer implementation. *
|
---|
| 67 | *********************************************************************************************************************************/
|
---|
| 68 |
|
---|
[71531] | 69 | UIHostDirectoryDiskUsageComputer::UIHostDirectoryDiskUsageComputer(QObject *parent, QStringList pathList)
|
---|
[71563] | 70 | :UIDirectoryDiskUsageComputer(parent, pathList)
|
---|
[71505] | 71 | {
|
---|
| 72 | }
|
---|
| 73 |
|
---|
| 74 | void UIHostDirectoryDiskUsageComputer::directoryStatisticsRecursive(const QString &path, UIDirectoryStatistics &statistics)
|
---|
| 75 | {
|
---|
[71645] | 76 | /* Prevent modification of the continue flag while reading: */
|
---|
| 77 | m_mutex.lock();
|
---|
| 78 | /* Check if m_fOkToContinue is set to false. if so just end recursion: */
|
---|
| 79 | if (!isOkToContinue())
|
---|
| 80 | {
|
---|
| 81 | m_mutex.unlock();
|
---|
| 82 | return;
|
---|
| 83 | }
|
---|
| 84 | m_mutex.unlock();
|
---|
[71505] | 85 |
|
---|
[71531] | 86 | QFileInfo fileInfo(path);
|
---|
| 87 | if (!fileInfo.exists())
|
---|
| 88 | return;
|
---|
| 89 | /* if the object is a file or a symlink then read the size and return: */
|
---|
| 90 | if (fileInfo.isFile())
|
---|
| 91 | {
|
---|
| 92 | statistics.m_totalSize += fileInfo.size();
|
---|
| 93 | ++statistics.m_uFileCount;
|
---|
| 94 | sigResultUpdated(statistics);
|
---|
| 95 | return;
|
---|
| 96 | }
|
---|
| 97 | else if (fileInfo.isSymLink())
|
---|
| 98 | {
|
---|
| 99 | statistics.m_totalSize += fileInfo.size();
|
---|
| 100 | ++statistics.m_uSymlinkCount;
|
---|
| 101 | sigResultUpdated(statistics);
|
---|
| 102 | return;
|
---|
| 103 | }
|
---|
[71505] | 104 |
|
---|
[71531] | 105 | /* if it is a directory then read the content: */
|
---|
| 106 | QDir dir(path);
|
---|
| 107 | if (!dir.exists())
|
---|
| 108 | return;
|
---|
[71505] | 109 |
|
---|
| 110 | QFileInfoList entryList = dir.entryInfoList();
|
---|
| 111 | for (int i = 0; i < entryList.size(); ++i)
|
---|
| 112 | {
|
---|
| 113 | const QFileInfo &entryInfo = entryList.at(i);
|
---|
[72086] | 114 | if (entryInfo.baseName().isEmpty() || entryInfo.baseName() == "." ||
|
---|
[102485] | 115 | entryInfo.baseName() == UIFileSystemModel::strUpDirectoryString)
|
---|
[71505] | 116 | continue;
|
---|
| 117 | statistics.m_totalSize += entryInfo.size();
|
---|
| 118 | if (entryInfo.isSymLink())
|
---|
| 119 | statistics.m_uSymlinkCount++;
|
---|
| 120 | else if(entryInfo.isFile())
|
---|
| 121 | statistics.m_uFileCount++;
|
---|
| 122 | else if (entryInfo.isDir())
|
---|
| 123 | {
|
---|
| 124 | statistics.m_uDirectoryCount++;
|
---|
| 125 | directoryStatisticsRecursive(entryInfo.absoluteFilePath(), statistics);
|
---|
| 126 | }
|
---|
| 127 | }
|
---|
[71531] | 128 | sigResultUpdated(statistics);
|
---|
[71505] | 129 | }
|
---|
| 130 |
|
---|
| 131 |
|
---|
| 132 | /*********************************************************************************************************************************
|
---|
[76177] | 133 | * UIFileManagerHostTable implementation. *
|
---|
[71505] | 134 | *********************************************************************************************************************************/
|
---|
| 135 |
|
---|
[76177] | 136 | UIFileManagerHostTable::UIFileManagerHostTable(UIActionPool *pActionPool, QWidget *pParent /* = 0 */)
|
---|
| 137 | :UIFileManagerTable(pActionPool, pParent)
|
---|
[102418] | 138 | , m_pModifierActionSeparator(0)
|
---|
[71169] | 139 | {
|
---|
[102378] | 140 | setModelFileSystem(isWindowsFileSystem());
|
---|
[71185] | 141 | initializeFileTree();
|
---|
[75148] | 142 | prepareToolbar();
|
---|
| 143 | prepareActionConnections();
|
---|
[78146] | 144 | determinePathSeparator();
|
---|
[104228] | 145 | sltRetranslateUI();
|
---|
| 146 | connect(&translationEventListener(), &UITranslationEventListener::sigRetranslateUI,
|
---|
| 147 | this, &UIFileManagerHostTable::sltRetranslateUI);
|
---|
[71169] | 148 | }
|
---|
| 149 |
|
---|
[102485] | 150 | /* static */ bool UIFileManagerHostTable::scanDirectory(const QString& strPath, UIFileSystemItem *parent,
|
---|
| 151 | QMap<QString, UIFileSystemItem*> &fileObjects)
|
---|
[76429] | 152 | {
|
---|
| 153 |
|
---|
[102441] | 154 | QDir directory(UIPathOperations::addTrailingDelimiters(strPath));
|
---|
[76429] | 155 | /* For some reason when this filter is applied, folder content QDir::entryInfoList()
|
---|
| 156 | returns an empty list: */
|
---|
| 157 | /*directory.setFilter(QDir::NoDotAndDotDot);*/
|
---|
[102418] | 158 | if (!directory.exists() || !directory.isReadable())
|
---|
| 159 | return false;
|
---|
[76621] | 160 | QFileInfoList entries = directory.entryInfoList(QDir::Hidden|QDir::AllEntries|QDir::NoDotAndDotDot);
|
---|
[102481] | 161 |
|
---|
[102456] | 162 | parent->setIsOpened(true);
|
---|
[76429] | 163 | for (int i = 0; i < entries.size(); ++i)
|
---|
| 164 | {
|
---|
[76495] | 165 | const QFileInfo &fileInfo = entries.at(i);
|
---|
[102485] | 166 | UIFileSystemItem *item = new UIFileSystemItem(fileInfo.fileName(), parent, fileType(fileInfo));
|
---|
[76429] | 167 | if (!item)
|
---|
| 168 | continue;
|
---|
[76495] | 169 |
|
---|
[102485] | 170 | item->setData(fileInfo.size(), UIFileSystemModelData_Size);
|
---|
| 171 | item->setData(fileInfo.lastModified(), UIFileSystemModelData_ChangeTime);
|
---|
| 172 | item->setData(fileInfo.owner(), UIFileSystemModelData_Owner);
|
---|
| 173 | item->setData(permissionString(fileInfo.permissions()), UIFileSystemModelData_Permissions);
|
---|
[100418] | 174 |
|
---|
[76429] | 175 | /* if the item is a symlink set the target path and
|
---|
| 176 | check the target if it is a directory: */
|
---|
| 177 | if (fileInfo.isSymLink()) /** @todo No symlinks here on windows, while fsObjectPropertyString() does see them. RTDirReadEx works wrt symlinks, btw. */
|
---|
| 178 | {
|
---|
| 179 | item->setTargetPath(fileInfo.symLinkTarget());
|
---|
| 180 | item->setIsSymLinkToADirectory(QFileInfo(fileInfo.symLinkTarget()).isDir());
|
---|
| 181 | }
|
---|
[76626] | 182 | item->setIsHidden(fileInfo.isHidden());
|
---|
[76429] | 183 | fileObjects.insert(fileInfo.fileName(), item);
|
---|
| 184 | item->setIsOpened(false);
|
---|
| 185 | }
|
---|
[102418] | 186 | return true;
|
---|
[76429] | 187 | }
|
---|
| 188 |
|
---|
[104228] | 189 | void UIFileManagerHostTable::sltRetranslateUI()
|
---|
[71191] | 190 | {
|
---|
| 191 | if (m_pLocationLabel)
|
---|
[92587] | 192 | m_pLocationLabel->setText(UIFileManager::tr("Host File System:"));
|
---|
[92765] | 193 | m_strTableName = UIFileManager::tr("Host");
|
---|
[104228] | 194 | UIFileManagerTable::sltRetranslateUI();
|
---|
[71191] | 195 | }
|
---|
| 196 |
|
---|
[76177] | 197 | void UIFileManagerHostTable::prepareToolbar()
|
---|
[71421] | 198 | {
|
---|
[75136] | 199 | if (m_pToolBar && m_pActionPool)
|
---|
| 200 | {
|
---|
[100302] | 201 | m_pToolBar->addAction(m_pActionPool->action(UIActionIndex_M_FileManager_S_Host_GoBackward));
|
---|
| 202 | m_pToolBar->addAction(m_pActionPool->action(UIActionIndex_M_FileManager_S_Host_GoForward));
|
---|
[76177] | 203 | m_pToolBar->addAction(m_pActionPool->action(UIActionIndex_M_FileManager_S_Host_GoUp));
|
---|
| 204 | m_pToolBar->addAction(m_pActionPool->action(UIActionIndex_M_FileManager_S_Host_GoHome));
|
---|
| 205 | m_pToolBar->addAction(m_pActionPool->action(UIActionIndex_M_FileManager_S_Host_Refresh));
|
---|
[102418] | 206 |
|
---|
| 207 | m_pModifierActionSeparator = m_pToolBar->addSeparator();
|
---|
[76177] | 208 | m_pToolBar->addAction(m_pActionPool->action(UIActionIndex_M_FileManager_S_Host_Delete));
|
---|
| 209 | m_pToolBar->addAction(m_pActionPool->action(UIActionIndex_M_FileManager_S_Host_Rename));
|
---|
| 210 | m_pToolBar->addAction(m_pActionPool->action(UIActionIndex_M_FileManager_S_Host_CreateNewDirectory));
|
---|
[102418] | 211 |
|
---|
[77871] | 212 | m_pToolBar->addAction(m_pActionPool->action(UIActionIndex_M_FileManager_S_Host_Copy));
|
---|
| 213 | m_pToolBar->addAction(m_pActionPool->action(UIActionIndex_M_FileManager_S_Host_Cut));
|
---|
| 214 | m_pToolBar->addAction(m_pActionPool->action(UIActionIndex_M_FileManager_S_Host_Paste));
|
---|
[75136] | 215 | m_pToolBar->addSeparator();
|
---|
[76177] | 216 | m_pToolBar->addAction(m_pActionPool->action(UIActionIndex_M_FileManager_S_Host_SelectAll));
|
---|
| 217 | m_pToolBar->addAction(m_pActionPool->action(UIActionIndex_M_FileManager_S_Host_InvertSelection));
|
---|
[75136] | 218 | m_pToolBar->addSeparator();
|
---|
[76177] | 219 | m_pToolBar->addAction(m_pActionPool->action(UIActionIndex_M_FileManager_S_Host_ShowProperties));
|
---|
[75162] | 220 |
|
---|
[76177] | 221 | m_selectionDependentActions.insert(m_pActionPool->action(UIActionIndex_M_FileManager_S_Host_Delete));
|
---|
| 222 | m_selectionDependentActions.insert(m_pActionPool->action(UIActionIndex_M_FileManager_S_Host_Rename));
|
---|
| 223 | m_selectionDependentActions.insert(m_pActionPool->action(UIActionIndex_M_FileManager_S_Host_ShowProperties));
|
---|
[77871] | 224 |
|
---|
| 225 | /* Hide cut, copy, and paste for now. We will implement those
|
---|
| 226 | when we have an API for host file operations: */
|
---|
| 227 | m_pActionPool->action(UIActionIndex_M_FileManager_S_Host_Copy)->setVisible(false);
|
---|
| 228 | m_pActionPool->action(UIActionIndex_M_FileManager_S_Host_Cut)->setVisible(false);
|
---|
| 229 | m_pActionPool->action(UIActionIndex_M_FileManager_S_Host_Paste)->setVisible(false);
|
---|
[75136] | 230 | }
|
---|
[75202] | 231 | setSelectionDependentActionsEnabled(false);
|
---|
| 232 | }
|
---|
| 233 |
|
---|
[76177] | 234 | void UIFileManagerHostTable::createFileViewContextMenu(const QWidget *pWidget, const QPoint &point)
|
---|
[75202] | 235 | {
|
---|
| 236 | if (!pWidget)
|
---|
| 237 | return;
|
---|
| 238 |
|
---|
| 239 | QMenu menu;
|
---|
[76177] | 240 | menu.addAction(m_pActionPool->action(UIActionIndex_M_FileManager_S_Host_GoUp));
|
---|
[75202] | 241 |
|
---|
[76177] | 242 | menu.addAction(m_pActionPool->action(UIActionIndex_M_FileManager_S_Host_GoHome));
|
---|
| 243 | menu.addAction(m_pActionPool->action(UIActionIndex_M_FileManager_S_Host_Refresh));
|
---|
[75202] | 244 | menu.addSeparator();
|
---|
[76177] | 245 | menu.addAction(m_pActionPool->action(UIActionIndex_M_FileManager_S_Host_Delete));
|
---|
| 246 | menu.addAction(m_pActionPool->action(UIActionIndex_M_FileManager_S_Host_Rename));
|
---|
| 247 | menu.addAction(m_pActionPool->action(UIActionIndex_M_FileManager_S_Host_CreateNewDirectory));
|
---|
[75202] | 248 | // menu.addSeparator();
|
---|
[77871] | 249 | menu.addAction(m_pActionPool->action(UIActionIndex_M_FileManager_S_Host_Copy));
|
---|
| 250 | menu.addAction(m_pActionPool->action(UIActionIndex_M_FileManager_S_Host_Cut));
|
---|
| 251 | menu.addAction(m_pActionPool->action(UIActionIndex_M_FileManager_S_Host_Paste));
|
---|
[75202] | 252 | menu.addSeparator();
|
---|
[76177] | 253 | menu.addAction(m_pActionPool->action(UIActionIndex_M_FileManager_S_Host_SelectAll));
|
---|
| 254 | menu.addAction(m_pActionPool->action(UIActionIndex_M_FileManager_S_Host_InvertSelection));
|
---|
[75202] | 255 | menu.addSeparator();
|
---|
[76177] | 256 | menu.addAction(m_pActionPool->action(UIActionIndex_M_FileManager_S_Host_ShowProperties));
|
---|
[75202] | 257 | menu.exec(pWidget->mapToGlobal(point));
|
---|
[71421] | 258 | }
|
---|
| 259 |
|
---|
[100301] | 260 | void UIFileManagerHostTable::toggleForwardBackwardActions()
|
---|
| 261 | {
|
---|
[100324] | 262 | if (!m_pNavigationWidget)
|
---|
| 263 | return;
|
---|
[100302] | 264 | if (m_pActionPool->action(UIActionIndex_M_FileManager_S_Host_GoForward))
|
---|
[100324] | 265 | m_pActionPool->action(UIActionIndex_M_FileManager_S_Host_GoForward)->setEnabled(m_pNavigationWidget->canGoForward());
|
---|
[100302] | 266 | if (m_pActionPool->action(UIActionIndex_M_FileManager_S_Host_GoBackward))
|
---|
[100324] | 267 | m_pActionPool->action(UIActionIndex_M_FileManager_S_Host_GoBackward)->setEnabled(m_pNavigationWidget->canGoBackward());
|
---|
[100301] | 268 | }
|
---|
| 269 |
|
---|
[102378] | 270 | bool UIFileManagerHostTable::isWindowsFileSystem() const
|
---|
[102363] | 271 | {
|
---|
| 272 | return uiCommon().hostOperatingSystem().contains("windows", Qt::CaseInsensitive);
|
---|
| 273 | }
|
---|
| 274 |
|
---|
[102485] | 275 | bool UIFileManagerHostTable::readDirectory(const QString& strPath, UIFileSystemItem *parent, bool isStartDir /*= false*/)
|
---|
[71181] | 276 | {
|
---|
[71185] | 277 | if (!parent)
|
---|
[102418] | 278 | return false;
|
---|
[71181] | 279 |
|
---|
[102485] | 280 | QMap<QString, UIFileSystemItem*> fileObjects;
|
---|
[102418] | 281 | if (!scanDirectory(strPath, parent, fileObjects))
|
---|
| 282 | return false;
|
---|
[76429] | 283 | checkDotDot(fileObjects, parent, isStartDir);
|
---|
[102418] | 284 | return true;
|
---|
[71181] | 285 | }
|
---|
[71185] | 286 |
|
---|
[102485] | 287 | void UIFileManagerHostTable::deleteByItem(UIFileSystemItem *item)
|
---|
[71201] | 288 | {
|
---|
[71362] | 289 | if (item->isUpDirectory())
|
---|
| 290 | return;
|
---|
[71234] | 291 | if (!item->isDirectory())
|
---|
| 292 | {
|
---|
[75610] | 293 | QDir itemToDelete;
|
---|
[102393] | 294 | itemToDelete.remove(UIPathOperations::removeTrailingDelimiters(item->path()));
|
---|
[71234] | 295 | }
|
---|
| 296 | QDir itemToDelete(item->path());
|
---|
| 297 | itemToDelete.setFilter(QDir::NoDotAndDotDot);
|
---|
| 298 | /* Try to delete item recursively (in case of directories).
|
---|
| 299 | note that this is no good way of deleting big directory
|
---|
| 300 | trees. We need a better error reporting and a kind of progress
|
---|
| 301 | indicator: */
|
---|
| 302 | /** @todo replace this recursive delete by a better implementation: */
|
---|
| 303 | bool deleteSuccess = itemToDelete.removeRecursively();
|
---|
| 304 |
|
---|
[92587] | 305 | if (!deleteSuccess)
|
---|
[92733] | 306 | emit sigLogOutput(QString(item->path()).append(" could not be deleted"), m_strTableName, FileManagerLogType_Error);
|
---|
[71201] | 307 | }
|
---|
| 308 |
|
---|
[76177] | 309 | void UIFileManagerHostTable::goToHomeDirectory()
|
---|
[71255] | 310 | {
|
---|
[76309] | 311 | if (!rootItem() || rootItem()->childCount() <= 0)
|
---|
[71255] | 312 | return;
|
---|
[102485] | 313 | UIFileSystemItem *startDirItem = rootItem()->child(0);
|
---|
[71255] | 314 | if (!startDirItem)
|
---|
| 315 | return;
|
---|
| 316 |
|
---|
[71439] | 317 | QString userHome = UIPathOperations::sanitize(QDir::homePath());
|
---|
[71832] | 318 | goIntoDirectory(UIPathOperations::pathTrail(userHome));
|
---|
[71255] | 319 | }
|
---|
| 320 |
|
---|
[102485] | 321 | bool UIFileManagerHostTable::renameItem(UIFileSystemItem *item, const QString &strOldPath)
|
---|
[71255] | 322 | {
|
---|
[100408] | 323 | if (!item || item->isUpDirectory())
|
---|
[71258] | 324 | return false;
|
---|
[71274] | 325 | QDir tempDir;
|
---|
[100408] | 326 | if (tempDir.rename(strOldPath, item->path()))
|
---|
[71274] | 327 | return true;
|
---|
[100408] | 328 |
|
---|
[71274] | 329 | return false;
|
---|
[71255] | 330 | }
|
---|
[71258] | 331 |
|
---|
[76177] | 332 | bool UIFileManagerHostTable::createDirectory(const QString &path, const QString &directoryName)
|
---|
[71269] | 333 | {
|
---|
| 334 | QDir parentDir(path);
|
---|
| 335 | if (!parentDir.mkdir(directoryName))
|
---|
| 336 | {
|
---|
[92733] | 337 | emit sigLogOutput(UIPathOperations::mergePaths(path, directoryName).append(" could not be created"), m_strTableName, FileManagerLogType_Error);
|
---|
[71269] | 338 | return false;
|
---|
| 339 | }
|
---|
[71258] | 340 |
|
---|
[71269] | 341 | return true;
|
---|
| 342 | }
|
---|
| 343 |
|
---|
[92913] | 344 | /* static */
|
---|
| 345 | KFsObjType UIFileManagerHostTable::fileType(const QFileInfo &fsInfo)
|
---|
[71350] | 346 | {
|
---|
| 347 | if (!fsInfo.exists())
|
---|
[76300] | 348 | return KFsObjType_Unknown;
|
---|
[71350] | 349 | /* first check if it is symlink becacuse for Qt
|
---|
| 350 | being smylin and directory/file is not mutually exclusive: */
|
---|
| 351 | if (fsInfo.isSymLink())
|
---|
[76300] | 352 | return KFsObjType_Symlink;
|
---|
[71350] | 353 | else if (fsInfo.isFile())
|
---|
[76300] | 354 | return KFsObjType_File;
|
---|
[71350] | 355 | else if (fsInfo.isDir())
|
---|
[76300] | 356 | return KFsObjType_Directory;
|
---|
| 357 | return KFsObjType_Unknown;
|
---|
[71350] | 358 | }
|
---|
| 359 |
|
---|
[92913] | 360 | /* static */
|
---|
| 361 | KFsObjType UIFileManagerHostTable::fileType(const QString &strPath)
|
---|
| 362 | {
|
---|
| 363 | return fileType(QFileInfo(strPath));
|
---|
| 364 | }
|
---|
| 365 |
|
---|
[76177] | 366 | QString UIFileManagerHostTable::fsObjectPropertyString()
|
---|
[71380] | 367 | {
|
---|
| 368 | QStringList selectedObjects = selectedItemPathList();
|
---|
| 369 | if (selectedObjects.isEmpty())
|
---|
| 370 | return QString();
|
---|
| 371 | if (selectedObjects.size() == 1)
|
---|
| 372 | {
|
---|
| 373 | if (selectedObjects.at(0).isNull())
|
---|
| 374 | return QString();
|
---|
| 375 | QFileInfo fileInfo(selectedObjects.at(0));
|
---|
| 376 | if (!fileInfo.exists())
|
---|
| 377 | return QString();
|
---|
[75682] | 378 | QStringList propertyStringList;
|
---|
[71380] | 379 | /* Name: */
|
---|
[76177] | 380 | propertyStringList << UIFileManager::tr("<b>Name:</b> %1<br/>").arg(fileInfo.fileName());
|
---|
[71380] | 381 | /* Size: */
|
---|
[76177] | 382 | propertyStringList << UIFileManager::tr("<b>Size:</b> %1 bytes").arg(QString::number(fileInfo.size()));
|
---|
[71421] | 383 | if (fileInfo.size() >= m_iKiloByte)
|
---|
[75682] | 384 | propertyStringList << QString(" (%1)").arg(humanReadableSize(fileInfo.size()));
|
---|
| 385 | propertyStringList << "<br/>";
|
---|
[71380] | 386 | /* Type: */
|
---|
[76177] | 387 | propertyStringList << UIFileManager::tr("<b>Type:</b> %1<br/>").arg(fileTypeString(fileType(fileInfo)));
|
---|
[71380] | 388 | /* Creation Date: */
|
---|
[94007] | 389 | propertyStringList << UIFileManager::tr("<b>Created:</b> %1<br/>").arg(fileInfo.birthTime().toString());
|
---|
[71380] | 390 | /* Last Modification Date: */
|
---|
[76177] | 391 | propertyStringList << UIFileManager::tr("<b>Modified:</b> %1<br/>").arg(fileInfo.lastModified().toString());
|
---|
[71380] | 392 | /* Owner: */
|
---|
[76177] | 393 | propertyStringList << UIFileManager::tr("<b>Owner:</b> %1").arg(fileInfo.owner());
|
---|
[71380] | 394 |
|
---|
[92900] | 395 | return propertyStringList.join(QString());
|
---|
[71380] | 396 | }
|
---|
[71531] | 397 |
|
---|
[71537] | 398 | int fileCount = 0;
|
---|
| 399 | int directoryCount = 0;
|
---|
| 400 | ULONG64 totalSize = 0;
|
---|
[71531] | 401 |
|
---|
[71537] | 402 | for(int i = 0; i < selectedObjects.size(); ++i)
|
---|
| 403 | {
|
---|
| 404 | QFileInfo fileInfo(selectedObjects.at(i));
|
---|
| 405 | if (!fileInfo.exists())
|
---|
| 406 | continue;
|
---|
| 407 | if (fileInfo.isFile())
|
---|
| 408 | ++fileCount;
|
---|
| 409 | if (fileInfo.isDir())
|
---|
| 410 | ++directoryCount;
|
---|
| 411 | totalSize += fileInfo.size();
|
---|
| 412 | }
|
---|
[75682] | 413 | QStringList propertyStringList;
|
---|
[76177] | 414 | propertyStringList << UIFileManager::tr("<b>Selected:</b> %1 files and %2 directories<br/>").
|
---|
[75682] | 415 | arg(QString::number(fileCount)).arg(QString::number(directoryCount));
|
---|
[76177] | 416 | propertyStringList << UIFileManager::tr("<b>Size:</b> %1 bytes").arg(QString::number(totalSize));
|
---|
[71537] | 417 | if (totalSize >= m_iKiloByte)
|
---|
[75682] | 418 | propertyStringList << QString(" (%1)").arg(humanReadableSize(totalSize));
|
---|
[71531] | 419 |
|
---|
[75682] | 420 | return propertyStringList.join(QString());
|
---|
[71380] | 421 | }
|
---|
[71412] | 422 |
|
---|
[76177] | 423 | void UIFileManagerHostTable::showProperties()
|
---|
[71412] | 424 | {
|
---|
[71505] | 425 | qRegisterMetaType<UIDirectoryStatistics>();
|
---|
| 426 | QString fsPropertyString = fsObjectPropertyString();
|
---|
| 427 | if (fsPropertyString.isEmpty())
|
---|
[71412] | 428 | return;
|
---|
[71505] | 429 | if (!m_pPropertiesDialog)
|
---|
[75184] | 430 | m_pPropertiesDialog = new UIPropertiesDialog(this);
|
---|
| 431 | if (!m_pPropertiesDialog)
|
---|
[71505] | 432 | return;
|
---|
| 433 |
|
---|
| 434 | UIHostDirectoryDiskUsageComputer *directoryThread = 0;
|
---|
| 435 |
|
---|
| 436 | QStringList selectedObjects = selectedItemPathList();
|
---|
[71531] | 437 | if ((selectedObjects.size() == 1 && QFileInfo(selectedObjects.at(0)).isDir())
|
---|
| 438 | || selectedObjects.size() > 1)
|
---|
[71412] | 439 | {
|
---|
[71531] | 440 | directoryThread = new UIHostDirectoryDiskUsageComputer(this, selectedObjects);
|
---|
| 441 | if (directoryThread)
|
---|
[71412] | 442 | {
|
---|
[71531] | 443 | connect(directoryThread, &UIHostDirectoryDiskUsageComputer::sigResultUpdated,
|
---|
[76177] | 444 | this, &UIFileManagerHostTable::sltReceiveDirectoryStatistics/*, Qt::DirectConnection*/);
|
---|
[71531] | 445 | directoryThread->start();
|
---|
[71412] | 446 | }
|
---|
| 447 | }
|
---|
[71505] | 448 | m_pPropertiesDialog->setWindowTitle("Properties");
|
---|
| 449 | m_pPropertiesDialog->setPropertyText(fsPropertyString);
|
---|
| 450 | m_pPropertiesDialog->execute();
|
---|
| 451 | if (directoryThread)
|
---|
| 452 | {
|
---|
| 453 | if (directoryThread->isRunning())
|
---|
| 454 | directoryThread->stopRecursion();
|
---|
| 455 | disconnect(directoryThread, &UIHostDirectoryDiskUsageComputer::sigResultUpdated,
|
---|
[76177] | 456 | this, &UIFileManagerHostTable::sltReceiveDirectoryStatistics/*, Qt::DirectConnection*/);
|
---|
[75184] | 457 | directoryThread->wait();
|
---|
[71505] | 458 | }
|
---|
[71412] | 459 | }
|
---|
[71505] | 460 |
|
---|
[76177] | 461 | void UIFileManagerHostTable::determineDriveLetters()
|
---|
[71832] | 462 | {
|
---|
[71852] | 463 | QFileInfoList drive = QDir::drives();
|
---|
[75184] | 464 | m_driveLetterList.clear();
|
---|
[71852] | 465 | for (int i = 0; i < drive.size(); ++i)
|
---|
| 466 | {
|
---|
[71861] | 467 | if (UIPathOperations::doesPathStartWithDriveLetter(drive[i].filePath()))
|
---|
| 468 | m_driveLetterList.push_back(drive[i].filePath());
|
---|
[71852] | 469 | }
|
---|
[71832] | 470 | }
|
---|
| 471 |
|
---|
[78146] | 472 | void UIFileManagerHostTable::determinePathSeparator()
|
---|
| 473 | {
|
---|
| 474 | setPathSeparator(QDir::separator());
|
---|
| 475 | }
|
---|
| 476 |
|
---|
[76429] | 477 | /* static */QString UIFileManagerHostTable::permissionString(QFileDevice::Permissions permissions)
|
---|
[71861] | 478 | {
|
---|
| 479 | QString strPermissions;
|
---|
| 480 | if (permissions & QFileDevice::ReadOwner)
|
---|
| 481 | strPermissions += 'r';
|
---|
| 482 | else
|
---|
| 483 | strPermissions += '-';
|
---|
| 484 |
|
---|
| 485 | if (permissions & QFileDevice::WriteOwner)
|
---|
| 486 | strPermissions += 'w';
|
---|
| 487 | else
|
---|
| 488 | strPermissions += '-';
|
---|
| 489 |
|
---|
| 490 | if (permissions & QFileDevice::ExeOwner)
|
---|
| 491 | strPermissions += 'x';
|
---|
| 492 | else
|
---|
| 493 | strPermissions += '-';
|
---|
| 494 |
|
---|
| 495 | if (permissions & QFileDevice::ReadGroup)
|
---|
| 496 | strPermissions += 'r';
|
---|
| 497 | else
|
---|
| 498 | strPermissions += '-';
|
---|
| 499 |
|
---|
| 500 | if (permissions & QFileDevice::WriteGroup)
|
---|
| 501 | strPermissions += 'w';
|
---|
| 502 | else
|
---|
| 503 | strPermissions += '-';
|
---|
| 504 |
|
---|
| 505 | if (permissions & QFileDevice::ExeGroup)
|
---|
| 506 | strPermissions += 'x';
|
---|
| 507 | else
|
---|
| 508 | strPermissions += '-';
|
---|
| 509 |
|
---|
| 510 | if (permissions & QFileDevice::ReadOther)
|
---|
| 511 | strPermissions += 'r';
|
---|
| 512 | else
|
---|
| 513 | strPermissions += '-';
|
---|
| 514 |
|
---|
| 515 | if (permissions & QFileDevice::WriteOther)
|
---|
| 516 | strPermissions += 'w';
|
---|
| 517 | else
|
---|
| 518 | strPermissions += '-';
|
---|
| 519 |
|
---|
| 520 | if (permissions & QFileDevice::ExeOther)
|
---|
| 521 | strPermissions += 'x';
|
---|
| 522 | else
|
---|
| 523 | strPermissions += '-';
|
---|
| 524 | return strPermissions;
|
---|
| 525 | }
|
---|
| 526 |
|
---|
[76177] | 527 | void UIFileManagerHostTable::prepareActionConnections()
|
---|
[75184] | 528 | {
|
---|
[76177] | 529 | connect(m_pActionPool->action(UIActionIndex_M_FileManager_S_Host_GoUp), &QAction::triggered,
|
---|
| 530 | this, &UIFileManagerTable::sltGoUp);
|
---|
| 531 | connect(m_pActionPool->action(UIActionIndex_M_FileManager_S_Host_GoHome), &QAction::triggered,
|
---|
| 532 | this, &UIFileManagerTable::sltGoHome);
|
---|
[100304] | 533 | connect(m_pActionPool->action(UIActionIndex_M_FileManager_S_Host_GoForward), &QAction::triggered,
|
---|
| 534 | this, &UIFileManagerTable::sltGoForward);
|
---|
| 535 | connect(m_pActionPool->action(UIActionIndex_M_FileManager_S_Host_GoBackward), &QAction::triggered,
|
---|
| 536 | this, &UIFileManagerTable::sltGoBackward);
|
---|
[76177] | 537 | connect(m_pActionPool->action(UIActionIndex_M_FileManager_S_Host_Refresh), &QAction::triggered,
|
---|
| 538 | this, &UIFileManagerTable::sltRefresh);
|
---|
| 539 | connect(m_pActionPool->action(UIActionIndex_M_FileManager_S_Host_Delete), &QAction::triggered,
|
---|
| 540 | this, &UIFileManagerTable::sltDelete);
|
---|
| 541 | connect(m_pActionPool->action(UIActionIndex_M_FileManager_S_Host_Rename), &QAction::triggered,
|
---|
| 542 | this, &UIFileManagerTable::sltRename);
|
---|
| 543 | connect(m_pActionPool->action(UIActionIndex_M_FileManager_S_Host_Copy), &QAction::triggered,
|
---|
| 544 | this, &UIFileManagerTable::sltCopy);
|
---|
| 545 | connect(m_pActionPool->action(UIActionIndex_M_FileManager_S_Host_Cut), &QAction::triggered,
|
---|
| 546 | this, &UIFileManagerTable::sltCut);
|
---|
| 547 | connect(m_pActionPool->action(UIActionIndex_M_FileManager_S_Host_Paste), &QAction::triggered,
|
---|
| 548 | this, &UIFileManagerTable::sltPaste);
|
---|
| 549 | connect(m_pActionPool->action(UIActionIndex_M_FileManager_S_Host_SelectAll), &QAction::triggered,
|
---|
| 550 | this, &UIFileManagerTable::sltSelectAll);
|
---|
| 551 | connect(m_pActionPool->action(UIActionIndex_M_FileManager_S_Host_InvertSelection), &QAction::triggered,
|
---|
| 552 | this, &UIFileManagerTable::sltInvertSelection);
|
---|
| 553 | connect(m_pActionPool->action(UIActionIndex_M_FileManager_S_Host_ShowProperties), &QAction::triggered,
|
---|
| 554 | this, &UIFileManagerTable::sltShowProperties);
|
---|
| 555 | connect(m_pActionPool->action(UIActionIndex_M_FileManager_S_Host_CreateNewDirectory), &QAction::triggered,
|
---|
| 556 | this, &UIFileManagerTable::sltCreateNewDirectory);
|
---|
[75184] | 557 | }
|
---|
| 558 |
|
---|
[76177] | 559 | #include "UIFileManagerHostTable.moc"
|
---|