VBoxGlobal.cpp revision bb8bff70351ae38a0b4e36f61c237a289af718d6
/** @file
*
* VBox frontends: Qt GUI ("VirtualBox"):
* VBoxGlobal class implementation
*/
/*
* Copyright (C) 2008 Sun Microsystems, Inc.
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
* Clara, CA 95054 USA or visit http://www.sun.com if you need
* additional information or have any questions.
*/
#include "VBoxGlobal.h"
#include <VBox/VBoxHDD-new.h>
#include "VBoxDefs.h"
#include "VBoxSelectorWnd.h"
#include "VBoxConsoleWnd.h"
#include "VBoxProblemReporter.h"
#include "QIHotKeyEdit.h"
#include "QIMessageBox.h"
#include "QIDialogButtonBox.h"
#ifdef VBOX_WITH_REGISTRATION
#include "VBoxRegistrationDlg.h"
#endif
#include "VBoxUpdateDlg.h"
/* Qt includes */
#include <QLibraryInfo>
#include <QFileDialog>
#include <QToolTip>
#include <QTranslator>
#include <QDesktopWidget>
#include <QMutex>
#include <QToolButton>
#include <QProcess>
#include <QThread>
#include <QPainter>
#include <math.h>
#ifdef Q_WS_X11
#ifndef VBOX_OSE
# include "VBoxLicenseViewer.h"
#endif /* VBOX_OSE */
#include <QTextBrowser>
#include <QScrollBar>
#include <QX11Info>
#endif
#if defined (Q_WS_MAC)
#include "VBoxUtils.h"
#endif
#if defined (Q_WS_WIN)
#include "shlobj.h"
#include <QEventLoop>
#endif
#if defined (Q_WS_X11)
* in COMDefs.h. A better fix would be to isolate X11-specific
* stuff by placing XX* helpers below to a separate source file. */
#endif
#ifdef VBOX_GUI_WITH_SYSTRAY
#if defined(RT_OS_WINDOWS) || defined(RT_OS_OS2)
#define HOSTSUFF_EXE ".exe"
#else /* !RT_OS_WINDOWS */
#define HOSTSUFF_EXE ""
#endif /* !RT_OS_WINDOWS */
#endif
#if defined (Q_WS_X11)
#endif
//#warning "port me: check this"
/// @todo bird: Use (U)INT_PTR, (U)LONG_PTR, DWORD_PTR, or (u)intptr_t.
#if defined(Q_OS_WIN64)
#else
typedef long Q_LONG; /* word up to 64 bit signed */
typedef unsigned long Q_ULONG; /* word up to 64 bit unsigned */
#endif
// VBoxMedium
/////////////////////////////////////////////////////////////////////////////
void VBoxMedium::init()
{
switch (mType)
{
case VBoxDefs::MediaType_HardDisk:
{
break;
}
case VBoxDefs::MediaType_DVD:
{
break;
}
case VBoxDefs::MediaType_Floppy:
{
break;
}
default:
AssertFailed();
}
refresh();
}
/**
* Queries the medium state. Call this and then read the state field instad
* of calling GetState() on medium directly as it will properly handle the
* situation when GetState() itself fails by setting state to Inaccessible
* and memorizing the error info describing why GetState() failed.
*
* As the last step, this method calls #refresh() to refresh all precomposed
* strings.
*
* @note This method blocks for the duration of the state check. Since this
* check may take quite a while (e.g. for a medium located on a
* network share), the calling thread must not be the UI thread. You
* have been warned.
*/
void VBoxMedium::blockAndQueryState()
{
/* save the result to distinguish between inaccessible and e.g.
* uninitialized objects */
{
}
else
refresh();
}
/**
* Refreshes the precomposed strings containing such media parameters as
* location, size by querying the respective data from the associated
* media object.
*
* Note that some string such as #size() are meaningless if the media state is
* KMediaState_NotCreated (i.e. the medium has not yet been checked for
* accessibility).
*/
void VBoxMedium::refresh()
{
{
/// @todo NEWMEDIA use CSystemProperties::GetHardDIskFormats to see if the
/// given hard disk format is a file
/* adjust the parent if necessary (note that mParent must always point
* to an item from VBoxGlobal::currentMediaList()) */
{
/* search for the parent (must be there) */
{
break;
{
/* we unconst here because by the const list we don't mean
* const items */
break;
}
}
}
}
else
{
mIsReadOnly = false;
}
if (mState != KMediaState_Inaccessible &&
{
else
}
else
{
}
/* detect usage */
if (machineIds.size() > 0)
{
{
{
{
/* the medium is attached to the machine in the current
* state, we don't distinguish this for now by always
* giving the VM name in front of snapshot names. */
continue;
}
snapshots += ", ";
}
usage += ", ";
{
mIsUsedInSnapshots = true;
}
else
mIsUsedInSnapshots = false;
}
}
/* compose the tooltip (makes sense to keep the format in sync with
* VBoxMediaManagerDlg::languageChangeImp() and
* VBoxMediaManagerDlg::processCurrentChanged()) */
{
"<br><nobr>Type (Format): %2 (%3)</nobr>",
"hard disk")
.arg (mHardDiskType)
.arg (mHardDiskFormat);
}
"<br><nobr>Attached to: %1</nobr>", "medium")
mUsage);
switch (mState)
{
case KMediaState_NotCreated:
{
"medium");
break;
}
case KMediaState_Inaccessible:
{
{
/* not accessibile */
true /* aToolTip */));
}
else
{
/* accessibility check (eg GetState()) itself failed */
"<hr>Failed to check media accessibility.<br>%1.",
"medium").
}
break;
}
default:
break;
}
/* reset mNoDiffs */
}
/**
* Returns a root medium of this medium. For non-hard disk media, this is always
* this medium itself.
*/
{
return *root;
}
/**
* Returns a tooltip for this medium.
*
* In "don't show diffs" mode (where the attributes of the base hard disk are
* shown instead of the attributes of the differencing hard disk), extra
* information will be added to the tooltip to give the user a hint that the
* medium is actually a differencing hard disk.
*
* @param aNoDiffs @c true to enable user-friendly "don't show diffs" mode.
* @param aCheckRO @c true to perform the #readOnly() check and add a notice
* accordingly.
*/
bool aCheckRO /*= false*/) const
{
if (aCheckRO && mIsReadOnly)
"<hr><img src=%1/> Attaching this hard disk will "
"be performed indirectly using a newly created "
"differencing hard disk.",
"medium").
arg (":/new_16px.png");
return tip;
}
/**
* Returns an icon corresponding to the media state. Distinguishes between
* the Inaccessible state and the situation when querying the state itself
* failed.
*
* In "don't show diffs" mode (where the attributes of the base hard disk are
* shown instead of the attributes of the differencing hard disk), the most
* worst media state on the given hard disk chain will be used to select the
* media icon.
*
* @param aNoDiffs @c true to enable user-friendly "don't show diffs" mode.
* @param aCheckRO @c true to perform the #readOnly() check and change the icon
* accordingly.
*/
bool aCheckRO /*= false*/) const
{
if (aCheckRO && mIsReadOnly)
icon = VBoxGlobal::
return icon;
}
/**
* Returns the details of this medium as a single-line string
*
* For hard disks, the details include the location, type and the logical size
* of the hard disk. Note that if @a aNoDiffs is @c true, these properties are
* queried on the root hard disk of the given hard disk because the primary
* purpose of the returned string is to be human readabile (so that seeing a
* complex diff hard disk name is usually not desirable).
*
* For other media types, the location and the actual size are returned.
* Arguments @a aPredictDiff and @a aNoRoot are ignored in this case.
*
* @param aNoDiffs @c true to enable user-friendly "don't show diffs" mode.
* @param aPredictDiff @c true to mark the hard disk as differencing if
* attaching it would create a differencing hard disk (not
* used when @a aNoRoot is true).
* @param aUseHTML @c true to allow for emphasizing using bold and italics.
*
* @note Use #detailsHTML() instead of passing @c true for @a aUseHTML.
*
* @note The media object may become uninitialized by a third party while this
* method is reading its properties. In this case, the method will return
* an empty string.
*/
bool aPredictDiff /*= false*/,
bool aUseHTML /*= false */) const
{
// @todo *** the below check is rough; if mMedium becomes uninitialized, any
// of getters called afterwards will also fail. The same relates to the
// root hard disk object (that will be the hard disk itself in case of
// non-differencing disks). However, this check was added to fix a
// particular use case: when the hard disk is a differencing hard disk and
// it happens to be discarded (and uninitialized) after this method is
// called but before we read all its properties (yes, it's possible!), the
// root object will be null and calling methods on it will assert in the
// debug builds. This check seems to be enough as a quick solution (fresh
// hard disk attachments will be re-read by a machine state change signal
// after the discard operation is finished, so the user will eventually see
// correct data), but in order to solve the problem properly we need to use
// exceptions everywhere (or check the result after every method call). See
// also Defect #2149.
{
if (aNoDiffs)
{
bool isDiff =
(aPredictDiff && mIsReadOnly);
/* overall (worst) state */
/* we cannot get the logical size if the root is not checked yet */
}
else
{
}
}
// icon when not accessible
switch (state)
{
case KMediaState_NotCreated:
break;
case KMediaState_Inaccessible:
break;
default:
break;
}
QString ("%1 (<nobr>%2</nobr>)").
QString ("%1 (%2)").
return details;
}
/**
* Checks if mNoDiffs is filled in and does it if not.
*
* @param aNoDiffs @if false, this method immediately returns.
*/
{
return;
/* fill mNoDiffs */
/* detect the overall (worst) state of the given hard disk chain */
{
{
"<hr>Some of the media in this hard disk chain are "
"inaccessible. Please use the Virtual Media Manager "
"in <b>Show Differencing Hard Disks</b> mode to inspect "
"these media.");
{
break;
}
/* comtinue looking for another !cur->mResult.isOk() */
}
}
{
"%1"
"<hr>This base hard disk is indirectly attached using the "
"following differencing hard disk:<br>"
"%2%3").
}
}
// VBoxMediaEnumEvent
/////////////////////////////////////////////////////////////////////////////
class VBoxMediaEnumEvent : public QEvent
{
public:
/** Constructs a regular enum event */
{}
/** Constructs the last enum event */
{}
/** Last enumerated medium (not valid when #last is true) */
const VBoxMedium mMedium;
/** Opaque iterator provided by the event sender (guaranteed to be
* the same variable for all media in the single enumeration procedure) */
/** Whether this is the last event for the given enumeration or not */
const bool mLast;
};
#if defined (Q_WS_WIN)
class VBoxShellExecuteEvent : public QEvent
{
public:
/** Constructs a regular enum event */
bool aOk)
{}
bool mOk;
};
#endif
// VirtualBox callback class
/////////////////////////////////////////////////////////////////////////////
class VBoxCallback : public IVirtualBoxCallback
{
public:
, mIsRegDlgOwner (false)
, mIsUpdDlgOwner (false)
#ifdef VBOX_GUI_WITH_SYSTRAY
, mIsTrayIconOwner (false)
#endif
{
#if defined (Q_OS_WIN32)
refcnt = 0;
#endif
}
virtual ~VBoxCallback() {}
#if defined (Q_OS_WIN32)
{
return ::InterlockedIncrement (&refcnt);
}
{
if (cnt == 0)
delete this;
return cnt;
}
{
if (riid == IID_IUnknown) {
*ppObj = this;
AddRef();
return S_OK;
}
if (riid == IID_IVirtualBoxCallback) {
*ppObj = this;
AddRef();
return S_OK;
}
return E_NOINTERFACE;
}
#endif
// IVirtualBoxCallback methods
// Note: we need to post custom events to the GUI event queue
// instead of doing what we need directly from here because on Win32
// these callback methods are never called on the main GUI thread.
// Another reason to handle events asynchronously is that internally
// most callback interface methods are called from under the initiator
// object's lock, so accessing the initiator object (for example, reading
// some property) directly from the callback method will definitely cause
// a deadlock.
{
(KMachineState) state));
return S_OK;
}
{
return S_OK;
}
{
if (!error || !allowChange)
return E_INVALIDARG;
{
/* it's a global extra data key someone wants to change */
{
{
if (mIsRegDlgOwner)
{
*allowChange = TRUE;
else
*allowChange = FALSE;
}
else
*allowChange = TRUE;
return S_OK;
}
{
if (mIsUpdDlgOwner)
{
*allowChange = TRUE;
else
*allowChange = FALSE;
}
else
*allowChange = TRUE;
return S_OK;
}
#ifdef VBOX_GUI_WITH_SYSTRAY
{
if (mIsTrayIconOwner)
{
*allowChange = TRUE;
else
*allowChange = FALSE;
}
else
*allowChange = TRUE;
return S_OK;
}
#endif
/* try to set the global setting to check its syntax */
{
/* this is a known GUI property key */
if (!gs)
{
/* disallow the change when there is an error*/
*allowChange = FALSE;
}
else
*allowChange = TRUE;
return S_OK;
}
}
}
/* not interested in this key -- never disagree */
*allowChange = TRUE;
return S_OK;
}
{
{
{
{
{
mIsRegDlgOwner = false;
}
{
mIsRegDlgOwner = true;
}
else
}
{
{
mIsUpdDlgOwner = false;
}
{
mIsUpdDlgOwner = true;
}
else
}
if (sKey == "GUI/LanguageID")
#ifdef VBOX_GUI_WITH_SYSTRAY
if (sKey == "GUI/MainWindowCount")
{
{
mIsTrayIconOwner = false;
}
{
mIsTrayIconOwner = true;
}
else
}
QApplication::postEvent (&mGlobal, new VBoxChangeTrayIconEvent ((sVal.toLower() == "true") ? true : false));
#endif
#ifdef Q_WS_MAC
{
/* Default to true if it is an empty value */
}
#endif
}
}
return S_OK;
}
{
/** @todo */
return S_OK;
}
{
registered));
return S_OK;
}
{
(KSessionState) state));
return S_OK;
}
{
return S_OK;
}
{
return S_OK;
}
{
return S_OK;
}
IN_BSTR /* key */,
IN_BSTR /* value */,
IN_BSTR /* flags */)
{
return S_OK;
}
private:
{
// currently, we don't post events if we are in the VM execution
// console mode, to save some CPU ticks (so far, there was no need
// to handle VirtualBox callback events in the execution console mode)
if (!mGlobal.isVMConsoleProcess())
}
/** protects #OnExtraDataChange() */
bool mIsRegDlgOwner;
bool mIsUpdDlgOwner;
#ifdef VBOX_GUI_WITH_SYSTRAY
bool mIsTrayIconOwner;
#endif
#if defined (Q_OS_WIN32)
private:
long refcnt;
#endif
};
#if !defined (Q_OS_WIN32)
#endif
// Helpers for VBoxGlobal::getOpenFileName() & getExistingDirectory()
/////////////////////////////////////////////////////////////////////////////
#if defined Q_WS_WIN
extern void qt_enter_modal (QWidget*);
extern void qt_leave_modal (QWidget*);
{
static const char qt_file_dialog_filter_reg_exp[] =
"([a-zA-Z0-9 ]*)\\(([a-zA-Z0-9_.*? +;#\\[\\]]*)\\)$";
if (index >= 0)
}
/**
* Converts QFileDialog filter list to Win32 API filter list.
*/
{
{
if (i == -1)
{
{
sep = "\n";
}
}
}
{
winfilters += *it;
}
return winfilters;
}
/*
* Callback function to control the native Win32 API file dialog
*/
{
{
{
/* locate native dialog controls */
return FALSE;
/* simulate filter change by pressing apply-key */
int size = 256;
/* make request for focus moving to filter selector combo-box */
}
}
return FALSE;
}
/*
* Callback function to control the native Win32 API folders dialog
*/
{
{
{
//SendMessage (hwnd, BFFM_SETEXPANDED, TRUE, Q_ULONG (initDir->utf16()));
}
}
else if (uMsg == BFFM_SELCHANGED)
{
else
}
return 0;
}
/**
* QEvent class to carry Win32 API native dialog's result information
*/
class OpenNativeDialogEvent : public QEvent
{
public:
private:
};
/**
* QObject class reimplementation which is the target for OpenNativeDialogEvent
* event. It receives OpenNativeDialogEvent event from another thread,
* stores result information and exits the given local event loop.
*/
class LoopObject : public QObject
{
public:
private:
{
{
return true;
}
}
};
#endif /* Q_WS_WIN */
// VBoxGlobal
////////////////////////////////////////////////////////////////////////////////
static bool sVBoxGlobalInited = false;
static bool sVBoxGlobalInCleanup = false;
/** @internal
*
* Special routine to do VBoxGlobal cleanup when the application is being
* terminated. It is called before some essential Qt functionality (for
* instance, QThread) becomes unavailable, allowing us to use it from
* VBoxGlobal::cleanup() if necessary.
*/
static void vboxGlobalCleanup()
{
sVBoxGlobalInCleanup = true;
vboxGlobal().cleanup();
}
/** @internal
*
* Determines the rendering mode from the argument. Sets the appropriate
* default rendering mode if the argumen is NULL.
*/
{
#if defined (Q_WS_MAC) && defined (VBOX_GUI_USE_QUARTZ2D)
#elif defined (VBOX_GUI_USE_QIMAGE)
#else
# error "Cannot determine the default render mode!"
#endif
if (aModeStr)
{
if (0) ;
#if defined (VBOX_GUI_USE_QIMAGE)
#endif
#if defined (VBOX_GUI_USE_SDL)
#endif
#if defined (VBOX_GUI_USE_DDRAW)
#endif
#if defined (VBOX_GUI_USE_QUARTZ2D)
#endif
}
return mode;
}
/** @class VBoxGlobal
*
* The VBoxGlobal class incapsulates the global VirtualBox data.
*
* There is only one instance of this class per VirtualBox application,
* the reference to it is returned by the static instance() method, or by
* the global vboxGlobal() function, that is just an inlined shortcut.
*/
: mValid (false)
, mMainWindow (NULL)
#ifdef VBOX_WITH_REGISTRATION
#endif
#ifdef VBOX_GUI_WITH_SYSTRAY
, mIsTrayMenu (false)
, mIncreasedWindowCounter (false)
#endif
, mMediaEnumThread (NULL)
, mVerString ("1.0")
, mDetailReportTemplatesReady (false)
{
}
//
// Public members
/////////////////////////////////////////////////////////////////////////////
/**
* Returns a reference to the global VirtualBox data, managed by this class.
*
* The main() function of the VBox GUI must call this function soon after
* creating a QApplication instance but before opening any of the main windows
* (to let the VBoxGlobal initialization procedure use various Qt facilities),
* and continue execution only when the isValid() method of the returned
* instancereturns true, i.e. do something like:
*
* @code
* if ( !VBoxGlobal::instance().isValid() )
* return 1;
* @endcode
* or
* @code
* if ( !vboxGlobal().isValid() )
* return 1;
* @endcode
*
* @note Some VBoxGlobal methods can be used on a partially constructed
* VBoxGlobal instance, i.e. from constructors and methods called
* from the VBoxGlobal::init() method, which obtain the instance
* using this instance() call or the ::vboxGlobal() function. Currently, such
* methods are:
* #vmStateText, #vmTypeIcon, #vmTypeText, #vmTypeTextList, #vmTypeFromText.
*
* @see ::vboxGlobal
*/
{
static VBoxGlobal vboxGlobal_instance;
if (!sVBoxGlobalInited)
{
/* check that a QApplication instance is created */
if (qApp)
{
sVBoxGlobalInited = true;
/* add our cleanup handler to the list of Qt post routines */
}
else
AssertMsgFailed (("Must construct a QApplication first!"));
}
return vboxGlobal_instance;
}
VBoxGlobal::~VBoxGlobal()
{
}
/**
* Sets the new global settings and saves them to the VirtualBox server.
*/
{
{
return false;
}
/* We don't assign gs to our gset member here, because VBoxCallback
* will update gset as necessary when new settings are successfullly
* sent to the VirtualBox server by gs.save(). */
return true;
}
/**
* Returns a reference to the main VBox VM Selector window.
* The reference is valid until application termination.
*
* There is only one such a window per VirtualBox application.
*/
{
#if defined (VBOX_GUI_SEPARATE_VM_PROCESS)
("Must NOT be a VM console process"));
#endif
if (!mSelectorWnd)
{
/*
* We pass the address of mSelectorWnd to the constructor to let it be
* initialized right after the constructor is called. It is necessary
* to avoid recursion, since this method may be (and will be) called
* from the below constructor or from constructors/methods it calls.
*/
Assert (w == mSelectorWnd);
NOREF(w);
}
return *mSelectorWnd;
}
/**
* Returns a reference to the main VBox VM Console window.
* The reference is valid until application termination.
*
* There is only one such a window per VirtualBox application.
*/
{
#if defined (VBOX_GUI_SEPARATE_VM_PROCESS)
("Must be a VM console process"));
#endif
if (!mConsoleWnd)
{
/*
* We pass the address of mConsoleWnd to the constructor to let it be
* initialized right after the constructor is called. It is necessary
* to avoid recursion, since this method may be (and will be) called
* from the below constructor or from constructors/methods it calls.
*/
Assert (w == mConsoleWnd);
NOREF(w);
}
return *mConsoleWnd;
}
#ifdef VBOX_GUI_WITH_SYSTRAY
/**
* Returns true if the current instance a systray menu only (started with
* "-systray" parameter).
*/
bool VBoxGlobal::isTrayMenu() const
{
return mIsTrayMenu;
}
{
}
/**
* Spawns a new selector window (process).
*/
void VBoxGlobal::trayIconShowSelector()
{
/* Get the path to the executable. */
char path [RTPATH_MAX];
int rc = 0;
# ifdef RT_OS_WINDOWS
# else
# endif
if (RT_FAILURE (rc))
}
/**
* Tries to install the tray icon using the current instance (singleton).
* Returns true if this instance is the tray icon, false if not.
*/
bool VBoxGlobal::trayIconInstall()
{
int rc = 0;
if (false == strTrayWinID.isEmpty())
{
/* Check if current tray icon is alive by writing some bogus value. */
{
/* Current tray icon died - clean up. */
}
}
/* Is there already a tray icon or is tray icon not active? */
if ( (mIsTrayMenu == false)
&& (QSystemTrayIcon::isSystemTrayAvailable())
&& (strTrayWinID.isEmpty()))
{
/* Get the path to the executable. */
char path [RTPATH_MAX];
# ifdef RT_OS_WINDOWS /** @todo drop this once the RTProcCreate bug has been fixed */
# else
# endif
if (RT_FAILURE (rc))
{
return false;
}
}
if (mIsTrayMenu)
{
// Use this selector for displaying the tray icon
/* The first process which can grab this "mutex" will win ->
* It will be the tray icon menu then. */
{
return true;
}
}
return false;
}
#endif
/**
* Returns the list of few guest OS types, queried from
* IVirtualBox corresponding to every family id.
*/
{
for (int i = 0 ; i < mFamilyIDs.size(); ++ i)
return result;
}
/**
* Returns the list of all guest OS types, queried from
* IVirtualBox corresponding to passed family id.
*/
{
AssertMsg (mFamilyIDs.contains (aFamilyId), ("Family ID incorrect: '%s'.", aFamilyId.toLatin1().constData()));
}
/**
* Returns the icon corresponding to the given guest OS type id.
*/
{
return p ? *p : none;
}
/**
* Returns the guest OS type object corresponding to the given type id of list
* containing OS types related to OS family determined by family id attribute.
* If the index is invalid a null object is returned.
*/
{
{
}
else
{
for (int i = 0; i < mFamilyIDs.size(); ++ i)
}
return list [j];
return CGuestOSType();
}
/**
* Returns the description corresponding to the given guest OS type id.
*/
{
for (int i = 0; i < mFamilyIDs.size(); ++ i)
{
return list [j].GetDescription();
}
}
/**
* Returns a string representation of the given channel number on the given
* storage bus. Complementary to #toStorageChannel (KStorageBus, const
* QString &) const.
*/
{
switch (aBus)
{
case KStorageBus_IDE:
{
{
break;
}
}
case KStorageBus_SATA:
{
break;
}
default:
}
return channel;
}
/**
* Returns a channel number on the given storage bus corresponding to the given
* string representation. Complementary to #toString (KStorageBus, LONG) const.
*/
{
switch (aBus)
{
case KStorageBus_IDE:
{
aChannel);
break;
}
case KStorageBus_SATA:
{
/// @todo use regexp to properly extract the %1 text
{
break;
}
break;
}
default:
}
return channel;
}
/**
* Returns a string representation of the given device number of the given
* channel on the given storage bus. Complementary to #toStorageDevice
* (KStorageBus, LONG, const QString &) const.
*/
{
switch (aBus)
{
case KStorageBus_IDE:
{
{
break;
}
}
case KStorageBus_SATA:
{
/* always empty so far for SATA */
device = "";
break;
}
default:
}
return device;
}
/**
* Returns a device number of the given channel on the given storage bus
* corresponding to the given string representation. Complementary to #toString
* (KStorageBus, LONG, LONG) const.
*/
{
switch (aBus)
{
case KStorageBus_IDE:
{
aDevice);
break;
}
case KStorageBus_SATA:
{
/* always zero for SATA so far. */
break;
}
default:
}
return device;
}
/**
* Returns a full string representation of the given device of the given channel
* on the given storage bus. Complementary to #toStorageParams (KStorageBus,
* LONG, LONG) const.
*/
{
switch (aBus)
{
case KStorageBus_IDE:
{
break;
}
case KStorageBus_SATA:
{
/* we only have one SATA device so far which is always zero */
break;
}
default:
}
return device;
}
/**
* Returns the list of all device types (VirtualBox::DeviceType COM enum).
*/
{
static QStringList list;
return list;
}
struct PortConfig
{
const char *name;
};
static const PortConfig kComKnownPorts[] =
{
{ "COM1", 4, 0x3F8 },
{ "COM2", 3, 0x2F8 },
{ "COM3", 4, 0x3E8 },
{ "COM4", 3, 0x2E8 },
/* must not contain an element with IRQ=0 and IOBase=0 used to cause
* toCOMPortName() to return the "User-defined" string for these values. */
};
static const PortConfig kLptKnownPorts[] =
{
{ "LPT1", 7, 0x3BC },
{ "LPT2", 5, 0x378 },
{ "LPT3", 5, 0x278 },
/* must not contain an element with IRQ=0 and IOBase=0 used to cause
* toLPTPortName() to return the "User-defined" string for these values. */
};
/**
* Returns the list of the standard COM port names (i.e. "COMx").
*/
{
return list;
}
/**
* Returns the list of the standard LPT port names (i.e. "LPTx").
*/
{
return list;
}
/**
* Returns the name of the standard COM port corresponding to the given
* parameters, or "User-defined" (which is also returned when both
* @a aIRQ and @a aIOBase are 0).
*/
{
return kComKnownPorts [i].name;
return mUserDefinedPortName;
}
/**
* Returns the name of the standard LPT port corresponding to the given
* parameters, or "User-defined" (which is also returned when both
* @a aIRQ and @a aIOBase are 0).
*/
{
return kLptKnownPorts [i].name;
return mUserDefinedPortName;
}
/**
* Returns port parameters corresponding to the given standard COM name.
* Returns @c true on success, or @c false if the given port name is not one
* of the standard names (i.e. "COMx").
*/
{
{
return true;
}
return false;
}
/**
* Returns port parameters corresponding to the given standard LPT name.
* Returns @c true on success, or @c false if the given port name is not one
* of the standard names (i.e. "LPTx").
*/
{
{
return true;
}
return false;
}
/**
* Searches for the given hard disk in the list of known media descriptors and
* calls VBoxMedium::details() on the found desriptor.
*
* If the requeststed hard disk is not found (for example, it's a new hard disk
* for a new VM created outside our UI), then media enumeration is requested and
* the search is repeated. We assume that the secont attempt always succeeds and
* assert otherwise.
*
* @note Technically, the second attempt may fail if, for example, the new hard
* passed to this method disk gets removed before #startEnumeratingMedia()
* succeeds. This (unexpected object uninitialization) is a generic
* problem though and needs to be addressed using exceptions (see also the
* @todo in VBoxMedium::details()).
*/
bool aPredictDiff)
{
{
/* media may be new and not alredy in the media list, request refresh */
{
/// @todo Still not found. Means that we are trying to get details
/// of a hard disk that was deleted by a third party before we got a
/// chance to complete the task. Returning null in this case should
/// be OK, For more information, see *** in VBoxMedium::etails().
}
}
}
/**
* Returns the details of the given USB device as a single-line string.
*/
{
{
details =
}
else
{
details = p;
else
details = m + " " + p;
}
if (r != 0)
}
/**
* Returns the multi-line description of the given USB device.
*/
{
tr ("<nobr>Vendor ID: %1</nobr><br>"
"<nobr>Product ID: %2</nobr><br>"
"<nobr>Revision: %3</nobr>", "USB device tooltip")
/* add the state field if it's a host USB device */
{
}
return tip;
}
/**
* Returns the multi-line description of the given USB filter
*/
{
if (!manufacturer.isEmpty())
.arg (manufacturer);
/* add the state field if it's a host USB device */
{
}
return tip;
}
/**
* Returns a details report on a given VM represented as a HTML table.
*
* @param aMachine Machine to create a report for.
* @param aIsNewVM @c true when called by the New VM Wizard.
* @param aWithLinks @c true if section titles should be hypertext links.
*/
bool aWithLinks)
{
static const char *sTableTpl =
"<table border=0 cellspacing=1 cellpadding=0>%1</table>";
static const char *sSectionHrefTpl =
"<tr><td width=22 rowspan=%1 align=left><img src='%2'></td>"
"<td colspan=3><b><a href='%3'><nobr>%4</nobr></a></b></td></tr>"
"%5"
"<tr><td colspan=3><font size=1> </font></td></tr>";
static const char *sSectionBoldTpl =
"<tr><td width=22 rowspan=%1 align=left><img src='%2'></td>"
"<td colspan=3><!-- %3 --><b><nobr>%4</nobr></b></td></tr>"
"%5"
"<tr><td colspan=3><font size=1> </font></td></tr>";
static const char *sSectionItemTpl1 =
"<tr><td width=40%><nobr><i>%1</i></nobr></td><td/><td/></tr>";
static const char *sSectionItemTpl2 =
"<tr><td width=40%><nobr>%1:</nobr></td><td/><td>%2</td></tr>";
/* generate templates after every language change */
{
mDetailReportTemplatesReady = true;
"#general", /* link */
generalItems); /* items */
"#general", /* link */
generalItems); /* items */
"#general", /* link */
generalItems); /* items */
"#general", /* link */
generalItems); /* items */
}
/* common generated content */
{
{
/// @todo for the explaination of the below isOk() checks, see ***
/// in VBoxMedium::details().
{
++ rows;
}
}
{
++ rows;
}
"#hdds", /* link */
hardDisks); /* items */
}
/* compose details report */
if (aIsNewVM)
{
+ hardDisks;
}
else
{
/* boot order */
{
if (device == KDeviceType_Null)
continue;
bootOrder += ", ";
}
/* ACPI */
/* IO APIC */
/* Nested Paging */
/* 3D Acceleration */
/* General + Hard Disks */
+ hardDisks;
/* DVD */
{
case KDriveState_NotMounted:
break;
case KDriveState_ImageMounted:
{
break;
}
{
drvName :
fullName);
break;
}
default:
}
"#dvd", /* link */
item); // items
/* Floppy */
{
case KDriveState_NotMounted:
break;
case KDriveState_ImageMounted:
{
break;
}
{
drvName :
fullName);
break;
}
default:
}
"#floppy", /* link */
item); /* items */
/* audio */
{
if (audio.GetEnabled())
else
"#audio", /* link */
item); /* items */
}
/* network */
{
{
if (adapter.GetEnabled())
{
/* don't use the adapter type string for types that have
* this name instead */
else if (type == KNetworkAttachmentType_Internal)
else
++ rows;
}
}
{
++ rows;
}
"#network", /* link */
item); /* items */
}
/* serial ports */
{
{
if (port.GetEnabled())
{
if (mode == KPortMode_HostPipe ||
else
++ rows;
}
}
{
++ rows;
}
"#serialPorts", /* link */
item); /* items */
}
/* parallel ports */
{
{
if (port.GetEnabled())
{
QString (" (<nobr>%1</nobr>)")
++ rows;
}
}
{
++ rows;
}
/* Temporary disabled */
"#parallelPorts", /* link */
item); /* items */
}
/* USB */
{
{
/* the USB controller may be unavailable (i.e. in VirtualBox OSE) */
if (ctl.GetEnabled())
{
active ++;
}
else
"#usb", /* link */
item); /* items */
}
}
/* Shared folders */
{
if (count > 0)
{
}
else
"#sfolders", /* link */
item); /* items */
}
/* VRDP */
{
{
/* the VRDP server may be unavailable (i.e. in VirtualBox OSE) */
if (srv.GetEnabled())
else
"#vrdp", /* link */
item); /* items */
}
}
}
}
{
#if defined (Q_OS_WIN)
platform = "win";
#elif defined (Q_OS_LINUX)
platform = "linux";
platform = "macosx";
platform = "os2";
#elif defined (Q_OS_FREEBSD)
platform = "freebsd";
#elif defined (Q_OS_SOLARIS)
platform = "solaris";
#else
platform = "unknown";
#endif
/* The format is <system>.<bitness> */
/* Add more system information */
#if defined (Q_OS_WIN)
if (major == 6)
else if (major == 5)
{
if (minor == 2)
else if (minor == 1)
else if (minor == 0)
else
}
else if (major == 4)
{
if (minor == 90)
else if (minor == 10)
else if (minor == 0)
else
}
else /** @todo Windows Server 2008 == vista? Probably not... */
#elif defined (Q_OS_LINUX)
/* Get script path */
char szAppPrivPath [RTPATH_MAX];
/* Run script */
#else
/* Use RTSystemQueryOSInfo. */
char szTmp[256];
if (!components.isEmpty())
#endif
return platform;
}
double VBoxGlobal::findLicenseFile (const QStringList &aFilesList, QRegExp aPattern, QString &aLicenseFile) const
{
double maxVersionNumber = 0;
aLicenseFile = "";
{
{
}
}
return maxVersionNumber;
}
bool VBoxGlobal::showVirtualBoxLicense()
{
/* get the apps doc path */
int size = 256;
/* Make sure that the language is in two letter code.
* Note: if languageId() returns an empty string lang.name() will
* return "C" which is an valid language code. */
/* First try to find a localized version of the license file. */
double versionNumber = findLicenseFile (filesList, QRegExp (QString ("License-([\\d\\.]+)-%1.html").arg (lang.name())), licenseFile);
/* If there wasn't a localized version of the currently selected language,
* search for the generic one. */
if (versionNumber == 0)
/* Check the version again. */
if (!versionNumber)
{
return false;
}
/* compose the latest license file full path */
/* check for the agreed license version */
if (licenseAgreed == latestVersion)
return true;
if (result)
return result;
}
#endif /* defined(Q_WS_X11) && !defined(VBOX_OSE) */
/**
* Checks if any of the settings files were auto-converted and informs the user
* if so. Returns @c false if the user select to exit the application.
*
* @param aAfterRefresh @c true to suppress the first simple dialog aExit
* button. Used when calling after the VM refresh.
*/
{
bool isGlobalConverted = false;
{
if (!m->GetAccessible())
continue;
version = m->GetSettingsFileVersion();
if (version != formatVersion)
{
"</td><td><nobr><i>%2</i></nobr></td></tr>")
.arg (m->GetSettingsFilePath())
}
}
if (!aAfterRefresh)
{
if (version != formatVersion)
{
isGlobalConverted = true;
"</td><td><nobr><i>%2</i></nobr></td></tr>")
}
}
{
int rc = vboxProblem()
return false;
/* backup (optionally) and save all settings files
* (QIMessageBox::No = Backup, QIMessageBox::Yes = Save) */
{
{
else
sm.SaveSettings();
}
}
if (isGlobalConverted)
{
else
}
}
return true;
}
/**
* Opens a direct session for a machine with the given ID.
* This method does user-friendly error handling (display error messages, etc.).
* and returns a null CSession object in case of any error.
* If this method succeeds, don't forget to close the returned session when
* it is no more necessary.
*
* @param aId Machine ID.
* @param aExisting @c true to open an existing session with the machine
* which is already running, @c false to open a new direct
* session.
*/
{
{
return session;
}
if (aExisting)
else
{
/* Make sure that the language is in two letter code.
* Note: if languageId() returns an empty string lang.name() will
* return "C" which is an valid language code. */
}
{
}
return session;
}
/**
* Starts a machine with the given ID.
*/
{
AssertReturn (mValid, false);
return false;
}
/**
* Appends the given list of hard disks and all their children to the media
* list. To be called only from VBoxGlobal::startEnumeratingMedia().
*/
static
VBoxMedium *aParent = 0)
{
/* First pass: Add siblings sorted */
{
/* Search for a proper alphabetic position */
break;
/* Adjust the first item if inserted before it */
-- first;
}
/* Second pass: Add children */
{
++ it; /* go to the next sibling before inserting children */
}
}
/**
* Starts a thread that asynchronously enumerates all currently registered
* media.
*
* Before the enumeration is started, the current media list (a list returned by
* #currentMediaList()) is populated with all registered media and the
* #mediumEnumStarted() signal is emitted. The enumeration thread then walks this
* list, checks for media acessiblity and emits #mediumEnumerated() signals of
* each checked medium. When all media are checked, the enumeration thread is
* stopped and the #mediumEnumFinished() signal is emitted.
*
* If the enumeration is already in progress, no new thread is started.
*
* The media list returned by #currentMediaList() is always sorted
* alphabetically by the location attribute and comes in the following order:
* <ol>
* <li>All hard disks. If a hard disk has children, these children
* (alphabetically sorted) immediately follow their parent and terefore
* appear before its next sibling hard disk.</li>
* <li>All Floppy images.</li>
* </ol>
*
* Note that #mediumEnumerated() signals are emitted in the same order as
* described above.
*
* @sa #currentMediaList()
* @sa #isMediaEnumerationStarted()
*/
void VBoxGlobal::startEnumeratingMedia()
{
/* check if already started but not yet finished */
if (mMediaEnumThread != NULL)
return;
/* ignore the request during application termination */
if (sVBoxGlobalInCleanup)
return;
/* composes a list of all currently known media & their children */
mMediaList.clear();
{
}
{
{
/* Search for a proper alphabetic position */
break;
/* Adjust the first item if inserted before it */
-- first;
}
}
{
{
/* Search for a proper alphabetic position */
break;
/* Adjust the first item if inserted before it */
-- first;
}
}
/* enumeration thread class */
class MediaEnumThread : public QThread
{
public:
{
int i = 0;
}
virtual void run()
{
LogFlow (("MediaEnumThread started.\n"));
COMBase::InitializeCOM();
/* Enumerate the list */
{
mVector [i].blockAndQueryState();
}
/* Post the end-of-enumeration event */
if (!sVBoxGlobalInCleanup)
COMBase::CleanupCOM();
LogFlow (("MediaEnumThread finished.\n"));
}
private:
};
/* emit mediumEnumStarted() after we set mMediaEnumThread to != NULL
* to cause isMediaEnumerationStarted() to return TRUE from slots */
}
/**
* Adds a new medium to the current media list and emits the #mediumAdded()
* signal.
*
* @sa #currentMediaList()
*/
{
/* Note that we maitain the same order here as #startEnumeratingMedia() */
{
{
break;
{
}
else
{
/* break if met a parent's sibling (will insert before it) */
break;
/* compare to aMedium's siblings */
break;
}
}
}
else
{
{
/* skip HardDisks that come first */
continue;
/* skip DVD when inserting Floppy */
continue;
break;
}
}
}
/**
* Updates the medium in the current media list and emits the #mediumUpdated()
* signal.
*
* @sa #currentMediaList()
*/
{
break;
}
/**
* Removes the medium from the current media list and emits the #mediumRemoved()
* signal.
*
* @sa #currentMediaList()
*/
{
break;
#if DEBUG
/* sanity: must be no children */
{
++ jt;
}
#endif
/* remove the medium from the list to keep it in sync with the server "for
* free" when the medium is deleted from one of our UIs */
/* also emit the parent update signal because some attributes like
* isReadOnly() may have been changed after child removal */
{
}
}
/**
* Searches for a VBoxMedum object representing the given COM medium object.
*
* @return true if found and false otherwise.
*/
{
{
{
return true;
}
}
return false;
}
#ifdef VBOX_GUI_WITH_SYSTRAY
/**
*
* @return Number of running main windows.
*/
int VBoxGlobal::mainWindowCount ()
{
}
#endif
/**
* Native language name of the currently installed translation.
* Returns "English" if no translation is installed
* or if the translation file is invalid.
*/
{
"Native language name");
}
/**
* Native language country name of the currently installed translation.
* Returns "--" if no translation is installed or if the translation file is
* invalid, or if the language is independent on the country.
*/
{
"Native language country name "
"(empty if this language is for all countries)");
}
/**
* Language name of the currently installed translation, in English.
* Returns "English" if no translation is installed
* or if the translation file is invalid.
*/
{
"Language name, in English");
}
/**
* Language country name of the currently installed translation, in English.
* Returns "--" if no translation is installed or if the translation file is
* invalid, or if the language is independent on the country.
*/
{
"Language country name, in English "
"(empty if native country name is empty)");
}
/**
* Comma-separated list of authors of the currently installed translation.
* Returns "Sun Microsystems, Inc." if no translation is installed or if the
* translation file is invalid, or if the translation is supplied by Sun
* Microsystems, inc.
*/
{
"Comma-separated list of translators");
}
/**
* Changes the language of all global string constants according to the
* currently installed translations tables.
*/
void VBoxGlobal::retranslateUi()
{
mDetailReportTemplatesReady = false;
/* refresh media properties since they contain some translations too */
/* As PM and X11 do not (to my knowledge) have functionality for providing
* human readable key names, we keep a table of them, which must be
* updated when the language is changed. */
#endif
}
// public static stuff
////////////////////////////////////////////////////////////////////////////////
/* static */
{
return true;
return false;
}
/**
* Sets the QLabel background and frame colors according tho the pixmap
* contents. The bottom right pixel of the label pixmap defines the
* background color of the label, the top right pixel defines the color of
* the one-pixel frame around it. This function also sets the alignment of
* the pixmap to AlignVTop (to correspond to the color choosing logic).
*
* This method is useful to provide nice scaling of pixmal labels without
* scaling pixmaps themselves. To see th eeffect, the size policy of the
* label in the corresponding direction (vertical, for now) should be set to
* something like MinimumExpanding.
*
* @todo Parametrize corners to select pixels from and set the alignment
* accordingly.
*/
/* static */
{
}
extern const char *gVBoxLangSubDir = "/nls";
extern const char *gVBoxLangFileBase = "VirtualBox_";
extern const char *gVBoxLangFileExt = ".qm";
extern const char *gVBoxLangIDRegExp = "(([a-z]{2})(?:_([A-Z]{2}))?)|(C)";
extern const char *gVBoxBuiltInLangName = "C";
class VBoxTranslator : public QTranslator
{
public:
: QTranslator (aParent) {}
{
return false;
}
private:
};
static VBoxTranslator *sTranslator = 0;
/**
* Returns the loaded (active) language ID.
* Note that it may not match with VBoxGlobalSettings::languageId() if the
* specified language cannot be loaded.
* If the built-in language is active, this method returns "C".
*
* @note "C" is treated as the built-in language for simplicity -- the C
* locale is used in unix environments as a fallback when the requested
* locale is invalid. This way we don't need to process both the "built_in"
* language and the "C" language (which is a valid environment setting)
* separately.
*/
/* static */
{
return sLoadedLangId;
}
/**
* Loads the language by language ID.
*
* @param aLangId Language ID in in form of xx_YY. QString::null means the
* system default language.
*/
/* static */
{
char szNlsPath[RTPATH_MAX];
int rc;
{
/* the language ID should match the regexp completely */
AssertReturnVoid (pos == 0);
{
}
{
}
else
{
/* Never complain when the default language is requested. In any
* case, if no explicit language file exists, we will simply
* fall-back to English (built-in). */
/* selectedLangId remains built-in here */
}
}
/* delete the old translator if there is one */
if (sTranslator)
{
/* QTranslator destructor will call qApp->removeTranslator() for
* us. It will also delete all its child translations we attach to it
* below, so we don't have to care about them specially. */
delete sTranslator;
}
/* load new language files */
bool loadOk = true;
if (sTranslator)
{
if (selectedLangId != gVBoxBuiltInLangName)
{
}
/* we install the translator in any case: on failure, this will
* activate an empty translator that will give us English
* (built-in) */
}
else
loadOk = false;
if (loadOk)
else
{
}
/* Try to load the corresponding Qt translation */
if (sLoadedLangId != gVBoxBuiltInLangName)
{
#ifdef Q_OS_UNIX
/* We use system installations of Qt on Linux systems, so first, try
* to load the Qt translation from the system location. */
/* Note that the Qt translation supplied by Sun is always loaded
* afterwards to make sure it will take precedence over the system
* translation (it may contain more decent variants of translation
* that better correspond to VirtualBox UI). We need to load both
* because a newer version of Qt may be installed on the user computer
* and the Sun version may not fully support it. We don't do it on
* Win32 because we supply a Qt library there and therefore the
* Sun translation is always the best one. */
#endif
/* The below message doesn't fit 100% (because it's an additonal
* language and the main one won't be reset to built-in on failure)
* but the load failure is so rare here that it's not worth a separate
* message (but still, having something is better than having none) */
}
}
{
#if defined (Q_WS_WIN32) || defined (Q_WS_X11)
#endif
/* Where are the docs located? */
char szDocsPath[RTPATH_MAX];
/* Make sure that the language is in two letter code.
* Note: if languageId() returns an empty string lang.name() will
* return "C" which is an valid language code. */
/* Construct the path and the filename */
/* Check if a help file with that name exists */
return manual;
/* Fall back to the standard */
return manual;
}
/* static */
const char *aDisabled /* = NULL */,
const char *aActive /* = NULL */)
{
return iconSet;
}
/* static */
const char *aDisabled /* = NULL */,
const char *aDisabledOff /* = NULL */,
const char *aActive /* = NULL */,
const char *aActiveOff /* = NULL */)
{
if (aNormalOff != NULL)
if (aDisabledOff != NULL)
if (aActiveOff != NULL)
return iconSet;
}
/* static */
const char *aNormal, const char *aSmallNormal,
const char *aDisabled /* = NULL */,
const char *aSmallDisabled /* = NULL */,
const char *aActive /* = NULL */,
const char *aSmallActive /* = NULL */)
{
if (aSmallDisabled != NULL)
{
}
if (aSmallActive != NULL)
{
}
return iconSet;
}
{
#ifdef Q_WS_MAC
/* At least in Qt 4.3.4/4.4 RC1 SP_MessageBoxWarning is the application
* icon. So change this to the critical icon. (Maybe this would be
* fixed in a later Qt version) */
#endif /* Q_WS_MAC */
}
/**
* Replacement for QToolButton::setTextLabel() that handles the shortcut
* letter (if it is present in the argument string) as if it were a setText()
* call: the shortcut letter is used to automatically assign an "Alt+<letter>"
* accelerator key sequence to the given tool button.
*
* @note This method preserves the icon set if it was assigned before. Only
* the text label and the accelerator are changed.
*
* @param aToolButton Tool button to set the text label on.
* @param aTextLabel Text label to set.
*/
/* static */
const QString &aTextLabel)
{
/* remember the icon set as setText() will kill it */
/* re-use the setText() method to detect and set the accelerator */
/* set the accel last as setIconSet() would kill it */
}
/**
* Performs direct and flipped search of position for \a aRectangle to make sure
* it is fully contained inside \a aBoundRegion region by moving & resizing
* \a aRectangle if necessary. Selects the minimum shifted result between direct
* and flipped variants.
*/
/* static */
bool aCanResize /* = true */)
{
/* Direct search for normalized rectangle */
/* Flipped search for normalized rectangle */
/* Calculate shift from starting position for both variants */
/* Return minimum shifted variant */
}
/**
* Ensures that the given rectangle \a aRectangle is fully contained within the
* region \a aBoundRegion by moving \a aRectangle if necessary. If \a aRectangle is
* larger than \a aBoundRegion, top left corner of \a aRectangle is aligned with the
* top left corner of maximum available rectangle and, if \a aCanResize is true,
* \a aRectangle is shrinked to become fully visible.
*/
/* static */
bool aCanResize /* = true */)
{
/* Storing available horizontal sub-rectangles & vertical shifts */
{
int itemPosition = 0;
{
}
int shift2TopPos = 0;
int shift2BotPos = 0;
}
/* Trying to find the appropriate place for window */
{
/* Move to appropriate vertical */
/* Search horizontal shift */
int maxShift = 0;
{
continue;
{
}
{
}
}
/* Shift across the horizontal direction */
/* Check the translated rectangle to feat the rules */
}
{
/* Resize window to feat desirable size
* using max of available rectangles */
{
{
maxRectangle = item;
}
}
result = aRectangle;
}
return result;
}
/**
* Returns the flipped (transposed) region.
*/
/* static */
{
return result;
}
/**
* Aligns the center of \a aWidget with the center of \a aRelative.
*
* If necessary, \a aWidget's position is adjusted to make it fully visible
* within the available desktop area. If \a aWidget is bigger then this area,
* it will also be resized unless \a aCanResize is false or there is an
* inappropriate minimum size limit (in which case the top left corner will be
* simply aligned with the top left corner of the available desktop area).
*
* \a aWidget must be a top-level widget. \a aRelative may be any widget, but
* if it's not top-level itself, its top-level widget will be used for
* calculations. \a aRelative can also be NULL, in which case \a aWidget will
* be centered relative to the available desktop area.
*/
/* static */
bool aCanResize /* = true */)
{
if (w)
{
w = w->window();
parentGeo = w->frameGeometry();
/* On X11/Gnome, geo/frameGeo.x() and y() are always 0 for top level
* widgets with parents, what a shame. Use mapToGlobal() to workaround. */
parentGeo.moveTopLeft (d);
}
else
{
}
/* On X11, there is no way to determine frame geometry (including WM
* decorations) before the widget is shown for the first time. Stupidly
* enumerate other top level widgets to find the thickest frame. The code
* is based on the idea taken from QDialog::adjustPositionInternal(). */
{
continue;
}
/// @todo (r=dmik) not sure if we really need this
#if 0
/* sanity check for decoration frames. With embedding, we
* might get extraordinary values */
{
extrah = 50;
extraw = 20;
}
#endif
/* On non-X11 platforms, the following would be enough instead of the
* above workaround: */
// QRect geo = frameGeometry();
/* ensure the widget is within the available desktop area */
if (aCanResize &&
}
/**
* Returns the decimal separator for the current locale.
*/
/* static */
{
}
/**
* Returns the regexp string that defines the format of the human-readable
* size representation, <tt>####[.##] B|KB|MB|GB|TB|PB</tt>.
*
* This regexp will capture 5 groups of text:
* - cap(1): integer number in case when no decimal point is present
* (if empty, it means that decimal point is present)
* - cap(2): size suffix in case when no decimal point is present (may be empty)
* - cap(3): integer number in case when decimal point is present (may be empty)
* - cap(4): fraction number (hundredth) in case when decimal point is present
* - cap(5): size suffix in case when decimal point is present (note that
* B cannot appear there)
*/
/* static */
{
QString ("^(?:(?:(\\d+)(?:\\s?([KMGTP]?B))?)|(?:(\\d*)%1(\\d{1,2})(?:\\s?([KMGTP]B))))$")
.arg (decimalSep());
return regexp;
}
/**
* Parses the given size string that should be in form of
* <tt>####[.##] B|KB|MB|GB|TB|PB</tt> and returns the size value
* in bytes. Zero is returned on error.
*/
/* static */
{
if (pos != -1)
{
{
}
denom = 1;
else if (suff == "KB")
else if (suff == "MB")
else if (suff == "GB")
else if (suff == "TB")
else if (suff == "PB")
if (denom == 1)
return intg;
return intg;
}
else
return 0;
}
/**
* Formats the given @a aSize value in bytes to a human readable string
* in form of <tt>####[.##] B|KB|MB|GB|TB|PB</tt>.
*
* The @a aMode and @a aDecimal parameters are used for rounding the resulting
* number when converting the size value to KB, MB, etc gives a fractional part:
* <ul>
* <li>When \a aMode is FormatSize_Round, the result is rounded to the
* closest number containing \a aDecimal decimal digits.
* </li>
* <li>When \a aMode is FormatSize_RoundDown, the result is rounded to the
* largest number with \a aDecimal decimal digits that is not greater than
* the result. This guarantees that converting the resulting string back to
* the integer value in bytes will not produce a value greater that the
* initial size parameter.
* </li>
* <li>When \a aMode is FormatSize_RoundUp, the result is rounded to the
* smallest number with \a aDecimal decimal digits that is not less than the
* result. This guarantees that converting the resulting string back to the
* integer value in bytes will not produce a value less that the initial
* size parameter.
* </li>
* </ul>
*
* @param aSize Size value in bytes.
* @param aMode Conversion mode.
* @param aDecimal Number of decimal digits in result.
* @return Human-readable size string.
*/
/* static */
{
int suffix = 0;
{
denom = 1;
suffix = 0;
}
{
suffix = 1;
}
{
suffix = 2;
}
{
suffix = 3;
}
{
suffix = 4;
}
else
{
suffix = 5;
}
if (denom > 1)
{
if (decm)
{
/* not greater */
/* not less */
/* nearest */
}
/* check for the fractional part overflow due to rounding */
{
decm = 0;
++ intg;
/* check if we've got 1024 XB after rounding and scale down if so */
{
intg /= 1024;
++ suffix;
}
}
}
else
{
}
}
/**
* Returns the required video memory in bytes for the current desktop
* resolution at maximum possible screen depth in bpp.
*/
/* static */
{
/* Calculate summary required memory amount in bits */
32 /* we will take the maximum possible bpp for now */ +
8 * 4096 /* adapter info */;
/* Translate value into megabytes with rounding to highest side */
return needMBytes * _1M;
}
/**
* Puts soft hyphens after every path component in the given file name.
*
* @param aFileName File name (must be a full path name).
*/
/* static */
{
/// @todo (dmik) remove?
// QString result = QDir::toNativeSeparators (fn);
//#ifdef Q_OS_LINUX
// result.replace ('/', "/<font color=red>­</font>");
//#else
// result.replace ('\\', "\\<font color=red>­</font>");
//#endif
// return result;
}
/**
* Reformats the input string @a aStr so that:
* - strings in single quotes will be put inside <nobr> and marked
* with blue color;
* - UUIDs be put inside <nobr> and marked
* with green color;
* - replaces new line chars with </p><p> constructs to form paragraphs
* (note that <p> and </p> are not appended to the beginnign and to the
* end of the string respectively, to allow the result be appended
* or prepended to the existing paragraph).
*
* If @a aToolTip is true, colouring is not applied, only the <nobr> tag
* is added. Also, new line chars are replaced with <br> instead of <p>.
*/
/* static */
{
if (!aToolTip)
{
strFont = "<font color=#0000CC>";
uuidFont = "<font color=#008000>";
endFont = "</font>";
}
/* replace special entities, '&' -- first! */
/* mark strings in single quotes with color */
rx.setMinimal (true);
QString ("\\1%1<nobr>'\\2'</nobr>%2")
/* mark UUIDs with color */
"((?:^|\\s)[(]?)"
"(\\{[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}\\})"
"(?=[:.-!);]?(?:\\s|$))"),
QString ("\\1%1<nobr>\\2</nobr>%2")
/* split to paragraphs at \n chars */
if (!aToolTip)
else
return text;
}
/**
* This does exactly the same as QLocale::system().name() but corrects its
* wrong behavior on Linux systems (LC_NUMERIC for some strange reason takes
* precedence over any other locale setting in the QLocale::system()
* implementation). This implementation first looks at LC_ALL (as defined by
* SUS), then looks at LC_MESSAGES which is designed to define a language for
* program messages in case if it differs from the language for other locale
* categories. Then it looks for LANG and finally falls back to
* QLocale::system().name().
*
* The order of precedence is well defined here:
*
* @note This method will return "C" when the requested locale is invalid or
* when the "C" locale is set explicitly.
*/
/* static */
{
#if defined (Q_WS_MAC)
/* QLocale return the right id only if the user select the format of the
* language also. So we use our own implementation */
return ::darwinSystemLanguage();
const char *s = RTEnvGet ("LC_ALL");
if (s == 0)
s = RTEnvGet ("LC_MESSAGES");
if (s == 0)
s = RTEnvGet ("LANG");
if (s != 0)
#endif
}
/**
* Reimplementation of QFileDialog::getExistingDirectory() that removes some
* oddities and limitations.
*
* On Win32, this function makes sure a native dialog is launched in
* another thread to avoid dialog visualization errors occuring due to
* multi-threaded COM apartment initialization on the main UI thread while
* the appropriate native dialog function expects a single-threaded one.
*
* On all other platforms, this function is equivalent to
* QFileDialog::getExistingDirectory().
*/
bool aDirOnly,
bool aResolveSymlinks)
{
#if defined Q_WS_WIN
/**
* QEvent class reimplementation to carry Win32 API native dialog's
* result folder information
*/
class GetExistDirectoryEvent : public OpenNativeDialogEvent
{
public:
};
/**
* QThread class reimplementation to open Win32 API native folder's dialog
*/
{
public:
virtual void run()
{
path [0] = 0;
initPath [0] = 0;
/* Qt is uncapable to properly handle modal state if the modal
* window is not a QWidget. For example, if we have the W1->W2->N
* ownership where Wx are QWidgets (W2 is modal), and N is a
* native modal window, cliking on the title bar of W1 will still
* to prevent it is to disable the entire widget... */
if (mParent)
mParent->setEnabled (false);
if (itemIdList)
{
else
{
}
}
else
/* Enable the parent widget again. */
if (mParent)
mParent->setEnabled (true);
}
private:
};
/* Local event loop to run while waiting for the result from another
* thread */
return loopObject.result();
/* Here is workaround for Qt4.3 bug with QFileDialog which crushes when
* gets initial path as hidden directory if no hidden files are shown.
* for details */
if (hidden)
{
hidden->setVisible (false);
}
#else
QFileDialog::Options o;
if (aDirOnly)
o = QFileDialog::ShowDirsOnly;
if (!aResolveSymlinks)
o |= QFileDialog::DontResolveSymlinks;
#endif
}
/**
* Reimplementation of QFileDialog::getOpenFileName() that removes some
* oddities and limitations.
*
* On Win32, this function makes sure a file filter is applied automatically
* right after it is selected from the drop-down list, to conform to common
* experience in other applications. Note that currently, @a selectedFilter
* is always set to null on return.
*
* On all other platforms, this function is equivalent to
* QFileDialog::getOpenFileName().
*/
/* static */
bool aResolveSymlinks /* = true */)
{
return getOpenFileNames (aStartWith,
}
/**
* Reimplementation of QFileDialog::getOpenFileNames() that removes some
* oddities and limitations.
*
* On Win32, this function makes sure a file filter is applied automatically
* right after it is selected from the drop-down list, to conform to common
* experience in other applications. Note that currently, @a selectedFilter
* is always set to null on return.
* @todo: implement the multiple file selection on win
* @todo: is this extra handling on win still necessary with Qt4?
*
* On all other platforms, this function is equivalent to
* QFileDialog::getOpenFileNames().
*/
/* static */
bool aResolveSymlinks /* = true */,
bool aSingleFile /* = false */)
{
#if defined Q_WS_WIN
/**
* QEvent class reimplementation to carry Win32 API native dialog's
* result folder information
*/
class GetOpenFileNameEvent : public OpenNativeDialogEvent
{
public:
};
/**
* QThread class reimplementation to open Win32 API native file dialog
*/
{
public:
virtual void run()
{
else
{
}
workDir += "\\";
else
buf [0] = 0;
if (GetOpenFileName (&ofn))
{
}
// qt_win_eatMouseMove();
}
private:
};
if (aSelectedFilter)
/* Local event loop to run while waiting for the result from another
* thread */
//#warning check me!
if (aParent)
//#warning check me!
if (aParent)
/* Here is workaround for Qt4.3 bug with QFileDialog which crushes when
* gets initial path as hidden directory if no hidden files are shown.
* for details */
if (aSingleFile)
else
if (aSelectedFilter)
if (hidden)
{
hidden->setVisible (false);
}
#else
QFileDialog::Options o;
if (!aResolveSymlinks)
o |= QFileDialog::DontResolveSymlinks;
if (aSingleFile)
aFilters, aSelectedFilter, o);
else
aFilters, aSelectedFilter, o);
#endif
}
/**
* Search for the first directory that exists starting from the passed one
* and going up through its parents. In case if none of the directories
* exist (except the root one), the function returns QString::null.
*/
/* static */
{
{
}
return result;
}
#if defined (Q_WS_X11)
{
True /* only_if_exists */);
if (propNameAtom == None)
return NULL;
int actFmt = 0;
unsigned long nItems = 0;
unsigned long nBytesAfter = 0;
return NULL;
return reinterpret_cast <char *> (propVal);
}
unsigned long aData4 = 0)
{
return False;
/* always send as 32 bit for now */
SubstructureRedirectMask, &ev) != 0;
}
#endif
/**
* Activates the specified window. If necessary, the window will be
* de-iconified activation.
*
* @note On X11, it is implied that @a aWid represents a window of the same
* display the application was started on.
*
* @param aWId Window ID to activate.
* @param aSwitchDesktop @c true to switch to the window's desktop before
* activation.
*
* @return @c true on success and @c false otherwise.
*/
/* static */
{
bool result = true;
#if defined (Q_WS_WIN32)
else if (!IsWindowVisible (aWId))
if (aSwitchDesktop)
{
/* try to find the desktop ID using the NetWM property */
"_NET_WM_DESKTOP");
/* if the NetWM propery is not supported try to find the desktop
* ID using the GNOME WM property */
"_WIN_WORKSPACE");
{
"_NET_CURRENT_DESKTOP",
*desktop);
if (!ok)
{
LogWarningFunc (("Couldn't switch to desktop=%08X\n",
desktop));
result = false;
}
}
else
{
LogWarningFunc (("Couldn't find a desktop ID for aWId=%08X\n",
aWId));
result = false;
}
}
#else
AssertFailed();
result = false;
#endif
if (!result)
return result;
}
/**
* Removes the acceletartor mark (the ampersand symbol) from the given string
* and returns the result. The string is supposed to be a menu item's text
* that may (or may not) contain the accelerator mark.
*
* In order to support accelerators used in non-alphabet languages
* (e.g. Japanese) that has a form of "(&<L>)" (where <L> is a latin letter),
* this method first searches for this pattern and, if found, removes it as a
* whole. If such a pattern is not found, then the '&' character is simply
* removed from the string.
*
* @note This function removes only the first occurense of the accelerator
* mark.
*
* @param aText Menu item's text to remove the acceletaror mark from.
*
* @return The resulting string.
*/
/* static */
{
if (pos >= 0)
else
{
if (pos >= 0)
}
return result;
}
/* static */
{
#ifdef Q_WS_MAC
#else
#endif
}
/* static */
{
#ifdef Q_WS_MAC
#else
#endif
return key;
}
/**
* Joins two pixmaps horizontally with 2px space between them and returns the
* result.
*
* @param aPM1 Left pixmap.
* @param aPM2 Right pixmap.
*/
/* static */
{
return aPM2;
return aPM1;
return result;
}
/**
* Searches for a widget that with @a aName (if it is not NULL) which inherits
* @a aClassName (if it is not NULL) and among children of @a aParent. If @a
* aParent is NULL, all top-level widgets are searched. If @a aRecursive is
* true, child widgets are recursively searched as well.
*/
/* static */
const char *aClassName /* = NULL */,
bool aRecursive /* = false */)
{
{
{
break;
if (aRecursive)
{
if (w)
break;
}
}
return w;
}
/* Find the first children of aParent with the appropriate properties.
* Please note that this call is recursivly. */
{
break;
}
return child;
}
/**
* Figures out which hard disk formats are currently supported by VirtualBox.
* Returned is a list of pairs with the form
* <tt>{"Backend Name", "*.suffix1 .suffix2 ..."}</tt>.
*/
/* static */
{
for (int i = 0; i < hardDiskFormats.size(); ++ i)
{
/* File extensions */
QStringList f;
for (int a = 0; a < fileExtensions.size(); ++ a)
/* Create a pair out of the backend description and all suffix's. */
if (!f.isEmpty())
}
return backendPropList;
}
// Public slots
////////////////////////////////////////////////////////////////////////////////
/**
*
* @param aURL URL to open
*
* @return true on success and false otherwise
*/
{
#if defined (Q_WS_WIN)
/* We cannot use ShellExecute() on the main UI thread because we've
* initialized COM with CoInitializeEx(COINIT_MULTITHREADED). See
* for more details. */
{
public:
void run()
{
(mObject,
}
};
/* thread will be deleted in the VBoxShellExecuteEvent handler */
return true;
static const char * const commands[] =
{ "kfmclient:exec", "gnome-open", "x-www-browser", "firefox", "konqueror" };
{
return true;
}
/* The code below is taken from Psi 0.10 sources
* (http://www.psi-im.org) */
/* Use Internet Config to hand the URL to the appropriate application, as
* set by the user in the Internet Preferences pane.
* NOTE: ICStart could be called once at Psi startup, saving the
* ICInstance in a global variable, as a minor optimization.
* ICStop should then be called at Psi shutdown if ICStart
* succeeded. */
{
long start (0);
/* Don't bother testing return value (error); launched application
* will report problems. */
ICStop (icInstance);
return true;
}
#else
tr ("Opening URLs is not implemented yet."));
return false;
#endif
/* if we go here it means we couldn't open the URL */
return false;
}
/**
* Shows the VirtualBox registration dialog.
*
* @note that this method is not part of VBoxProblemReporter (like e.g.
* VBoxProblemReporter::showHelpAboutDialog()) because it is tied to
* VBoxCallback::OnExtraDataChange() handling performed by VBoxGlobal.
*
* @param aForce
*/
{
#ifdef VBOX_WITH_REGISTRATION
return;
if (mRegDlg)
{
/* Show the already opened registration dialog */
}
else
{
/* Store the ID of the main window to ensure that only one
* registration dialog is shown at a time. Due to manipulations with
* OnExtraDataCanChange() and OnExtraDataChange() signals, this extra
* data item acts like an inter-process mutex, so the first process
* that attempts to set it will win, the rest will get a failure from
* the SetExtraData() call. */
{
/* We've got the "mutex", create a new registration dialog */
}
}
#endif
}
/**
* Shows the VirtualBox version check & update dialog.
*
* @note that this method is not part of VBoxProblemReporter (like e.g.
* VBoxProblemReporter::showHelpAboutDialog()) because it is tied to
* VBoxCallback::OnExtraDataChange() handling performed by VBoxGlobal.
*
* @param aForce
*/
{
if (!aForce && !isNecessary)
return;
if (mUpdDlg)
{
{
}
}
else
{
/* Store the ID of the main window to ensure that only one
* update dialog is shown at a time. Due to manipulations with
* OnExtraDataCanChange() and OnExtraDataChange() signals, this extra
* data item acts like an inter-process mutex, so the first process
* that attempts to set it will win, the rest will get a failure from
* the SetExtraData() call. */
{
/* We've got the "mutex", create a new update dialog */
/* Update dialog always in background mode for now.
* if (!aForce && isAutomatic) */
/* else mUpdDlg->show(); */
}
}
}
// Protected members
////////////////////////////////////////////////////////////////////////////////
{
switch (e->type())
{
#if defined (Q_WS_WIN)
case VBoxDefs::ShellExecuteEventType:
{
/* wait for the thread and free resources */
return true;
}
#endif
case VBoxDefs::AsyncEventType:
{
return true;
}
case VBoxDefs::MediaEnumEventType:
{
{
}
else
{
/* the thread has posted the last message, wait for termination */
mMediaEnumThread->wait();
delete mMediaEnumThread;
mMediaEnumThread = 0;
}
return true;
}
/* VirtualBox callback events */
{
return true;
}
{
return true;
}
{
return true;
}
{
return true;
}
case VBoxDefs::SnapshotEventType:
{
return true;
}
case VBoxDefs::CanShowRegDlgEventType:
{
return true;
}
case VBoxDefs::CanShowUpdDlgEventType:
{
return true;
}
{
return true;
}
#ifdef VBOX_GUI_WITH_SYSTRAY
return true;
case VBoxDefs::CanShowTrayIconEventType:
{
return true;
}
case VBoxDefs::ShowTrayIconEventType:
{
return true;
}
case VBoxDefs::TrayIconChangeEventType:
{
return true;
}
#endif
#if defined(Q_WS_MAC)
{
return true;
}
#endif
default:
break;
}
}
{
aObject->isWidgetType() &&
{
/* Catch the language change event before any other widget gets it in
* order to invalidate cached string resources (like the details view
* templates) that may be used by other widgets. */
{
/* call this only once per every language change (see
* QApplication::installTranslator() for details) */
}
}
}
// Private members
////////////////////////////////////////////////////////////////////////////////
void VBoxGlobal::init()
{
#ifdef DEBUG
mVerString += " [DEBUG]";
#endif
#ifdef Q_WS_WIN
/* COM for the main thread is initialized in main() */
#else
{
return;
}
#endif
{
return;
}
/* create default non-null global settings */
gset = VBoxGlobalSettings (false);
/* try to load global settings */
{
return;
}
/* Load the customized language as early as possible to get possible error
* messages translated */
if (!languageId.isNull())
/* Note: the settings conversion check must be done before anything else
* that may unconditionally overwrite settings files in the new format (like
* SetExtraData()). But after loading the proper the language. */
if (!checkForAutoConvertedSettings())
return;
#ifdef VBOX_GUI_WITH_SYSTRAY
{
("Something went wrong with the window reference count!"));
}
#endif
/* Initialize guest OS Type list */
if (osTypeCount > 0)
{
/* Here we assume 'Other' type is always the first, so we
* remember it and will append it to the list when finish */
/* Fill the lists with all the available OS Types except
* the 'Other' one type, it will be appended. */
{
{
mFamilyIDs << familyId;
}
}
/* Append the 'Other' OS Type to the end of list */
{
}
}
/* Fill in OS type icon dictionary */
static const char *kOSTypeIcons [][2] =
{
{"Other", ":/os_other.png"},
{"DOS", ":/os_dos.png"},
{"Netware", ":/os_netware.png"},
{"L4", ":/os_l4.png"},
{"Windows31", ":/os_win31.png"},
{"Windows95", ":/os_win95.png"},
{"Windows98", ":/os_win98.png"},
{"WindowsMe", ":/os_winme.png"},
{"WindowsNT4", ":/os_winnt4.png"},
{"Windows2000", ":/os_win2k.png"},
{"WindowsXP", ":/os_winxp.png"},
{"WindowsXP_64", ":/os_winxp_64.png"},
{"Windows2003", ":/os_win2k3.png"},
{"Windows2003_64", ":/os_win2k3_64.png"},
{"WindowsVista", ":/os_winvista.png"},
{"WindowsVista_64", ":/os_winvista_64.png"},
{"Windows2008", ":/os_win2k8.png"},
{"Windows2008_64", ":/os_win2k8_64.png"},
{"Windows7", ":/os_win7.png"},
{"Windows7_64", ":/os_win7_64.png"},
{"WindowsNT", ":/os_win_other.png"},
{"OS2Warp3", ":/os_os2warp3.png"},
{"OS2Warp4", ":/os_os2warp4.png"},
{"OS2Warp45", ":/os_os2warp45.png"},
{"OS2eCS", ":/os_os2ecs.png"},
{"OS2", ":/os_os2_other.png"},
{"Linux22", ":/os_linux22.png"},
{"Linux24", ":/os_linux24.png"},
{"Linux24_64", ":/os_linux24_64.png"},
{"Linux26", ":/os_linux26.png"},
{"Linux26_64", ":/os_linux26_64.png"},
{"ArchLinux", ":/os_archlinux.png"},
{"ArchLinux_64", ":/os_archlinux_64.png"},
{"Debian", ":/os_debian.png"},
{"Debian_64", ":/os_debian_64.png"},
{"OpenSUSE", ":/os_opensuse.png"},
{"OpenSUSE_64", ":/os_opensuse_64.png"},
{"Fedora", ":/os_fedora.png"},
{"Fedora_64", ":/os_fedora_64.png"},
{"Gentoo", ":/os_gentoo.png"},
{"Gentoo_64", ":/os_gentoo_64.png"},
{"Mandriva", ":/os_mandriva.png"},
{"Mandriva_64", ":/os_mandriva_64.png"},
{"RedHat", ":/os_redhat.png"},
{"RedHat_64", ":/os_redhat_64.png"},
{"Ubuntu", ":/os_ubuntu.png"},
{"Ubuntu_64", ":/os_ubuntu_64.png"},
{"Xandros", ":/os_xandros.png"},
{"Xandros_64", ":/os_xandros_64.png"},
{"Linux", ":/os_linux_other.png"},
{"FreeBSD", ":/os_freebsd.png"},
{"FreeBSD_64", ":/os_freebsd_64.png"},
{"OpenBSD", ":/os_openbsd.png"},
{"OpenBSD_64", ":/os_openbsd_64.png"},
{"NetBSD", ":/os_netbsd.png"},
{"NetBSD_64", ":/os_netbsd_64.png"},
{"Solaris", ":/os_solaris.png"},
{"Solaris_64", ":/os_solaris_64.png"},
{"OpenSolaris", ":/os_opensolaris.png"},
{"OpenSolaris_64", ":/os_opensolaris_64.png"},
{"QNX", ":/os_qnx.png"},
};
{
}
/* fill in VM state icon map */
static const struct
{
const char *name;
}
kVMStateIcons[] =
{
{KMachineState_PoweredOff, ":/state_powered_off_16px.png"},
{KMachineState_Saved, ":/state_saved_16px.png"},
{KMachineState_Aborted, ":/state_aborted_16px.png"},
{KMachineState_Running, ":/state_running_16px.png"},
{KMachineState_Paused, ":/state_paused_16px.png"},
{KMachineState_Stuck, ":/state_stuck_16px.png"},
{KMachineState_Saving, ":/state_saving_16px.png"},
{KMachineState_Restoring, ":/state_restoring_16px.png"},
{KMachineState_Discarding, ":/state_discarding_16px.png"},
{KMachineState_SettingUp, ":/settings_16px.png"},
};
{
}
/* initialize state colors map */
qApp->installEventFilter (this);
/* process command line */
vm_render_mode_str = 0;
#ifdef VBOX_WITH_DEBUGGER_GUI
# ifdef VBOX_WITH_DEBUGGER_GUI_MENU
mDbgEnabled = true;
# else
# endif
#endif
int i = 1;
while (i < argc)
{
{
if (++i < argc)
{
{
}
else
{
if (m.isNull())
{
return;
}
}
}
}
#ifdef VBOX_GUI_WITH_SYSTRAY
{
mIsTrayMenu = true;
}
#endif
{
++i;
}
{
if (++i < argc)
}
#ifdef VBOX_WITH_DEBUGGER_GUI
{
mDbgEnabled = true;
}
{
mDbgEnabled = true;
mDbgAutoShow = true;
}
{
mDbgEnabled = false;
mDbgAutoShow = false;
}
#endif
/** @todo add an else { msgbox(syntax error); exit(1); } here, pretty please... */
i++;
}
/* setup the callback */
return;
#ifdef VBOX_WITH_DEBUGGER_GUI
/* setup the debugger gui. */
if (RTEnvExist("VBOX_GUI_NO_DEBUGGER"))
mDbgEnabled = mDbgAutoShow = false;
if (mDbgEnabled)
{
if (RT_FAILURE(rc))
{
mDbgAutoShow = false;
}
}
#endif
mValid = true;
}
/** @internal
*
* This method should be never called directly. It is called automatically
* when the application terminates.
*/
void VBoxGlobal::cleanup()
{
/* sanity check */
if (!sVBoxGlobalInCleanup)
{
AssertMsgFailed (("Should never be called directly\n"));
return;
}
#ifdef VBOX_GUI_WITH_SYSTRAY
{
("Something went wrong with the window reference count!"));
if (c < 0)
c = 0; /* Clean up the mess. */
if (c == 0)
{
}
}
#endif
{
}
if (mMediaEnumThread)
{
/* sVBoxGlobalInCleanup is true here, so just wait for the thread */
mMediaEnumThread->wait();
delete mMediaEnumThread;
mMediaEnumThread = 0;
}
#ifdef VBOX_WITH_REGISTRATION
if (mRegDlg)
#endif
if (mConsoleWnd)
delete mConsoleWnd;
if (mSelectorWnd)
delete mSelectorWnd;
/* ensure CGuestOSType objects are no longer used */
mFamilyIDs.clear();
/* media list contains a lot of CUUnknown, release them */
mMediaList.clear();
/* the last step to ensure we don't use COM any more */
/* There may be VBoxMediaEnumEvent instances still in the message
* queue which reference COM objects. Remove them to release those objects
* before uninitializing the COM subsystem. */
QApplication::removePostedEvents (this);
#ifdef Q_WS_WIN
/* COM for the main thread is shutdown in main() */
#else
COMBase::CleanupCOM();
#endif
mValid = false;
}
/** @fn vboxGlobal
*
* Shortcut to the static VBoxGlobal::instance() method, for convenience.
*/
/**
* USB Popup Menu class methods
* This class provides the list of USB devices attached to the host.
*/
{
this, SLOT (processAboutToShow()));
// connect (this, SIGNAL (hovered (QAction *)),
// this, SLOT (processHighlighted (QAction *)));
}
{
return mUSBDevicesMap [aAction];
}
{
}
void VBoxUSBMenu::processAboutToShow()
{
clear();
if (isUSBEmpty)
{
action->setEnabled (false);
"USB device tooltip"));
}
else
{
{
action->setCheckable (true);
/* check if created item was alread attached to this session */
{
}
}
}
}
{
/* We provide dynamic tooltips for the usb devices */
{
if (action)
{
{
return true;
}
}
}
}
/**
*/
bool aInverted)
{
/* this menu works only with toggle action */
this, SLOT (processAboutToShow()));
}
{
}
void VBoxSwitchMenu::processAboutToShow()
{
}