1 | /* $Id: UIFileManagerDialog.cpp 100896 2023-08-17 12:18:19Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox Qt GUI - UIFileManagerDialog 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 <QPushButton>
|
---|
30 | #include <QVBoxLayout>
|
---|
31 |
|
---|
32 | /* GUI includes: */
|
---|
33 | #include "UIDesktopWidgetWatchdog.h"
|
---|
34 | #include "UIExtraDataManager.h"
|
---|
35 | #include "UIIconPool.h"
|
---|
36 | #include "UIFileManager.h"
|
---|
37 | #include "UIFileManagerDialog.h"
|
---|
38 | #include "UICommon.h"
|
---|
39 | #ifdef VBOX_WS_MAC
|
---|
40 | # include "VBoxUtils-darwin.h"
|
---|
41 | #endif
|
---|
42 |
|
---|
43 | /* COM includes: */
|
---|
44 | #include "COMEnums.h"
|
---|
45 | #include "CMachine.h"
|
---|
46 |
|
---|
47 | /*********************************************************************************************************************************
|
---|
48 | * Class UIFileManagerDialogFactory implementation. *
|
---|
49 | *********************************************************************************************************************************/
|
---|
50 |
|
---|
51 | UIFileManagerDialogFactory::UIFileManagerDialogFactory(UIActionPool *pActionPool, const QUuid &uMachineId, const QString &strMachineName)
|
---|
52 | : m_pActionPool(pActionPool)
|
---|
53 | , m_uMachineId(uMachineId)
|
---|
54 | , m_strMachineName(strMachineName)
|
---|
55 | {
|
---|
56 | }
|
---|
57 |
|
---|
58 |
|
---|
59 | UIFileManagerDialogFactory::UIFileManagerDialogFactory()
|
---|
60 | : m_pActionPool(0)
|
---|
61 | , m_uMachineId(QUuid())
|
---|
62 | {
|
---|
63 | }
|
---|
64 |
|
---|
65 | void UIFileManagerDialogFactory::create(QIManagerDialog *&pDialog, QWidget *pCenterWidget)
|
---|
66 | {
|
---|
67 | pDialog = new UIFileManagerDialog(pCenterWidget, m_pActionPool, m_uMachineId, m_strMachineName);
|
---|
68 | }
|
---|
69 |
|
---|
70 |
|
---|
71 | /*********************************************************************************************************************************
|
---|
72 | * Class UIFileManagerDialog implementation. *
|
---|
73 | *********************************************************************************************************************************/
|
---|
74 |
|
---|
75 | UIFileManagerDialog::UIFileManagerDialog(QWidget *pCenterWidget,
|
---|
76 | UIActionPool *pActionPool,
|
---|
77 | const QUuid &uMachineId,
|
---|
78 | const QString &strMachineName)
|
---|
79 | : QIWithRetranslateUI<QIManagerDialog>(pCenterWidget)
|
---|
80 | , m_pActionPool(pActionPool)
|
---|
81 | , m_uMachineId(uMachineId)
|
---|
82 | , m_strMachineName(strMachineName)
|
---|
83 | {
|
---|
84 | }
|
---|
85 |
|
---|
86 | UIFileManagerDialog::~UIFileManagerDialog()
|
---|
87 | {
|
---|
88 | }
|
---|
89 |
|
---|
90 | void UIFileManagerDialog::retranslateUi()
|
---|
91 | {
|
---|
92 | if (!m_strMachineName.isEmpty())
|
---|
93 | setWindowTitle(UIFileManager::tr("%1 - File Manager").arg(m_strMachineName));
|
---|
94 | else
|
---|
95 | setWindowTitle(UIFileManager::tr("File Manager"));
|
---|
96 |
|
---|
97 | /* Retranslate button box buttons: */
|
---|
98 | if (button(ButtonType_Close))
|
---|
99 | {
|
---|
100 | button(ButtonType_Close)->setText(UIFileManager::tr("Close"));
|
---|
101 | button(ButtonType_Close)->setStatusTip(UIFileManager::tr("Close dialog without saving"));
|
---|
102 | button(ButtonType_Close)->setShortcut(Qt::Key_Escape);
|
---|
103 | button(ButtonType_Close)->setToolTip(UIFileManager::tr("Reset Changes (%1)").arg(button(ButtonType_Close)->shortcut().toString()));
|
---|
104 | }
|
---|
105 |
|
---|
106 | if (button(ButtonType_Help))
|
---|
107 | {
|
---|
108 | button(ButtonType_Help)->setText(UIFileManager::tr("Help"));
|
---|
109 | button(ButtonType_Help)->setStatusTip(UIFileManager::tr("Show dialog help"));
|
---|
110 | button(ButtonType_Help)->setShortcut(QKeySequence::HelpContents);
|
---|
111 | button(ButtonType_Help)->setToolTip(UIFileManager::tr("Show Help (%1)").arg(button(ButtonType_Help)->shortcut().toString()));
|
---|
112 | }
|
---|
113 | }
|
---|
114 |
|
---|
115 | void UIFileManagerDialog::configure()
|
---|
116 | {
|
---|
117 | #ifndef VBOX_WS_MAC
|
---|
118 | /* Assign window icon: */
|
---|
119 | setWindowIcon(UIIconPool::iconSetFull(":/file_manager_32px.png", ":/file_manager_16px.png"));
|
---|
120 | #endif
|
---|
121 | }
|
---|
122 |
|
---|
123 | void UIFileManagerDialog::configureCentralWidget()
|
---|
124 | {
|
---|
125 | CMachine comMachine;
|
---|
126 | CVirtualBox vbox = uiCommon().virtualBox();
|
---|
127 | if (!vbox.isNull() && !m_uMachineId.isNull())
|
---|
128 | comMachine = vbox.FindMachine(m_uMachineId.toString());
|
---|
129 | /* Create widget: */
|
---|
130 | UIFileManager *pWidget = new UIFileManager(EmbedTo_Dialog, m_pActionPool,
|
---|
131 | comMachine, this, true);
|
---|
132 |
|
---|
133 | if (pWidget)
|
---|
134 | {
|
---|
135 | /* Configure widget: */
|
---|
136 | setWidget(pWidget);
|
---|
137 | setWidgetMenu(pWidget->menu());
|
---|
138 | #ifdef VBOX_WS_MAC
|
---|
139 | setWidgetToolbar(pWidget->toolbar());
|
---|
140 | #endif
|
---|
141 | connect(pWidget, &UIFileManager::sigSetCloseButtonShortCut,
|
---|
142 | this, &UIFileManagerDialog::sltSetCloseButtonShortCut);
|
---|
143 |
|
---|
144 | /* Add into layout: */
|
---|
145 | centralWidget()->layout()->addWidget(pWidget);
|
---|
146 | }
|
---|
147 | }
|
---|
148 |
|
---|
149 | void UIFileManagerDialog::finalize()
|
---|
150 | {
|
---|
151 | /* Apply language settings: */
|
---|
152 | retranslateUi();
|
---|
153 | manageEscapeShortCut();
|
---|
154 | }
|
---|
155 |
|
---|
156 | void UIFileManagerDialog::loadSettings()
|
---|
157 | {
|
---|
158 | /* Load geometry from extradata: */
|
---|
159 | const QRect geo = gEDataManager->fileManagerDialogGeometry(this, centerWidget());
|
---|
160 | LogRel2(("GUI: UIFileManagerDialog: Restoring geometry to: Origin=%dx%d, Size=%dx%d\n",
|
---|
161 | geo.x(), geo.y(), geo.width(), geo.height()));
|
---|
162 | restoreGeometry(geo);
|
---|
163 | }
|
---|
164 |
|
---|
165 | void UIFileManagerDialog::saveSettings()
|
---|
166 | {
|
---|
167 | /* Save geometry to extradata: */
|
---|
168 | const QRect geo = currentGeometry();
|
---|
169 | LogRel2(("GUI: UIFileManagerDialog: Saving geometry as: Origin=%dx%d, Size=%dx%d\n",
|
---|
170 | geo.x(), geo.y(), geo.width(), geo.height()));
|
---|
171 | gEDataManager->setFileManagerDialogGeometry(geo, isCurrentlyMaximized());
|
---|
172 | }
|
---|
173 |
|
---|
174 | bool UIFileManagerDialog::shouldBeMaximized() const
|
---|
175 | {
|
---|
176 | return gEDataManager->fileManagerDialogShouldBeMaximized();
|
---|
177 | }
|
---|
178 |
|
---|
179 | void UIFileManagerDialog::sltSetCloseButtonShortCut(QKeySequence shortcut)
|
---|
180 | {
|
---|
181 | if (!closeEmitted() && button(ButtonType_Close))
|
---|
182 | button(ButtonType_Close)->setShortcut(shortcut);
|
---|
183 | }
|
---|
184 |
|
---|
185 | void UIFileManagerDialog::manageEscapeShortCut()
|
---|
186 | {
|
---|
187 | UIFileManager *pWidget = qobject_cast<UIFileManager*>(widget());
|
---|
188 | if (!pWidget)
|
---|
189 | return;
|
---|
190 | pWidget->manageEscapeShortCut();
|
---|
191 | }
|
---|