VirtualBox

Ignore:
Timestamp:
Oct 27, 2020 9:39:34 AM (4 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:9831. Showing a 404 error when the file in not found

Location:
trunk/src/VBox/Frontends/VirtualBox/src/helpbrowser
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/helpbrowser/UIHelpBrowserWidget.cpp

    r86716 r86718  
    4242#include "UIIconPool.h"
    4343#include "UIMessageCenter.h"
    44 #include "UIVMLogPage.h"
    4544#include "UIHelpBrowserWidget.h"
    46 #include "UIVMLogViewerBookmarksPanel.h"
    47 #include "UIVMLogViewerFilterPanel.h"
    48 #include "UIVMLogViewerSearchPanel.h"
    49 #include "UIVMLogViewerOptionsPanel.h"
    5045#include "QIToolBar.h"
    5146#include "UICommon.h"
     
    256251void UIHelpBrowserWidget::loadOptions()
    257252{
    258     if (m_pContentViewer)
     253    if (m_pContentViewer && m_pHelpEngine)
    259254    {
    260255        QUrl url(gEDataManager->helpBrowserLastUrl());
     256        if (url.isEmpty())
     257            return;
    261258        if (url.isValid())
    262             m_pContentViewer->setSource(url);
     259        {
     260            if (m_pHelpEngine->findFile(url).isValid())
     261                m_pContentViewer->setSource(url);
     262            else
     263                show404Error(url);
     264        }
    263265    }
    264266}
     
    297299    }
    298300    if (m_pShowHideTabWidgetAction)
    299         m_pShowHideTabWidgetAction->setText("Show/Hide Tabs Widget");
     301        m_pShowHideTabWidgetAction->setText(tr("Show/Hide Tabs Widget"));
     302
     303    m_strPageNotFoundText = tr("<div><p><h3>404. Not found.</h3>The page <b>%1</b> could not be found.</p></div>");
    300304}
    301305
     
    328332}
    329333
    330 void UIHelpBrowserWidget::sltHandleHelpEngineSetupFinished()
    331 {
    332 #if defined(RT_OS_LINUX) && defined(VBOX_WITH_DOCS_QHELP)
    333     AssertReturnVoid(m_pContentViewer && m_pHelpEngine);
     334QUrl UIHelpBrowserWidget::findIndexHtml() const
     335{
    334336    QList<QUrl> files = m_pHelpEngine->files(m_pHelpEngine->namespaceName(m_strHelpFilePath), QStringList());
    335     /* Search for the index of the index.htnl: */
    336     int iIndex = 0;
     337    int iIndex = -1;
    337338    for (int i = 0; i < files.size(); ++i)
    338339    {
     
    343344        }
    344345    }
    345     if (files.size() > iIndex)
    346         m_pContentViewer->setSource(files[iIndex]);
    347     /** @todo show some kind of error maybe. */
     346    if (iIndex == -1)
     347    {
     348        /* If index html/htm could not be found try to find a html file at least: */
     349        for (int i = 0; i < files.size(); ++i)
     350        {
     351            if (files[i].toString().contains(".html", Qt::CaseInsensitive) ||
     352                files[i].toString().contains(".htm", Qt::CaseInsensitive))
     353            {
     354                iIndex = i;
     355                break;
     356            }
     357        }
     358    }
     359    if (iIndex != -1 && files.size() > iIndex)
     360        return files[iIndex];
     361    return QUrl();
     362}
     363
     364void UIHelpBrowserWidget::show404Error(const QUrl &url)
     365{
     366    if (m_pContentWidget)
     367        m_pContentViewer->setText(m_strPageNotFoundText.arg(url.toString()));
     368}
     369
     370void UIHelpBrowserWidget::sltHandleHelpEngineSetupFinished()
     371{
     372#if defined(RT_OS_LINUX) && defined(VBOX_WITH_DOCS_QHELP)
     373    AssertReturnVoid(m_pContentViewer && m_pHelpEngine);
     374    /* Search for the index of the index.htnl: */
     375    QUrl url = findIndexHtml();
     376    if (url.isValid())
     377        m_pContentViewer->setSource(url);
     378    else
     379        show404Error(url);
    348380#endif
    349381}
     
    369401void UIHelpBrowserWidget::sltHandleHelpBrowserViewerSourceChange(const QUrl &source)
    370402{
    371     printf("%s\n", qPrintable(source.toString()));
     403    Q_UNUSED(source);
    372404}
    373405
  • trunk/src/VBox/Frontends/VirtualBox/src/helpbrowser/UIHelpBrowserWidget.h

    r86716 r86718  
    9393    void saveOptions();
    9494    void cleanup();
     95    QUrl findIndexHtml() const;
     96    void show404Error();
    9597    /** @name Event handling stuff.
    9698      * @{ */
     
    133135    QWidget             *m_pBookmarksWidget;
    134136    QAction             *m_pShowHideTabWidgetAction;
     137    QString              m_strPageNotFoundText;
    135138};
    136139
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette