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