VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/guestctrl/UIFileManagerPaneContainer.cpp@ 103987

Last change on this file since 103987 was 103987, checked in by vboxsync, 3 months ago

FE/Qt: bugref:10624. Adding RT_FINAL to virtual functions whereever appropriate.

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

© 2023 Oracle
ContactPrivacy policyTerms of Use