Changeset 871 for trunk


Ignore:
Timestamp:
Jun 9, 2011, 8:17:01 PM (14 years ago)
Author:
Dmitry A. Kuminov
Message:

gui: Fixed application crashes if the xsystray API DLL could not be loaded.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/gui/util/qsystemtrayicon_pm.cpp

    r856 r871  
    246246}
    247247
     248template <typename T>
     249inline T AssignFromVoidPtr(T &var, void *val) { var = (T)val; return var; }
     250
     251static bool gotApis = false;
     252
     253static bool resolveApis()
     254{
     255    static bool tried = false;
     256
     257    if (!tried) {
     258        tried = true;
     259
     260        do {
     261            // link to the xsystray API DLL at runtime
     262            QLibrary xsystray(QLatin1String("xsystray"));
     263
     264            #define R(f) if (AssignFromVoidPtr(f, xsystray.resolve(#f)) == NULL) break
     265
     266            R(xstQuerySysTrayVersion);
     267            R(xstAddSysTrayIcon);
     268            R(xstReplaceSysTrayIcon);
     269            R(xstRemoveSysTrayIcon);
     270            R(xstSetSysTrayIconToolTip);
     271            R(xstQuerySysTrayIconRect);
     272            R(xstShowSysTrayIconBalloon);
     273            R(xstHideSysTrayIconBalloon);
     274            R(xstGetSysTrayCreatedMsgId);
     275            R(xstGetSysTrayMaxTextLen);
     276
     277            #undef R
     278
     279            // initialize some constants
     280            WM_XST_CREATED = xstGetSysTrayCreatedMsgId();
     281            MaxTextLen = xstGetSysTrayMaxTextLen();
     282
     283            gotApis = true;
     284
     285        } while (0);
     286    }
     287
     288    return gotApis;
     289}
     290
    248291void QSystemTrayIconPrivate::install_sys()
    249292{
     293    if (!gotApis && !resolveApis())
     294        return;
     295
    250296    Q_Q(QSystemTrayIcon);
    251297    if (!sys) {
     
    308354}
    309355
    310 template <typename T>
    311 inline T AssignFromVoidPtr(T &var, void *val) { var = (T)val; return var; }
    312 
    313356bool QSystemTrayIconPrivate::isSystemTrayAvailable_sys()
    314357{
    315     static bool tried = false;
    316     if (!tried) {
    317         tried = true;
    318 
    319         // link to the xsystray DLL at runtime
    320         QLibrary xsystray(QLatin1String("xsystray"));
    321 
    322         #define R(f) if (AssignFromVoidPtr(f, xsystray.resolve(#f)) == NULL) return false
    323 
    324         R(xstQuerySysTrayVersion);
    325         R(xstAddSysTrayIcon);
    326         R(xstReplaceSysTrayIcon);
    327         R(xstRemoveSysTrayIcon);
    328         R(xstSetSysTrayIconToolTip);
    329         R(xstQuerySysTrayIconRect);
    330         R(xstShowSysTrayIconBalloon);
    331         R(xstHideSysTrayIconBalloon);
    332         R(xstGetSysTrayCreatedMsgId);
    333         R(xstGetSysTrayMaxTextLen);
    334 
    335         #undef R
    336 
    337         // initialize some constants
    338         WM_XST_CREATED = xstGetSysTrayCreatedMsgId();
    339         MaxTextLen = xstGetSysTrayMaxTextLen();
    340     }
    341 
     358    if (!gotApis && !resolveApis())
     359        return false;
    342360    return xstQuerySysTrayVersion(0, 0, 0);
    343361}
Note: See TracChangeset for help on using the changeset viewer.