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