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