VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/guestctrl/UIGuestControlFileTable.cpp@ 75633

Last change on this file since 75633 was 75633, checked in by vboxsync, 6 years ago

FE/Qt: bugref:6699. Implement a 'delete confirmation' dialog

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 47.4 KB
Line 
1/* $Id: UIGuestControlFileTable.cpp 75633 2018-11-21 10:03:40Z 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 */
68class UIGuestControlFileView : public QTableView
69{
70
71 Q_OBJECT;
72
73signals:
74
75 void sigSelectionChanged(const QItemSelection & selected, const QItemSelection & deselected);
76
77public:
78
79 UIGuestControlFileView(QWidget * parent = 0);
80 bool hasSelection() const;
81
82protected:
83
84 virtual void selectionChanged(const QItemSelection & selected, const QItemSelection & deselected) /*override */;
85
86private:
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 */
97class UIFileDelegate : public QItemDelegate
98{
99
100 Q_OBJECT;
101
102protected:
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 */
114class UIStringInputDialog : public QIDialog
115{
116
117 Q_OBJECT;
118
119public:
120
121 UIStringInputDialog(QWidget *pParent = 0, Qt::WindowFlags flags = 0);
122 QString getString() const;
123
124private:
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 */
136class UIFileDeleteConfirmationDialog : public QIDialog
137{
138
139 Q_OBJECT;
140
141public:
142
143 UIFileDeleteConfirmationDialog(QWidget *pParent = 0, Qt::WindowFlags flags = 0);
144 /** Returns whether m_pAskNextTimeCheckBox is checked or not. */
145 bool askDeleteConfirmationNextTime() const;
146
147private:
148
149 QCheckBox *m_pAskNextTimeCheckBox;
150 QLabel *m_pQuestionLabel;
151
152};
153
154
155/*********************************************************************************************************************************
156* UIHostDirectoryDiskUsageComputer implementation. *
157*********************************************************************************************************************************/
158
159UIDirectoryDiskUsageComputer::UIDirectoryDiskUsageComputer(QObject *parent, QStringList pathList)
160 :QThread(parent)
161 , m_pathList(pathList)
162 , m_fOkToContinue(true)
163{
164}
165
166void UIDirectoryDiskUsageComputer::run()
167{
168 for (int i = 0; i < m_pathList.size(); ++i)
169 directoryStatisticsRecursive(m_pathList[i], m_resultStatistics);
170}
171
172void UIDirectoryDiskUsageComputer::stopRecursion()
173{
174 m_mutex.lock();
175 m_fOkToContinue = false;
176 m_mutex.unlock();
177}
178
179bool UIDirectoryDiskUsageComputer::isOkToContinue() const
180{
181 return m_fOkToContinue;
182}
183
184
185/*********************************************************************************************************************************
186* UIPathOperations implementation. *
187*********************************************************************************************************************************/
188
189const QChar UIPathOperations::delimiter = QChar('/');
190const 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
322UIGuestControlFileView::UIGuestControlFileView(QWidget *parent)
323 :QTableView(parent)
324 , m_pParent(parent)
325{
326 configure();
327}
328
329void 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
342bool UIGuestControlFileView::hasSelection() const
343{
344 QItemSelectionModel *pSelectionModel = selectionModel();
345 if (!pSelectionModel)
346 return false;
347 return pSelectionModel->hasSelection();
348}
349
350void 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
361UIStringInputDialog::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
375QString 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
387UIPropertiesDialog::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
407void UIPropertiesDialog::setPropertyText(const QString &strProperty)
408{
409 if (!m_pInfoEdit)
410 return;
411 m_strProperty = strProperty;
412 m_pInfoEdit->setHtml(strProperty);
413}
414
415void 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>Total Size:</b> " + QString::number(directoryStatistics.m_totalSize) + QString(" bytes");
431 if (directoryStatistics.m_totalSize >= UIGuestControlFileTable::m_iKiloByte)
432 detailsString += " (" + UIGuestControlFileTable::humanReadableSize(directoryStatistics.m_totalSize) + ")";
433 detailsString += "<br/>";
434
435 detailsString += "<b>File Count:</b> " + QString::number(directoryStatistics.m_uFileCount);
436
437 m_pInfoEdit->setHtml(detailsString);
438
439}
440
441/*********************************************************************************************************************************
442* UIDirectoryStatistics implementation.
443 *
444*********************************************************************************************************************************/
445
446UIDirectoryStatistics::UIDirectoryStatistics()
447 : m_totalSize(0)
448 , m_uFileCount(0)
449 , m_uDirectoryCount(0)
450 , m_uSymlinkCount(0)
451{
452}
453
454
455/*********************************************************************************************************************************
456* UIFileTableItem implementation. *
457*********************************************************************************************************************************/
458
459UIFileTableItem::UIFileTableItem(const QVector<QVariant> &data,
460 UIFileTableItem *parent, FileObjectType type)
461 : m_itemData(data)
462 , m_parentItem(parent)
463 , m_bIsOpened(false)
464 , m_isTargetADirectory(false)
465 , m_type(type)
466 , m_isDriveItem(false)
467{
468}
469
470UIFileTableItem::~UIFileTableItem()
471{
472 qDeleteAll(m_childItems);
473 m_childItems.clear();
474}
475
476void UIFileTableItem::appendChild(UIFileTableItem *item)
477{
478 if (!item)
479 return;
480 m_childItems.append(item);
481
482 m_childMap.insert(item->name(), item);
483}
484
485UIFileTableItem *UIFileTableItem::child(int row) const
486{
487 return m_childItems.value(row);
488}
489
490UIFileTableItem *UIFileTableItem::child(const QString &path) const
491{
492 if (!m_childMap.contains(path))
493 return 0;
494 return m_childMap.value(path);
495}
496
497int UIFileTableItem::childCount() const
498{
499 return m_childItems.count();
500}
501
502int UIFileTableItem::columnCount() const
503{
504 return m_itemData.count();
505}
506
507QVariant UIFileTableItem::data(int column) const
508{
509 return m_itemData.value(column);
510}
511
512QString 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
519void UIFileTableItem::setData(const QVariant &data, int index)
520{
521 if (index >= m_itemData.length())
522 return;
523 m_itemData[index] = data;
524}
525
526UIFileTableItem *UIFileTableItem::parentItem()
527{
528 return m_parentItem;
529}
530
531int UIFileTableItem::row() const
532{
533 if (m_parentItem)
534 return m_parentItem->m_childItems.indexOf(const_cast<UIFileTableItem*>(this));
535 return 0;
536}
537
538bool UIFileTableItem::isDirectory() const
539{
540 return m_type == FileObjectType_Directory;
541}
542
543bool UIFileTableItem::isSymLink() const
544{
545 return m_type == FileObjectType_SymLink;
546}
547
548bool UIFileTableItem::isFile() const
549{
550 return m_type == FileObjectType_File;
551}
552
553void UIFileTableItem::clearChildren()
554{
555 qDeleteAll(m_childItems);
556 m_childItems.clear();
557 m_childMap.clear();
558}
559
560bool UIFileTableItem::isOpened() const
561{
562 return m_bIsOpened;
563}
564
565void UIFileTableItem::setIsOpened(bool flag)
566{
567 m_bIsOpened = flag;
568}
569
570const QString &UIFileTableItem::path() const
571{
572 return m_strPath;
573}
574
575void 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
583bool UIFileTableItem::isUpDirectory() const
584{
585 if (!isDirectory())
586 return false;
587 if (data(0) == UIGuestControlFileModel::strUpDirectoryString)
588 return true;
589 return false;
590}
591
592FileObjectType UIFileTableItem::type() const
593{
594 return m_type;
595}
596
597const QString &UIFileTableItem::targetPath() const
598{
599 return m_strTargetPath;
600}
601
602void UIFileTableItem::setTargetPath(const QString &path)
603{
604 m_strTargetPath = path;
605}
606
607bool UIFileTableItem::isTargetADirectory() const
608{
609 return m_isTargetADirectory;
610}
611
612void UIFileTableItem::setIsTargetADirectory(bool flag)
613{
614 m_isTargetADirectory = flag;
615}
616
617void UIFileTableItem::setIsDriveItem(bool flag)
618{
619 m_isDriveItem = flag;
620}
621
622bool UIFileTableItem::isDriveItem() const
623{
624 return m_isDriveItem;
625}
626
627/*********************************************************************************************************************************
628+* UIFileDeleteConfirmationDialog implementation. *
629+*********************************************************************************************************************************/
630
631UIFileDeleteConfirmationDialog::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 QLabel;
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 QCheckBox *m_pAskNextTimeCheckBox = new QCheckBox;
655
656 if (m_pAskNextTimeCheckBox)
657 {
658 pLayout->addWidget(m_pAskNextTimeCheckBox);
659 m_pAskNextTimeCheckBox->setText(UIGuestControlFileManager::tr("Ask for this confirmation next time"));
660 }
661}
662
663bool UIFileDeleteConfirmationDialog::askDeleteConfirmationNextTime() const
664{
665 if (!m_pAskNextTimeCheckBox)
666 return true;
667 return m_pAskNextTimeCheckBox->isChecked();
668}
669
670
671/*********************************************************************************************************************************
672* UIGuestControlFileTable implementation. *
673*********************************************************************************************************************************/
674const unsigned UIGuestControlFileTable::m_iKiloByte = 1000;
675UIGuestControlFileTable::UIGuestControlFileTable(UIActionPool *pActionPool, QWidget *pParent /* = 0 */)
676 :QIWithRetranslateUI<QWidget>(pParent)
677 , m_pRootItem(0)
678 , m_pLocationLabel(0)
679 , m_pPropertiesDialog(0)
680 , m_pActionPool(pActionPool)
681 , m_pToolBar(0)
682 , m_pModel(0)
683 , m_pView(0)
684 , m_pProxyModel(0)
685 , m_pMainLayout(0)
686 , m_pLocationComboBox(0)
687{
688 prepareObjects();
689}
690
691UIGuestControlFileTable::~UIGuestControlFileTable()
692{
693 delete m_pRootItem;
694}
695
696void UIGuestControlFileTable::reset()
697{
698 if (m_pModel)
699 m_pModel->beginReset();
700 delete m_pRootItem;
701 m_pRootItem = 0;
702 if (m_pModel)
703 m_pModel->endReset();
704 if (m_pLocationComboBox)
705 {
706 disconnect(m_pLocationComboBox, static_cast<void(QComboBox::*)(const QString&)>(&QComboBox::currentIndexChanged),
707 this, &UIGuestControlFileTable::sltLocationComboCurrentChange);
708 m_pLocationComboBox->clear();
709 connect(m_pLocationComboBox, static_cast<void(QComboBox::*)(const QString&)>(&QComboBox::currentIndexChanged),
710 this, &UIGuestControlFileTable::sltLocationComboCurrentChange);
711 }
712}
713
714void UIGuestControlFileTable::emitLogOutput(const QString& strOutput, FileManagerLogType eLogType)
715{
716 emit sigLogOutput(strOutput, eLogType);
717}
718
719void UIGuestControlFileTable::prepareObjects()
720{
721 m_pMainLayout = new QGridLayout();
722 if (!m_pMainLayout)
723 return;
724 m_pMainLayout->setSpacing(0);
725 m_pMainLayout->setContentsMargins(0, 0, 0, 0);
726 setLayout(m_pMainLayout);
727
728 m_pToolBar = new UIToolBar;
729 if (m_pToolBar)
730 {
731 m_pMainLayout->addWidget(m_pToolBar, 0, 0, 1, 5);
732 }
733
734 m_pLocationLabel = new QILabel;
735 if (m_pLocationLabel)
736 {
737 m_pMainLayout->addWidget(m_pLocationLabel, 1, 0, 1, 1);
738 }
739
740 m_pLocationComboBox = new QComboBox;
741 if (m_pLocationComboBox)
742 {
743 m_pMainLayout->addWidget(m_pLocationComboBox, 1, 1, 1, 4);
744 m_pLocationComboBox->setEditable(false);
745 connect(m_pLocationComboBox, static_cast<void(QComboBox::*)(const QString&)>(&QComboBox::currentIndexChanged),
746 this, &UIGuestControlFileTable::sltLocationComboCurrentChange);
747 }
748
749
750 m_pModel = new UIGuestControlFileModel(this);
751 if (!m_pModel)
752 return;
753
754 m_pProxyModel = new UIGuestControlFileProxyModel(this);
755 if (!m_pProxyModel)
756 return;
757 m_pProxyModel->setSourceModel(m_pModel);
758
759 m_pView = new UIGuestControlFileView(this);
760 if (m_pView)
761 {
762 m_pMainLayout->addWidget(m_pView, 2, 0, 5, 5);
763 m_pView->setModel(m_pProxyModel);
764 m_pView->setItemDelegate(new UIFileDelegate);
765 m_pView->setSortingEnabled(true);
766 m_pView->sortByColumn(0, Qt::AscendingOrder);
767
768 connect(m_pView, &UIGuestControlFileView::doubleClicked,
769 this, &UIGuestControlFileTable::sltItemDoubleClicked);
770 connect(m_pView, &UIGuestControlFileView::clicked,
771 this, &UIGuestControlFileTable::sltItemClicked);
772 connect(m_pView, &UIGuestControlFileView::sigSelectionChanged,
773 this, &UIGuestControlFileTable::sltSelectionChanged);
774 connect(m_pView, &UIGuestControlFileView::customContextMenuRequested,
775 this, &UIGuestControlFileTable::sltCreateFileViewContextMenu);
776
777 }
778 m_pSearchLineEdit = new QILineEdit;
779 if (m_pSearchLineEdit)
780 {
781 m_pMainLayout->addWidget(m_pSearchLineEdit, 8, 0, 1, 5);
782 m_pSearchLineEdit->hide();
783 m_pSearchLineEdit->setClearButtonEnabled(true);
784 connect(m_pSearchLineEdit, &QLineEdit::textChanged,
785 this, &UIGuestControlFileTable::sltSearchTextChanged);
786 }
787}
788
789void UIGuestControlFileTable::updateCurrentLocationEdit(const QString& strLocation)
790{
791 if (!m_pLocationComboBox)
792 return;
793 int itemIndex = m_pLocationComboBox->findText(strLocation,
794 Qt::MatchExactly | Qt::MatchCaseSensitive);
795 if (itemIndex == -1)
796 {
797 m_pLocationComboBox->insertItem(m_pLocationComboBox->count(), strLocation);
798 itemIndex = m_pLocationComboBox->count() - 1;
799 }
800 m_pLocationComboBox->setCurrentIndex(itemIndex);
801}
802
803void UIGuestControlFileTable::changeLocation(const QModelIndex &index)
804{
805 if (!index.isValid() || !m_pView)
806 return;
807 m_pView->setRootIndex(m_pProxyModel->mapFromSource(index));
808 m_pView->clearSelection();
809
810 UIFileTableItem *item = static_cast<UIFileTableItem*>(index.internalPointer());
811 if (item)
812 {
813 updateCurrentLocationEdit(item->path());
814 }
815 /** @todo check if we really need this and if not remove it */
816 //m_pModel->signalUpdate();
817}
818
819void UIGuestControlFileTable::initializeFileTree()
820{
821 if (m_pRootItem)
822 reset();
823
824 /* Root item: */
825 const QString startPath("/");
826 QVector<QVariant> headData;
827 headData.resize(UIGuestControlFileModelColumn_Max);
828 headData[UIGuestControlFileModelColumn_Name] = "Name";
829 headData[UIGuestControlFileModelColumn_Size] = "Size";
830 headData[UIGuestControlFileModelColumn_ChangeTime] = "Change Time";
831 headData[UIGuestControlFileModelColumn_Owner] = "Owner";
832 headData[UIGuestControlFileModelColumn_Permissions] = "Permissions";
833 m_pRootItem = new UIFileTableItem(headData, 0, FileObjectType_Directory);
834 UIFileTableItem* startItem = new UIFileTableItem(createTreeItemData(startPath, 4096, QDateTime(),
835 "" /* owner */, "" /* permissions */),
836 m_pRootItem, FileObjectType_Directory);
837 startItem->setPath(startPath);
838 m_pRootItem->appendChild(startItem);
839 startItem->setIsOpened(false);
840 populateStartDirectory(startItem);
841
842 m_pModel->signalUpdate();
843 updateCurrentLocationEdit(startPath);
844 m_pView->setRootIndex(m_pProxyModel->mapFromSource(m_pModel->rootIndex()));
845}
846
847void UIGuestControlFileTable::populateStartDirectory(UIFileTableItem *startItem)
848{
849 determineDriveLetters();
850 if (m_driveLetterList.isEmpty())
851 {
852 /* Read the root directory and get the list: */
853 readDirectory(startItem->path(), startItem, true);
854 }
855 else
856 {
857 for (int i = 0; i < m_driveLetterList.size(); ++i)
858 {
859 UIFileTableItem* driveItem = new UIFileTableItem(createTreeItemData(m_driveLetterList[i], 4096,
860 QDateTime(), QString(), QString()),
861 startItem, FileObjectType_Directory);
862 driveItem->setPath(m_driveLetterList[i]);
863 startItem->appendChild(driveItem);
864 driveItem->setIsOpened(false);
865 driveItem->setIsDriveItem(true);
866 startItem->setIsOpened(true);
867 }
868 }
869}
870
871void UIGuestControlFileTable::insertItemsToTree(QMap<QString,UIFileTableItem*> &map,
872 UIFileTableItem *parent, bool isDirectoryMap, bool isStartDir)
873{
874 if (parent)
875
876 /* Make sure we have an item representing up directory, and make sure it is not there for the start dir: */
877 if (isDirectoryMap)
878 {
879 if (!map.contains(UIGuestControlFileModel::strUpDirectoryString) && !isStartDir)
880 {
881 QVector<QVariant> data;
882 UIFileTableItem *item = new UIFileTableItem(createTreeItemData(UIGuestControlFileModel::strUpDirectoryString, 4096,
883 QDateTime(), QString(), QString())
884 , parent, FileObjectType_Directory);
885 item->setIsOpened(false);
886 map.insert(UIGuestControlFileModel::strUpDirectoryString, item);
887 }
888 else if (map.contains(UIGuestControlFileModel::strUpDirectoryString) && isStartDir)
889 {
890 map.remove(UIGuestControlFileModel::strUpDirectoryString);
891 }
892 }
893 for (QMap<QString,UIFileTableItem*>::const_iterator iterator = map.begin();
894 iterator != map.end(); ++iterator)
895 {
896 if (iterator.key() == "." || iterator.key().isEmpty())
897 continue;
898 parent->appendChild(iterator.value());
899 }
900}
901
902void UIGuestControlFileTable::sltItemDoubleClicked(const QModelIndex &index)
903{
904 if (!index.isValid() || !m_pModel || !m_pView)
905 return;
906 QModelIndex nIndex = m_pProxyModel ? m_pProxyModel->mapToSource(index) : index;
907 goIntoDirectory(nIndex);
908}
909
910void UIGuestControlFileTable::sltItemClicked(const QModelIndex &index)
911{
912 Q_UNUSED(index);
913 disableSelectionSearch();
914}
915
916void UIGuestControlFileTable::sltGoUp()
917{
918 if (!m_pView || !m_pModel)
919 return;
920 QModelIndex currentRoot = currentRootIndex();
921
922 if (!currentRoot.isValid())
923 return;
924 if (currentRoot != m_pModel->rootIndex())
925 {
926 QModelIndex parentIndex = currentRoot.parent();
927 if (parentIndex.isValid())
928 {
929 changeLocation(currentRoot.parent());
930 m_pView->selectRow(currentRoot.row());
931 }
932 }
933}
934
935void UIGuestControlFileTable::sltGoHome()
936{
937 goToHomeDirectory();
938}
939
940void UIGuestControlFileTable::sltRefresh()
941{
942 refresh();
943}
944
945void UIGuestControlFileTable::goIntoDirectory(const QModelIndex &itemIndex)
946{
947 if (!m_pModel)
948 return;
949
950 /* Make sure the colum is 0: */
951 QModelIndex index = m_pModel->index(itemIndex.row(), 0, itemIndex.parent());
952 if (!index.isValid())
953 return;
954
955 UIFileTableItem *item = static_cast<UIFileTableItem*>(index.internalPointer());
956 if (!item)
957 return;
958
959 /* check if we need to go up: */
960 if (item->isUpDirectory())
961 {
962 QModelIndex parentIndex = m_pModel->parent(m_pModel->parent(index));
963 if (parentIndex.isValid())
964 changeLocation(parentIndex);
965 return;
966 }
967
968 if (!item->isDirectory())
969 return;
970 if (!item->isOpened())
971 readDirectory(item->path(),item);
972 changeLocation(index);
973}
974
975void UIGuestControlFileTable::goIntoDirectory(const QStringList &pathTrail)
976{
977 UIFileTableItem *parent = getStartDirectoryItem();
978
979 for(int i = 0; i < pathTrail.size(); ++i)
980 {
981 if (!parent)
982 return;
983 /* Make sure parent is already opened: */
984 if (!parent->isOpened())
985 readDirectory(parent->path(), parent, parent == getStartDirectoryItem());
986 /* search the current path item among the parent's children: */
987 UIFileTableItem *item = parent->child(pathTrail.at(i));
988 if (!item)
989 return;
990 parent = item;
991 }
992 if (!parent)
993 return;
994 if (!parent->isOpened())
995 readDirectory(parent->path(), parent, parent == getStartDirectoryItem());
996 goIntoDirectory(parent);
997}
998
999void UIGuestControlFileTable::goIntoDirectory(UIFileTableItem *item)
1000{
1001 if (!item || !m_pModel)
1002 return;
1003 goIntoDirectory(m_pModel->index(item));
1004}
1005
1006UIFileTableItem* UIGuestControlFileTable::indexData(const QModelIndex &index) const
1007{
1008 if (!index.isValid())
1009 return 0;
1010 return static_cast<UIFileTableItem*>(index.internalPointer());
1011}
1012
1013void UIGuestControlFileTable::refresh()
1014{
1015 if (!m_pView || !m_pModel)
1016 return;
1017 QModelIndex currentIndex = currentRootIndex();
1018
1019 UIFileTableItem *treeItem = indexData(currentIndex);
1020 if (!treeItem)
1021 return;
1022 bool isRootDir = (m_pModel->rootIndex() == currentIndex);
1023 m_pModel->beginReset();
1024 /* For now we clear the whole subtree (that isrecursively) which is an overkill: */
1025 treeItem->clearChildren();
1026 if (isRootDir)
1027 populateStartDirectory(treeItem);
1028 else
1029 readDirectory(treeItem->path(), treeItem, isRootDir);
1030 m_pModel->endReset();
1031 m_pView->setRootIndex(m_pProxyModel->mapFromSource(currentIndex));
1032 setSelectionDependentActionsEnabled(m_pView->hasSelection());
1033}
1034
1035void UIGuestControlFileTable::relist()
1036{
1037 if (!m_pProxyModel)
1038 return;
1039 m_pProxyModel->invalidate();
1040}
1041
1042void UIGuestControlFileTable::sltDelete()
1043{
1044 if (!checkIfDeleteOK())
1045 return;
1046
1047 if (!m_pView || !m_pModel)
1048 return;
1049
1050 if (!m_pView || !m_pModel)
1051 return;
1052 QItemSelectionModel *selectionModel = m_pView->selectionModel();
1053 if (!selectionModel)
1054 return;
1055
1056 QModelIndexList selectedItemIndices = selectionModel->selectedRows();
1057 for(int i = 0; i < selectedItemIndices.size(); ++i)
1058 {
1059 QModelIndex index =
1060 m_pProxyModel ? m_pProxyModel->mapToSource(selectedItemIndices.at(i)) : selectedItemIndices.at(i);
1061 deleteByIndex(index);
1062 }
1063 /** @todo dont refresh here, just delete the rows and update the table view: */
1064 refresh();
1065}
1066
1067void UIGuestControlFileTable::sltRename()
1068{
1069 if (!m_pView)
1070 return;
1071 QItemSelectionModel *selectionModel = m_pView->selectionModel();
1072 if (!selectionModel)
1073 return;
1074
1075 QModelIndexList selectedItemIndices = selectionModel->selectedRows();
1076 if (selectedItemIndices.size() == 0)
1077 return;
1078 QModelIndex modelIndex =
1079 m_pProxyModel ? m_pProxyModel->mapToSource(selectedItemIndices.at(0)) : selectedItemIndices.at(0);
1080 UIFileTableItem *item = indexData(modelIndex);
1081 if (!item || item->isUpDirectory())
1082 return;
1083 m_pView->edit(selectedItemIndices.at(0));
1084}
1085
1086void UIGuestControlFileTable::sltCreateNewDirectory()
1087{
1088 if (!m_pModel || !m_pView)
1089 return;
1090 QModelIndex currentIndex = currentRootIndex();
1091 if (!currentIndex.isValid())
1092 return;
1093 UIFileTableItem *item = static_cast<UIFileTableItem*>(currentIndex.internalPointer());
1094 if (!item)
1095 return;
1096
1097 QString newDirectoryName = getNewDirectoryName();
1098 if (newDirectoryName.isEmpty())
1099 return;
1100
1101 if (createDirectory(item->path(), newDirectoryName))
1102 {
1103 /** @todo instead of refreshing here (an overkill) just add the
1104 rows and update the tabel view: */
1105 sltRefresh();
1106 }
1107}
1108
1109void UIGuestControlFileTable::sltCopy()
1110{
1111
1112 m_copyCutBuffer = selectedItemPathList();
1113 // if (!m_copyCutBuffer.isEmpty())
1114 // m_pPaste->setEnabled(true);
1115 // else
1116 // m_pPaste->setEnabled(false);
1117}
1118
1119void UIGuestControlFileTable::sltCut()
1120{
1121 m_copyCutBuffer = selectedItemPathList();
1122 // if (!m_copyCutBuffer.isEmpty())
1123 // m_pPaste->setEnabled(true);
1124 // else
1125 // m_pPaste->setEnabled(false);
1126}
1127
1128void UIGuestControlFileTable::sltPaste()
1129{
1130 // paste them
1131 m_copyCutBuffer.clear();
1132 //m_pPaste->setEnabled(false);
1133}
1134
1135void UIGuestControlFileTable::sltShowProperties()
1136{
1137 showProperties();
1138}
1139
1140void UIGuestControlFileTable::sltSelectionChanged(const QItemSelection & selected, const QItemSelection & deselected)
1141{
1142 Q_UNUSED(selected);
1143 Q_UNUSED(deselected);
1144 setSelectionDependentActionsEnabled(m_pView->hasSelection());
1145}
1146
1147void UIGuestControlFileTable::sltLocationComboCurrentChange(const QString &strLocation)
1148{
1149 QString comboLocation(UIPathOperations::sanitize(strLocation));
1150 if (comboLocation == currentDirectoryPath())
1151 return;
1152 goIntoDirectory(UIPathOperations::pathTrail(comboLocation));
1153}
1154
1155void UIGuestControlFileTable::sltSelectAll()
1156{
1157 if (!m_pModel || !m_pView)
1158 return;
1159 m_pView->selectAll();
1160 deSelectUpDirectoryItem();
1161}
1162
1163void UIGuestControlFileTable::sltInvertSelection()
1164{
1165 setSelectionForAll(QItemSelectionModel::Toggle | QItemSelectionModel::Rows);
1166 deSelectUpDirectoryItem();
1167}
1168
1169void UIGuestControlFileTable::sltSearchTextChanged(const QString &strText)
1170{
1171 performSelectionSearch(strText);
1172}
1173
1174void UIGuestControlFileTable::sltCreateFileViewContextMenu(const QPoint &point)
1175{
1176 QWidget *pSender = qobject_cast<QWidget*>(sender());
1177 if (!pSender)
1178 return;
1179 createFileViewContextMenu(pSender, point);
1180}
1181
1182void UIGuestControlFileTable::deSelectUpDirectoryItem()
1183{
1184 if (!m_pView)
1185 return;
1186 QItemSelectionModel *pSelectionModel = m_pView->selectionModel();
1187 if (!pSelectionModel)
1188 return;
1189 QModelIndex currentRoot = currentRootIndex();
1190 if (!currentRoot.isValid())
1191 return;
1192
1193 /* Make sure that "up directory item" (if exists) is deselected: */
1194 for (int i = 0; i < m_pModel->rowCount(currentRoot); ++i)
1195 {
1196 QModelIndex index = m_pModel->index(i, 0, currentRoot);
1197 if (!index.isValid())
1198 continue;
1199
1200 UIFileTableItem *item = static_cast<UIFileTableItem*>(index.internalPointer());
1201 if (item && item->isUpDirectory())
1202 {
1203 QModelIndex indexToDeselect = m_pProxyModel ? m_pProxyModel->mapFromSource(index) : index;
1204 pSelectionModel->select(indexToDeselect, QItemSelectionModel::Deselect | QItemSelectionModel::Rows);
1205 }
1206 }
1207}
1208
1209void UIGuestControlFileTable::setSelectionForAll(QItemSelectionModel::SelectionFlags flags)
1210{
1211 if (!m_pView)
1212 return;
1213 QItemSelectionModel *pSelectionModel = m_pView->selectionModel();
1214 if (!pSelectionModel)
1215 return;
1216 QModelIndex currentRoot = currentRootIndex();
1217 if (!currentRoot.isValid())
1218 return;
1219
1220 for (int i = 0; i < m_pModel->rowCount(currentRoot); ++i)
1221 {
1222 QModelIndex index = m_pModel->index(i, 0, currentRoot);
1223 if (!index.isValid())
1224 continue;
1225 QModelIndex indexToSelect = m_pProxyModel ? m_pProxyModel->mapFromSource(index) : index;
1226 pSelectionModel->select(indexToSelect, flags);
1227 }
1228}
1229
1230void UIGuestControlFileTable::setSelection(const QModelIndex &indexInProxyModel)
1231{
1232 if (!m_pView)
1233 return;
1234 QItemSelectionModel *selectionModel = m_pView->selectionModel();
1235 if (!selectionModel)
1236 return;
1237 selectionModel->select(indexInProxyModel, QItemSelectionModel::Current | QItemSelectionModel::Rows | QItemSelectionModel::Select);
1238 m_pView->scrollTo(indexInProxyModel, QAbstractItemView::EnsureVisible);
1239}
1240
1241void UIGuestControlFileTable::deleteByIndex(const QModelIndex &itemIndex)
1242{
1243 UIFileTableItem *treeItem = indexData(itemIndex);
1244 if (!treeItem)
1245 return;
1246 deleteByItem(treeItem);
1247}
1248
1249void UIGuestControlFileTable::retranslateUi()
1250{
1251}
1252
1253bool UIGuestControlFileTable::eventFilter(QObject *pObject, QEvent *pEvent) /* override */
1254{
1255 Q_UNUSED(pObject);
1256 if (pEvent->type() == QEvent::KeyPress)
1257 {
1258 QKeyEvent *pKeyEvent = dynamic_cast<QKeyEvent*>(pEvent);
1259 if (pKeyEvent)
1260 {
1261 if (pKeyEvent->key() == Qt::Key_Enter || pKeyEvent->key() == Qt::Key_Return)
1262 {
1263 if (m_pView && m_pModel)
1264 {
1265 /* Get the selected item. If there are 0 or more than 1 selection do nothing: */
1266 QItemSelectionModel *selectionModel = m_pView->selectionModel();
1267 if (selectionModel)
1268 {
1269 QModelIndexList selectedItemIndices = selectionModel->selectedRows();
1270 if (selectedItemIndices.size() == 1 && m_pModel)
1271 goIntoDirectory( m_pProxyModel->mapToSource(selectedItemIndices.at(0)));
1272 }
1273 }
1274 return true;
1275 }
1276 else if (pKeyEvent->key() == Qt::Key_Delete)
1277 {
1278 sltDelete();
1279 return true;
1280 }
1281 else if (pKeyEvent->key() == Qt::Key_Backspace)
1282 {
1283 sltGoUp();
1284 return true;
1285 }
1286 else if (pKeyEvent->text().length() == 1 && pKeyEvent->text().at(0).unicode() <= 127)
1287 {
1288 if (m_pSearchLineEdit)
1289 {
1290 m_pSearchLineEdit->show();
1291 QString strText = m_pSearchLineEdit->text();
1292 strText.append(pKeyEvent->text());
1293 m_pSearchLineEdit->setText(strText);
1294 }
1295 }
1296 }
1297 }
1298
1299 return false;
1300}
1301
1302UIFileTableItem *UIGuestControlFileTable::getStartDirectoryItem()
1303{
1304 if (!m_pRootItem)
1305 return 0;
1306 if (m_pRootItem->childCount() <= 0)
1307 return 0;
1308 return m_pRootItem->child(0);
1309}
1310
1311
1312QString UIGuestControlFileTable::getNewDirectoryName()
1313{
1314 UIStringInputDialog *dialog = new UIStringInputDialog();
1315 if (dialog->execute())
1316 {
1317 QString strDialog = dialog->getString();
1318 delete dialog;
1319 return strDialog;
1320 }
1321 delete dialog;
1322 return QString();
1323}
1324
1325QString UIGuestControlFileTable::currentDirectoryPath() const
1326{
1327 if (!m_pView)
1328 return QString();
1329 QModelIndex currentRoot = currentRootIndex();
1330 if (!currentRoot.isValid())
1331 return QString();
1332 UIFileTableItem *item = static_cast<UIFileTableItem*>(currentRoot.internalPointer());
1333 if (!item)
1334 return QString();
1335 /* be paranoid: */
1336 if (!item->isDirectory())
1337 return QString();
1338 return item->path();
1339}
1340
1341QStringList UIGuestControlFileTable::selectedItemPathList()
1342{
1343 QItemSelectionModel *selectionModel = m_pView->selectionModel();
1344 if (!selectionModel)
1345 return QStringList();
1346
1347 QStringList pathList;
1348 QModelIndexList selectedItemIndices = selectionModel->selectedRows();
1349 for(int i = 0; i < selectedItemIndices.size(); ++i)
1350 {
1351 QModelIndex index =
1352 m_pProxyModel ? m_pProxyModel->mapToSource(selectedItemIndices.at(i)) : selectedItemIndices.at(i);
1353 UIFileTableItem *item = static_cast<UIFileTableItem*>(index.internalPointer());
1354 if (!item)
1355 continue;
1356 pathList.push_back(item->path());
1357 }
1358 return pathList;
1359}
1360
1361CGuestFsObjInfo UIGuestControlFileTable::guestFsObjectInfo(const QString& path, CGuestSession &comGuestSession) const
1362{
1363 if (comGuestSession.isNull())
1364 return CGuestFsObjInfo();
1365 CGuestFsObjInfo comFsObjInfo = comGuestSession.FsObjQueryInfo(path, true /*aFollowSymlinks*/);
1366 if (!comFsObjInfo.isOk())
1367 return CGuestFsObjInfo();
1368 return comFsObjInfo;
1369}
1370
1371void UIGuestControlFileTable::setSelectionDependentActionsEnabled(bool fIsEnabled)
1372{
1373 foreach (QAction *pAction, m_selectionDependentActions)
1374 {
1375 pAction->setEnabled(fIsEnabled);
1376 }
1377}
1378
1379
1380QVector<QVariant> UIGuestControlFileTable::createTreeItemData(const QString &strName, ULONG64 size, const QDateTime &changeTime,
1381 const QString &strOwner, const QString &strPermissions)
1382{
1383 QVector<QVariant> data;
1384 data.resize(UIGuestControlFileModelColumn_Max);
1385 data[UIGuestControlFileModelColumn_Name] = strName;
1386 data[UIGuestControlFileModelColumn_Size] = (qulonglong)size;
1387 data[UIGuestControlFileModelColumn_ChangeTime] = changeTime;
1388 data[UIGuestControlFileModelColumn_Owner] = strOwner;
1389 data[UIGuestControlFileModelColumn_Permissions] = strPermissions;
1390 return data;
1391}
1392
1393QString UIGuestControlFileTable::fileTypeString(FileObjectType type)
1394{
1395 QString strType("Unknown");
1396 switch(type)
1397 {
1398 case FileObjectType_File:
1399 strType = "File";
1400 break;
1401 case FileObjectType_Directory:
1402 strType = "Directory";
1403 break;
1404 case FileObjectType_SymLink:
1405 strType = "Symbolic Link";
1406 break;
1407 case FileObjectType_Other:
1408 strType = "Other";
1409 break;
1410
1411 case FileObjectType_Unknown:
1412 default:
1413 break;
1414 }
1415 return strType;
1416}
1417
1418/* static */ QString UIGuestControlFileTable::humanReadableSize(ULONG64 size)
1419{
1420 int i = 0;
1421 double dSize = size;
1422 const char* units[] = {" B", " kB", " MB", " GB", " TB", " PB", " EB", " ZB", " YB"};
1423 while (size > m_iKiloByte) {
1424 size /= m_iKiloByte;
1425 dSize /= (double) m_iKiloByte;
1426 i++;
1427 }
1428 if (i > 8)
1429 return QString();
1430
1431 QString strResult(QString::number(dSize, 'f', 2));
1432 strResult += units[i];
1433 return strResult;
1434}
1435
1436void UIGuestControlFileTable::continueWithMove(const QUuid &progressId)
1437{
1438 deleteByPath(m_deleteAfterCopyCache.value(progressId, QStringList()));
1439}
1440
1441void UIGuestControlFileTable::sltReceiveDirectoryStatistics(UIDirectoryStatistics statistics)
1442{
1443 if (!m_pPropertiesDialog)
1444 return;
1445 m_pPropertiesDialog->addDirectoryStatistics(statistics);
1446}
1447
1448QModelIndex UIGuestControlFileTable::currentRootIndex() const
1449{
1450 if (!m_pView)
1451 return QModelIndex();
1452 if (!m_pProxyModel)
1453 return m_pView->rootIndex();
1454 return m_pProxyModel->mapToSource(m_pView->rootIndex());
1455}
1456
1457void UIGuestControlFileTable::performSelectionSearch(const QString &strSearchText)
1458{
1459 if (!m_pProxyModel | !m_pView || strSearchText.isEmpty())
1460 return;
1461
1462 int rowCount = m_pProxyModel->rowCount(m_pView->rootIndex());
1463 UIFileTableItem *pFoundItem = 0;
1464 QModelIndex index;
1465 for (int i = 0; i < rowCount && !pFoundItem; ++i)
1466 {
1467 index = m_pProxyModel->index(i, 0, m_pView->rootIndex());
1468 if (!index.isValid())
1469 continue;
1470 pFoundItem = static_cast<UIFileTableItem*>(m_pProxyModel->mapToSource(index).internalPointer());
1471 if (!pFoundItem)
1472 continue;
1473 const QString &strName = pFoundItem->name();
1474 if (!strName.startsWith(m_pSearchLineEdit->text(), Qt::CaseInsensitive))
1475 pFoundItem = 0;
1476 }
1477 if (pFoundItem)
1478 {
1479 /* Deselect anything that is already selected: */
1480 m_pView->clearSelection();
1481 setSelection(index);
1482 }
1483}
1484
1485void UIGuestControlFileTable::disableSelectionSearch()
1486{
1487 if (!m_pSearchLineEdit)
1488 return;
1489 m_pSearchLineEdit->blockSignals(true);
1490 m_pSearchLineEdit->clear();
1491 m_pSearchLineEdit->hide();
1492 m_pSearchLineEdit->blockSignals(false);
1493}
1494
1495bool UIGuestControlFileTable::checkIfDeleteOK()
1496{
1497 UIGuestControlFileManagerSettings *pFileManagerSettings = UIGuestControlFileManagerSettings::instance();
1498 if (!pFileManagerSettings)
1499 return true;
1500 if (!pFileManagerSettings->bAskDeleteConfirmation)
1501 return true;
1502 UIFileDeleteConfirmationDialog *pDialog =
1503 new UIFileDeleteConfirmationDialog(this);
1504
1505
1506 bool fContinueWithDelete = (pDialog->execute() == QDialog::Accepted);
1507
1508 bool bAskNextTime = pDialog->askDeleteConfirmationNextTime();
1509
1510 /* Update the file manager settings only if it is necessary: */
1511 if (pFileManagerSettings->bAskDeleteConfirmation != bAskNextTime)
1512 {
1513 pFileManagerSettings->bAskDeleteConfirmation = bAskNextTime;
1514 /* Notify file manager settings panel so that the check box there is updated: */
1515 emit sigDeleteConfirmationSettingChanged();
1516 }
1517
1518 delete pDialog;
1519
1520 return fContinueWithDelete;
1521
1522}
1523
1524#include "UIGuestControlFileTable.moc"
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette