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