VirtualBox

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

Last change on this file since 104586 was 104297, checked in by vboxsync, 8 months ago

FE/Qt. bugref:10622. Using new UITranslationEventListener in the guest control related GUI classes.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 24.3 KB
Line 
1/* $Id: UIFileManagerPaneContainer.cpp 104297 2024-04-11 13:20:43Z 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 <QApplication>
30#include <QCheckBox>
31#include <QHBoxLayout>
32#include <QMenu>
33#include <QProgressBar>
34#include <QScrollArea>
35#include <QScrollBar>
36#include <QSpinBox>
37#include <QStyle>
38#include <QTabWidget>
39#include <QTextEdit>
40#include <QTime>
41
42/* GUI includes: */
43#include "QILabel.h"
44#include "QIToolButton.h"
45#include "UIErrorString.h"
46#include "UIFileManagerPaneContainer.h"
47#include "UIFileManager.h"
48#include "UIProgressEventHandler.h"
49#include "UITranslationEventListener.h"
50
51/* Other VBox includes: */
52#include <iprt/assert.h>
53
54
55/*********************************************************************************************************************************
56* UIFileOperationProgressWidget definition. *
57*********************************************************************************************************************************/
58
59class UIFileOperationProgressWidget : public QFrame
60{
61
62 Q_OBJECT;
63
64signals:
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
71public:
72
73 UIFileOperationProgressWidget(const CProgress &comProgress, const QString &strSourceTableName, QWidget *pParent = 0);
74 ~UIFileOperationProgressWidget();
75 bool isCompleted() const;
76 bool isCanceled() const;
77
78protected:
79
80 virtual void focusInEvent(QFocusEvent *pEvent) RT_OVERRIDE RT_FINAL;
81 virtual void focusOutEvent(QFocusEvent *pEvent) RT_OVERRIDE RT_FINAL;
82
83private slots:
84
85 void sltHandleProgressPercentageChange(const QUuid &uProgressId, const int iPercent);
86 void sltHandleProgressComplete(const QUuid &uProgressId);
87 void sltCancelProgress();
88 void sltRetranslateUI();
89
90private:
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
125UIFileOperationProgressWidget::UIFileOperationProgressWidget(const CProgress &comProgress, const QString &strSourceTableName, QWidget *pParent /* = 0 */)
126 : QFrame(pParent)
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
142UIFileOperationProgressWidget::~UIFileOperationProgressWidget()
143{
144 cleanupEventHandler();
145}
146
147bool UIFileOperationProgressWidget::isCompleted() const
148{
149 if (m_comProgress.isNull())
150 return true;
151 return m_comProgress.GetCompleted();
152}
153
154bool UIFileOperationProgressWidget::isCanceled() const
155{
156 if (m_comProgress.isNull())
157 return true;
158 return m_comProgress.GetCanceled();
159}
160
161void UIFileOperationProgressWidget::sltRetranslateUI()
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
194void UIFileOperationProgressWidget::focusInEvent(QFocusEvent *pEvent)
195{
196 QFrame::focusInEvent(pEvent);
197 emit sigFocusIn(this);
198}
199
200void UIFileOperationProgressWidget::focusOutEvent(QFocusEvent *pEvent)
201{
202 QFrame::focusOutEvent(pEvent);
203 emit sigFocusOut(this);
204}
205
206void UIFileOperationProgressWidget::prepare()
207{
208 prepareWidgets();
209 prepareEventHandler();
210 sltRetranslateUI();
211 connect(&translationEventListener(), &UITranslationEventListener::sigRetranslateUI,
212 this, &UIFileOperationProgressWidget::sltRetranslateUI);
213}
214
215void 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);
258 sltRetranslateUI();
259}
260
261void 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;
271 sltRetranslateUI();
272}
273
274void UIFileOperationProgressWidget::cleanupEventHandler()
275{
276 delete m_pEventHandler;
277 m_pEventHandler = 0;
278}
279
280void UIFileOperationProgressWidget::sltHandleProgressPercentageChange(const QUuid &uProgressId, const int iPercent)
281{
282 Q_UNUSED(uProgressId);
283 m_pProgressBar->setValue(iPercent);
284}
285
286void 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();
306 sltRetranslateUI();
307}
308
309void 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();
319 sltRetranslateUI();
320}
321
322/*********************************************************************************************************************************
323* UIFileManagerLogViewer definition. *
324*********************************************************************************************************************************/
325
326class UIFileManagerLogViewer : public QTextEdit
327{
328
329 Q_OBJECT;
330
331public:
332
333 UIFileManagerLogViewer(QWidget *pParent = 0);
334
335protected:
336
337 virtual void contextMenuEvent(QContextMenuEvent * event) final override;
338
339private slots:
340
341 void sltClear();
342};
343
344/*********************************************************************************************************************************
345* UIFileManagerLogViewer implementation. *
346*********************************************************************************************************************************/
347
348UIFileManagerLogViewer::UIFileManagerLogViewer(QWidget *pParent /* = 0 */)
349 :QTextEdit(pParent)
350{
351 setUndoRedoEnabled(false);
352 setReadOnly(true);
353}
354
355void 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
365void UIFileManagerLogViewer::sltClear()
366{
367 clear();
368}
369
370
371/*********************************************************************************************************************************
372* UIFileManagerPaneContainer implementation. *
373*********************************************************************************************************************************/
374
375UIFileManagerPaneContainer::UIFileManagerPaneContainer(QWidget *pParent, UIFileManagerOptions *pFileManagerOptions)
376 : UIPaneContainer(pParent)
377 , m_pListDirectoriesOnTopCheckBox(0)
378 , m_pDeleteConfirmationCheckBox(0)
379 , m_pHumanReabableSizesCheckBox(0)
380 , m_pShowHiddenObjectsCheckBox(0)
381 , m_pFileManagerOptions(pFileManagerOptions)
382 , m_pLogTextEdit(0)
383 , m_pScrollArea(0)
384 , m_pOperationsTabLayout(0)
385 , m_pContainerSpaceItem(0)
386 , m_pWidgetInFocus(0)
387{
388 prepare();
389 sltRetranslateUI();
390 connect(&translationEventListener(), &UITranslationEventListener::sigRetranslateUI,
391 this, &UIFileManagerPaneContainer::sltRetranslateUI);
392}
393
394
395void UIFileManagerPaneContainer::prepare()
396{
397 preparePreferencesTab();
398 prepareLogTab();
399 prepareOperationsTab();
400}
401
402void UIFileManagerPaneContainer::preparePreferencesTab()
403{
404 QWidget *pPreferencesTab = new QWidget;
405 m_pListDirectoriesOnTopCheckBox = new QCheckBox;
406 m_pDeleteConfirmationCheckBox = new QCheckBox;
407 m_pHumanReabableSizesCheckBox = new QCheckBox;
408 m_pShowHiddenObjectsCheckBox = new QCheckBox;
409
410 AssertReturnVoid(pPreferencesTab);
411 AssertReturnVoid(m_pListDirectoriesOnTopCheckBox);
412 AssertReturnVoid(m_pDeleteConfirmationCheckBox);
413 AssertReturnVoid(m_pHumanReabableSizesCheckBox);
414 AssertReturnVoid(m_pShowHiddenObjectsCheckBox);
415
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 }
427
428 connect(m_pListDirectoriesOnTopCheckBox, &QCheckBox::toggled,
429 this, &UIFileManagerPaneContainer::sltListDirectoryCheckBoxToogled);
430 connect(m_pDeleteConfirmationCheckBox, &QCheckBox::toggled,
431 this, &UIFileManagerPaneContainer::sltDeleteConfirmationCheckBoxToogled);
432 connect(m_pHumanReabableSizesCheckBox, &QCheckBox::toggled,
433 this, &UIFileManagerPaneContainer::sltHumanReabableSizesCheckBoxToogled);
434 connect(m_pShowHiddenObjectsCheckBox, &QCheckBox::toggled,
435 this, &UIFileManagerPaneContainer::sltShowHiddenObjectsCheckBoxToggled);
436
437 QGridLayout *pPreferencesLayout = new QGridLayout(pPreferencesTab);
438 AssertReturnVoid(pPreferencesLayout);
439 //pPreferencesLayout->setContentsMargins(0, 0, 0, 0);
440
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);
445 pPreferencesLayout->addItem(new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding), 2, 0, 1, 2);
446
447 insertTab(Page_Preferences, pPreferencesTab);
448}
449
450void UIFileManagerPaneContainer::prepareLogTab()
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);
460 insertTab(Page_Log, pLogTab);
461}
462
463void UIFileManagerPaneContainer::prepareOperationsTab()
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)
478 QObject::connect(pVerticalScrollBar, &QScrollBar::rangeChanged, this, &UIFileManagerPaneContainer::sltScrollToBottom);
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);
488 insertTab(Page_Operations, m_pScrollArea);
489}
490
491void UIFileManagerPaneContainer::sltListDirectoryCheckBoxToogled(bool bChecked)
492{
493 if (!m_pFileManagerOptions)
494 return;
495 m_pFileManagerOptions->fListDirectoriesOnTop = bChecked;
496 emit sigOptionsChanged();
497}
498
499void UIFileManagerPaneContainer::sltDeleteConfirmationCheckBoxToogled(bool bChecked)
500{
501 if (!m_pFileManagerOptions)
502 return;
503 m_pFileManagerOptions->fAskDeleteConfirmation = bChecked;
504 emit sigOptionsChanged();
505}
506
507void UIFileManagerPaneContainer::sltHumanReabableSizesCheckBoxToogled(bool bChecked)
508{
509 if (!m_pFileManagerOptions)
510 return;
511 m_pFileManagerOptions->fShowHumanReadableSizes = bChecked;
512 emit sigOptionsChanged();
513}
514
515void UIFileManagerPaneContainer::sltShowHiddenObjectsCheckBoxToggled(bool bChecked)
516{
517 if (!m_pFileManagerOptions)
518 return;
519 m_pFileManagerOptions->fShowHiddenObjects = bChecked;
520 emit sigOptionsChanged();
521}
522
523void UIFileManagerPaneContainer::sltRetranslateUI()
524{
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 }
530
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 }
537
538 if (m_pHumanReabableSizesCheckBox)
539 {
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"));
543 }
544
545 if (m_pShowHiddenObjectsCheckBox)
546 {
547 m_pShowHiddenObjectsCheckBox->setText(QApplication::translate("UIFileManager", "Show hidden objects"));
548 m_pShowHiddenObjectsCheckBox->setToolTip(QApplication::translate("UIFileManager", "Show hidden files/directories"));
549 }
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"));
554}
555
556void UIFileManagerPaneContainer::updatePreferences()
557{
558 if (!m_pFileManagerOptions)
559 return;
560
561 if (m_pListDirectoriesOnTopCheckBox)
562 {
563 m_pListDirectoriesOnTopCheckBox->blockSignals(true);
564 m_pListDirectoriesOnTopCheckBox->setChecked(m_pFileManagerOptions->fListDirectoriesOnTop);
565 m_pListDirectoriesOnTopCheckBox->blockSignals(false);
566 }
567
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
590void UIFileManagerPaneContainer::appendLog(const QString &strLog, const QString &strMachineName, FileManagerLogType eLogType)
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}
606
607void UIFileManagerPaneContainer::addNewProgress(const CProgress &comProgress, const QString &strSourceTableName)
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,
619 this, &UIFileManagerPaneContainer::sigFileOperationComplete);
620 connect(pOperationsWidget, &UIFileOperationProgressWidget::sigProgressFail,
621 this, &UIFileManagerPaneContainer::sigFileOperationFail);
622
623 connect(pOperationsWidget, &UIFileOperationProgressWidget::sigFocusIn,
624 this, &UIFileManagerPaneContainer::sltHandleWidgetFocusIn);
625 connect(pOperationsWidget, &UIFileOperationProgressWidget::sigFocusOut,
626 this, &UIFileManagerPaneContainer::sltHandleWidgetFocusOut);
627}
628
629void UIFileManagerPaneContainer::contextMenuEvent(QContextMenuEvent *pEvent)
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,
637 this, &UIFileManagerPaneContainer::sltRemoveSelected);
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,
644 this, &UIFileManagerPaneContainer::sltRemoveFinished);
645 connect(pRemoveAll, &QAction::triggered,
646 this, &UIFileManagerPaneContainer::sltRemoveAll);
647
648 menu->exec(pEvent->globalPos());
649 delete menu;
650}
651
652void UIFileManagerPaneContainer::sltRemoveFinished()
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
668void UIFileManagerPaneContainer::sltRemoveAll()
669{
670 foreach (QWidget *pWidget, m_widgetSet)
671 {
672 if (pWidget)
673 {
674 delete pWidget;
675 }
676 }
677 m_widgetSet.clear();
678}
679
680void UIFileManagerPaneContainer::sltRemoveSelected()
681{
682 if (!m_pWidgetInFocus)
683 return;
684 delete m_pWidgetInFocus;
685 m_widgetSet.remove(m_pWidgetInFocus);
686}
687
688void UIFileManagerPaneContainer::sltHandleWidgetFocusIn(QWidget *pWidget)
689{
690 if (!pWidget)
691 return;
692 m_pWidgetInFocus = pWidget;
693}
694
695void UIFileManagerPaneContainer::sltHandleWidgetFocusOut(QWidget *pWidget)
696{
697 if (!pWidget)
698 return;
699 m_pWidgetInFocus = 0;
700}
701
702void UIFileManagerPaneContainer::sltScrollToBottom(int iMin, int iMax)
703{
704 Q_UNUSED(iMin);
705 if (m_pScrollArea)
706 m_pScrollArea->verticalScrollBar()->setValue(iMax);
707}
708
709
710#include "UIFileManagerPaneContainer.moc"
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette