PageRenderTime 29ms CodeModel.GetById 16ms app.highlight 10ms RepoModel.GetById 1ms app.codeStats 0ms

/src/VBox/Frontends/VirtualBox/src/settings/vm/VBoxVMSettingsGeneral.cpp

https://gitlab.com/ufo/virtualbox-ose-3-1-8
C++ | 184 lines | 102 code | 37 blank | 45 comment | 7 complexity | 9f5e78c8fbc9064adb7fa1f454edeff6 MD5 | raw file
  1/** @file
  2 *
  3 * VBox frontends: Qt4 GUI ("VirtualBox"):
  4 * VBoxVMSettingsGeneral class implementation
  5 */
  6
  7/*
  8 * Copyright (C) 2006-2008 Sun Microsystems, Inc.
  9 *
 10 * This file is part of VirtualBox Open Source Edition (OSE), as
 11 * available from http://www.virtualbox.org. This file is free software;
 12 * you can redistribute it and/or modify it under the terms of the GNU
 13 * General Public License (GPL) as published by the Free Software
 14 * Foundation, in version 2 as it comes in the "COPYING" file of the
 15 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
 16 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
 17 *
 18 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
 19 * Clara, CA 95054 USA or visit http://www.sun.com if you need
 20 * additional information or have any questions.
 21 */
 22
 23#include "VBoxVMSettingsGeneral.h"
 24#include "VBoxGlobal.h"
 25#include "VBoxProblemReporter.h"
 26#include "QIWidgetValidator.h"
 27
 28#include <QDir>
 29
 30VBoxVMSettingsGeneral::VBoxVMSettingsGeneral()
 31    : mValidator (0)
 32{
 33    /* Apply UI decorations */
 34    Ui::VBoxVMSettingsGeneral::setupUi (this);
 35
 36    /* Setup validators */
 37    mLeName->setValidator (new QRegExpValidator (QRegExp (".+"), this));
 38
 39    /* Shared Clipboard mode */
 40    mCbClipboard->addItem (""); /* KClipboardMode_Disabled */
 41    mCbClipboard->addItem (""); /* KClipboardMode_HostToGuest */
 42    mCbClipboard->addItem (""); /* KClipboardMode_GuestToHost */
 43    mCbClipboard->addItem (""); /* KClipboardMode_Bidirectional */
 44
 45#ifdef Q_WS_MAC
 46    mTeDescription->setMinimumHeight (150);
 47#endif /* Q_WS_MAC */
 48
 49    /* Applying language settings */
 50    retranslateUi();
 51}
 52
 53bool VBoxVMSettingsGeneral::is64BitOSTypeSelected() const
 54{
 55    return mOSTypeSelector->type().GetIs64Bit();
 56}
 57
 58#ifdef VBOX_WITH_VIDEOHWACCEL
 59bool VBoxVMSettingsGeneral::isWindowsOSTypeSelected() const
 60{
 61    return mOSTypeSelector->type().GetFamilyId() == "Windows";
 62}
 63#endif
 64
 65void VBoxVMSettingsGeneral::getFrom (const CMachine &aMachine)
 66{
 67    mMachine = aMachine;
 68
 69    /* Name */
 70    mLeName->setText (aMachine.GetName());
 71
 72    /* OS type */
 73    mOSTypeSelector->setType (vboxGlobal().vmGuestOSType (aMachine.GetOSTypeId()));
 74
 75    /* Remember mediums mounted at runtime */
 76    QString saveRtimeImages = mMachine.GetExtraData (VBoxDefs::GUI_SaveMountedAtRuntime);
 77    mCbSaveMounted->setChecked (saveRtimeImages != "no");
 78
 79    /* Show Mini ToolBar in fullscreen/seamless */
 80    QString showMiniToolBar = mMachine.GetExtraData (VBoxDefs::GUI_ShowMiniToolBar);
 81    mCbShowToolBar->setChecked (showMiniToolBar != "no");
 82
 83    /* Show Mini ToolBar at top */
 84    QString miniToolBarAlignment = mMachine.GetExtraData (VBoxDefs::GUI_MiniToolBarAlignment);
 85    mCbToolBarAlignment->setChecked (miniToolBarAlignment == "top");
 86    mCbToolBarAlignment->setEnabled (mCbShowToolBar->isChecked());
 87
 88    /* Snapshot folder */
 89    mPsSnapshot->setPath (aMachine.GetSnapshotFolder());
 90    mPsSnapshot->setHomeDir (QFileInfo (mMachine.GetSettingsFilePath()).absolutePath());
 91
 92    /* Shared clipboard mode */
 93    mCbClipboard->setCurrentIndex (aMachine.GetClipboardMode());
 94
 95    /* Description */
 96    mTeDescription->setPlainText (aMachine.GetDescription());
 97
 98    if (mValidator)
 99        mValidator->revalidate();
100}
101
102void VBoxVMSettingsGeneral::putBackTo()
103{
104    /* Name */
105    mMachine.SetName (mLeName->text());
106
107    /* OS type */
108    AssertMsg (!mOSTypeSelector->type().isNull(), ("mOSTypeSelector must return non-null type"));
109    mMachine.SetOSTypeId (mOSTypeSelector->type().GetId());
110
111    /* Remember mediums mounted at runtime */
112    mMachine.SetExtraData (VBoxDefs::GUI_SaveMountedAtRuntime,
113                           mCbSaveMounted->isChecked() ? "yes" : "no");
114
115    /* Show Mini ToolBar in fullscreen/seamless */
116    mMachine.SetExtraData (VBoxDefs::GUI_ShowMiniToolBar,
117                           mCbShowToolBar->isChecked() ? "yes" : "no");
118
119    /* Show Mini ToolBar at top */
120    mMachine.SetExtraData (VBoxDefs::GUI_MiniToolBarAlignment,
121                           mCbToolBarAlignment->isChecked() ? "top" : "bottom");
122
123    /* Saved state folder */
124    if (mPsSnapshot->isModified())
125    {
126        mMachine.SetSnapshotFolder (mPsSnapshot->path());
127        if (!mMachine.isOk())
128            vboxProblem().cannotSetSnapshotFolder (mMachine,
129                    QDir::toNativeSeparators (mPsSnapshot->path()));
130    }
131
132    /* Shared clipboard mode */
133    mMachine.SetClipboardMode ((KClipboardMode) mCbClipboard->currentIndex());
134
135    /* Description (set empty to null to avoid an empty <Description> node
136     * in the settings file) */
137    mMachine.SetDescription (mTeDescription->toPlainText().isEmpty() ?
138                             QString::null : mTeDescription->toPlainText());
139}
140
141void VBoxVMSettingsGeneral::setValidator (QIWidgetValidator *aVal)
142{
143    mValidator = aVal;
144    connect (mOSTypeSelector, SIGNAL (osTypeChanged()), mValidator, SLOT (revalidate()));
145}
146
147void VBoxVMSettingsGeneral::setOrderAfter (QWidget *aWidget)
148{
149    /* Setup Tab order */
150    setTabOrder (aWidget, mTwGeneral->focusProxy());
151    setTabOrder (mTwGeneral->focusProxy(), mLeName);
152    setTabOrder (mLeName, mOSTypeSelector);
153
154    setTabOrder (mOSTypeSelector, mPsSnapshot);
155    setTabOrder (mPsSnapshot, mCbClipboard);
156    setTabOrder (mCbClipboard, mCbSaveMounted);
157
158    setTabOrder (mCbSaveMounted, mTeDescription);
159}
160
161void VBoxVMSettingsGeneral::retranslateUi()
162{
163    /* Translate uic generated strings */
164    Ui::VBoxVMSettingsGeneral::retranslateUi (this);
165
166    /* Path selector */
167    mPsSnapshot->setWhatsThis (tr ("Displays the path where snapshots of this "
168                                   "virtual machine will be stored. Be aware that "
169                                   "snapshots can take quite a lot of disk "
170                                   "space."));
171
172    /* Shared Clipboard mode */
173    mCbClipboard->setItemText (0, vboxGlobal().toString (KClipboardMode_Disabled));
174    mCbClipboard->setItemText (1, vboxGlobal().toString (KClipboardMode_HostToGuest));
175    mCbClipboard->setItemText (2, vboxGlobal().toString (KClipboardMode_GuestToHost));
176    mCbClipboard->setItemText (3, vboxGlobal().toString (KClipboardMode_Bidirectional));
177}
178
179void VBoxVMSettingsGeneral::showEvent (QShowEvent *aEvent)
180{
181    QCoreApplication::sendPostedEvents();
182    VBoxSettingsPage::showEvent (aEvent);
183}
184