VirtualBox

Changeset 91390 in vbox


Ignore:
Timestamp:
Sep 27, 2021 11:45:15 AM (3 years ago)
Author:
vboxsync
Message:

Main/NLS: TRCOMPONENT -> PTRCOMPONENT w/ some added type safety. unregisterTranslation should mostly ignore NULL. Docs. bugref:1909

Location:
trunk/src/VBox/Main
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/include/VirtualBoxClientImpl.h

    r91373 r91390  
    106106#ifdef VBOX_WITH_MAIN_NLS
    107107        VirtualBoxTranslator *m_pVBoxTranslator;
    108         TRCOMPONENT           m_pTrComponent;
     108        PTRCOMPONENT          m_pTrComponent;
    109109#endif
    110110    };
  • trunk/src/VBox/Main/include/VirtualBoxTranslator.h

    r91373 r91390  
    2727#include <VBox/com/AutoLock.h>
    2828
    29 typedef void *TRCOMPONENT;
    30 
    3129class QMTranslator;
    3230
     
    3533{
    3634public:
    37 
    3835    virtual ~VirtualBoxTranslator();
    3936
     
    4643    HRESULT loadLanguage(ComPtr<IVirtualBox> aVirtualBox);
    4744
     45    /** Pointer to a translator component. */
     46    typedef struct TranslatorComponent *PTRCOMPONENT;
     47
    4848    /**
    49      * Adds path containing translation files into list of known paths.
    50      * Path should include translation file prefix.
     49     * Registers the translation for a component.
    5150     *
    5251     * @returns VBox status code
    53      * @param aTranslationPath   Path to translation files including file prefix
    54      * @param aDefault           Use as default translation component, i.e.
    55      *                           Use this path for translation if component
    56      *                           is NULL
    57      * @param aComponent         Where is the pointer to component returned
     52     * @param aTranslationPath  Path to the translation files, this includes the
     53     *                          base filename prefix.
     54     * @param aDefault          Use this as the default translation component, i.e.
     55     *                          when translate() is called with NULL for @a
     56     *                          aComponent.
     57     * @param aComponent        Pointer to where is the component handle should be
     58     *                          returned on success.  The return value must be used
     59     *                          for all subsequent calls to translate().
    5860     */
    5961    static int registerTranslation(const char *aTranslationPath,
    6062                                   bool aDefault,
    61                                    TRCOMPONENT *aComponent);
     63                                   PTRCOMPONENT *aComponent);
    6264
    6365    /**
    64      * Removes the path from list of known paths.
    65      * Does not remove already loaded translation from string cache.
     66     * Removes translations for a component.
     67     *
     68     * @returns VBox status code
     69     * @param   aComponent      The component.  NULL is quietly (VWRN_NOT_FOUND)
     70     *                          ignored .
    6671     */
    67     static int unregisterTranslation(TRCOMPONENT aComponent);
     72    static int unregisterTranslation(PTRCOMPONENT aComponent);
    6873
    6974    /**
     
    7479     *          valid only during lifetime of the translator instance.
    7580     */
    76     static const char *translate(TRCOMPONENT aComponent,
     81    static const char *translate(PTRCOMPONENT aComponent,
    7782                                 const char *aContext,
    7883                                 const char *aSourceText,
     
    97102    uint32_t m_cInstanceRefs;
    98103
     104    /** Translator component. */
    99105    struct TranslatorComponent
    100106    {
    101107        QMTranslator *pTranslator;
    102         /* Path to translation files. It includes file prefix, i.e
    103          * /path/to/folder/file_prefix */
     108        /** Path to translation files. It includes file prefix, i.e '/path/to/folder/file_prefix'. */
    104109        com::Utf8Str  strPath;
    105110
     
    128133    int i_registerTranslation(const char *aTranslationPath,
    129134                              bool aDefault,
    130                               TRCOMPONENT *aComponent);
     135                              PTRCOMPONENT *aComponent);
    131136
    132     int i_unregisterTranslation(TRCOMPONENT aComponent);
     137    int i_unregisterTranslation(PTRCOMPONENT aComponent);
    133138
    134     const char *i_translate(TRCOMPONENT aComponent,
     139    const char *i_translate(PTRCOMPONENT aComponent,
    135140                            const char *aContext,
    136141                            const char *aSourceText,
     
    139144};
    140145
     146/** Pointer to a translator component. */
     147typedef VirtualBoxTranslator::PTRCOMPONENT PTRCOMPONENT;
     148
    141149#endif /* !MAIN_INCLUDED_VirtualBoxTranslator_h */
    142150/* vi: set tabstop=4 shiftwidth=4 expandtab: */
  • trunk/src/VBox/Main/src-all/ExtPackManagerImpl.cpp

    r91388 r91390  
    150150#endif
    151151#ifdef VBOX_WITH_MAIN_NLS
    152     TRCOMPONENT         pTrComponent;
     152    PTRCOMPONENT        pTrComponent;
    153153#endif
    154154
  • trunk/src/VBox/Main/src-all/VirtualBoxTranslator.cpp

    r91373 r91390  
    330330int VirtualBoxTranslator::registerTranslation(const char *aTranslationPath,
    331331                                              bool aDefault,
    332                                               TRCOMPONENT *aComponent)
     332                                              PTRCOMPONENT *aComponent)
    333333{
    334334    VirtualBoxTranslator *pCurrInstance = VirtualBoxTranslator::tryInstance();
     
    345345int VirtualBoxTranslator::i_registerTranslation(const char *aTranslationPath,
    346346                                                bool aDefault,
    347                                                 TRCOMPONENT *aComponent)
     347                                                PTRCOMPONENT *aComponent)
    348348{
    349349    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
     
    358358            if (aDefault)
    359359                m_pDefaultComponent = pComponent;
    360             *aComponent = (TRCOMPONENT)pComponent;
     360            *aComponent = (PTRCOMPONENT)pComponent;
    361361            return VINF_SUCCESS;
    362362        }
     
    376376    if (aDefault)
    377377        m_pDefaultComponent = pComponent;
    378     *aComponent = (TRCOMPONENT)pComponent;
     378    *aComponent = (PTRCOMPONENT)pComponent;
    379379    /* ignore the error during loading because path
    380380     * could contain no translation for current language */
     
    384384
    385385
    386 int VirtualBoxTranslator::unregisterTranslation(TRCOMPONENT aComponent)
    387 {
    388     VirtualBoxTranslator *pCurrInstance = VirtualBoxTranslator::tryInstance();
    389     int rc = VERR_GENERAL_FAILURE;
    390     if (pCurrInstance != NULL)
    391     {
    392         rc = pCurrInstance->i_unregisterTranslation(aComponent);
    393         pCurrInstance->release();
    394     }
     386int VirtualBoxTranslator::unregisterTranslation(PTRCOMPONENT aComponent)
     387{
     388    int rc;
     389    if (aComponent != NULL)
     390    {
     391        VirtualBoxTranslator *pCurrInstance = VirtualBoxTranslator::tryInstance();
     392        if (pCurrInstance != NULL)
     393        {
     394            rc = pCurrInstance->i_unregisterTranslation(aComponent);
     395            pCurrInstance->release();
     396        }
     397        else
     398            rc = VERR_GENERAL_FAILURE;
     399    }
     400    else
     401        rc = VWRN_NOT_FOUND;
    395402    return rc;
    396403}
    397404
    398405
    399 int VirtualBoxTranslator::i_unregisterTranslation(TRCOMPONENT aComponent)
     406int VirtualBoxTranslator::i_unregisterTranslation(PTRCOMPONENT aComponent)
    400407{
    401408    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
     
    422429
    423430
    424 const char *VirtualBoxTranslator::translate(TRCOMPONENT aComponent,
     431const char *VirtualBoxTranslator::translate(PTRCOMPONENT aComponent,
    425432                                            const char *aContext,
    426433                                            const char *aSourceText,
     
    466473
    467474
    468 const char *VirtualBoxTranslator::i_translate(TRCOMPONENT aComponent,
     475const char *VirtualBoxTranslator::i_translate(PTRCOMPONENT aComponent,
    469476                                              const char *aContext,
    470477                                              const char *aSourceText,
  • trunk/src/VBox/Main/src-server/VirtualBoxImpl.cpp

    r91314 r91390  
    411411#ifdef VBOX_WITH_MAIN_NLS
    412412    VirtualBoxTranslator               *pVBoxTranslator;
    413     TRCOMPONENT                         pTrComponent;
     413    PTRCOMPONENT                        pTrComponent;
    414414#endif
    415415#if defined(RT_OS_WINDOWS) && defined(VBOXSVC_WITH_CLIENT_WATCHER)
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