Development/Tutorials/PortToKStatusNotifierItem: Difference between revisions

    From KDE TechBase
    No edit summary
    Line 1: Line 1:
    Here is a list of changes to make to your application so that it can take advantage of the new KStatusNotifierItem (KSNI) class, available since KDE 4.4.
    Here is a list of changes to make to your application so that it can take advantage of the new KStatusNotifierItem (KSNI) class, available since KDE 4.4.
    KSNI API can be found here:
    http://api.kde.org/4.x-api/kdelibs-apidocs/kdeui/html/classKStatusNotifierItem.html


    == Initialization ==
    == Initialization ==
    * KSNI constructor takes a QObject, not a QWidget
    * KSNI constructor takes a QObject, not a QWidget
    * Be sure to set the category of your application with setCategory()
    * Be sure to set the category of your application with setCategory()
    * Tell KSNI what your main window is with setAssociatedWidget()


    == Signals ==
    == Signals ==
    * activated() becomes activateRequested(bool active, QPoint pos)
    Note: the mapping presented here is the one implemented by the Plasma Systemtray applet. Other implementations may do different choices.
    * Plasma systemtray will emit secondaryActivateRequested() when a user middle-click on the icon (other implementations may not support this though)
     
    * activated(Trigger) becomes activateRequested()
    * activated(MiddleClick) becomes secondaryActivateRequested()
    * mouse wheel on the item triggers scrollRequested()


    == Icons ==
    == Icons ==
    Line 16: Line 23:


    == Tooltip ==
    == Tooltip ==
    A KSNI tooltip is made of an icon, a title and a subtitle (which may contain some limited markup).
    A KSNI tooltip is made of an icon, a title and a subtitle (which may contain some limited markup).
    This means you have to replace your call to setToolTip(QString) with calls to:
    This means you have to replace your call to setToolTip(QString) with calls to:
    * setToolTipIconByName(QString) or setToolTipIconByPixmap()
    * setToolTipIconByName(QString) (prefered) or setToolTipIconByPixmap(QPixmap)
    * setToolTipTitle(QString)
    * setToolTipTitle(QString)
    * setToolTipSubTitle(QString)
    * setToolTipSubTitle(QString)


    show() -> setStatus(KStatusNotifierItem::Active)
    == Status ==
    hide() -> setStatus(KStatusNotifierItem::Passive)
    An item has a status, which can be set with setStatus(). The host implementation can use this status to adjust the way it presents the item. For example, the Plasma Systemtray applet will automatically hide items with the Passive status by default, making it only visible if you click on the applet expand arrow.
     
    When porting from KSystemTrayIcon, you can replace calls to show() or hide() with  setStatus(KStatusNotifierItem::Active) and setStatus(KStatusNotifierItem::Passive) respectively. You can also choose to delete the KSNI instance to hide it, and recreate it when you want to show it.


    == Misc ==
    == Misc ==
    * There is no equivalent for the convenience static loadIcon(QString) function. You have to replace it with KIconLoader::global()->loadIcon(name, KIconLoader::Panel)
    There is no equivalent for the convenience static loadIcon(QString name) function. You have to replace it with KIconLoader::global()->loadIcon(name, KIconLoader::Panel)

    Revision as of 17:46, 25 February 2010

    Here is a list of changes to make to your application so that it can take advantage of the new KStatusNotifierItem (KSNI) class, available since KDE 4.4.

    KSNI API can be found here:

    http://api.kde.org/4.x-api/kdelibs-apidocs/kdeui/html/classKStatusNotifierItem.html

    Initialization

    • KSNI constructor takes a QObject, not a QWidget
    • Be sure to set the category of your application with setCategory()
    • Tell KSNI what your main window is with setAssociatedWidget()

    Signals

    Note: the mapping presented here is the one implemented by the Plasma Systemtray applet. Other implementations may do different choices.

    • activated(Trigger) becomes activateRequested()
    • activated(MiddleClick) becomes secondaryActivateRequested()
    • mouse wheel on the item triggers scrollRequested()

    Icons

    Icons can be passed as a QString or as a QPixmap. Note that both must go through D-Bus, so for performance reasons, pass icons by name whenever possible.

    • setIcon() becomes either setIconByName(QString) or setIconByPixmap(QPixmap)

    Tooltip

    A KSNI tooltip is made of an icon, a title and a subtitle (which may contain some limited markup). This means you have to replace your call to setToolTip(QString) with calls to:

    • setToolTipIconByName(QString) (prefered) or setToolTipIconByPixmap(QPixmap)
    • setToolTipTitle(QString)
    • setToolTipSubTitle(QString)

    Status

    An item has a status, which can be set with setStatus(). The host implementation can use this status to adjust the way it presents the item. For example, the Plasma Systemtray applet will automatically hide items with the Passive status by default, making it only visible if you click on the applet expand arrow.

    When porting from KSystemTrayIcon, you can replace calls to show() or hide() with setStatus(KStatusNotifierItem::Active) and setStatus(KStatusNotifierItem::Passive) respectively. You can also choose to delete the KSNI instance to hide it, and recreate it when you want to show it.

    Misc

    There is no equivalent for the convenience static loadIcon(QString name) function. You have to replace it with KIconLoader::global()->loadIcon(name, KIconLoader::Panel)