d34409ad02ea0d28e08a6c4b089a412fdb3b4c9cvboxsync * VBox Qt GUI - UINetworkManagerIndicator stuff implementation.
430474e5ec398f769830a548d818d75ff37d5113vboxsync * Copyright (C) 2012 Oracle Corporation
430474e5ec398f769830a548d818d75ff37d5113vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
430474e5ec398f769830a548d818d75ff37d5113vboxsync * available from http://www.virtualbox.org. This file is free software;
430474e5ec398f769830a548d818d75ff37d5113vboxsync * you can redistribute it and/or modify it under the terms of the GNU
430474e5ec398f769830a548d818d75ff37d5113vboxsync * General Public License (GPL) as published by the Free Software
430474e5ec398f769830a548d818d75ff37d5113vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
430474e5ec398f769830a548d818d75ff37d5113vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
430474e5ec398f769830a548d818d75ff37d5113vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
a9b62afc62b28da7a1a77f34259f8013892d9664vboxsync#else /* !VBOX_WITH_PRECOMPILED_HEADERS */
430474e5ec398f769830a548d818d75ff37d5113vboxsync/* Local includes: */
a9b62afc62b28da7a1a77f34259f8013892d9664vboxsync#endif /* !VBOX_WITH_PRECOMPILED_HEADERS */
430474e5ec398f769830a548d818d75ff37d5113vboxsyncUINetworkManagerIndicator::UINetworkManagerIndicator()
430474e5ec398f769830a548d818d75ff37d5113vboxsync /* Assign state icons: */
430474e5ec398f769830a548d818d75ff37d5113vboxsync setStateIcon(UINetworkManagerIndicatorState_Idle, QPixmap(":/nw_16px.png"));
430474e5ec398f769830a548d818d75ff37d5113vboxsync setStateIcon(UINetworkManagerIndicatorState_Loading, QPixmap(":/nw_loading_16px.png"));
430474e5ec398f769830a548d818d75ff37d5113vboxsync setStateIcon(UINetworkManagerIndicatorState_Error, QPixmap(":/nw_error_16px.png"));
430474e5ec398f769830a548d818d75ff37d5113vboxsync /* Translate content: */
430474e5ec398f769830a548d818d75ff37d5113vboxsyncvoid UINetworkManagerIndicator::addNetworkRequest(UINetworkRequest *pNetworkRequest)
430474e5ec398f769830a548d818d75ff37d5113vboxsync /* Make sure network-request is really exists: */
430474e5ec398f769830a548d818d75ff37d5113vboxsync AssertMsg(pNetworkRequest, ("Invalid network-request passed!"));
430474e5ec398f769830a548d818d75ff37d5113vboxsync /* Make sure network-request was NOT registered yet: */
430474e5ec398f769830a548d818d75ff37d5113vboxsync AssertMsg(!m_ids.contains(pNetworkRequest->uuid()), ("Network-request already registered!"));
430474e5ec398f769830a548d818d75ff37d5113vboxsync /* Append network-request data: */
430474e5ec398f769830a548d818d75ff37d5113vboxsync m_data.append(UINetworkRequestData(pNetworkRequest->description(), 0, 0));
430474e5ec398f769830a548d818d75ff37d5113vboxsync /* Prepare network-request listeners: */
430474e5ec398f769830a548d818d75ff37d5113vboxsync connect(pNetworkRequest, SIGNAL(sigStarted(const QUuid &)),
430474e5ec398f769830a548d818d75ff37d5113vboxsync this, SLOT(sltSetProgressToStarted(const QUuid &)));
430474e5ec398f769830a548d818d75ff37d5113vboxsync connect(pNetworkRequest, SIGNAL(sigCanceled(const QUuid &)),
430474e5ec398f769830a548d818d75ff37d5113vboxsync this, SLOT(sltSetProgressToCanceled(const QUuid &)));
430474e5ec398f769830a548d818d75ff37d5113vboxsync connect(pNetworkRequest, SIGNAL(sigFinished(const QUuid &)),
430474e5ec398f769830a548d818d75ff37d5113vboxsync this, SLOT(sltSetProgressToFinished(const QUuid &)));
430474e5ec398f769830a548d818d75ff37d5113vboxsync connect(pNetworkRequest, SIGNAL(sigFailed(const QUuid &, const QString &)),
430474e5ec398f769830a548d818d75ff37d5113vboxsync this, SLOT(sltSetProgressToFailed(const QUuid &, const QString &)));
430474e5ec398f769830a548d818d75ff37d5113vboxsync connect(pNetworkRequest, SIGNAL(sigProgress(const QUuid &, qint64, qint64)),
430474e5ec398f769830a548d818d75ff37d5113vboxsync this, SLOT(sltSetProgress(const QUuid &, qint64, qint64)));
430474e5ec398f769830a548d818d75ff37d5113vboxsync /* Update appearance: */
430474e5ec398f769830a548d818d75ff37d5113vboxsyncvoid UINetworkManagerIndicator::removeNetworkRequest(const QUuid &uuid)
430474e5ec398f769830a548d818d75ff37d5113vboxsync /* Make sure network-request still registered: */
430474e5ec398f769830a548d818d75ff37d5113vboxsync AssertMsg(m_ids.contains(uuid), ("Network-request already unregistered!"));
430474e5ec398f769830a548d818d75ff37d5113vboxsync /* Search for network-request index: */
430474e5ec398f769830a548d818d75ff37d5113vboxsync /* Delete corresponding network-request: */
430474e5ec398f769830a548d818d75ff37d5113vboxsync /* Update appearance: */
430474e5ec398f769830a548d818d75ff37d5113vboxsyncvoid UINetworkManagerIndicator::sltSetProgressToStarted(const QUuid &uuid)
430474e5ec398f769830a548d818d75ff37d5113vboxsync /* Make sure that network-request still registered: */
430474e5ec398f769830a548d818d75ff37d5113vboxsync AssertMsg(m_ids.contains(uuid), ("That network-request already unregistered!"));
430474e5ec398f769830a548d818d75ff37d5113vboxsync /* Search for network-request index: */
430474e5ec398f769830a548d818d75ff37d5113vboxsync /* Update corresponding network-request data: */
430474e5ec398f769830a548d818d75ff37d5113vboxsync UINetworkRequestData &data = m_data[iIndexOfNetworkRequest];
430474e5ec398f769830a548d818d75ff37d5113vboxsync /* Update appearance: */
430474e5ec398f769830a548d818d75ff37d5113vboxsyncvoid UINetworkManagerIndicator::sltSetProgressToCanceled(const QUuid &uuid)
430474e5ec398f769830a548d818d75ff37d5113vboxsync /* Make sure that network-request still registered: */
430474e5ec398f769830a548d818d75ff37d5113vboxsync AssertMsg(m_ids.contains(uuid), ("That network-request already unregistered!"));
430474e5ec398f769830a548d818d75ff37d5113vboxsync /* Update appearance: */
430474e5ec398f769830a548d818d75ff37d5113vboxsyncvoid UINetworkManagerIndicator::sltSetProgressToFailed(const QUuid &uuid, const QString &)
430474e5ec398f769830a548d818d75ff37d5113vboxsync /* Make sure that network-request still registered: */
430474e5ec398f769830a548d818d75ff37d5113vboxsync AssertMsg(m_ids.contains(uuid), ("That network-request already unregistered!"));
430474e5ec398f769830a548d818d75ff37d5113vboxsync /* Search for network-request index: */
430474e5ec398f769830a548d818d75ff37d5113vboxsync /* Update corresponding data: */
430474e5ec398f769830a548d818d75ff37d5113vboxsync UINetworkRequestData &data = m_data[iIndexOfNetworkRequest];
430474e5ec398f769830a548d818d75ff37d5113vboxsync /* Update appearance: */
430474e5ec398f769830a548d818d75ff37d5113vboxsyncvoid UINetworkManagerIndicator::sltSetProgressToFinished(const QUuid &uuid)
430474e5ec398f769830a548d818d75ff37d5113vboxsync /* Make sure that network-request still registered: */
430474e5ec398f769830a548d818d75ff37d5113vboxsync AssertMsg(m_ids.contains(uuid), ("That network-request already unregistered!"));
430474e5ec398f769830a548d818d75ff37d5113vboxsync /* Update appearance: */
430474e5ec398f769830a548d818d75ff37d5113vboxsyncvoid UINetworkManagerIndicator::sltSetProgress(const QUuid &uuid, qint64 iReceived, qint64 iTotal)
430474e5ec398f769830a548d818d75ff37d5113vboxsync /* Make sure that network-request still registered: */
430474e5ec398f769830a548d818d75ff37d5113vboxsync AssertMsg(m_ids.contains(uuid), ("That network-request already unregistered!"));
430474e5ec398f769830a548d818d75ff37d5113vboxsync /* Search for network-request index: */
430474e5ec398f769830a548d818d75ff37d5113vboxsync /* Update corresponding network-request data: */
430474e5ec398f769830a548d818d75ff37d5113vboxsync UINetworkRequestData &data = m_data[iIndexOfNetworkRequest];
430474e5ec398f769830a548d818d75ff37d5113vboxsync /* Update appearance: */
430474e5ec398f769830a548d818d75ff37d5113vboxsync /* Update appearance: */
430474e5ec398f769830a548d818d75ff37d5113vboxsyncvoid UINetworkManagerIndicator::recalculateIndicatorState()
430474e5ec398f769830a548d818d75ff37d5113vboxsync /* Check if there are network-requests at all: */
430474e5ec398f769830a548d818d75ff37d5113vboxsync /* Set state to 'idle': */
430474e5ec398f769830a548d818d75ff37d5113vboxsync /* Check if there is at least one failed network-request: */
430474e5ec398f769830a548d818d75ff37d5113vboxsync bool fIsThereAtLeastOneFailedNetworkRequest = false;
430474e5ec398f769830a548d818d75ff37d5113vboxsync /* If there it least one failed network-request: */
430474e5ec398f769830a548d818d75ff37d5113vboxsync /* Set state to 'error': */
430474e5ec398f769830a548d818d75ff37d5113vboxsync /* Set state to 'loading': */
430474e5ec398f769830a548d818d75ff37d5113vboxsync /* Update appearance finally: */
430474e5ec398f769830a548d818d75ff37d5113vboxsync /* First of all, we are hiding LED in case of 'idle' state: */
430474e5ec398f769830a548d818d75ff37d5113vboxsync if (state() == UINetworkManagerIndicatorState_Idle && !isHidden())
430474e5ec398f769830a548d818d75ff37d5113vboxsync /* Prepare description: */
430474e5ec398f769830a548d818d75ff37d5113vboxsync /* Check if there are any network-requests: */
430474e5ec398f769830a548d818d75ff37d5113vboxsync /* Prepare table: */
430474e5ec398f769830a548d818d75ff37d5113vboxsync QString strBodyItem("<tr><td>%1</td><td> </td><td>%2</td></tr>");
430474e5ec398f769830a548d818d75ff37d5113vboxsync /* Prepare header: */
430474e5ec398f769830a548d818d75ff37d5113vboxsync QString strHeader(strBoldNobreak.arg(tr("Current network operations:")));
430474e5ec398f769830a548d818d75ff37d5113vboxsync /* Prepare table body: */
430474e5ec398f769830a548d818d75ff37d5113vboxsync QString strStatus(data.failed ? tr("failed", "network operation") :
430474e5ec398f769830a548d818d75ff37d5113vboxsync QString strBodyLine(strBodyItem.arg(strNobreak.arg(strDescription)).arg(strNobreak.arg(strStatus)));
430474e5ec398f769830a548d818d75ff37d5113vboxsync /* Compose description: */
430474e5ec398f769830a548d818d75ff37d5113vboxsync strDecription = strParagraph.arg(strHeader + strTable.arg(strBody)) +
430474e5ec398f769830a548d818d75ff37d5113vboxsync strParagraph.arg(strNobreak.arg(strItalic.arg(tr("Double-click for more information."))));
430474e5ec398f769830a548d818d75ff37d5113vboxsync /* Set description: */
430474e5ec398f769830a548d818d75ff37d5113vboxsync /* Finally, we are showing LED in case of state is not 'idle': */