1 | /* $Id: UIFileManagerDialog.cpp 76553 2019-01-01 01:45:53Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox Qt GUI - UIFileManagerDialog class implementation.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2010-2019 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | */
|
---|
17 |
|
---|
18 | #ifdef VBOX_WITH_PRECOMPILED_HEADERS
|
---|
19 | # include <precomp.h>
|
---|
20 | #else /* !VBOX_WITH_PRECOMPILED_HEADERS */
|
---|
21 |
|
---|
22 | /* Qt includes: */
|
---|
23 | # include <QPushButton>
|
---|
24 | # include <QVBoxLayout>
|
---|
25 |
|
---|
26 | /* GUI includes: */
|
---|
27 | # include "UIDesktopWidgetWatchdog.h"
|
---|
28 | # include "UIExtraDataManager.h"
|
---|
29 | # include "UIIconPool.h"
|
---|
30 | # include "UIFileManager.h"
|
---|
31 | # include "UIFileManagerDialog.h"
|
---|
32 | # include "VBoxGlobal.h"
|
---|
33 | # ifdef VBOX_WS_MAC
|
---|
34 | # include "VBoxUtils-darwin.h"
|
---|
35 | # endif
|
---|
36 |
|
---|
37 | #endif /* !VBOX_WITH_PRECOMPILED_HEADERS */
|
---|
38 |
|
---|
39 |
|
---|
40 | /*********************************************************************************************************************************
|
---|
41 | * Class UIFileManagerDialogFactory implementation. *
|
---|
42 | *********************************************************************************************************************************/
|
---|
43 |
|
---|
44 | UIFileManagerDialogFactory::UIFileManagerDialogFactory(UIActionPool *pActionPool /* = 0 */,
|
---|
45 | const CGuest &comGuest /* = CGuest() */,
|
---|
46 | const QString &strMachineName /* = QString() */)
|
---|
47 | : m_pActionPool(pActionPool)
|
---|
48 | , m_comGuest(comGuest)
|
---|
49 | , m_strMachineName(strMachineName)
|
---|
50 | {
|
---|
51 | }
|
---|
52 |
|
---|
53 | void UIFileManagerDialogFactory::create(QIManagerDialog *&pDialog, QWidget *pCenterWidget)
|
---|
54 | {
|
---|
55 | pDialog = new UIFileManagerDialog(pCenterWidget, m_pActionPool, m_comGuest, m_strMachineName);
|
---|
56 | }
|
---|
57 |
|
---|
58 |
|
---|
59 | /*********************************************************************************************************************************
|
---|
60 | * Class UIFileManagerDialog implementation. *
|
---|
61 | *********************************************************************************************************************************/
|
---|
62 |
|
---|
63 | UIFileManagerDialog::UIFileManagerDialog(QWidget *pCenterWidget,
|
---|
64 | UIActionPool *pActionPool,
|
---|
65 | const CGuest &comGuest,
|
---|
66 | const QString &strMachineName /* = QString() */)
|
---|
67 | : QIWithRetranslateUI<QIManagerDialog>(pCenterWidget)
|
---|
68 | , m_pActionPool(pActionPool)
|
---|
69 | , m_comGuest(comGuest)
|
---|
70 | , m_strMachineName(strMachineName)
|
---|
71 | {
|
---|
72 | }
|
---|
73 |
|
---|
74 | void UIFileManagerDialog::retranslateUi()
|
---|
75 | {
|
---|
76 | /* Translate window title: */
|
---|
77 | setWindowTitle(UIFileManager::tr("%1 - File Manager").arg(m_strMachineName));
|
---|
78 | /* Translate buttons: */
|
---|
79 | button(ButtonType_Close)->setText(UIFileManager::tr("Close"));
|
---|
80 | }
|
---|
81 |
|
---|
82 | void UIFileManagerDialog::configure()
|
---|
83 | {
|
---|
84 | /* Apply window icons: */
|
---|
85 | setWindowIcon(UIIconPool::iconSetFull(":/file_manager_32px.png", ":/file_manager_16px.png"));
|
---|
86 | }
|
---|
87 |
|
---|
88 | void UIFileManagerDialog::configureCentralWidget()
|
---|
89 | {
|
---|
90 | /* Create widget: */
|
---|
91 | UIFileManager *pWidget = new UIFileManager(EmbedTo_Dialog, m_pActionPool,
|
---|
92 | m_comGuest, this);
|
---|
93 |
|
---|
94 | if (pWidget)
|
---|
95 | {
|
---|
96 | /* Configure widget: */
|
---|
97 | setWidget(pWidget);
|
---|
98 | setWidgetMenu(pWidget->menu());
|
---|
99 | #ifdef VBOX_WS_MAC
|
---|
100 | setWidgetToolbar(pWidget->toolbar());
|
---|
101 | #endif
|
---|
102 | connect(pWidget, &UIFileManager::sigSetCloseButtonShortCut,
|
---|
103 | this, &UIFileManagerDialog::sltSetCloseButtonShortCut);
|
---|
104 |
|
---|
105 | /* Add into layout: */
|
---|
106 | centralWidget()->layout()->addWidget(pWidget);
|
---|
107 | }
|
---|
108 | }
|
---|
109 |
|
---|
110 | void UIFileManagerDialog::finalize()
|
---|
111 | {
|
---|
112 | /* Apply language settings: */
|
---|
113 | retranslateUi();
|
---|
114 | manageEscapeShortCut();
|
---|
115 | }
|
---|
116 |
|
---|
117 | void UIFileManagerDialog::loadSettings()
|
---|
118 | {
|
---|
119 | const QRect desktopRect = gpDesktop->availableGeometry(this);
|
---|
120 | int iDefaultWidth = desktopRect.width() / 2;
|
---|
121 | int iDefaultHeight = desktopRect.height() * 3 / 4;
|
---|
122 |
|
---|
123 | QRect defaultGeometry(0, 0, iDefaultWidth, iDefaultHeight);
|
---|
124 | if (centerWidget())
|
---|
125 | defaultGeometry.moveCenter(centerWidget()->geometry().center());
|
---|
126 |
|
---|
127 | /* Load geometry from extradata: */
|
---|
128 | QRect geometry = gEDataManager->fileManagerDialogGeometry(this, defaultGeometry);
|
---|
129 |
|
---|
130 | /* Restore geometry: */
|
---|
131 | LogRel2(("GUI: UIFileManagerDialog: Restoring geometry to: Origin=%dx%d, Size=%dx%d\n",
|
---|
132 | geometry.x(), geometry.y(), geometry.width(), geometry.height()));
|
---|
133 | setDialogGeometry(geometry);
|
---|
134 | }
|
---|
135 |
|
---|
136 | void UIFileManagerDialog::saveSettings() const
|
---|
137 | {
|
---|
138 | /* Save window geometry to extradata: */
|
---|
139 | const QRect saveGeometry = geometry();
|
---|
140 | #ifdef VBOX_WS_MAC
|
---|
141 | /* darwinIsWindowMaximized expects a non-const QWidget*. thus const_cast: */
|
---|
142 | QWidget *pw = const_cast<QWidget*>(qobject_cast<const QWidget*>(this));
|
---|
143 | gEDataManager->setFileManagerDialogGeometry(saveGeometry, ::darwinIsWindowMaximized(pw));
|
---|
144 | #else /* !VBOX_WS_MAC */
|
---|
145 | gEDataManager->setFileManagerDialogGeometry(saveGeometry, isMaximized());
|
---|
146 | #endif /* !VBOX_WS_MAC */
|
---|
147 | LogRel2(("GUI: File Manager Dialog: Geometry saved as: Origin=%dx%d, Size=%dx%d\n",
|
---|
148 | saveGeometry.x(), saveGeometry.y(), saveGeometry.width(), saveGeometry.height()));
|
---|
149 | }
|
---|
150 |
|
---|
151 | bool UIFileManagerDialog::shouldBeMaximized() const
|
---|
152 | {
|
---|
153 | return gEDataManager->fileManagerDialogShouldBeMaximized();
|
---|
154 | }
|
---|
155 |
|
---|
156 | void UIFileManagerDialog::sltSetCloseButtonShortCut(QKeySequence shortcut)
|
---|
157 | {
|
---|
158 | if (button(ButtonType_Close))
|
---|
159 | button(ButtonType_Close)->setShortcut(shortcut);
|
---|
160 | }
|
---|
161 |
|
---|
162 | void UIFileManagerDialog::manageEscapeShortCut()
|
---|
163 | {
|
---|
164 | UIFileManager *pWidget = qobject_cast<UIFileManager*>(widget());
|
---|
165 | if (!pWidget)
|
---|
166 | return;
|
---|
167 | pWidget->manageEscapeShortCut();
|
---|
168 | }
|
---|