VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/guestctrl/UIFileManagerTable.cpp@ 103977

Last change on this file since 103977 was 103710, checked in by vboxsync, 9 months ago

FE/Qt: Get rid of unwanted UICommon includes across whole the GUI.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 44.9 KB
Line 
1/* $Id: UIFileManagerTable.cpp 103710 2024-03-06 16:53:27Z vboxsync $ */
2/** @file
3 * VBox Qt GUI - UIFileManagerTable class implementation.
4 */
5
6/*
7 * Copyright (C) 2016-2023 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * SPDX-License-Identifier: GPL-3.0-only
26 */
27
28/* Qt includes: */
29#include <QAction>
30#include <QCheckBox>
31#include <QHBoxLayout>
32#include <QHeaderView>
33#include <QItemDelegate>
34#include <QGridLayout>
35#include <QTextEdit>
36
37/* GUI includes: */
38#include "QIDialog.h"
39#include "QIDialogButtonBox.h"
40#include "QILabel.h"
41#include "QILineEdit.h"
42#include "QIToolBar.h"
43#include "UIActionPool.h"
44#include "UIFileSystemModel.h"
45#include "UIErrorString.h"
46#include "UIFileManager.h"
47#include "UIFileManagerTable.h"
48#include "UIFileTableNavigationWidget.h"
49#include "UIIconPool.h"
50#include "UIPathOperations.h"
51#include "UITranslator.h"
52
53/* COM includes: */
54#include "CFsObjInfo.h"
55#include "CGuestFsObjInfo.h"
56#include "CGuestDirectory.h"
57#include "CProgress.h"
58
59
60/*********************************************************************************************************************************
61* UIGuestControlFileView definition. *
62*********************************************************************************************************************************/
63
64/** Using QITableView causes the following problem when I click on the table items
65 Qt WARNING: Cannot creat accessible child interface for object: UIGuestControlFileView.....
66 so for now subclass QTableView */
67class UIGuestControlFileView : public QTableView
68{
69
70 Q_OBJECT;
71
72signals:
73
74 void sigSelectionChanged(const QItemSelection & selected, const QItemSelection & deselected);
75 /* Emitted upon mouse double click while Alt key is pressed. */
76 void sigAltDoubleClick();
77
78public:
79
80 UIGuestControlFileView(QWidget * parent = 0);
81 bool hasSelection() const;
82 bool isInEditState() const;
83
84protected:
85
86 virtual void selectionChanged(const QItemSelection & selected, const QItemSelection & deselected) override;
87 virtual void mouseDoubleClickEvent(QMouseEvent *event) override;
88 virtual void mousePressEvent(QMouseEvent *event) override;
89
90private:
91
92 void configure();
93 QWidget *m_pParent;
94};
95
96
97/*********************************************************************************************************************************
98* UIFileDelegate definition. *
99*********************************************************************************************************************************/
100/** A QItemDelegate child class to disable dashed lines drawn around selected cells in QTableViews */
101class UIFileDelegate : public QItemDelegate
102{
103
104 Q_OBJECT;
105
106public:
107
108 UIFileDelegate(QObject *pParent)
109 : QItemDelegate(pParent){}
110
111protected:
112
113 virtual void drawFocus ( QPainter * /*painter*/, const QStyleOptionViewItem & /*option*/, const QRect & /*rect*/ ) const {}
114};
115
116
117/*********************************************************************************************************************************
118* UStringInputDialog definition. *
119*********************************************************************************************************************************/
120
121/** A QIDialog child including a line edit whose text exposed when the dialog is accepted */
122class UIStringInputDialog : public QIDialog
123{
124
125 Q_OBJECT;
126
127public:
128
129 UIStringInputDialog(QWidget *pParent = 0, Qt::WindowFlags enmFlags = Qt::WindowFlags());
130 QString getString() const;
131
132private:
133
134 QILineEdit *m_pLineEdit;
135};
136
137
138/*********************************************************************************************************************************
139* UIFileDeleteConfirmationDialog definition. *
140*********************************************************************************************************************************/
141
142/** A QIDialog child including a line edit whose text exposed when the dialog is accepted */
143class UIFileDeleteConfirmationDialog : public QIDialog
144{
145
146 Q_OBJECT;
147
148public:
149
150 UIFileDeleteConfirmationDialog(QWidget *pParent = 0, Qt::WindowFlags enmFlags = Qt::WindowFlags());
151 /** Returns whether m_pAskNextTimeCheckBox is checked or not. */
152 bool askDeleteConfirmationNextTime() const;
153
154private:
155
156 QCheckBox *m_pAskNextTimeCheckBox;
157 QILabel *m_pQuestionLabel;
158};
159
160
161/*********************************************************************************************************************************
162* UIHostDirectoryDiskUsageComputer implementation. *
163*********************************************************************************************************************************/
164
165UIDirectoryDiskUsageComputer::UIDirectoryDiskUsageComputer(QObject *parent, QStringList pathList)
166 :QThread(parent)
167 , m_pathList(pathList)
168 , m_fOkToContinue(true)
169{
170}
171
172void UIDirectoryDiskUsageComputer::run()
173{
174 for (int i = 0; i < m_pathList.size(); ++i)
175 directoryStatisticsRecursive(m_pathList[i], m_resultStatistics);
176}
177
178void UIDirectoryDiskUsageComputer::stopRecursion()
179{
180 m_mutex.lock();
181 m_fOkToContinue = false;
182 m_mutex.unlock();
183}
184
185bool UIDirectoryDiskUsageComputer::isOkToContinue() const
186{
187 return m_fOkToContinue;
188}
189
190
191/*********************************************************************************************************************************
192* UIGuestControlFileView implementation. *
193*********************************************************************************************************************************/
194
195UIGuestControlFileView::UIGuestControlFileView(QWidget *parent)
196 :QTableView(parent)
197 , m_pParent(parent)
198{
199 configure();
200}
201
202void UIGuestControlFileView::configure()
203{
204 setContextMenuPolicy(Qt::CustomContextMenu);
205 setShowGrid(false);
206 setSelectionBehavior(QAbstractItemView::SelectRows);
207 verticalHeader()->setVisible(false);
208 setEditTriggers(QAbstractItemView::NoEditTriggers);
209 /* Minimize the row height: */
210 verticalHeader()->setDefaultSectionSize(verticalHeader()->minimumSectionSize());
211 setAlternatingRowColors(true);
212 installEventFilter(m_pParent);
213}
214
215bool UIGuestControlFileView::hasSelection() const
216{
217 QItemSelectionModel *pSelectionModel = selectionModel();
218 if (!pSelectionModel)
219 return false;
220 return pSelectionModel->hasSelection();
221}
222
223bool UIGuestControlFileView::isInEditState() const
224{
225 return state() == QAbstractItemView::EditingState;
226}
227
228void UIGuestControlFileView::selectionChanged(const QItemSelection & selected, const QItemSelection & deselected)
229{
230 emit sigSelectionChanged(selected, deselected);
231 QTableView::selectionChanged(selected, deselected);
232}
233
234void UIGuestControlFileView::mousePressEvent(QMouseEvent *event)
235{
236 if (qApp->queryKeyboardModifiers() & Qt::AltModifier)
237 return;
238 QTableView::mousePressEvent(event);
239}
240
241void UIGuestControlFileView::mouseDoubleClickEvent(QMouseEvent *event)
242{
243 if (qApp->queryKeyboardModifiers() & Qt::AltModifier)
244 {
245 printf("dou\n");
246 emit sigAltDoubleClick();
247 return;
248 }
249 QTableView::mouseDoubleClickEvent(event);
250}
251
252
253/*********************************************************************************************************************************
254* UIFileStringInputDialog implementation. *
255*********************************************************************************************************************************/
256
257UIStringInputDialog::UIStringInputDialog(QWidget *pParent /* = 0 */, Qt::WindowFlags enmFlags /* = Qt::WindowFlags() */)
258 :QIDialog(pParent, enmFlags)
259{
260 QVBoxLayout *layout = new QVBoxLayout(this);
261 m_pLineEdit = new QILineEdit(this);
262 layout->addWidget(m_pLineEdit);
263
264 QIDialogButtonBox *pButtonBox =
265 new QIDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, this);
266 layout->addWidget(pButtonBox);
267 connect(pButtonBox, &QIDialogButtonBox::accepted, this, &UIStringInputDialog::accept);
268 connect(pButtonBox, &QIDialogButtonBox::rejected, this, &UIStringInputDialog::reject);
269}
270
271QString UIStringInputDialog::getString() const
272{
273 if (!m_pLineEdit)
274 return QString();
275 return m_pLineEdit->text();
276}
277
278
279/*********************************************************************************************************************************
280* UIPropertiesDialog implementation. *
281*********************************************************************************************************************************/
282
283UIPropertiesDialog::UIPropertiesDialog(QWidget *pParent, Qt::WindowFlags enmFlags)
284 :QIDialog(pParent, enmFlags)
285 , m_pMainLayout(new QVBoxLayout)
286 , m_pInfoEdit(new QTextEdit)
287{
288 setLayout(m_pMainLayout);
289
290 if (m_pMainLayout)
291 m_pMainLayout->addWidget(m_pInfoEdit);
292 if (m_pInfoEdit)
293 {
294 m_pInfoEdit->setReadOnly(true);
295 m_pInfoEdit->setFrameStyle(QFrame::NoFrame);
296 }
297 QIDialogButtonBox *pButtonBox =
298 new QIDialogButtonBox(QDialogButtonBox::Ok, Qt::Horizontal, this);
299 m_pMainLayout->addWidget(pButtonBox);
300 connect(pButtonBox, &QIDialogButtonBox::accepted, this, &UIStringInputDialog::accept);
301}
302
303void UIPropertiesDialog::setPropertyText(const QString &strProperty)
304{
305 if (!m_pInfoEdit)
306 return;
307 m_strProperty = strProperty;
308 m_pInfoEdit->setHtml(strProperty);
309}
310
311void UIPropertiesDialog::addDirectoryStatistics(UIDirectoryStatistics directoryStatistics)
312{
313 if (!m_pInfoEdit)
314 return;
315 // QString propertyString = m_pInfoEdit->toHtml();
316 // propertyString += "<b>Total Size:</b> " + QString::number(directoryStatistics.m_totalSize) + QString(" bytes");
317 // if (directoryStatistics.m_totalSize >= UIFileManagerTable::m_iKiloByte)
318 // propertyString += " (" + UIFileManagerTable::humanReadableSize(directoryStatistics.m_totalSize) + ")";
319 // propertyString += "<br/>";
320 // propertyString += "<b>File Count:</b> " + QString::number(directoryStatistics.m_uFileCount);
321
322 // m_pInfoEdit->setHtml(propertyString);
323
324 QString detailsString(m_strProperty);
325 detailsString += "<br/>";
326 detailsString += "<b>" + UIFileManager::tr("Total Size") + "</b> " +
327 QString::number(directoryStatistics.m_totalSize) + UIFileManager::tr(" bytes");
328 if (directoryStatistics.m_totalSize >= UIFileManagerTable::m_iKiloByte)
329 detailsString += " (" + UIFileManagerTable::humanReadableSize(directoryStatistics.m_totalSize) + ")";
330 detailsString += "<br/>";
331
332 detailsString += "<b>" + UIFileManager::tr("File Count") + ":</b> " +
333 QString::number(directoryStatistics.m_uFileCount);
334
335 m_pInfoEdit->setHtml(detailsString);
336}
337
338
339/*********************************************************************************************************************************
340* UIDirectoryStatistics implementation. *
341*********************************************************************************************************************************/
342
343UIDirectoryStatistics::UIDirectoryStatistics()
344 : m_totalSize(0)
345 , m_uFileCount(0)
346 , m_uDirectoryCount(0)
347 , m_uSymlinkCount(0)
348{
349}
350
351
352/*********************************************************************************************************************************
353* UIFileDeleteConfirmationDialog implementation. *
354*********************************************************************************************************************************/
355
356UIFileDeleteConfirmationDialog::UIFileDeleteConfirmationDialog(QWidget *pParent /* = 0 */, Qt::WindowFlags enmFlags /* = Qt::WindowFlags() */)
357 :QIDialog(pParent, enmFlags)
358 , m_pAskNextTimeCheckBox(0)
359 , m_pQuestionLabel(0)
360{
361 QVBoxLayout *pLayout = new QVBoxLayout(this);
362
363 m_pQuestionLabel = new QILabel;
364 if (m_pQuestionLabel)
365 {
366 pLayout->addWidget(m_pQuestionLabel);
367 m_pQuestionLabel->setText(UIFileManager::tr("Delete the selected file(s) and/or folder(s)"));
368 }
369
370 QIDialogButtonBox *pButtonBox =
371 new QIDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, this);
372 if (pButtonBox)
373 {
374 pLayout->addWidget(pButtonBox, 0, Qt::AlignCenter);
375 connect(pButtonBox, &QIDialogButtonBox::accepted, this, &UIStringInputDialog::accept);
376 connect(pButtonBox, &QIDialogButtonBox::rejected, this, &UIStringInputDialog::reject);
377 }
378
379 m_pAskNextTimeCheckBox = new QCheckBox;
380
381 if (m_pAskNextTimeCheckBox)
382 {
383 UIFileManagerOptions *pFileManagerOptions = UIFileManagerOptions::instance();
384 if (pFileManagerOptions)
385 m_pAskNextTimeCheckBox->setChecked(pFileManagerOptions->fAskDeleteConfirmation);
386
387 pLayout->addWidget(m_pAskNextTimeCheckBox);
388 m_pAskNextTimeCheckBox->setText(UIFileManager::tr("Ask for this confirmation next time"));
389 m_pAskNextTimeCheckBox->setToolTip(UIFileManager::tr("Delete confirmation can be "
390 "disabled/enabled also from the Options panel."));
391 }
392}
393
394bool UIFileDeleteConfirmationDialog::askDeleteConfirmationNextTime() const
395{
396 if (!m_pAskNextTimeCheckBox)
397 return true;
398 return m_pAskNextTimeCheckBox->isChecked();
399}
400
401
402/*********************************************************************************************************************************
403* UIFileManagerTable implementation. *
404*********************************************************************************************************************************/
405const unsigned UIFileManagerTable::m_iKiloByte = 1024; /**< Our kilo bytes are a power of two! (bird) */
406
407UIFileManagerTable::UIFileManagerTable(UIActionPool *pActionPool, QWidget *pParent /* = 0 */)
408 :QIWithRetranslateUI<QWidget>(pParent)
409 , m_eFileOperationType(FileOperationType_None)
410 , m_pLocationLabel(0)
411 , m_pPropertiesDialog(0)
412 , m_pActionPool(pActionPool)
413 , m_pToolBar(0)
414 , m_pMainLayout(0)
415 , m_pNavigationWidget(0)
416 , m_pModel(0)
417 , m_pView(0)
418 , m_pProxyModel(0)
419 , m_pathSeparator('/')
420 , m_pToolBarLayout(0)
421{
422 prepareObjects();
423}
424
425UIFileManagerTable::~UIFileManagerTable()
426{
427}
428
429void UIFileManagerTable::reset()
430{
431 if (m_pModel)
432 m_pModel->reset();
433
434 if (m_pNavigationWidget)
435 m_pNavigationWidget->reset();
436}
437
438void UIFileManagerTable::prepareObjects()
439{
440 m_pMainLayout = new QGridLayout();
441 if (!m_pMainLayout)
442 return;
443 m_pMainLayout->setSpacing(0);
444 m_pMainLayout->setContentsMargins(0, 0, 0, 0);
445 setLayout(m_pMainLayout);
446
447 m_pToolBarLayout = new QHBoxLayout;
448 if (m_pToolBarLayout)
449 {
450 m_pToolBarLayout->setSpacing(0);
451 m_pToolBarLayout->setContentsMargins(0, 0, 0, 0);
452
453 m_pToolBar = new QIToolBar;
454 if (m_pToolBar)
455 {
456 m_pToolBarLayout->addWidget(m_pToolBar);
457 m_sessionWidgets << m_pToolBar;
458 }
459
460 m_pMainLayout->addLayout(m_pToolBarLayout, 0, 0, 1, 7);
461 }
462
463 m_pLocationLabel = new QILabel;
464 if (m_pLocationLabel)
465 {
466 m_pMainLayout->addWidget(m_pLocationLabel, 1, 0, 1, 1);
467 m_sessionWidgets << m_pLocationLabel;
468 }
469
470 m_pNavigationWidget = new UIFileTableNavigationWidget;
471 if (m_pNavigationWidget)
472 {
473 m_pNavigationWidget->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Maximum);
474 connect(m_pNavigationWidget, &UIFileTableNavigationWidget::sigPathChanged,
475 this, &UIFileManagerTable::sltHandleNavigationWidgetPathChange);
476 connect(m_pNavigationWidget, &UIFileTableNavigationWidget::sigHistoryListChanged,
477 this, &UIFileManagerTable::sltHandleNavigationWidgetHistoryListChanged);
478 m_pMainLayout->addWidget(m_pNavigationWidget, 1, 1, 1, 6);
479 m_sessionWidgets << m_pNavigationWidget;
480 }
481
482 m_pModel = new UIFileSystemModel(this);
483 if (!m_pModel)
484 return;
485
486 connect(m_pModel, &UIFileSystemModel::sigItemRenamed,
487 this, &UIFileManagerTable::sltHandleItemRenameAttempt);
488
489 m_pProxyModel = new UIFileSystemProxyModel(this);
490 if (!m_pProxyModel)
491 return;
492 m_pProxyModel->setSourceModel(m_pModel);
493
494 m_pView = new UIGuestControlFileView(this);
495 if (m_pView)
496 {
497 m_pView->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::MinimumExpanding);
498 m_pMainLayout->addWidget(m_pView, 2, 0, 5, 7);
499
500 QHeaderView *pHorizontalHeader = m_pView->horizontalHeader();
501 if (pHorizontalHeader)
502 {
503 pHorizontalHeader->setHighlightSections(false);
504 pHorizontalHeader->setSectionResizeMode(QHeaderView::ResizeToContents);
505 pHorizontalHeader->setStretchLastSection(true);
506 }
507
508 m_pView->setModel(m_pProxyModel);
509 m_pView->setItemDelegate(new UIFileDelegate(this));
510 m_pView->setSortingEnabled(true);
511 m_pView->sortByColumn(0, Qt::AscendingOrder);
512
513 connect(m_pView, &UIGuestControlFileView::doubleClicked,
514 this, &UIFileManagerTable::sltItemDoubleClicked);
515 connect(m_pView, &UIGuestControlFileView::sigAltDoubleClick,
516 this, &UIFileManagerTable::sltAltDoubleClick);
517 connect(m_pView, &UIGuestControlFileView::clicked,
518 this, &UIFileManagerTable::sltItemClicked);
519 connect(m_pView, &UIGuestControlFileView::sigSelectionChanged,
520 this, &UIFileManagerTable::sltSelectionChanged);
521 connect(m_pView, &UIGuestControlFileView::customContextMenuRequested,
522 this, &UIFileManagerTable::sltCreateFileViewContextMenu);
523 m_pView->hideColumn(UIFileSystemModelData_LocalPath);
524 m_pView->hideColumn(UIFileSystemModelData_ISOFilePath);
525 m_pView->hideColumn(UIFileSystemModelData_RemovedFromVISO);
526 m_pView->hideColumn(UIFileSystemModelData_DescendantRemovedFromVISO);
527
528 m_sessionWidgets << m_pView;
529 }
530
531 m_pSearchLineEdit = new QILineEdit;
532 if (m_pSearchLineEdit)
533 {
534 m_pMainLayout->addWidget(m_pSearchLineEdit, 8, 0, 1, 7);
535 m_pSearchLineEdit->hide();
536 m_pSearchLineEdit->setClearButtonEnabled(true);
537 m_searchLineUnmarkColor = m_pSearchLineEdit->palette().color(QPalette::Base);
538 m_searchLineMarkColor = QColor(m_searchLineUnmarkColor.green(),
539 0.5 * m_searchLineUnmarkColor.green(),
540 0.5 * m_searchLineUnmarkColor.blue());
541 connect(m_pSearchLineEdit, &QLineEdit::textChanged,
542 this, &UIFileManagerTable::sltSearchTextChanged);
543 }
544 optionsUpdated();
545}
546
547void UIFileManagerTable::updateCurrentLocationEdit(const QString& strLocation)
548{
549 if (m_pNavigationWidget)
550 m_pNavigationWidget->setPath(strLocation);
551}
552
553void UIFileManagerTable::changeLocation(const QModelIndex &index)
554{
555 if (!index.isValid() || !m_pView)
556 return;
557 m_pView->setRootIndex(m_pProxyModel->mapFromSource(index));
558
559 if (m_pView->selectionModel())
560 m_pView->selectionModel()->reset();
561
562 UIFileSystemItem *item = static_cast<UIFileSystemItem*>(index.internalPointer());
563 if (item)
564 {
565 updateCurrentLocationEdit(item->path());
566 }
567 setSelectionDependentActionsEnabled(false);
568
569 m_pView->scrollToTop();
570}
571
572void UIFileManagerTable::initializeFileTree()
573{
574 if (m_pModel)
575 m_pModel->reset();
576 if (!rootItem())
577 return;
578
579 QString startPath("/");
580 /* On Unix-like systems startItem represents the root directory. On Windows it is like "my computer" under which
581 * drives are listed: */
582 UIFileSystemItem* startItem = new UIFileSystemItem(startPath, rootItem(), KFsObjType_Directory);
583
584 startItem->setIsOpened(false);
585 populateStartDirectory(startItem);
586
587 m_pModel->signalUpdate();
588 m_pView->setRootIndex(m_pProxyModel->mapFromSource(m_pModel->rootIndex()));
589 updateCurrentLocationEdit(currentDirectoryPath());
590}
591
592void UIFileManagerTable::populateStartDirectory(UIFileSystemItem *startItem)
593{
594 determineDriveLetters();
595 if (m_driveLetterList.isEmpty())
596 {
597 /* Read the root directory and get the list: */
598 readDirectory(startItem->path(), startItem, true);
599 }
600 else
601 {
602 for (int i = 0; i < m_driveLetterList.size(); ++i)
603 {
604 UIFileSystemItem* driveItem = new UIFileSystemItem(UIPathOperations::removeTrailingDelimiters(m_driveLetterList[i]),
605 startItem, KFsObjType_Directory);
606 driveItem->setIsOpened(false);
607 driveItem->setIsDriveItem(true);
608 startItem->setIsOpened(true);
609 }
610 }
611}
612
613void UIFileManagerTable::checkDotDot(QMap<QString,UIFileSystemItem*> &map,
614 UIFileSystemItem *parent, bool isStartDir)
615{
616 if (!parent)
617 return;
618 /* Make sure we have an item representing up directory, and make sure it is not there for the start dir: */
619 if (!map.contains(UIFileSystemModel::strUpDirectoryString) && !isStartDir)
620 {
621 UIFileSystemItem *item = new UIFileSystemItem(UIFileSystemModel::strUpDirectoryString,
622 parent, KFsObjType_Directory);
623 item->setIsOpened(false);
624 map.insert(UIFileSystemModel::strUpDirectoryString, item);
625 }
626 else if (map.contains(UIFileSystemModel::strUpDirectoryString) && isStartDir)
627 {
628 map.remove(UIFileSystemModel::strUpDirectoryString);
629 }
630}
631
632void UIFileManagerTable::sltItemDoubleClicked(const QModelIndex &index)
633{
634 if (!index.isValid() || !m_pModel || !m_pView)
635 return;
636 QModelIndex nIndex = m_pProxyModel ? m_pProxyModel->mapToSource(index) : index;
637 goIntoDirectory(nIndex);
638}
639
640void UIFileManagerTable::sltAltDoubleClick()
641{
642 emit sigAltDoubleClick();
643}
644
645void UIFileManagerTable::sltItemClicked(const QModelIndex &index)
646{
647 Q_UNUSED(index);
648 disableSelectionSearch();
649}
650
651void UIFileManagerTable::sltGoUp()
652{
653 if (!m_pView || !m_pModel)
654 return;
655 QModelIndex currentRoot = currentRootIndex();
656
657 if (!currentRoot.isValid())
658 return;
659 if (currentRoot != m_pModel->rootIndex())
660 {
661 QModelIndex parentIndex = currentRoot.parent();
662 if (parentIndex.isValid())
663 {
664 changeLocation(currentRoot.parent());
665 m_pView->selectRow(currentRoot.row());
666 }
667 }
668}
669
670void UIFileManagerTable::sltGoHome()
671{
672 goToHomeDirectory();
673}
674
675void UIFileManagerTable::sltGoForward()
676{
677 if (m_pNavigationWidget)
678 m_pNavigationWidget->goForwardInHistory();
679}
680
681void UIFileManagerTable::sltGoBackward()
682{
683 if (m_pNavigationWidget)
684 m_pNavigationWidget->goBackwardInHistory();
685}
686
687void UIFileManagerTable::sltRefresh()
688{
689 refresh();
690}
691
692void UIFileManagerTable::goIntoDirectory(const QModelIndex &itemIndex)
693{
694 if (!m_pModel)
695 return;
696
697 /* Make sure the colum is 0: */
698 QModelIndex index = m_pModel->index(itemIndex.row(), 0, itemIndex.parent());
699 if (!index.isValid())
700 return;
701
702 UIFileSystemItem *item = static_cast<UIFileSystemItem*>(index.internalPointer());
703 if (!item)
704 return;
705
706 /* check if we need to go up: */
707 if (item->isUpDirectory())
708 {
709 QModelIndex parentIndex = m_pModel->parent(m_pModel->parent(index));
710 if (parentIndex.isValid())
711 changeLocation(parentIndex);
712 return;
713 }
714
715 if (item->isDirectory() || item->isSymLinkToADirectory())
716 {
717 if (!item->isOpened())
718 {
719 if (readDirectory(item->path(),item))
720 changeLocation(index);
721 }
722 else
723 changeLocation(index);
724 }
725}
726
727void UIFileManagerTable::goIntoDirectory(const QStringList &pathTrail)
728{
729 UIFileSystemItem *parent = getStartDirectoryItem();
730
731 for(int i = 0; i < pathTrail.size(); ++i)
732 {
733 if (!parent)
734 return;
735 /* Make sure parent is already opened: */
736 if (!parent->isOpened())
737 if (!readDirectory(parent->path(), parent, parent == getStartDirectoryItem()))
738 return;
739 /* search the current path item among the parent's children: */
740 UIFileSystemItem *item = parent->child(pathTrail.at(i));
741
742 if (!item)
743 return;
744 parent = item;
745 }
746 if (!parent)
747 return;
748 if (!parent->isOpened())
749 {
750 if (!readDirectory(parent->path(), parent, parent == getStartDirectoryItem()))
751 return;
752 }
753 goIntoDirectory(parent);
754}
755
756void UIFileManagerTable::goIntoDirectory(UIFileSystemItem *item)
757{
758 if (!item || !m_pModel)
759 return;
760 goIntoDirectory(m_pModel->index(item));
761}
762
763UIFileSystemItem* UIFileManagerTable::indexData(const QModelIndex &index) const
764{
765 if (!index.isValid())
766 return 0;
767 return static_cast<UIFileSystemItem*>(index.internalPointer());
768}
769
770void UIFileManagerTable::refresh()
771{
772 if (!m_pView || !m_pModel)
773 return;
774 QModelIndex currentIndex = currentRootIndex();
775
776 UIFileSystemItem *treeItem = indexData(currentIndex);
777 if (!treeItem)
778 return;
779 bool isRootDir = (m_pModel->rootIndex() == currentIndex);
780 m_pModel->beginReset();
781 /* For now we clear the whole subtree (that isrecursively) which is an overkill: */
782 treeItem->clearChildren();
783 if (isRootDir)
784 populateStartDirectory(treeItem);
785 else
786 readDirectory(treeItem->path(), treeItem, isRootDir);
787 m_pModel->endReset();
788 m_pView->setRootIndex(m_pProxyModel->mapFromSource(currentIndex));
789 setSelectionDependentActionsEnabled(m_pView->hasSelection());
790}
791
792void UIFileManagerTable::relist()
793{
794 if (!m_pProxyModel)
795 return;
796 m_pProxyModel->invalidate();
797}
798
799void UIFileManagerTable::sltDelete()
800{
801 if (!checkIfDeleteOK())
802 return;
803
804 if (!m_pView || !m_pModel)
805 return;
806
807 if (!m_pView || !m_pModel)
808 return;
809 QItemSelectionModel *selectionModel = m_pView->selectionModel();
810 if (!selectionModel)
811 return;
812
813 QModelIndexList selectedItemIndices = selectionModel->selectedRows();
814 for(int i = 0; i < selectedItemIndices.size(); ++i)
815 {
816 QModelIndex index =
817 m_pProxyModel ? m_pProxyModel->mapToSource(selectedItemIndices.at(i)) : selectedItemIndices.at(i);
818 deleteByIndex(index);
819 }
820 /** @todo dont refresh here, just delete the rows and update the table view: */
821 refresh();
822}
823
824void UIFileManagerTable::sltRename()
825{
826 if (!m_pView || !m_pModel)
827 return;
828 QItemSelectionModel *selectionModel = m_pView->selectionModel();
829 if (!selectionModel)
830 return;
831
832 QModelIndexList selectedItemIndices = selectionModel->selectedRows();
833 if (selectedItemIndices.size() == 0)
834 return;
835 QModelIndex modelIndex =
836 m_pProxyModel ? m_pProxyModel->mapToSource(selectedItemIndices.at(0)) : selectedItemIndices.at(0);
837 UIFileSystemItem *item = indexData(modelIndex);
838 if (!item || item->isUpDirectory())
839 return;
840 m_pView->edit(selectedItemIndices.at(0));
841}
842
843void UIFileManagerTable::sltCreateNewDirectory()
844{
845 if (!m_pModel || !m_pView)
846 return;
847 QModelIndex currentIndex = currentRootIndex();
848 if (!currentIndex.isValid())
849 return;
850 UIFileSystemItem *parentFolderItem = static_cast<UIFileSystemItem*>(currentIndex.internalPointer());
851 if (!parentFolderItem)
852 return;
853 QString strBase(UIFileSystemModel::tr("NewDirectory"));
854 QString newDirectoryName(strBase);
855 QStringList nameList = currentDirectoryListing();
856 int iSuffix = 1;
857 while (nameList.contains(newDirectoryName))
858 newDirectoryName = QString("%1_%2").arg(strBase).arg(QString::number(iSuffix++));
859
860 if (!createDirectory(parentFolderItem->path(), newDirectoryName))
861 return;
862
863 /* Refesh the current directory so that we correctly populate the child list of parentFolderItem: */
864 /** @todo instead of refreshing here (an overkill) just add the
865 rows and update the tabel view: */
866 sltRefresh();
867
868 /* Now we try to edit the newly created item thereby enabling the user to rename the new item: */
869 QList<UIFileSystemItem*> content = parentFolderItem->children();
870 UIFileSystemItem* newItem = 0;
871 /* Search the new item: */
872 foreach (UIFileSystemItem* childItem, content)
873 {
874
875 if (childItem && newDirectoryName == childItem->fileObjectName())
876 newItem = childItem;
877 }
878
879 if (!newItem)
880 return;
881 QModelIndex newItemIndex = m_pProxyModel->mapFromSource(m_pModel->index(newItem));
882 if (!newItemIndex.isValid())
883 return;
884 m_pView->edit(newItemIndex);
885}
886
887void UIFileManagerTable::sltCopy()
888{
889 m_copyCutBuffer = selectedItemPathList();
890 m_eFileOperationType = FileOperationType_Copy;
891 setPasteActionEnabled(true);
892}
893
894void UIFileManagerTable::sltCut()
895{
896 m_copyCutBuffer = selectedItemPathList();
897 m_eFileOperationType = FileOperationType_Cut;
898 setPasteActionEnabled(true);
899}
900
901void UIFileManagerTable::sltPaste()
902{
903 m_copyCutBuffer.clear();
904
905 m_eFileOperationType = FileOperationType_None;
906 setPasteActionEnabled(false);
907}
908
909void UIFileManagerTable::sltShowProperties()
910{
911 showProperties();
912}
913
914void UIFileManagerTable::sltSelectionChanged(const QItemSelection & selected, const QItemSelection & deselected)
915{
916 Q_UNUSED(selected);
917 Q_UNUSED(deselected);
918 setSelectionDependentActionsEnabled(m_pView->hasSelection());
919}
920
921void UIFileManagerTable::sltSelectAll()
922{
923 if (!m_pModel || !m_pView)
924 return;
925 m_pView->selectAll();
926 deSelectUpDirectoryItem();
927}
928
929void UIFileManagerTable::sltInvertSelection()
930{
931 setSelectionForAll(QItemSelectionModel::Toggle | QItemSelectionModel::Rows);
932 deSelectUpDirectoryItem();
933}
934
935void UIFileManagerTable::sltSearchTextChanged(const QString &strText)
936{
937 performSelectionSearch(strText);
938}
939
940void UIFileManagerTable::sltHandleItemRenameAttempt(UIFileSystemItem *pItem, const QString &strOldPath,
941 const QString &strOldName, const QString &strNewName)
942{
943 Q_UNUSED(strNewName);
944 if (!pItem)
945 return;
946 /* Attempt to chage item name in the file system: */
947 if (!renameItem(pItem, strOldPath))
948 {
949 /* Restore the previous name. relist the view: */
950 pItem->setData(strOldName, static_cast<int>(UIFileSystemModelData_Name));
951 relist();
952 emit sigLogOutput(QString(pItem->path()).append(" could not be renamed"), QString(), FileManagerLogType_Error);
953 }
954}
955
956void UIFileManagerTable::sltCreateFileViewContextMenu(const QPoint &point)
957{
958 QWidget *pSender = qobject_cast<QWidget*>(sender());
959 if (!pSender)
960 return;
961 createFileViewContextMenu(pSender, point);
962}
963
964void UIFileManagerTable::sltHandleNavigationWidgetPathChange(const QString& strPath)
965{
966 goIntoDirectory(UIPathOperations::pathTrail(strPath));
967}
968
969void UIFileManagerTable::sltHandleNavigationWidgetHistoryListChanged()
970{
971 toggleForwardBackwardActions();
972}
973
974void UIFileManagerTable::deSelectUpDirectoryItem()
975{
976 if (!m_pView)
977 return;
978 QItemSelectionModel *pSelectionModel = m_pView->selectionModel();
979 if (!pSelectionModel)
980 return;
981 QModelIndex currentRoot = currentRootIndex();
982 if (!currentRoot.isValid())
983 return;
984
985 /* Make sure that "up directory item" (if exists) is deselected: */
986 for (int i = 0; i < m_pModel->rowCount(currentRoot); ++i)
987 {
988 QModelIndex index = m_pModel->index(i, 0, currentRoot);
989 if (!index.isValid())
990 continue;
991
992 UIFileSystemItem *item = static_cast<UIFileSystemItem*>(index.internalPointer());
993 if (item && item->isUpDirectory())
994 {
995 QModelIndex indexToDeselect = m_pProxyModel ? m_pProxyModel->mapFromSource(index) : index;
996 pSelectionModel->select(indexToDeselect, QItemSelectionModel::Deselect | QItemSelectionModel::Rows);
997 }
998 }
999}
1000
1001void UIFileManagerTable::setSelectionForAll(QItemSelectionModel::SelectionFlags flags)
1002{
1003 if (!m_pView)
1004 return;
1005 QItemSelectionModel *pSelectionModel = m_pView->selectionModel();
1006 if (!pSelectionModel)
1007 return;
1008 QModelIndex currentRoot = currentRootIndex();
1009 if (!currentRoot.isValid())
1010 return;
1011
1012 for (int i = 0; i < m_pModel->rowCount(currentRoot); ++i)
1013 {
1014 QModelIndex index = m_pModel->index(i, 0, currentRoot);
1015 if (!index.isValid())
1016 continue;
1017 QModelIndex indexToSelect = m_pProxyModel ? m_pProxyModel->mapFromSource(index) : index;
1018 pSelectionModel->select(indexToSelect, flags);
1019 }
1020}
1021
1022void UIFileManagerTable::setSelection(const QModelIndex &indexInProxyModel)
1023{
1024 if (!m_pView)
1025 return;
1026 QItemSelectionModel *selectionModel = m_pView->selectionModel();
1027 if (!selectionModel)
1028 return;
1029 selectionModel->select(indexInProxyModel, QItemSelectionModel::Current | QItemSelectionModel::Rows | QItemSelectionModel::Select);
1030 m_pView->scrollTo(indexInProxyModel, QAbstractItemView::EnsureVisible);
1031}
1032
1033void UIFileManagerTable::deleteByIndex(const QModelIndex &itemIndex)
1034{
1035 UIFileSystemItem *treeItem = indexData(itemIndex);
1036 if (!treeItem)
1037 return;
1038 deleteByItem(treeItem);
1039}
1040
1041void UIFileManagerTable::retranslateUi()
1042{
1043 UIFileSystemItem *pRootItem = rootItem();
1044 if (pRootItem)
1045 {
1046 pRootItem->setData(UIFileManager::tr("Name"), UIFileSystemModelData_Name);
1047 pRootItem->setData(UIFileManager::tr("Size"), UIFileSystemModelData_Size);
1048 pRootItem->setData(UIFileManager::tr("Change Time"), UIFileSystemModelData_ChangeTime);
1049 pRootItem->setData(UIFileManager::tr("Owner"), UIFileSystemModelData_Owner);
1050 pRootItem->setData(UIFileManager::tr("Permissions"), UIFileSystemModelData_Permissions);
1051 }
1052}
1053
1054bool UIFileManagerTable::eventFilter(QObject *pObject, QEvent *pEvent) /* override */
1055{
1056 /* Handle only events sent to m_pView: */
1057 if (pObject != m_pView)
1058 return QIWithRetranslateUI<QWidget>::eventFilter(pObject, pEvent);
1059
1060 if (pEvent->type() == QEvent::KeyPress)
1061 {
1062 QKeyEvent *pKeyEvent = dynamic_cast<QKeyEvent*>(pEvent);
1063 if (pKeyEvent)
1064 {
1065 if (pKeyEvent->key() == Qt::Key_Enter || pKeyEvent->key() == Qt::Key_Return)
1066 {
1067 if (m_pView && m_pModel && !m_pView->isInEditState())
1068 {
1069 /* Get the selected item. If there are 0 or more than 1 selection do nothing: */
1070 QItemSelectionModel *selectionModel = m_pView->selectionModel();
1071 if (selectionModel)
1072 {
1073 QModelIndexList selectedItemIndices = selectionModel->selectedRows();
1074 if (selectedItemIndices.size() == 1 && m_pModel)
1075 goIntoDirectory( m_pProxyModel->mapToSource(selectedItemIndices.at(0)));
1076 }
1077 }
1078 return true;
1079 }
1080 else if (pKeyEvent->key() == Qt::Key_Delete)
1081 {
1082 sltDelete();
1083 return true;
1084 }
1085 else if (pKeyEvent->key() == Qt::Key_Backspace)
1086 {
1087 sltGoUp();
1088 return true;
1089 }
1090 else if (pKeyEvent->text().length() == 1 &&
1091 (pKeyEvent->text().at(0).isDigit() ||
1092 pKeyEvent->text().at(0).isLetter()))
1093 {
1094 if (m_pSearchLineEdit)
1095 {
1096 markUnmarkSearchLineEdit(false);
1097 m_pSearchLineEdit->clear();
1098 m_pSearchLineEdit->show();
1099 m_pSearchLineEdit->setFocus();
1100 m_pSearchLineEdit->setText(pKeyEvent->text());
1101 }
1102 }
1103 else if (pKeyEvent->key() == Qt::Key_Tab)
1104 {
1105 return true;
1106 }
1107 }
1108 }
1109 else if (pEvent->type() == QEvent::FocusOut)
1110 {
1111 disableSelectionSearch();
1112 }
1113
1114 /* Call to base-class: */
1115 return QIWithRetranslateUI<QWidget>::eventFilter(pObject, pEvent);
1116}
1117
1118UIFileSystemItem *UIFileManagerTable::getStartDirectoryItem()
1119{
1120 UIFileSystemItem* pRootItem = rootItem();
1121 if (!pRootItem)
1122 return 0;
1123 if (pRootItem->childCount() <= 0)
1124 return 0;
1125 return pRootItem->child(0);
1126}
1127
1128QString UIFileManagerTable::currentDirectoryPath() const
1129{
1130 if (!m_pView)
1131 return QString();
1132 QModelIndex currentRoot = currentRootIndex();
1133 if (!currentRoot.isValid())
1134 return QString();
1135 UIFileSystemItem *item = static_cast<UIFileSystemItem*>(currentRoot.internalPointer());
1136 if (!item)
1137 return QString();
1138 /* be paranoid: */
1139 if (!item->isDirectory())
1140 return QString();
1141 return item->path();
1142}
1143
1144QStringList UIFileManagerTable::selectedItemPathList()
1145{
1146 QItemSelectionModel *selectionModel = m_pView->selectionModel();
1147 if (!selectionModel)
1148 return QStringList();
1149
1150 QStringList pathList;
1151 QModelIndexList selectedItemIndices = selectionModel->selectedRows();
1152 for(int i = 0; i < selectedItemIndices.size(); ++i)
1153 {
1154 QModelIndex index =
1155 m_pProxyModel ? m_pProxyModel->mapToSource(selectedItemIndices.at(i)) : selectedItemIndices.at(i);
1156 UIFileSystemItem *item = static_cast<UIFileSystemItem*>(index.internalPointer());
1157 if (!item)
1158 continue;
1159 pathList.push_back(item->path());
1160 }
1161 return pathList;
1162}
1163
1164CGuestFsObjInfo UIFileManagerTable::guestFsObjectInfo(const QString& path, CGuestSession &comGuestSession) const
1165{
1166 if (comGuestSession.isNull())
1167 return CGuestFsObjInfo();
1168 CGuestFsObjInfo comFsObjInfo = comGuestSession.FsObjQueryInfo(path, true /*aFollowSymlinks*/);
1169 if (!comFsObjInfo.isOk())
1170 return CGuestFsObjInfo();
1171 return comFsObjInfo;
1172}
1173
1174void UIFileManagerTable::setSelectionDependentActionsEnabled(bool fIsEnabled)
1175{
1176 foreach (QAction *pAction, m_selectionDependentActions)
1177 pAction->setEnabled(fIsEnabled);
1178 if (m_pView)
1179 emit sigSelectionChanged(m_pView->hasSelection());
1180}
1181
1182UIFileSystemItem* UIFileManagerTable::rootItem()
1183{
1184 if (!m_pModel)
1185 return 0;
1186 return m_pModel->rootItem();
1187}
1188
1189void UIFileManagerTable::setPathSeparator(const QChar &separator)
1190{
1191 m_pathSeparator = separator;
1192 if (m_pNavigationWidget)
1193 m_pNavigationWidget->setPathSeparator(m_pathSeparator);
1194}
1195
1196QHBoxLayout* UIFileManagerTable::toolBarLayout()
1197{
1198 return m_pToolBarLayout;
1199}
1200
1201bool UIFileManagerTable::event(QEvent *pEvent)
1202{
1203 if (pEvent->type() == QEvent::EnabledChange)
1204 retranslateUi();
1205 return QIWithRetranslateUI<QWidget>::event(pEvent);
1206}
1207
1208QString UIFileManagerTable::fileTypeString(KFsObjType type)
1209{
1210 QString strType = UIFileManager::tr("Unknown");
1211 switch (type)
1212 {
1213 case KFsObjType_File:
1214 strType = UIFileManager::tr("File");
1215 break;
1216 case KFsObjType_Directory:
1217 strType = UIFileManager::tr("Directory");
1218 break;
1219 case KFsObjType_Symlink:
1220 strType = UIFileManager::tr("Symbolic Link");
1221 break;
1222 case KFsObjType_Unknown:
1223 default:
1224 strType = UIFileManager::tr("Unknown");
1225 break;
1226 }
1227 return strType;
1228}
1229
1230/* static */ QString UIFileManagerTable::humanReadableSize(ULONG64 size)
1231{
1232 return UITranslator::formatSize(size);
1233}
1234
1235void UIFileManagerTable::optionsUpdated()
1236{
1237 UIFileManagerOptions *pOptions = UIFileManagerOptions::instance();
1238 if (pOptions)
1239 {
1240 if (m_pProxyModel)
1241 {
1242 m_pProxyModel->setListDirectoriesOnTop(pOptions->fListDirectoriesOnTop);
1243 m_pProxyModel->setShowHiddenObjects(pOptions->fShowHiddenObjects);
1244 }
1245 if (m_pModel)
1246 m_pModel->setShowHumanReadableSizes(pOptions->fShowHumanReadableSizes);
1247 }
1248 relist();
1249}
1250
1251bool UIFileManagerTable::hasSelection() const
1252{
1253 if (m_pView)
1254 return m_pView->hasSelection();
1255 return false;
1256}
1257
1258void UIFileManagerTable::setDragDropMode(QAbstractItemView::DragDropMode behavior)
1259{
1260 if (m_pView)
1261 m_pView->setDragDropMode(behavior);
1262}
1263
1264void UIFileManagerTable::sltReceiveDirectoryStatistics(UIDirectoryStatistics statistics)
1265{
1266 if (!m_pPropertiesDialog)
1267 return;
1268 m_pPropertiesDialog->addDirectoryStatistics(statistics);
1269}
1270
1271QModelIndex UIFileManagerTable::currentRootIndex() const
1272{
1273 if (!m_pView)
1274 return QModelIndex();
1275 if (!m_pProxyModel)
1276 return m_pView->rootIndex();
1277 return m_pProxyModel->mapToSource(m_pView->rootIndex());
1278}
1279
1280void UIFileManagerTable::performSelectionSearch(const QString &strSearchText)
1281{
1282 if (!m_pProxyModel | !m_pView)
1283 return;
1284
1285 if (strSearchText.isEmpty())
1286 {
1287 markUnmarkSearchLineEdit(false);
1288 return;
1289 }
1290
1291 int rowCount = m_pProxyModel->rowCount(m_pView->rootIndex());
1292 UIFileSystemItem *pFoundItem = 0;
1293 QModelIndex index;
1294 for (int i = 0; i < rowCount && !pFoundItem; ++i)
1295 {
1296 index = m_pProxyModel->index(i, 0, m_pView->rootIndex());
1297 if (!index.isValid())
1298 continue;
1299 pFoundItem = static_cast<UIFileSystemItem*>(m_pProxyModel->mapToSource(index).internalPointer());
1300 if (!pFoundItem)
1301 continue;
1302 const QString &strName = pFoundItem->fileObjectName();
1303 if (!strName.startsWith(m_pSearchLineEdit->text(), Qt::CaseInsensitive))
1304 pFoundItem = 0;
1305 }
1306 if (pFoundItem)
1307 {
1308 /* Deselect anything that is already selected: */
1309 m_pView->clearSelection();
1310 setSelection(index);
1311 }
1312 markUnmarkSearchLineEdit(!pFoundItem);
1313}
1314
1315void UIFileManagerTable::disableSelectionSearch()
1316{
1317 if (!m_pSearchLineEdit)
1318 return;
1319 m_pSearchLineEdit->blockSignals(true);
1320 m_pSearchLineEdit->clear();
1321 m_pSearchLineEdit->hide();
1322 m_pSearchLineEdit->blockSignals(false);
1323}
1324
1325bool UIFileManagerTable::checkIfDeleteOK()
1326{
1327 UIFileManagerOptions *pFileManagerOptions = UIFileManagerOptions::instance();
1328 if (!pFileManagerOptions)
1329 return true;
1330 if (!pFileManagerOptions->fAskDeleteConfirmation)
1331 return true;
1332 UIFileDeleteConfirmationDialog *pDialog =
1333 new UIFileDeleteConfirmationDialog(this);
1334
1335 bool fContinueWithDelete = (pDialog->execute() == QDialog::Accepted);
1336 bool bAskNextTime = pDialog->askDeleteConfirmationNextTime();
1337
1338 /* Update the file manager options only if it is necessary: */
1339 if (pFileManagerOptions->fAskDeleteConfirmation != bAskNextTime)
1340 {
1341 pFileManagerOptions->fAskDeleteConfirmation = bAskNextTime;
1342 /* Notify file manager options panel so that the check box there is updated: */
1343 emit sigDeleteConfirmationOptionChanged();
1344 }
1345
1346 delete pDialog;
1347
1348 return fContinueWithDelete;
1349
1350}
1351
1352void UIFileManagerTable::markUnmarkSearchLineEdit(bool fMark)
1353{
1354 if (!m_pSearchLineEdit)
1355 return;
1356 QPalette palette = m_pSearchLineEdit->palette();
1357
1358 if (fMark)
1359 palette.setColor(QPalette::Base, m_searchLineMarkColor);
1360 else
1361 palette.setColor(QPalette::Base, m_searchLineUnmarkColor);
1362 m_pSearchLineEdit->setPalette(palette);
1363}
1364
1365void UIFileManagerTable::setSessionWidgetsEnabled(bool fEnabled)
1366{
1367 foreach (QWidget *pWidget, m_sessionWidgets)
1368 {
1369 if (pWidget)
1370 pWidget->setEnabled(fEnabled);
1371 }
1372}
1373
1374QStringList UIFileManagerTable::currentDirectoryListing() const
1375{
1376 UIFileSystemItem *pItem = static_cast<UIFileSystemItem*>(currentRootIndex().internalPointer());
1377 if (!pItem)
1378 return QStringList();
1379 QStringList list;
1380 foreach (const UIFileSystemItem *pChild, pItem->children())
1381 {
1382 if (pChild)
1383 list << pChild->fileObjectName();
1384 }
1385 return list;
1386}
1387
1388void UIFileManagerTable::setModelFileSystem(bool fIsWindowsFileSystem)
1389{
1390 if (m_pModel)
1391 m_pModel->setIsWindowsFileSystem(fIsWindowsFileSystem);
1392 /* On Windows it is generally desired to sort file objects case insensitively: */
1393 if (m_pProxyModel)
1394 {
1395 if (fIsWindowsFileSystem)
1396 m_pProxyModel->setSortCaseSensitivity(Qt::CaseInsensitive);
1397 else
1398 m_pProxyModel->setSortCaseSensitivity(Qt::CaseSensitive);
1399 }
1400}
1401
1402#include "UIFileManagerTable.moc"
Note: See TracBrowser for help on using the repository browser.

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