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