[71025] | 1 | /* $Id: UIFileManagerTable.cpp 106061 2024-09-16 14:03:52Z vboxsync $ */
|
---|
| 2 | /** @file
|
---|
[76177] | 3 | * VBox Qt GUI - UIFileManagerTable class implementation.
|
---|
[71025] | 4 | */
|
---|
| 5 |
|
---|
| 6 | /*
|
---|
[106061] | 7 | * Copyright (C) 2016-2024 Oracle and/or its affiliates.
|
---|
[71025] | 8 | *
|
---|
[96407] | 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
|
---|
[71025] | 26 | */
|
---|
| 27 |
|
---|
| 28 | /* Qt includes: */
|
---|
[76606] | 29 | #include <QAction>
|
---|
[104393] | 30 | #include <QApplication>
|
---|
[76606] | 31 | #include <QCheckBox>
|
---|
[92710] | 32 | #include <QHBoxLayout>
|
---|
[76606] | 33 | #include <QHeaderView>
|
---|
| 34 | #include <QItemDelegate>
|
---|
| 35 | #include <QGridLayout>
|
---|
| 36 | #include <QTextEdit>
|
---|
[71025] | 37 |
|
---|
| 38 | /* GUI includes: */
|
---|
[76606] | 39 | #include "QIDialog.h"
|
---|
| 40 | #include "QIDialogButtonBox.h"
|
---|
| 41 | #include "QILabel.h"
|
---|
| 42 | #include "QILineEdit.h"
|
---|
[90967] | 43 | #include "QIToolBar.h"
|
---|
| 44 | #include "UIActionPool.h"
|
---|
[102485] | 45 | #include "UIFileSystemModel.h"
|
---|
[76606] | 46 | #include "UIErrorString.h"
|
---|
[90967] | 47 | #include "UIFileManager.h"
|
---|
[76606] | 48 | #include "UIFileManagerTable.h"
|
---|
[100283] | 49 | #include "UIFileTableNavigationWidget.h"
|
---|
[76606] | 50 | #include "UIIconPool.h"
|
---|
| 51 | #include "UIPathOperations.h"
|
---|
[90967] | 52 | #include "UITranslator.h"
|
---|
[104228] | 53 | #include "UITranslationEventListener.h"
|
---|
[71025] | 54 |
|
---|
| 55 | /* COM includes: */
|
---|
[76606] | 56 | #include "CFsObjInfo.h"
|
---|
| 57 | #include "CGuestFsObjInfo.h"
|
---|
| 58 | #include "CGuestDirectory.h"
|
---|
| 59 | #include "CProgress.h"
|
---|
[71025] | 60 |
|
---|
| 61 |
|
---|
[71362] | 62 | /*********************************************************************************************************************************
|
---|
| 63 | * UIGuestControlFileView definition. *
|
---|
| 64 | *********************************************************************************************************************************/
|
---|
| 65 |
|
---|
[104995] | 66 | /** Using QTableView causes the following problem when I click on the table items
|
---|
[71362] | 67 | Qt WARNING: Cannot creat accessible child interface for object: UIGuestControlFileView.....
|
---|
| 68 | so for now subclass QTableView */
|
---|
| 69 | class UIGuestControlFileView : public QTableView
|
---|
| 70 | {
|
---|
[71380] | 71 |
|
---|
[71362] | 72 | Q_OBJECT;
|
---|
[71380] | 73 |
|
---|
[71362] | 74 | signals:
|
---|
| 75 |
|
---|
[71380] | 76 | void sigSelectionChanged(const QItemSelection & selected, const QItemSelection & deselected);
|
---|
[103651] | 77 | /* Emitted upon mouse double click while Alt key is pressed. */
|
---|
| 78 | void sigAltDoubleClick();
|
---|
[71380] | 79 |
|
---|
[71362] | 80 | public:
|
---|
| 81 |
|
---|
| 82 | UIGuestControlFileView(QWidget * parent = 0);
|
---|
| 83 | bool hasSelection() const;
|
---|
[77851] | 84 | bool isInEditState() const;
|
---|
[71362] | 85 |
|
---|
| 86 | protected:
|
---|
[71536] | 87 |
|
---|
[103982] | 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;
|
---|
[71536] | 91 |
|
---|
| 92 | private:
|
---|
| 93 |
|
---|
| 94 | void configure();
|
---|
[75000] | 95 | QWidget *m_pParent;
|
---|
[71362] | 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 |
|
---|
[92711] | 108 | public:
|
---|
| 109 |
|
---|
| 110 | UIFileDelegate(QObject *pParent)
|
---|
| 111 | : QItemDelegate(pParent){}
|
---|
| 112 |
|
---|
[71362] | 113 | protected:
|
---|
[75633] | 114 |
|
---|
[103988] | 115 | virtual void drawFocus ( QPainter * /*painter*/, const QStyleOptionViewItem & /*option*/, const QRect & /*rect*/ ) const RT_OVERRIDE RT_FINAL{}
|
---|
[71362] | 116 | };
|
---|
| 117 |
|
---|
| 118 |
|
---|
| 119 | /*********************************************************************************************************************************
|
---|
[102537] | 120 | * UStringInputDialog definition. *
|
---|
[71362] | 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 |
|
---|
[87718] | 131 | UIStringInputDialog(QWidget *pParent = 0, Qt::WindowFlags enmFlags = Qt::WindowFlags());
|
---|
[71362] | 132 | QString getString() const;
|
---|
| 133 |
|
---|
| 134 | private:
|
---|
| 135 |
|
---|
| 136 | QILineEdit *m_pLineEdit;
|
---|
| 137 | };
|
---|
| 138 |
|
---|
| 139 |
|
---|
[71380] | 140 | /*********************************************************************************************************************************
|
---|
[75633] | 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 |
|
---|
[87718] | 152 | UIFileDeleteConfirmationDialog(QWidget *pParent = 0, Qt::WindowFlags enmFlags = Qt::WindowFlags());
|
---|
[75633] | 153 | /** Returns whether m_pAskNextTimeCheckBox is checked or not. */
|
---|
| 154 | bool askDeleteConfirmationNextTime() const;
|
---|
| 155 |
|
---|
| 156 | private:
|
---|
| 157 |
|
---|
| 158 | QCheckBox *m_pAskNextTimeCheckBox;
|
---|
[75673] | 159 | QILabel *m_pQuestionLabel;
|
---|
[75633] | 160 | };
|
---|
| 161 |
|
---|
| 162 |
|
---|
| 163 | /*********************************************************************************************************************************
|
---|
[71563] | 164 | * UIHostDirectoryDiskUsageComputer implementation. *
|
---|
| 165 | *********************************************************************************************************************************/
|
---|
| 166 |
|
---|
| 167 | UIDirectoryDiskUsageComputer::UIDirectoryDiskUsageComputer(QObject *parent, QStringList pathList)
|
---|
| 168 | :QThread(parent)
|
---|
| 169 | , m_pathList(pathList)
|
---|
[71645] | 170 | , m_fOkToContinue(true)
|
---|
[71563] | 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();
|
---|
[71645] | 183 | m_fOkToContinue = false;
|
---|
[71563] | 184 | m_mutex.unlock();
|
---|
| 185 | }
|
---|
| 186 |
|
---|
[71645] | 187 | bool UIDirectoryDiskUsageComputer::isOkToContinue() const
|
---|
| 188 | {
|
---|
| 189 | return m_fOkToContinue;
|
---|
| 190 | }
|
---|
[71563] | 191 |
|
---|
[71645] | 192 |
|
---|
[71563] | 193 | /*********************************************************************************************************************************
|
---|
[71363] | 194 | * UIGuestControlFileView implementation. *
|
---|
[71269] | 195 | *********************************************************************************************************************************/
|
---|
[71362] | 196 |
|
---|
[75000] | 197 | UIGuestControlFileView::UIGuestControlFileView(QWidget *parent)
|
---|
[71362] | 198 | :QTableView(parent)
|
---|
[75000] | 199 | , m_pParent(parent)
|
---|
[71185] | 200 | {
|
---|
[71536] | 201 | configure();
|
---|
[71362] | 202 | }
|
---|
[71169] | 203 |
|
---|
[71536] | 204 | void UIGuestControlFileView::configure()
|
---|
| 205 | {
|
---|
[75202] | 206 | setContextMenuPolicy(Qt::CustomContextMenu);
|
---|
[71536] | 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);
|
---|
[75000] | 214 | installEventFilter(m_pParent);
|
---|
[71536] | 215 | }
|
---|
| 216 |
|
---|
[71362] | 217 | bool UIGuestControlFileView::hasSelection() const
|
---|
| 218 | {
|
---|
| 219 | QItemSelectionModel *pSelectionModel = selectionModel();
|
---|
| 220 | if (!pSelectionModel)
|
---|
| 221 | return false;
|
---|
| 222 | return pSelectionModel->hasSelection();
|
---|
| 223 | }
|
---|
| 224 |
|
---|
[77851] | 225 | bool UIGuestControlFileView::isInEditState() const
|
---|
| 226 | {
|
---|
| 227 | return state() == QAbstractItemView::EditingState;
|
---|
| 228 | }
|
---|
| 229 |
|
---|
[71380] | 230 | void UIGuestControlFileView::selectionChanged(const QItemSelection & selected, const QItemSelection & deselected)
|
---|
| 231 | {
|
---|
| 232 | emit sigSelectionChanged(selected, deselected);
|
---|
| 233 | QTableView::selectionChanged(selected, deselected);
|
---|
| 234 | }
|
---|
[71363] | 235 |
|
---|
[103651] | 236 | void UIGuestControlFileView::mousePressEvent(QMouseEvent *event)
|
---|
| 237 | {
|
---|
| 238 | if (qApp->queryKeyboardModifiers() & Qt::AltModifier)
|
---|
| 239 | return;
|
---|
| 240 | QTableView::mousePressEvent(event);
|
---|
| 241 | }
|
---|
[75203] | 242 |
|
---|
[103651] | 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 |
|
---|
[103652] | 254 |
|
---|
[71269] | 255 | /*********************************************************************************************************************************
|
---|
[71271] | 256 | * UIFileStringInputDialog implementation. *
|
---|
[71181] | 257 | *********************************************************************************************************************************/
|
---|
[71169] | 258 |
|
---|
[87718] | 259 | UIStringInputDialog::UIStringInputDialog(QWidget *pParent /* = 0 */, Qt::WindowFlags enmFlags /* = Qt::WindowFlags() */)
|
---|
| 260 | :QIDialog(pParent, enmFlags)
|
---|
[71269] | 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 |
|
---|
[71285] | 280 |
|
---|
[71269] | 281 | /*********************************************************************************************************************************
|
---|
[71380] | 282 | * UIPropertiesDialog implementation. *
|
---|
| 283 | *********************************************************************************************************************************/
|
---|
| 284 |
|
---|
[87718] | 285 | UIPropertiesDialog::UIPropertiesDialog(QWidget *pParent, Qt::WindowFlags enmFlags)
|
---|
| 286 | :QIDialog(pParent, enmFlags)
|
---|
[71380] | 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 | {
|
---|
[81340] | 296 | m_pInfoEdit->setReadOnly(true);
|
---|
[71380] | 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;
|
---|
[71505] | 309 | m_strProperty = strProperty;
|
---|
| 310 | m_pInfoEdit->setHtml(strProperty);
|
---|
| 311 | }
|
---|
[71380] | 312 |
|
---|
[71505] | 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");
|
---|
[76177] | 319 | // if (directoryStatistics.m_totalSize >= UIFileManagerTable::m_iKiloByte)
|
---|
| 320 | // propertyString += " (" + UIFileManagerTable::humanReadableSize(directoryStatistics.m_totalSize) + ")";
|
---|
[71505] | 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/>";
|
---|
[76177] | 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) + ")";
|
---|
[71505] | 332 | detailsString += "<br/>";
|
---|
| 333 |
|
---|
[76177] | 334 | detailsString += "<b>" + UIFileManager::tr("File Count") + ":</b> " +
|
---|
[75662] | 335 | QString::number(directoryStatistics.m_uFileCount);
|
---|
[71505] | 336 |
|
---|
| 337 | m_pInfoEdit->setHtml(detailsString);
|
---|
[71380] | 338 | }
|
---|
| 339 |
|
---|
[75662] | 340 |
|
---|
[71380] | 341 | /*********************************************************************************************************************************
|
---|
[75662] | 342 | * UIDirectoryStatistics implementation. *
|
---|
[71421] | 343 | *********************************************************************************************************************************/
|
---|
| 344 |
|
---|
| 345 | UIDirectoryStatistics::UIDirectoryStatistics()
|
---|
| 346 | : m_totalSize(0)
|
---|
| 347 | , m_uFileCount(0)
|
---|
| 348 | , m_uDirectoryCount(0)
|
---|
| 349 | , m_uSymlinkCount(0)
|
---|
[71536] | 350 | {
|
---|
| 351 | }
|
---|
[71421] | 352 |
|
---|
[102537] | 353 |
|
---|
[71421] | 354 | /*********************************************************************************************************************************
|
---|
[102531] | 355 | * UIFileDeleteConfirmationDialog implementation. *
|
---|
| 356 | *********************************************************************************************************************************/
|
---|
[71832] | 357 |
|
---|
[87718] | 358 | UIFileDeleteConfirmationDialog::UIFileDeleteConfirmationDialog(QWidget *pParent /* = 0 */, Qt::WindowFlags enmFlags /* = Qt::WindowFlags() */)
|
---|
| 359 | :QIDialog(pParent, enmFlags)
|
---|
[75633] | 360 | , m_pAskNextTimeCheckBox(0)
|
---|
| 361 | , m_pQuestionLabel(0)
|
---|
| 362 | {
|
---|
| 363 | QVBoxLayout *pLayout = new QVBoxLayout(this);
|
---|
| 364 |
|
---|
[75673] | 365 | m_pQuestionLabel = new QILabel;
|
---|
[75633] | 366 | if (m_pQuestionLabel)
|
---|
| 367 | {
|
---|
| 368 | pLayout->addWidget(m_pQuestionLabel);
|
---|
[76177] | 369 | m_pQuestionLabel->setText(UIFileManager::tr("Delete the selected file(s) and/or folder(s)"));
|
---|
[75633] | 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 |
|
---|
[75643] | 381 | m_pAskNextTimeCheckBox = new QCheckBox;
|
---|
[75633] | 382 |
|
---|
| 383 | if (m_pAskNextTimeCheckBox)
|
---|
| 384 | {
|
---|
[76177] | 385 | UIFileManagerOptions *pFileManagerOptions = UIFileManagerOptions::instance();
|
---|
[75762] | 386 | if (pFileManagerOptions)
|
---|
[76627] | 387 | m_pAskNextTimeCheckBox->setChecked(pFileManagerOptions->fAskDeleteConfirmation);
|
---|
[75643] | 388 |
|
---|
[75633] | 389 | pLayout->addWidget(m_pAskNextTimeCheckBox);
|
---|
[76177] | 390 | m_pAskNextTimeCheckBox->setText(UIFileManager::tr("Ask for this confirmation next time"));
|
---|
| 391 | m_pAskNextTimeCheckBox->setToolTip(UIFileManager::tr("Delete confirmation can be "
|
---|
[75662] | 392 | "disabled/enabled also from the Options panel."));
|
---|
[75633] | 393 | }
|
---|
| 394 | }
|
---|
| 395 |
|
---|
| 396 | bool UIFileDeleteConfirmationDialog::askDeleteConfirmationNextTime() const
|
---|
| 397 | {
|
---|
| 398 | if (!m_pAskNextTimeCheckBox)
|
---|
| 399 | return true;
|
---|
| 400 | return m_pAskNextTimeCheckBox->isChecked();
|
---|
| 401 | }
|
---|
| 402 |
|
---|
| 403 |
|
---|
[71181] | 404 | /*********************************************************************************************************************************
|
---|
[102537] | 405 | * UIFileManagerTable implementation. *
|
---|
[71181] | 406 | *********************************************************************************************************************************/
|
---|
[76177] | 407 | const unsigned UIFileManagerTable::m_iKiloByte = 1024; /**< Our kilo bytes are a power of two! (bird) */
|
---|
[78024] | 408 |
|
---|
[76177] | 409 | UIFileManagerTable::UIFileManagerTable(UIActionPool *pActionPool, QWidget *pParent /* = 0 */)
|
---|
[104228] | 410 | : QWidget(pParent)
|
---|
[75760] | 411 | , m_eFileOperationType(FileOperationType_None)
|
---|
[71191] | 412 | , m_pLocationLabel(0)
|
---|
[71563] | 413 | , m_pPropertiesDialog(0)
|
---|
[75136] | 414 | , m_pActionPool(pActionPool)
|
---|
| 415 | , m_pToolBar(0)
|
---|
[92710] | 416 | , m_pMainLayout(0)
|
---|
[100303] | 417 | , m_pNavigationWidget(0)
|
---|
[72086] | 418 | , m_pModel(0)
|
---|
| 419 | , m_pView(0)
|
---|
| 420 | , m_pProxyModel(0)
|
---|
[78146] | 421 | , m_pathSeparator('/')
|
---|
[92754] | 422 | , m_pToolBarLayout(0)
|
---|
[71169] | 423 | {
|
---|
| 424 | prepareObjects();
|
---|
| 425 | }
|
---|
| 426 |
|
---|
[76177] | 427 | UIFileManagerTable::~UIFileManagerTable()
|
---|
[71169] | 428 | {
|
---|
| 429 | }
|
---|
| 430 |
|
---|
[76177] | 431 | void UIFileManagerTable::reset()
|
---|
[71185] | 432 | {
|
---|
[71191] | 433 | if (m_pModel)
|
---|
[76309] | 434 | m_pModel->reset();
|
---|
| 435 |
|
---|
[78010] | 436 | if (m_pNavigationWidget)
|
---|
| 437 | m_pNavigationWidget->reset();
|
---|
[71185] | 438 | }
|
---|
| 439 |
|
---|
[76177] | 440 | void UIFileManagerTable::prepareObjects()
|
---|
[71169] | 441 | {
|
---|
[71191] | 442 | m_pMainLayout = new QGridLayout();
|
---|
[71169] | 443 | if (!m_pMainLayout)
|
---|
| 444 | return;
|
---|
| 445 | m_pMainLayout->setSpacing(0);
|
---|
| 446 | m_pMainLayout->setContentsMargins(0, 0, 0, 0);
|
---|
| 447 | setLayout(m_pMainLayout);
|
---|
| 448 |
|
---|
[92754] | 449 | m_pToolBarLayout = new QHBoxLayout;
|
---|
| 450 | if (m_pToolBarLayout)
|
---|
| 451 | {
|
---|
| 452 | m_pToolBarLayout->setSpacing(0);
|
---|
| 453 | m_pToolBarLayout->setContentsMargins(0, 0, 0, 0);
|
---|
[71186] | 454 |
|
---|
[92754] | 455 | m_pToolBar = new QIToolBar;
|
---|
| 456 | if (m_pToolBar)
|
---|
[92860] | 457 | {
|
---|
[92754] | 458 | m_pToolBarLayout->addWidget(m_pToolBar);
|
---|
[92860] | 459 | m_sessionWidgets << m_pToolBar;
|
---|
| 460 | }
|
---|
[92754] | 461 |
|
---|
| 462 | m_pMainLayout->addLayout(m_pToolBarLayout, 0, 0, 1, 7);
|
---|
| 463 | }
|
---|
| 464 |
|
---|
[71191] | 465 | m_pLocationLabel = new QILabel;
|
---|
| 466 | if (m_pLocationLabel)
|
---|
[92860] | 467 | {
|
---|
[71191] | 468 | m_pMainLayout->addWidget(m_pLocationLabel, 1, 0, 1, 1);
|
---|
[92860] | 469 | m_sessionWidgets << m_pLocationLabel;
|
---|
| 470 | }
|
---|
[71186] | 471 |
|
---|
[100283] | 472 | m_pNavigationWidget = new UIFileTableNavigationWidget;
|
---|
[78010] | 473 | if (m_pNavigationWidget)
|
---|
[71181] | 474 | {
|
---|
[78024] | 475 | m_pNavigationWidget->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Maximum);
|
---|
[100283] | 476 | connect(m_pNavigationWidget, &UIFileTableNavigationWidget::sigPathChanged,
|
---|
[78010] | 477 | this, &UIFileManagerTable::sltHandleNavigationWidgetPathChange);
|
---|
[100300] | 478 | connect(m_pNavigationWidget, &UIFileTableNavigationWidget::sigHistoryListChanged,
|
---|
| 479 | this, &UIFileManagerTable::sltHandleNavigationWidgetHistoryListChanged);
|
---|
[78024] | 480 | m_pMainLayout->addWidget(m_pNavigationWidget, 1, 1, 1, 6);
|
---|
[92860] | 481 | m_sessionWidgets << m_pNavigationWidget;
|
---|
[78010] | 482 | }
|
---|
[71181] | 483 |
|
---|
[102485] | 484 | m_pModel = new UIFileSystemModel(this);
|
---|
[71169] | 485 | if (!m_pModel)
|
---|
| 486 | return;
|
---|
[102378] | 487 |
|
---|
[102485] | 488 | connect(m_pModel, &UIFileSystemModel::sigItemRenamed,
|
---|
[76312] | 489 | this, &UIFileManagerTable::sltHandleItemRenameAttempt);
|
---|
[71181] | 490 |
|
---|
[102485] | 491 | m_pProxyModel = new UIFileSystemProxyModel(this);
|
---|
[72086] | 492 | if (!m_pProxyModel)
|
---|
| 493 | return;
|
---|
| 494 | m_pProxyModel->setSourceModel(m_pModel);
|
---|
[71181] | 495 |
|
---|
[75000] | 496 | m_pView = new UIGuestControlFileView(this);
|
---|
[71169] | 497 | if (m_pView)
|
---|
| 498 | {
|
---|
[92711] | 499 | m_pView->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::MinimumExpanding);
|
---|
[78024] | 500 | m_pMainLayout->addWidget(m_pView, 2, 0, 5, 7);
|
---|
[75905] | 501 |
|
---|
| 502 | QHeaderView *pHorizontalHeader = m_pView->horizontalHeader();
|
---|
| 503 | if (pHorizontalHeader)
|
---|
[76496] | 504 | {
|
---|
[75905] | 505 | pHorizontalHeader->setHighlightSections(false);
|
---|
[78519] | 506 | pHorizontalHeader->setSectionResizeMode(QHeaderView::ResizeToContents);
|
---|
| 507 | pHorizontalHeader->setStretchLastSection(true);
|
---|
[76496] | 508 | }
|
---|
[75905] | 509 |
|
---|
[72086] | 510 | m_pView->setModel(m_pProxyModel);
|
---|
[92711] | 511 | m_pView->setItemDelegate(new UIFileDelegate(this));
|
---|
[72086] | 512 | m_pView->setSortingEnabled(true);
|
---|
| 513 | m_pView->sortByColumn(0, Qt::AscendingOrder);
|
---|
[71185] | 514 |
|
---|
[71362] | 515 | connect(m_pView, &UIGuestControlFileView::doubleClicked,
|
---|
[76177] | 516 | this, &UIFileManagerTable::sltItemDoubleClicked);
|
---|
[103651] | 517 | connect(m_pView, &UIGuestControlFileView::sigAltDoubleClick,
|
---|
| 518 | this, &UIFileManagerTable::sltAltDoubleClick);
|
---|
[75000] | 519 | connect(m_pView, &UIGuestControlFileView::clicked,
|
---|
[76177] | 520 | this, &UIFileManagerTable::sltItemClicked);
|
---|
[71380] | 521 | connect(m_pView, &UIGuestControlFileView::sigSelectionChanged,
|
---|
[76177] | 522 | this, &UIFileManagerTable::sltSelectionChanged);
|
---|
[75202] | 523 | connect(m_pView, &UIGuestControlFileView::customContextMenuRequested,
|
---|
[76177] | 524 | this, &UIFileManagerTable::sltCreateFileViewContextMenu);
|
---|
[102485] | 525 | m_pView->hideColumn(UIFileSystemModelData_LocalPath);
|
---|
| 526 | m_pView->hideColumn(UIFileSystemModelData_ISOFilePath);
|
---|
| 527 | m_pView->hideColumn(UIFileSystemModelData_RemovedFromVISO);
|
---|
| 528 | m_pView->hideColumn(UIFileSystemModelData_DescendantRemovedFromVISO);
|
---|
[100604] | 529 |
|
---|
[92860] | 530 | m_sessionWidgets << m_pView;
|
---|
[71169] | 531 | }
|
---|
[75673] | 532 |
|
---|
[75000] | 533 | m_pSearchLineEdit = new QILineEdit;
|
---|
| 534 | if (m_pSearchLineEdit)
|
---|
| 535 | {
|
---|
[78024] | 536 | m_pMainLayout->addWidget(m_pSearchLineEdit, 8, 0, 1, 7);
|
---|
[75000] | 537 | m_pSearchLineEdit->hide();
|
---|
| 538 | m_pSearchLineEdit->setClearButtonEnabled(true);
|
---|
[78058] | 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());
|
---|
[75000] | 543 | connect(m_pSearchLineEdit, &QLineEdit::textChanged,
|
---|
[76177] | 544 | this, &UIFileManagerTable::sltSearchTextChanged);
|
---|
[75000] | 545 | }
|
---|
[104228] | 546 |
|
---|
| 547 | connect(&translationEventListener(), &UITranslationEventListener::sigRetranslateUI,
|
---|
| 548 | this, &UIFileManagerTable::sltRetranslateUI);
|
---|
| 549 |
|
---|
[76296] | 550 | optionsUpdated();
|
---|
[71169] | 551 | }
|
---|
| 552 |
|
---|
[76177] | 553 | void UIFileManagerTable::updateCurrentLocationEdit(const QString& strLocation)
|
---|
[71181] | 554 | {
|
---|
[78010] | 555 | if (m_pNavigationWidget)
|
---|
| 556 | m_pNavigationWidget->setPath(strLocation);
|
---|
[71181] | 557 | }
|
---|
| 558 |
|
---|
[76177] | 559 | void UIFileManagerTable::changeLocation(const QModelIndex &index)
|
---|
[71181] | 560 | {
|
---|
[71191] | 561 | if (!index.isValid() || !m_pView)
|
---|
[71181] | 562 | return;
|
---|
[72086] | 563 | m_pView->setRootIndex(m_pProxyModel->mapFromSource(index));
|
---|
[71181] | 564 |
|
---|
[77904] | 565 | if (m_pView->selectionModel())
|
---|
| 566 | m_pView->selectionModel()->reset();
|
---|
| 567 |
|
---|
[102485] | 568 | UIFileSystemItem *item = static_cast<UIFileSystemItem*>(index.internalPointer());
|
---|
[71191] | 569 | if (item)
|
---|
[71181] | 570 | {
|
---|
| 571 | updateCurrentLocationEdit(item->path());
|
---|
| 572 | }
|
---|
[78163] | 573 | setSelectionDependentActionsEnabled(false);
|
---|
| 574 |
|
---|
[92587] | 575 | m_pView->scrollToTop();
|
---|
[71181] | 576 | }
|
---|
| 577 |
|
---|
[76177] | 578 | void UIFileManagerTable::initializeFileTree()
|
---|
[71169] | 579 | {
|
---|
[76309] | 580 | if (m_pModel)
|
---|
| 581 | m_pModel->reset();
|
---|
| 582 | if (!rootItem())
|
---|
| 583 | return;
|
---|
[71852] | 584 |
|
---|
[102378] | 585 | QString startPath("/");
|
---|
[102363] | 586 | /* On Unix-like systems startItem represents the root directory. On Windows it is like "my computer" under which
|
---|
| 587 | * drives are listed: */
|
---|
[102485] | 588 | UIFileSystemItem* startItem = new UIFileSystemItem(startPath, rootItem(), KFsObjType_Directory);
|
---|
[100418] | 589 |
|
---|
[71832] | 590 | startItem->setIsOpened(false);
|
---|
[71852] | 591 | populateStartDirectory(startItem);
|
---|
[72086] | 592 |
|
---|
[71852] | 593 | m_pModel->signalUpdate();
|
---|
[72086] | 594 | m_pView->setRootIndex(m_pProxyModel->mapFromSource(m_pModel->rootIndex()));
|
---|
[102378] | 595 | updateCurrentLocationEdit(currentDirectoryPath());
|
---|
[71852] | 596 | }
|
---|
| 597 |
|
---|
[102485] | 598 | void UIFileManagerTable::populateStartDirectory(UIFileSystemItem *startItem)
|
---|
[71852] | 599 | {
|
---|
| 600 | determineDriveLetters();
|
---|
[71832] | 601 | if (m_driveLetterList.isEmpty())
|
---|
| 602 | {
|
---|
| 603 | /* Read the root directory and get the list: */
|
---|
[71852] | 604 | readDirectory(startItem->path(), startItem, true);
|
---|
[71832] | 605 | }
|
---|
| 606 | else
|
---|
| 607 | {
|
---|
| 608 | for (int i = 0; i < m_driveLetterList.size(); ++i)
|
---|
| 609 | {
|
---|
[102485] | 610 | UIFileSystemItem* driveItem = new UIFileSystemItem(UIPathOperations::removeTrailingDelimiters(m_driveLetterList[i]),
|
---|
[78146] | 611 | startItem, KFsObjType_Directory);
|
---|
[71832] | 612 | driveItem->setIsOpened(false);
|
---|
| 613 | driveItem->setIsDriveItem(true);
|
---|
| 614 | startItem->setIsOpened(true);
|
---|
| 615 | }
|
---|
| 616 | }
|
---|
[71169] | 617 | }
|
---|
| 618 |
|
---|
[102485] | 619 | void UIFileManagerTable::checkDotDot(QMap<QString,UIFileSystemItem*> &map,
|
---|
| 620 | UIFileSystemItem *parent, bool isStartDir)
|
---|
[71185] | 621 | {
|
---|
[76333] | 622 | if (!parent)
|
---|
| 623 | return;
|
---|
[72086] | 624 | /* Make sure we have an item representing up directory, and make sure it is not there for the start dir: */
|
---|
[102485] | 625 | if (!map.contains(UIFileSystemModel::strUpDirectoryString) && !isStartDir)
|
---|
[71185] | 626 | {
|
---|
[102485] | 627 | UIFileSystemItem *item = new UIFileSystemItem(UIFileSystemModel::strUpDirectoryString,
|
---|
[76495] | 628 | parent, KFsObjType_Directory);
|
---|
[76429] | 629 | item->setIsOpened(false);
|
---|
[102485] | 630 | map.insert(UIFileSystemModel::strUpDirectoryString, item);
|
---|
[71185] | 631 | }
|
---|
[102485] | 632 | else if (map.contains(UIFileSystemModel::strUpDirectoryString) && isStartDir)
|
---|
[71185] | 633 | {
|
---|
[102485] | 634 | map.remove(UIFileSystemModel::strUpDirectoryString);
|
---|
[71185] | 635 | }
|
---|
| 636 | }
|
---|
| 637 |
|
---|
[76177] | 638 | void UIFileManagerTable::sltItemDoubleClicked(const QModelIndex &index)
|
---|
[71185] | 639 | {
|
---|
| 640 | if (!index.isValid() || !m_pModel || !m_pView)
|
---|
| 641 | return;
|
---|
[72086] | 642 | QModelIndex nIndex = m_pProxyModel ? m_pProxyModel->mapToSource(index) : index;
|
---|
| 643 | goIntoDirectory(nIndex);
|
---|
[71234] | 644 | }
|
---|
[71185] | 645 |
|
---|
[103651] | 646 | void UIFileManagerTable::sltAltDoubleClick()
|
---|
| 647 | {
|
---|
| 648 | emit sigAltDoubleClick();
|
---|
| 649 | }
|
---|
| 650 |
|
---|
[76177] | 651 | void UIFileManagerTable::sltItemClicked(const QModelIndex &index)
|
---|
[75000] | 652 | {
|
---|
| 653 | Q_UNUSED(index);
|
---|
| 654 | disableSelectionSearch();
|
---|
| 655 | }
|
---|
| 656 |
|
---|
[76177] | 657 | void UIFileManagerTable::sltGoUp()
|
---|
[71234] | 658 | {
|
---|
| 659 | if (!m_pView || !m_pModel)
|
---|
| 660 | return;
|
---|
[72086] | 661 | QModelIndex currentRoot = currentRootIndex();
|
---|
| 662 |
|
---|
[71234] | 663 | if (!currentRoot.isValid())
|
---|
| 664 | return;
|
---|
| 665 | if (currentRoot != m_pModel->rootIndex())
|
---|
[71467] | 666 | {
|
---|
| 667 | QModelIndex parentIndex = currentRoot.parent();
|
---|
| 668 | if (parentIndex.isValid())
|
---|
| 669 | {
|
---|
| 670 | changeLocation(currentRoot.parent());
|
---|
| 671 | m_pView->selectRow(currentRoot.row());
|
---|
| 672 | }
|
---|
| 673 | }
|
---|
[71234] | 674 | }
|
---|
| 675 |
|
---|
[76177] | 676 | void UIFileManagerTable::sltGoHome()
|
---|
[71234] | 677 | {
|
---|
[71255] | 678 | goToHomeDirectory();
|
---|
[71234] | 679 | }
|
---|
| 680 |
|
---|
[100300] | 681 | void UIFileManagerTable::sltGoForward()
|
---|
| 682 | {
|
---|
[100304] | 683 | if (m_pNavigationWidget)
|
---|
| 684 | m_pNavigationWidget->goForwardInHistory();
|
---|
[100300] | 685 | }
|
---|
| 686 |
|
---|
| 687 | void UIFileManagerTable::sltGoBackward()
|
---|
| 688 | {
|
---|
[100304] | 689 | if (m_pNavigationWidget)
|
---|
| 690 | m_pNavigationWidget->goBackwardInHistory();
|
---|
[100300] | 691 | }
|
---|
| 692 |
|
---|
[76177] | 693 | void UIFileManagerTable::sltRefresh()
|
---|
[71234] | 694 | {
|
---|
| 695 | refresh();
|
---|
| 696 | }
|
---|
| 697 |
|
---|
[76177] | 698 | void UIFileManagerTable::goIntoDirectory(const QModelIndex &itemIndex)
|
---|
[71234] | 699 | {
|
---|
[71350] | 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 |
|
---|
[102485] | 708 | UIFileSystemItem *item = static_cast<UIFileSystemItem*>(index.internalPointer());
|
---|
[71185] | 709 | if (!item)
|
---|
| 710 | return;
|
---|
[71255] | 711 |
|
---|
[71185] | 712 | /* check if we need to go up: */
|
---|
| 713 | if (item->isUpDirectory())
|
---|
| 714 | {
|
---|
[71350] | 715 | QModelIndex parentIndex = m_pModel->parent(m_pModel->parent(index));
|
---|
[71185] | 716 | if (parentIndex.isValid())
|
---|
| 717 | changeLocation(parentIndex);
|
---|
| 718 | return;
|
---|
| 719 | }
|
---|
| 720 |
|
---|
[76106] | 721 | if (item->isDirectory() || item->isSymLinkToADirectory())
|
---|
[75910] | 722 | {
|
---|
| 723 | if (!item->isOpened())
|
---|
[102418] | 724 | {
|
---|
| 725 | if (readDirectory(item->path(),item))
|
---|
| 726 | changeLocation(index);
|
---|
| 727 | }
|
---|
| 728 | else
|
---|
| 729 | changeLocation(index);
|
---|
[75910] | 730 | }
|
---|
[71185] | 731 | }
|
---|
| 732 |
|
---|
[76177] | 733 | void UIFileManagerTable::goIntoDirectory(const QStringList &pathTrail)
|
---|
[71255] | 734 | {
|
---|
[102485] | 735 | UIFileSystemItem *parent = getStartDirectoryItem();
|
---|
[71255] | 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())
|
---|
[102418] | 743 | if (!readDirectory(parent->path(), parent, parent == getStartDirectoryItem()))
|
---|
| 744 | return;
|
---|
[71255] | 745 | /* search the current path item among the parent's children: */
|
---|
[102485] | 746 | UIFileSystemItem *item = parent->child(pathTrail.at(i));
|
---|
[100418] | 747 |
|
---|
[71255] | 748 | if (!item)
|
---|
| 749 | return;
|
---|
| 750 | parent = item;
|
---|
| 751 | }
|
---|
| 752 | if (!parent)
|
---|
| 753 | return;
|
---|
| 754 | if (!parent->isOpened())
|
---|
[102418] | 755 | {
|
---|
| 756 | if (!readDirectory(parent->path(), parent, parent == getStartDirectoryItem()))
|
---|
| 757 | return;
|
---|
| 758 | }
|
---|
[71255] | 759 | goIntoDirectory(parent);
|
---|
| 760 | }
|
---|
| 761 |
|
---|
[102485] | 762 | void UIFileManagerTable::goIntoDirectory(UIFileSystemItem *item)
|
---|
[71255] | 763 | {
|
---|
| 764 | if (!item || !m_pModel)
|
---|
| 765 | return;
|
---|
| 766 | goIntoDirectory(m_pModel->index(item));
|
---|
| 767 | }
|
---|
| 768 |
|
---|
[102485] | 769 | UIFileSystemItem* UIFileManagerTable::indexData(const QModelIndex &index) const
|
---|
[71255] | 770 | {
|
---|
| 771 | if (!index.isValid())
|
---|
| 772 | return 0;
|
---|
[102485] | 773 | return static_cast<UIFileSystemItem*>(index.internalPointer());
|
---|
[71255] | 774 | }
|
---|
| 775 |
|
---|
[76177] | 776 | void UIFileManagerTable::refresh()
|
---|
[71208] | 777 | {
|
---|
[71201] | 778 | if (!m_pView || !m_pModel)
|
---|
| 779 | return;
|
---|
[72086] | 780 | QModelIndex currentIndex = currentRootIndex();
|
---|
[71255] | 781 |
|
---|
[102485] | 782 | UIFileSystemItem *treeItem = indexData(currentIndex);
|
---|
[71201] | 783 | if (!treeItem)
|
---|
| 784 | return;
|
---|
[71208] | 785 | bool isRootDir = (m_pModel->rootIndex() == currentIndex);
|
---|
[71201] | 786 | m_pModel->beginReset();
|
---|
| 787 | /* For now we clear the whole subtree (that isrecursively) which is an overkill: */
|
---|
| 788 | treeItem->clearChildren();
|
---|
[71852] | 789 | if (isRootDir)
|
---|
| 790 | populateStartDirectory(treeItem);
|
---|
| 791 | else
|
---|
| 792 | readDirectory(treeItem->path(), treeItem, isRootDir);
|
---|
[71201] | 793 | m_pModel->endReset();
|
---|
[72086] | 794 | m_pView->setRootIndex(m_pProxyModel->mapFromSource(currentIndex));
|
---|
[75162] | 795 | setSelectionDependentActionsEnabled(m_pView->hasSelection());
|
---|
[71201] | 796 | }
|
---|
| 797 |
|
---|
[76177] | 798 | void UIFileManagerTable::relist()
|
---|
[75220] | 799 | {
|
---|
| 800 | if (!m_pProxyModel)
|
---|
| 801 | return;
|
---|
| 802 | m_pProxyModel->invalidate();
|
---|
| 803 | }
|
---|
| 804 |
|
---|
[76177] | 805 | void UIFileManagerTable::sltDelete()
|
---|
[71208] | 806 | {
|
---|
[75633] | 807 | if (!checkIfDeleteOK())
|
---|
| 808 | return;
|
---|
| 809 |
|
---|
[71208] | 810 | if (!m_pView || !m_pModel)
|
---|
| 811 | return;
|
---|
[75633] | 812 |
|
---|
| 813 | if (!m_pView || !m_pModel)
|
---|
| 814 | return;
|
---|
[71208] | 815 | QItemSelectionModel *selectionModel = m_pView->selectionModel();
|
---|
| 816 | if (!selectionModel)
|
---|
| 817 | return;
|
---|
[71201] | 818 |
|
---|
[71234] | 819 | QModelIndexList selectedItemIndices = selectionModel->selectedRows();
|
---|
[71208] | 820 | for(int i = 0; i < selectedItemIndices.size(); ++i)
|
---|
| 821 | {
|
---|
[72086] | 822 | QModelIndex index =
|
---|
| 823 | m_pProxyModel ? m_pProxyModel->mapToSource(selectedItemIndices.at(i)) : selectedItemIndices.at(i);
|
---|
| 824 | deleteByIndex(index);
|
---|
[71208] | 825 | }
|
---|
[71269] | 826 | /** @todo dont refresh here, just delete the rows and update the table view: */
|
---|
[71208] | 827 | refresh();
|
---|
| 828 | }
|
---|
| 829 |
|
---|
[76177] | 830 | void UIFileManagerTable::sltRename()
|
---|
[71234] | 831 | {
|
---|
[76312] | 832 | if (!m_pView || !m_pModel)
|
---|
[71255] | 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;
|
---|
[72086] | 841 | QModelIndex modelIndex =
|
---|
| 842 | m_pProxyModel ? m_pProxyModel->mapToSource(selectedItemIndices.at(0)) : selectedItemIndices.at(0);
|
---|
[102485] | 843 | UIFileSystemItem *item = indexData(modelIndex);
|
---|
[71255] | 844 | if (!item || item->isUpDirectory())
|
---|
| 845 | return;
|
---|
| 846 | m_pView->edit(selectedItemIndices.at(0));
|
---|
[71269] | 847 | }
|
---|
[71255] | 848 |
|
---|
[76177] | 849 | void UIFileManagerTable::sltCreateNewDirectory()
|
---|
[71269] | 850 | {
|
---|
| 851 | if (!m_pModel || !m_pView)
|
---|
| 852 | return;
|
---|
[72086] | 853 | QModelIndex currentIndex = currentRootIndex();
|
---|
[71269] | 854 | if (!currentIndex.isValid())
|
---|
| 855 | return;
|
---|
[102485] | 856 | UIFileSystemItem *parentFolderItem = static_cast<UIFileSystemItem*>(currentIndex.internalPointer());
|
---|
[77868] | 857 | if (!parentFolderItem)
|
---|
[71269] | 858 | return;
|
---|
[105803] | 859 | QString strBase(UIFileManager::tr("NewDirectory"));
|
---|
[100455] | 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++));
|
---|
[71269] | 865 |
|
---|
[77868] | 866 | if (!createDirectory(parentFolderItem->path(), newDirectoryName))
|
---|
[71269] | 867 | return;
|
---|
| 868 |
|
---|
[77868] | 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: */
|
---|
[102485] | 875 | QList<UIFileSystemItem*> content = parentFolderItem->children();
|
---|
| 876 | UIFileSystemItem* newItem = 0;
|
---|
[77868] | 877 | /* Search the new item: */
|
---|
[102485] | 878 | foreach (UIFileSystemItem* childItem, content)
|
---|
[71269] | 879 | {
|
---|
[77868] | 880 |
|
---|
[100406] | 881 | if (childItem && newDirectoryName == childItem->fileObjectName())
|
---|
[77868] | 882 | newItem = childItem;
|
---|
[71269] | 883 | }
|
---|
[77868] | 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);
|
---|
[71234] | 891 | }
|
---|
| 892 |
|
---|
[76177] | 893 | void UIFileManagerTable::sltCopy()
|
---|
[71362] | 894 | {
|
---|
[71380] | 895 | m_copyCutBuffer = selectedItemPathList();
|
---|
[75760] | 896 | m_eFileOperationType = FileOperationType_Copy;
|
---|
| 897 | setPasteActionEnabled(true);
|
---|
[71362] | 898 | }
|
---|
| 899 |
|
---|
[76177] | 900 | void UIFileManagerTable::sltCut()
|
---|
[71362] | 901 | {
|
---|
[71380] | 902 | m_copyCutBuffer = selectedItemPathList();
|
---|
[75760] | 903 | m_eFileOperationType = FileOperationType_Cut;
|
---|
| 904 | setPasteActionEnabled(true);
|
---|
[71362] | 905 | }
|
---|
| 906 |
|
---|
[76177] | 907 | void UIFileManagerTable::sltPaste()
|
---|
[71362] | 908 | {
|
---|
[71380] | 909 | m_copyCutBuffer.clear();
|
---|
[75760] | 910 |
|
---|
| 911 | m_eFileOperationType = FileOperationType_None;
|
---|
| 912 | setPasteActionEnabled(false);
|
---|
[71362] | 913 | }
|
---|
| 914 |
|
---|
[76177] | 915 | void UIFileManagerTable::sltShowProperties()
|
---|
[71380] | 916 | {
|
---|
[71505] | 917 | showProperties();
|
---|
[71380] | 918 | }
|
---|
| 919 |
|
---|
[76177] | 920 | void UIFileManagerTable::sltSelectionChanged(const QItemSelection & selected, const QItemSelection & deselected)
|
---|
[71380] | 921 | {
|
---|
[71793] | 922 | Q_UNUSED(selected);
|
---|
| 923 | Q_UNUSED(deselected);
|
---|
[75162] | 924 | setSelectionDependentActionsEnabled(m_pView->hasSelection());
|
---|
[71380] | 925 | }
|
---|
| 926 |
|
---|
[76177] | 927 | void UIFileManagerTable::sltSelectAll()
|
---|
[71792] | 928 | {
|
---|
| 929 | if (!m_pModel || !m_pView)
|
---|
| 930 | return;
|
---|
| 931 | m_pView->selectAll();
|
---|
| 932 | deSelectUpDirectoryItem();
|
---|
| 933 | }
|
---|
| 934 |
|
---|
[76177] | 935 | void UIFileManagerTable::sltInvertSelection()
|
---|
[71792] | 936 | {
|
---|
[71794] | 937 | setSelectionForAll(QItemSelectionModel::Toggle | QItemSelectionModel::Rows);
|
---|
[71792] | 938 | deSelectUpDirectoryItem();
|
---|
| 939 | }
|
---|
| 940 |
|
---|
[76177] | 941 | void UIFileManagerTable::sltSearchTextChanged(const QString &strText)
|
---|
[75000] | 942 | {
|
---|
| 943 | performSelectionSearch(strText);
|
---|
| 944 | }
|
---|
| 945 |
|
---|
[102485] | 946 | void UIFileManagerTable::sltHandleItemRenameAttempt(UIFileSystemItem *pItem, const QString &strOldPath,
|
---|
[100410] | 947 | const QString &strOldName, const QString &strNewName)
|
---|
[76312] | 948 | {
|
---|
[100408] | 949 | Q_UNUSED(strNewName);
|
---|
[76312] | 950 | if (!pItem)
|
---|
| 951 | return;
|
---|
| 952 | /* Attempt to chage item name in the file system: */
|
---|
[100408] | 953 | if (!renameItem(pItem, strOldPath))
|
---|
[76312] | 954 | {
|
---|
| 955 | /* Restore the previous name. relist the view: */
|
---|
[102485] | 956 | pItem->setData(strOldName, static_cast<int>(UIFileSystemModelData_Name));
|
---|
[76312] | 957 | relist();
|
---|
[92733] | 958 | emit sigLogOutput(QString(pItem->path()).append(" could not be renamed"), QString(), FileManagerLogType_Error);
|
---|
[76312] | 959 | }
|
---|
| 960 | }
|
---|
| 961 |
|
---|
[76177] | 962 | void UIFileManagerTable::sltCreateFileViewContextMenu(const QPoint &point)
|
---|
[75202] | 963 | {
|
---|
| 964 | QWidget *pSender = qobject_cast<QWidget*>(sender());
|
---|
| 965 | if (!pSender)
|
---|
| 966 | return;
|
---|
| 967 | createFileViewContextMenu(pSender, point);
|
---|
| 968 | }
|
---|
| 969 |
|
---|
[78010] | 970 | void UIFileManagerTable::sltHandleNavigationWidgetPathChange(const QString& strPath)
|
---|
| 971 | {
|
---|
| 972 | goIntoDirectory(UIPathOperations::pathTrail(strPath));
|
---|
| 973 | }
|
---|
| 974 |
|
---|
[100300] | 975 | void UIFileManagerTable::sltHandleNavigationWidgetHistoryListChanged()
|
---|
| 976 | {
|
---|
[100301] | 977 | toggleForwardBackwardActions();
|
---|
[100300] | 978 | }
|
---|
| 979 |
|
---|
[76177] | 980 | void UIFileManagerTable::deSelectUpDirectoryItem()
|
---|
[71792] | 981 | {
|
---|
| 982 | if (!m_pView)
|
---|
| 983 | return;
|
---|
| 984 | QItemSelectionModel *pSelectionModel = m_pView->selectionModel();
|
---|
| 985 | if (!pSelectionModel)
|
---|
| 986 | return;
|
---|
[72086] | 987 | QModelIndex currentRoot = currentRootIndex();
|
---|
[71792] | 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 |
|
---|
[102485] | 998 | UIFileSystemItem *item = static_cast<UIFileSystemItem*>(index.internalPointer());
|
---|
[71792] | 999 | if (item && item->isUpDirectory())
|
---|
| 1000 | {
|
---|
[72086] | 1001 | QModelIndex indexToDeselect = m_pProxyModel ? m_pProxyModel->mapFromSource(index) : index;
|
---|
| 1002 | pSelectionModel->select(indexToDeselect, QItemSelectionModel::Deselect | QItemSelectionModel::Rows);
|
---|
[71792] | 1003 | }
|
---|
| 1004 | }
|
---|
| 1005 | }
|
---|
| 1006 |
|
---|
[76177] | 1007 | void UIFileManagerTable::setSelectionForAll(QItemSelectionModel::SelectionFlags flags)
|
---|
[71792] | 1008 | {
|
---|
| 1009 | if (!m_pView)
|
---|
| 1010 | return;
|
---|
| 1011 | QItemSelectionModel *pSelectionModel = m_pView->selectionModel();
|
---|
| 1012 | if (!pSelectionModel)
|
---|
| 1013 | return;
|
---|
[72086] | 1014 | QModelIndex currentRoot = currentRootIndex();
|
---|
[71792] | 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;
|
---|
[72086] | 1023 | QModelIndex indexToSelect = m_pProxyModel ? m_pProxyModel->mapFromSource(index) : index;
|
---|
| 1024 | pSelectionModel->select(indexToSelect, flags);
|
---|
[71792] | 1025 | }
|
---|
| 1026 | }
|
---|
| 1027 |
|
---|
[76177] | 1028 | void UIFileManagerTable::setSelection(const QModelIndex &indexInProxyModel)
|
---|
[75000] | 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 |
|
---|
[76177] | 1039 | void UIFileManagerTable::deleteByIndex(const QModelIndex &itemIndex)
|
---|
[71208] | 1040 | {
|
---|
[102485] | 1041 | UIFileSystemItem *treeItem = indexData(itemIndex);
|
---|
[71208] | 1042 | if (!treeItem)
|
---|
| 1043 | return;
|
---|
| 1044 | deleteByItem(treeItem);
|
---|
| 1045 | }
|
---|
| 1046 |
|
---|
[104228] | 1047 | void UIFileManagerTable::sltRetranslateUI()
|
---|
[71185] | 1048 | {
|
---|
[102485] | 1049 | UIFileSystemItem *pRootItem = rootItem();
|
---|
[76309] | 1050 | if (pRootItem)
|
---|
[75662] | 1051 | {
|
---|
[102485] | 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);
|
---|
[75662] | 1057 | }
|
---|
[71234] | 1058 | }
|
---|
[71191] | 1059 |
|
---|
[76177] | 1060 | bool UIFileManagerTable::eventFilter(QObject *pObject, QEvent *pEvent) /* override */
|
---|
[71234] | 1061 | {
|
---|
[78002] | 1062 | /* Handle only events sent to m_pView: */
|
---|
| 1063 | if (pObject != m_pView)
|
---|
[104228] | 1064 | return QWidget::eventFilter(pObject, pEvent);
|
---|
[78002] | 1065 |
|
---|
[75002] | 1066 | if (pEvent->type() == QEvent::KeyPress)
|
---|
[71234] | 1067 | {
|
---|
[75000] | 1068 | QKeyEvent *pKeyEvent = dynamic_cast<QKeyEvent*>(pEvent);
|
---|
| 1069 | if (pKeyEvent)
|
---|
[71234] | 1070 | {
|
---|
[75000] | 1071 | if (pKeyEvent->key() == Qt::Key_Enter || pKeyEvent->key() == Qt::Key_Return)
|
---|
[71234] | 1072 | {
|
---|
[77851] | 1073 | if (m_pView && m_pModel && !m_pView->isInEditState())
|
---|
[75000] | 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;
|
---|
[71234] | 1085 | }
|
---|
[75000] | 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 | }
|
---|
[75973] | 1096 | else if (pKeyEvent->text().length() == 1 &&
|
---|
| 1097 | (pKeyEvent->text().at(0).isDigit() ||
|
---|
| 1098 | pKeyEvent->text().at(0).isLetter()))
|
---|
[75000] | 1099 | {
|
---|
| 1100 | if (m_pSearchLineEdit)
|
---|
| 1101 | {
|
---|
[78058] | 1102 | markUnmarkSearchLineEdit(false);
|
---|
[78055] | 1103 | m_pSearchLineEdit->clear();
|
---|
[75000] | 1104 | m_pSearchLineEdit->show();
|
---|
[78055] | 1105 | m_pSearchLineEdit->setFocus();
|
---|
| 1106 | m_pSearchLineEdit->setText(pKeyEvent->text());
|
---|
[75000] | 1107 | }
|
---|
| 1108 | }
|
---|
[75973] | 1109 | else if (pKeyEvent->key() == Qt::Key_Tab)
|
---|
| 1110 | {
|
---|
| 1111 | return true;
|
---|
| 1112 | }
|
---|
[78002] | 1113 | }
|
---|
| 1114 | }
|
---|
[75973] | 1115 | else if (pEvent->type() == QEvent::FocusOut)
|
---|
| 1116 | {
|
---|
| 1117 | disableSelectionSearch();
|
---|
[71234] | 1118 | }
|
---|
[78002] | 1119 |
|
---|
| 1120 | /* Call to base-class: */
|
---|
[104228] | 1121 | return QWidget::eventFilter(pObject, pEvent);
|
---|
[71185] | 1122 | }
|
---|
| 1123 |
|
---|
[102485] | 1124 | UIFileSystemItem *UIFileManagerTable::getStartDirectoryItem()
|
---|
[71255] | 1125 | {
|
---|
[102485] | 1126 | UIFileSystemItem* pRootItem = rootItem();
|
---|
[76309] | 1127 | if (!pRootItem)
|
---|
[71255] | 1128 | return 0;
|
---|
[76309] | 1129 | if (pRootItem->childCount() <= 0)
|
---|
[71255] | 1130 | return 0;
|
---|
[76309] | 1131 | return pRootItem->child(0);
|
---|
[71255] | 1132 | }
|
---|
[71187] | 1133 |
|
---|
[76177] | 1134 | QString UIFileManagerTable::currentDirectoryPath() const
|
---|
[71276] | 1135 | {
|
---|
| 1136 | if (!m_pView)
|
---|
| 1137 | return QString();
|
---|
[75000] | 1138 | QModelIndex currentRoot = currentRootIndex();
|
---|
[71276] | 1139 | if (!currentRoot.isValid())
|
---|
| 1140 | return QString();
|
---|
[102485] | 1141 | UIFileSystemItem *item = static_cast<UIFileSystemItem*>(currentRoot.internalPointer());
|
---|
[71276] | 1142 | if (!item)
|
---|
| 1143 | return QString();
|
---|
[71298] | 1144 | /* be paranoid: */
|
---|
| 1145 | if (!item->isDirectory())
|
---|
| 1146 | return QString();
|
---|
[71276] | 1147 | return item->path();
|
---|
| 1148 | }
|
---|
[71269] | 1149 |
|
---|
[76177] | 1150 | QStringList UIFileManagerTable::selectedItemPathList()
|
---|
[71276] | 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 | {
|
---|
[72086] | 1160 | QModelIndex index =
|
---|
| 1161 | m_pProxyModel ? m_pProxyModel->mapToSource(selectedItemIndices.at(i)) : selectedItemIndices.at(i);
|
---|
[102485] | 1162 | UIFileSystemItem *item = static_cast<UIFileSystemItem*>(index.internalPointer());
|
---|
[71276] | 1163 | if (!item)
|
---|
| 1164 | continue;
|
---|
[102393] | 1165 | pathList.push_back(item->path());
|
---|
[71276] | 1166 | }
|
---|
| 1167 | return pathList;
|
---|
| 1168 | }
|
---|
| 1169 |
|
---|
[76177] | 1170 | CGuestFsObjInfo UIFileManagerTable::guestFsObjectInfo(const QString& path, CGuestSession &comGuestSession) const
|
---|
[71325] | 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 | }
|
---|
[71285] | 1179 |
|
---|
[76177] | 1180 | void UIFileManagerTable::setSelectionDependentActionsEnabled(bool fIsEnabled)
|
---|
[71380] | 1181 | {
|
---|
[75162] | 1182 | foreach (QAction *pAction, m_selectionDependentActions)
|
---|
| 1183 | pAction->setEnabled(fIsEnabled);
|
---|
[92899] | 1184 | if (m_pView)
|
---|
| 1185 | emit sigSelectionChanged(m_pView->hasSelection());
|
---|
[71380] | 1186 | }
|
---|
[71325] | 1187 |
|
---|
[102485] | 1188 | UIFileSystemItem* UIFileManagerTable::rootItem()
|
---|
[75480] | 1189 | {
|
---|
[76309] | 1190 | if (!m_pModel)
|
---|
| 1191 | return 0;
|
---|
| 1192 | return m_pModel->rootItem();
|
---|
| 1193 | }
|
---|
| 1194 |
|
---|
[78146] | 1195 | void UIFileManagerTable::setPathSeparator(const QChar &separator)
|
---|
| 1196 | {
|
---|
| 1197 | m_pathSeparator = separator;
|
---|
| 1198 | if (m_pNavigationWidget)
|
---|
| 1199 | m_pNavigationWidget->setPathSeparator(m_pathSeparator);
|
---|
| 1200 | }
|
---|
| 1201 |
|
---|
[92754] | 1202 | QHBoxLayout* UIFileManagerTable::toolBarLayout()
|
---|
| 1203 | {
|
---|
| 1204 | return m_pToolBarLayout;
|
---|
| 1205 | }
|
---|
| 1206 |
|
---|
[76177] | 1207 | bool UIFileManagerTable::event(QEvent *pEvent)
|
---|
[75673] | 1208 | {
|
---|
| 1209 | if (pEvent->type() == QEvent::EnabledChange)
|
---|
[104228] | 1210 | sltRetranslateUI();
|
---|
| 1211 | return QWidget::event(pEvent);
|
---|
[75673] | 1212 | }
|
---|
| 1213 |
|
---|
[76300] | 1214 | QString UIFileManagerTable::fileTypeString(KFsObjType type)
|
---|
[71380] | 1215 | {
|
---|
[76177] | 1216 | QString strType = UIFileManager::tr("Unknown");
|
---|
[75928] | 1217 | switch (type)
|
---|
[71380] | 1218 | {
|
---|
[76300] | 1219 | case KFsObjType_File:
|
---|
[76177] | 1220 | strType = UIFileManager::tr("File");
|
---|
[71380] | 1221 | break;
|
---|
[76300] | 1222 | case KFsObjType_Directory:
|
---|
[76177] | 1223 | strType = UIFileManager::tr("Directory");
|
---|
[71380] | 1224 | break;
|
---|
[76300] | 1225 | case KFsObjType_Symlink:
|
---|
[76177] | 1226 | strType = UIFileManager::tr("Symbolic Link");
|
---|
[71380] | 1227 | break;
|
---|
[76300] | 1228 | case KFsObjType_Unknown:
|
---|
[71380] | 1229 | default:
|
---|
[76300] | 1230 | strType = UIFileManager::tr("Unknown");
|
---|
[71380] | 1231 | break;
|
---|
| 1232 | }
|
---|
| 1233 | return strType;
|
---|
| 1234 | }
|
---|
| 1235 |
|
---|
[76177] | 1236 | /* static */ QString UIFileManagerTable::humanReadableSize(ULONG64 size)
|
---|
[71412] | 1237 | {
|
---|
[90967] | 1238 | return UITranslator::formatSize(size);
|
---|
[71412] | 1239 | }
|
---|
| 1240 |
|
---|
[76296] | 1241 | void UIFileManagerTable::optionsUpdated()
|
---|
| 1242 | {
|
---|
| 1243 | UIFileManagerOptions *pOptions = UIFileManagerOptions::instance();
|
---|
| 1244 | if (pOptions)
|
---|
| 1245 | {
|
---|
| 1246 | if (m_pProxyModel)
|
---|
[76626] | 1247 | {
|
---|
[76627] | 1248 | m_pProxyModel->setListDirectoriesOnTop(pOptions->fListDirectoriesOnTop);
|
---|
| 1249 | m_pProxyModel->setShowHiddenObjects(pOptions->fShowHiddenObjects);
|
---|
[76626] | 1250 | }
|
---|
[76296] | 1251 | if (m_pModel)
|
---|
[76627] | 1252 | m_pModel->setShowHumanReadableSizes(pOptions->fShowHumanReadableSizes);
|
---|
[76296] | 1253 | }
|
---|
| 1254 | relist();
|
---|
| 1255 | }
|
---|
| 1256 |
|
---|
[92947] | 1257 | bool UIFileManagerTable::hasSelection() const
|
---|
| 1258 | {
|
---|
| 1259 | if (m_pView)
|
---|
| 1260 | return m_pView->hasSelection();
|
---|
| 1261 | return false;
|
---|
| 1262 | }
|
---|
| 1263 |
|
---|
[102446] | 1264 | void UIFileManagerTable::setDragDropMode(QAbstractItemView::DragDropMode behavior)
|
---|
| 1265 | {
|
---|
| 1266 | if (m_pView)
|
---|
| 1267 | m_pView->setDragDropMode(behavior);
|
---|
| 1268 | }
|
---|
| 1269 |
|
---|
[76177] | 1270 | void UIFileManagerTable::sltReceiveDirectoryStatistics(UIDirectoryStatistics statistics)
|
---|
[71563] | 1271 | {
|
---|
| 1272 | if (!m_pPropertiesDialog)
|
---|
| 1273 | return;
|
---|
| 1274 | m_pPropertiesDialog->addDirectoryStatistics(statistics);
|
---|
| 1275 | }
|
---|
[71412] | 1276 |
|
---|
[76177] | 1277 | QModelIndex UIFileManagerTable::currentRootIndex() const
|
---|
[72086] | 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 |
|
---|
[76177] | 1286 | void UIFileManagerTable::performSelectionSearch(const QString &strSearchText)
|
---|
[75000] | 1287 | {
|
---|
[78058] | 1288 | if (!m_pProxyModel | !m_pView)
|
---|
[75000] | 1289 | return;
|
---|
| 1290 |
|
---|
[78058] | 1291 | if (strSearchText.isEmpty())
|
---|
| 1292 | {
|
---|
| 1293 | markUnmarkSearchLineEdit(false);
|
---|
| 1294 | return;
|
---|
| 1295 | }
|
---|
| 1296 |
|
---|
[75000] | 1297 | int rowCount = m_pProxyModel->rowCount(m_pView->rootIndex());
|
---|
[102485] | 1298 | UIFileSystemItem *pFoundItem = 0;
|
---|
[75000] | 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;
|
---|
[102485] | 1305 | pFoundItem = static_cast<UIFileSystemItem*>(m_pProxyModel->mapToSource(index).internalPointer());
|
---|
[75000] | 1306 | if (!pFoundItem)
|
---|
| 1307 | continue;
|
---|
[100406] | 1308 | const QString &strName = pFoundItem->fileObjectName();
|
---|
[75000] | 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 | }
|
---|
[78058] | 1318 | markUnmarkSearchLineEdit(!pFoundItem);
|
---|
[75000] | 1319 | }
|
---|
| 1320 |
|
---|
[76177] | 1321 | void UIFileManagerTable::disableSelectionSearch()
|
---|
[75000] | 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 | }
|
---|
[75480] | 1330 |
|
---|
[76177] | 1331 | bool UIFileManagerTable::checkIfDeleteOK()
|
---|
[75633] | 1332 | {
|
---|
[76177] | 1333 | UIFileManagerOptions *pFileManagerOptions = UIFileManagerOptions::instance();
|
---|
[75762] | 1334 | if (!pFileManagerOptions)
|
---|
[75633] | 1335 | return true;
|
---|
[76627] | 1336 | if (!pFileManagerOptions->fAskDeleteConfirmation)
|
---|
[75633] | 1337 | return true;
|
---|
| 1338 | UIFileDeleteConfirmationDialog *pDialog =
|
---|
| 1339 | new UIFileDeleteConfirmationDialog(this);
|
---|
| 1340 |
|
---|
| 1341 | bool fContinueWithDelete = (pDialog->execute() == QDialog::Accepted);
|
---|
| 1342 | bool bAskNextTime = pDialog->askDeleteConfirmationNextTime();
|
---|
| 1343 |
|
---|
[75762] | 1344 | /* Update the file manager options only if it is necessary: */
|
---|
[76627] | 1345 | if (pFileManagerOptions->fAskDeleteConfirmation != bAskNextTime)
|
---|
[75633] | 1346 | {
|
---|
[76627] | 1347 | pFileManagerOptions->fAskDeleteConfirmation = bAskNextTime;
|
---|
[75762] | 1348 | /* Notify file manager options panel so that the check box there is updated: */
|
---|
[75643] | 1349 | emit sigDeleteConfirmationOptionChanged();
|
---|
[75633] | 1350 | }
|
---|
| 1351 |
|
---|
| 1352 | delete pDialog;
|
---|
| 1353 |
|
---|
| 1354 | return fContinueWithDelete;
|
---|
| 1355 |
|
---|
| 1356 | }
|
---|
| 1357 |
|
---|
[78058] | 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 |
|
---|
[92860] | 1371 | void UIFileManagerTable::setSessionWidgetsEnabled(bool fEnabled)
|
---|
[92765] | 1372 | {
|
---|
[92860] | 1373 | foreach (QWidget *pWidget, m_sessionWidgets)
|
---|
| 1374 | {
|
---|
| 1375 | if (pWidget)
|
---|
| 1376 | pWidget->setEnabled(fEnabled);
|
---|
| 1377 | }
|
---|
[92765] | 1378 | }
|
---|
[100455] | 1379 |
|
---|
| 1380 | QStringList UIFileManagerTable::currentDirectoryListing() const
|
---|
| 1381 | {
|
---|
[102485] | 1382 | UIFileSystemItem *pItem = static_cast<UIFileSystemItem*>(currentRootIndex().internalPointer());
|
---|
[100455] | 1383 | if (!pItem)
|
---|
| 1384 | return QStringList();
|
---|
| 1385 | QStringList list;
|
---|
[102485] | 1386 | foreach (const UIFileSystemItem *pChild, pItem->children())
|
---|
[100455] | 1387 | {
|
---|
| 1388 | if (pChild)
|
---|
| 1389 | list << pChild->fileObjectName();
|
---|
| 1390 | }
|
---|
| 1391 | return list;
|
---|
| 1392 | }
|
---|
| 1393 |
|
---|
[102378] | 1394 | void UIFileManagerTable::setModelFileSystem(bool fIsWindowsFileSystem)
|
---|
| 1395 | {
|
---|
| 1396 | if (m_pModel)
|
---|
| 1397 | m_pModel->setIsWindowsFileSystem(fIsWindowsFileSystem);
|
---|
[102441] | 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 | }
|
---|
[102378] | 1406 | }
|
---|
| 1407 |
|
---|
[76177] | 1408 | #include "UIFileManagerTable.moc"
|
---|