VBoxGlobal.h revision 9a2923915af7ea9a11f9a50dca2ebe24daf18173
/** @file
*
* VBox frontends: Qt GUI ("VirtualBox"):
* VBoxGlobal class declaration
*/
/*
* Copyright (C) 2006-2007 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.
*/
#ifndef __VBoxGlobal_h__
#define __VBoxGlobal_h__
#include "COMDefs.h"
#include "VBoxGlobalSettings.h"
/* Qt includes */
#include <QApplication>
#include <QLayout>
#include <QHash>
#include <QPixmap>
#include <QMenu>
#include <QStyle>
#include <QProcess>
#include <QLinkedList>
// Auxiliary types
////////////////////////////////////////////////////////////////////////////////
/**
* Media descriptor for the GUI.
*
* Maintains the results of the last state (accessibility) check and precomposes
* string parameters such as location, size which can be used in various GUI
* controls.
*
* Many getter methods take the boolean @a aNoDiffs argument. Unless explicitly
* stated otherwise, this argument, when set to @c true, will cause the
* corresponding property of this object's root medium to be returned instead of
* its own one. This is useful when hard disk media is represented in the
* user-friendly "don't show diffs" mode. For non-hard disk media, the value of
* this argument is irrelevant because the root object for such medium is
* the medium itself.
*
* Note that this class "abuses" the KMediaState_NotCreated state value to
* indicate that the accessibility check of the given medium (see
* #blockAndQueryState()) has not been done yet and therefore some parameters
* such as #size() are meaningless because they can be read only from the
* accessible medium. The real KMediaState_NotCreated state is not necessary
* because this class is only used with created (existing) media.
*/
{
/**
* Creates a null medium descriptor which is not associated with any medium.
* The state field is set to KMediaState_NotCreated.
*/
, mIsReadOnly (false), mIsUsedInSnapshots (false)
/**
* Creates a media descriptor associated with the given medium.
*
* The state field remain KMediaState_NotCreated until #blockAndQueryState()
* is called. All precomposed strings are filled up by implicitly calling
* #refresh(), see the #refresh() details for more info.
*
* One of the hardDisk, dvdImage, or floppyImage members is assigned from
* aMedium according to aType. @a aParent must be always NULL for non-hard
* disk media.
*/
, mIsReadOnly (false), mIsUsedInSnapshots (false)
/**
* Similar to the other non-null constructor but sets the media state to
* @a aState. Suitable when the media state is known such as right after
* creation.
*/
, mIsReadOnly (false), mIsUsedInSnapshots (false)
void blockAndQueryState();
void refresh();
/**
* Media state. In "don't show diffs" mode, this is the worst state (in
* terms of inaccessibility) detected on the given hard disk chain.
*
* @param aNoDiffs @c true to enable user-friendly "don't show diffs" mode.
*/
{
}
/**
* Result of the last blockAndQueryState() call. Will indicate an error and
* contain a proper error info if the last state check fails. In "don't show
* diffs" mode, this is the worst result (in terms of inaccessibility)
* detected on the given hard disk chain.
*
* @param aNoDiffs @c true to enable user-friendly "don't show diffs" mode.
*/
{
}
/**
* Returns @c true if this medium is read-only (either because it is
* Immutable or because it has child hard disks). Read-only media can only
* be attached indirectly.
*/
bool isReadOnly() const { return mIsReadOnly; }
/**
* Returns @c true if this medium is attached to any VM (in the current
* state or in a snapshot) in which case #usage() will contain a string with
* comma-sparated VM names (with snapshot names, if any, in parenthesis).
*/
/**
* Returns @c true if this medium is attached to any VM in any snapshot.
* which case #usage() will contain a string with comma-sparated VM names.
*/
bool isUsedInSnapshots() const { return mIsUsedInSnapshots; }
/**
* Returns @c true if this medium is attached to the given machine in the
* current state.
*/
/**
* Returns a vector of IDs of all machines this medium is attached
* to in their current state (i.e. excluding snapshots).
*/
{ return mCurStateMachineIds; }
/**
* Returns a parent medium. For non-hard disk media, this is always NULL.
*/
VBoxMedium &root() const;
/** Shortcut to <tt>#toolTip (aNoDiffs, true)</tt>. */
/** Shortcut to <tt>#icon (aNoDiffs, true)</tt>. */
bool aUseHTML = false) const;
/** Shortcut to <tt>#details (aNoDiffs, aPredictDiff, true)</tt>. */
/** Returns @c true if this media descriptor is a null object. */
void init();
void checkNoDiffs (bool aNoDiffs);
bool mIsReadOnly : 1;
bool mIsUsedInSnapshots : 1;
/**
* Used to override some attributes in the user-friendly "don't show diffs"
* mode.
*/
struct NoDiffs
{
bool isSet : 1;
}
};
// VirtualBox callback events
////////////////////////////////////////////////////////////////////////////////
{
{}
const KMachineState state;
};
{
{}
};
{
{}
const bool registered;
};
{
{}
const KSessionState state;
};
{
{}
const QUuid snapshotId;
};
{
VBoxCanShowRegDlgEvent (bool aCanShow)
{}
const bool mCanShow;
};
{
VBoxCanShowUpdDlgEvent (bool aCanShow)
{}
const bool mCanShow;
};
{
{}
};
{
int aTimeout = 5000
/* wait for data maximum 5 seconds */)
{
/* Why is it really needed is because of Qt4.3 bug with QProcess.
* This bug is about QProcess sometimes (~70%) do not receive
* notification about process was finished, so this makes
* 'bool QProcess::waitForFinished (int)' block the GUI thread and
* never dismissed with 'true' result even if process was really
* started&finished. So we just waiting for some information
* on process output and destroy the process with force. Due to
* QProcess::~QProcess() has the same 'waitForFinished (int)' blocker
* we have to change process state to QProcess::NotRunning. */
if (firstShotReady)
return result;
}
};
// VBoxGlobal class
////////////////////////////////////////////////////////////////////////////////
{
static VBoxGlobal &instance();
/* main window handle storage */
const char *vmRenderModeStr() const { return vm_render_mode_str; }
#ifdef VBOX_WITH_DEBUGGER_GUI
bool isDebuggerEnabled() const { return mDbgEnabled; }
bool isDebuggerAutoShowEnabled() const { return mDbgAutoShow; }
#else
bool isDebuggerAutoShowEnabled() const { return false; }
#endif
{
}
{
}
{
return machineStates.value (s);
}
{
return sessionStates.value (s);
}
/**
* Returns a string representation of the given KStorageBus enum value.
* Complementary to #toStorageBusType (const QString &) const.
*/
{
return storageBuses [aBus];
}
/**
* Returns a KStorageBus enum value corresponding to the given string
* representation. Complementary to #toString (KStorageBus) const.
*/
{
}
{
}
/**
* Similar to toString (KHardDiskType), but returns 'Differencing' for
* normal hard disks that have a parent.
*/
{
{
return diskTypes_Differencing;
}
}
{
return vrdpAuthTypes.value (t);
}
{
return portModeTypes.value (t);
}
{
return usbFilterActionTypes.value (t);
}
{
return clipboardTypes.value (t);
}
{
}
{
return ideControllerTypes.value (t);
}
{
}
{
}
{
}
{
}
{
return deviceTypes.value (t);
}
{
}
QStringList deviceTypeStrings() const;
{
return audioDriverTypes.value (t);
}
{
}
{
return audioControllerTypes.value (t);
}
{
}
{
return networkAdapterTypes.value (t);
}
{
}
{
return networkAttachmentTypes.value (t);
}
{
}
{
}
QStringList COMPortNames() const;
QStringList LPTPortNames() const;
{
}
/* details generators */
bool aWithLinks);
/* VirtualBox helpers */
double findLicenseFile (const QStringList &aFilesList, QRegExp aPattern, QString &aLicenseFile) const;
bool showVirtualBoxLicense();
#endif
bool checkForAutoConvertedSettings();
/** Shortcut to openSession (aId, true). */
void startEnumeratingMedia();
/**
* Returns a list of all currently registered media. This list is used to
* globally track the accessiblity state of all media on a dedicated thread.
*
* Note that the media list is initially empty (i.e. before the enumeration
* process is started for the first time using #startEnumeratingMedia()).
* See #startEnumeratingMedia() for more information about how meida are
* sorted in the returned list.
*/
/** Returns true if the media enumeration is in progress. */
void addMedium (const VBoxMedium &);
void updateMedium (const VBoxMedium &);
/** Compact version of #findMediumTo(). Asserts if not found. */
{
AssertFailed();
return medium;
}
/* various helpers */
QString languageName() const;
QString languageCountry() const;
QString languageNameEnglish() const;
QString languageCountryEnglish() const;
QString languageTranslators() const;
void retranslateUi();
/** @internal made public for internal purposes */
void cleanup();
/* public static stuff */
static void adoptLabelPixmap (QLabel *);
static QString languageId();
const char *aNormal, const char *aSmallNormal,
const char *aSmallDisabled = NULL,
const char *aSmallActive = NULL);
bool aCanResize = true);
bool aCanResize = true);
static QChar decimalSep();
static QString sizeRegexp();
static QString systemLanguageId();
bool resolveSymlinks = TRUE);
static QString getOpenFileName (const QString &aStartWith, const QString &aFilters, QWidget *aParent,
bool aResolveSymLinks = true);
static QStringList getOpenFileNames (const QString &aStartWith, const QString &aFilters, QWidget *aParent,
bool aResolveSymLinks = true,
bool aSingleFile = false);
const char *aClassName = NULL,
bool aRecursive = false);
/* Qt 4.2.0 support function */
{
#if QT_VERSION < 0x040300
/* Deprecated since > 4.2 */
#else
/* New since > 4.2 */
#endif
}
/**
* Emitted at the beginning of the enumeration process started by
* #startEnumeratingMedia().
*/
void mediumEnumStarted();
/**
* Emitted when a new medium item from the list has updated its
* accessibility state.
*/
/**
* Emitted at the end of the enumeration process started by
* #startEnumeratingMedia(). The @a aList argument is passed for
* convenience, it is exactly the same as returned by #currentMediaList().
*/
/** Emitted when a new media is added using #addMedia(). */
void mediumAdded (const VBoxMedium &);
/** Emitted when the media is updated using #updateMedia(). */
void mediumUpdated (const VBoxMedium &);
/** Emitted when the media is removed using #removeMedia(). */
/* signals emitted when the VirtualBox callback is called by the server
* (not that currently these signals are emitted only when the application
* is the in the VM selector mode) */
void machineStateChanged (const VBoxMachineStateChangeEvent &e);
void machineDataChanged (const VBoxMachineDataChangeEvent &e);
void machineRegistered (const VBoxMachineRegisteredEvent &e);
void sessionStateChanged (const VBoxSessionStateChangeEvent &e);
void snapshotChanged (const VBoxSnapshotEvent &e);
void canShowRegDlg (bool aCanShow);
void canShowUpdDlg (bool aCanShow);
void showRegistrationDialog (bool aForce = true);
void showUpdateDialog (bool aForce = true);
VBoxGlobal();
~VBoxGlobal();
void init();
bool mValid;
#ifdef VBOX_WITH_REGISTRATION
#endif
const char * vm_render_mode_str;
#ifdef VBOX_WITH_DEBUGGER_GUI
/** Whether the debugger should be accessible or not.
* Use --dbg, the env.var. VBOX_GUI_DBG_ENABLED, --debug or the env.var.
* VBOX_GUI_DBG_AUTO_SHOW to enable. */
bool mDbgEnabled;
/** Whether to show the debugger automatically with the console.
* Use --debug or the env.var. VBOX_GUI_DBG_AUTO_SHOW to enable. */
bool mDbgAutoShow;
/** VBoxDbg module handle. */
#endif
#if defined (Q_WS_WIN32)
#endif
};
// Helper classes
////////////////////////////////////////////////////////////////////////////////
/**
* Generic asyncronous event.
*
* This abstract class is intended to provide a conveinent way to execute
* code on the main GUI thread asynchronously to the calling party. This is
* done by putting necessary actions to the #handle() function in a subclass
* and then posting an instance of the subclass using #post(). The instance
* must be allocated on the heap using the <tt>new</tt> operation and will be
* automatically deleted after processing. Note that if you don't call #post()
* on the created instance, you have to delete it yourself.
*/
{
/**
* Worker function. Gets executed on the GUI thread when the posted event
* is processed by the main event loop.
*/
/**
* Posts this event to the main event loop.
* The caller loses ownership of this object after this method returns
* and must not delete the object.
*/
void post()
{
}
};
/**
* USB Popup Menu class.
* This class provides the list of USB devices attached to the host.
*/
{
VBoxUSBMenu (QWidget *);
void setConsole (const CConsole &);
void processAboutToShow();
};
/**
*/
{
void setToolTip (const QString &);
void processAboutToShow();
bool mInverted;
};
#endif /* __VBoxGlobal_h__ */