1 | /* $Id: UIGuestControlFileTable.cpp 75903 2018-12-03 13:03:37Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox Qt GUI - UIGuestControlFileTable class implementation.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2016-2018 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 | #ifdef VBOX_WITH_PRECOMPILED_HEADERS
|
---|
19 | # include <precomp.h>
|
---|
20 | #else /* !VBOX_WITH_PRECOMPILED_HEADERS */
|
---|
21 |
|
---|
22 | /* Qt includes: */
|
---|
23 | # include <QAction>
|
---|
24 | # include <QComboBox>
|
---|
25 | # include <QCheckBox>
|
---|
26 | # include <QDateTime>
|
---|
27 | # include <QDir>
|
---|
28 | # include <QHeaderView>
|
---|
29 | # include <QItemDelegate>
|
---|
30 | # include <QGridLayout>
|
---|
31 | # include <QMenu>
|
---|
32 | # include <QSortFilterProxyModel>
|
---|
33 | # include <QTextEdit>
|
---|
34 | # include <QPushButton>
|
---|
35 |
|
---|
36 | /* GUI includes: */
|
---|
37 | # include "QIDialog.h"
|
---|
38 | # include "QIDialogButtonBox.h"
|
---|
39 | # include "QILabel.h"
|
---|
40 | # include "QILineEdit.h"
|
---|
41 | # include "QIMessageBox.h"
|
---|
42 | # include "UIActionPool.h"
|
---|
43 | # include "UIErrorString.h"
|
---|
44 | # include "UIGuestFileTable.h"
|
---|
45 | # include "UIIconPool.h"
|
---|
46 | # include "UIGuestControlFileTable.h"
|
---|
47 | # include "UIGuestControlFileManager.h"
|
---|
48 | # include "UIGuestControlFileModel.h"
|
---|
49 | # include "UIToolBar.h"
|
---|
50 |
|
---|
51 | /* COM includes: */
|
---|
52 | # include "CFsObjInfo.h"
|
---|
53 | # include "CGuestFsObjInfo.h"
|
---|
54 | # include "CGuestDirectory.h"
|
---|
55 | # include "CProgress.h"
|
---|
56 |
|
---|
57 | #endif /* !VBOX_WITH_PRECOMPILED_HEADERS */
|
---|
58 |
|
---|
59 |
|
---|
60 |
|
---|
61 | /*********************************************************************************************************************************
|
---|
62 | * UIGuestControlFileView definition. *
|
---|
63 | *********************************************************************************************************************************/
|
---|
64 |
|
---|
65 | /** Using QITableView causes the following problem when I click on the table items
|
---|
66 | Qt WARNING: Cannot creat accessible child interface for object: UIGuestControlFileView.....
|
---|
67 | so for now subclass QTableView */
|
---|
68 | class UIGuestControlFileView : public QTableView
|
---|
69 | {
|
---|
70 |
|
---|
71 | Q_OBJECT;
|
---|
72 |
|
---|
73 | signals:
|
---|
74 |
|
---|
75 | void sigSelectionChanged(const QItemSelection & selected, const QItemSelection & deselected);
|
---|
76 |
|
---|
77 | public:
|
---|
78 |
|
---|
79 | UIGuestControlFileView(QWidget * parent = 0);
|
---|
80 | bool hasSelection() const;
|
---|
81 |
|
---|
82 | protected:
|
---|
83 |
|
---|
84 | virtual void selectionChanged(const QItemSelection & selected, const QItemSelection & deselected) /*override */;
|
---|
85 |
|
---|
86 | private:
|
---|
87 |
|
---|
88 | void configure();
|
---|
89 | QWidget *m_pParent;
|
---|
90 | };
|
---|
91 |
|
---|
92 |
|
---|
93 | /*********************************************************************************************************************************
|
---|
94 | * UIFileDelegate definition. *
|
---|
95 | *********************************************************************************************************************************/
|
---|
96 | /** A QItemDelegate child class to disable dashed lines drawn around selected cells in QTableViews */
|
---|
97 | class UIFileDelegate : public QItemDelegate
|
---|
98 | {
|
---|
99 |
|
---|
100 | Q_OBJECT;
|
---|
101 |
|
---|
102 | protected:
|
---|
103 |
|
---|
104 | virtual void drawFocus ( QPainter * /*painter*/, const QStyleOptionViewItem & /*option*/, const QRect & /*rect*/ ) const {}
|
---|
105 |
|
---|
106 | };
|
---|
107 |
|
---|
108 |
|
---|
109 | /*********************************************************************************************************************************
|
---|
110 | * UStringInputDialog definition. *
|
---|
111 | *********************************************************************************************************************************/
|
---|
112 |
|
---|
113 | /** A QIDialog child including a line edit whose text exposed when the dialog is accepted */
|
---|
114 | class UIStringInputDialog : public QIDialog
|
---|
115 | {
|
---|
116 |
|
---|
117 | Q_OBJECT;
|
---|
118 |
|
---|
119 | public:
|
---|
120 |
|
---|
121 | UIStringInputDialog(QWidget *pParent = 0, Qt::WindowFlags flags = 0);
|
---|
122 | QString getString() const;
|
---|
123 |
|
---|
124 | private:
|
---|
125 |
|
---|
126 | QILineEdit *m_pLineEdit;
|
---|
127 |
|
---|
128 | };
|
---|
129 |
|
---|
130 |
|
---|
131 | /*********************************************************************************************************************************
|
---|
132 | * UIFileDeleteConfirmationDialog definition. *
|
---|
133 | *********************************************************************************************************************************/
|
---|
134 |
|
---|
135 | /** A QIDialog child including a line edit whose text exposed when the dialog is accepted */
|
---|
136 | class UIFileDeleteConfirmationDialog : public QIDialog
|
---|
137 | {
|
---|
138 |
|
---|
139 | Q_OBJECT;
|
---|
140 |
|
---|
141 | public:
|
---|
142 |
|
---|
143 | UIFileDeleteConfirmationDialog(QWidget *pParent = 0, Qt::WindowFlags flags = 0);
|
---|
144 | /** Returns whether m_pAskNextTimeCheckBox is checked or not. */
|
---|
145 | bool askDeleteConfirmationNextTime() const;
|
---|
146 |
|
---|
147 | private:
|
---|
148 |
|
---|
149 | QCheckBox *m_pAskNextTimeCheckBox;
|
---|
150 | QILabel *m_pQuestionLabel;
|
---|
151 |
|
---|
152 | };
|
---|
153 |
|
---|
154 |
|
---|
155 | /*********************************************************************************************************************************
|
---|
156 | * UIHostDirectoryDiskUsageComputer implementation. *
|
---|
157 | *********************************************************************************************************************************/
|
---|
158 |
|
---|
159 | UIDirectoryDiskUsageComputer::UIDirectoryDiskUsageComputer(QObject *parent, QStringList pathList)
|
---|
160 | :QThread(parent)
|
---|
161 | , m_pathList(pathList)
|
---|
162 | , m_fOkToContinue(true)
|
---|
163 | {
|
---|
164 | }
|
---|
165 |
|
---|
166 | void UIDirectoryDiskUsageComputer::run()
|
---|
167 | {
|
---|
168 | for (int i = 0; i < m_pathList.size(); ++i)
|
---|
169 | directoryStatisticsRecursive(m_pathList[i], m_resultStatistics);
|
---|
170 | }
|
---|
171 |
|
---|
172 | void UIDirectoryDiskUsageComputer::stopRecursion()
|
---|
173 | {
|
---|
174 | m_mutex.lock();
|
---|
175 | m_fOkToContinue = false;
|
---|
176 | m_mutex.unlock();
|
---|
177 | }
|
---|
178 |
|
---|
179 | bool UIDirectoryDiskUsageComputer::isOkToContinue() const
|
---|
180 | {
|
---|
181 | return m_fOkToContinue;
|
---|
182 | }
|
---|
183 |
|
---|
184 |
|
---|
185 | /*********************************************************************************************************************************
|
---|
186 | * UIPathOperations implementation. *
|
---|
187 | *********************************************************************************************************************************/
|
---|
188 |
|
---|
189 | const QChar UIPathOperations::delimiter = QChar('/');
|
---|
190 | const QChar UIPathOperations::dosDelimiter = QChar('\\');
|
---|
191 |
|
---|
192 | /* static */ QString UIPathOperations::removeMultipleDelimiters(const QString &path)
|
---|
193 | {
|
---|
194 | QString newPath(path);
|
---|
195 | QString doubleDelimiter(2, delimiter);
|
---|
196 |
|
---|
197 | while (newPath.contains(doubleDelimiter) && !newPath.isEmpty())
|
---|
198 | newPath = newPath.replace(doubleDelimiter, delimiter);
|
---|
199 | return newPath;
|
---|
200 | }
|
---|
201 |
|
---|
202 | /* static */ QString UIPathOperations::removeTrailingDelimiters(const QString &path)
|
---|
203 | {
|
---|
204 | if (path.isNull() || path.isEmpty())
|
---|
205 | return QString();
|
---|
206 | QString newPath(path);
|
---|
207 | /* Make sure for we dont have any trailing delimiters: */
|
---|
208 | while (newPath.length() > 1 && newPath.at(newPath.length() - 1) == UIPathOperations::delimiter)
|
---|
209 | newPath.chop(1);
|
---|
210 | return newPath;
|
---|
211 | }
|
---|
212 |
|
---|
213 | /* static */ QString UIPathOperations::addTrailingDelimiters(const QString &path)
|
---|
214 | {
|
---|
215 | if (path.isNull() || path.isEmpty())
|
---|
216 | return QString();
|
---|
217 | QString newPath(path);
|
---|
218 | while (newPath.length() > 1 && newPath.at(newPath.length() - 1) != UIPathOperations::delimiter)
|
---|
219 | newPath += UIPathOperations::delimiter;
|
---|
220 | return newPath;
|
---|
221 | }
|
---|
222 |
|
---|
223 | /* static */ QString UIPathOperations::addStartDelimiter(const QString &path)
|
---|
224 | {
|
---|
225 | if (path.isEmpty())
|
---|
226 | return QString(path);
|
---|
227 | QString newPath(path);
|
---|
228 |
|
---|
229 | if (doesPathStartWithDriveLetter(newPath))
|
---|
230 | {
|
---|
231 | if (newPath.at(newPath.length() - 1) != delimiter)
|
---|
232 | newPath += delimiter;
|
---|
233 | return newPath;
|
---|
234 | }
|
---|
235 | if (newPath.at(0) != delimiter)
|
---|
236 | newPath.insert(0, delimiter);
|
---|
237 | return newPath;
|
---|
238 | }
|
---|
239 |
|
---|
240 | /* static */ QString UIPathOperations::sanitize(const QString &path)
|
---|
241 | {
|
---|
242 | //return addStartDelimiter(removeTrailingDelimiters(removeMultipleDelimiters(path)));
|
---|
243 | QString newPath = addStartDelimiter(removeTrailingDelimiters(removeMultipleDelimiters(path))).replace(dosDelimiter, delimiter);
|
---|
244 | return newPath;
|
---|
245 | }
|
---|
246 |
|
---|
247 | /* static */ QString UIPathOperations::mergePaths(const QString &path, const QString &baseName)
|
---|
248 | {
|
---|
249 | QString newBase(baseName);
|
---|
250 | newBase = newBase.remove(delimiter);
|
---|
251 |
|
---|
252 | /* make sure we have one and only one trailing '/': */
|
---|
253 | QString newPath(sanitize(path));
|
---|
254 | if(newPath.isEmpty())
|
---|
255 | newPath = delimiter;
|
---|
256 | if(newPath.at(newPath.length() - 1) != delimiter)
|
---|
257 | newPath += UIPathOperations::delimiter;
|
---|
258 | newPath += newBase;
|
---|
259 | return sanitize(newPath);
|
---|
260 | }
|
---|
261 |
|
---|
262 | /* static */ QString UIPathOperations::getObjectName(const QString &path)
|
---|
263 | {
|
---|
264 | if (path.length() <= 1)
|
---|
265 | return QString(path);
|
---|
266 |
|
---|
267 | QString strTemp(sanitize(path));
|
---|
268 | if (strTemp.length() < 2)
|
---|
269 | return strTemp;
|
---|
270 | int lastSlashPosition = strTemp.lastIndexOf(UIPathOperations::delimiter);
|
---|
271 | if (lastSlashPosition == -1)
|
---|
272 | return QString();
|
---|
273 | return strTemp.right(strTemp.length() - lastSlashPosition - 1);
|
---|
274 | }
|
---|
275 |
|
---|
276 | /* static */ QString UIPathOperations::getPathExceptObjectName(const QString &path)
|
---|
277 | {
|
---|
278 | if (path.length() <= 1)
|
---|
279 | return QString(path);
|
---|
280 |
|
---|
281 | QString strTemp(sanitize(path));
|
---|
282 | int lastSlashPosition = strTemp.lastIndexOf(UIPathOperations::delimiter);
|
---|
283 | if (lastSlashPosition == -1)
|
---|
284 | return QString();
|
---|
285 | return strTemp.left(lastSlashPosition + 1);
|
---|
286 | }
|
---|
287 |
|
---|
288 | /* static */ QString UIPathOperations::constructNewItemPath(const QString &previousPath, const QString &newBaseName)
|
---|
289 | {
|
---|
290 | if (previousPath.length() <= 1)
|
---|
291 | return QString(previousPath);
|
---|
292 | return sanitize(mergePaths(getPathExceptObjectName(previousPath), newBaseName));
|
---|
293 | }
|
---|
294 |
|
---|
295 | /* static */ QStringList UIPathOperations::pathTrail(const QString &path)
|
---|
296 | {
|
---|
297 | QStringList pathList = path.split(UIPathOperations::delimiter, QString::SkipEmptyParts);
|
---|
298 | if (!pathList.isEmpty() && doesPathStartWithDriveLetter(pathList[0]))
|
---|
299 | {
|
---|
300 | pathList[0] = addTrailingDelimiters(pathList[0]);
|
---|
301 | }
|
---|
302 | return pathList;
|
---|
303 | }
|
---|
304 |
|
---|
305 | /* static */ bool UIPathOperations::doesPathStartWithDriveLetter(const QString &path)
|
---|
306 | {
|
---|
307 | if (path.length() < 2)
|
---|
308 | return false;
|
---|
309 | /* search for ':' with the path: */
|
---|
310 | if (!path[0].isLetter())
|
---|
311 | return false;
|
---|
312 | if (path[1] != ':')
|
---|
313 | return false;
|
---|
314 | return true;
|
---|
315 | }
|
---|
316 |
|
---|
317 |
|
---|
318 | /*********************************************************************************************************************************
|
---|
319 | * UIGuestControlFileView implementation. *
|
---|
320 | *********************************************************************************************************************************/
|
---|
321 |
|
---|
322 | UIGuestControlFileView::UIGuestControlFileView(QWidget *parent)
|
---|
323 | :QTableView(parent)
|
---|
324 | , m_pParent(parent)
|
---|
325 | {
|
---|
326 | configure();
|
---|
327 | }
|
---|
328 |
|
---|
329 | void UIGuestControlFileView::configure()
|
---|
330 | {
|
---|
331 | setContextMenuPolicy(Qt::CustomContextMenu);
|
---|
332 | setShowGrid(false);
|
---|
333 | setSelectionBehavior(QAbstractItemView::SelectRows);
|
---|
334 | verticalHeader()->setVisible(false);
|
---|
335 | setEditTriggers(QAbstractItemView::NoEditTriggers);
|
---|
336 | /* Minimize the row height: */
|
---|
337 | verticalHeader()->setDefaultSectionSize(verticalHeader()->minimumSectionSize());
|
---|
338 | setAlternatingRowColors(true);
|
---|
339 | installEventFilter(m_pParent);
|
---|
340 | }
|
---|
341 |
|
---|
342 | bool UIGuestControlFileView::hasSelection() const
|
---|
343 | {
|
---|
344 | QItemSelectionModel *pSelectionModel = selectionModel();
|
---|
345 | if (!pSelectionModel)
|
---|
346 | return false;
|
---|
347 | return pSelectionModel->hasSelection();
|
---|
348 | }
|
---|
349 |
|
---|
350 | void UIGuestControlFileView::selectionChanged(const QItemSelection & selected, const QItemSelection & deselected)
|
---|
351 | {
|
---|
352 | emit sigSelectionChanged(selected, deselected);
|
---|
353 | QTableView::selectionChanged(selected, deselected);
|
---|
354 | }
|
---|
355 |
|
---|
356 |
|
---|
357 | /*********************************************************************************************************************************
|
---|
358 | * UIFileStringInputDialog implementation. *
|
---|
359 | *********************************************************************************************************************************/
|
---|
360 |
|
---|
361 | UIStringInputDialog::UIStringInputDialog(QWidget *pParent /* = 0 */, Qt::WindowFlags flags /* = 0 */)
|
---|
362 | :QIDialog(pParent, flags)
|
---|
363 | {
|
---|
364 | QVBoxLayout *layout = new QVBoxLayout(this);
|
---|
365 | m_pLineEdit = new QILineEdit(this);
|
---|
366 | layout->addWidget(m_pLineEdit);
|
---|
367 |
|
---|
368 | QIDialogButtonBox *pButtonBox =
|
---|
369 | new QIDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, this);
|
---|
370 | layout->addWidget(pButtonBox);
|
---|
371 | connect(pButtonBox, &QIDialogButtonBox::accepted, this, &UIStringInputDialog::accept);
|
---|
372 | connect(pButtonBox, &QIDialogButtonBox::rejected, this, &UIStringInputDialog::reject);
|
---|
373 | }
|
---|
374 |
|
---|
375 | QString UIStringInputDialog::getString() const
|
---|
376 | {
|
---|
377 | if (!m_pLineEdit)
|
---|
378 | return QString();
|
---|
379 | return m_pLineEdit->text();
|
---|
380 | }
|
---|
381 |
|
---|
382 |
|
---|
383 | /*********************************************************************************************************************************
|
---|
384 | * UIPropertiesDialog implementation. *
|
---|
385 | *********************************************************************************************************************************/
|
---|
386 |
|
---|
387 | UIPropertiesDialog::UIPropertiesDialog(QWidget *pParent, Qt::WindowFlags flags)
|
---|
388 | :QIDialog(pParent, flags)
|
---|
389 | , m_pMainLayout(new QVBoxLayout)
|
---|
390 | , m_pInfoEdit(new QTextEdit)
|
---|
391 | {
|
---|
392 | setLayout(m_pMainLayout);
|
---|
393 |
|
---|
394 | if (m_pMainLayout)
|
---|
395 | m_pMainLayout->addWidget(m_pInfoEdit);
|
---|
396 | if (m_pInfoEdit)
|
---|
397 | {
|
---|
398 | m_pInfoEdit->setReadOnly(true);
|
---|
399 | m_pInfoEdit->setFrameStyle(QFrame::NoFrame);
|
---|
400 | }
|
---|
401 | QIDialogButtonBox *pButtonBox =
|
---|
402 | new QIDialogButtonBox(QDialogButtonBox::Ok, Qt::Horizontal, this);
|
---|
403 | m_pMainLayout->addWidget(pButtonBox);
|
---|
404 | connect(pButtonBox, &QIDialogButtonBox::accepted, this, &UIStringInputDialog::accept);
|
---|
405 | }
|
---|
406 |
|
---|
407 | void UIPropertiesDialog::setPropertyText(const QString &strProperty)
|
---|
408 | {
|
---|
409 | if (!m_pInfoEdit)
|
---|
410 | return;
|
---|
411 | m_strProperty = strProperty;
|
---|
412 | m_pInfoEdit->setHtml(strProperty);
|
---|
413 | }
|
---|
414 |
|
---|
415 | void UIPropertiesDialog::addDirectoryStatistics(UIDirectoryStatistics directoryStatistics)
|
---|
416 | {
|
---|
417 | if (!m_pInfoEdit)
|
---|
418 | return;
|
---|
419 | // QString propertyString = m_pInfoEdit->toHtml();
|
---|
420 | // propertyString += "<b>Total Size:</b> " + QString::number(directoryStatistics.m_totalSize) + QString(" bytes");
|
---|
421 | // if (directoryStatistics.m_totalSize >= UIGuestControlFileTable::m_iKiloByte)
|
---|
422 | // propertyString += " (" + UIGuestControlFileTable::humanReadableSize(directoryStatistics.m_totalSize) + ")";
|
---|
423 | // propertyString += "<br/>";
|
---|
424 | // propertyString += "<b>File Count:</b> " + QString::number(directoryStatistics.m_uFileCount);
|
---|
425 |
|
---|
426 | // m_pInfoEdit->setHtml(propertyString);
|
---|
427 |
|
---|
428 | QString detailsString(m_strProperty);
|
---|
429 | detailsString += "<br/>";
|
---|
430 | detailsString += "<b>" + UIGuestControlFileManager::tr("Total Size") + "</b> " +
|
---|
431 | QString::number(directoryStatistics.m_totalSize) + UIGuestControlFileManager::tr(" bytes");
|
---|
432 | if (directoryStatistics.m_totalSize >= UIGuestControlFileTable::m_iKiloByte)
|
---|
433 | detailsString += " (" + UIGuestControlFileTable::humanReadableSize(directoryStatistics.m_totalSize) + ")";
|
---|
434 | detailsString += "<br/>";
|
---|
435 |
|
---|
436 | detailsString += "<b>" + UIGuestControlFileManager::tr("File Count") + ":</b> " +
|
---|
437 | QString::number(directoryStatistics.m_uFileCount);
|
---|
438 |
|
---|
439 | m_pInfoEdit->setHtml(detailsString);
|
---|
440 | }
|
---|
441 |
|
---|
442 |
|
---|
443 | /*********************************************************************************************************************************
|
---|
444 | * UIDirectoryStatistics implementation. *
|
---|
445 | *********************************************************************************************************************************/
|
---|
446 |
|
---|
447 | UIDirectoryStatistics::UIDirectoryStatistics()
|
---|
448 | : m_totalSize(0)
|
---|
449 | , m_uFileCount(0)
|
---|
450 | , m_uDirectoryCount(0)
|
---|
451 | , m_uSymlinkCount(0)
|
---|
452 | {
|
---|
453 | }
|
---|
454 |
|
---|
455 |
|
---|
456 | /*********************************************************************************************************************************
|
---|
457 | * UIFileTableItem implementation. *
|
---|
458 | *********************************************************************************************************************************/
|
---|
459 |
|
---|
460 | UIFileTableItem::UIFileTableItem(const QVector<QVariant> &data,
|
---|
461 | UIFileTableItem *parent, FileObjectType type)
|
---|
462 | : m_itemData(data)
|
---|
463 | , m_parentItem(parent)
|
---|
464 | , m_bIsOpened(false)
|
---|
465 | , m_isTargetADirectory(false)
|
---|
466 | , m_type(type)
|
---|
467 | , m_isDriveItem(false)
|
---|
468 | {
|
---|
469 | }
|
---|
470 |
|
---|
471 | UIFileTableItem::~UIFileTableItem()
|
---|
472 | {
|
---|
473 | qDeleteAll(m_childItems);
|
---|
474 | m_childItems.clear();
|
---|
475 | }
|
---|
476 |
|
---|
477 | void UIFileTableItem::appendChild(UIFileTableItem *item)
|
---|
478 | {
|
---|
479 | if (!item)
|
---|
480 | return;
|
---|
481 | m_childItems.append(item);
|
---|
482 | m_childMap.insert(item->name(), item);
|
---|
483 | }
|
---|
484 |
|
---|
485 | UIFileTableItem *UIFileTableItem::child(int row) const
|
---|
486 | {
|
---|
487 | return m_childItems.value(row);
|
---|
488 | }
|
---|
489 |
|
---|
490 | UIFileTableItem *UIFileTableItem::child(const QString &path) const
|
---|
491 | {
|
---|
492 | if (!m_childMap.contains(path))
|
---|
493 | return 0;
|
---|
494 | return m_childMap.value(path);
|
---|
495 | }
|
---|
496 |
|
---|
497 | int UIFileTableItem::childCount() const
|
---|
498 | {
|
---|
499 | return m_childItems.count();
|
---|
500 | }
|
---|
501 |
|
---|
502 | int UIFileTableItem::columnCount() const
|
---|
503 | {
|
---|
504 | return m_itemData.count();
|
---|
505 | }
|
---|
506 |
|
---|
507 | QVariant UIFileTableItem::data(int column) const
|
---|
508 | {
|
---|
509 | return m_itemData.value(column);
|
---|
510 | }
|
---|
511 |
|
---|
512 | QString UIFileTableItem::name() const
|
---|
513 | {
|
---|
514 | if (m_itemData.isEmpty() || !m_itemData[0].canConvert(QMetaType::QString))
|
---|
515 | return QString();
|
---|
516 | return m_itemData[0].toString();
|
---|
517 | }
|
---|
518 |
|
---|
519 | void UIFileTableItem::setData(const QVariant &data, int index)
|
---|
520 | {
|
---|
521 | if (index >= m_itemData.length())
|
---|
522 | return;
|
---|
523 | m_itemData[index] = data;
|
---|
524 | }
|
---|
525 |
|
---|
526 | UIFileTableItem *UIFileTableItem::parentItem()
|
---|
527 | {
|
---|
528 | return m_parentItem;
|
---|
529 | }
|
---|
530 |
|
---|
531 | int UIFileTableItem::row() const
|
---|
532 | {
|
---|
533 | if (m_parentItem)
|
---|
534 | return m_parentItem->m_childItems.indexOf(const_cast<UIFileTableItem*>(this));
|
---|
535 | return 0;
|
---|
536 | }
|
---|
537 |
|
---|
538 | bool UIFileTableItem::isDirectory() const
|
---|
539 | {
|
---|
540 | return m_type == FileObjectType_Directory;
|
---|
541 | }
|
---|
542 |
|
---|
543 | bool UIFileTableItem::isSymLink() const
|
---|
544 | {
|
---|
545 | return m_type == FileObjectType_SymLink;
|
---|
546 | }
|
---|
547 |
|
---|
548 | bool UIFileTableItem::isFile() const
|
---|
549 | {
|
---|
550 | return m_type == FileObjectType_File;
|
---|
551 | }
|
---|
552 |
|
---|
553 | void UIFileTableItem::clearChildren()
|
---|
554 | {
|
---|
555 | qDeleteAll(m_childItems);
|
---|
556 | m_childItems.clear();
|
---|
557 | m_childMap.clear();
|
---|
558 | }
|
---|
559 |
|
---|
560 | bool UIFileTableItem::isOpened() const
|
---|
561 | {
|
---|
562 | return m_bIsOpened;
|
---|
563 | }
|
---|
564 |
|
---|
565 | void UIFileTableItem::setIsOpened(bool flag)
|
---|
566 | {
|
---|
567 | m_bIsOpened = flag;
|
---|
568 | }
|
---|
569 |
|
---|
570 | const QString &UIFileTableItem::path() const
|
---|
571 | {
|
---|
572 | return m_strPath;
|
---|
573 | }
|
---|
574 |
|
---|
575 | void UIFileTableItem::setPath(const QString &path)
|
---|
576 | {
|
---|
577 | if (path.isNull() || path.isEmpty())
|
---|
578 | return;
|
---|
579 | m_strPath = path;
|
---|
580 | UIPathOperations::removeTrailingDelimiters(m_strPath);
|
---|
581 | }
|
---|
582 |
|
---|
583 | bool UIFileTableItem::isUpDirectory() const
|
---|
584 | {
|
---|
585 | if (!isDirectory())
|
---|
586 | return false;
|
---|
587 | if (data(0) == UIGuestControlFileModel::strUpDirectoryString)
|
---|
588 | return true;
|
---|
589 | return false;
|
---|
590 | }
|
---|
591 |
|
---|
592 | FileObjectType UIFileTableItem::type() const
|
---|
593 | {
|
---|
594 | return m_type;
|
---|
595 | }
|
---|
596 |
|
---|
597 | const QString &UIFileTableItem::targetPath() const
|
---|
598 | {
|
---|
599 | return m_strTargetPath;
|
---|
600 | }
|
---|
601 |
|
---|
602 | void UIFileTableItem::setTargetPath(const QString &path)
|
---|
603 | {
|
---|
604 | m_strTargetPath = path;
|
---|
605 | }
|
---|
606 |
|
---|
607 | bool UIFileTableItem::isTargetADirectory() const
|
---|
608 | {
|
---|
609 | return m_isTargetADirectory;
|
---|
610 | }
|
---|
611 |
|
---|
612 | void UIFileTableItem::setIsTargetADirectory(bool flag)
|
---|
613 | {
|
---|
614 | m_isTargetADirectory = flag;
|
---|
615 | }
|
---|
616 |
|
---|
617 | void UIFileTableItem::setIsDriveItem(bool flag)
|
---|
618 | {
|
---|
619 | m_isDriveItem = flag;
|
---|
620 | }
|
---|
621 |
|
---|
622 | bool UIFileTableItem::isDriveItem() const
|
---|
623 | {
|
---|
624 | return m_isDriveItem;
|
---|
625 | }
|
---|
626 |
|
---|
627 | /*********************************************************************************************************************************
|
---|
628 | +* UIFileDeleteConfirmationDialog implementation. *
|
---|
629 | +*********************************************************************************************************************************/
|
---|
630 |
|
---|
631 | UIFileDeleteConfirmationDialog::UIFileDeleteConfirmationDialog(QWidget *pParent /* = 0 */, Qt::WindowFlags flags /* = 0 */)
|
---|
632 | :QIDialog(pParent, flags)
|
---|
633 | , m_pAskNextTimeCheckBox(0)
|
---|
634 | , m_pQuestionLabel(0)
|
---|
635 | {
|
---|
636 | QVBoxLayout *pLayout = new QVBoxLayout(this);
|
---|
637 |
|
---|
638 | m_pQuestionLabel = new QILabel;
|
---|
639 | if (m_pQuestionLabel)
|
---|
640 | {
|
---|
641 | pLayout->addWidget(m_pQuestionLabel);
|
---|
642 | m_pQuestionLabel->setText(UIGuestControlFileManager::tr("Delete the selected file(s) and/or folder(s)"));
|
---|
643 | }
|
---|
644 |
|
---|
645 | QIDialogButtonBox *pButtonBox =
|
---|
646 | new QIDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, this);
|
---|
647 | if (pButtonBox)
|
---|
648 | {
|
---|
649 | pLayout->addWidget(pButtonBox, 0, Qt::AlignCenter);
|
---|
650 | connect(pButtonBox, &QIDialogButtonBox::accepted, this, &UIStringInputDialog::accept);
|
---|
651 | connect(pButtonBox, &QIDialogButtonBox::rejected, this, &UIStringInputDialog::reject);
|
---|
652 | }
|
---|
653 |
|
---|
654 | m_pAskNextTimeCheckBox = new QCheckBox;
|
---|
655 |
|
---|
656 | if (m_pAskNextTimeCheckBox)
|
---|
657 | {
|
---|
658 | UIGuestControlFileManagerOptions *pFileManagerOptions = UIGuestControlFileManagerOptions::instance();
|
---|
659 | if (pFileManagerOptions)
|
---|
660 | m_pAskNextTimeCheckBox->setChecked(pFileManagerOptions->bAskDeleteConfirmation);
|
---|
661 |
|
---|
662 | pLayout->addWidget(m_pAskNextTimeCheckBox);
|
---|
663 | m_pAskNextTimeCheckBox->setText(UIGuestControlFileManager::tr("Ask for this confirmation next time"));
|
---|
664 | m_pAskNextTimeCheckBox->setToolTip(UIGuestControlFileManager::tr("Delete confirmation can be "
|
---|
665 | "disabled/enabled also from the Options panel."));
|
---|
666 | }
|
---|
667 | }
|
---|
668 |
|
---|
669 | bool UIFileDeleteConfirmationDialog::askDeleteConfirmationNextTime() const
|
---|
670 | {
|
---|
671 | if (!m_pAskNextTimeCheckBox)
|
---|
672 | return true;
|
---|
673 | return m_pAskNextTimeCheckBox->isChecked();
|
---|
674 | }
|
---|
675 |
|
---|
676 |
|
---|
677 | /*********************************************************************************************************************************
|
---|
678 | * UIGuestControlFileTable implementation. *
|
---|
679 | *********************************************************************************************************************************/
|
---|
680 | const unsigned UIGuestControlFileTable::m_iKiloByte = 1000;
|
---|
681 | UIGuestControlFileTable::UIGuestControlFileTable(UIActionPool *pActionPool, QWidget *pParent /* = 0 */)
|
---|
682 | :QIWithRetranslateUI<QWidget>(pParent)
|
---|
683 | , m_eFileOperationType(FileOperationType_None)
|
---|
684 | , m_pRootItem(0)
|
---|
685 | , m_pLocationLabel(0)
|
---|
686 | , m_pPropertiesDialog(0)
|
---|
687 | , m_pActionPool(pActionPool)
|
---|
688 | , m_pToolBar(0)
|
---|
689 | , m_pModel(0)
|
---|
690 | , m_pView(0)
|
---|
691 | , m_pProxyModel(0)
|
---|
692 | , m_pMainLayout(0)
|
---|
693 | , m_pLocationComboBox(0)
|
---|
694 | , m_pWarningLabel(0)
|
---|
695 | {
|
---|
696 | prepareObjects();
|
---|
697 | }
|
---|
698 |
|
---|
699 | UIGuestControlFileTable::~UIGuestControlFileTable()
|
---|
700 | {
|
---|
701 | delete m_pRootItem;
|
---|
702 | }
|
---|
703 |
|
---|
704 | void UIGuestControlFileTable::reset()
|
---|
705 | {
|
---|
706 | if (m_pModel)
|
---|
707 | m_pModel->beginReset();
|
---|
708 | delete m_pRootItem;
|
---|
709 | m_pRootItem = 0;
|
---|
710 | if (m_pModel)
|
---|
711 | m_pModel->endReset();
|
---|
712 | if (m_pLocationComboBox)
|
---|
713 | {
|
---|
714 | disconnect(m_pLocationComboBox, static_cast<void(QComboBox::*)(const QString&)>(&QComboBox::currentIndexChanged),
|
---|
715 | this, &UIGuestControlFileTable::sltLocationComboCurrentChange);
|
---|
716 | m_pLocationComboBox->clear();
|
---|
717 | connect(m_pLocationComboBox, static_cast<void(QComboBox::*)(const QString&)>(&QComboBox::currentIndexChanged),
|
---|
718 | this, &UIGuestControlFileTable::sltLocationComboCurrentChange);
|
---|
719 | }
|
---|
720 | }
|
---|
721 |
|
---|
722 | void UIGuestControlFileTable::emitLogOutput(const QString& strOutput, FileManagerLogType eLogType)
|
---|
723 | {
|
---|
724 | emit sigLogOutput(strOutput, eLogType);
|
---|
725 | }
|
---|
726 |
|
---|
727 | void UIGuestControlFileTable::prepareObjects()
|
---|
728 | {
|
---|
729 | m_pMainLayout = new QGridLayout();
|
---|
730 | if (!m_pMainLayout)
|
---|
731 | return;
|
---|
732 | m_pMainLayout->setSpacing(0);
|
---|
733 | m_pMainLayout->setContentsMargins(0, 0, 0, 0);
|
---|
734 | setLayout(m_pMainLayout);
|
---|
735 |
|
---|
736 | m_pToolBar = new UIToolBar;
|
---|
737 | if (m_pToolBar)
|
---|
738 | {
|
---|
739 | m_pMainLayout->addWidget(m_pToolBar, 0, 0, 1, 5);
|
---|
740 | }
|
---|
741 |
|
---|
742 | m_pLocationLabel = new QILabel;
|
---|
743 | if (m_pLocationLabel)
|
---|
744 | {
|
---|
745 | m_pMainLayout->addWidget(m_pLocationLabel, 1, 0, 1, 1);
|
---|
746 | }
|
---|
747 |
|
---|
748 | m_pLocationComboBox = new QComboBox;
|
---|
749 | if (m_pLocationComboBox)
|
---|
750 | {
|
---|
751 | m_pMainLayout->addWidget(m_pLocationComboBox, 1, 1, 1, 4);
|
---|
752 | m_pLocationComboBox->setEditable(false);
|
---|
753 | connect(m_pLocationComboBox, static_cast<void(QComboBox::*)(const QString&)>(&QComboBox::currentIndexChanged),
|
---|
754 | this, &UIGuestControlFileTable::sltLocationComboCurrentChange);
|
---|
755 | }
|
---|
756 |
|
---|
757 |
|
---|
758 | m_pModel = new UIGuestControlFileModel(this);
|
---|
759 | if (!m_pModel)
|
---|
760 | return;
|
---|
761 |
|
---|
762 | m_pProxyModel = new UIGuestControlFileProxyModel(this);
|
---|
763 | if (!m_pProxyModel)
|
---|
764 | return;
|
---|
765 | m_pProxyModel->setSourceModel(m_pModel);
|
---|
766 |
|
---|
767 | m_pView = new UIGuestControlFileView(this);
|
---|
768 | if (m_pView)
|
---|
769 | {
|
---|
770 | m_pMainLayout->addWidget(m_pView, 2, 0, 5, 5);
|
---|
771 | m_pView->setModel(m_pProxyModel);
|
---|
772 | m_pView->setItemDelegate(new UIFileDelegate);
|
---|
773 | m_pView->setSortingEnabled(true);
|
---|
774 | m_pView->sortByColumn(0, Qt::AscendingOrder);
|
---|
775 |
|
---|
776 | connect(m_pView, &UIGuestControlFileView::doubleClicked,
|
---|
777 | this, &UIGuestControlFileTable::sltItemDoubleClicked);
|
---|
778 | connect(m_pView, &UIGuestControlFileView::clicked,
|
---|
779 | this, &UIGuestControlFileTable::sltItemClicked);
|
---|
780 | connect(m_pView, &UIGuestControlFileView::sigSelectionChanged,
|
---|
781 | this, &UIGuestControlFileTable::sltSelectionChanged);
|
---|
782 | connect(m_pView, &UIGuestControlFileView::customContextMenuRequested,
|
---|
783 | this, &UIGuestControlFileTable::sltCreateFileViewContextMenu);
|
---|
784 |
|
---|
785 | }
|
---|
786 | m_pWarningLabel = new QILabel(this);
|
---|
787 | if (m_pWarningLabel)
|
---|
788 | {
|
---|
789 | m_pMainLayout->addWidget(m_pWarningLabel, 2, 0, 5, 5);
|
---|
790 | QFont labelFont = m_pWarningLabel->font();
|
---|
791 | float fSizeMultiplier = 2.5;
|
---|
792 | if (labelFont.pointSize() != -1)
|
---|
793 | labelFont.setPointSize(fSizeMultiplier * labelFont.pointSize());
|
---|
794 | else
|
---|
795 | labelFont.setPixelSize(fSizeMultiplier * labelFont.pixelSize());
|
---|
796 | labelFont.setBold(true);
|
---|
797 | m_pWarningLabel->setFont(labelFont);
|
---|
798 | m_pWarningLabel->setAlignment(Qt::AlignCenter | Qt::AlignVCenter);
|
---|
799 | m_pWarningLabel->setWordWrap(true);
|
---|
800 | }
|
---|
801 | m_pWarningLabel->setVisible(!isEnabled());
|
---|
802 | m_pView->setVisible(isEnabled());
|
---|
803 |
|
---|
804 | m_pSearchLineEdit = new QILineEdit;
|
---|
805 | if (m_pSearchLineEdit)
|
---|
806 | {
|
---|
807 | m_pMainLayout->addWidget(m_pSearchLineEdit, 8, 0, 1, 5);
|
---|
808 | m_pSearchLineEdit->hide();
|
---|
809 | m_pSearchLineEdit->setClearButtonEnabled(true);
|
---|
810 | connect(m_pSearchLineEdit, &QLineEdit::textChanged,
|
---|
811 | this, &UIGuestControlFileTable::sltSearchTextChanged);
|
---|
812 | }
|
---|
813 | }
|
---|
814 |
|
---|
815 | void UIGuestControlFileTable::updateCurrentLocationEdit(const QString& strLocation)
|
---|
816 | {
|
---|
817 | if (!m_pLocationComboBox)
|
---|
818 | return;
|
---|
819 | int itemIndex = m_pLocationComboBox->findText(strLocation,
|
---|
820 | Qt::MatchExactly | Qt::MatchCaseSensitive);
|
---|
821 | if (itemIndex == -1)
|
---|
822 | {
|
---|
823 | m_pLocationComboBox->insertItem(m_pLocationComboBox->count(), strLocation);
|
---|
824 | itemIndex = m_pLocationComboBox->count() - 1;
|
---|
825 | }
|
---|
826 | m_pLocationComboBox->setCurrentIndex(itemIndex);
|
---|
827 | }
|
---|
828 |
|
---|
829 | void UIGuestControlFileTable::changeLocation(const QModelIndex &index)
|
---|
830 | {
|
---|
831 | if (!index.isValid() || !m_pView)
|
---|
832 | return;
|
---|
833 | m_pView->setRootIndex(m_pProxyModel->mapFromSource(index));
|
---|
834 | m_pView->clearSelection();
|
---|
835 |
|
---|
836 | UIFileTableItem *item = static_cast<UIFileTableItem*>(index.internalPointer());
|
---|
837 | if (item)
|
---|
838 | {
|
---|
839 | updateCurrentLocationEdit(item->path());
|
---|
840 | }
|
---|
841 | /** @todo check if we really need this and if not remove it */
|
---|
842 | //m_pModel->signalUpdate();
|
---|
843 | }
|
---|
844 |
|
---|
845 | void UIGuestControlFileTable::initializeFileTree()
|
---|
846 | {
|
---|
847 | if (m_pRootItem)
|
---|
848 | reset();
|
---|
849 |
|
---|
850 | /* Root item: */
|
---|
851 | const QString startPath("/");
|
---|
852 | QVector<QVariant> headData;
|
---|
853 | headData.resize(UIGuestControlFileModelColumn_Max);
|
---|
854 | m_pRootItem = new UIFileTableItem(headData, 0, FileObjectType_Directory);
|
---|
855 | UIFileTableItem* startItem = new UIFileTableItem(createTreeItemData(startPath, 4096, QDateTime(),
|
---|
856 | "" /* owner */, "" /* permissions */),
|
---|
857 | m_pRootItem, FileObjectType_Directory);
|
---|
858 | startItem->setPath(startPath);
|
---|
859 | m_pRootItem->appendChild(startItem);
|
---|
860 | startItem->setIsOpened(false);
|
---|
861 | populateStartDirectory(startItem);
|
---|
862 |
|
---|
863 | m_pModel->signalUpdate();
|
---|
864 | updateCurrentLocationEdit(startPath);
|
---|
865 | m_pView->setRootIndex(m_pProxyModel->mapFromSource(m_pModel->rootIndex()));
|
---|
866 | }
|
---|
867 |
|
---|
868 | void UIGuestControlFileTable::populateStartDirectory(UIFileTableItem *startItem)
|
---|
869 | {
|
---|
870 | determineDriveLetters();
|
---|
871 | if (m_driveLetterList.isEmpty())
|
---|
872 | {
|
---|
873 | /* Read the root directory and get the list: */
|
---|
874 | readDirectory(startItem->path(), startItem, true);
|
---|
875 | }
|
---|
876 | else
|
---|
877 | {
|
---|
878 | for (int i = 0; i < m_driveLetterList.size(); ++i)
|
---|
879 | {
|
---|
880 | UIFileTableItem* driveItem = new UIFileTableItem(createTreeItemData(m_driveLetterList[i], 4096,
|
---|
881 | QDateTime(), QString(), QString()),
|
---|
882 | startItem, FileObjectType_Directory);
|
---|
883 | driveItem->setPath(m_driveLetterList[i]);
|
---|
884 | startItem->appendChild(driveItem);
|
---|
885 | driveItem->setIsOpened(false);
|
---|
886 | driveItem->setIsDriveItem(true);
|
---|
887 | startItem->setIsOpened(true);
|
---|
888 | }
|
---|
889 | }
|
---|
890 | }
|
---|
891 |
|
---|
892 | void UIGuestControlFileTable::insertItemsToTree(QMap<QString,UIFileTableItem*> &map,
|
---|
893 | UIFileTableItem *parent, bool isDirectoryMap, bool isStartDir)
|
---|
894 | {
|
---|
895 | if (parent)
|
---|
896 |
|
---|
897 | /* Make sure we have an item representing up directory, and make sure it is not there for the start dir: */
|
---|
898 | if (isDirectoryMap)
|
---|
899 | {
|
---|
900 | if (!map.contains(UIGuestControlFileModel::strUpDirectoryString) && !isStartDir)
|
---|
901 | {
|
---|
902 | QVector<QVariant> data;
|
---|
903 | UIFileTableItem *item = new UIFileTableItem(createTreeItemData(UIGuestControlFileModel::strUpDirectoryString, 4096,
|
---|
904 | QDateTime(), QString(), QString())
|
---|
905 | , parent, FileObjectType_Directory);
|
---|
906 | item->setIsOpened(false);
|
---|
907 | map.insert(UIGuestControlFileModel::strUpDirectoryString, item);
|
---|
908 | }
|
---|
909 | else if (map.contains(UIGuestControlFileModel::strUpDirectoryString) && isStartDir)
|
---|
910 | {
|
---|
911 | map.remove(UIGuestControlFileModel::strUpDirectoryString);
|
---|
912 | }
|
---|
913 | }
|
---|
914 | for (QMap<QString,UIFileTableItem*>::const_iterator iterator = map.begin();
|
---|
915 | iterator != map.end(); ++iterator)
|
---|
916 | {
|
---|
917 | if (iterator.key() == "." || iterator.key().isEmpty())
|
---|
918 | continue;
|
---|
919 | parent->appendChild(iterator.value());
|
---|
920 | }
|
---|
921 | }
|
---|
922 |
|
---|
923 | void UIGuestControlFileTable::sltItemDoubleClicked(const QModelIndex &index)
|
---|
924 | {
|
---|
925 | if (!index.isValid() || !m_pModel || !m_pView)
|
---|
926 | return;
|
---|
927 | QModelIndex nIndex = m_pProxyModel ? m_pProxyModel->mapToSource(index) : index;
|
---|
928 | goIntoDirectory(nIndex);
|
---|
929 | }
|
---|
930 |
|
---|
931 | void UIGuestControlFileTable::sltItemClicked(const QModelIndex &index)
|
---|
932 | {
|
---|
933 | Q_UNUSED(index);
|
---|
934 | disableSelectionSearch();
|
---|
935 | }
|
---|
936 |
|
---|
937 | void UIGuestControlFileTable::sltGoUp()
|
---|
938 | {
|
---|
939 | if (!m_pView || !m_pModel)
|
---|
940 | return;
|
---|
941 | QModelIndex currentRoot = currentRootIndex();
|
---|
942 |
|
---|
943 | if (!currentRoot.isValid())
|
---|
944 | return;
|
---|
945 | if (currentRoot != m_pModel->rootIndex())
|
---|
946 | {
|
---|
947 | QModelIndex parentIndex = currentRoot.parent();
|
---|
948 | if (parentIndex.isValid())
|
---|
949 | {
|
---|
950 | changeLocation(currentRoot.parent());
|
---|
951 | m_pView->selectRow(currentRoot.row());
|
---|
952 | }
|
---|
953 | }
|
---|
954 | }
|
---|
955 |
|
---|
956 | void UIGuestControlFileTable::sltGoHome()
|
---|
957 | {
|
---|
958 | goToHomeDirectory();
|
---|
959 | }
|
---|
960 |
|
---|
961 | void UIGuestControlFileTable::sltRefresh()
|
---|
962 | {
|
---|
963 | refresh();
|
---|
964 | }
|
---|
965 |
|
---|
966 | void UIGuestControlFileTable::goIntoDirectory(const QModelIndex &itemIndex)
|
---|
967 | {
|
---|
968 | if (!m_pModel)
|
---|
969 | return;
|
---|
970 |
|
---|
971 | /* Make sure the colum is 0: */
|
---|
972 | QModelIndex index = m_pModel->index(itemIndex.row(), 0, itemIndex.parent());
|
---|
973 | if (!index.isValid())
|
---|
974 | return;
|
---|
975 |
|
---|
976 | UIFileTableItem *item = static_cast<UIFileTableItem*>(index.internalPointer());
|
---|
977 | if (!item)
|
---|
978 | return;
|
---|
979 |
|
---|
980 | /* check if we need to go up: */
|
---|
981 | if (item->isUpDirectory())
|
---|
982 | {
|
---|
983 | QModelIndex parentIndex = m_pModel->parent(m_pModel->parent(index));
|
---|
984 | if (parentIndex.isValid())
|
---|
985 | changeLocation(parentIndex);
|
---|
986 | return;
|
---|
987 | }
|
---|
988 |
|
---|
989 | if (!item->isDirectory())
|
---|
990 | return;
|
---|
991 | if (!item->isOpened())
|
---|
992 | readDirectory(item->path(),item);
|
---|
993 | changeLocation(index);
|
---|
994 | }
|
---|
995 |
|
---|
996 | void UIGuestControlFileTable::goIntoDirectory(const QStringList &pathTrail)
|
---|
997 | {
|
---|
998 | UIFileTableItem *parent = getStartDirectoryItem();
|
---|
999 |
|
---|
1000 | for(int i = 0; i < pathTrail.size(); ++i)
|
---|
1001 | {
|
---|
1002 | if (!parent)
|
---|
1003 | return;
|
---|
1004 | /* Make sure parent is already opened: */
|
---|
1005 | if (!parent->isOpened())
|
---|
1006 | readDirectory(parent->path(), parent, parent == getStartDirectoryItem());
|
---|
1007 | /* search the current path item among the parent's children: */
|
---|
1008 | UIFileTableItem *item = parent->child(pathTrail.at(i));
|
---|
1009 | if (!item)
|
---|
1010 | return;
|
---|
1011 | parent = item;
|
---|
1012 | }
|
---|
1013 | if (!parent)
|
---|
1014 | return;
|
---|
1015 | if (!parent->isOpened())
|
---|
1016 | readDirectory(parent->path(), parent, parent == getStartDirectoryItem());
|
---|
1017 | goIntoDirectory(parent);
|
---|
1018 | }
|
---|
1019 |
|
---|
1020 | void UIGuestControlFileTable::goIntoDirectory(UIFileTableItem *item)
|
---|
1021 | {
|
---|
1022 | if (!item || !m_pModel)
|
---|
1023 | return;
|
---|
1024 | goIntoDirectory(m_pModel->index(item));
|
---|
1025 | }
|
---|
1026 |
|
---|
1027 | UIFileTableItem* UIGuestControlFileTable::indexData(const QModelIndex &index) const
|
---|
1028 | {
|
---|
1029 | if (!index.isValid())
|
---|
1030 | return 0;
|
---|
1031 | return static_cast<UIFileTableItem*>(index.internalPointer());
|
---|
1032 | }
|
---|
1033 |
|
---|
1034 | void UIGuestControlFileTable::refresh()
|
---|
1035 | {
|
---|
1036 | if (!m_pView || !m_pModel)
|
---|
1037 | return;
|
---|
1038 | QModelIndex currentIndex = currentRootIndex();
|
---|
1039 |
|
---|
1040 | UIFileTableItem *treeItem = indexData(currentIndex);
|
---|
1041 | if (!treeItem)
|
---|
1042 | return;
|
---|
1043 | bool isRootDir = (m_pModel->rootIndex() == currentIndex);
|
---|
1044 | m_pModel->beginReset();
|
---|
1045 | /* For now we clear the whole subtree (that isrecursively) which is an overkill: */
|
---|
1046 | treeItem->clearChildren();
|
---|
1047 | if (isRootDir)
|
---|
1048 | populateStartDirectory(treeItem);
|
---|
1049 | else
|
---|
1050 | readDirectory(treeItem->path(), treeItem, isRootDir);
|
---|
1051 | m_pModel->endReset();
|
---|
1052 | m_pView->setRootIndex(m_pProxyModel->mapFromSource(currentIndex));
|
---|
1053 | setSelectionDependentActionsEnabled(m_pView->hasSelection());
|
---|
1054 | }
|
---|
1055 |
|
---|
1056 | void UIGuestControlFileTable::relist()
|
---|
1057 | {
|
---|
1058 | if (!m_pProxyModel)
|
---|
1059 | return;
|
---|
1060 | m_pProxyModel->invalidate();
|
---|
1061 | }
|
---|
1062 |
|
---|
1063 | void UIGuestControlFileTable::sltDelete()
|
---|
1064 | {
|
---|
1065 | if (!checkIfDeleteOK())
|
---|
1066 | return;
|
---|
1067 |
|
---|
1068 | if (!m_pView || !m_pModel)
|
---|
1069 | return;
|
---|
1070 |
|
---|
1071 | if (!m_pView || !m_pModel)
|
---|
1072 | return;
|
---|
1073 | QItemSelectionModel *selectionModel = m_pView->selectionModel();
|
---|
1074 | if (!selectionModel)
|
---|
1075 | return;
|
---|
1076 |
|
---|
1077 | QModelIndexList selectedItemIndices = selectionModel->selectedRows();
|
---|
1078 | for(int i = 0; i < selectedItemIndices.size(); ++i)
|
---|
1079 | {
|
---|
1080 | QModelIndex index =
|
---|
1081 | m_pProxyModel ? m_pProxyModel->mapToSource(selectedItemIndices.at(i)) : selectedItemIndices.at(i);
|
---|
1082 | deleteByIndex(index);
|
---|
1083 | }
|
---|
1084 | /** @todo dont refresh here, just delete the rows and update the table view: */
|
---|
1085 | refresh();
|
---|
1086 | }
|
---|
1087 |
|
---|
1088 | void UIGuestControlFileTable::sltRename()
|
---|
1089 | {
|
---|
1090 | if (!m_pView)
|
---|
1091 | return;
|
---|
1092 | QItemSelectionModel *selectionModel = m_pView->selectionModel();
|
---|
1093 | if (!selectionModel)
|
---|
1094 | return;
|
---|
1095 |
|
---|
1096 | QModelIndexList selectedItemIndices = selectionModel->selectedRows();
|
---|
1097 | if (selectedItemIndices.size() == 0)
|
---|
1098 | return;
|
---|
1099 | QModelIndex modelIndex =
|
---|
1100 | m_pProxyModel ? m_pProxyModel->mapToSource(selectedItemIndices.at(0)) : selectedItemIndices.at(0);
|
---|
1101 | UIFileTableItem *item = indexData(modelIndex);
|
---|
1102 | if (!item || item->isUpDirectory())
|
---|
1103 | return;
|
---|
1104 | m_pView->edit(selectedItemIndices.at(0));
|
---|
1105 | }
|
---|
1106 |
|
---|
1107 | void UIGuestControlFileTable::sltCreateNewDirectory()
|
---|
1108 | {
|
---|
1109 | if (!m_pModel || !m_pView)
|
---|
1110 | return;
|
---|
1111 | QModelIndex currentIndex = currentRootIndex();
|
---|
1112 | if (!currentIndex.isValid())
|
---|
1113 | return;
|
---|
1114 | UIFileTableItem *item = static_cast<UIFileTableItem*>(currentIndex.internalPointer());
|
---|
1115 | if (!item)
|
---|
1116 | return;
|
---|
1117 |
|
---|
1118 | QString newDirectoryName = getNewDirectoryName();
|
---|
1119 | if (newDirectoryName.isEmpty())
|
---|
1120 | return;
|
---|
1121 |
|
---|
1122 | if (createDirectory(item->path(), newDirectoryName))
|
---|
1123 | {
|
---|
1124 | /** @todo instead of refreshing here (an overkill) just add the
|
---|
1125 | rows and update the tabel view: */
|
---|
1126 | sltRefresh();
|
---|
1127 | }
|
---|
1128 | }
|
---|
1129 |
|
---|
1130 | void UIGuestControlFileTable::sltCopy()
|
---|
1131 | {
|
---|
1132 | m_copyCutBuffer = selectedItemPathList();
|
---|
1133 | m_eFileOperationType = FileOperationType_Copy;
|
---|
1134 | setPasteActionEnabled(true);
|
---|
1135 | }
|
---|
1136 |
|
---|
1137 | void UIGuestControlFileTable::sltCut()
|
---|
1138 | {
|
---|
1139 | m_copyCutBuffer = selectedItemPathList();
|
---|
1140 | m_eFileOperationType = FileOperationType_Cut;
|
---|
1141 | setPasteActionEnabled(true);
|
---|
1142 | }
|
---|
1143 |
|
---|
1144 | void UIGuestControlFileTable::sltPaste()
|
---|
1145 | {
|
---|
1146 | m_copyCutBuffer.clear();
|
---|
1147 |
|
---|
1148 | m_eFileOperationType = FileOperationType_None;
|
---|
1149 | setPasteActionEnabled(false);
|
---|
1150 | }
|
---|
1151 |
|
---|
1152 | void UIGuestControlFileTable::sltShowProperties()
|
---|
1153 | {
|
---|
1154 | showProperties();
|
---|
1155 | }
|
---|
1156 |
|
---|
1157 | void UIGuestControlFileTable::sltSelectionChanged(const QItemSelection & selected, const QItemSelection & deselected)
|
---|
1158 | {
|
---|
1159 | Q_UNUSED(selected);
|
---|
1160 | Q_UNUSED(deselected);
|
---|
1161 | setSelectionDependentActionsEnabled(m_pView->hasSelection());
|
---|
1162 | }
|
---|
1163 |
|
---|
1164 | void UIGuestControlFileTable::sltLocationComboCurrentChange(const QString &strLocation)
|
---|
1165 | {
|
---|
1166 | QString comboLocation(UIPathOperations::sanitize(strLocation));
|
---|
1167 | if (comboLocation == currentDirectoryPath())
|
---|
1168 | return;
|
---|
1169 | goIntoDirectory(UIPathOperations::pathTrail(comboLocation));
|
---|
1170 | }
|
---|
1171 |
|
---|
1172 | void UIGuestControlFileTable::sltSelectAll()
|
---|
1173 | {
|
---|
1174 | if (!m_pModel || !m_pView)
|
---|
1175 | return;
|
---|
1176 | m_pView->selectAll();
|
---|
1177 | deSelectUpDirectoryItem();
|
---|
1178 | }
|
---|
1179 |
|
---|
1180 | void UIGuestControlFileTable::sltInvertSelection()
|
---|
1181 | {
|
---|
1182 | setSelectionForAll(QItemSelectionModel::Toggle | QItemSelectionModel::Rows);
|
---|
1183 | deSelectUpDirectoryItem();
|
---|
1184 | }
|
---|
1185 |
|
---|
1186 | void UIGuestControlFileTable::sltSearchTextChanged(const QString &strText)
|
---|
1187 | {
|
---|
1188 | performSelectionSearch(strText);
|
---|
1189 | }
|
---|
1190 |
|
---|
1191 | void UIGuestControlFileTable::sltCreateFileViewContextMenu(const QPoint &point)
|
---|
1192 | {
|
---|
1193 | QWidget *pSender = qobject_cast<QWidget*>(sender());
|
---|
1194 | if (!pSender)
|
---|
1195 | return;
|
---|
1196 | createFileViewContextMenu(pSender, point);
|
---|
1197 | }
|
---|
1198 |
|
---|
1199 | void UIGuestControlFileTable::deSelectUpDirectoryItem()
|
---|
1200 | {
|
---|
1201 | if (!m_pView)
|
---|
1202 | return;
|
---|
1203 | QItemSelectionModel *pSelectionModel = m_pView->selectionModel();
|
---|
1204 | if (!pSelectionModel)
|
---|
1205 | return;
|
---|
1206 | QModelIndex currentRoot = currentRootIndex();
|
---|
1207 | if (!currentRoot.isValid())
|
---|
1208 | return;
|
---|
1209 |
|
---|
1210 | /* Make sure that "up directory item" (if exists) is deselected: */
|
---|
1211 | for (int i = 0; i < m_pModel->rowCount(currentRoot); ++i)
|
---|
1212 | {
|
---|
1213 | QModelIndex index = m_pModel->index(i, 0, currentRoot);
|
---|
1214 | if (!index.isValid())
|
---|
1215 | continue;
|
---|
1216 |
|
---|
1217 | UIFileTableItem *item = static_cast<UIFileTableItem*>(index.internalPointer());
|
---|
1218 | if (item && item->isUpDirectory())
|
---|
1219 | {
|
---|
1220 | QModelIndex indexToDeselect = m_pProxyModel ? m_pProxyModel->mapFromSource(index) : index;
|
---|
1221 | pSelectionModel->select(indexToDeselect, QItemSelectionModel::Deselect | QItemSelectionModel::Rows);
|
---|
1222 | }
|
---|
1223 | }
|
---|
1224 | }
|
---|
1225 |
|
---|
1226 | void UIGuestControlFileTable::setSelectionForAll(QItemSelectionModel::SelectionFlags flags)
|
---|
1227 | {
|
---|
1228 | if (!m_pView)
|
---|
1229 | return;
|
---|
1230 | QItemSelectionModel *pSelectionModel = m_pView->selectionModel();
|
---|
1231 | if (!pSelectionModel)
|
---|
1232 | return;
|
---|
1233 | QModelIndex currentRoot = currentRootIndex();
|
---|
1234 | if (!currentRoot.isValid())
|
---|
1235 | return;
|
---|
1236 |
|
---|
1237 | for (int i = 0; i < m_pModel->rowCount(currentRoot); ++i)
|
---|
1238 | {
|
---|
1239 | QModelIndex index = m_pModel->index(i, 0, currentRoot);
|
---|
1240 | if (!index.isValid())
|
---|
1241 | continue;
|
---|
1242 | QModelIndex indexToSelect = m_pProxyModel ? m_pProxyModel->mapFromSource(index) : index;
|
---|
1243 | pSelectionModel->select(indexToSelect, flags);
|
---|
1244 | }
|
---|
1245 | }
|
---|
1246 |
|
---|
1247 | void UIGuestControlFileTable::setSelection(const QModelIndex &indexInProxyModel)
|
---|
1248 | {
|
---|
1249 | if (!m_pView)
|
---|
1250 | return;
|
---|
1251 | QItemSelectionModel *selectionModel = m_pView->selectionModel();
|
---|
1252 | if (!selectionModel)
|
---|
1253 | return;
|
---|
1254 | selectionModel->select(indexInProxyModel, QItemSelectionModel::Current | QItemSelectionModel::Rows | QItemSelectionModel::Select);
|
---|
1255 | m_pView->scrollTo(indexInProxyModel, QAbstractItemView::EnsureVisible);
|
---|
1256 | }
|
---|
1257 |
|
---|
1258 | void UIGuestControlFileTable::deleteByIndex(const QModelIndex &itemIndex)
|
---|
1259 | {
|
---|
1260 | UIFileTableItem *treeItem = indexData(itemIndex);
|
---|
1261 | if (!treeItem)
|
---|
1262 | return;
|
---|
1263 | deleteByItem(treeItem);
|
---|
1264 | }
|
---|
1265 |
|
---|
1266 | void UIGuestControlFileTable::retranslateUi()
|
---|
1267 | {
|
---|
1268 | if (m_pRootItem)
|
---|
1269 | {
|
---|
1270 | m_pRootItem->setData(UIGuestControlFileManager::tr("Name"), UIGuestControlFileModelColumn_Name);
|
---|
1271 | m_pRootItem->setData(UIGuestControlFileManager::tr("Size"), UIGuestControlFileModelColumn_Size);
|
---|
1272 | m_pRootItem->setData(UIGuestControlFileManager::tr("Change Time"), UIGuestControlFileModelColumn_ChangeTime);
|
---|
1273 | m_pRootItem->setData(UIGuestControlFileManager::tr("Owner"), UIGuestControlFileModelColumn_Owner);
|
---|
1274 | m_pRootItem->setData(UIGuestControlFileManager::tr("Permissions"), UIGuestControlFileModelColumn_Permissions);
|
---|
1275 | }
|
---|
1276 | if (m_pWarningLabel)
|
---|
1277 | m_pWarningLabel->setText(UIGuestControlFileManager::tr("No Guest Session"));
|
---|
1278 | }
|
---|
1279 |
|
---|
1280 | bool UIGuestControlFileTable::eventFilter(QObject *pObject, QEvent *pEvent) /* override */
|
---|
1281 | {
|
---|
1282 | Q_UNUSED(pObject);
|
---|
1283 | if (pEvent->type() == QEvent::KeyPress)
|
---|
1284 | {
|
---|
1285 | QKeyEvent *pKeyEvent = dynamic_cast<QKeyEvent*>(pEvent);
|
---|
1286 | if (pKeyEvent)
|
---|
1287 | {
|
---|
1288 | if (pKeyEvent->key() == Qt::Key_Enter || pKeyEvent->key() == Qt::Key_Return)
|
---|
1289 | {
|
---|
1290 | if (m_pView && m_pModel)
|
---|
1291 | {
|
---|
1292 | /* Get the selected item. If there are 0 or more than 1 selection do nothing: */
|
---|
1293 | QItemSelectionModel *selectionModel = m_pView->selectionModel();
|
---|
1294 | if (selectionModel)
|
---|
1295 | {
|
---|
1296 | QModelIndexList selectedItemIndices = selectionModel->selectedRows();
|
---|
1297 | if (selectedItemIndices.size() == 1 && m_pModel)
|
---|
1298 | goIntoDirectory( m_pProxyModel->mapToSource(selectedItemIndices.at(0)));
|
---|
1299 | }
|
---|
1300 | }
|
---|
1301 | return true;
|
---|
1302 | }
|
---|
1303 | else if (pKeyEvent->key() == Qt::Key_Delete)
|
---|
1304 | {
|
---|
1305 | sltDelete();
|
---|
1306 | return true;
|
---|
1307 | }
|
---|
1308 | else if (pKeyEvent->key() == Qt::Key_Backspace)
|
---|
1309 | {
|
---|
1310 | sltGoUp();
|
---|
1311 | return true;
|
---|
1312 | }
|
---|
1313 | else if (pKeyEvent->text().length() == 1 && pKeyEvent->text().at(0).unicode() <= 127)
|
---|
1314 | {
|
---|
1315 | if (m_pSearchLineEdit)
|
---|
1316 | {
|
---|
1317 | m_pSearchLineEdit->show();
|
---|
1318 | QString strText = m_pSearchLineEdit->text();
|
---|
1319 | strText.append(pKeyEvent->text());
|
---|
1320 | m_pSearchLineEdit->setText(strText);
|
---|
1321 | }
|
---|
1322 | }
|
---|
1323 | }
|
---|
1324 | }
|
---|
1325 |
|
---|
1326 | return false;
|
---|
1327 | }
|
---|
1328 |
|
---|
1329 | UIFileTableItem *UIGuestControlFileTable::getStartDirectoryItem()
|
---|
1330 | {
|
---|
1331 | if (!m_pRootItem)
|
---|
1332 | return 0;
|
---|
1333 | if (m_pRootItem->childCount() <= 0)
|
---|
1334 | return 0;
|
---|
1335 | return m_pRootItem->child(0);
|
---|
1336 | }
|
---|
1337 |
|
---|
1338 |
|
---|
1339 | QString UIGuestControlFileTable::getNewDirectoryName()
|
---|
1340 | {
|
---|
1341 | UIStringInputDialog *dialog = new UIStringInputDialog();
|
---|
1342 | if (dialog->execute())
|
---|
1343 | {
|
---|
1344 | QString strDialog = dialog->getString();
|
---|
1345 | delete dialog;
|
---|
1346 | return strDialog;
|
---|
1347 | }
|
---|
1348 | delete dialog;
|
---|
1349 | return QString();
|
---|
1350 | }
|
---|
1351 |
|
---|
1352 | QString UIGuestControlFileTable::currentDirectoryPath() const
|
---|
1353 | {
|
---|
1354 | if (!m_pView)
|
---|
1355 | return QString();
|
---|
1356 | QModelIndex currentRoot = currentRootIndex();
|
---|
1357 | if (!currentRoot.isValid())
|
---|
1358 | return QString();
|
---|
1359 | UIFileTableItem *item = static_cast<UIFileTableItem*>(currentRoot.internalPointer());
|
---|
1360 | if (!item)
|
---|
1361 | return QString();
|
---|
1362 | /* be paranoid: */
|
---|
1363 | if (!item->isDirectory())
|
---|
1364 | return QString();
|
---|
1365 | return item->path();
|
---|
1366 | }
|
---|
1367 |
|
---|
1368 | QStringList UIGuestControlFileTable::selectedItemPathList()
|
---|
1369 | {
|
---|
1370 | QItemSelectionModel *selectionModel = m_pView->selectionModel();
|
---|
1371 | if (!selectionModel)
|
---|
1372 | return QStringList();
|
---|
1373 |
|
---|
1374 | QStringList pathList;
|
---|
1375 | QModelIndexList selectedItemIndices = selectionModel->selectedRows();
|
---|
1376 | for(int i = 0; i < selectedItemIndices.size(); ++i)
|
---|
1377 | {
|
---|
1378 | QModelIndex index =
|
---|
1379 | m_pProxyModel ? m_pProxyModel->mapToSource(selectedItemIndices.at(i)) : selectedItemIndices.at(i);
|
---|
1380 | UIFileTableItem *item = static_cast<UIFileTableItem*>(index.internalPointer());
|
---|
1381 | if (!item)
|
---|
1382 | continue;
|
---|
1383 | pathList.push_back(item->path());
|
---|
1384 | }
|
---|
1385 | return pathList;
|
---|
1386 | }
|
---|
1387 |
|
---|
1388 | CGuestFsObjInfo UIGuestControlFileTable::guestFsObjectInfo(const QString& path, CGuestSession &comGuestSession) const
|
---|
1389 | {
|
---|
1390 | if (comGuestSession.isNull())
|
---|
1391 | return CGuestFsObjInfo();
|
---|
1392 | CGuestFsObjInfo comFsObjInfo = comGuestSession.FsObjQueryInfo(path, true /*aFollowSymlinks*/);
|
---|
1393 | if (!comFsObjInfo.isOk())
|
---|
1394 | return CGuestFsObjInfo();
|
---|
1395 | return comFsObjInfo;
|
---|
1396 | }
|
---|
1397 |
|
---|
1398 | void UIGuestControlFileTable::setSelectionDependentActionsEnabled(bool fIsEnabled)
|
---|
1399 | {
|
---|
1400 | foreach (QAction *pAction, m_selectionDependentActions)
|
---|
1401 | {
|
---|
1402 | pAction->setEnabled(fIsEnabled);
|
---|
1403 | }
|
---|
1404 | }
|
---|
1405 |
|
---|
1406 |
|
---|
1407 | QVector<QVariant> UIGuestControlFileTable::createTreeItemData(const QString &strName, ULONG64 size, const QDateTime &changeTime,
|
---|
1408 | const QString &strOwner, const QString &strPermissions)
|
---|
1409 | {
|
---|
1410 | QVector<QVariant> data;
|
---|
1411 | data.resize(UIGuestControlFileModelColumn_Max);
|
---|
1412 | data[UIGuestControlFileModelColumn_Name] = strName;
|
---|
1413 | data[UIGuestControlFileModelColumn_Size] = (qulonglong)size;
|
---|
1414 | data[UIGuestControlFileModelColumn_ChangeTime] = changeTime;
|
---|
1415 | data[UIGuestControlFileModelColumn_Owner] = strOwner;
|
---|
1416 | data[UIGuestControlFileModelColumn_Permissions] = strPermissions;
|
---|
1417 | return data;
|
---|
1418 | }
|
---|
1419 |
|
---|
1420 | bool UIGuestControlFileTable::event(QEvent *pEvent)
|
---|
1421 | {
|
---|
1422 | if (pEvent->type() == QEvent::EnabledChange)
|
---|
1423 | {
|
---|
1424 | m_pWarningLabel->setVisible(!isEnabled());
|
---|
1425 | m_pView->setVisible(isEnabled());
|
---|
1426 | retranslateUi();
|
---|
1427 | }
|
---|
1428 | return QIWithRetranslateUI<QWidget>::event(pEvent);
|
---|
1429 | }
|
---|
1430 |
|
---|
1431 | QString UIGuestControlFileTable::fileTypeString(FileObjectType type)
|
---|
1432 | {
|
---|
1433 | QString strType = UIGuestControlFileManager::tr("Unknown");
|
---|
1434 | switch(type)
|
---|
1435 | {
|
---|
1436 | case FileObjectType_File:
|
---|
1437 | strType = UIGuestControlFileManager::tr("File");
|
---|
1438 | break;
|
---|
1439 | case FileObjectType_Directory:
|
---|
1440 | strType = UIGuestControlFileManager::tr("Directory");
|
---|
1441 | break;
|
---|
1442 | case FileObjectType_SymLink:
|
---|
1443 | strType = UIGuestControlFileManager::tr("Symbolic Link");
|
---|
1444 | break;
|
---|
1445 | case FileObjectType_Other:
|
---|
1446 | strType = UIGuestControlFileManager::tr("Other");
|
---|
1447 | break;
|
---|
1448 |
|
---|
1449 | case FileObjectType_Unknown:
|
---|
1450 | default:
|
---|
1451 | break;
|
---|
1452 | }
|
---|
1453 | return strType;
|
---|
1454 | }
|
---|
1455 |
|
---|
1456 | /* static */ QString UIGuestControlFileTable::humanReadableSize(ULONG64 size)
|
---|
1457 | {
|
---|
1458 | int i = 0;
|
---|
1459 | double dSize = size;
|
---|
1460 | const char* units[] = {" B", " kB", " MB", " GB", " TB", " PB", " EB", " ZB", " YB"};
|
---|
1461 | while (size > m_iKiloByte) {
|
---|
1462 | size /= m_iKiloByte;
|
---|
1463 | dSize /= (double) m_iKiloByte;
|
---|
1464 | i++;
|
---|
1465 | }
|
---|
1466 | if (i > 8)
|
---|
1467 | return QString();
|
---|
1468 |
|
---|
1469 | QString strResult(QString::number(dSize, 'f', 2));
|
---|
1470 | strResult += units[i];
|
---|
1471 | return strResult;
|
---|
1472 | }
|
---|
1473 |
|
---|
1474 | void UIGuestControlFileTable::sltReceiveDirectoryStatistics(UIDirectoryStatistics statistics)
|
---|
1475 | {
|
---|
1476 | if (!m_pPropertiesDialog)
|
---|
1477 | return;
|
---|
1478 | m_pPropertiesDialog->addDirectoryStatistics(statistics);
|
---|
1479 | }
|
---|
1480 |
|
---|
1481 | QModelIndex UIGuestControlFileTable::currentRootIndex() const
|
---|
1482 | {
|
---|
1483 | if (!m_pView)
|
---|
1484 | return QModelIndex();
|
---|
1485 | if (!m_pProxyModel)
|
---|
1486 | return m_pView->rootIndex();
|
---|
1487 | return m_pProxyModel->mapToSource(m_pView->rootIndex());
|
---|
1488 | }
|
---|
1489 |
|
---|
1490 | void UIGuestControlFileTable::performSelectionSearch(const QString &strSearchText)
|
---|
1491 | {
|
---|
1492 | if (!m_pProxyModel | !m_pView || strSearchText.isEmpty())
|
---|
1493 | return;
|
---|
1494 |
|
---|
1495 | int rowCount = m_pProxyModel->rowCount(m_pView->rootIndex());
|
---|
1496 | UIFileTableItem *pFoundItem = 0;
|
---|
1497 | QModelIndex index;
|
---|
1498 | for (int i = 0; i < rowCount && !pFoundItem; ++i)
|
---|
1499 | {
|
---|
1500 | index = m_pProxyModel->index(i, 0, m_pView->rootIndex());
|
---|
1501 | if (!index.isValid())
|
---|
1502 | continue;
|
---|
1503 | pFoundItem = static_cast<UIFileTableItem*>(m_pProxyModel->mapToSource(index).internalPointer());
|
---|
1504 | if (!pFoundItem)
|
---|
1505 | continue;
|
---|
1506 | const QString &strName = pFoundItem->name();
|
---|
1507 | if (!strName.startsWith(m_pSearchLineEdit->text(), Qt::CaseInsensitive))
|
---|
1508 | pFoundItem = 0;
|
---|
1509 | }
|
---|
1510 | if (pFoundItem)
|
---|
1511 | {
|
---|
1512 | /* Deselect anything that is already selected: */
|
---|
1513 | m_pView->clearSelection();
|
---|
1514 | setSelection(index);
|
---|
1515 | }
|
---|
1516 | }
|
---|
1517 |
|
---|
1518 | void UIGuestControlFileTable::disableSelectionSearch()
|
---|
1519 | {
|
---|
1520 | if (!m_pSearchLineEdit)
|
---|
1521 | return;
|
---|
1522 | m_pSearchLineEdit->blockSignals(true);
|
---|
1523 | m_pSearchLineEdit->clear();
|
---|
1524 | m_pSearchLineEdit->hide();
|
---|
1525 | m_pSearchLineEdit->blockSignals(false);
|
---|
1526 | }
|
---|
1527 |
|
---|
1528 | bool UIGuestControlFileTable::checkIfDeleteOK()
|
---|
1529 | {
|
---|
1530 | UIGuestControlFileManagerOptions *pFileManagerOptions = UIGuestControlFileManagerOptions::instance();
|
---|
1531 | if (!pFileManagerOptions)
|
---|
1532 | return true;
|
---|
1533 | if (!pFileManagerOptions->bAskDeleteConfirmation)
|
---|
1534 | return true;
|
---|
1535 | UIFileDeleteConfirmationDialog *pDialog =
|
---|
1536 | new UIFileDeleteConfirmationDialog(this);
|
---|
1537 |
|
---|
1538 | bool fContinueWithDelete = (pDialog->execute() == QDialog::Accepted);
|
---|
1539 | bool bAskNextTime = pDialog->askDeleteConfirmationNextTime();
|
---|
1540 |
|
---|
1541 | /* Update the file manager options only if it is necessary: */
|
---|
1542 | if (pFileManagerOptions->bAskDeleteConfirmation != bAskNextTime)
|
---|
1543 | {
|
---|
1544 | pFileManagerOptions->bAskDeleteConfirmation = bAskNextTime;
|
---|
1545 | /* Notify file manager options panel so that the check box there is updated: */
|
---|
1546 | emit sigDeleteConfirmationOptionChanged();
|
---|
1547 | }
|
---|
1548 |
|
---|
1549 | delete pDialog;
|
---|
1550 |
|
---|
1551 | return fContinueWithDelete;
|
---|
1552 |
|
---|
1553 | }
|
---|
1554 |
|
---|
1555 | #include "UIGuestControlFileTable.moc"
|
---|