[70027] | 1 | /* $Id: UIFileManagerPaneContainer.cpp 104297 2024-04-11 13:20:43Z vboxsync $ */
|
---|
| 2 | /** @file
|
---|
| 3 | * VBox Qt GUI - UIVMLogViewer class implementation.
|
---|
| 4 | */
|
---|
| 5 |
|
---|
| 6 | /*
|
---|
[98103] | 7 | * Copyright (C) 2010-2023 Oracle and/or its affiliates.
|
---|
[70027] | 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
|
---|
[70027] | 26 | */
|
---|
| 27 |
|
---|
| 28 | /* Qt includes: */
|
---|
[104297] | 29 | #include <QApplication>
|
---|
[100879] | 30 | #include <QCheckBox>
|
---|
[76606] | 31 | #include <QHBoxLayout>
|
---|
| 32 | #include <QMenu>
|
---|
[100893] | 33 | #include <QProgressBar>
|
---|
| 34 | #include <QScrollArea>
|
---|
| 35 | #include <QScrollBar>
|
---|
[76606] | 36 | #include <QSpinBox>
|
---|
[100893] | 37 | #include <QStyle>
|
---|
[100879] | 38 | #include <QTabWidget>
|
---|
[100890] | 39 | #include <QTextEdit>
|
---|
| 40 | #include <QTime>
|
---|
[70581] | 41 |
|
---|
[70027] | 42 | /* GUI includes: */
|
---|
[100893] | 43 | #include "QILabel.h"
|
---|
| 44 | #include "QIToolButton.h"
|
---|
| 45 | #include "UIErrorString.h"
|
---|
[101020] | 46 | #include "UIFileManagerPaneContainer.h"
|
---|
[100887] | 47 | #include "UIFileManager.h"
|
---|
[100893] | 48 | #include "UIProgressEventHandler.h"
|
---|
[103923] | 49 | #include "UITranslationEventListener.h"
|
---|
[70529] | 50 |
|
---|
[100880] | 51 | /* Other VBox includes: */
|
---|
| 52 | #include <iprt/assert.h>
|
---|
[70027] | 53 |
|
---|
[100890] | 54 |
|
---|
| 55 | /*********************************************************************************************************************************
|
---|
[100893] | 56 | * UIFileOperationProgressWidget definition. *
|
---|
| 57 | *********************************************************************************************************************************/
|
---|
| 58 |
|
---|
[103923] | 59 | class UIFileOperationProgressWidget : public QFrame
|
---|
[100893] | 60 | {
|
---|
| 61 |
|
---|
| 62 | Q_OBJECT;
|
---|
| 63 |
|
---|
| 64 | signals:
|
---|
| 65 |
|
---|
| 66 | void sigProgressComplete(QUuid progressId);
|
---|
| 67 | void sigProgressFail(QString strErrorString, QString strSourceTableName, FileManagerLogType eLogType);
|
---|
| 68 | void sigFocusIn(QWidget *pWidget);
|
---|
| 69 | void sigFocusOut(QWidget *pWidget);
|
---|
| 70 |
|
---|
| 71 | public:
|
---|
| 72 |
|
---|
| 73 | UIFileOperationProgressWidget(const CProgress &comProgress, const QString &strSourceTableName, QWidget *pParent = 0);
|
---|
| 74 | ~UIFileOperationProgressWidget();
|
---|
| 75 | bool isCompleted() const;
|
---|
| 76 | bool isCanceled() const;
|
---|
| 77 |
|
---|
| 78 | protected:
|
---|
| 79 |
|
---|
[103987] | 80 | virtual void focusInEvent(QFocusEvent *pEvent) RT_OVERRIDE RT_FINAL;
|
---|
| 81 | virtual void focusOutEvent(QFocusEvent *pEvent) RT_OVERRIDE RT_FINAL;
|
---|
[100893] | 82 |
|
---|
| 83 | private slots:
|
---|
| 84 |
|
---|
| 85 | void sltHandleProgressPercentageChange(const QUuid &uProgressId, const int iPercent);
|
---|
| 86 | void sltHandleProgressComplete(const QUuid &uProgressId);
|
---|
| 87 | void sltCancelProgress();
|
---|
[103923] | 88 | void sltRetranslateUI();
|
---|
[100893] | 89 |
|
---|
| 90 | private:
|
---|
| 91 | enum OperationStatus
|
---|
| 92 | {
|
---|
| 93 | OperationStatus_NotStarted,
|
---|
| 94 | OperationStatus_Working,
|
---|
| 95 | OperationStatus_Paused,
|
---|
| 96 | OperationStatus_Canceled,
|
---|
| 97 | OperationStatus_Succeded,
|
---|
| 98 | OperationStatus_Failed,
|
---|
| 99 | OperationStatus_Invalid,
|
---|
| 100 | OperationStatus_Max
|
---|
| 101 | };
|
---|
| 102 |
|
---|
| 103 | void prepare();
|
---|
| 104 | void prepareWidgets();
|
---|
| 105 | void prepareEventHandler();
|
---|
| 106 | void cleanupEventHandler();
|
---|
| 107 |
|
---|
| 108 | OperationStatus m_eStatus;
|
---|
| 109 | CProgress m_comProgress;
|
---|
| 110 | UIProgressEventHandler *m_pEventHandler;
|
---|
| 111 | QGridLayout *m_pMainLayout;
|
---|
| 112 | QProgressBar *m_pProgressBar;
|
---|
| 113 | QIToolButton *m_pCancelButton;
|
---|
| 114 | QILabel *m_pStatusLabel;
|
---|
| 115 | QILabel *m_pOperationDescriptionLabel;
|
---|
| 116 | /** Name of the table from which this operation has originated. */
|
---|
| 117 | QString m_strSourceTableName;
|
---|
| 118 | };
|
---|
| 119 |
|
---|
| 120 |
|
---|
| 121 | /*********************************************************************************************************************************
|
---|
| 122 | * UIFileOperationProgressWidget implementation. *
|
---|
| 123 | *********************************************************************************************************************************/
|
---|
| 124 |
|
---|
| 125 | UIFileOperationProgressWidget::UIFileOperationProgressWidget(const CProgress &comProgress, const QString &strSourceTableName, QWidget *pParent /* = 0 */)
|
---|
[103923] | 126 | : QFrame(pParent)
|
---|
[100893] | 127 | , m_eStatus(OperationStatus_NotStarted)
|
---|
| 128 | , m_comProgress(comProgress)
|
---|
| 129 | , m_pEventHandler(0)
|
---|
| 130 | , m_pMainLayout(0)
|
---|
| 131 | , m_pProgressBar(0)
|
---|
| 132 | , m_pCancelButton(0)
|
---|
| 133 | , m_pStatusLabel(0)
|
---|
| 134 | , m_pOperationDescriptionLabel(0)
|
---|
| 135 | , m_strSourceTableName(strSourceTableName)
|
---|
| 136 | {
|
---|
| 137 | prepare();
|
---|
| 138 | setFocusPolicy(Qt::ClickFocus);
|
---|
| 139 | setStyleSheet("QFrame:focus { border-width: 1px; border-style: dashed; border-color: black; }");
|
---|
| 140 | }
|
---|
| 141 |
|
---|
| 142 | UIFileOperationProgressWidget::~UIFileOperationProgressWidget()
|
---|
| 143 | {
|
---|
| 144 | cleanupEventHandler();
|
---|
| 145 | }
|
---|
| 146 |
|
---|
| 147 | bool UIFileOperationProgressWidget::isCompleted() const
|
---|
| 148 | {
|
---|
| 149 | if (m_comProgress.isNull())
|
---|
| 150 | return true;
|
---|
| 151 | return m_comProgress.GetCompleted();
|
---|
| 152 | }
|
---|
| 153 |
|
---|
| 154 | bool UIFileOperationProgressWidget::isCanceled() const
|
---|
| 155 | {
|
---|
| 156 | if (m_comProgress.isNull())
|
---|
| 157 | return true;
|
---|
| 158 | return m_comProgress.GetCanceled();
|
---|
| 159 | }
|
---|
| 160 |
|
---|
[103923] | 161 | void UIFileOperationProgressWidget::sltRetranslateUI()
|
---|
[100893] | 162 | {
|
---|
| 163 | if (m_pCancelButton)
|
---|
| 164 | m_pCancelButton->setToolTip(UIFileManager::tr("Cancel"));
|
---|
| 165 |
|
---|
| 166 | switch (m_eStatus)
|
---|
| 167 | {
|
---|
| 168 | case OperationStatus_NotStarted:
|
---|
| 169 | m_pStatusLabel->setText(UIFileManager::tr("Not yet started"));
|
---|
| 170 | break;
|
---|
| 171 | case OperationStatus_Working:
|
---|
| 172 | m_pStatusLabel->setText(UIFileManager::tr("Working"));
|
---|
| 173 | break;
|
---|
| 174 | case OperationStatus_Paused:
|
---|
| 175 | m_pStatusLabel->setText(UIFileManager::tr("Paused"));
|
---|
| 176 | break;
|
---|
| 177 | case OperationStatus_Canceled:
|
---|
| 178 | m_pStatusLabel->setText(UIFileManager::tr("Canceled"));
|
---|
| 179 | break;
|
---|
| 180 | case OperationStatus_Succeded:
|
---|
| 181 | m_pStatusLabel->setText(UIFileManager::tr("Succeded"));
|
---|
| 182 | break;
|
---|
| 183 | case OperationStatus_Failed:
|
---|
| 184 | m_pStatusLabel->setText(UIFileManager::tr("Failed"));
|
---|
| 185 | break;
|
---|
| 186 | case OperationStatus_Invalid:
|
---|
| 187 | case OperationStatus_Max:
|
---|
| 188 | default:
|
---|
| 189 | m_pStatusLabel->setText(UIFileManager::tr("Invalid"));
|
---|
| 190 | break;
|
---|
| 191 | }
|
---|
| 192 | }
|
---|
| 193 |
|
---|
| 194 | void UIFileOperationProgressWidget::focusInEvent(QFocusEvent *pEvent)
|
---|
| 195 | {
|
---|
| 196 | QFrame::focusInEvent(pEvent);
|
---|
| 197 | emit sigFocusIn(this);
|
---|
| 198 | }
|
---|
| 199 |
|
---|
| 200 | void UIFileOperationProgressWidget::focusOutEvent(QFocusEvent *pEvent)
|
---|
| 201 | {
|
---|
| 202 | QFrame::focusOutEvent(pEvent);
|
---|
| 203 | emit sigFocusOut(this);
|
---|
| 204 | }
|
---|
| 205 |
|
---|
| 206 | void UIFileOperationProgressWidget::prepare()
|
---|
| 207 | {
|
---|
| 208 | prepareWidgets();
|
---|
| 209 | prepareEventHandler();
|
---|
[103923] | 210 | sltRetranslateUI();
|
---|
| 211 | connect(&translationEventListener(), &UITranslationEventListener::sigRetranslateUI,
|
---|
| 212 | this, &UIFileOperationProgressWidget::sltRetranslateUI);
|
---|
[100893] | 213 | }
|
---|
| 214 |
|
---|
| 215 | void UIFileOperationProgressWidget::prepareWidgets()
|
---|
| 216 | {
|
---|
| 217 | m_pMainLayout = new QGridLayout;
|
---|
| 218 | if (!m_pMainLayout)
|
---|
| 219 | return;
|
---|
| 220 | //m_pMainLayout->setSpacing(0);
|
---|
| 221 |
|
---|
| 222 | m_pOperationDescriptionLabel = new QILabel;
|
---|
| 223 | if (m_pOperationDescriptionLabel)
|
---|
| 224 | {
|
---|
| 225 | m_pOperationDescriptionLabel->setContextMenuPolicy(Qt::NoContextMenu);
|
---|
| 226 | m_pMainLayout->addWidget(m_pOperationDescriptionLabel, 0, 0, 1, 3);
|
---|
| 227 | if (!m_comProgress.isNull())
|
---|
| 228 | m_pOperationDescriptionLabel->setText(m_comProgress.GetDescription());
|
---|
| 229 | }
|
---|
| 230 |
|
---|
| 231 | m_pProgressBar = new QProgressBar;
|
---|
| 232 | if (m_pProgressBar)
|
---|
| 233 | {
|
---|
| 234 | m_pProgressBar->setMinimum(0);
|
---|
| 235 | m_pProgressBar->setMaximum(100);
|
---|
| 236 | m_pProgressBar->setTextVisible(true);
|
---|
| 237 | m_pMainLayout->addWidget(m_pProgressBar, 1, 0, 1, 2);
|
---|
| 238 | }
|
---|
| 239 |
|
---|
| 240 | m_pCancelButton = new QIToolButton;
|
---|
| 241 | if (m_pCancelButton)
|
---|
| 242 | {
|
---|
| 243 | m_pCancelButton->setIcon(QApplication::style()->standardIcon(QStyle::SP_DockWidgetCloseButton));
|
---|
| 244 | connect(m_pCancelButton, &QIToolButton::clicked, this, &UIFileOperationProgressWidget::sltCancelProgress);
|
---|
| 245 | if (!m_comProgress.isNull() && !m_comProgress.GetCancelable())
|
---|
| 246 | m_pCancelButton->setEnabled(false);
|
---|
| 247 | m_pMainLayout->addWidget(m_pCancelButton, 1, 2, 1, 1);
|
---|
| 248 | }
|
---|
| 249 |
|
---|
| 250 | m_pStatusLabel = new QILabel;
|
---|
| 251 | if (m_pStatusLabel)
|
---|
| 252 | {
|
---|
| 253 | m_pStatusLabel->setContextMenuPolicy(Qt::NoContextMenu);
|
---|
| 254 | m_pMainLayout->addWidget(m_pStatusLabel, 1, 3, 1, 1);
|
---|
| 255 | }
|
---|
| 256 |
|
---|
| 257 | setLayout(m_pMainLayout);
|
---|
[103923] | 258 | sltRetranslateUI();
|
---|
[100893] | 259 | }
|
---|
| 260 |
|
---|
| 261 | void UIFileOperationProgressWidget::prepareEventHandler()
|
---|
| 262 | {
|
---|
| 263 | if (m_comProgress.isNull())
|
---|
| 264 | return;
|
---|
| 265 | m_pEventHandler = new UIProgressEventHandler(this, m_comProgress);
|
---|
| 266 | connect(m_pEventHandler, &UIProgressEventHandler::sigProgressPercentageChange,
|
---|
| 267 | this, &UIFileOperationProgressWidget::sltHandleProgressPercentageChange);
|
---|
| 268 | connect(m_pEventHandler, &UIProgressEventHandler::sigProgressTaskComplete,
|
---|
| 269 | this, &UIFileOperationProgressWidget::sltHandleProgressComplete);
|
---|
| 270 | m_eStatus = OperationStatus_Working;
|
---|
[103923] | 271 | sltRetranslateUI();
|
---|
[100893] | 272 | }
|
---|
| 273 |
|
---|
| 274 | void UIFileOperationProgressWidget::cleanupEventHandler()
|
---|
| 275 | {
|
---|
| 276 | delete m_pEventHandler;
|
---|
| 277 | m_pEventHandler = 0;
|
---|
| 278 | }
|
---|
| 279 |
|
---|
| 280 | void UIFileOperationProgressWidget::sltHandleProgressPercentageChange(const QUuid &uProgressId, const int iPercent)
|
---|
| 281 | {
|
---|
| 282 | Q_UNUSED(uProgressId);
|
---|
| 283 | m_pProgressBar->setValue(iPercent);
|
---|
| 284 | }
|
---|
| 285 |
|
---|
| 286 | void UIFileOperationProgressWidget::sltHandleProgressComplete(const QUuid &uProgressId)
|
---|
| 287 | {
|
---|
| 288 | Q_UNUSED(uProgressId);
|
---|
| 289 | if (m_pCancelButton)
|
---|
| 290 | m_pCancelButton->setEnabled(false);
|
---|
| 291 |
|
---|
| 292 | if (!m_comProgress.isOk() || m_comProgress.GetResultCode() != 0)
|
---|
| 293 | {
|
---|
| 294 | emit sigProgressFail(UIErrorString::formatErrorInfo(m_comProgress), m_strSourceTableName, FileManagerLogType_Error);
|
---|
| 295 | m_eStatus = OperationStatus_Failed;
|
---|
| 296 | }
|
---|
| 297 | else
|
---|
| 298 | {
|
---|
| 299 | emit sigProgressComplete(m_comProgress.GetId());
|
---|
| 300 | m_eStatus = OperationStatus_Succeded;
|
---|
| 301 | }
|
---|
| 302 | if (m_pProgressBar)
|
---|
| 303 | m_pProgressBar->setValue(100);
|
---|
| 304 |
|
---|
| 305 | cleanupEventHandler();
|
---|
[103923] | 306 | sltRetranslateUI();
|
---|
[100893] | 307 | }
|
---|
| 308 |
|
---|
| 309 | void UIFileOperationProgressWidget::sltCancelProgress()
|
---|
| 310 | {
|
---|
| 311 | m_comProgress.Cancel();
|
---|
| 312 | /* Since we dont have a "progress canceled" event we have to do this here: */
|
---|
| 313 | if (m_pCancelButton)
|
---|
| 314 | m_pCancelButton->setEnabled(false);
|
---|
| 315 | if (m_pProgressBar)
|
---|
| 316 | m_pProgressBar->setEnabled(false);
|
---|
| 317 | m_eStatus = OperationStatus_Canceled;
|
---|
| 318 | cleanupEventHandler();
|
---|
[103923] | 319 | sltRetranslateUI();
|
---|
[100893] | 320 | }
|
---|
| 321 |
|
---|
| 322 | /*********************************************************************************************************************************
|
---|
[100890] | 323 | * UIFileManagerLogViewer definition. *
|
---|
| 324 | *********************************************************************************************************************************/
|
---|
| 325 |
|
---|
| 326 | class UIFileManagerLogViewer : public QTextEdit
|
---|
| 327 | {
|
---|
| 328 |
|
---|
| 329 | Q_OBJECT;
|
---|
| 330 |
|
---|
| 331 | public:
|
---|
| 332 |
|
---|
| 333 | UIFileManagerLogViewer(QWidget *pParent = 0);
|
---|
| 334 |
|
---|
| 335 | protected:
|
---|
| 336 |
|
---|
[100895] | 337 | virtual void contextMenuEvent(QContextMenuEvent * event) final override;
|
---|
[100890] | 338 |
|
---|
| 339 | private slots:
|
---|
| 340 |
|
---|
| 341 | void sltClear();
|
---|
| 342 | };
|
---|
| 343 |
|
---|
| 344 | /*********************************************************************************************************************************
|
---|
| 345 | * UIFileManagerLogViewer implementation. *
|
---|
| 346 | *********************************************************************************************************************************/
|
---|
| 347 |
|
---|
| 348 | UIFileManagerLogViewer::UIFileManagerLogViewer(QWidget *pParent /* = 0 */)
|
---|
| 349 | :QTextEdit(pParent)
|
---|
| 350 | {
|
---|
| 351 | setUndoRedoEnabled(false);
|
---|
| 352 | setReadOnly(true);
|
---|
| 353 | }
|
---|
| 354 |
|
---|
| 355 | void UIFileManagerLogViewer::contextMenuEvent(QContextMenuEvent *event)
|
---|
| 356 | {
|
---|
| 357 | QMenu *menu = createStandardContextMenu();
|
---|
| 358 |
|
---|
| 359 | QAction *pClearAction = menu->addAction(UIFileManager::tr("Clear"));
|
---|
| 360 | connect(pClearAction, &QAction::triggered, this, &UIFileManagerLogViewer::sltClear);
|
---|
| 361 | menu->exec(event->globalPos());
|
---|
| 362 | delete menu;
|
---|
| 363 | }
|
---|
| 364 |
|
---|
| 365 | void UIFileManagerLogViewer::sltClear()
|
---|
| 366 | {
|
---|
| 367 | clear();
|
---|
| 368 | }
|
---|
| 369 |
|
---|
[101020] | 370 |
|
---|
[100890] | 371 | /*********************************************************************************************************************************
|
---|
[101020] | 372 | * UIFileManagerPaneContainer implementation. *
|
---|
[100890] | 373 | *********************************************************************************************************************************/
|
---|
| 374 |
|
---|
[101020] | 375 | UIFileManagerPaneContainer::UIFileManagerPaneContainer(QWidget *pParent, UIFileManagerOptions *pFileManagerOptions)
|
---|
[100956] | 376 | : UIPaneContainer(pParent)
|
---|
[100879] | 377 | , m_pListDirectoriesOnTopCheckBox(0)
|
---|
| 378 | , m_pDeleteConfirmationCheckBox(0)
|
---|
| 379 | , m_pHumanReabableSizesCheckBox(0)
|
---|
| 380 | , m_pShowHiddenObjectsCheckBox(0)
|
---|
[100887] | 381 | , m_pFileManagerOptions(pFileManagerOptions)
|
---|
[100893] | 382 | , m_pLogTextEdit(0)
|
---|
| 383 | , m_pScrollArea(0)
|
---|
| 384 | , m_pOperationsTabLayout(0)
|
---|
| 385 | , m_pContainerSpaceItem(0)
|
---|
| 386 | , m_pWidgetInFocus(0)
|
---|
[70027] | 387 | {
|
---|
[100879] | 388 | prepare();
|
---|
[103923] | 389 | sltRetranslateUI();
|
---|
| 390 | connect(&translationEventListener(), &UITranslationEventListener::sigRetranslateUI,
|
---|
| 391 | this, &UIFileManagerPaneContainer::sltRetranslateUI);
|
---|
[100879] | 392 | }
|
---|
[75220] | 393 |
|
---|
| 394 |
|
---|
[101020] | 395 | void UIFileManagerPaneContainer::prepare()
|
---|
[100879] | 396 | {
|
---|
| 397 | preparePreferencesTab();
|
---|
[100890] | 398 | prepareLogTab();
|
---|
[100901] | 399 | prepareOperationsTab();
|
---|
[100879] | 400 | }
|
---|
[75220] | 401 |
|
---|
[101020] | 402 | void UIFileManagerPaneContainer::preparePreferencesTab()
|
---|
[100879] | 403 | {
|
---|
[100890] | 404 | QWidget *pPreferencesTab = new QWidget;
|
---|
[100879] | 405 | m_pListDirectoriesOnTopCheckBox = new QCheckBox;
|
---|
| 406 | m_pDeleteConfirmationCheckBox = new QCheckBox;
|
---|
| 407 | m_pHumanReabableSizesCheckBox = new QCheckBox;
|
---|
| 408 | m_pShowHiddenObjectsCheckBox = new QCheckBox;
|
---|
[75220] | 409 |
|
---|
[100890] | 410 | AssertReturnVoid(pPreferencesTab);
|
---|
[100879] | 411 | AssertReturnVoid(m_pListDirectoriesOnTopCheckBox);
|
---|
| 412 | AssertReturnVoid(m_pDeleteConfirmationCheckBox);
|
---|
| 413 | AssertReturnVoid(m_pHumanReabableSizesCheckBox);
|
---|
| 414 | AssertReturnVoid(m_pShowHiddenObjectsCheckBox);
|
---|
[75220] | 415 |
|
---|
[100887] | 416 | if (m_pFileManagerOptions)
|
---|
| 417 | {
|
---|
| 418 | if (m_pListDirectoriesOnTopCheckBox)
|
---|
| 419 | m_pListDirectoriesOnTopCheckBox->setChecked(m_pFileManagerOptions->fListDirectoriesOnTop);
|
---|
| 420 | if (m_pDeleteConfirmationCheckBox)
|
---|
| 421 | m_pDeleteConfirmationCheckBox->setChecked(m_pFileManagerOptions->fAskDeleteConfirmation);
|
---|
| 422 | if (m_pHumanReabableSizesCheckBox)
|
---|
| 423 | m_pHumanReabableSizesCheckBox->setChecked(m_pFileManagerOptions->fShowHumanReadableSizes);
|
---|
| 424 | if (m_pShowHiddenObjectsCheckBox)
|
---|
| 425 | m_pShowHiddenObjectsCheckBox->setChecked(m_pFileManagerOptions->fShowHiddenObjects);
|
---|
| 426 | }
|
---|
[75220] | 427 |
|
---|
[100887] | 428 | connect(m_pListDirectoriesOnTopCheckBox, &QCheckBox::toggled,
|
---|
[101020] | 429 | this, &UIFileManagerPaneContainer::sltListDirectoryCheckBoxToogled);
|
---|
[100887] | 430 | connect(m_pDeleteConfirmationCheckBox, &QCheckBox::toggled,
|
---|
[101020] | 431 | this, &UIFileManagerPaneContainer::sltDeleteConfirmationCheckBoxToogled);
|
---|
[100887] | 432 | connect(m_pHumanReabableSizesCheckBox, &QCheckBox::toggled,
|
---|
[101020] | 433 | this, &UIFileManagerPaneContainer::sltHumanReabableSizesCheckBoxToogled);
|
---|
[100887] | 434 | connect(m_pShowHiddenObjectsCheckBox, &QCheckBox::toggled,
|
---|
[101020] | 435 | this, &UIFileManagerPaneContainer::sltShowHiddenObjectsCheckBoxToggled);
|
---|
[100887] | 436 |
|
---|
[100890] | 437 | QGridLayout *pPreferencesLayout = new QGridLayout(pPreferencesTab);
|
---|
[100879] | 438 | AssertReturnVoid(pPreferencesLayout);
|
---|
[100893] | 439 | //pPreferencesLayout->setContentsMargins(0, 0, 0, 0);
|
---|
[100890] | 440 |
|
---|
[100879] | 441 | pPreferencesLayout->addWidget(m_pListDirectoriesOnTopCheckBox, 0, 0, 1, 1);
|
---|
| 442 | pPreferencesLayout->addWidget(m_pDeleteConfirmationCheckBox, 1, 0, 1, 1);
|
---|
| 443 | pPreferencesLayout->addWidget(m_pHumanReabableSizesCheckBox, 0, 1, 1, 1);
|
---|
| 444 | pPreferencesLayout->addWidget(m_pShowHiddenObjectsCheckBox, 1, 1, 1, 1);
|
---|
[100890] | 445 | pPreferencesLayout->addItem(new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding), 2, 0, 1, 2);
|
---|
[75220] | 446 |
|
---|
[100907] | 447 | insertTab(Page_Preferences, pPreferencesTab);
|
---|
[70027] | 448 | }
|
---|
| 449 |
|
---|
[101020] | 450 | void UIFileManagerPaneContainer::prepareLogTab()
|
---|
[100890] | 451 | {
|
---|
| 452 | QWidget *pLogTab = new QWidget;
|
---|
| 453 | AssertReturnVoid(pLogTab);
|
---|
| 454 | QHBoxLayout *pLogLayout = new QHBoxLayout(pLogTab);
|
---|
| 455 | AssertReturnVoid(pLogLayout);
|
---|
| 456 | pLogLayout->setContentsMargins(0, 0, 0, 0);
|
---|
| 457 | m_pLogTextEdit = new UIFileManagerLogViewer;
|
---|
| 458 | if (m_pLogTextEdit)
|
---|
| 459 | pLogLayout->addWidget(m_pLogTextEdit);
|
---|
[100907] | 460 | insertTab(Page_Log, pLogTab);
|
---|
[100890] | 461 | }
|
---|
| 462 |
|
---|
[101020] | 463 | void UIFileManagerPaneContainer::prepareOperationsTab()
|
---|
[100893] | 464 | {
|
---|
| 465 | QPalette pal = QApplication::palette();
|
---|
| 466 | pal.setColor(QPalette::Active, QPalette::Window, pal.color(QPalette::Active, QPalette::Base));
|
---|
| 467 | setPalette(pal);
|
---|
| 468 |
|
---|
| 469 | m_pScrollArea = new QScrollArea;
|
---|
| 470 | AssertReturnVoid(m_pScrollArea);
|
---|
| 471 | QWidget *pOperationsTab = new QWidget;
|
---|
| 472 | AssertReturnVoid(pOperationsTab);
|
---|
| 473 | m_pOperationsTabLayout = new QVBoxLayout;
|
---|
| 474 | AssertReturnVoid(m_pOperationsTabLayout);
|
---|
| 475 |
|
---|
| 476 | QScrollBar *pVerticalScrollBar = m_pScrollArea->verticalScrollBar();
|
---|
| 477 | if (pVerticalScrollBar)
|
---|
[101020] | 478 | QObject::connect(pVerticalScrollBar, &QScrollBar::rangeChanged, this, &UIFileManagerPaneContainer::sltScrollToBottom);
|
---|
[100893] | 479 |
|
---|
| 480 | m_pScrollArea->setBackgroundRole(QPalette::Window);
|
---|
| 481 | m_pScrollArea->setWidgetResizable(true);
|
---|
| 482 |
|
---|
| 483 | //mainLayout()->addWidget(m_pScrollArea);
|
---|
| 484 |
|
---|
| 485 | m_pScrollArea->setWidget(pOperationsTab);
|
---|
| 486 | pOperationsTab->setLayout(m_pOperationsTabLayout);
|
---|
| 487 | m_pOperationsTabLayout->addStretch(4);
|
---|
[100907] | 488 | insertTab(Page_Operations, m_pScrollArea);
|
---|
[100893] | 489 | }
|
---|
| 490 |
|
---|
[101020] | 491 | void UIFileManagerPaneContainer::sltListDirectoryCheckBoxToogled(bool bChecked)
|
---|
[100887] | 492 | {
|
---|
| 493 | if (!m_pFileManagerOptions)
|
---|
| 494 | return;
|
---|
| 495 | m_pFileManagerOptions->fListDirectoriesOnTop = bChecked;
|
---|
| 496 | emit sigOptionsChanged();
|
---|
| 497 | }
|
---|
[75220] | 498 |
|
---|
[101020] | 499 | void UIFileManagerPaneContainer::sltDeleteConfirmationCheckBoxToogled(bool bChecked)
|
---|
[100887] | 500 | {
|
---|
| 501 | if (!m_pFileManagerOptions)
|
---|
| 502 | return;
|
---|
| 503 | m_pFileManagerOptions->fAskDeleteConfirmation = bChecked;
|
---|
| 504 | emit sigOptionsChanged();
|
---|
| 505 | }
|
---|
[70466] | 506 |
|
---|
[101020] | 507 | void UIFileManagerPaneContainer::sltHumanReabableSizesCheckBoxToogled(bool bChecked)
|
---|
[100887] | 508 | {
|
---|
| 509 | if (!m_pFileManagerOptions)
|
---|
| 510 | return;
|
---|
| 511 | m_pFileManagerOptions->fShowHumanReadableSizes = bChecked;
|
---|
| 512 | emit sigOptionsChanged();
|
---|
| 513 | }
|
---|
| 514 |
|
---|
[101020] | 515 | void UIFileManagerPaneContainer::sltShowHiddenObjectsCheckBoxToggled(bool bChecked)
|
---|
[100887] | 516 | {
|
---|
| 517 | if (!m_pFileManagerOptions)
|
---|
| 518 | return;
|
---|
| 519 | m_pFileManagerOptions->fShowHiddenObjects = bChecked;
|
---|
| 520 | emit sigOptionsChanged();
|
---|
| 521 | }
|
---|
| 522 |
|
---|
[103923] | 523 | void UIFileManagerPaneContainer::sltRetranslateUI()
|
---|
[70466] | 524 | {
|
---|
[100879] | 525 | if (m_pListDirectoriesOnTopCheckBox)
|
---|
| 526 | {
|
---|
| 527 | m_pListDirectoriesOnTopCheckBox->setText(QApplication::translate("UIFileManager", "List directories on top"));
|
---|
| 528 | m_pListDirectoriesOnTopCheckBox->setToolTip(QApplication::translate("UIFileManager", "List directories before files"));
|
---|
| 529 | }
|
---|
[70027] | 530 |
|
---|
[100879] | 531 | if (m_pDeleteConfirmationCheckBox)
|
---|
| 532 | {
|
---|
| 533 | m_pDeleteConfirmationCheckBox->setText(QApplication::translate("UIFileManager", "Ask before delete"));
|
---|
| 534 | m_pDeleteConfirmationCheckBox->setToolTip(QApplication::translate("UIFileManager", "Show a confirmation dialog "
|
---|
| 535 | "before deleting files and directories"));
|
---|
| 536 | }
|
---|
[75220] | 537 |
|
---|
[100879] | 538 | if (m_pHumanReabableSizesCheckBox)
|
---|
[75290] | 539 | {
|
---|
[100879] | 540 | m_pHumanReabableSizesCheckBox->setText(QApplication::translate("UIFileManager", "Human readable sizes"));
|
---|
| 541 | m_pHumanReabableSizesCheckBox->setToolTip(QApplication::translate("UIFileManager", "Show file/directory sizes in human "
|
---|
| 542 | "readable format rather than in bytes"));
|
---|
[75290] | 543 | }
|
---|
[75224] | 544 |
|
---|
[100879] | 545 | if (m_pShowHiddenObjectsCheckBox)
|
---|
[70663] | 546 | {
|
---|
[100879] | 547 | m_pShowHiddenObjectsCheckBox->setText(QApplication::translate("UIFileManager", "Show hidden objects"));
|
---|
| 548 | m_pShowHiddenObjectsCheckBox->setToolTip(QApplication::translate("UIFileManager", "Show hidden files/directories"));
|
---|
[70663] | 549 | }
|
---|
[100906] | 550 |
|
---|
| 551 | setTabText(Page_Preferences, QApplication::translate("UIFileManager", "Preferences"));
|
---|
| 552 | setTabText(Page_Log, QApplication::translate("UIFileManager", "Log"));
|
---|
| 553 | setTabText(Page_Operations, QApplication::translate("UIFileManager", "Operations"));
|
---|
[70027] | 554 | }
|
---|
| 555 |
|
---|
[101020] | 556 | void UIFileManagerPaneContainer::updatePreferences()
|
---|
[100887] | 557 | {
|
---|
| 558 | if (!m_pFileManagerOptions)
|
---|
| 559 | return;
|
---|
[70473] | 560 |
|
---|
[100887] | 561 | if (m_pListDirectoriesOnTopCheckBox)
|
---|
| 562 | {
|
---|
| 563 | m_pListDirectoriesOnTopCheckBox->blockSignals(true);
|
---|
| 564 | m_pListDirectoriesOnTopCheckBox->setChecked(m_pFileManagerOptions->fListDirectoriesOnTop);
|
---|
| 565 | m_pListDirectoriesOnTopCheckBox->blockSignals(false);
|
---|
| 566 | }
|
---|
[70529] | 567 |
|
---|
[100887] | 568 | if (m_pDeleteConfirmationCheckBox)
|
---|
| 569 | {
|
---|
| 570 | m_pDeleteConfirmationCheckBox->blockSignals(true);
|
---|
| 571 | m_pDeleteConfirmationCheckBox->setChecked(m_pFileManagerOptions->fAskDeleteConfirmation);
|
---|
| 572 | m_pDeleteConfirmationCheckBox->blockSignals(false);
|
---|
| 573 | }
|
---|
| 574 |
|
---|
| 575 | if (m_pHumanReabableSizesCheckBox)
|
---|
| 576 | {
|
---|
| 577 | m_pHumanReabableSizesCheckBox->blockSignals(true);
|
---|
| 578 | m_pHumanReabableSizesCheckBox->setChecked(m_pFileManagerOptions->fShowHumanReadableSizes);
|
---|
| 579 | m_pHumanReabableSizesCheckBox->blockSignals(false);
|
---|
| 580 | }
|
---|
| 581 |
|
---|
| 582 | if (m_pShowHiddenObjectsCheckBox)
|
---|
| 583 | {
|
---|
| 584 | m_pShowHiddenObjectsCheckBox->blockSignals(true);
|
---|
| 585 | m_pShowHiddenObjectsCheckBox->setChecked(m_pFileManagerOptions->fShowHiddenObjects);
|
---|
| 586 | m_pShowHiddenObjectsCheckBox->blockSignals(false);
|
---|
| 587 | }
|
---|
| 588 | }
|
---|
| 589 |
|
---|
[101020] | 590 | void UIFileManagerPaneContainer::appendLog(const QString &strLog, const QString &strMachineName, FileManagerLogType eLogType)
|
---|
[100890] | 591 | {
|
---|
| 592 | if (!m_pLogTextEdit)
|
---|
| 593 | return;
|
---|
| 594 | QString strStartTag("<font color=\"Black\">");
|
---|
| 595 | QString strEndTag("</font>");
|
---|
| 596 | if (eLogType == FileManagerLogType_Error)
|
---|
| 597 | {
|
---|
| 598 | strStartTag = "<b><font color=\"Red\">";
|
---|
| 599 | strEndTag = "</font></b>";
|
---|
| 600 | }
|
---|
| 601 | QString strColoredLog = QString("%1 %2: %3 %4 %5").arg(strStartTag).arg(QTime::currentTime().toString("hh:mm:ss:z")).arg(strMachineName).arg(strLog).arg(strEndTag);
|
---|
| 602 | m_pLogTextEdit->append(strColoredLog);
|
---|
| 603 | m_pLogTextEdit->moveCursor(QTextCursor::End);
|
---|
| 604 | m_pLogTextEdit->ensureCursorVisible();
|
---|
| 605 | }
|
---|
[100887] | 606 |
|
---|
[101020] | 607 | void UIFileManagerPaneContainer::addNewProgress(const CProgress &comProgress, const QString &strSourceTableName)
|
---|
[100893] | 608 | {
|
---|
| 609 | if (!m_pOperationsTabLayout)
|
---|
| 610 | return;
|
---|
| 611 |
|
---|
| 612 | UIFileOperationProgressWidget *pOperationsWidget = new UIFileOperationProgressWidget(comProgress, strSourceTableName);
|
---|
| 613 | if (!pOperationsWidget)
|
---|
| 614 | return;
|
---|
| 615 | m_widgetSet.insert(pOperationsWidget);
|
---|
| 616 | m_pOperationsTabLayout->insertWidget(m_pOperationsTabLayout->count() - 1, pOperationsWidget);
|
---|
| 617 |
|
---|
| 618 | connect(pOperationsWidget, &UIFileOperationProgressWidget::sigProgressComplete,
|
---|
[101020] | 619 | this, &UIFileManagerPaneContainer::sigFileOperationComplete);
|
---|
[100893] | 620 | connect(pOperationsWidget, &UIFileOperationProgressWidget::sigProgressFail,
|
---|
[101020] | 621 | this, &UIFileManagerPaneContainer::sigFileOperationFail);
|
---|
[100893] | 622 |
|
---|
| 623 | connect(pOperationsWidget, &UIFileOperationProgressWidget::sigFocusIn,
|
---|
[101020] | 624 | this, &UIFileManagerPaneContainer::sltHandleWidgetFocusIn);
|
---|
[100893] | 625 | connect(pOperationsWidget, &UIFileOperationProgressWidget::sigFocusOut,
|
---|
[101020] | 626 | this, &UIFileManagerPaneContainer::sltHandleWidgetFocusOut);
|
---|
[100893] | 627 | }
|
---|
| 628 |
|
---|
[101020] | 629 | void UIFileManagerPaneContainer::contextMenuEvent(QContextMenuEvent *pEvent)
|
---|
[100893] | 630 | {
|
---|
| 631 | QMenu *menu = new QMenu(this);
|
---|
| 632 |
|
---|
| 633 | if (m_pWidgetInFocus)
|
---|
| 634 | {
|
---|
| 635 | QAction *pRemoveSelected = menu->addAction(UIFileManager::tr("Remove Selected"));
|
---|
| 636 | connect(pRemoveSelected, &QAction::triggered,
|
---|
[101020] | 637 | this, &UIFileManagerPaneContainer::sltRemoveSelected);
|
---|
[100893] | 638 | }
|
---|
| 639 |
|
---|
| 640 | QAction *pRemoveFinished = menu->addAction(UIFileManager::tr("Remove Finished"));
|
---|
| 641 | QAction *pRemoveAll = menu->addAction(UIFileManager::tr("Remove All"));
|
---|
| 642 |
|
---|
| 643 | connect(pRemoveFinished, &QAction::triggered,
|
---|
[101020] | 644 | this, &UIFileManagerPaneContainer::sltRemoveFinished);
|
---|
[100893] | 645 | connect(pRemoveAll, &QAction::triggered,
|
---|
[101020] | 646 | this, &UIFileManagerPaneContainer::sltRemoveAll);
|
---|
[100893] | 647 |
|
---|
| 648 | menu->exec(pEvent->globalPos());
|
---|
| 649 | delete menu;
|
---|
| 650 | }
|
---|
| 651 |
|
---|
[101020] | 652 | void UIFileManagerPaneContainer::sltRemoveFinished()
|
---|
[100893] | 653 | {
|
---|
| 654 | QList<UIFileOperationProgressWidget*> widgetsToRemove;
|
---|
| 655 | foreach (QWidget *pWidget, m_widgetSet)
|
---|
| 656 | {
|
---|
| 657 | UIFileOperationProgressWidget *pProgressWidget = qobject_cast<UIFileOperationProgressWidget*>(pWidget);
|
---|
| 658 | if (pProgressWidget && pProgressWidget->isCompleted())
|
---|
| 659 | {
|
---|
| 660 | delete pProgressWidget;
|
---|
| 661 | widgetsToRemove << pProgressWidget;
|
---|
| 662 | }
|
---|
| 663 | }
|
---|
| 664 | foreach (UIFileOperationProgressWidget *pWidget, widgetsToRemove)
|
---|
| 665 | m_widgetSet.remove(pWidget);
|
---|
| 666 | }
|
---|
| 667 |
|
---|
[101020] | 668 | void UIFileManagerPaneContainer::sltRemoveAll()
|
---|
[100893] | 669 | {
|
---|
| 670 | foreach (QWidget *pWidget, m_widgetSet)
|
---|
| 671 | {
|
---|
| 672 | if (pWidget)
|
---|
| 673 | {
|
---|
| 674 | delete pWidget;
|
---|
| 675 | }
|
---|
| 676 | }
|
---|
| 677 | m_widgetSet.clear();
|
---|
| 678 | }
|
---|
| 679 |
|
---|
[101020] | 680 | void UIFileManagerPaneContainer::sltRemoveSelected()
|
---|
[100893] | 681 | {
|
---|
| 682 | if (!m_pWidgetInFocus)
|
---|
| 683 | return;
|
---|
| 684 | delete m_pWidgetInFocus;
|
---|
| 685 | m_widgetSet.remove(m_pWidgetInFocus);
|
---|
| 686 | }
|
---|
| 687 |
|
---|
[101020] | 688 | void UIFileManagerPaneContainer::sltHandleWidgetFocusIn(QWidget *pWidget)
|
---|
[100893] | 689 | {
|
---|
| 690 | if (!pWidget)
|
---|
| 691 | return;
|
---|
| 692 | m_pWidgetInFocus = pWidget;
|
---|
| 693 | }
|
---|
| 694 |
|
---|
[101020] | 695 | void UIFileManagerPaneContainer::sltHandleWidgetFocusOut(QWidget *pWidget)
|
---|
[100893] | 696 | {
|
---|
| 697 | if (!pWidget)
|
---|
| 698 | return;
|
---|
| 699 | m_pWidgetInFocus = 0;
|
---|
| 700 | }
|
---|
| 701 |
|
---|
[101020] | 702 | void UIFileManagerPaneContainer::sltScrollToBottom(int iMin, int iMax)
|
---|
[100893] | 703 | {
|
---|
| 704 | Q_UNUSED(iMin);
|
---|
| 705 | if (m_pScrollArea)
|
---|
| 706 | m_pScrollArea->verticalScrollBar()->setValue(iMax);
|
---|
| 707 | }
|
---|
| 708 |
|
---|
| 709 |
|
---|
[101020] | 710 | #include "UIFileManagerPaneContainer.moc"
|
---|