VirtualBox

Changeset 1370 in vbox


Ignore:
Timestamp:
Mar 9, 2007 1:12:43 PM (18 years ago)
Author:
vboxsync
Message:

FE/Qt: Added VBoxGlobal::openURL(); implemented Help -> VirtualBox Web Site.

Location:
trunk/src/VBox/Frontends/VirtualBox
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/include/VBoxDefs.h

    r689 r1370  
    123123    /** Additional Qt event types. */
    124124    enum {
    125         ResizeEventType = QEvent::User + 0,
    126         RepaintEventType = QEvent::User + 1,
    127         MouseCapabilityEventType = QEvent::User + 2,
    128         MousePointerChangeEventType = QEvent::User + 3,
    129         MachineStateChangeEventType = QEvent::User + 4,
    130         MachineDataChangeEventType = QEvent::User + 5,
    131         MachineRegisteredEventType = QEvent::User + 6,
    132         SessionStateChangeEventType = QEvent::User + 7,
    133         SnapshotEventType = QEvent::User + 8,
    134         RuntimeErrorEventType = QEvent::User + 9,
    135         ModifierKeyChangeEventType = QEvent::User + 10,
     125        ResizeEventType = QEvent::User,
     126        RepaintEventType,
     127        MouseCapabilityEventType,
     128        MousePointerChangeEventType,
     129        MachineStateChangeEventType,
     130        MachineDataChangeEventType,
     131        MachineRegisteredEventType,
     132        SessionStateChangeEventType,
     133        SnapshotEventType,
     134        RuntimeErrorEventType,
     135        ModifierKeyChangeEventType,
    136136        EnumerateMediaEventType = QEvent::User + 100,
    137         ActivateMenuEventType = QEvent::User + 101,
     137#if defined (Q_WS_WIN)
     138        ShellExecuteEventType,
     139#endif
     140        ActivateMenuEventType,
    138141    };
    139142};
  • trunk/src/VBox/Frontends/VirtualBox/include/VBoxGlobal.h

    r1018 r1370  
    359359    /* various helpers */
    360360
     361    bool openURL (const QString &aURL);
     362
    361363    void languageChange();
    362364
  • trunk/src/VBox/Frontends/VirtualBox/include/VBoxProblemReporter.h

    r968 r1370  
    9696    // problem handlers
    9797
     98    void cannotOpenURL (const QString &aURL);
     99
    98100    void cannotInitCOM (HRESULT rc);
    99101    void cannotCreateVirtualBox (const CVirtualBox &vbox);
  • trunk/src/VBox/Frontends/VirtualBox/src/VBoxGlobal.cpp

    r1266 r1370  
    3939#include <qregexp.h>
    4040#include <qlocale.h>
     41#include <qprocess.h>
     42
     43#ifdef Q_WS_MAC
     44#include <Carbon/Carbon.h> // for HIToolbox/InternetConfig
     45#endif
    4146
    4247#if defined (VBOX_GUI_DEBUG)
     
    6974    const int mIndex;
    7075};
     76
     77#if defined (Q_WS_WIN)
     78class VBoxShellExecuteEvent : public QEvent
     79{
     80public:
     81
     82    /** Constructs a regular enum event */
     83    VBoxShellExecuteEvent (QThread *aThread, const QString &aURL,
     84                             bool aOk)
     85        : QEvent ((QEvent::Type) VBoxDefs::ShellExecuteEventType)
     86        , mThread (aThread), mURL (aURL), mOk (aOk)
     87        {}
     88
     89    QThread *mThread;
     90    QString mURL;
     91    bool mOk;
     92};
     93#endif
    7194
    7295// VirtualBox callback class
     
    13321355}
    13331356
     1357/**
     1358 * Opens the specified URL using OS/Desktop capabilities.
     1359 *
     1360 * @param aURL URL to open
     1361 *
     1362 * @return true on success and false otherwise
     1363 */
     1364bool VBoxGlobal::openURL (const QString &aURL)
     1365{
     1366#if defined (Q_WS_WIN)
     1367    /* We cannot use ShellExecute() on the main UI thread because we've
     1368     * initialized COM with CoInitializeEx(COINIT_MULTITHREADED). See
     1369     * http://support.microsoft.com/default.aspx?scid=kb;en-us;287087
     1370     * for more details. */
     1371    class Thread : public QThread
     1372    {
     1373    public:
     1374
     1375        Thread (const QString &aURL, QObject *aObject)
     1376            : mObject (aObject), mURL (aURL) {}
     1377
     1378        void run()
     1379        {
     1380            int rc = (int) ShellExecute (NULL, NULL, mURL.ucs2(), NULL, NULL, SW_SHOW);
     1381            bool ok = rc > 32;
     1382            QApplication::postEvent
     1383                (mObject,
     1384                 new VBoxShellExecuteEvent (this, mURL, ok));
     1385        }
     1386
     1387        QString mURL;
     1388        QObject *mObject;
     1389    };
     1390
     1391    Thread *thread = new Thread (aURL, this);
     1392    thread->start();
     1393    /* thread will be deleted in the VBoxShellExecuteEvent handler */
     1394
     1395    return true;
     1396
     1397#elif defined (Q_WS_X11)
     1398
     1399    static const char * const commands[] =
     1400        { "gnome-open", "kfmclient:exec", "x-www-browser", "firefox", "konqueror" };
     1401
     1402    for (size_t i = 0; i < ELEMENTS (commands); ++ i)
     1403    {
     1404        QStringList args = QStringList::split (':', commands [i]);
     1405        args += aURL;
     1406        QProcess cmd (args);
     1407        if (cmd.start())
     1408            return true;
     1409    }
     1410
     1411#elif defined (Q_WS_MAC)
     1412
     1413    /* The code below is taken from Psi 0.10 sources
     1414     * (http://www.psi-im.org) */
     1415
     1416    /* Use Internet Config to hand the URL to the appropriate application, as
     1417     * set by the user in the Internet Preferences pane.
     1418     * NOTE: ICStart could be called once at Psi startup, saving the
     1419     *       ICInstance in a global variable, as a minor optimization.
     1420     *       ICStop should then be called at Psi shutdown if ICStart
     1421     *       succeeded. */
     1422    ICInstance icInstance;
     1423    OSType psiSignature = 'psi ';
     1424    OSStatus error = ::ICStart (&icInstance, psiSignature);
     1425    if (error == noErr)
     1426    {
     1427        ConstStr255Param hint (0x0);
     1428        QCString cs = aURL.local8Bit();
     1429        const char* data = cs.data();
     1430        long length = cs.length();
     1431        long start (0);
     1432        long end (length);
     1433        /* Don't bother testing return value (error); launched application
     1434         * will report problems. */
     1435        ::ICLaunchURL (icInstance, hint, data, length, &start, &end);
     1436        ICStop (icInstance);
     1437    }
     1438
     1439#else
     1440    vboxProblem().message
     1441        (NULL, VBoxProblemReporter::Error,
     1442         tr ("Opening URLs is not implemented yet."));
     1443    return false;
     1444#endif
     1445
     1446    /* if we go here it means we couldn't open the URL */
     1447    vboxProblem().cannotOpenURL (aURL);
     1448
     1449    return false;
     1450}
     1451
    13341452/**
    13351453 *  Changes the language of all global string constants according to the
     
    18661984    switch (e->type())
    18671985    {
     1986#if defined (Q_WS_WIN)
     1987        case VBoxDefs::ShellExecuteEventType:
     1988        {
     1989            VBoxShellExecuteEvent *ev = (VBoxShellExecuteEvent *) e;
     1990            if (!ev->mOk)
     1991                vboxProblem().cannotOpenURL (ev->mURL);
     1992            /* wait for the thread and free resources */
     1993            ev->mThread->wait();
     1994            delete ev->mThread;
     1995            return true;
     1996        }
     1997#endif
     1998
    18681999        case VBoxDefs::EnumerateMediaEventType:
    18692000        {
  • trunk/src/VBox/Frontends/VirtualBox/src/VBoxProblemReporter.cpp

    r991 r1370  
    437437/////////////////////////////////////////////////////////////////////////////
    438438
     439void VBoxProblemReporter::cannotOpenURL (const QString &aURL)
     440{
     441    message
     442        (mainWindowShown(), VBoxProblemReporter::Error,
     443         tr ("Failed to open <tt>%1</tt>. Make sure your desktop environment "
     444             "can properly handle URLs of this type.")
     445         .arg (aURL));
     446}
     447
    439448void VBoxProblemReporter::cannotInitCOM (HRESULT rc)
    440449{
     
    15511560void VBoxProblemReporter::showHelpWebDialog()
    15521561{
     1562    vboxGlobal().openURL ("http://www.virtualbox.org");
    15531563}
    15541564
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